def planeLandmarks(self, Landmark1Value, Landmark2Value, Landmark3Value, slider, sliderOpacity): self.initialize() # Limit the number of 3 landmarks to define a plane # Keep the coordinates of the landmarks listCoord = list() fidNode = slicer.mrmlScene.GetNodeByID('vtkMRMLMarkupsFiducialNode1') self.coord = numpy.zeros(3) if Landmark1Value != "List of fiducials": fidNode.GetNthFiducialPosition(int(Landmark1Value)-1, self.coord) listCoord.append(self.coord) print self.coord print listCoord r1 = self.coord[0] a1 = self.coord[1] s1 = self.coord[2] # Limit the number of 3 landmarks to define a plane # Keep the coordinates of the landmarks listCoord = list() fidNode = slicer.mrmlScene.GetNodeByID('vtkMRMLMarkupsFiducialNode1') self.coord = numpy.zeros(3) if Landmark2Value != "List of fiducials": fidNode.GetNthFiducialPosition(int(Landmark2Value)-1, self.coord) listCoord.append(self.coord) print self.coord print listCoord r2 = self.coord[0] a2 = self.coord[1] s2 = self.coord[2] # Limit the number of 3 landmarks to define a plane # Keep the coordinates of the landmarks listCoord = list() fidNode = slicer.mrmlScene.GetNodeByID('vtkMRMLMarkupsFiducialNode1') self.coord = numpy.zeros(3) if Landmark3Value != "List of fiducials": fidNode.GetNthFiducialPosition(int(Landmark3Value)-1, self.coord) listCoord.append(self.coord) print self.coord print listCoord r3 = self.coord[0] a3 = self.coord[1] s3 = self.coord[2] A = (r1,a1,s1) B = (r2,a2,s2) C = (r3,a3,s3) # Vn = Vectorial Product (AB, BC) # Normal N = Vn/norm(Vn) points = vtk.vtkPoints() points.InsertNextPoint(r1,a1,s1) points.InsertNextPoint(r2,a2,s2) points.InsertNextPoint(r3,a3,s3) polydata = vtk.vtkPolyData() polydata.SetPoints(points) centerOfMass = vtk.vtkCenterOfMass() centerOfMass.SetInputData(polydata) centerOfMass.SetUseScalarsAsWeights(False) centerOfMass.Update() G = centerOfMass.GetCenter() print "Center of mass = ",G # Vector GA GA = numpy.matrix([[0],[0],[0]]) GA[0] = A[0]-G[0] GA[1] = A[1]-G[1] GA[2] = A[2]-G[2] print "GA = ", GA # Vector BG GB = numpy.matrix([[0],[0],[0]]) GB[0] = B[0]-G[0] GB[1] = B[1]-G[1] GB[2] = B[2]-G[2] print "GB = ", GB # Vector CG GC = numpy.matrix([[0],[0],[0]]) GC[0] = C[0]-G[0] GC[1] = C[1]-G[1] GC[2] = C[2]-G[2] print "GC = ", GC self.N = self.normalLandmarks(GA,GB) D = numpy.matrix([[0],[0],[0]]) E = numpy.matrix([[0],[0],[0]]) F = numpy.matrix([[0],[0],[0]]) D[0] = slider*GA[0] + G[0] D[1] = slider*GA[1] + G[1] D[2] = slider*GA[2] + G[2] print "Slider value : ", slider print "D = ",D E[0] = slider*GB[0] + G[0] E[1] = slider*GB[1] + G[1] E[2] = slider*GB[2] + G[2] print "E = ",E F[0] = slider*GC[0] + G[0] F[1] = slider*GC[1] + G[1] F[2] = slider*GC[2] + G[2] print "F = ",F self.renderWindow.AddRenderer(self.renderer) planeSource = vtk.vtkPlaneSource() planeSource.SetNormal(self.N[0],self.N[1],self.N[2]) planeSource.SetOrigin(D[0],D[1],D[2]) planeSource.SetPoint1(E[0],E[1],E[2]) planeSource.SetPoint2(F[0],F[1],F[2]) planeSource.Update() plane = planeSource.GetOutput() mapper = vtk.vtkPolyDataMapper() mapper.SetInputData(plane) self.actor.SetMapper(mapper) self.actor.GetProperty().SetColor(0, 0.4, 0.8) self.actor.GetProperty().SetOpacity(sliderOpacity) self.renderer.AddActor(self.actor) self.renderWindow.Render()
def planeLandmarks(self, Landmark1Value, Landmark2Value, Landmark3Value, slider, sliderOpacity): # Limit the number of 3 landmarks to define a plane # Keep the coordinates of the landmarks fidNode = self.getFiducialList() r1 = 0 a1 = 0 s1 = 0 coord = numpy.zeros(3) if Landmark1Value != 0: fidNode.GetNthFiducialPosition(int(Landmark1Value)-1, coord) r1 = coord[0] a1 = coord[1] s1 = coord[2] # Limit the number of 3 landmarks to define a plane # Keep the coordinates of the landmarks r2 = 0 a2 = 0 s2 = 0 if Landmark2Value != 0: fidNode.GetNthFiducialPosition(int(Landmark2Value)-1, coord) r2 = coord[0] a2 = coord[1] s2 = coord[2] # Limit the number of 3 landmarks to define a plane # Keep the coordinates of the landmarks r3 = 0 a3 = 0 s3 = 0 if Landmark3Value != 0: fidNode.GetNthFiducialPosition(int(Landmark3Value)-1, coord) r3 = coord[0] a3 = coord[1] s3 = coord[2] points = self.points if points.GetNumberOfPoints() == 0: points.InsertNextPoint(r1,a1,s1) points.InsertNextPoint(r2,a2,s2) points.InsertNextPoint(r3,a3,s3) else: points.SetPoint(0, r1,a1,s1) points.SetPoint(1, r2,a2,s2) points.SetPoint(2, r3,a3,s3) polydata = self.polydata polydata.SetPoints(points) centerOfMass = vtk.vtkCenterOfMass() centerOfMass.SetInputData(polydata) centerOfMass.SetUseScalarsAsWeights(False) centerOfMass.Update() G = centerOfMass.GetCenter() #print "Center of mass = ",G A = (r1,a1,s1) B = (r2,a2,s2) C = (r3,a3,s3) # Vector GA GA = numpy.matrix([[0],[0],[0]]) GA[0] = A[0]-G[0] GA[1] = A[1]-G[1] GA[2] = A[2]-G[2] #print "GA = ", GA # Vector BG GB = numpy.matrix([[0],[0],[0]]) GB[0] = B[0]-G[0] GB[1] = B[1]-G[1] GB[2] = B[2]-G[2] #print "GB = ", GB # Vector CG GC = numpy.matrix([[0],[0],[0]]) GC[0] = C[0]-G[0] GC[1] = C[1]-G[1] GC[2] = C[2]-G[2] #print "GC = ", GC self.N = self.normalLandmarks(GA,GB) D = numpy.matrix([[0],[0],[0]]) E = numpy.matrix([[0],[0],[0]]) F = numpy.matrix([[0],[0],[0]]) D[0] = slider*GA[0] + G[0] D[1] = slider*GA[1] + G[1] D[2] = slider*GA[2] + G[2] #print "Slider value : ", slider #print "D = ",D E[0] = slider*GB[0] + G[0] E[1] = slider*GB[1] + G[1] E[2] = slider*GB[2] + G[2] #print "E = ",E F[0] = slider*GC[0] + G[0] F[1] = slider*GC[1] + G[1] F[2] = slider*GC[2] + G[2] #print "F = ",F planeSource = self.planeSource planeSource.SetNormal(self.N[0],self.N[1],self.N[2]) planeSource.SetOrigin(D[0],D[1],D[2]) planeSource.SetPoint1(E[0],E[1],E[2]) planeSource.SetPoint2(F[0],F[1],F[2]) planeSource.Update() plane = planeSource.GetOutput() mapper = self.mapper mapper.SetInputData(plane) mapper.Update() self.actor.SetMapper(mapper) self.actor.GetProperty().SetColor(0, 0.4, 0.8) self.actor.GetProperty().SetOpacity(sliderOpacity) self.renderer.Render() self.renderWindow.Render()
def planeLandmarks(self, Landmark1Value, Landmark2Value, Landmark3Value, slider, sliderOpacity): # Limit the number of 3 landmarks to define a plane # Keep the coordinates of the landmarks fidNode = self.getFiducialList() r1 = 0 a1 = 0 s1 = 0 coord = numpy.zeros(3) if Landmark1Value != 0: fidNode.GetNthFiducialPosition(int(Landmark1Value) - 1, coord) r1 = coord[0] a1 = coord[1] s1 = coord[2] # Limit the number of 3 landmarks to define a plane # Keep the coordinates of the landmarks r2 = 0 a2 = 0 s2 = 0 if Landmark2Value != 0: fidNode.GetNthFiducialPosition(int(Landmark2Value) - 1, coord) r2 = coord[0] a2 = coord[1] s2 = coord[2] # Limit the number of 3 landmarks to define a plane # Keep the coordinates of the landmarks r3 = 0 a3 = 0 s3 = 0 if Landmark3Value != 0: fidNode.GetNthFiducialPosition(int(Landmark3Value) - 1, coord) r3 = coord[0] a3 = coord[1] s3 = coord[2] points = self.points if points.GetNumberOfPoints() == 0: points.InsertNextPoint(r1, a1, s1) points.InsertNextPoint(r2, a2, s2) points.InsertNextPoint(r3, a3, s3) else: points.SetPoint(0, r1, a1, s1) points.SetPoint(1, r2, a2, s2) points.SetPoint(2, r3, a3, s3) polydata = self.polydata polydata.SetPoints(points) centerOfMass = vtk.vtkCenterOfMass() centerOfMass.SetInputData(polydata) centerOfMass.SetUseScalarsAsWeights(False) centerOfMass.Update() G = centerOfMass.GetCenter() #print "Center of mass = ",G A = (r1, a1, s1) B = (r2, a2, s2) C = (r3, a3, s3) # Vector GA GA = numpy.matrix([[0], [0], [0]]) GA[0] = A[0] - G[0] GA[1] = A[1] - G[1] GA[2] = A[2] - G[2] #print "GA = ", GA # Vector BG GB = numpy.matrix([[0], [0], [0]]) GB[0] = B[0] - G[0] GB[1] = B[1] - G[1] GB[2] = B[2] - G[2] #print "GB = ", GB # Vector CG GC = numpy.matrix([[0], [0], [0]]) GC[0] = C[0] - G[0] GC[1] = C[1] - G[1] GC[2] = C[2] - G[2] #print "GC = ", GC self.N = self.normalLandmarks(GA, GB) D = numpy.matrix([[0], [0], [0]]) E = numpy.matrix([[0], [0], [0]]) F = numpy.matrix([[0], [0], [0]]) D[0] = slider * GA[0] + G[0] D[1] = slider * GA[1] + G[1] D[2] = slider * GA[2] + G[2] #print "Slider value : ", slider #print "D = ",D E[0] = slider * GB[0] + G[0] E[1] = slider * GB[1] + G[1] E[2] = slider * GB[2] + G[2] #print "E = ",E F[0] = slider * GC[0] + G[0] F[1] = slider * GC[1] + G[1] F[2] = slider * GC[2] + G[2] #print "F = ",F planeSource = self.planeSource planeSource.SetNormal(self.N[0], self.N[1], self.N[2]) planeSource.SetOrigin(D[0], D[1], D[2]) planeSource.SetPoint1(E[0], E[1], E[2]) planeSource.SetPoint2(F[0], F[1], F[2]) planeSource.Update() plane = planeSource.GetOutput() mapper = self.mapper mapper.SetInputData(plane) mapper.Update() self.actor.SetMapper(mapper) self.actor.GetProperty().SetColor(0, 0.4, 0.8) self.actor.GetProperty().SetOpacity(sliderOpacity) self.renderer.Render() self.renderWindow.Render()