def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__(self, module_manager, vtk.vtkRotationalExtrusionFilter(), 'Processing.', ('vtkPolyData', ), ('vtkPolyData', ), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkRotationalExtrusionFilter(), "Processing.", ("vtkPolyData",), ("vtkPolyData",), replaceDoc=True, inputFunctions=None, outputFunctions=None, )
def createActor1(self): # Create source polyDataPoints = vtk.vtkPoints() polyDataPoints.InsertPoint(0, 1., 0., 0.) polyDataPoints.InsertPoint(1, 1., 0., 10.) polyDataPoints.InsertPoint(2, 3., 0., 10.) polyDataPoints.InsertPoint(3, 2., 0., 0.) polygon = vtk.vtkPolygon() polygon.GetPointIds().SetNumberOfIds(4) polygon.GetPointIds().SetId(0, 0) polygon.GetPointIds().SetId(1, 1) polygon.GetPointIds().SetId(2, 2) polygon.GetPointIds().SetId(3, 3) polygons = vtk.vtkCellArray() polygons.InsertNextCell(polygon) polyData = vtk.vtkPolyData() polyData.SetPoints(polyDataPoints) #polyData.SetLines(polygons) polyData.SetPolys(polygons) rotationalExtrusionFilter = vtk.vtkRotationalExtrusionFilter() rotationalExtrusionFilter.SetInput(polyData) rotationalExtrusionFilter.SetResolution(10) rotationalExtrusionFilter.SetAngle(240) rotationalExtrusionFilter.SetTranslation(0) # Create a mapper mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(rotationalExtrusionFilter.GetOutputPort()) # Create an actor actor = vtk.vtkActor() actor.SetMapper(mapper) #actor.GetProperty().SetColor(1.0, 0, 0) return actor
a4Actor.RotateX(-90) a4Actor.SetPosition(1, 1, 0) a4Actor.GetProperty().SetColor(0.3, 1, 0.3) a4Actor.GetProperty().SetSpecularColor(1, 1, 1) a4Actor.GetProperty().SetSpecular(0.3) a4Actor.GetProperty().SetSpecularPower(20) a4Actor.GetProperty().SetAmbient(0.2) a4Actor.GetProperty().SetDiffuse(0.8) # draw the DOP arrowT2 = vtk.vtkTransform() arrowT2.Scale(1, 0.6, 1) arrowT2.RotateY(90) arrowTF2 = vtk.vtkTransformPolyDataFilter() arrowTF2.SetInputData(pd2) arrowTF2.SetTransform(arrowT2) arrowREF = vtk.vtkRotationalExtrusionFilter() arrowREF.SetInputConnection(arrowTF2.GetOutputPort()) arrowREF.CappingOff() arrowREF.SetResolution(30) spikeMapper = vtk.vtkPolyDataMapper() spikeMapper.SetInputConnection(arrowREF.GetOutputPort()) a5Actor = vtk.vtkLODActor() a5Actor.SetMapper(spikeMapper) a5Actor.SetScale(.3, .3, .6) a5Actor.RotateY(90) a5Actor.SetPosition(-2, 0, 0) a5Actor.GetProperty().SetColor(1, 0.3, 1) a5Actor.GetProperty().SetAmbient(0.2) a5Actor.GetProperty().SetDiffuse(0.8) # focal point fps = vtk.vtkSphereSource()
# Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # create a semi-cylinder # line = vtk.vtkLineSource() line.SetPoint1(0, 1, 0) line.SetPoint2(0, 1, 2) line.SetResolution(10) lineSweeper = vtk.vtkRotationalExtrusionFilter() lineSweeper.SetResolution(20) lineSweeper.SetInputConnection(line.GetOutputPort()) lineSweeper.SetAngle(270) bump = vtk.vtkBrownianPoints() bump.SetInputConnection(lineSweeper.GetOutputPort()) warp = vtk.vtkWarpVector() warp.SetInputConnection(bump.GetOutputPort()) warp.SetScaleFactor(.2) smooth = vtk.vtkSmoothPolyDataFilter() smooth.SetInputConnection(warp.GetOutputPort()) smooth.SetNumberOfIterations(50) smooth.BoundarySmoothingOn()
#* https://www.mooseframework.org #* #* All rights reserved, see COPYRIGHT for full restrictions #* https://github.com/idaholab/moose/blob/master/COPYRIGHT #* #* Licensed under LGPL 2.1, please see LICENSE for details #* https://www.gnu.org/licenses/lgpl-2.1.html import vtk line = vtk.vtkPlaneSource() line.SetOrigin(1, 0, 1) line.SetPoint1(2, 0, 1) line.SetPoint2(1, 0, 2) extrude = vtk.vtkRotationalExtrusionFilter() extrude.SetResolution(20) extrude.SetInputConnection(line.GetOutputPort()) extrude.SetAngle(90) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(extrude.GetOutputPort()) actor = vtk.vtkActor() actor.SetMapper(mapper) ren = vtk.vtkRenderer() ren.AddActor(actor) ren.SetBackground([0.5]*3) win = vtk.vtkRenderWindow()
#!/usr/bin/env python import vtk line = vtk.vtkPlaneSource() line.SetOrigin(1, 0, 1) line.SetPoint1(2, 0, 1) line.SetPoint2(1, 0, 2) extrude = vtk.vtkRotationalExtrusionFilter() extrude.SetResolution(20) extrude.SetInputConnection(line.GetOutputPort()) extrude.SetAngle(90) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(extrude.GetOutputPort()) actor = vtk.vtkActor() actor.SetMapper(mapper) ren = vtk.vtkRenderer() ren.AddActor(actor) ren.SetBackground([0.5]*3) win = vtk.vtkRenderWindow() win.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(win) iren.Initialize() iren.Start()
def main(): colors = vtk.vtkNamedColors() # Set the colors. azArrowColor = map(lambda x: x / 255.0, [255, 77, 77]) colors.SetColor('AzimuthArrowColor', *azArrowColor) elevArrowColor = map(lambda x: x / 255.0, [77, 255, 77]) colors.SetColor('ElevationArrowColor', *elevArrowColor) rollArrowColor = map(lambda x: x / 255.0, [255, 255, 77]) colors.SetColor('RollArrowColor', *rollArrowColor) spikeColor = map(lambda x: x / 255.0, [255, 77, 255]) colors.SetColor('SpikeColor', *spikeColor) bkg = map(lambda x: x / 255.0, [25, 51, 102]) colors.SetColor('BkgColor', *bkg) # Create a rendering window, renderer and interactor. ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Create a camera model. camCS = vtk.vtkConeSource() camCS.SetHeight(1.5) camCS.SetResolution(12) camCS.SetRadius(0.4) camCBS = vtk.vtkCubeSource() camCBS.SetXLength(1.5) camCBS.SetZLength(0.8) camCBS.SetCenter(0.4, 0, 0) camAPD = vtk.vtkAppendFilter() camAPD.AddInputConnection(camCBS.GetOutputPort()) camAPD.AddInputConnection(camCS.GetOutputPort()) camMapper = vtk.vtkPolyDataMapper() camMapper.SetInputConnection(camAPD.GetOutputPort()) camActor = vtk.vtkLODActor() camActor.SetMapper(camMapper) camActor.SetScale(2, 2, 2) # Draw the arrows. pd = vtk.vtkPolyData() ca = vtk.vtkCellArray() fp = vtk.vtkPoints() fp.InsertNextPoint(0, 1, 0) fp.InsertNextPoint(8, 1, 0) fp.InsertNextPoint(8, 2, 0) fp.InsertNextPoint(10, 0.01, 0) fp.InsertNextPoint(8, -2, 0) fp.InsertNextPoint(8, -1, 0) fp.InsertNextPoint(0, -1, 0) ca.InsertNextCell(7) ca.InsertCellPoint(0) ca.InsertCellPoint(1) ca.InsertCellPoint(2) ca.InsertCellPoint(3) ca.InsertCellPoint(4) ca.InsertCellPoint(5) ca.InsertCellPoint(6) pd.SetPoints(fp) pd.SetPolys(ca) pd2 = vtk.vtkPolyData() ca2 = vtk.vtkCellArray() fp2 = vtk.vtkPoints() fp2.InsertNextPoint(0, 1, 0) fp2.InsertNextPoint(8, 1, 0) fp2.InsertNextPoint(8, 2, 0) fp2.InsertNextPoint(10, 0.01, 0) ca2.InsertNextCell(4) ca2.InsertCellPoint(0) ca2.InsertCellPoint(1) ca2.InsertCellPoint(2) ca2.InsertCellPoint(3) pd2.SetPoints(fp2) pd2.SetLines(ca2) arrowIM = vtk.vtkImplicitModeller() arrowIM.SetInputData(pd) arrowIM.SetSampleDimensions(50, 20, 8) arrowCF = vtk.vtkContourFilter() arrowCF.SetInputConnection(arrowIM.GetOutputPort()) arrowCF.SetValue(0, 0.2) arrowWT = vtk.vtkWarpTo() arrowWT.SetInputConnection(arrowCF.GetOutputPort()) arrowWT.SetPosition(5, 0, 5) arrowWT.SetScaleFactor(0.85) arrowWT.AbsoluteOn() arrowT = vtk.vtkTransform() arrowT.RotateY(60) arrowT.Translate(-1.33198, 0, -1.479) arrowT.Scale(1, 0.5, 1) arrowTF = vtk.vtkTransformFilter() arrowTF.SetInputConnection(arrowWT.GetOutputPort()) arrowTF.SetTransform(arrowT) arrowMapper = vtk.vtkDataSetMapper() arrowMapper.SetInputConnection(arrowTF.GetOutputPort()) arrowMapper.ScalarVisibilityOff() # Draw the azimuth arrows. a1Actor = vtk.vtkLODActor() a1Actor.SetMapper(arrowMapper) a1Actor.RotateZ(180) a1Actor.SetPosition(1, 0, -1) a1Actor.GetProperty().SetColor(colors.GetColor3d("AzimuthArrowColor")) a1Actor.GetProperty().SetSpecularColor(colors.GetColor3d("White")) a1Actor.GetProperty().SetSpecular(0.3) a1Actor.GetProperty().SetSpecularPower(20) a1Actor.GetProperty().SetAmbient(0.2) a1Actor.GetProperty().SetDiffuse(0.8) a2Actor = vtk.vtkLODActor() a2Actor.SetMapper(arrowMapper) a2Actor.RotateZ(180) a2Actor.RotateX(180) a2Actor.SetPosition(1, 0, 1) a2Actor.GetProperty().SetColor(colors.GetColor3d("AzimuthArrowColor")) a2Actor.GetProperty().SetSpecularColor(colors.GetColor3d("White")) a2Actor.GetProperty().SetSpecular(0.3) a2Actor.GetProperty().SetSpecularPower(20) a2Actor.GetProperty().SetAmbient(0.2) a2Actor.GetProperty().SetDiffuse(0.8) # Draw the elevation arrows. a3Actor = vtk.vtkLODActor() a3Actor.SetMapper(arrowMapper) a3Actor.RotateZ(180) a3Actor.RotateX(90) a3Actor.SetPosition(1, -1, 0) a3Actor.GetProperty().SetColor(colors.GetColor3d("ElevationArrowColor")) a3Actor.GetProperty().SetSpecularColor(colors.GetColor3d("White")) a3Actor.GetProperty().SetSpecular(0.3) a3Actor.GetProperty().SetSpecularPower(20) a3Actor.GetProperty().SetAmbient(0.2) a3Actor.GetProperty().SetDiffuse(0.8) a4Actor = vtk.vtkLODActor() a4Actor.SetMapper(arrowMapper) a4Actor.RotateZ(180) a4Actor.RotateX(-90) a4Actor.SetPosition(1, 1, 0) a4Actor.GetProperty().SetColor(colors.GetColor3d("ElevationArrowColor")) a4Actor.GetProperty().SetSpecularColor(colors.GetColor3d("White")) a4Actor.GetProperty().SetSpecular(0.3) a4Actor.GetProperty().SetSpecularPower(20) a4Actor.GetProperty().SetAmbient(0.2) a4Actor.GetProperty().SetDiffuse(0.8) # Draw the DOP. arrowT2 = vtk.vtkTransform() arrowT2.Scale(1, 0.6, 1) arrowT2.RotateY(90) arrowTF2 = vtk.vtkTransformPolyDataFilter() arrowTF2.SetInputData(pd2) arrowTF2.SetTransform(arrowT2) arrowREF = vtk.vtkRotationalExtrusionFilter() arrowREF.SetInputConnection(arrowTF2.GetOutputPort()) arrowREF.CappingOff() arrowREF.SetResolution(30) spikeMapper = vtk.vtkPolyDataMapper() spikeMapper.SetInputConnection(arrowREF.GetOutputPort()) a5Actor = vtk.vtkLODActor() a5Actor.SetMapper(spikeMapper) a5Actor.SetScale(.3, .3, .6) a5Actor.RotateY(90) a5Actor.SetPosition(-2, 0, 0) a5Actor.GetProperty().SetColor(colors.GetColor3d("SpikeColor")) a5Actor.GetProperty().SetAmbient(0.2) a5Actor.GetProperty().SetDiffuse(0.8) # Focal point. fps = vtk.vtkSphereSource() fps.SetRadius(0.5) fpMapper = vtk.vtkPolyDataMapper() fpMapper.SetInputConnection(fps.GetOutputPort()) fpActor = vtk.vtkLODActor() fpActor.SetMapper(fpMapper) fpActor.SetPosition(-9, 0, 0) fpActor.GetProperty().SetSpecularColor(colors.GetColor3d("White")) fpActor.GetProperty().SetSpecular(0.3) fpActor.GetProperty().SetAmbient(0.2) fpActor.GetProperty().SetDiffuse(0.8) fpActor.GetProperty().SetSpecularPower(20) # Create the roll arrows. arrowWT2 = vtk.vtkWarpTo() arrowWT2.SetInputConnection(arrowCF.GetOutputPort()) arrowWT2.SetPosition(5, 0, 2.5) arrowWT2.SetScaleFactor(0.95) arrowWT2.AbsoluteOn() arrowT3 = vtk.vtkTransform() arrowT3.Translate(-2.50358, 0, -1.70408) arrowT3.Scale(0.5, 0.3, 1) arrowTF3 = vtk.vtkTransformFilter() arrowTF3.SetInputConnection(arrowWT2.GetOutputPort()) arrowTF3.SetTransform(arrowT3) arrowMapper2 = vtk.vtkDataSetMapper() arrowMapper2.SetInputConnection(arrowTF3.GetOutputPort()) arrowMapper2.ScalarVisibilityOff() # Draw the roll arrows. a6Actor = vtk.vtkLODActor() a6Actor.SetMapper(arrowMapper2) a6Actor.RotateZ(90) a6Actor.SetPosition(-4, 0, 0) a6Actor.SetScale(1.5, 1.5, 1.5) a6Actor.GetProperty().SetColor(colors.GetColor3d("RollArrowColor")) a6Actor.GetProperty().SetSpecularColor(colors.GetColor3d("White")) a6Actor.GetProperty().SetSpecular(0.3) a6Actor.GetProperty().SetSpecularPower(20) a6Actor.GetProperty().SetAmbient(0.2) a6Actor.GetProperty().SetDiffuse(0.8) # Add the actors to the renderer, set the background and size. ren.AddActor(camActor) ren.AddActor(a1Actor) ren.AddActor(a2Actor) ren.AddActor(a3Actor) ren.AddActor(a4Actor) ren.AddActor(a5Actor) ren.AddActor(a6Actor) ren.AddActor(fpActor) ren.SetBackground(colors.GetColor3d("BkgColor")) ren.SetBackground(colors.GetColor3d("SlateGray")) renWin.SetSize(640, 480) # Render the image. cam1 = (ren.GetActiveCamera()) ren.ResetCamera() cam1.Azimuth(150) cam1.Elevation(30) cam1.Dolly(1.5) ren.ResetCameraClippingRange() # Create a TextActor for azimuth (a1 and a2 actor's color). text = vtk.vtkTextActor() text.SetInput("Azimuth") tprop = text.GetTextProperty() tprop.SetFontFamilyToArial() tprop.ShadowOff() tprop.SetLineSpacing(1.0) tprop.SetFontSize(36) tprop.SetColor(a1Actor.GetProperty().GetColor()) text.SetDisplayPosition(20, 50) ren.AddActor2D(text) # Create a TextActor for elevation (a3 and a4 actor's color). text2 = vtk.vtkTextActor() text2.SetInput("Elevation") tprop = text2.GetTextProperty() tprop.SetFontFamilyToArial() tprop.ShadowOff() tprop.SetLineSpacing(1.0) tprop.SetFontSize(36) tprop.SetColor(a3Actor.GetProperty().GetColor()) text2.SetDisplayPosition(20, 100) ren.AddActor2D(text2) # Create a TextActor for roll (a6 actor's color). text3 = vtk.vtkTextActor() text3.SetInput("Roll") tprop = text3.GetTextProperty() tprop.SetFontFamilyToArial() tprop.ShadowOff() tprop.SetLineSpacing(1.0) tprop.SetFontSize(36) tprop.SetColor(a6Actor.GetProperty().GetColor()) text3.SetDisplayPosition(20, 150) ren.AddActor2D(text3) iren.Initialize() iren.Start()
def main(): colors = vtk.vtkNamedColors() # Create the RenderWindow, Renderer and Interactor. # renderer = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(renderer) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Create the bottle profile. # points = vtk.vtkPoints() points.InsertPoint(0, 0.01, 0.0, 0.0) points.InsertPoint(1, 1.5, 0.0, 0.0) points.InsertPoint(2, 1.5, 0.0, 3.5) points.InsertPoint(3, 1.25, 0.0, 3.75) points.InsertPoint(4, 0.75, 0.0, 4.00) points.InsertPoint(5, 0.6, 0.0, 4.35) points.InsertPoint(6, 0.7, 0.0, 4.65) points.InsertPoint(7, 1.0, 0.0, 4.75) points.InsertPoint(8, 1.0, 0.0, 5.0) points.InsertPoint(9, 0.2, 0.0, 5.0) lines = vtk.vtkCellArray() lines.InsertNextCell(10) # The number of points. lines.InsertCellPoint(0) lines.InsertCellPoint(1) lines.InsertCellPoint(2) lines.InsertCellPoint(3) lines.InsertCellPoint(4) lines.InsertCellPoint(5) lines.InsertCellPoint(6) lines.InsertCellPoint(7) lines.InsertCellPoint(8) lines.InsertCellPoint(9) profile = vtk.vtkPolyData() profile.SetPoints(points) profile.SetLines(lines) # Extrude the profile to make the bottle. # extrude = vtk.vtkRotationalExtrusionFilter() extrude.SetInputData(profile) extrude.SetResolution(60) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(extrude.GetOutputPort()) bottle = vtk.vtkActor() bottle.SetMapper(mapper) bottle.GetProperty().SetColor(colors.GetColor3d('Mint')) # Sisplay the profile. stripper = vtk.vtkStripper() stripper.SetInputData(profile) tubes = vtk.vtkTubeFilter() tubes.SetInputConnection(stripper.GetOutputPort()) tubes.SetNumberOfSides(11) tubes.SetRadius(0.05) profileMapper = vtk.vtkPolyDataMapper() profileMapper.SetInputConnection(tubes.GetOutputPort()) profileActor = vtk.vtkActor() profileActor.SetMapper(profileMapper) profileActor.GetProperty().SetColor(colors.GetColor3d('Tomato')) # Add the actors to the renderer, set the background and size. # renderer.AddActor(bottle) renderer.AddActor(profileActor) renderer.SetBackground(colors.GetColor3d('Burlywood')) renWin.SetSize(640, 480) renWin.SetWindowName('Bottle') renWin.Render() renderer.GetActiveCamera().SetPosition(1, 0, 0) renderer.GetActiveCamera().SetFocalPoint(0, 0, 0) renderer.GetActiveCamera().SetViewUp(0, 0, 1) renderer.ResetCamera() renderer.GetActiveCamera().Azimuth(30) renderer.GetActiveCamera().Elevation(30) # Render the image. # renWin.Render() iren.Start()
def main(): colors = vtk.vtkNamedColors() # Create the RenderWindow, Renderer and Interactor. # renderer = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(renderer) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Create the spring profile (a circle). # points = vtk.vtkPoints() points.InsertPoint(0, 1.0, 0.0, 0.0) points.InsertPoint(1, 1.0732, 0.0, -0.1768) points.InsertPoint(2, 1.25, 0.0, -0.25) points.InsertPoint(3, 1.4268, 0.0, -0.1768) points.InsertPoint(4, 1.5, 0.0, 0.00) points.InsertPoint(5, 1.4268, 0.0, 0.1768) points.InsertPoint(6, 1.25, 0.0, 0.25) points.InsertPoint(7, 1.0732, 0.0, 0.1768) poly = vtk.vtkCellArray() poly.InsertNextCell(8) # The number of points. poly.InsertCellPoint(0) poly.InsertCellPoint(1) poly.InsertCellPoint(2) poly.InsertCellPoint(3) poly.InsertCellPoint(4) poly.InsertCellPoint(5) poly.InsertCellPoint(6) poly.InsertCellPoint(7) profile = vtk.vtkPolyData() profile.SetPoints(points) profile.SetPolys(poly) # Extrude the profile to make a spring. # extrude = vtk.vtkRotationalExtrusionFilter() extrude.SetInputData(profile) extrude.SetResolution(360) extrude.SetTranslation(6) extrude.SetDeltaRadius(1.0) extrude.SetAngle(2160.0) # six revolutions normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(extrude.GetOutputPort()) normals.SetFeatureAngle(60) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(normals.GetOutputPort()) spring = vtk.vtkActor() spring.SetMapper(mapper) spring.GetProperty().SetColor(colors.GetColor3d("PowderBlue")) spring.GetProperty().SetDiffuse(0.7) spring.GetProperty().SetSpecular(0.4) spring.GetProperty().SetSpecularPower(20) spring.GetProperty().BackfaceCullingOn() # Add the actors to the renderer, set the background and size. # renderer.AddActor(spring) renderer.SetBackground(colors.GetColor3d("Burlywood")) renWin.SetSize(640, 512) renWin.SetWindowName('Spring') renderer.ResetCamera() renderer.GetActiveCamera().Azimuth(90) # Render the image. # renWin.Render() iren.Start()
a4Actor.RotateX(-90) a4Actor.SetPosition(1,1,0) a4Actor.GetProperty().SetColor(0.3,1,0.3) a4Actor.GetProperty().SetSpecularColor(1,1,1) a4Actor.GetProperty().SetSpecular(0.3) a4Actor.GetProperty().SetSpecularPower(20) a4Actor.GetProperty().SetAmbient(0.2) a4Actor.GetProperty().SetDiffuse(0.8) # draw the DOP arrowT2 = vtk.vtkTransform() arrowT2.Scale(1,0.6,1) arrowT2.RotateY(90) arrowTF2 = vtk.vtkTransformPolyDataFilter() arrowTF2.SetInputData(pd2) arrowTF2.SetTransform(arrowT2) arrowREF = vtk.vtkRotationalExtrusionFilter() arrowREF.SetInputConnection(arrowTF2.GetOutputPort()) arrowREF.CappingOff() arrowREF.SetResolution(30) spikeMapper = vtk.vtkPolyDataMapper() spikeMapper.SetInputConnection(arrowREF.GetOutputPort()) a5Actor = vtk.vtkLODActor() a5Actor.SetMapper(spikeMapper) a5Actor.SetScale(.3,.3,.6) a5Actor.RotateY(90) a5Actor.SetPosition(-2,0,0) a5Actor.GetProperty().SetColor(1,0.3,1) a5Actor.GetProperty().SetAmbient(0.2) a5Actor.GetProperty().SetDiffuse(0.8) # focal point fps = vtk.vtkSphereSource()
def _CreatePointerData(self): # Create the VTK pipeline for the probe data. # we want the button properties to be shared between # actors that are produced for separate panes. self._HandleProperty = vtk.vtkProperty() self._HandleProperty.SetSpecularColor(1.0, 1.0, 1.0) self._HandleProperty.SetSpecular(20.0) self._HandleProperty.SetSpecularPower(20.0) self._HandleProperty.SetColor(0.2, 0.2, 0.2) self._Button1Property = vtk.vtkProperty() self._Button1Property.SetColor(0.3922, 0.5843, 0.9294) self._Button2Property = vtk.vtkProperty() self._Button2Property.SetColor(1.0, 1.0, 0.0) self._Button3Property = vtk.vtkProperty() self._Button3Property.SetColor(0.3922, 0.5843, 0.9294) # the shaft has the warning property, i.e. it goes red # when the probe is out-of-view self._WarningProperty.SetSpecularColor(1.0, 1.0, 1.0) self._WarningProperty.SetSpecular(0.9) self._WarningProperty.SetSpecularPower(200.0) self._WarningProperty.SetColor(0.9, 0.9, 0.9) self._TrajProperty = vtk.vtkProperty() self._TrajProperty.SetColor(1, 0, 0) # get on with the data # for handle: handlePoints = vtk.vtkPoints() handlePoints.InsertNextPoint(2.0, 0.0, -149.0) # handle x 'tube' handlePoints.InsertNextPoint(10.0, 0.0, -157.0) # start of handle handlePoints.InsertNextPoint(10.0, 0.0, -282.0) # butt diameter = 20 handlePoints.InsertNextPoint(3.0, 0.0, -287.0) # handle shaft handlePoints.InsertNextPoint(3.0, 0.0, -290.0) # cord plug handlePoints.InsertNextPoint(0.1, 0.0, -290.0) # tit at end of probe # for probe bend: bendPoints = vtk.vtkPoints() bendPoints.InsertNextPoint(0, 0.0, -149.0) # origin at handle bendPoints.InsertNextPoint(0, 0.0, -146.0) # first bend bendPoints.InsertNextPoint(0.0, -1.0, -145.0) bendPoints.InsertNextPoint(0.0, -2.0, -144.0) bendPoints.InsertNextPoint(0.0, -8.0, -144.0) # second bend bendPoints.InsertNextPoint(0.0, -9.0, -143.0) bendPoints.InsertNextPoint(0.0, -10.0, -142.0) bendPoints.InsertNextPoint(0.0, -9.0, -141.0) # just under bend # for probe shaft: shaftPoints = vtk.vtkPoints() shaftPoints.InsertNextPoint(1.96, 0.0, -142.0) # from bend shaftPoints.InsertNextPoint(0.8, 0.0, -2.0) shaftPoints.InsertNextPoint(0.1, 0.0, 0.0) # to tip # the handle########### handleLine = vtk.vtkCellArray() handleLine.InsertNextCell(6) # number.of.points handleLine.InsertCellPoint(0) handleLine.InsertCellPoint(1) handleLine.InsertCellPoint(2) handleLine.InsertCellPoint(3) handleLine.InsertCellPoint(4) handleLine.InsertCellPoint(5) handleProfile = vtk.vtkPolyData() handleProfile.SetPoints(handlePoints) handleProfile.SetLines(handleLine) self.__HandleExtrude = vtk.vtkRotationalExtrusionFilter() self.__HandleExtrude.SetInputData(handleProfile) self.__HandleExtrude.SetResolution(24) self.__HandleExtrude.Update() # the bend in the probe############ probeBend = vtk.vtkCellArray() probeBend.InsertNextCell(8) probeBend.InsertCellPoint(0) probeBend.InsertCellPoint(1) probeBend.InsertCellPoint(2) probeBend.InsertCellPoint(3) probeBend.InsertCellPoint(4) probeBend.InsertCellPoint(5) probeBend.InsertCellPoint(6) probeBend.InsertCellPoint(7) probeBendProfile = vtk.vtkPolyData() probeBendProfile.SetPoints(bendPoints) probeBendProfile.SetLines(probeBend) self.__ProbeBend = vtk.vtkTubeFilter() self.__ProbeBend.SetInput(probeBendProfile) self.__ProbeBend.SetNumberOfSides(24) self.__ProbeBend.SetRadius(2) self.__ProbeBend.Update() # the shaft of the probe************ probeShaft = vtk.vtkCellArray() probeShaft.InsertNextCell(3) probeShaft.InsertCellPoint(0) probeShaft.InsertCellPoint(1) probeShaft.InsertCellPoint(2) probeShaftProfile = vtk.vtkPolyData() probeShaftProfile.SetPoints(shaftPoints) probeShaftProfile.SetLines(probeShaft) self.__ProbeShaftExtrude = vtk.vtkRotationalExtrusionFilter() self.__ProbeShaftExtrude.SetInput(probeShaftProfile) self.__ProbeShaftExtrude.SetResolution(24) self.__ProbeShaftExtrude.Update() ### The Handle Logo ### self.logo = vtk.vtkVectorText() self.logo.SetText("Finnis Virtual Design") logotransform = vtk.vtkTransform() logotransform.PostMultiply() logotransform.Translate(-7, -0.5, 0.0) logotransform.RotateY(90) logotransform.RotateX(180) logotransform.Scale(2, 2, 2) logotransform.Translate(10.0, 0.0, -250) self.__Logo = vtk.vtkTransformPolyDataFilter() self.__Logo.SetInput(self.logo.GetOutput()) self.__Logo.SetTransform(logotransform) ### The Trajectory Line ### self.__TrajLine = vtk.vtkLineSource() self.__TrajLine.SetPoint1(0, 0, 0) self.__TrajLine.SetPoint2(0, self._Depth * 0.071, self._Depth) ### The Buttons ### self.__Button1 = vtk.vtkCubeSource() self.__Button1.SetXLength(2) self.__Button1.SetYLength(7) self.__Button1.SetZLength(10) self.__Button1.SetCenter(10, 0, -189.5) self.__Button2 = vtk.vtkCubeSource() self.__Button2.SetXLength(2) self.__Button2.SetYLength(7) self.__Button2.SetZLength(10) self.__Button2.SetCenter(10, 0, -204.5) self.__Button3 = vtk.vtkCubeSource() self.__Button3.SetXLength(2) self.__Button3.SetYLength(7) self.__Button3.SetZLength(10) self.__Button3.SetCenter(10, 0, -219.5) # correct for the orientation of the pointer transform = vtk.vtkTransform() transform.RotateX(270) transform.RotateZ(180) self.__HandleExtrudeRotate = vtk.vtkTransformPolyDataFilter() self.__HandleExtrudeRotate.SetInput(self.__HandleExtrude.GetOutput()) self.__HandleExtrudeRotate.SetTransform(transform) self.__ProbeBendRotate = vtk.vtkTransformPolyDataFilter() self.__ProbeBendRotate.SetInput(self.__ProbeBend.GetOutput()) self.__ProbeBendRotate.SetTransform(transform) self.__ProbeShaftExtrudeRotate = vtk.vtkTransformPolyDataFilter() self.__ProbeShaftExtrudeRotate.SetInput( self.__ProbeShaftExtrude.GetOutput()) self.__ProbeShaftExtrudeRotate.SetTransform(transform) self.__LogoRotate = vtk.vtkTransformPolyDataFilter() self.__LogoRotate.SetInput(self.__Logo.GetOutput()) self.__LogoRotate.SetTransform(transform) self.__Button1Rotate = vtk.vtkTransformPolyDataFilter() self.__Button1Rotate.SetInput(self.__Button1.GetOutput()) self.__Button1Rotate.SetTransform(transform) self.__Button2Rotate = vtk.vtkTransformPolyDataFilter() self.__Button2Rotate.SetInput(self.__Button2.GetOutput()) self.__Button2Rotate.SetTransform(transform) self.__Button3Rotate = vtk.vtkTransformPolyDataFilter() self.__Button3Rotate.SetInput(self.__Button3.GetOutput()) self.__Button3Rotate.SetTransform(transform) self.__TrajLineRotate = vtk.vtkTransformPolyDataFilter() self.__TrajLineRotate.SetInput(self.__TrajLine.GetOutput()) self.__TrajLineRotate.SetTransform(transform) self.__HandleData = self.__HandleExtrudeRotate.GetOutput() self.__ProbeBendData = self.__ProbeBendRotate.GetOutput() self.__ProbeShaftData = self.__ProbeShaftExtrudeRotate.GetOutput() self.__LogoData = self.__LogoRotate.GetOutput() self.__Button1Data = self.__Button1Rotate.GetOutput() self.__Button2Data = self.__Button2Rotate.GetOutput() self.__Button3Data = self.__Button3Rotate.GetOutput() self.__TrajLineData = self.__TrajLineRotate.GetOutput()
def main(): angle, step, radius, uncapped, show_line = get_program_parameters() angle = math.radians(abs(angle)) step = math.radians(abs(step)) radius = abs(radius) # With default settings set this to 45 and you get a bowl with a flat bottom. start = math.radians(90) pts = get_line(angle, step, radius, uncapped, start) # Setup points and lines points = vtk.vtkPoints() lines = vtk.vtkCellArray() for pt in pts: pt_id = points.InsertNextPoint(pt) if pt_id < len(pts) - 1: line = vtk.vtkLine() line.GetPointIds().SetId(0, pt_id) line.GetPointIds().SetId(1, pt_id + 1) lines.InsertNextCell(line) polydata = vtk.vtkPolyData() polydata.SetPoints(points) polydata.SetLines(lines) # Extrude the profile to make the capped sphere extrude = vtk.vtkRotationalExtrusionFilter() extrude.SetInputData(polydata) extrude.SetResolution(60) # Visualize colors = vtk.vtkNamedColors() # To see the line lineMapper = vtk.vtkPolyDataMapper() lineMapper.SetInputData(polydata) lineActor = vtk.vtkActor() lineActor.SetMapper(lineMapper) lineActor.GetProperty().SetLineWidth(4) lineActor.GetProperty().SetColor(colors.GetColor3d('Red')) # To see the surface surfaceMapper = vtk.vtkPolyDataMapper() surfaceMapper.SetInputConnection(extrude.GetOutputPort()) surfaceActor = vtk.vtkActor() surfaceActor.SetMapper(surfaceMapper) surfaceActor.GetProperty().SetColor(colors.GetColor3d('Khaki')) ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) ren.AddActor(surfaceActor) if show_line: ren.AddActor(lineActor) ren.SetBackground(colors.GetColor3d('LightSlateGray')) ren.ResetCamera() ren.GetActiveCamera().Azimuth(0) ren.GetActiveCamera().Elevation(60) ren.ResetCameraClippingRange() renWin.SetSize(600, 600) renWin.Render() renWin.SetWindowName('CappedSphere') iren.Start()