示例#1
0
    def Execute(self):
        if self.Surface == None:
            self.PrintError('Error: no Surface.')

        triangleFilter = vtk.vtkTriangleFilter()
        triangleFilter.SetInput(self.Surface)
        triangleFilter.Update()

        self.Surface = triangleFilter.GetOutput()

        if self.Loop == None:
            self.PrintError('Error: no Loop.')

        select = vtk.vtkImplicitSelectionLoop()
        select.SetLoop(self.Loop.GetPoints())
        normal = [0.0,0.0,0.0]
        centroid = [0.0,0.0,0.0]
        vtk.vtkPolygon().ComputeNormal(self.Loop.GetPoints(),normal)

        #compute centroid and check normals
        p = [0.0,0.0,0.0]
        for i in range (self.Loop.GetNumberOfPoints()):
            p = self.Loop.GetPoint(i)
            centroid[0] += p[0]
            centroid[1] += p[1]
            centroid[2] += p[2]
        centroid[0] = centroid[0] / self.Loop.GetNumberOfPoints()
        centroid[1] = centroid[1] / self.Loop.GetNumberOfPoints()
        centroid[2] = centroid[2] / self.Loop.GetNumberOfPoints()
        print "loop centroid", centroid

        locator = vtk.vtkPointLocator()
        locator.SetDataSet(self.Surface)
        locator.AutomaticOn()
        locator.BuildLocator()
        idsurface = locator.FindClosestPoint(centroid)

        if (self.Surface.GetPointData().GetNormals() == None):
            normalsFilter = vmtkscripts.vmtkSurfaceNormals()
            normalsFilter.Surface = self.Surface
            normalsFilter.NormalsArrayName = 'Normals'
            normalsFilter.Execute()
            self.Surface = normalsFilter.Surface
        normalsurface = [0.0,0.0,0.0]
        self.Surface.GetPointData().GetNormals().GetTuple(idsurface,normalsurface)
        print "loop normal: ", normal
        print "surface normal inside the loop: ", normalsurface
        check = vtk.vtkMath.Dot(normalsurface,normal)
        if check < 0:
            normal[0] = - normal[0]
            normal[1] = - normal[1]
            normal[2] = - normal[2]

        #compute plane
        proj = float(vtk.vtkMath.Dot(self.Loop.GetPoint(0),normal))
        point = [0.0,0.0,0.0]
        self.Loop.GetPoint(0,point)
        for i in range (self.Loop.GetNumberOfPoints()):
            tmp = vtk.vtkMath.Dot(self.Loop.GetPoint(i),normal)
            if tmp < proj:
                proj = tmp
                self.Loop.GetPoint(i,point)
        origin = [0.0,0.0,0.0]
        origin[0] = point[0] #- normal[0]
        origin[1] = point[1] #- normal[1]
        origin[2] = point[2] #- normal[2]
        plane=vtk.vtkPlane()
        plane.SetNormal(normal[0],normal[1],normal[2])
        plane.SetOrigin(origin[0],origin[1],origin[2])

        #set bool
        Bool = vtk.vtkImplicitBoolean()
        Bool.SetOperationTypeToDifference()
        Bool.AddFunction(select)
        Bool.AddFunction(plane)

        clipper=vtk.vtkClipPolyData()
        clipper.SetInput(self.Surface)
        clipper.SetClipFunction(Bool)
        clipper.GenerateClippedOutputOn()
        clipper.InsideOutOff()
        clipper.Update()

        self.Surface = clipper.GetOutput()
示例#2
0
# connectivity
#
# create pipeline
#
sphere = vtk.vtkSphereSource()
sphere.SetRadius(1)
sphere.SetPhiResolution(100)
sphere.SetThetaResolution(100)
selectionPoints = vtk.vtkPoints()
selectionPoints.InsertPoint(0, 0.07325, 0.8417, 0.5612)
selectionPoints.InsertPoint(1, 0.07244, 0.6568, 0.7450)
selectionPoints.InsertPoint(2, 0.1727, 0.4597, 0.8850)
selectionPoints.InsertPoint(3, 0.3265, 0.6054, 0.7309)
selectionPoints.InsertPoint(4, 0.5722, 0.5848, 0.5927)
selectionPoints.InsertPoint(5, 0.4305, 0.8138, 0.4189)
loop = vtk.vtkImplicitSelectionLoop()
loop.SetLoop(selectionPoints)
extract = vtk.vtkExtractGeometry()
extract.SetInputConnection(sphere.GetOutputPort())
extract.SetImplicitFunction(loop)
connect = vtk.vtkConnectivityFilter()
connect.SetInputConnection(extract.GetOutputPort())
connect.SetExtractionModeToClosestPointRegion()
connect.SetClosestPoint(selectionPoints.GetPoint(0))
clipMapper = vtk.vtkDataSetMapper()
clipMapper.SetInputConnection(connect.GetOutputPort())
backProp = vtk.vtkProperty()
backProp.SetDiffuseColor(tomato)
clipActor = vtk.vtkActor()
clipActor.SetMapper(clipMapper)
clipActor.GetProperty().SetColor(peacock)
示例#3
0
    def _extract_polygon(self, PolyData, is_clean):

        self._contour_widget.EnabledOff()
        print "Init Extracting"

        self.setCursor(QCursor(Qt.WaitCursor))
        QApplication.processEvents()

        polydata_rep = self._contour_representation.GetContourRepresentationAsPolyData()
        planes = self.get_frustrum()
        normal = planes.GetNormals()

        nor = np.array([0,0,0])
        normal.GetTuple(5, nor)

        #progressBar.setValue(10)
        #QApplication.processEvents()

        selection = vtkImplicitSelectionLoop()
        selection.SetLoop(polydata_rep.GetPoints())
        selection.SetNormal(nor[0], nor[1], nor[2])

        #progressBar.setValue(20)
        #QApplication.processEvents()

        tip = vtkImplicitBoolean()
        tip.AddFunction(selection)
        tip.AddFunction(planes)
        tip.SetOperationTypeToIntersection()
        tip.Modified()

        #progressBar.setValue(40)
        #QApplication.processEvents()

        if is_clean:
            extractGeometry = vtkExtractPolyDataGeometry()
        else:
            extractGeometry = vtkExtractGeometry()

        extractGeometry.SetInput(PolyData)
        extractGeometry.SetImplicitFunction(tip)

        if is_clean:
            extractGeometry.ExtractInsideOff()
        extractGeometry.Update()

        if is_clean:
            clean = vtkCleanPolyData()
            clean.SetInputConnection(extractGeometry.GetOutputPort())
            clean.Update()
        #progressBar.setValue(80)
        #QApplication.processEvents()

        filter = vtkDataSetSurfaceFilter()
        if is_clean:
            filter.SetInputConnection(clean.GetOutputPort())
        else:
            filter.SetInputConnection(extractGeometry.GetOutputPort())
        filter.Update()

        #progressBar.setValue(90)
        #QApplication.processEvents()

        self.setCursor(QCursor(Qt.ArrowCursor))
        QApplication.processEvents()
        self.extract_action.setEnabled(False)
        self.clean_action.setEnabled(False)

        print "End Extracting"
        return filter.GetOutput()
    def cropWithCurve(self, modelNode, fidList, breastFlag, reverseNormal, setInsideOut, torsoFlag):
        # This method takes in a surface scan and list of fiducials as input and computes the breast volume
        # A curved posterior chest wall is constructed to create the closed breast

        modelsLogic = slicer.modules.models.logic()
        #Check which breast volume is being computed for
        if breastFlag == True:
            name = "ClosedLeftBreast"
        else:
            name = "ClosedRightBreast"

        # Define parameters

        InputModel = modelNode.GetPolyData()
        breastBoundPolyData = vtk.vtkPolyData()
        self.FiducialsToPolyData(fidList, breastBoundPolyData)

        # Create plane of best fit from input breast boundary fiducials
        plane = vtk.vtkPlane()
        self.LeastSquaresPlane(modelNode, breastBoundPolyData, plane)

        #creates loop from the breast boundary points
        breastBound = vtk.vtkImplicitSelectionLoop()
        breastBound.SetLoop(breastBoundPolyData.GetPoints())

        #creates the torso model when the torso flag is set
        if torsoFlag == True:
            self.createTorsoModel(InputModel,breastBound)

        # creates model for the plane of best fit
        planeModel = vtk.vtkReverseSense()
        planeModel = self.createPlaneModel(InputModel, plane, breastFlag)

        splineTransform = vtk.vtkThinPlateSplineTransform()
        splineTransform = self.thinPlateSplineTransform(breastBoundPolyData,plane, modelNode)

        #apply spline transform to the plane visualization
        planeWithSplineTransform = vtk.vtkTransformPolyDataFilter()
        planeWithSplineTransform.SetInputConnection(planeModel.GetOutputPort())
        planeWithSplineTransform.SetTransform(splineTransform)

        #create model of the transformed plane
        transformedPlaneModel = modelsLogic.AddModel(planeWithSplineTransform.GetOutputPort())
        transformedPlaneModel.GetDisplayNode().SetVisibility(False)
        transformedPlaneModel.SetName("transformedPlane")

        # Creates cropped breast model
        breastModel = self.createBreastModel(breastBound, InputModel, breastFlag, reverseNormal, setInsideOut, plane, planeWithSplineTransform)

        # Creates cropped-posterior wall
        posteriorWallModel = vtk.vtkPolyData()
        posteriorWallModel = self.createClippedPlane(breastBound,planeWithSplineTransform)

        # Creates closed breast model
        appendClosedBreast = vtk.vtkAppendPolyData()
        appendClosedBreast.AddInputData(breastModel) #Breasts
        appendClosedBreast.AddInputData(posteriorWallModel) #Chest Wall
        appendClosedBreast.Update()

        # Applies cleaning filter to closed breast model
        cleanClosedBreast = vtk.vtkCleanPolyData()
        cleanClosedBreast.SetInputData(appendClosedBreast.GetOutput())
        cleanClosedBreast.Update()

        # Added closed breast model to slicer models
        closedBreastModel = modelsLogic.AddModel(cleanClosedBreast.GetOutput())
        closedBreastModel.GetDisplayNode().SetVisibility(True)
        closedBreastModel.SetName(name)
        closedBreastModel.GetDisplayNode().BackfaceCullingOff()

        slicer.mrmlScene.RemoveNode(transformedPlaneModel)

        return closedBreastModel
示例#5
0
# connectivity
#
# create pipeline
#
sphere = vtk.vtkSphereSource()
sphere.SetRadius(1)
sphere.SetPhiResolution(100)
sphere.SetThetaResolution(100)
selectionPoints = vtk.vtkPoints()
selectionPoints.InsertPoint(0,0.07325,0.8417,0.5612)
selectionPoints.InsertPoint(1,0.07244,0.6568,0.7450)
selectionPoints.InsertPoint(2,0.1727,0.4597,0.8850)
selectionPoints.InsertPoint(3,0.3265,0.6054,0.7309)
selectionPoints.InsertPoint(4,0.5722,0.5848,0.5927)
selectionPoints.InsertPoint(5,0.4305,0.8138,0.4189)
loop = vtk.vtkImplicitSelectionLoop()
loop.SetLoop(selectionPoints)
extract = vtk.vtkExtractGeometry()
extract.SetInputConnection(sphere.GetOutputPort())
extract.SetImplicitFunction(loop)
connect = vtk.vtkConnectivityFilter()
connect.SetInputConnection(extract.GetOutputPort())
connect.SetExtractionModeToClosestPointRegion()
connect.SetClosestPoint(selectionPoints.GetPoint(0))
clipMapper = vtk.vtkDataSetMapper()
clipMapper.SetInputConnection(connect.GetOutputPort())
backProp = vtk.vtkProperty()
backProp.SetDiffuseColor(tomato)
clipActor = vtk.vtkActor()
clipActor.SetMapper(clipMapper)
clipActor.GetProperty().SetColor(peacock)
示例#6
0
    def Execute(self):
        if self.Surface == None:
            self.PrintError('Error: no Surface.')

        triangleFilter = vtk.vtkTriangleFilter()
        triangleFilter.SetInputData(self.Surface)
        triangleFilter.Update()

        self.Surface = triangleFilter.GetOutput()

        if self.Loop == None:
            self.PrintError('Error: no Loop.')

        select = vtk.vtkImplicitSelectionLoop()
        select.SetLoop(self.Loop.GetPoints())
        normal = [0.0, 0.0, 0.0]
        centroid = [0.0, 0.0, 0.0]
        vtk.vtkPolygon().ComputeNormal(self.Loop.GetPoints(), normal)

        #compute centroid and check normals
        p = [0.0, 0.0, 0.0]
        for i in range(self.Loop.GetNumberOfPoints()):
            p = self.Loop.GetPoint(i)
            centroid[0] += p[0]
            centroid[1] += p[1]
            centroid[2] += p[2]
        centroid[0] = centroid[0] / self.Loop.GetNumberOfPoints()
        centroid[1] = centroid[1] / self.Loop.GetNumberOfPoints()
        centroid[2] = centroid[2] / self.Loop.GetNumberOfPoints()
        print "loop centroid", centroid

        locator = vtk.vtkPointLocator()
        locator.SetDataSet(self.Surface)
        locator.AutomaticOn()
        locator.BuildLocator()
        idsurface = locator.FindClosestPoint(centroid)

        if (self.Surface.GetPointData().GetNormals() == None):
            normalsFilter = vmtkscripts.vmtkSurfaceNormals()
            normalsFilter.Surface = self.Surface
            normalsFilter.NormalsArrayName = 'Normals'
            normalsFilter.Execute()
            self.Surface = normalsFilter.Surface
        normalsurface = [0.0, 0.0, 0.0]
        self.Surface.GetPointData().GetNormals().GetTuple(
            idsurface, normalsurface)
        print "loop normal: ", normal
        print "surface normal inside the loop: ", normalsurface
        check = vtk.vtkMath.Dot(normalsurface, normal)
        if check < 0:
            normal[0] = -normal[0]
            normal[1] = -normal[1]
            normal[2] = -normal[2]

        #compute plane
        proj = float(vtk.vtkMath.Dot(self.Loop.GetPoint(0), normal))
        point = [0.0, 0.0, 0.0]
        self.Loop.GetPoint(0, point)
        for i in range(self.Loop.GetNumberOfPoints()):
            tmp = vtk.vtkMath.Dot(self.Loop.GetPoint(i), normal)
            if tmp < proj:
                proj = tmp
                self.Loop.GetPoint(i, point)
        origin = [0.0, 0.0, 0.0]
        origin[0] = point[0]  #- normal[0]
        origin[1] = point[1]  #- normal[1]
        origin[2] = point[2]  #- normal[2]
        plane = vtk.vtkPlane()
        plane.SetNormal(normal[0], normal[1], normal[2])
        plane.SetOrigin(origin[0], origin[1], origin[2])

        #set bool
        Bool = vtk.vtkImplicitBoolean()
        Bool.SetOperationTypeToDifference()
        Bool.AddFunction(select)
        Bool.AddFunction(plane)

        clipper = vtk.vtkClipPolyData()
        clipper.SetInputData(self.Surface)
        clipper.SetClipFunction(Bool)
        clipper.GenerateClippedOutputOn()
        clipper.InsideOutOff()
        clipper.Update()

        self.Surface = clipper.GetOutput()