def _createPETTumorSegmentationParameterNode(self): """create the PETTumorSegmentation parameter node - a singleton in the scene This is used internally by getPETTumorSegmentationParameterNode - shouldn't really be called for any other reason. """ node = slicer.vtkMRMLPETTumorSegmentationParametersNode() self.scene.AddNode(node) # Since we are a singleton, the scene won't add our node into the scene, # but will instead insert a copy, so we find that and return it node = self._findPETTumorSegmentationParameterNodeInScene() centerFiducialList = slicer.vtkMRMLFiducialListNode() self.scene.AddNode(centerFiducialList) node.SetCenterPointIndicatorListReference(centerFiducialList.GetID()) globalRefinementFiducialList = slicer.vtkMRMLFiducialListNode() self.scene.AddNode(globalRefinementFiducialList) node.SetGlobalRefinementIndicatorListReference( globalRefinementFiducialList.GetID()) localRefinementFiducialList = slicer.vtkMRMLFiducialListNode() self.scene.AddNode(localRefinementFiducialList) node.SetLocalRefinementIndicatorListReference( localRefinementFiducialList.GetID()) return node
def test_Collisions(self): self.delayDisplay("Starting the test") # Create models of needle and cautery, in a position that does not represent # collision self.createSampleModels_Collisions() # Compute the center of mass of the target model node tumorModelNode = slicer.mrmlScene.GetNodeByID('vtkMRMLModelNode5') tumorModelPolyData = tumorModelNode.GetPolyData() testingLogic = AutoTransparencyLogic() centerFilter = testingLogic.computeCenterOfMass(tumorModelPolyData) # Transform center to RAS coordinate system center = [] for i,val in enumerate(centerFilter.GetCenter()): center.append(val) center.append(1.0) tumorModelToRAS_transformNode = slicer.mrmlScene.GetNodeByID('vtkMRMLLinearTransformNode5') tumorModelToRAS_vtkMatrix = vtk.vtkMatrix4x4() tumorModelToRAS_transformNode.GetMatrixTransformToParent(tumorModelToRAS_vtkMatrix) tumorModelToRAS_vtkMatrix.MultiplyPoint(center,center) center.remove(1.0) #print "Center of mass in RAS: ", center # Get the camera node's position cameraPosition = testingLogic.getCameraPosition() #print "Camera position: ", cameraPosition # Find cone dimensions coneDimensions = testingLogic.computeConeDimensions(tumorModelPolyData, center, cameraPosition) # Create a model of the cone and visualize it in the scene resolution = 10 coneSource = testingLogic.createConeSource(coneDimensions, center, resolution) coneModelNode = testingLogic.drawCone(coneSource, coneDimensions, center) # Find the tip of cone and the center of the base of the cone, points which # will be used as inputs for the landmark registration coneTip = testingLogic.getConeTip(coneModelNode) #print "coneTip" #print coneTip # Compute center of mass of points of cone base coneBaseCenter = testingLogic.getCenterOfConeBase(coneSource, coneModelNode) #print "coneBaseCenter" #print coneBaseCenter # Create a third point for use in landmark registration, perpendicular to a # line drawn in the AP plane of the cone tip pointPairThree = testingLogic.computeThirdPointsForLandmarkRegistration(cameraPosition, coneTip) coneModelToRAS = slicer.vtkMRMLLinearTransformNode() coneModelToRAS.SetName("coneModelToRAS") coneModelFiducialsNode = slicer.vtkMRMLFiducialListNode() coneModelFiducialsNode.AddFiducialWithLabelXYZSelectedVisibility('coneTip', \ coneTip[0], \ coneTip[1], \ coneTip[2], \ 0, \ 0) coneModelFiducialsNode.AddFiducialWithLabelXYZSelectedVisibility('centerConeBase', \ coneBaseCenter[0], \ coneBaseCenter[1], \ coneBaseCenter[2], \ 0, \ 0) coneModelFiducialsNode.AddFiducialWithLabelXYZSelectedVisibility('perpendicularPointConeAxis', \ pointPairThree.perpendicularPointCone[0], \ pointPairThree.perpendicularPointCone[1], \ pointPairThree.perpendicularPointCone[2], \ 0, \ 0) rasFiducialsNode = slicer.vtkMRMLFiducialListNode() rasFiducialsNode.AddFiducialWithLabelXYZSelectedVisibility('cameraPosition', \ cameraPosition[0], \ cameraPosition[1], \ cameraPosition[2], \ 0, \ 0) rasFiducialsNode.AddFiducialWithLabelXYZSelectedVisibility('modelCOM', \ center[0], \ center[1], \ center[2], \ 0, \ 0) rasFiducialsNode.AddFiducialWithLabelXYZSelectedVisibility('perpendicularPointRAS', \ pointPairThree.perpendicularPointRAS[0], \ pointPairThree.perpendicularPointRAS[1], \ pointPairThree.perpendicularPointRAS[2], \ 0, \ 0) testingLogic.performLandmarkRegistion(coneModelFiducialsNode, rasFiducialsNode, coneModelToRAS) slicer.mrmlScene.AddNode(coneModelToRAS) coneModelNode.SetAndObserveTransformNodeID(coneModelToRAS.GetID()) # Check if collision is occcuring cauteryModelNode = slicer.mrmlScene.GetNodeByID('vtkMRMLModelNode4') coneCauteryCollisionDetectionFilter = \ testingLogic.setUpCollisionDetection(coneModelNode, cauteryModelNode, coneModelToRAS, self.cauteryModelToRAS) testingLogic.checkForCollisions() self.delayDisplay('Collision test passed!') testBool = True return testBool