def Callback(obj, ev): global lastNormal global lastAxis1 global outlineActor normal0 = lastNormal first0 = lastAxis1 origin0 = outlineActor.GetOrigin() # New values normal1 = np.array(obj.GetNormal()) first1 = np.array(obj.GetPoint1()) - np.array(obj.GetOrigin()) origin1 = obj.GetCenter() trans = AxesToTransform(normal0, first0, origin0, normal1, first1, origin1) if outlineActor.GetUserTransform() is not None: outlineActor.GetUserTransform().Concatenate(trans) else: transform = vtk.vtkTransform() transform.SetMatrix(trans) transform.PostMultiply() outlineActor.SetUserTransform(transform) # Only for book keeping outlineActor.SetOrigin(obj.GetCenter()) # Not modified by SetUserTransform outlineActor.Modified() # Update last axes lastAxis1[0] = first1[0] lastAxis1[1] = first1[1] lastAxis1[2] = first1[2] lastNormal = (normal1[0], normal1[1], normal1[2])
def DummyFunc2(obj, ev): global lastNormal global lastAxis1 global lastOrigin normal0 = lastNormal first0 = lastAxis1 origin0 = lastOrigin normal1 = np.array(obj.GetNormal()) first1 = np.array(obj.GetPoint1()) - np.array(obj.GetOrigin()) origin1 = obj.GetCenter() trans = AxesToTransform(normal0, first0, origin0, normal1, first1, origin1) if extraActor.GetUserTransform() is not None: extraActor.GetUserTransform().Concatenate(trans) else: transform = vtk.vtkTransform() transform.SetMatrix(trans) transform.PostMultiply() extraActor.SetUserTransform(transform) lastOrigin = obj.GetCenter() lastAxis1[0] = first1[0] lastAxis1[1] = first1[1] lastAxis1[2] = first1[2] lastNormal = (normal1[0], normal1[1], normal1[2]) extraActor.Modified()
def MyFunc2(obj, ev): global lastNormal global lastAxis1 global axes normal0 = lastNormal first0 = lastAxis1 origin0 = axes.GetOrigin() normal1 = np.array(obj.GetNormal()) first1 = np.array(obj.GetPoint1()) - np.array(obj.GetOrigin()) origin1 = obj.GetCenter() trans = AxesToTransform(normal0, first0, origin0, normal1, first1, origin1) if axes.GetUserTransform() is not None: axes.GetUserTransform().Concatenate(trans) else: transform = vtk.vtkTransform() transform.SetMatrix(trans) transform.PostMultiply() axes.SetUserTransform(transform) # Only for book keeping axes.SetOrigin(obj.GetCenter()) # Not modified by SetUserTransform axes.Modified() # Update last axes lastAxis1[0] = first1[0] lastAxis1[1] = first1[1] lastAxis1[2] = first1[2] lastNormal = (normal1[0], normal1[1], normal1[2])
def onWidgetMoved(self, obj, ev): if (obj in self.planeWidgets): index = self.planeWidgets.index(obj) self.lastIndex = index normal0 = self.lastPositions['normal'][index] first0 = self.lastPositions['axis1'][index] origin0 = self.lastPositions['origin'][index] normal1 = np.array(obj.GetNormal()) first1 = np.array(obj.GetPoint1()) - np.array(obj.GetOrigin()) origin1 = obj.GetCenter() trans = AxesToTransform(normal0, first0, origin0, normal1, first1, origin1) if self.userAttempts[index].GetUserTransform() is not None: self.userAttempts[index].GetUserTransform().Concatenate(trans) else: transform = vtk.vtkTransform() transform.SetMatrix(trans) transform.PostMultiply() self.userAttempts[index].SetUserTransform(transform) (deg, x, y, z) = self.userAttempts[index].GetUserTransform( ).GetOrientationWXYZ() self.lastPositions['origin'][index] = obj.GetCenter() lastAxis1 = [first1[0], first1[1], first1[2]] lastNormal = (normal1[0], normal1[1], normal1[2]) self.lastPositions['axis1'][index] = lastAxis1 self.lastPositions['normal'][index] = lastNormal self.userAttempts[index].Modified() self.render_window.Render() print("center") print('wtf') originalNormal = self.lastPositions['reset'][index][4] originalNormal = originalNormal / np.sqrt(np.sum(originalNormal** 2)) self.widgetMoved.emit( (deg, np.r_[x, y, z]), originalNormal, np.array(obj.GetCenter()) - np.array(self.lastPositions['reset'][index][3]))
def Callback(obj, ev): global renderWindow global lastNormal global lastAxis1 global outlineActor global originActor global origin2DActor normal0 = lastNormal first0 = lastAxis1 origin0 = outlineActor.GetOrigin() # New values normal1 = np.array(obj.GetNormal()) first1 = np.array(obj.GetPoint1()) - np.array(obj.GetOrigin()) origin1 = obj.GetCenter() trans = AxesToTransform(normal0, first0, origin0, normal1, first1, origin1) if outlineActor.GetUserTransform() is not None: outlineActor.GetUserTransform().Concatenate(trans) else: transform = vtk.vtkTransform() transform.SetMatrix(trans) transform.PostMultiply() outlineActor.SetUserTransform(transform) # Only for book keeping outlineActor.SetOrigin(obj.GetCenter()) # Not modified by SetUserTransform outlineActor.Modified() # Update last axes lastAxis1[0] = first1[0] lastAxis1[1] = first1[1] lastAxis1[2] = first1[2] lastNormal = (normal1[0], normal1[1], normal1[2]) # Show where (0,0,0) in global coordinates transformedOrigin = outlineActor.GetUserTransform().TransformPoint(0, 0, 0) if 0: roiStencil.SetInformationInput(reslice.GetOutput()) roiStencil.Update() stencil.SetInputConnection(reslice.GetOutputPort()) stencil.SetBackgroundValue(0.0) stencil.SetStencilConnection(roiStencil.GetOutputPort()) renderWindow.Render()
def GetScreenTransform(self): """ Get transform from origin to window slice plane """ renderer = self.viewer.GetRenderer() # Get screen frame coordinate = vtk.vtkCoordinate() coordinate.SetCoordinateSystemToNormalizedDisplay() coordinate.SetValue(0.0, 0.0) # Lower left lowerLeft = coordinate.GetComputedWorldValue(renderer) coordinate.SetValue(1.0, 0.0) # Lower right lowerRight = coordinate.GetComputedWorldValue(renderer) coordinate.SetValue(0.0, 1.0) # Upper left upperLeft = coordinate.GetComputedWorldValue(renderer) first1 = vtk.vtkVector3d() vtk.vtkMath.Subtract(lowerRight, lowerLeft, first1) tmp = vtk.vtkMath.Distance2BetweenPoints(lowerRight, lowerLeft) vtk.vtkMath.MultiplyScalar(first1, 1.0 / math.sqrt(tmp)) second1 = vtk.vtkVector3d() vtk.vtkMath.Subtract(upperLeft, lowerLeft, second1) tmp = vtk.vtkMath.Distance2BetweenPoints(upperLeft, lowerLeft) vtk.vtkMath.MultiplyScalar(second1, 1.0 / math.sqrt(tmp)) normal1 = vtk.vtkVector3d() vtk.vtkMath.Cross(first1, second1, normal1) # Get distance from plane to screen cursor = self.viewer.GetResliceCursorWidget( ).GetResliceCursorRepresentation().GetResliceCursor() normal = cursor.GetPlane(self.iDim).GetNormal() origin = cursor.GetPlane(self.iDim).GetOrigin() PQ = vtk.vtkVector3d() vtk.vtkMath.Subtract(origin, lowerLeft, PQ) dist = vtk.vtkMath.Dot(normal, PQ) trans = vtk.vtkTransform() trans.Translate(dist * normal[0], dist * normal[1], dist * normal[2]) origin1 = trans.TransformPoint(lowerLeft) normal0 = (0.0, 0.0, 1.0) first0 = (1.0, 0.0, 0.0) origin0 = (0.0, 0.0, 0.0) transMat = AxesToTransform(normal0, first0, origin0, normal1, first1, origin1) return transMat
def SynchronizeAxes(obj, ev): global lastNormal global lastAxis1 global axes global extrinsic print('sync') normal0 = lastNormal first0 = lastAxis1 origin0 = axes.GetOrigin() normal1 = np.array(obj.GetNormal()) first1 = np.array(obj.GetPoint1()) - np.array(obj.GetOrigin()) # Normalize (not needed) l = np.sqrt(np.sum(first1**2)) first1 = 1 / l * first1 origin1 = obj.GetCenter() trans = AxesToTransform(normal0, first0, origin0, normal1, first1, origin1) if axes.GetUserTransform() is not None: axes.GetUserTransform().Concatenate(trans) else: transform = vtk.vtkTransform() transform.PostMultiply() transform.SetMatrix(trans) axes.SetUserTransform(transform) # Center moved to origin of axes axes.SetOrigin(obj.GetCenter()) axes.Modified() # Update last axes lastAxis1[0] = first1[0] lastAxis1[1] = first1[1] lastAxis1[2] = first1[2] lastNormal = (normal1[0], normal1[1], normal1[2])
def SynchronizeAxes(self, obj, ev): # Old coordinate system normal0 = self.lastNormal first0 = self.lastAxis1 origin0 = self.axes.GetOrigin() # Way to store origin # New coordinate system normal1 = obj.GetNormal() first1 = vtk.vtkVector3d() vtk.vtkMath.Subtract(obj.GetPoint1(), obj.GetOrigin(), first1) # Normalize (not needed - but we do this anyway) #first1.Normalize() #origin1 = obj.GetCenter() # Original origin1 = obj.GetOrigin() # Transform trans = AxesToTransform(normal0, first0, origin0, normal1, first1, origin1) if self.axes.GetUserTransform() is not None: self.axes.GetUserTransform().Concatenate(trans) else: transform = vtk.vtkTransform() transform.PostMultiply() transform.SetMatrix(trans) self.axes.SetUserTransform(transform) self.axes.GetUserTransform().Update() # Center moved to origin of axes self.axes.SetOrigin(obj.GetOrigin()) self.axes.Modified() # Update last axes self.lastAxis1 = first1 self.lastNormal = normal1 print(self.__repr__) print('done sync')