[vtkusers] Tapered "cylinder".

kenichiro yoshimi rccm.kyoshimi at gmail.com
Thu Jul 12 21:21:31 EDT 2018


Hi,

The easiest way to create a tapered hollow cylinder is scaling the
points on top surface of the cylinder created as an extrusion of a
disk. The sample code below shows this:

------
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import vtk


def main():
    colors = vtk.vtkNamedColors()

    diskSource = vtk.vtkDiskSource()
    diskSource.SetInnerRadius(0.5);
    diskSource.SetOuterRadius(1.0);
    diskSource.SetRadialResolution(1);
    diskSource.SetCircumferentialResolution(40);

    # Apply linear extrusion
    extrude = vtk.vtkLinearExtrusionFilter()
    extrude.SetInputConnection(diskSource.GetOutputPort())
    extrude.SetExtrusionTypeToNormalExtrusion();
    extrude.SetVector(0, 0, 2)
    extrude.Update()

    # Taper the cylinder
    scale = 0.5
    taperedCylinder = extrude.GetOutput()
    points = taperedCylinder.GetPoints()
    numPts = taperedCylinder.GetNumberOfPoints()
    for ptId in range(numPts/2, numPts):
      point = points.GetPoint(ptId)
      points.SetPoint(ptId, point[0]*scale, point[1]*scale, point[2])

    # Create a mapper and actor.
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(taperedCylinder)

    actor = vtk.vtkActor()
    actor.GetProperty().SetColor(colors.GetColor3d("Cornsilk"))
    actor.SetMapper(mapper)

    # Create a renderer, render window, and interactor
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.SetWindowName("TaperedCylinder")
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)

    # Add the actors to the scene
    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d("DarkGreen"))

    # Render and interact
    renderWindow.Render()
    renderWindowInteractor.Start()


if __name__ == '__main__':
    main()
------

Regards
2018年7月12日(木) 21:12 M_skov <M.skovmand1 at gmail.com>:
>
> Hello there.
>
> Disclaimer, I am quite new to using VTK, and even coding in general (which
> is done in Python).
> I am trying to visualize a tapered hollow cylinder, I have start and
> end-coordinates (x,y,z) and a different diameter at each coordinate.
>      ___
>    /      \
>   /        \  This is basically what I want.
>  /_____ \
>
> I have searched, quite a bit, but have yet to find a solution to this.
> As of right now, when the diameters are equal, I am visualizing the cylinder
> as an extruded disk, transforming it for the orientation, which works
> perfectly!
>
> I have been looking at vtktubefilter, but as I see it, I end up losing my
> wall thickness using that option.
> Is there a radius scaling factor I have overlooked, or other functions that
> can help me accomplish this?
>
> Hoping the question is clear and that someone is able to assist me in this.
> Have a nice day!
>
> - Martin
>
>
>
>
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers


More information about the vtkusers mailing list