def testThreshold(self): global args writefiles = "SaveData" in args renderer = vtk.vtkRenderer() renwin = vtk.vtkRenderWindow() renwin.AddRenderer(renderer) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renwin) renwin.Render() if "GPURender" in args: vtk.vtkPistonMapper.InitCUDAGL(renwin) src = vtk.vtkImageMandelbrotSource() src.SetWholeExtent(0,10,0,10,0,10) #scale and bias until piston's threshold understands origin and spacing src.Update() inputdata = src.GetOutput() if "Normalize" in args: testdata1 = inputdata.NewInstance() testdata1.ShallowCopy(inputdata) testdata1.SetSpacing(1,1,1) testdata1.SetOrigin(0,0,0) inputdata = testdata1 d2p = vtk.vtkDataSetToPiston() d2p.SetInputData(inputdata) #d2p.SetInputConnection(src.GetOutputPort()) threshF = vtk.vtkPistonThreshold() threshF.SetInputConnection(d2p.GetOutputPort()) threshF.SetMinValue(0) threshF.SetMaxValue(80) p2d = vtk.vtkPistonToDataSet() p2d.SetInputConnection(threshF.GetOutputPort()) p2d.SetOutputDataSetType(vtk.VTK_POLY_DATA) if writefiles: writeFile(p2d, "piston_threshold.vtk") mapper = vtk.vtkPistonMapper() mapper.SetInputConnection(threshF.GetOutputPort()) mapper.Update() actor = vtk.vtkActor() actor.SetMapper(mapper) renderer.AddActor(actor) renderer.ResetCamera() renwin.Render() img_file = "TestThreshold.png" Testing.compareImage(renwin, Testing.getAbsImagePath(img_file)) if Testing.isInteractive(): iren.Start()
def testvtkTkRenderWidget(self): "Test if vtkTkRenderWidget works." self.rw.Render() self.root.update() img_file = "TestTkRenderWidget.png" Testing.compareImage(self.rw, Testing.getAbsImagePath(img_file)) Testing.interact()
def testBoundaryExtraction(self): ugg = vtkUnstructuredGridGeometryFilter() ugg.SetInputConnection(self.rdr.GetOutputPort()) ugg.Update() a1, m1 = self.addToScene(ugg) clr = vtkColorSeries() lkup = vtkLookupTable() # Color the contours with a qualitative color scheme: clr.SetColorScheme(vtkColorSeries.BREWER_QUALITATIVE_DARK2) clr.BuildLookupTable(lkup, vtkColorSeries.CATEGORICAL) lkup.SetAnnotation(vtkVariant(0), 'Cell Low') lkup.SetAnnotation(vtkVariant(1), 'Somewhat Low') lkup.SetAnnotation(vtkVariant(2), 'Medium') lkup.SetAnnotation(vtkVariant(3), 'High') m1.SetScalarModeToUseCellFieldData() m1.SelectColorArray('SrcCellNum') m1.SetLookupTable(lkup) self.ri.Initialize() cam = self.rr.GetActiveCamera() cam.SetPosition(16.429826228, -5.64575247779, 12.7186363446) cam.SetFocalPoint(4.12105459591, 1.95201869763, 1.69574200166) cam.SetViewUp(-0.503606926552, 0.337767269532, 0.795168746344) # wri = vtkXMLUnstructuredGridWriter() # wri.SetInputConnection(ugg.GetOutputPort()) # wri.SetDataModeToAscii() # wri.SetFileName('/tmp/surface.vtu') # wri.Write() self.rw.Render() image = 'LagrangeGeometricOperations-Boundary.png' #events = self.prepareTestImage(self.ri, filename=os.path.join('/tmp', image)) Testing.compareImage(self.rw, self.pathToValidatedOutput(image))
def testThreshold(self): global args writefiles = "SaveData" in args renderer = vtk.vtkRenderer() renwin = vtk.vtkRenderWindow() renwin.AddRenderer(renderer) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renwin) renwin.Render() if "GPURender" in args: vtk.vtkPistonMapper.InitCUDAGL(renwin) src = vtk.vtkImageMandelbrotSource() src.SetWholeExtent(0, 10, 0, 10, 0, 10) #scale and bias until piston's threshold understands origin and spacing src.Update() inputdata = src.GetOutput() if "Normalize" in args: testdata1 = inputdata.NewInstance() testdata1.ShallowCopy(inputdata) testdata1.SetSpacing(1, 1, 1) testdata1.SetOrigin(0, 0, 0) inputdata = testdata1 d2p = vtk.vtkDataSetToPiston() d2p.SetInputData(inputdata) #d2p.SetInputConnection(src.GetOutputPort()) threshF = vtk.vtkPistonThreshold() threshF.SetInputConnection(d2p.GetOutputPort()) threshF.SetMinValue(0) threshF.SetMaxValue(80) p2d = vtk.vtkPistonToDataSet() p2d.SetInputConnection(threshF.GetOutputPort()) p2d.SetOutputDataSetType(vtk.VTK_POLY_DATA) if writefiles: writeFile(p2d, "piston_threshold.vtk") mapper = vtk.vtkPistonMapper() mapper.SetInputConnection(threshF.GetOutputPort()) mapper.Update() actor = vtk.vtkActor() actor.SetMapper(mapper) renderer.AddActor(actor) renderer.ResetCamera() renwin.Render() img_file = "TestThreshold.png" Testing.compareImage(renwin, Testing.getAbsImagePath(img_file)) if Testing.isInteractive(): iren.Start()
def testBoundaryExtraction(self): ugg = vtkUnstructuredGridGeometryFilter() ugg.SetInputConnection(self.rdr.GetOutputPort()) ugg.Update() a1, m1 = self.addToScene(ugg) clr = vtkColorSeries() lkup = vtkLookupTable() # Color the contours with a qualitative color scheme: clr.SetColorScheme(vtkColorSeries.BREWER_QUALITATIVE_DARK2) clr.BuildLookupTable(lkup, vtkColorSeries.CATEGORICAL); lkup.SetAnnotation(vtkVariant(0), 'Cell Low') lkup.SetAnnotation(vtkVariant(1), 'Somewhat Low') lkup.SetAnnotation(vtkVariant(2), 'Medium') lkup.SetAnnotation(vtkVariant(3), 'High') m1.SetScalarModeToUseCellFieldData() m1.SelectColorArray('SrcCellNum') m1.SetLookupTable(lkup) self.ri.Initialize() cam = self.rr.GetActiveCamera() cam.SetPosition(16.429826228, -5.64575247779, 12.7186363446) cam.SetFocalPoint(4.12105459591, 1.95201869763, 1.69574200166) cam.SetViewUp(-0.503606926552, 0.337767269532, 0.795168746344) # wri = vtkXMLUnstructuredGridWriter() # wri.SetInputConnection(ugg.GetOutputPort()) # wri.SetDataModeToAscii() # wri.SetFileName('/tmp/surface.vtu') # wri.Write() self.rw.Render() image = 'LagrangeGeometricOperations-Boundary.png' #events = self.prepareTestImage(self.ri, filename=os.path.join('/tmp', image)) Testing.compareImage(self.rw, self.pathToValidatedOutput(image))
def testvtkTkRenderWindowInteractor(self): "Test if vtkTkRenderWindowInteractor works." self.tkrw.Start() self.tkrw.Render() self.root.update() img_file = "TestTkRenderWindowInteractor.png" Testing.compareImage(self.rw, Testing.getAbsImagePath(img_file)) Testing.interact()
def testGlyphs(self): '''Test if the glyphs are created nicely.''' reader = vtk.vtkDataSetReader() data_file = os.path.join(Testing.VTK_DATA_ROOT, "Data", "tensors.vtk") reader.SetFileName(data_file) g1 = SimpleGlyph(reader) g1.glyph.ColorGlyphsOff() g1.Update() g2 = SimpleGlyph(reader) g2.glyph.ExtractEigenvaluesOff() g2.Update() g2.SetPosition((2.0, 0.0, 0.0)) g3 = SimpleGlyph(reader) g3.glyph.SetColorModeToEigenvalues() g3.glyph.ThreeGlyphsOn() g3.Update() g3.SetPosition((0.0, 2.0, 0.0)) g4 = SimpleGlyph(reader) g4.glyph.SetColorModeToEigenvalues() g4.glyph.ThreeGlyphsOn() g4.glyph.SymmetricOn() g4.Update() g4.SetPosition((2.0, 2.0, 0.0)) # 6Components symetric tensor g5 = SimpleGlyph(reader) g5.glyph.SetInputArrayToProcess(0, 0, 0, 0, "symTensors1") g5.SetPosition((4.0, 2.0, 0.0)) g5.Update() ren = vtk.vtkRenderer() for i in (g1, g2, g3, g4, g5): for j in i.GetActors(): ren.AddActor(j) ren.ResetCamera(); cam = ren.GetActiveCamera() cam.Azimuth(-20) cam.Elevation(20) cam.Zoom(1.1) ren.SetBackground(0.5, 0.5, 0.5) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) renWin.Render() img_file = "TestTensorGlyph.png" Testing.compareImage(renWin, Testing.getAbsImagePath(img_file)) Testing.interact()
def testGlyphs(self): '''Test if the glyphs are created nicely.''' reader = vtk.vtkDataSetReader() data_file = os.path.join(Testing.VTK_DATA_ROOT, "Data", "tensors.vtk") reader.SetFileName(data_file) g1 = SimpleGlyph(reader) g1.glyph.ColorGlyphsOff() g1.Update() g2 = SimpleGlyph(reader) g2.glyph.ExtractEigenvaluesOff() g2.Update() g2.SetPosition((2.0, 0.0, 0.0)) g3 = SimpleGlyph(reader) g3.glyph.SetColorModeToEigenvalues() g3.glyph.ThreeGlyphsOn() g3.Update() g3.SetPosition((0.0, 2.0, 0.0)) g4 = SimpleGlyph(reader) g4.glyph.SetColorModeToEigenvalues() g4.glyph.ThreeGlyphsOn() g4.glyph.SymmetricOn() g4.Update() g4.SetPosition((2.0, 2.0, 0.0)) # 6Components symetric tensor g5 = SimpleGlyph(reader) g5.glyph.SetInputArrayToProcess(0, 0, 0, 0, "symTensors1") g5.SetPosition((4.0, 2.0, 0.0)) g5.Update() ren = vtk.vtkRenderer() for i in (g1, g2, g3, g4, g5): for j in i.GetActors(): ren.AddActor(j) ren.ResetCamera() cam = ren.GetActiveCamera() cam.Azimuth(-20) cam.Elevation(20) cam.Zoom(1.1) ren.SetBackground(0.5, 0.5, 0.5) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) renWin.Render() img_file = "TestTensorGlyph.png" Testing.compareImage(renWin, Testing.getAbsImagePath(img_file)) Testing.interact()
def DoIt(self): self.SetUp() self.viewer.Render() self.tkrw.Render() self.root.update() # If you want to interact and use the sliders etc, # uncomment the following line. #self.root.mainloop() img_file = "cursor3D.png" Testing.compareImage(self.viewer.GetRenderWindow(), Testing.getAbsImagePath(img_file))
def DoIt(self): self.SetUp() self.viewer.Render() self.tkrw.Render() self.root.update() # If you want to interact and use the sliders etc, # uncomment the following line. # self.root.mainloop() img_file = "cursor3D.png" Testing.compareImage(self.viewer.GetRenderWindow(), Testing.getAbsImagePath(img_file))
def DoIt(self): self.SetUp() self.renWin.Render() self.tkrw.Render() self.root.update() # If you want to interact and use the sliders etc, # uncomment the following line. #self.root.mainloop() img_file = "squadViewer.png" Testing.compareImage(self.renWin, Testing.getAbsImagePath(img_file)) Testing.interact()
def DoIt(self): self.SetUp() self.renWin.Render() self.tkrw.Render() self.root.update() # If you want to interact and use the sliders etc, # uncomment the following line. #self.root.mainloop() img_file = "TestTextActor3D.png" Testing.compareImage(self.renWin, Testing.getAbsImagePath(img_file)) Testing.interact()
def testContour(self): ## Contour actor con = vtkContourFilter() con.SetInputConnection(self.rdr.GetOutputPort()) con.SetInputArrayToProcess( 0, 0, 0, vtkDataSet.FIELD_ASSOCIATION_POINTS_THEN_CELLS, 'Ellipsoid') con.SetComputeNormals(1) con.SetComputeScalars(1) con.SetComputeGradients(1) con.SetNumberOfContours(4) con.SetValue(0, 2.5) con.SetValue(1, 1.5) con.SetValue(2, 0.5) con.SetValue(3, 1.05) con.Update() # Add the contour to the scene: a1, m1 = self.addToScene(con) clr = vtkColorSeries() lkup = vtkLookupTable() # Color the contours with a qualitative color scheme: clr.SetColorScheme(vtkColorSeries.BREWER_QUALITATIVE_DARK2) clr.BuildLookupTable(lkup, vtkColorSeries.CATEGORICAL) lkup.SetAnnotation(vtkVariant(0.5), 'Really Low') lkup.SetAnnotation(vtkVariant(1.05), 'Somewhat Low') lkup.SetAnnotation(vtkVariant(1.5), 'Medium') lkup.SetAnnotation(vtkVariant(2.5), 'High') m1.SelectColorArray('Ellipsoid') m1.SetLookupTable(lkup) a2, m2 = self.addSurfaceToScene() self.ri.Initialize() cam = self.rr.GetActiveCamera() cam.SetPosition(12.9377265875, 6.5914481094, 7.54647854482) cam.SetFocalPoint(4.38052401617, 0.925973308028, 1.91021697659) cam.SetViewUp(-0.491867406412, -0.115590747077, 0.862963054655) ## Other nice viewpoints: # cam.SetPosition(-1.53194314907, -6.07277748432, 19.283152654) # cam.SetFocalPoint(4.0, 2.25, 2.25) # cam.SetViewUp(0.605781341771, 0.619386648223, 0.499388772365) # # cam.SetPosition(10.5925480421, -3.08988382244, 9.2072891403) # cam.SetFocalPoint(4.0, 2.25, 2.25) # cam.SetViewUp(-0.384040517561, 0.519961374525, 0.762989547683) self.rw.Render() image = 'LagrangeGeometricOperations-Contour.png' # events = self.prepareTestImage(self.ri, filename=os.path.join('/tmp', image)) Testing.compareImage(self.rw, self.pathToValidatedOutput(image))
def testContour(self): ## Contour actor con = vtkContourFilter() con.SetInputConnection(self.rdr.GetOutputPort()) con.SetInputArrayToProcess(0,0,0, vtkDataSet.FIELD_ASSOCIATION_POINTS_THEN_CELLS, 'Ellipsoid') con.SetComputeNormals(1) con.SetComputeScalars(1) con.SetComputeGradients(1) con.SetNumberOfContours(4) con.SetValue(0, 2.5) con.SetValue(1, 1.5) con.SetValue(2, 0.5) con.SetValue(3, 1.05) con.Update() # Add the contour to the scene: a1, m1 = self.addToScene(con) clr = vtkColorSeries() lkup = vtkLookupTable() # Color the contours with a qualitative color scheme: clr.SetColorScheme(vtkColorSeries.BREWER_QUALITATIVE_DARK2) clr.BuildLookupTable(lkup, vtkColorSeries.CATEGORICAL); lkup.SetAnnotation(vtkVariant(0.5), 'Really Low') lkup.SetAnnotation(vtkVariant(1.05), 'Somewhat Low') lkup.SetAnnotation(vtkVariant(1.5), 'Medium') lkup.SetAnnotation(vtkVariant(2.5), 'High') m1.SelectColorArray('Ellipsoid') m1.SetLookupTable(lkup) a2, m2 = self.addSurfaceToScene() self.ri.Initialize() cam = self.rr.GetActiveCamera() cam.SetPosition(12.9377265875, 6.5914481094, 7.54647854482) cam.SetFocalPoint(4.38052401617, 0.925973308028, 1.91021697659) cam.SetViewUp(-0.491867406412, -0.115590747077, 0.862963054655) ## Other nice viewpoints: # cam.SetPosition(-1.53194314907, -6.07277748432, 19.283152654) # cam.SetFocalPoint(4.0, 2.25, 2.25) # cam.SetViewUp(0.605781341771, 0.619386648223, 0.499388772365) # # cam.SetPosition(10.5925480421, -3.08988382244, 9.2072891403) # cam.SetFocalPoint(4.0, 2.25, 2.25) # cam.SetViewUp(-0.384040517561, 0.519961374525, 0.762989547683) self.rw.Render() image = 'LagrangeGeometricOperations-Contour.png' # events = self.prepareTestImage(self.ri, filename=os.path.join('/tmp', image)) Testing.compareImage(self.rw, self.pathToValidatedOutput(image))
def testClip(self): # Color the cells with a qualitative color scheme: clr = vtkColorSeries() lkup = vtkLookupTable() clr.SetColorScheme(vtkColorSeries.BREWER_QUALITATIVE_DARK2) clr.BuildLookupTable(lkup, vtkColorSeries.CATEGORICAL) lkup.SetAnnotation(vtkVariant(0), 'First cell') lkup.SetAnnotation(vtkVariant(1), 'Second cell') ## Clip pln = vtkPlane() pln.SetOrigin(4, 2, 2) pln.SetNormal(-0.28735, -0.67728, 0.67728) clp = vtkClipDataSet() clp.SetInputConnection(self.rdr.GetOutputPort()) clp.SetClipFunction(pln) # clp.InsideOutOn() # clp.GenerateClipScalarsOn() clp.Update() # wri = vtkXMLUnstructuredGridWriter() # wri.SetFileName('/tmp/clip.vtu') # wri.SetInputDataObject(0, clp.GetOutputDataObject(0)) # wri.SetDataModeToAscii() # wri.Write() # Add the clipped data to the scene: a1, m1 = self.addToScene(clp) m1.SetScalarModeToUseCellFieldData() m1.SelectColorArray('SrcCellNum') m1.SetLookupTable(lkup) ## Surface actor a2, m2 = self.addSurfaceToScene() m2.SetScalarModeToUseCellFieldData() m2.SelectColorArray('SrcCellNum') m2.SetLookupTable(lkup) self.ri.Initialize() cam = self.rr.GetActiveCamera() cam.SetPosition(16.0784261776, 11.8079343039, -6.69074553411) cam.SetFocalPoint(4.54685488135, 1.74152986486, 2.38091647662) cam.SetViewUp(-0.523934540522, 0.81705750638, 0.240644194852) self.rw.Render() image = 'LagrangeGeometricOperations-Clip.png' # events = self.prepareTestImage(self.ri, filename=os.path.join('/tmp', image)) Testing.compareImage(self.rw, self.pathToValidatedOutput(image))
def testClip(self): # Color the cells with a qualitative color scheme: clr = vtkColorSeries() lkup = vtkLookupTable() clr.SetColorScheme(vtkColorSeries.BREWER_QUALITATIVE_DARK2) clr.BuildLookupTable(lkup, vtkColorSeries.CATEGORICAL); lkup.SetAnnotation(vtkVariant(0), 'First cell') lkup.SetAnnotation(vtkVariant(1), 'Second cell') ## Clip pln = vtkPlane() pln.SetOrigin(4, 2, 2) pln.SetNormal(-0.28735, -0.67728, 0.67728) clp = vtkClipDataSet() clp.SetInputConnection(self.rdr.GetOutputPort()) clp.SetClipFunction(pln) # clp.InsideOutOn() # clp.GenerateClipScalarsOn() clp.Update() # wri = vtkXMLUnstructuredGridWriter() # wri.SetFileName('/tmp/clip.vtu') # wri.SetInputDataObject(0, clp.GetOutputDataObject(0)) # wri.SetDataModeToAscii() # wri.Write() # Add the clipped data to the scene: a1, m1 = self.addToScene(clp) m1.SetScalarModeToUseCellFieldData() m1.SelectColorArray('SrcCellNum') m1.SetLookupTable(lkup) ## Surface actor a2, m2 = self.addSurfaceToScene() m2.SetScalarModeToUseCellFieldData() m2.SelectColorArray('SrcCellNum') m2.SetLookupTable(lkup) self.ri.Initialize() cam = self.rr.GetActiveCamera() cam.SetPosition(16.0784261776, 11.8079343039, -6.69074553411) cam.SetFocalPoint(4.54685488135, 1.74152986486, 2.38091647662) cam.SetViewUp(-0.523934540522, 0.81705750638, 0.240644194852) self.rw.Render() image = 'LagrangeGeometricOperations-Clip.png' # events = self.prepareTestImage(self.ri, filename=os.path.join('/tmp', image)) Testing.compareImage(self.rw, self.pathToValidatedOutput(image))
def testRendering(self): global args renderer = vtk.vtkRenderer() renwin = vtk.vtkRenderWindow() renwin.AddRenderer(renderer) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renwin) renwin.Render() if "GPURender" in args: print "Testing GPU direct render path" vtk.vtkPistonMapper.InitCudaGL(renwin) else: print "Testing CPU indirect render path" src = vtk.vtkSphereSource() d2p = vtk.vtkDataSetToPiston() d2p.SetInputConnection(src.GetOutputPort()) mapper = vtk.vtkPistonMapper() mapper.SetInputConnection(d2p.GetOutputPort()) mapper.Update() #TODO: shouldn't need this actor = vtk.vtkActor() actor.SetMapper(mapper) renderer.AddActor(actor) renderer.ResetCamera() renwin.Render() img_file = "TestRendering.png" Testing.compareImage(renwin, Testing.getAbsImagePath(img_file)) if Testing.isInteractive(): iren.Start()
def testRendering(self): global args renderer = vtk.vtkRenderer() renwin = vtk.vtkRenderWindow() renwin.AddRenderer(renderer) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renwin) renwin.Render() if "GPURender" in args: print "Testing GPU direct render path" vtk.vtkPistonMapper.InitCUDAGL(renwin) else: print "Testing CPU indirect render path" src = vtk.vtkSphereSource() d2p = vtk.vtkDataSetToPiston() d2p.SetInputConnection(src.GetOutputPort()) mapper = vtk.vtkPistonMapper() mapper.SetInputConnection(d2p.GetOutputPort()) mapper.Update() #TODO: shouldn't need this actor = vtk.vtkActor() actor.SetMapper(mapper) renderer.AddActor(actor) renderer.ResetCamera() renwin.Render() img_file = "TestRendering.png" Testing.compareImage(renwin, Testing.getAbsImagePath(img_file)) if Testing.isInteractive(): iren.Start()
def testGlyphs(self): """Test if texturing of the glyphs works correctly.""" # The Glyph cs = vtk.vtkCubeSource() cs.SetXLength(2.0) cs.SetYLength(1.0) cs.SetZLength(0.5) # Create input point data. pts = vtk.vtkPoints() pts.InsertPoint(0, (1, 1, 1)) pts.InsertPoint(1, (0, 0, 0)) pts.InsertPoint(2, (-1, -1, -1)) polys = vtk.vtkCellArray() polys.InsertNextCell(1) polys.InsertCellPoint(0) polys.InsertNextCell(1) polys.InsertCellPoint(1) polys.InsertNextCell(1) polys.InsertCellPoint(2) pd = vtk.vtkPolyData() pd.SetPoints(pts) pd.SetPolys(polys) # Orient the glyphs as per vectors. vec = vtk.vtkFloatArray() vec.SetNumberOfComponents(3) vec.InsertTuple3(0, 1, 0, 0) vec.InsertTuple3(1, 0, 1, 0) vec.InsertTuple3(2, 0, 0, 1) pd.GetPointData().SetVectors(vec) # The glyph filter. g = vtk.vtkGlyph3D() g.SetScaleModeToDataScalingOff() g.SetVectorModeToUseVector() g.SetInput(pd) g.SetSource(cs.GetOutput()) m = vtk.vtkPolyDataMapper() m.SetInputConnection(g.GetOutputPort()) a = vtk.vtkActor() a.SetMapper(m) # The texture. img_file = os.path.join(Testing.VTK_DATA_ROOT, "Data", "masonry.bmp") img_r = vtk.vtkBMPReader() img_r.SetFileName(img_file) t = vtk.vtkTexture() t.SetInputConnection(img_r.GetOutputPort()) t.InterpolateOn() a.SetTexture(t) # Renderer, RenderWindow etc. ren = vtk.vtkRenderer() ren.SetBackground(0.5, 0.5, 0.5) ren.AddActor(a) ren.ResetCamera() cam = ren.GetActiveCamera() cam.Azimuth(-90) cam.Zoom(1.4) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) rwi = vtk.vtkRenderWindowInteractor() rwi.SetRenderWindow(renWin) rwi.Initialize() rwi.Render() # Compare the images and test. img_file = "TestTextureGlyph.png" Testing.compareImage(renWin, Testing.getAbsImagePath(img_file)) # Interact if necessary. if Testing.isInteractive(): rwi.Start()
def testBug(self): # Uncomment the next line if you want to run this via # `gdb python`. #raw_input('Hit Ctrl-C') # Load some data. v16 = vtk.vtkVolume16Reader() v16.SetDataDimensions(64, 64) v16.SetDataByteOrderToLittleEndian() v16.SetFilePrefix(os.path.join(Testing.VTK_DATA_ROOT, "Data", "headsq", "quarter")) v16.SetImageRange(1, 93) v16.SetDataSpacing(3.2, 3.2, 1.5) v16.Update() xMin, xMax, yMin, yMax, zMin, zMax = v16.GetOutput().GetWholeExtent() img_data = v16.GetOutput() # ************************************************** # Look here for wierdness. # Lets create this data using the data from the reader. my_img_data = vtk.vtkImageData() my_img_data.SetDimensions(img_data.GetDimensions()) my_img_data.SetWholeExtent(img_data.GetWholeExtent()) my_img_data.SetExtent(img_data.GetExtent()) my_img_data.SetUpdateExtent(img_data.GetUpdateExtent()) my_img_data.SetSpacing(img_data.GetSpacing()) my_img_data.SetOrigin(img_data.GetOrigin()) my_img_data.SetScalarType(img_data.GetScalarType()) my_img_data.GetPointData().SetScalars(img_data.GetPointData().GetScalars()) my_img_data.Update() # hang on to original image data. orig_img_data = img_data # hijack img_data with our own. If you comment this out everything is # fine. img_data = my_img_data # ************************************************** spacing = img_data.GetSpacing() sx, sy, sz = spacing origin = img_data.GetOrigin() ox, oy, oz = origin # An outline is shown for context. outline = vtk.vtkOutlineFilter() outline.SetInput(img_data) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) # The shared picker enables us to use 3 planes at one time # and gets the picking order right picker = vtk.vtkCellPicker() picker.SetTolerance(0.005) # The 3 image plane widgets are used to probe the dataset. planeWidgetX = vtk.vtkImagePlaneWidget() planeWidgetX.DisplayTextOn() planeWidgetX.SetInput(img_data) planeWidgetX.SetPlaneOrientationToXAxes() planeWidgetX.SetSliceIndex(32) planeWidgetX.SetPicker(picker) planeWidgetX.SetKeyPressActivationValue("x") prop1 = planeWidgetX.GetPlaneProperty() prop1.SetColor(1, 0, 0) planeWidgetY = vtk.vtkImagePlaneWidget() planeWidgetY.DisplayTextOn() planeWidgetY.SetInput(img_data) planeWidgetY.SetPlaneOrientationToYAxes() planeWidgetY.SetSliceIndex(32) planeWidgetY.SetPicker(picker) planeWidgetY.SetKeyPressActivationValue("y") prop2 = planeWidgetY.GetPlaneProperty() prop2.SetColor(1, 1, 0) planeWidgetY.SetLookupTable(planeWidgetX.GetLookupTable()) # for the z-slice, turn off texture interpolation: # interpolation is now nearest neighbour, to demonstrate # cross-hair cursor snapping to pixel centers planeWidgetZ = vtk.vtkImagePlaneWidget() planeWidgetZ.DisplayTextOn() planeWidgetZ.SetInput(img_data) planeWidgetZ.SetPlaneOrientationToZAxes() planeWidgetZ.SetSliceIndex(46) planeWidgetZ.SetPicker(picker) planeWidgetZ.SetKeyPressActivationValue("z") prop3 = planeWidgetZ.GetPlaneProperty() prop3.SetColor(0, 0, 1) planeWidgetZ.SetLookupTable(planeWidgetX.GetLookupTable()) # Create the RenderWindow and Renderer ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) # Add the outline actor to the renderer, set the background # color and size ren.AddActor(outlineActor) renWin.SetSize(600, 600) ren.SetBackground(0.1, 0.1, 0.2) current_widget = planeWidgetZ mode_widget = planeWidgetZ # Set the interactor for the widgets iact = vtk.vtkRenderWindowInteractor() iact.SetRenderWindow(renWin) planeWidgetX.SetInteractor(iact) planeWidgetX.On() planeWidgetY.SetInteractor(iact) planeWidgetY.On() planeWidgetZ.SetInteractor(iact) planeWidgetZ.On() # Create an initial interesting view ren.ResetCamera(); cam1 = ren.GetActiveCamera() cam1.Elevation(110) cam1.SetViewUp(0, 0, -1) cam1.Azimuth(45) ren.ResetCameraClippingRange() iact.Initialize() renWin.Render() # Compare the images and test. img_file = "TestImagePlaneWidget.png" Testing.compareImage(renWin, Testing.getAbsImagePath(img_file)) # Interact if necessary. if Testing.isInteractive(): iact.Start()
def testImagePlaneWidget(self): "A more rigorous test using the image plane widget." # This test is largely copied from # Widgets/Python/TestImagePlaneWidget.py # Load some data. v16 = vtk.vtkVolume16Reader() v16.SetDataDimensions(64, 64) v16.SetDataByteOrderToLittleEndian() v16.SetFilePrefix(os.path.join(Testing.VTK_DATA_ROOT, "Data", "headsq", "quarter")) v16.SetImageRange(1, 93) v16.SetDataSpacing(3.2, 3.2, 1.5) v16.Update() xMin, xMax, yMin, yMax, zMin, zMax = v16.GetExecutive().GetWholeExtent(v16.GetOutputInformation(0)) img_data = v16.GetOutput() spacing = img_data.GetSpacing() sx, sy, sz = spacing origin = img_data.GetOrigin() ox, oy, oz = origin # An outline is shown for context. outline = vtk.vtkOutlineFilter() outline.SetInputData(img_data) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) # The shared picker enables us to use 3 planes at one time # and gets the picking order right picker = vtk.vtkCellPicker() picker.SetTolerance(0.005) # The 3 image plane widgets are used to probe the dataset. planeWidgetX = vtk.vtkImagePlaneWidget() planeWidgetX.DisplayTextOn() planeWidgetX.SetInputData(img_data) planeWidgetX.SetPlaneOrientationToXAxes() planeWidgetX.SetSliceIndex(32) planeWidgetX.SetPicker(picker) planeWidgetX.SetKeyPressActivationValue("x") prop1 = planeWidgetX.GetPlaneProperty() prop1.SetColor(1, 0, 0) planeWidgetY = vtk.vtkImagePlaneWidget() planeWidgetY.DisplayTextOn() planeWidgetY.SetInputData(img_data) planeWidgetY.SetPlaneOrientationToYAxes() planeWidgetY.SetSliceIndex(32) planeWidgetY.SetPicker(picker) planeWidgetY.SetKeyPressActivationValue("y") prop2 = planeWidgetY.GetPlaneProperty() prop2.SetColor(1, 1, 0) planeWidgetY.SetLookupTable(planeWidgetX.GetLookupTable()) # for the z-slice, turn off texture interpolation: # interpolation is now nearest neighbour, to demonstrate # cross-hair cursor snapping to pixel centers planeWidgetZ = vtk.vtkImagePlaneWidget() planeWidgetZ.DisplayTextOn() planeWidgetZ.SetInputData(img_data) planeWidgetZ.SetPlaneOrientationToZAxes() planeWidgetZ.SetSliceIndex(46) planeWidgetZ.SetPicker(picker) planeWidgetZ.SetKeyPressActivationValue("z") prop3 = planeWidgetZ.GetPlaneProperty() prop3.SetColor(0, 0, 1) planeWidgetZ.SetLookupTable(planeWidgetX.GetLookupTable()) # Now create another actor with an opacity < 1 and with some # scalars. p = vtk.vtkPolyData() pts = vtk.vtkPoints() pts.InsertNextPoint((0,0,0)) sc = vtk.vtkFloatArray() sc.InsertNextValue(1.0) p.SetPoints(pts) p.GetPointData().SetScalars(sc) m = vtk.vtkPolyDataMapper() m.SetInputData(p) # Share the lookup table of the widgets. m.SetLookupTable(planeWidgetX.GetLookupTable()) m.UseLookupTableScalarRangeOn() dummyActor = vtk.vtkActor() dummyActor.SetMapper(m) dummyActor.GetProperty().SetOpacity(0.0) # Create the RenderWindow and Renderer ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.SetMultiSamples(0) renWin.AddRenderer(ren) # Add the dummy actor. ren.AddActor(dummyActor) # Add the outline actor to the renderer, set the background # color and size ren.AddActor(outlineActor) renWin.SetSize(600, 600) ren.SetBackground(0.1, 0.1, 0.2) current_widget = planeWidgetZ mode_widget = planeWidgetZ # Set the interactor for the widgets iact = vtk.vtkRenderWindowInteractor() iact.SetRenderWindow(renWin) planeWidgetX.SetInteractor(iact) planeWidgetX.On() planeWidgetY.SetInteractor(iact) planeWidgetY.On() planeWidgetZ.SetInteractor(iact) planeWidgetZ.On() # Create an initial interesting view ren.ResetCamera(); cam1 = ren.GetActiveCamera() cam1.Elevation(110) cam1.SetViewUp(0, 0, -1) cam1.Azimuth(45) ren.ResetCameraClippingRange() iact.Initialize() renWin.Render() # Compare the images and test. img_file = "TestImagePlaneWidget.png" Testing.compareImage(renWin, Testing.getAbsImagePath(img_file)) # Interact if necessary. if Testing.isInteractive(): iact.Start()
def testIntersectWithLine(self): import numpy as np rn = vtkMinimalStandardRandomSequence() ## Choose some random lines and intersect them with our cells def rnums(N, vmin, vmax): result = [] delta = vmax - vmin for i in range(N): result.append(rn.GetValue() * delta + vmin) rn.Next() return result # p1 = list(zip(rnums(10, -4, 8), rnums(10, -4, 4), rnums(10, -4, 4))) # p2 = list(zip(rnums(10, 0, 12), rnums(10, 0, 8), rnums(10, 0, 8))) p1 = [ \ (-4, 2, 2), (2, -4, 2), (2, 2, -4), (0.125, 0.125, 4.125), (8.125, 0.125, 4.125), \ (0.125, 0.125, 0.125), (7.875, 3.875, 3.875), \ ] + list(zip(rnums(1000, -4, 8), rnums(1000, -4, 4), rnums(1000, -4, 4))) p2 = [ \ (12, 2, 2), (2, 8, 2), (2, 2, 8), (3.45, 0.125, 4.125), (3.65, 0.125, 4.125), \ (4.8, 4.3, 4.3), (3.3, -0.5, -0.5), ] + list(zip(rnums(1000, 0, 12), rnums(1000, 0, 8), rnums(1000, 0, 8))) lca = vtkCellArray() lpt = vtkPoints() nli = len(p1) [lpt.InsertNextPoint(x) for x in p1] [lpt.InsertNextPoint(x) for x in p2] [lca.InsertNextCell(2, [i, nli + i]) for i in range(nli)] lpd = vtkPolyData() lpd.SetPoints(lpt) lpd.SetLines(lca) # tub = vtkTubeFilter() # tub.SetInputDataObject(0, lpd) # tub.SetVaryRadiusToVaryRadiusOff() # tub.SetRadius(0.025) # tub.SetCapping(1) # tub.SetNumberOfSides(16) # al, ml = self.addToScene(tub) # al.GetProperty().SetColor(0.5, 0.5, 0.5) ug = self.rdr.GetOutputDataObject(0) from vtkmodules.vtkCommonCore import mutable tt = mutable(0) subId = mutable(-1) xx = [0, 0, 0] rr = [0, 0, 0] ipt = vtkPoints() ica = vtkCellArray() rst = [vtkDoubleArray(), vtkDoubleArray(), vtkDoubleArray()] pname = ['R', 'S', 'T'] [rst[i].SetName(pname[i]) for i in range(3)] for cidx in range(ug.GetNumberOfCells()): cell = ug.GetCell(cidx) order = [cell.GetOrder(i) for i in range(cell.GetCellDimension())] npts = 1 for o in order: npts = npts * (o + 1) weights = np.zeros((npts, 1)) # print('Cell {:1}'.format(cidx)) for pp in range(len(p1)): # print(' Line {p1} -- {p2}'.format(p1=p1[pp], p2=p2[pp])) done = False xp1 = np.array(p1[pp], dtype=np.float64) xp2 = np.array(p2[pp], dtype=np.float64) while not done: done = not cell.IntersectWithLine(xp1, xp2, 1e-8, tt, xx, rr, subId) # print(' Hit: {hit} @{t} posn {posn} param {rr} subId {subId}'.format( \ # hit=not done, t=tt.get(), posn=xx, rr=rr, subId=subId.get())) if not done: pid = [ipt.InsertNextPoint(xx)] ica.InsertNextCell(1, pid) [rst[i].InsertNextTuple([ rr[i], ]) for i in range(3)] delta = xp2 - xp1 mag = np.sqrt(np.sum(delta * delta)) # Note: we use the single-precision epsilon below because # some arithmetic in IntersectWithLine appears to be # done at low precision or with a large tolerance. xp1 = np.array(xx) + (delta / mag) * np.finfo( np.float32).eps ipd = vtkPolyData() ipd.SetPoints(ipt) ipd.SetVerts(ica) [ipd.GetPointData().AddArray(rst[i]) for i in range(3)] print('{N} vertices to glyph'.format(N=ipd.GetNumberOfCells())) gly = vtkGlyph3D() ssc = vtkSphereSource() gly.SetSourceConnection(ssc.GetOutputPort()) gly.SetInputDataObject(0, ipd) gly.SetScaleFactor(0.15) gly.FillCellDataOn() ai, mi = self.addToScene(gly) # ai.GetProperty().SetColor(0.8, 0.3, 0.3) clr = vtkColorSeries() lkup = vtkLookupTable() clr.SetColorScheme(vtkColorSeries.BREWER_SEQUENTIAL_BLUE_PURPLE_9) clr.BuildLookupTable(lkup, vtkColorSeries.ORDINAL) lkup.SetRange(0, 1) mi.SetScalarModeToUseCellFieldData() mi.SelectColorArray('R') mi.SetLookupTable(lkup) #wri = vtkXMLPolyDataWriter() #wri.SetFileName('/tmp/s2.vtp') #gly.Update() #wri.SetInputDataObject(0, gly.GetOutputDataObject(0)) #wri.SetDataModeToAscii() #wri.Write() ## Surface actor a2, m2 = self.addSurfaceToScene(1) a3, m3 = self.addSurfaceToScene(1) a3.GetProperty().SetRepresentationToWireframe() ## Render test scene self.ri.Initialize() cam = self.rr.GetActiveCamera() # cam.SetPosition(4.14824823557, -15.3201939164, 7.48529277914) # cam.SetFocalPoint(4.0392921746, 2.25197875899, 1.59174422348) # cam.SetViewUp(-0.00880943634729, 0.317921564576, 0.948076090095) cam.SetPosition(14.9792978813, -9.28884906174, 13.1673942646) cam.SetFocalPoint(3.76340069188, 2.13047224356, 1.73084897464) cam.SetViewUp(-0.0714929546473, 0.669898141926, 0.739002866625) self.rr.ResetCameraClippingRange() for color in ['R', 'S', 'T']: mi.SelectColorArray(color) self.rw.Render() image = 'LagrangeGeometricOperations-Stab{c}.png'.format(c=color) # events = self.prepareTestImage(self.ri, filename=os.path.join('/tmp', image)) Testing.compareImage(self.rw, self.pathToValidatedOutput(image))
def testGlyphs(self): """Test if texturing of the glyphs works correctly.""" # The Glyph cs = vtk.vtkCubeSource() cs.SetXLength(2.0); cs.SetYLength(1.0); cs.SetZLength(0.5) # Create input point data. pts = vtk.vtkPoints() pts.InsertPoint(0, (1,1,1)) pts.InsertPoint(1, (0,0,0)) pts.InsertPoint(2, (-1,-1,-1)) polys = vtk.vtkCellArray() polys.InsertNextCell(1) polys.InsertCellPoint(0) polys.InsertNextCell(1) polys.InsertCellPoint(1) polys.InsertNextCell(1) polys.InsertCellPoint(2) pd = vtk.vtkPolyData() pd.SetPoints(pts) pd.SetPolys(polys) # Orient the glyphs as per vectors. vec = vtk.vtkFloatArray() vec.SetNumberOfComponents(3) vec.InsertTuple3(0, 1, 0, 0) vec.InsertTuple3(1, 0, 1, 0) vec.InsertTuple3(2, 0, 0, 1) pd.GetPointData().SetVectors(vec) # The glyph filter. g = vtk.vtkGlyph3D() g.SetScaleModeToDataScalingOff() g.SetVectorModeToUseVector() g.SetInput(pd) g.SetSource(cs.GetOutput()) m = vtk.vtkPolyDataMapper() m.SetInputConnection(g.GetOutputPort()) a = vtk.vtkActor() a.SetMapper(m) # The texture. img_file = os.path.join(Testing.VTK_DATA_ROOT, "Data", "masonry.bmp") img_r = vtk.vtkBMPReader() img_r.SetFileName(img_file) t = vtk.vtkTexture() t.SetInputConnection(img_r.GetOutputPort()) t.InterpolateOn() a.SetTexture(t) # Renderer, RenderWindow etc. ren = vtk.vtkRenderer() ren.SetBackground(0.5, 0.5, 0.5) ren.AddActor(a) ren.ResetCamera(); cam = ren.GetActiveCamera() cam.Azimuth(-90) cam.Zoom(1.4) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) rwi = vtk.vtkRenderWindowInteractor() rwi.SetRenderWindow(renWin) rwi.Initialize() rwi.Render() # Compare the images and test. img_file = "TestTextureGlyph.png" Testing.compareImage(renWin, Testing.getAbsImagePath(img_file)) # Interact if necessary. if Testing.isInteractive(): rwi.Start()
def testSlice(self): global plane, filter, args writefiles = "SaveData" in args renderer = vtk.vtkRenderer() renwin = vtk.vtkRenderWindow() renwin.AddRenderer(renderer) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renwin) renwin.Render() if "GPURender" in args: vtk.vtkPistonMapper.InitCUDAGL(renwin) src = vtk.vtkImageMandelbrotSource() src.SetWholeExtent(0, 20, 0, 20, 0, 20) #scale and bias until piston understands origin and spacing src.Update() inputdata = src.GetOutput() if "Normalize" in args: testdata1 = inputdata.NewInstance() testdata1.ShallowCopy(inputdata) testdata1.SetSpacing(1, 1, 1) testdata1.SetOrigin(0, 0, 0) inputdata = testdata1 bounds = inputdata.GetBounds() center = [(bounds[1] - bounds[0]) / 2 + bounds[0], (bounds[3] - bounds[2]) / 2 + bounds[2], (bounds[5] - bounds[4]) / 2 + bounds[4]] d2p = vtk.vtkDataSetToPiston() d2p.SetInputData(inputdata) #d2p.SetInputConnection(src.GetOutputPort()) plane = vtk.vtkPlane() plane.SetOrigin(center) plane.SetNormal(0, 0, 1) filter = vtk.vtkPistonSlice() filter.SetInputConnection(d2p.GetOutputPort()) filter.SetClippingPlane(plane) filter.SetOffset(0.0) p2d = vtk.vtkPistonToDataSet() p2d.SetOutputDataSetType(vtk.VTK_POLY_DATA) p2d.SetInputConnection(filter.GetOutputPort()) if writefiles: writeFile(p2d, "piston_slice.vtk") mapper = vtk.vtkPistonMapper() mapper.SetInputConnection(filter.GetOutputPort()) mapper.Update() #TODO why is this necessary actor = vtk.vtkActor() actor.SetMapper(mapper) renderer.AddActor(actor) widget = vtk.vtkImplicitPlaneWidget() widget.PlaceWidget(bounds) widget.SetOrigin([plane.GetOrigin()[x] for x in 0, 1, 2]) widget.SetNormal([plane.GetNormal()[x] for x in 0, 1, 2]) widget.SetInteractor(iren) widget.AddObserver("InteractionEvent", widgetCallBack) widget.SetEnabled(1) widget.DrawPlaneOff() renderer.ResetCamera() renwin.Render() img_file = "TestSlice.png" Testing.compareImage(renwin, Testing.getAbsImagePath(img_file)) if Testing.isInteractive(): widget.DrawPlaneOn() iren.Start()
def testIntersectWithLine(self): import numpy as np rn = vtkMinimalStandardRandomSequence() ## Choose some random lines and intersect them with our cells def rnums(N, vmin, vmax): result = [] delta = vmax - vmin for i in range(N): result.append(rn.GetValue() * delta + vmin) rn.Next() return result # p1 = list(zip(rnums(10, -4, 8), rnums(10, -4, 4), rnums(10, -4, 4))) # p2 = list(zip(rnums(10, 0, 12), rnums(10, 0, 8), rnums(10, 0, 8))) p1 = [ \ (-4, 2, 2), (2, -4, 2), (2, 2, -4), (0.125, 0.125, 4.125), (8.125, 0.125, 4.125), \ (0.125, 0.125, 0.125), (7.875, 3.875, 3.875), \ ] + list(zip(rnums(1000, -4, 8), rnums(1000, -4, 4), rnums(1000, -4, 4))) p2 = [ \ (12, 2, 2), (2, 8, 2), (2, 2, 8), (3.45, 0.125, 4.125), (3.65, 0.125, 4.125), \ (4.8, 4.3, 4.3), (3.3, -0.5, -0.5), ] + list(zip(rnums(1000, 0, 12), rnums(1000, 0, 8), rnums(1000, 0, 8))) lca = vtkCellArray() lpt = vtkPoints() nli = len(p1) [lpt.InsertNextPoint(x) for x in p1] [lpt.InsertNextPoint(x) for x in p2] [lca.InsertNextCell(2, [i, nli + i]) for i in range(nli)] lpd = vtkPolyData() lpd.SetPoints(lpt) lpd.SetLines(lca) # tub = vtkTubeFilter() # tub.SetInputDataObject(0, lpd) # tub.SetVaryRadiusToVaryRadiusOff() # tub.SetRadius(0.025) # tub.SetCapping(1) # tub.SetNumberOfSides(16) # al, ml = self.addToScene(tub) # al.GetProperty().SetColor(0.5, 0.5, 0.5) ug = self.rdr.GetOutputDataObject(0) from vtkmodules.vtkCommonCore import mutable tt = mutable(0) subId = mutable(-1) xx = [0,0,0] rr = [0,0,0] ipt = vtkPoints() ica = vtkCellArray() rst = [vtkDoubleArray(), vtkDoubleArray(), vtkDoubleArray()] pname = ['R', 'S', 'T'] [rst[i].SetName(pname[i]) for i in range(3)] for cidx in range(ug.GetNumberOfCells()): cell = ug.GetCell(cidx) order = [cell.GetOrder(i) for i in range(cell.GetCellDimension())] npts = 1 for o in order: npts = npts * (o + 1) weights = np.zeros((npts,1)); # print('Cell {:1}'.format(cidx)) for pp in range(len(p1)): # print(' Line {p1} -- {p2}'.format(p1=p1[pp], p2=p2[pp])) done = False xp1 = np.array(p1[pp], dtype=np.float64) xp2 = np.array(p2[pp], dtype=np.float64) while not done: done = not cell.IntersectWithLine(xp1, xp2, 1e-8, tt, xx, rr, subId) # print(' Hit: {hit} @{t} posn {posn} param {rr} subId {subId}'.format( \ # hit=not done, t=tt.get(), posn=xx, rr=rr, subId=subId.get())) if not done: pid = [ipt.InsertNextPoint(xx)] ica.InsertNextCell(1, pid) [rst[i].InsertNextTuple([rr[i],]) for i in range(3)] delta = xp2 - xp1 mag = np.sqrt(np.sum(delta * delta)) # Note: we use the single-precision epsilon below because # some arithmetic in IntersectWithLine appears to be # done at low precision or with a large tolerance. xp1 = np.array(xx) + (delta / mag) * np.finfo(np.float32).eps ipd = vtkPolyData() ipd.SetPoints(ipt) ipd.SetVerts(ica) [ipd.GetPointData().AddArray(rst[i]) for i in range(3)] print('{N} vertices to glyph'.format(N=ipd.GetNumberOfCells())) gly = vtkGlyph3D() ssc = vtkSphereSource() gly.SetSourceConnection(ssc.GetOutputPort()) gly.SetInputDataObject(0, ipd) gly.SetScaleFactor(0.15) gly.FillCellDataOn() ai, mi = self.addToScene(gly) # ai.GetProperty().SetColor(0.8, 0.3, 0.3) clr = vtkColorSeries() lkup = vtkLookupTable() clr.SetColorScheme(vtkColorSeries.BREWER_SEQUENTIAL_BLUE_PURPLE_9) clr.BuildLookupTable(lkup, vtkColorSeries.ORDINAL); lkup.SetRange(0,1) mi.SetScalarModeToUseCellFieldData() mi.SelectColorArray('R') mi.SetLookupTable(lkup) #wri = vtkXMLPolyDataWriter() #wri.SetFileName('/tmp/s2.vtp') #gly.Update() #wri.SetInputDataObject(0, gly.GetOutputDataObject(0)) #wri.SetDataModeToAscii() #wri.Write() ## Surface actor a2, m2 = self.addSurfaceToScene(1) a3, m3 = self.addSurfaceToScene(1) a3.GetProperty().SetRepresentationToWireframe() ## Render test scene self.ri.Initialize() cam = self.rr.GetActiveCamera() # cam.SetPosition(4.14824823557, -15.3201939164, 7.48529277914) # cam.SetFocalPoint(4.0392921746, 2.25197875899, 1.59174422348) # cam.SetViewUp(-0.00880943634729, 0.317921564576, 0.948076090095) cam.SetPosition(14.9792978813, -9.28884906174, 13.1673942646) cam.SetFocalPoint(3.76340069188, 2.13047224356, 1.73084897464) cam.SetViewUp(-0.0714929546473, 0.669898141926, 0.739002866625) self.rr.ResetCameraClippingRange() for color in ['R', 'S', 'T']: mi.SelectColorArray(color) self.rw.Render() image = 'LagrangeGeometricOperations-Stab{c}.png'.format(c=color) # events = self.prepareTestImage(self.ri, filename=os.path.join('/tmp', image)) Testing.compareImage(self.rw, self.pathToValidatedOutput(image))
mapper.Update() #TODO why is this necessary actor = vtk.vtkActor() actor.SetMapper(mapper) renderer.AddActor(actor) widget = vtk.vtkImplicitPlaneWidget() widget.PlaceWidget(bounds) widget.SetOrigin([plane.GetOrigin()[x] for x in 0,1,2]) widget.SetNormal([plane.GetNormal()[x] for x in 0,1,2]) widget.SetInteractor(iren) widget.AddObserver("InteractionEvent", widgetCallBack) widget.SetEnabled(1) widget.DrawPlaneOff() renderer.ResetCamera() renwin.Render() img_file = "TestSlice.png" Testing.compareImage(renwin, Testing.getAbsImagePath(img_file)) if Testing.isInteractive(): widget.DrawPlaneOn() iren.Start() if __name__ == "__main__": global args args = parseArgs() Testing.main([(TestSlice, 'test')])
def testBug(self): # Uncomment the next line if you want to run this via # `gdb python`. #raw_input('Hit Ctrl-C') # Load some data. v16 = vtk.vtkVolume16Reader() v16.SetDataDimensions(64, 64) v16.SetDataByteOrderToLittleEndian() v16.SetFilePrefix(os.path.join(Testing.VTK_DATA_ROOT, "Data", "headsq", "quarter")) v16.SetImageRange(1, 93) v16.SetDataSpacing(3.2, 3.2, 1.5) v16.Update() xMin, xMax, yMin, yMax, zMin, zMax = v16.GetExecutive().GetWholeExtent(v16.GetOutputInformation(0)) img_data = v16.GetOutput() # ************************************************** # Look here for wierdness. # Lets create this data using the data from the reader. my_img_data = vtk.vtkImageData() my_img_data.SetDimensions(img_data.GetDimensions()) # my_img_data.SetWholeExtent(img_data.GetWholeExtent()) my_img_data.SetExtent(img_data.GetExtent()) # my_img_data.SetUpdateExtent(img_data.GetUpdateExtent()) my_img_data.SetSpacing(img_data.GetSpacing()) my_img_data.SetOrigin(img_data.GetOrigin()) my_img_data.SetScalarType(img_data.GetScalarType(), my_img_data.GetInformation()) my_img_data.GetPointData().SetScalars(img_data.GetPointData().GetScalars()) # hang on to original image data. orig_img_data = img_data # hijack img_data with our own. If you comment this out everything is # fine. img_data = my_img_data # ************************************************** spacing = img_data.GetSpacing() sx, sy, sz = spacing origin = img_data.GetOrigin() ox, oy, oz = origin # An outline is shown for context. outline = vtk.vtkOutlineFilter() outline.SetInputData(img_data) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) # The shared picker enables us to use 3 planes at one time # and gets the picking order right picker = vtk.vtkCellPicker() picker.SetTolerance(0.005) # The 3 image plane widgets are used to probe the dataset. planeWidgetX = vtk.vtkImagePlaneWidget() planeWidgetX.DisplayTextOn() planeWidgetX.SetInputData(img_data) planeWidgetX.SetPlaneOrientationToXAxes() planeWidgetX.SetSliceIndex(32) planeWidgetX.SetPicker(picker) planeWidgetX.SetKeyPressActivationValue("x") prop1 = planeWidgetX.GetPlaneProperty() prop1.SetColor(1, 0, 0) planeWidgetY = vtk.vtkImagePlaneWidget() planeWidgetY.DisplayTextOn() planeWidgetY.SetInputData(img_data) planeWidgetY.SetPlaneOrientationToYAxes() planeWidgetY.SetSliceIndex(32) planeWidgetY.SetPicker(picker) planeWidgetY.SetKeyPressActivationValue("y") prop2 = planeWidgetY.GetPlaneProperty() prop2.SetColor(1, 1, 0) planeWidgetY.SetLookupTable(planeWidgetX.GetLookupTable()) # for the z-slice, turn off texture interpolation: # interpolation is now nearest neighbour, to demonstrate # cross-hair cursor snapping to pixel centers planeWidgetZ = vtk.vtkImagePlaneWidget() planeWidgetZ.DisplayTextOn() planeWidgetZ.SetInputData(img_data) planeWidgetZ.SetPlaneOrientationToZAxes() planeWidgetZ.SetSliceIndex(46) planeWidgetZ.SetPicker(picker) planeWidgetZ.SetKeyPressActivationValue("z") prop3 = planeWidgetZ.GetPlaneProperty() prop3.SetColor(0, 0, 1) planeWidgetZ.SetLookupTable(planeWidgetX.GetLookupTable()) # Create the RenderWindow and Renderer ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.SetMultiSamples(0) renWin.AddRenderer(ren) # Add the outline actor to the renderer, set the background # color and size ren.AddActor(outlineActor) renWin.SetSize(600, 600) ren.SetBackground(0.1, 0.1, 0.2) current_widget = planeWidgetZ mode_widget = planeWidgetZ # Set the interactor for the widgets iact = vtk.vtkRenderWindowInteractor() iact.SetRenderWindow(renWin) planeWidgetX.SetInteractor(iact) planeWidgetX.On() planeWidgetY.SetInteractor(iact) planeWidgetY.On() planeWidgetZ.SetInteractor(iact) planeWidgetZ.On() # Create an initial interesting view ren.ResetCamera(); cam1 = ren.GetActiveCamera() cam1.Elevation(110) cam1.SetViewUp(0, 0, -1) cam1.Azimuth(45) ren.ResetCameraClippingRange() iact.Initialize() renWin.Render() # Compare the images and test. img_file = "TestImagePlaneWidget.png" Testing.compareImage(renWin, Testing.getAbsImagePath(img_file)) # Interact if necessary. if Testing.isInteractive(): iact.Start()