def createTPS( sourceLM, targetLM): """Perform the thin plate transform using the vtkThinPlateSplineTransform class""" # thinPlateTransform = vtk.vtkThinPlateSplineTransform() thinPlateTransform.SetBasisToR() # for 3D transform # thinPlateTransform.SetSourceLandmarks(sourceLM) thinPlateTransform.SetTargetLandmarks(targetLM) thinPlateTransform.Update() return thinPlateTransform
def initializeErrorTransform(self, errorTransformNode): if not errorTransformNode: return alwaysClearOutputTransformOnStart = True errorTransform=errorTransformNode.GetTransformToParentAs('vtkThinPlateSplineTransform', False) if alwaysClearOutputTransformOnStart or not errorTransform: errorTransform=vtk.vtkThinPlateSplineTransform() groundTruthPoints=vtk.vtkPoints() mappedPoints=vtk.vtkPoints() errorTransform.SetSourceLandmarks(groundTruthPoints) errorTransform.SetTargetLandmarks(mappedPoints) errorTransformNode.SetAndObserveTransformToParent(errorTransform) # We need to use R basis function to be able to save the transform # VTK does not set the basis for the inverse transform (probably a bug) # so we set that manually. errorTransformNode.GetTransformToParent().SetBasisToR() errorTransformNode.GetTransformFromParent().SetBasisToR()
def initializeErrorTransform(self, errorTransformNode): if not errorTransformNode: return alwaysClearOutputTransformOnStart = True errorTransform=errorTransformNode.GetTransformToParentAs('vtkThinPlateSplineTransform', False) if alwaysClearOutputTransformOnStart or not errorTransform: errorTransform=vtk.vtkThinPlateSplineTransform() groundTruthPoints=vtk.vtkPoints() mappedPoints=vtk.vtkPoints() errorTransform.SetSourceLandmarks(groundTruthPoints) errorTransform.SetTargetLandmarks(mappedPoints) errorTransformNode.SetAndObserveTransformToParent(errorTransform) # We need to use R basis function to be able to save the transform # VTK does not set the basis for the inverse transform (probably a bug) # so we set that manually. errorTransformNode.GetTransformToParent().SetBasisToR() errorTransformNode.GetTransformFromParent().SetBasisToR()
def performThinPlateRegistration(self, state, landmarks): """Perform the thin plate transform using the vtkThinPlateSplineTransform class""" print('performing thin plate registration') state.transformed.SetAndObserveTransformNodeID(None) volumeNodes = (state.fixed, state.moving) fiducialNodes = (state.fixedFiducials,state.movingFiducials) points = state.logic.vtkPointForVolumes( volumeNodes, fiducialNodes ) # since this is a resample transform, source is the fixed (resampling target) space # and moving is the target space self.thinPlateTransform = vtk.vtkThinPlateSplineTransform() self.thinPlateTransform.SetBasisToR() # for 3D transform self.thinPlateTransform.SetSourceLandmarks(points[state.fixed]) self.thinPlateTransform.SetTargetLandmarks(points[state.moving]) self.thinPlateTransform.Update() state.logic.resliceThroughTransform(state.moving, self.thinPlateTransform, state.fixed, state.transformed)
def performThinPlateRegistration(self, state, landmarks): """Perform the thin plate transform using the vtkThinPlateSplineTransform class""" volumeNodes = (state.fixed, state.moving) fiducialNodes = (state.fixedFiducials,state.movingFiducials) points = state.logic.vtkPointsForVolumes( volumeNodes, fiducialNodes ) # since this is a resample transform, source is the fixed (resampling target) space # and moving is the target space if not self.thinPlateTransform: self.thinPlateTransform = vtk.vtkThinPlateSplineTransform() self.thinPlateTransform.SetBasisToR() # for 3D transform self.thinPlateTransform.SetSourceLandmarks(points[state.moving]) self.thinPlateTransform.SetTargetLandmarks(points[state.fixed]) self.thinPlateTransform.Update() if points[state.moving].GetNumberOfPoints() != points[state.fixed].GetNumberOfPoints(): raise hell state.transform.SetAndObserveTransformToParent(self.thinPlateTransform)
def performThinPlateRegistration(self,fixed,moving,landmarks,transformed): """Perform the thin plate transform using the vtkThinPlateSplineTransform class""" print('performing thin plate registration') transformed.SetAndObserveTransformNodeID(None) self.thinPlateTransform = vtk.vtkThinPlateSplineTransform() self.thinPlateTransform.SetBasisToR() # for 3D transform points = {} point = [0,]*3 for volumeNode in (fixed,moving): points[volumeNode] = vtk.vtkPoints() for fiducialName in landmarks.keys(): for volumeNode,fid in zip((fixed,moving),landmarks[fiducialName]): fid.GetFiducialCoordinates(point) points[volumeNode].InsertNextPoint(point) print("%s: ('%s', %s)" % (volumeNode.GetName(), fiducialName, str(point))) # since this is a resample transform, source is the fixed (resampling target) space # and moving is the target space self.thinPlateTransform.SetSourceLandmarks(points[fixed]) self.thinPlateTransform.SetTargetLandmarks(points[moving]) self.thinPlateTransform.Update() self.resliceThroughTransform(moving,self.thinPlateTransform, fixed, transformed)
def updateTpsTransform(caller, eventid): numPerEdge = self.fromFids.GetNumberOfFiducials() if numPerEdge != self.toFids.GetNumberOfFiducials(): print 'Error: Fiducial numbers are not equal!' return fp = vtk.vtkPoints() tp = vtk.vtkPoints() f = [0, 0, 0] t = [0, 0, 0] for i in range(numPerEdge): self.fromFids.GetNthFiducialPosition(i, f) self.toFids.GetNthFiducialPosition(i, t) fp.InsertNextPoint(f) tp.InsertNextPoint(t) tps = vtk.vtkThinPlateSplineTransform() tps.SetSourceLandmarks(fp) tps.SetTargetLandmarks(tp) tps.SetBasisToR() tNode.SetAndObserveTransformToParent(tps)