Exemple #1
0
 def UpdateVisibility(self, visible):
     actors = []
     actors.extend(DataStore.Markers())
     actors.extend(DataStore.BacteriaActors())
     for actor in actors:
         actor.SetVisibility(boolInt(visible))
     
     self.renwin_update_callback()
Exemple #2
0
 def CreateMarker(self, loc, radius=None, color=None):
     """
     :@type loc: Vec3f
     :@param loc: The 3D location of the marker.
     """
     if radius is None:
         radius = self.actor_radius
     if color is None:
         color = self.markerColor
     sphere = vtk.vtkSphereSource()
     sphere.SetCenter(loc.x, loc.y, loc.z)
     sphere.SetRadius(radius)
     sphere.SetPhiResolution(20)
     sphere.SetThetaResolution(20)
     sphereMapper = vtk.vtkPolyDataMapper()
     sphereMapper.SetInput(sphere.GetOutput())
     sphereActor = vtk.vtkActor()
     sphereActor.SetMapper(sphereMapper)
     sphereActor.GetProperty().SetDiffuseColor(color.r, color.g, color.b)
     sphereActor.SetVisibility(boolInt(self.visible))
     
     return sphereActor
Exemple #3
0
    def Render(self, volumeReader):
        """
        This method attempts to tesselate the image data.
        
        :@type volumeReader: data.imageIO.base.VolumeImageReader
        :@param volumeReader: This object handles opening image data and 
                              passing it to the appropriate VTK image container
        :@rtype: 2-tuple
        :@return: The vtkActor created from tesselated image data and a 
                  vtkLocator for improving picking operations.
        """
        if self.imageSetID is None: return        
        
        self.volumeReader = volumeReader
        self.vtkReader = volumeReader.LoadVTKReader(self.dataSpacing)
        
        # Gaussian Smoothing
        self.gaussFilter = vtk.vtkImageGaussianSmooth()
        self.gaussFilter.SetDimensionality(3)
        self.gaussFilter.SetStandardDeviation(1)
        self.gaussFilter.SetRadiusFactors(1, 1, 1)
        self.gaussFilter.SetInput(self.vtkReader.GetOutput())
        
        # VOI Extractor
        self.voi = vtk.vtkExtractVOI()
        self.voi.SetInputConnection(self.gaussFilter.GetOutputPort())
#        self.voi.SetInputConnection(self.vtkReader.GetOutputPort())
        self.voi.SetVOI(self.volumeReader.VolumeExtents)
        
        # Surface rendering
        self.bactExtractor = vtk.vtkMarchingCubes()
        self.bactExtractor.GenerateValues(1, self.isocontourLevel)
        self.bactExtractor.ComputeNormalsOff()
        self.bactExtractor.SetInputConnection(self.voi.GetOutputPort())

        # surface rendering with dividing cubes
#        self.bactExtractor = vtk.vtkRecursiveDividingCubes()
#        self.bactExtractor.SetInputConnection(self.voi.GetOutputPort())
#        self.bactExtractor.SetValue(self.isocontourLevel[0])
#        self.bactExtractor.SetDistance(0.5)
#        self.bactExtractor.SetIncrement(2)

        # Smooth the mesh
        relaxedMesh = vtk.vtkSmoothPolyDataFilter()
        relaxedMesh.SetNumberOfIterations(50)
        relaxedMesh.SetInput(self.bactExtractor.GetOutput())

        # Calculate normals
        meshNormals = vtk.vtkPolyDataNormals()
        meshNormals.SetFeatureAngle(60.0)
        meshNormals.SetInput(relaxedMesh.GetOutput())

        # Restrip mesh after normal computation
        restrippedMesh = vtk.vtkStripper()
        restrippedMesh.SetInput(meshNormals.GetOutput())
        
        # Convert mesh to graphics primitives
        self.meshMapper = vtk.vtkPolyDataMapper()
        self.meshMapper.ScalarVisibilityOff()
        self.meshMapper.SetInput(restrippedMesh.GetOutput())
        
        # Finally create a renderable object "Actor" 
        # that can be passed to the render window
        self.ibcActor = vtk.vtkActor()
        self.ibcActor.SetMapper(self.meshMapper)
        ibcColor = DataStore.GetImageSet(self.imageSetID).color
        self.ibcActor.GetProperty().SetDiffuseColor(ibcColor.r, ibcColor.g, ibcColor.b)
        self.ibcActor.GetProperty().SetSpecular(.1)
        self.ibcActor.GetProperty().SetSpecularPower(5)
        self.ibcActor.GetProperty().SetOpacity(1)
        self.ibcActor.SetVisibility(boolInt(self.visible))
        
        self.renderer.AddActor(self.ibcActor)
        
        # Optional Locator to help the ray traced picker
        self.bactLocator = vtk.vtkCellLocator()
        self.bactLocator.SetDataSet(restrippedMesh.GetOutput())
        self.bactLocator.LazyEvaluationOn()
        
        return self.bactLocator
Exemple #4
0
 def UpdateVisibility(self, visible):
     self.visible = visible
     self.ibcActor.SetVisibility(boolInt(visible))
     self.renwin_update_callback()
 def _pickerVisibility(self, visible):
     self.redCone.SetVisibility(boolInt(visible))
     self.greenCone.SetVisibility(boolInt(visible))