def getIntersectionBetweenModelAnd1PlaneWithNormalAndOrigin_2(
        modelNode, normal, origin, intersectionModel):
    plane = vtk.vtkPlane()
    plane.SetOrigin(origin)
    plane.SetNormal(normal)

    cutter = vtk.vtkCutter()
    cutter.SetInputData(modelNode.GetPolyData())
    cutter.SetCutFunction(plane)
    cutter.Update()

    intersectionModel.SetAndObservePolyData(cutter.GetOutput())
Esempio n. 2
0
    def CreateBackLine(self, ruler, ROI, implicitPlane):
        """ Creates the polydata for where the cutting plane hits the the back
    of the ROI.  
    This backline will be used to close the catheter path allowing for the
    specification of Towards or Away from the face
    
    ASSERTION: that the ruler's second point will be closest to the 
    front of our mask. 
    """
        roiPoints = self.utility.GetROIPoints(ROI)
        frontExtentIndex = self.utility.GetClosestExtent(ruler, ROI)
        backExtentIndex = self.utility.GetOppositeExtent(frontExtentIndex)

        #Creating an implict plane for the back of the ROI
        ROICenterPoint = [0, 0, 0]
        ROI.GetXYZ(ROICenterPoint)
        backNormal = self.utility.GetVector(ROICenterPoint,
                                            roiPoints[backExtentIndex])
        backPlane = vtk.vtkPlane()
        backPlane.SetNormal(backNormal)
        backPlane.SetOrigin(roiPoints[backExtentIndex])

        #Finding the Intercept of this and the CuttingPlane
        sampleFunction = vtk.vtkSampleFunction()
        sampleFunction.SetSampleDimensions(10, 10, 10)
        sampleFunction.SetImplicitFunction(backPlane)
        bounds = self.utility.ExpandExtents(self.utility.GetROIExtents(ROI), 1)
        sampleFunction.SetModelBounds(bounds)
        sampleFunction.Update()

        contourFilter = vtk.vtkContourFilter()
        contourFilter.SetInputConnection(sampleFunction.GetOutputPort())
        contourFilter.GenerateValues(1, 1, 1)
        contourFilter.Update()

        cutter = vtk.vtkCutter()
        cutter.SetInputConnection(contourFilter.GetOutputPort())
        cutter.SetCutFunction(implicitPlane)
        cutter.GenerateValues(1, 1, 1)
        cutter.Update()
        self.listOfBackLines.append(cutter.GetOutput())
        PATH = self.ROOTPATH + "\\doc\\DebugPolyData\\" + "BackLine-" + str(
            len(self.listOfBackLines))
        self.utility.PolyDataWriter(self.listOfBackLines[-1], PATH + ".vtk")
Esempio n. 3
0
 def getPointsOnPlane(self, planePosition, planeNormal):
     plane = vtk.vtkPlane()
     plane.SetOrigin(planePosition)
     plane.SetNormal(planeNormal)
     cutEdges = vtk.vtkCutter()
     cutEdges.SetInputData(self.curvePoly)
     cutEdges.SetCutFunction(plane)
     cutEdges.GenerateCutScalarsOff()
     cutEdges.SetValue(0, 0)
     cutEdges.Update()
     intersection = cutEdges.GetOutput()
     intersectionPoints = intersection.GetPoints()
     n = intersectionPoints.GetNumberOfPoints()
     points = np.zeros([3, n])
     pos = [0.0, 0.0, 0.0]
     for i in range(n):
         intersectionPoints.GetPoint(i, pos)
         points[:, i] = pos
     return points
Esempio n. 4
0
    def CreateBackLine(self, ruler, ROI, implicitPlane):
        """ Creates the polydata for where the cutting plane hits the the back
    of the ROI.  
    This backline will be used to close the catheter path allowing for the
    specification of Towards or Away from the face
    
    ASSERTION: that the ruler's second point will be closest to the 
    front of our mask. 
    """
        roiPoints = self.utility.GetROIPoints(ROI)
        frontExtentIndex = self.utility.GetClosestExtent(ruler, ROI)
        backExtentIndex = self.utility.GetOppositeExtent(frontExtentIndex)

        # Creating an implict plane for the back of the ROI
        ROICenterPoint = [0, 0, 0]
        ROI.GetXYZ(ROICenterPoint)
        backNormal = self.utility.GetVector(ROICenterPoint, roiPoints[backExtentIndex])
        backPlane = vtk.vtkPlane()
        backPlane.SetNormal(backNormal)
        backPlane.SetOrigin(roiPoints[backExtentIndex])

        # Finding the Intercept of this and the CuttingPlane
        sampleFunction = vtk.vtkSampleFunction()
        sampleFunction.SetSampleDimensions(10, 10, 10)
        sampleFunction.SetImplicitFunction(backPlane)
        bounds = self.utility.ExpandExtents(self.utility.GetROIExtents(ROI), 1)
        sampleFunction.SetModelBounds(bounds)
        sampleFunction.Update()

        contourFilter = vtk.vtkContourFilter()
        contourFilter.SetInputConnection(sampleFunction.GetOutputPort())
        contourFilter.GenerateValues(1, 1, 1)
        contourFilter.Update()

        cutter = vtk.vtkCutter()
        cutter.SetInputConnection(contourFilter.GetOutputPort())
        cutter.SetCutFunction(implicitPlane)
        cutter.GenerateValues(1, 1, 1)
        cutter.Update()
        self.listOfBackLines.append(cutter.GetOutput())
        PATH = self.ROOTPATH + "\\doc\\DebugPolyData\\" + "BackLine-" + str(len(self.listOfBackLines))
        self.utility.PolyDataWriter(self.listOfBackLines[-1], PATH + ".vtk")
def getIntersectionBetweenModelAnd1TransformedPlane(modelNode, transform,
                                                    planeNode,
                                                    intersectionModel):
    plane = vtk.vtkPlane()
    origin = [0, 0, 0]
    normal = [0, 0, 0]
    transformedOrigin = [0, 0, 0]
    transformedNormal = [0, 0, 0]
    planeNode.GetOrigin(origin)
    planeNode.GetNormal(normal)
    transform.TransformPoint(origin, transformedOrigin)
    transform.TransformNormal(normal, transformedNormal)
    plane.SetOrigin(transformedOrigin)
    plane.SetNormal(transformedNormal)

    cutter = vtk.vtkCutter()
    cutter.SetInputData(modelNode.GetPolyData())
    cutter.SetCutFunction(plane)
    cutter.Update()

    intersectionModel.SetAndObservePolyData(cutter.GetOutput())
def getNearestIntersectionBetweenModelAnd1Plane(modelNode, planeNode,
                                                intersectionModel):
    plane = vtk.vtkPlane()
    origin = [0, 0, 0]
    normal = [0, 0, 0]
    planeNode.GetOrigin(origin)
    planeNode.GetNormal(normal)
    plane.SetOrigin(origin)
    plane.SetNormal(normal)

    cutter = vtk.vtkCutter()
    cutter.SetInputData(modelNode.GetPolyData())
    cutter.SetCutFunction(plane)
    cutter.Update()

    connectivityFilter = vtk.vtkConnectivityFilter()
    connectivityFilter.SetInputData(cutter.GetOutput())
    connectivityFilter.SetClosestPoint(origin)
    connectivityFilter.SetExtractionModeToClosestPointRegion()
    connectivityFilter.Update()

    intersectionModel.SetAndObservePolyData(connectivityFilter.GetOutput())