I am not sure if there are any 3D Slicer developers here that could help but I figured it is worth the try. I am developing an extension that builds on the endoscopy module. The endoscopy module creates a path model from a set of fiducial points. I am using this path model to set a plane view that is normal to the path it follows, then display that view in one of the viewports.
The issue is that sometimes the plane on view randomly rotates about the plane normal (or path parallel) and I am unsure how to fixate so the orientation is static. See attached code snippet of the algorithm that does this render and the screen capture of the issue.
def reslice_on_path(self, p0, pN, orientation='normal'):
fx=np.poly1d(np.polyfit([p0[0],pN[0]],[p0[1],pN[1]], 1))
fdx = np.polyder(fx)
normal_line = lambda x: (-1/fdx(p0[0]))*(x-p0[0])+p0[1]
t=np.array([p0[0]+0.00001,normal_line(p0[0]+0.00001),p0[2]], dtype='f')
t=t-p0
n=pN-p0
t.astype(float)
n.astype(float)
p0.astype(float)
sliceNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSliceNodeGreen")
if orientation == 'normal': orientation = 0
elif orientation == 'tangent': orientation = 1
sliceNode.SetSliceToRASByNTP(n[0], n[1], n[2], t[0], t[1], t[2], p0[0], p0[1], p0[2], orientation)
sliceNode.Modified()