def DisplayPoints(self, polyDataLine,name): """ Will display all of the points of a given Polydata Line """ sphere= vtk.vtkSphereSource() sphere.SetRadius(0.3) sphere.Update() glyphFilter=vtk.vtkGlyph3D() glyphFilter.ScalingOff() glyphFilter.SetSourceData(sphere.GetOutput()) #object at eachPoint glyphFilter.SetInputData(polyDataLine) glyphFilter.Update() node=self.DisplayPolyData(name, glyphFilter.GetOutput()) node.SetColor(0.3,0.4,1) #Max 1 for each column node.SetAmbient(1) return node
def DisplayPoints(self, polyDataLine, name): """ Will display all of the points of a given Polydata Line """ sphere = vtk.vtkSphereSource() sphere.SetRadius(0.3) sphere.Update() glyphFilter = vtk.vtkGlyph3D() glyphFilter.ScalingOff() glyphFilter.SetSourceData(sphere.GetOutput()) #object at eachPoint glyphFilter.SetInputData(polyDataLine) glyphFilter.Update() node = self.DisplayPolyData(name, glyphFilter.GetOutput()) node.SetColor(0.3, 0.4, 1) #Max 1 for each column node.SetAmbient(1) return node
def startTransformMapping(self, groundTruthTransformNode, mappedTransformNode, outputVisitedPointsModelNode, positionErrorTransformNode, orientationErrorTransformNode): self.removeObservers() self.groundTruthTransformNode = groundTruthTransformNode self.mappedTransformNode = mappedTransformNode self.outputVisitedPointsModelNode = outputVisitedPointsModelNode self.positionErrorTransformNode = positionErrorTransformNode self.orientationErrorTransformNode = orientationErrorTransformNode self.positionErrorMagnitudeList = [] self.orientationErrorMagnitudeList = [] if self.outputVisitedPointsModelNode: if not self.outputVisitedPointsModelNode.GetDisplayNode(): modelDisplay = slicer.vtkMRMLModelDisplayNode() #modelDisplay.SetSliceIntersectionVisibility(False) # Show in slice view #modelDisplay.SetEdgeVisibility(True) # Hide in 3D view modelDisplay.SetEdgeVisibility(True) slicer.mrmlScene.AddNode(modelDisplay) self.outputVisitedPointsModelNode.SetAndObserveDisplayNodeID(modelDisplay.GetID()) self.visitedPoints = vtk.vtkPoints() self.visitedPointsPolydata = vtk.vtkPolyData() self.visitedPointsPolydata.SetPoints(self.visitedPoints) glyph = vtk.vtkPolyData() cubeSource = vtk.vtkCubeSource() cubeSource.SetXLength(self.minimumSamplingDistance) cubeSource.SetYLength(self.minimumSamplingDistance) cubeSource.SetZLength(self.minimumSamplingDistance) self.visitedPointsGlyph3d = vtk.vtkGlyph3D() self.visitedPointsGlyph3d.SetSourceConnection(cubeSource.GetOutputPort()) self.visitedPointsGlyph3d.SetInputData(self.visitedPointsPolydata) self.visitedPointsGlyph3d.Update() self.outputVisitedPointsModelNode.SetPolyDataConnection(self.visitedPointsGlyph3d.GetOutputPort()) self.initializeErrorTransform(self.positionErrorTransformNode) self.initializeErrorTransform(self.orientationErrorTransformNode) # Start the updates self.addObservers() self.onGroundTruthTransformNodeModified(0,0)
def createTumorFromMarkups(self): logging.debug('createTumorFromMarkups') #self.tumorMarkups_Needle.SetDisplayVisibility(0) # Create polydata point set from markup points points = vtk.vtkPoints() cellArray = vtk.vtkCellArray() numberOfPoints = self.tumorMarkups_Needle.GetNumberOfFiducials() if numberOfPoints > 0: self.deleteLastFiducialButton.setEnabled(True) self.deleteAllFiducialsButton.setEnabled(True) self.deleteLastFiducialDuringNavigationButton.setEnabled(True) # Surface generation algorithms behave unpredictably when there are not enough points # return if there are very few points if numberOfPoints < 1: return points.SetNumberOfPoints(numberOfPoints) new_coord = [0.0, 0.0, 0.0] for i in range(numberOfPoints): self.tumorMarkups_Needle.GetNthFiducialPosition(i, new_coord) points.SetPoint(i, new_coord) cellArray.InsertNextCell(numberOfPoints) for i in range(numberOfPoints): cellArray.InsertCellPoint(i) pointPolyData = vtk.vtkPolyData() pointPolyData.SetLines(cellArray) pointPolyData.SetPoints(points) delaunay = vtk.vtkDelaunay3D() if numberOfPoints < 10: logging.debug("use glyphs") sphere = vtk.vtkCubeSource() glyph = vtk.vtkGlyph3D() glyph.SetInputData(pointPolyData) glyph.SetSourceConnection(sphere.GetOutputPort()) #glyph.SetVectorModeToUseNormal() #glyph.SetScaleModeToScaleByVector() #glyph.SetScaleFactor(0.25) delaunay.SetInputConnection(glyph.GetOutputPort()) else: delaunay.SetInputData(pointPolyData) surfaceFilter = vtk.vtkDataSetSurfaceFilter() surfaceFilter.SetInputConnection(delaunay.GetOutputPort()) smoother = vtk.vtkButterflySubdivisionFilter() smoother.SetInputConnection(surfaceFilter.GetOutputPort()) smoother.SetNumberOfSubdivisions(3) smoother.Update() forceConvexShape = True if (forceConvexShape == True): delaunaySmooth = vtk.vtkDelaunay3D() delaunaySmooth.SetInputData(smoother.GetOutput()) delaunaySmooth.Update() smoothSurfaceFilter = vtk.vtkDataSetSurfaceFilter() smoothSurfaceFilter.SetInputConnection( delaunaySmooth.GetOutputPort()) self.tumorModel_Needle.SetPolyDataConnection( smoothSurfaceFilter.GetOutputPort()) else: self.tumorModel_Needle.SetPolyDataConnection( smoother.GetOutputPort()) self.tumorModel_Needle.Modified()
def createTumorFromMarkups(self): logging.debug("createTumorFromMarkups") # self.tumorMarkups_Needle.SetDisplayVisibility(0) # Create polydata point set from markup points points = vtk.vtkPoints() cellArray = vtk.vtkCellArray() numberOfPoints = self.tumorMarkups_Needle.GetNumberOfFiducials() if numberOfPoints > 0: self.deleteLastFiducialButton.setEnabled(True) self.deleteAllFiducialsButton.setEnabled(True) self.deleteLastFiducialDuringNavigationButton.setEnabled(True) # Surface generation algorithms behave unpredictably when there are not enough points # return if there are very few points if numberOfPoints < 1: return points.SetNumberOfPoints(numberOfPoints) new_coord = [0.0, 0.0, 0.0] for i in range(numberOfPoints): self.tumorMarkups_Needle.GetNthFiducialPosition(i, new_coord) points.SetPoint(i, new_coord) cellArray.InsertNextCell(numberOfPoints) for i in range(numberOfPoints): cellArray.InsertCellPoint(i) pointPolyData = vtk.vtkPolyData() pointPolyData.SetLines(cellArray) pointPolyData.SetPoints(points) delaunay = vtk.vtkDelaunay3D() if numberOfPoints < 10: logging.debug("use glyphs") sphere = vtk.vtkCubeSource() glyph = vtk.vtkGlyph3D() glyph.SetInputData(pointPolyData) glyph.SetSourceConnection(sphere.GetOutputPort()) # glyph.SetVectorModeToUseNormal() # glyph.SetScaleModeToScaleByVector() # glyph.SetScaleFactor(0.25) delaunay.SetInputConnection(glyph.GetOutputPort()) else: delaunay.SetInputData(pointPolyData) surfaceFilter = vtk.vtkDataSetSurfaceFilter() surfaceFilter.SetInputConnection(delaunay.GetOutputPort()) smoother = vtk.vtkButterflySubdivisionFilter() smoother.SetInputConnection(surfaceFilter.GetOutputPort()) smoother.SetNumberOfSubdivisions(3) smoother.Update() forceConvexShape = True if forceConvexShape == True: delaunaySmooth = vtk.vtkDelaunay3D() delaunaySmooth.SetInputData(smoother.GetOutput()) delaunaySmooth.Update() smoothSurfaceFilter = vtk.vtkDataSetSurfaceFilter() smoothSurfaceFilter.SetInputConnection(delaunaySmooth.GetOutputPort()) self.tumorModel_Needle.SetPolyDataConnection(smoothSurfaceFilter.GetOutputPort()) else: self.tumorModel_Needle.SetPolyDataConnection(smoother.GetOutputPort()) self.tumorModel_Needle.Modified()