1#!/usr/bin/env python 2import vtk 3from vtk.util.misc import vtkGetDataRoot 4VTK_DATA_ROOT = vtkGetDataRoot() 5 6# Create the RenderWindow, Renderer and both Actors 7# 8ren1 = vtk.vtkRenderer() 9renWin = vtk.vtkRenderWindow() 10renWin.AddRenderer(ren1) 11iren = vtk.vtkRenderWindowInteractor() 12iren.SetRenderWindow(renWin) 13# create a camera model 14camCS = vtk.vtkConeSource() 15camCS.SetHeight(1.5) 16camCS.SetResolution(12) 17camCS.SetRadius(0.4) 18camCBS = vtk.vtkCubeSource() 19camCBS.SetXLength(1.5) 20camCBS.SetZLength(0.8) 21camCBS.SetCenter(0.4,0,0) 22camAPD = vtk.vtkAppendFilter() 23camAPD.AddInputConnection(camCS.GetOutputPort()) 24camAPD.AddInputConnection(camCBS.GetOutputPort()) 25camMapper = vtk.vtkDataSetMapper() 26camMapper.SetInputConnection(camAPD.GetOutputPort()) 27camActor = vtk.vtkLODActor() 28camActor.SetMapper(camMapper) 29camActor.SetScale(2,2,2) 30# draw the arrows 31pd = vtk.vtkPolyData() 32ca = vtk.vtkCellArray() 33fp = vtk.vtkPoints() 34fp.InsertNextPoint(0,1,0) 35fp.InsertNextPoint(8,1,0) 36fp.InsertNextPoint(8,2,0) 37fp.InsertNextPoint(10,0.01,0) 38fp.InsertNextPoint(8,-2,0) 39fp.InsertNextPoint(8,-1,0) 40fp.InsertNextPoint(0,-1,0) 41ca.InsertNextCell(7) 42ca.InsertCellPoint(0) 43ca.InsertCellPoint(1) 44ca.InsertCellPoint(2) 45ca.InsertCellPoint(3) 46ca.InsertCellPoint(4) 47ca.InsertCellPoint(5) 48ca.InsertCellPoint(6) 49pd.SetPoints(fp) 50pd.SetPolys(ca) 51pd2 = vtk.vtkPolyData() 52ca2 = vtk.vtkCellArray() 53fp2 = vtk.vtkPoints() 54fp2.InsertNextPoint(0,1,0) 55fp2.InsertNextPoint(8,1,0) 56fp2.InsertNextPoint(8,2,0) 57fp2.InsertNextPoint(10,0.01,0) 58#prevents degenerate triangles 59ca2.InsertNextCell(4) 60ca2.InsertCellPoint(0) 61ca2.InsertCellPoint(1) 62ca2.InsertCellPoint(2) 63ca2.InsertCellPoint(3) 64pd2.SetPoints(fp2) 65pd2.SetLines(ca2) 66arrowIM = vtk.vtkImplicitModeller() 67arrowIM.SetInputData(pd) 68arrowIM.SetSampleDimensions(50,20,8) 69arrowCF = vtk.vtkContourFilter() 70arrowCF.SetInputConnection(arrowIM.GetOutputPort()) 71arrowCF.SetValue(0,0.2) 72arrowWT = vtk.vtkWarpTo() 73arrowWT.SetInputConnection(arrowCF.GetOutputPort()) 74arrowWT.SetPosition(5,0,5) 75arrowWT.SetScaleFactor(0.85) 76arrowWT.AbsoluteOn() 77arrowT = vtk.vtkTransform() 78arrowT.RotateY(60) 79arrowT.Translate(-1.33198,0,-1.479) 80arrowT.Scale(1,0.5,1) 81arrowTF = vtk.vtkTransformFilter() 82arrowTF.SetInputConnection(arrowWT.GetOutputPort()) 83arrowTF.SetTransform(arrowT) 84arrowMapper = vtk.vtkDataSetMapper() 85arrowMapper.SetInputConnection(arrowTF.GetOutputPort()) 86arrowMapper.ScalarVisibilityOff() 87# draw the azimuth arrows 88a1Actor = vtk.vtkLODActor() 89a1Actor.SetMapper(arrowMapper) 90a1Actor.RotateZ(180) 91a1Actor.SetPosition(1,0,-1) 92a1Actor.GetProperty().SetColor(1,0.3,0.3) 93a1Actor.GetProperty().SetSpecularColor(1,1,1) 94a1Actor.GetProperty().SetSpecular(0.3) 95a1Actor.GetProperty().SetSpecularPower(20) 96a1Actor.GetProperty().SetAmbient(0.2) 97a1Actor.GetProperty().SetDiffuse(0.8) 98a2Actor = vtk.vtkLODActor() 99a2Actor.SetMapper(arrowMapper) 100a2Actor.RotateZ(180) 101a2Actor.RotateX(180) 102a2Actor.SetPosition(1,0,1) 103a2Actor.GetProperty().SetColor(1,0.3,0.3) 104a2Actor.GetProperty().SetSpecularColor(1,1,1) 105a2Actor.GetProperty().SetSpecular(0.3) 106a2Actor.GetProperty().SetSpecularPower(20) 107a2Actor.GetProperty().SetAmbient(0.2) 108a2Actor.GetProperty().SetDiffuse(0.8) 109# draw the elevation arrows 110a3Actor = vtk.vtkLODActor() 111a3Actor.SetMapper(arrowMapper) 112a3Actor.RotateZ(180) 113a3Actor.RotateX(90) 114a3Actor.SetPosition(1,-1,0) 115a3Actor.GetProperty().SetColor(0.3,1,0.3) 116a3Actor.GetProperty().SetSpecularColor(1,1,1) 117a3Actor.GetProperty().SetSpecular(0.3) 118a3Actor.GetProperty().SetSpecularPower(20) 119a3Actor.GetProperty().SetAmbient(0.2) 120a3Actor.GetProperty().SetDiffuse(0.8) 121a4Actor = vtk.vtkLODActor() 122a4Actor.SetMapper(arrowMapper) 123a4Actor.RotateZ(180) 124a4Actor.RotateX(-90) 125a4Actor.SetPosition(1,1,0) 126a4Actor.GetProperty().SetColor(0.3,1,0.3) 127a4Actor.GetProperty().SetSpecularColor(1,1,1) 128a4Actor.GetProperty().SetSpecular(0.3) 129a4Actor.GetProperty().SetSpecularPower(20) 130a4Actor.GetProperty().SetAmbient(0.2) 131a4Actor.GetProperty().SetDiffuse(0.8) 132# draw the DOP 133arrowT2 = vtk.vtkTransform() 134arrowT2.Scale(1,0.6,1) 135arrowT2.RotateY(90) 136arrowTF2 = vtk.vtkTransformPolyDataFilter() 137arrowTF2.SetInputData(pd2) 138arrowTF2.SetTransform(arrowT2) 139arrowREF = vtk.vtkRotationalExtrusionFilter() 140arrowREF.SetInputConnection(arrowTF2.GetOutputPort()) 141arrowREF.CappingOff() 142arrowREF.SetResolution(30) 143spikeMapper = vtk.vtkPolyDataMapper() 144spikeMapper.SetInputConnection(arrowREF.GetOutputPort()) 145a5Actor = vtk.vtkLODActor() 146a5Actor.SetMapper(spikeMapper) 147a5Actor.SetScale(.3,.3,.6) 148a5Actor.RotateY(90) 149a5Actor.SetPosition(-2,0,0) 150a5Actor.GetProperty().SetColor(1,0.3,1) 151a5Actor.GetProperty().SetAmbient(0.2) 152a5Actor.GetProperty().SetDiffuse(0.8) 153# focal point 154fps = vtk.vtkSphereSource() 155fps.SetRadius(0.5) 156fpMapper = vtk.vtkPolyDataMapper() 157fpMapper.SetInputConnection(fps.GetOutputPort()) 158fpActor = vtk.vtkLODActor() 159fpActor.SetMapper(fpMapper) 160fpActor.SetPosition(-9,0,0) 161fpActor.GetProperty().SetSpecularColor(1,1,1) 162fpActor.GetProperty().SetSpecular(0.3) 163fpActor.GetProperty().SetAmbient(0.2) 164fpActor.GetProperty().SetDiffuse(0.8) 165fpActor.GetProperty().SetSpecularPower(20) 166# create the roll arrows 167arrowWT2 = vtk.vtkWarpTo() 168arrowWT2.SetInputConnection(arrowCF.GetOutputPort()) 169arrowWT2.SetPosition(5,0,2.5) 170arrowWT2.SetScaleFactor(0.95) 171arrowWT2.AbsoluteOn() 172arrowT3 = vtk.vtkTransform() 173arrowT3.Translate(-2.50358,0,-1.70408) 174arrowT3.Scale(0.5,0.3,1) 175arrowTF3 = vtk.vtkTransformFilter() 176arrowTF3.SetInputConnection(arrowWT2.GetOutputPort()) 177arrowTF3.SetTransform(arrowT3) 178arrowMapper2 = vtk.vtkDataSetMapper() 179arrowMapper2.SetInputConnection(arrowTF3.GetOutputPort()) 180arrowMapper2.ScalarVisibilityOff() 181# draw the roll arrows 182a6Actor = vtk.vtkLODActor() 183a6Actor.SetMapper(arrowMapper2) 184a6Actor.RotateZ(90) 185a6Actor.SetPosition(-4,0,0) 186a6Actor.SetScale(1.5,1.5,1.5) 187a6Actor.GetProperty().SetColor(1,1,0.3) 188a6Actor.GetProperty().SetSpecularColor(1,1,1) 189a6Actor.GetProperty().SetSpecular(0.3) 190a6Actor.GetProperty().SetSpecularPower(20) 191a6Actor.GetProperty().SetAmbient(0.2) 192a6Actor.GetProperty().SetDiffuse(0.8) 193# Add the actors to the renderer, set the background and size 194ren1.AddActor(camActor) 195ren1.AddActor(a1Actor) 196ren1.AddActor(a2Actor) 197ren1.AddActor(a3Actor) 198ren1.AddActor(a4Actor) 199ren1.AddActor(a5Actor) 200ren1.AddActor(a6Actor) 201ren1.AddActor(fpActor) 202ren1.SetBackground(0.1,0.2,0.4) 203renWin.SetSize(300,300) 204# render the image 205ren1.ResetCamera() 206cam1 = ren1.GetActiveCamera() 207cam1.Zoom(1.5) 208cam1.Azimuth(150) 209cam1.Elevation(30) 210iren.Initialize() 211# prevent the tk window from showing up then start the event loop 212# for testing 213threshold = 15 214# --- end of script -- 215