def onLandmarkMoved_NOT(self,state): """Perform the linear transform using the vtkLandmarkTransform class""" if state.transformed.GetTransformNodeID() != state.linearTransform.GetID(): state.transformed.SetAndObserveTransformNodeID(state.linearTransform.GetID()) self.linearMode = "Rigid" # try to use user selection, but fall back if not enough points are available landmarkTransform = vtk.vtkLandmarkTransform() if self.linearMode == 'Rigid': landmarkTransform.SetModeToRigidBody() if self.linearMode == 'Similarity': landmarkTransform.SetModeToSimilarity() if self.linearMode == 'Affine': landmarkTransform.SetModeToAffine() if state.fixedFiducials.GetNumberOfFiducials() < 3: landmarkTransform.SetModeToRigidBody() points = {} point = [0,]*3 for volumeNode in (state.fixed,state.moving): points[volumeNode] = vtk.vtkPoints() indices = range(state.fixedFiducials.GetNumberOfFiducials()) fiducialLists = (state.fixedFiducials,state.movingFiducials) volumeNodes = (state.fixed,state.moving) for fiducials,volumeNode in zip(fiducialLists,volumeNodes): for index in indices: fiducials.GetNthFiducialPosition(index,point) points[volumeNode].InsertNextPoint(point) landmarkTransform.SetSourceLandmarks(points[state.moving]) landmarkTransform.SetTargetLandmarks(points[state.fixed]) landmarkTransform.Update() t = state.linearTransform t.SetAndObserveMatrixTransformToParent(landmarkTransform.GetMatrix())
def onLandmarkMoved(self,state): """Perform the linear transform using the vtkLandmarkTransform class""" if state.transformed.GetTransformNodeID() != state.linearTransform.GetID(): state.transformed.SetAndObserveTransformNodeID(state.linearTransform.GetID()) self.linearMode = "Rigid" # try to use user selection, but fall back if not enough points are available landmarkTransform = vtk.vtkLandmarkTransform() if self.linearMode == 'Rigid': landmarkTransform.SetModeToRigidBody() if self.linearMode == 'Similarity': landmarkTransform.SetModeToSimilarity() if self.linearMode == 'Affine': landmarkTransform.SetModeToAffine() if state.fixedFiducials.GetNumberOfFiducials() < 3: landmarkTransform.SetModeToRigidBody() volumeNodes = (state.fixed, state.moving) fiducialNodes = (state.fixedFiducials,state.movingFiducials) points = state.logic.vtkPointForVolumes( volumeNodes, fiducialNodes ) landmarkTransform.SetSourceLandmarks(points[state.moving]) landmarkTransform.SetTargetLandmarks(points[state.fixed]) landmarkTransform.Update() t = state.linearTransform t.SetAndObserveMatrixTransformToParent(landmarkTransform.GetMatrix())
def performLinearRegistration(self,fixed,moving,landmarks,transform,transformed): """Perform the linear transform using the vtkLandmarkTransform class""" print('performing registration') transformed.SetAndObserveTransformNodeID(transform.GetID()) # try to use user selection, but fall back if not enough points are available landmarkTransform = vtk.vtkLandmarkTransform() if self.linearMode == 'Rigid': landmarkTransform.SetModeToRigidBody() if self.linearMode == 'Similarity': landmarkTransform.SetModeToSimilarity() if self.linearMode == 'Affine': landmarkTransform.SetModeToAffine() if len(landmarks.values()) < 3: landmarkTransform.SetModeToRigidBody() points = {} point = [0,]*3 for volumeNode in (fixed,moving): points[volumeNode] = vtk.vtkPoints() for fiducials in landmarks.values(): for volumeNode,fid in zip((fixed,moving),fiducials): fid.GetFiducialCoordinates(point) points[volumeNode].InsertNextPoint(point) print("%s: %s" % (volumeNode.GetName(), str(point))) landmarkTransform.SetSourceLandmarks(points[moving]) landmarkTransform.SetTargetLandmarks(points[fixed]) landmarkTransform.Update() transform.SetAndObserveMatrixTransformToParent(landmarkTransform.GetMatrix())
def onLandmarkMoved(self, state): """Perform the linear transform using the vtkLandmarkTransform class""" if state.transformed: if state.transformed.GetTransformNodeID() != state.transform.GetID( ): state.transformed.SetAndObserveTransformNodeID( state.transform.GetID()) if not state.fixedFiducials or not state.movingFiducials: return # try to use user selection, but fall back if not enough points are available landmarkTransform = vtk.vtkLandmarkTransform() if self.linearMode == 'Rigid': landmarkTransform.SetModeToRigidBody() if self.linearMode == 'Similarity': landmarkTransform.SetModeToSimilarity() if self.linearMode == 'Affine': landmarkTransform.SetModeToAffine() if state.fixedFiducials.GetNumberOfFiducials() < 3: landmarkTransform.SetModeToRigidBody() volumeNodes = (state.fixed, state.moving) fiducialNodes = (state.fixedFiducials, state.movingFiducials) points = state.logic.vtkPointsForVolumes(volumeNodes, fiducialNodes) landmarkTransform.SetSourceLandmarks(points[state.moving]) landmarkTransform.SetTargetLandmarks(points[state.fixed]) landmarkTransform.Update() state.transform.SetAndObserveTransformToParent(landmarkTransform)
def performLinearRegistration(self,fixed,moving,landmarks,transform,transformed): transformed.SetAndObserveTransformNodeID(transform.GetID()) landmarkTransform = vtk.vtkLandmarkTransform() if self.linearMode == 'Rigid': landmarkTransform.SetModeToRigidBody() if self.linearMode == 'Similarity': landmarkTransform.SetModeToSimilarity() if self.linearMode == 'Affine': landmarkTransform.SetModeToAffine() points = {} point = [0,]*3 for volumeNode in (fixed,moving): points[volumeNode] = vtk.vtkPoints() for fiducials in landmarks.values(): for volumeNode,fid in zip((fixed,moving),fiducials): fid.GetFiducialCoordinates(point) points[volumeNode].InsertNextPoint(point) print("%s: %s" % (volumeNode.GetName(), str(point))) landmarkTransform.SetSourceLandmarks(points[moving]) landmarkTransform.SetTargetLandmarks(points[fixed]) landmarkTransform.Update() transform.SetAndObserveMatrixTransformToParent(landmarkTransform.GetMatrix())
def GetDiffusingLaserTransform(self): fiducialsNode = self.inputFiducialsNodeSelector.currentNode(); print fiducialsNode.GetClassName() if fiducialsNode.GetClassName() == "vtkMRMLMarkupsFiducialNode": # slicer4 Markups node NumFid = fiducialsNode.GetNumberOfFiducials() if NumFid < 2: print("Two Fiducials Needed ") return None # get fiducial positions else: # slicer Points pointtip = [0.0, 0.0, 0.0] fiducialsNode.GetNthFiducialPosition(0, pointtip ) pointentry = [0.0, 0.0, 0.0] fiducialsNode.GetNthFiducialPosition(1, pointentry) else: print("Unknown Class ") return None # diffusing applicator center at coordinate (0, 0., 0. ) mm # template laser distal ends at coordinates (0, +/- DiffusingTipLength/2., 0. ) mm originalOrientation = vtk.vtkPoints() originalOrientation.SetNumberOfPoints(3) originalOrientation.SetPoint(0, 0., 0.,0.) originalOrientation.SetPoint(1, 0.,self.DiffusingTipLength/2.,0.) originalOrientation.SetPoint(2,self.DiffusingTipLength/10., 0.,0.) # compute target landmarks slicerLength = numpy.linalg.norm( numpy.array(pointentry) - numpy.array(pointtip) ) unitdirection = 1./slicerLength * (numpy.array(pointentry) - numpy.array(pointtip) ) pointtip = pointtip - self.PullBackValueSliderWidget.value * unitdirection pointscaled = pointtip - self.PullBackValueSliderWidget.value * unitdirection + self.DiffusingTipLength/2. * unitdirection # compute cross product for other direction appcross = numpy.cross(pointtip ,pointscaled ) normcross = numpy.linalg.norm( appcross ) appcross = pointtip + 1./normcross * appcross print "points", pointentry, pointtip, pointscaled, slicerLength, numpy.linalg.norm( unitdirection ), numpy.linalg.norm( pointscaled - pointtip ) ,appcross slicerOrientation = vtk.vtkPoints() slicerOrientation.SetNumberOfPoints(3) slicerOrientation.SetPoint(0,pointtip[ 0],pointtip[ 1],pointtip[ 2] ) slicerOrientation.SetPoint(1,pointscaled[0],pointscaled[1],pointscaled[2] ) slicerOrientation.SetPoint(2,appcross[ 0],appcross[ 1],appcross[ 2] ) LaserLineTransform = vtk.vtkLandmarkTransform() LaserLineTransform.SetSourceLandmarks(originalOrientation) LaserLineTransform.SetTargetLandmarks(slicerOrientation ) LaserLineTransform.SetModeToRigidBody() LaserLineTransform.Update() print LaserLineTransform.GetMatrix() ## # Get RAS transformation ## rasToXY = vtk.vtkMatrix4x4() ## layoutManager = slicer.app.layoutManager() ## sliceWidget = layoutManager.sliceWidget('Red') ## sliceLogic = sliceWidget.sliceLogic() ## layerLogic = sliceLogic.GetBackgroundLayer() ## xyToIJK = layerLogic.GetXYToIJKTransform().GetMatrix() ## rasToXY.DeepCopy( xyToIJK ) ## #rasToXY.Invert() ## outnode = self.outputSelector.currentNode() ## ras2ijk = vtk.vtkMatrix4x4() ## ijk2ras = vtk.vtkMatrix4x4() ## outnode.GetRASToIJKMatrix(ras2ijk) ## outnode.GetIJKToRASMatrix(ijk2ras) ## print ras2ijk ## print ijk2ras ## print rasToXY ## print pointtip ## print rasToXY.MultiplyPoint( (pointtip[0],pointtip[1],pointtip[2],1.) ) ## print ras2ijk.MultiplyPoint( (pointtip[0],pointtip[1],pointtip[2],1.) ) return LaserLineTransform