Example #1
0
  def applyFilters(self, state):

    surface = state.inputModelNode.GetPolyData()

    if state.decimation:
      triangle = vtk.vtkTriangleFilter()
      triangle.SetInput(surface)
      decimation = vtk.vtkDecimatePro()
      decimation.SetInput(triangle.GetOutput())
      decimation.SetTargetReduction(state.reduction)
      decimation.SetBoundaryVertexDeletion(state.boundaryDeletion)
      decimation.PreserveTopologyOn()
      decimation.Update()
      surface = decimation.GetOutput()

    if state.smoothing:
      if state.smoothingMethod == "Laplace":
        smoothing = vtk.vtkSmoothPolyDataFilter()
        smoothing.SetInput(surface)
        smoothing.SetBoundarySmoothing(state.boundarySmoothing)
        smoothing.SetNumberOfIterations(state.laplaceIterations)
        smoothing.SetRelaxationFactor(state.laplaceRelaxation)
        smoothing.Update()
        surface = smoothing.GetOutput()
      elif state.smoothingMethod == "Taubin":
        smoothing = vtk.vtkWindowedSincPolyDataFilter()
        smoothing.SetInput(surface)
        smoothing.SetBoundarySmoothing(state.boundarySmoothing)
        smoothing.SetNumberOfIterations(state.taubinIterations)
        smoothing.SetPassBand(state.taubinPassBand)
        smoothing.Update()
        surface = smoothing.GetOutput()

    if state.normals:
      normals = vtk.vtkPolyDataNormals()
      normals.SetInput(surface)
      normals.AutoOrientNormalsOn()
      normals.SetFlipNormals(state.flipNormals)
      normals.SetSplitting(state.splitting)
      normals.SetFeatureAngle(state.featureAngle)
      normals.ConsistencyOn()
      normals.Update()
      surface = normals.GetOutput()

    if state.cleaner:
      cleaner = vtk.vtkCleanPolyData()
      cleaner.SetInput(surface)
      cleaner.Update()
      surface = cleaner.GetOutput()

    if state.connectivity:
      connectivity = vtk.vtkPolyDataConnectivityFilter()
      connectivity.SetInput(surface)
      connectivity.SetExtractionModeToLargestRegion()
      connectivity.Update()
      surface = connectivity.GetOutput()

    state.outputModelNode.SetAndObservePolyData(surface)

    return True
Example #2
0
    def ClipData(self, ROI, noisySurfacePolyData):
        """ Returns the clipped polydata from the region defined by the ROI
    Turn on the Debug to make the clipped object appear, 
    For specific filter functionality see DataFlow doc: ClipData.pdf
    """
        connectivityFilter = vtk.vtkPolyDataConnectivityFilter()
        self.utility.PolyDataWriter(noisySurfacePolyData,
                                    "C:\\MakeHDRApplicatorMask\\doc\\"+\
                                    "DebugPolyData\\PreClipped.vtk")
        connectivityFilter.SetInputData(noisySurfacePolyData)
        connectivityFilter.SetExtractionModeToLargestRegion()
        connectivityFilter.Update()
        self.skinSurface = connectivityFilter.GetOutput()  #skinSurface Set
        if self.DEBUG_CONNECTIVITYFACE:
            self.utility.DisplayPolyData("ConnectedFace", self.skinSurface)
        # Expansion of ROI is explained in vtkImplicitModeller limitations
        ROIExtents = self.utility.GetROIExtents(ROI)
        BiggerROI = self.utility.ExpandExtents(ROIExtents, .5)
        #See vtkImplicitModdeler limitations.pdf for explanation
        implicitBoxRegion = vtk.vtkBox()
        implicitBoxRegion.SetBounds(BiggerROI)

        clipper = vtk.vtkClipPolyData()
        clipper.InsideOutOn()  # Clip the regions outside of implicit function
        clipper.SetInputConnection(connectivityFilter.GetOutputPort())
        clipper.SetClipFunction(implicitBoxRegion)
        clipper.Update()
        self.clippedSurface = clipper.GetOutput()
        return clipper
Example #3
0
    def MinimumDistanceMask(self,
                            vtkAlgorythmObject,
                            distanceFromMask,
                            ROI,
                            ruler,
                            isBubble=False):
        """ Takes an algorythm object which is will send through a pipeline to 
    create a mask defining the minimum distance value from the skin surface
    returns an algorythm object as well to preform GetOutput() -> polydata
    or GetOutputPort() -> algorythm
    see MinimumDistanceMask.pdf 
    """
        if distanceFromMask < 2:
            print "WARNING: MouldLogic: MinimumDistanceMask implicit",
            "modeling is very unstable below 1.5 , mask may degrade",
            "and lines will become discontinuous."
        Extents = self.utility.GetROIExtents(ROI)
        if (isBubble):
            Extents = self.utility.ExpandExtents(Extents, 100)
        implicitModeller = vtk.vtkImplicitModeller()
        implicitModeller.SetInputConnection(vtkAlgorythmObject.GetOutputPort())
        implicitModeller.SetMaximumDistance(distanceFromMask)
        implicitModeller.SetModelBounds(Extents)
        implicitModeller.AdjustBoundsOn()
        implicitModeller.SetAdjustBounds(10)  # Removes the boundary effects
        implicitModeller.CappingOff(
        )  # Important to create disjoint inner and outer masks
        implicitModeller.SetProcessModeToPerVoxel()
        implicitModeller.Update()

        contourFilter = vtk.vtkContourFilter()
        contourFilter.SetValue(0, distanceFromMask)
        contourFilter.SetInputConnection(implicitModeller.GetOutputPort())
        contourFilter.Update()

        normalsFunction = vtk.vtkPolyDataNormals()
        normalsFunction.FlipNormalsOn()
        normalsFunction.AddInputConnection(contourFilter.GetOutputPort())
        normalsFunction.Update()

        implicitBoxRegion = vtk.vtkBox()
        implicitBoxRegion.SetBounds(Extents)
        clipper2 = vtk.vtkClipPolyData()
        clipper2.InsideOutOn()  # Clip the regions outside of implicit function
        clipper2.SetInputConnection(normalsFunction.GetOutputPort())
        clipper2.SetClipFunction(implicitBoxRegion)
        clipper2.Update()

        closestPoint = [0, 0, 0]
        ruler.GetPosition1(closestPoint)
        connectivityFilter = vtk.vtkPolyDataConnectivityFilter()
        connectivityFilter.SetInputConnection(clipper2.GetOutputPort())
        connectivityFilter.SetExtractionModeToClosestPointRegion()
        connectivityFilter.SetClosestPoint(closestPoint)
        connectivityFilter.Update()

        return connectivityFilter.GetOutput()
    def clipSurfaceAtEndPoints(self, networkPolyData, surfacePolyData):
        '''
        Clips the surfacePolyData on the endpoints identified using the networkPolyData.
        
        Returns a tupel of the form [clippedPolyData, endpointsPoints]
        '''
        # import the vmtk libraries
        try:
            from libvtkvmtkComputationalGeometryPython import *
            from libvtkvmtkMiscPython import *
        except ImportError:
            print "FAILURE: Unable to import the SlicerVmtk4 libraries!"

        cleaner = vtk.vtkCleanPolyData()
        cleaner.SetInput(networkPolyData)
        cleaner.Update()
        network = cleaner.GetOutput()
        network.BuildCells()
        network.BuildLinks(0)
        endpointIds = vtk.vtkIdList()

        radiusArray = network.GetPointData().GetArray('Radius')

        endpoints = vtk.vtkPolyData()
        endpointsPoints = vtk.vtkPoints()
        endpointsRadius = vtk.vtkDoubleArray()
        endpointsRadius.SetName('Radius')
        endpoints.SetPoints(endpointsPoints)
        endpoints.GetPointData().AddArray(endpointsRadius)

        radiusFactor = 1.2
        minRadius = 0.01

        for i in range(network.GetNumberOfCells()):
            numberOfCellPoints = network.GetCell(i).GetNumberOfPoints()
            pointId0 = network.GetCell(i).GetPointId(0)
            pointId1 = network.GetCell(i).GetPointId(numberOfCellPoints - 1)

            pointCells = vtk.vtkIdList()
            network.GetPointCells(pointId0, pointCells)
            numberOfEndpoints = endpointIds.GetNumberOfIds()
            if pointCells.GetNumberOfIds() == 1:
                pointId = endpointIds.InsertUniqueId(pointId0)
                if pointId == numberOfEndpoints:
                    point = network.GetPoint(pointId0)
                    radius = radiusArray.GetValue(pointId0)
                    radius = max(radius, minRadius)
                    endpointsPoints.InsertNextPoint(point)
                    endpointsRadius.InsertNextValue(radiusFactor * radius)

            pointCells = vtk.vtkIdList()
            network.GetPointCells(pointId1, pointCells)
            numberOfEndpoints = endpointIds.GetNumberOfIds()
            if pointCells.GetNumberOfIds() == 1:
                pointId = endpointIds.InsertUniqueId(pointId1)
                if pointId == numberOfEndpoints:
                    point = network.GetPoint(pointId1)
                    radius = radiusArray.GetValue(pointId1)
                    radius = max(radius, minRadius)
                    endpointsPoints.InsertNextPoint(point)
                    endpointsRadius.InsertNextValue(radiusFactor * radius)

        polyBall = vtkvmtkPolyBall()
        polyBall.SetInput(endpoints)
        polyBall.SetPolyBallRadiusArrayName('Radius')

        clipper = vtk.vtkClipPolyData()
        clipper.SetInput(surfacePolyData)
        clipper.SetClipFunction(polyBall)
        clipper.Update()

        connectivityFilter = vtk.vtkPolyDataConnectivityFilter()
        connectivityFilter.SetInput(clipper.GetOutput())
        connectivityFilter.ColorRegionsOff()
        connectivityFilter.SetExtractionModeToLargestRegion()
        connectivityFilter.Update()

        clippedSurface = connectivityFilter.GetOutput()

        outPolyData = vtk.vtkPolyData()
        outPolyData.DeepCopy(clippedSurface)
        outPolyData.Update()

        return [outPolyData, endpointsPoints]