Plane slicer at custom position #1020
-
Hello, I experienced the most problems if I define a tilted plane in middle part of the volume. For example this pointset does not work: [ 5. 40. 20.] [ 87.27681404 138.05368872 20. ] [-79.91698537 111.2538111 84. ] [ 2.35982867 209.30749982 84. ] My code so far: def slice_plane_custom(volume, p0, p1, p2, p3):
p0_vis = Sphere(pos=p0, r=3.0, res=24, quads=False, c='g5', alpha=1.0)
p1_vis = Sphere(pos=p1, r=3.0, res=24, quads=False, c='g5', alpha=1.0)
p2_vis = Sphere(pos=p2, r=3.0, res=24, quads=False, c='g5', alpha=1.0)
p3_vis = Sphere(pos=p3, r=3.0, res=24, quads=False, c='g5', alpha=1.0)
T = vtk.vtkTransform()
Test_M= T.GetMatrix()
Test_M.SetElement(0,0, cutting_plane_coordi[0, 0]) # cutting_plane_coordi[0,:] = e1 of the coordinate system between p0 and p1
Test_M.SetElement(1,0, cutting_plane_coordi[0, 1])
Test_M.SetElement(2,0, cutting_plane_coordi[0, 2])
Test_M.SetElement(0,1, cutting_plane_coordi[1, 0])# cutting_plane_coordi[1,:] = e2 of the coordinate system between p0 and p2
Test_M.SetElement(1,1, cutting_plane_coordi[1, 1])
Test_M.SetElement(2,1, cutting_plane_coordi[1, 2])
Test_M.SetElement(0,2, cutting_plane_coordi[2, 0])# cutting_plane_coordi[2,:] = e3 crossproduct of e1 and e2
Test_M.SetElement(1,2, cutting_plane_coordi[2, 1])
Test_M.SetElement(2,2, cutting_plane_coordi[2, 2])
Test_M.SetElement(0,3, p0[0])
Test_M.SetElement(1,3, p0[1])
Test_M.SetElement(2,3, p0[2])
reslice = vtk.new("ImageReslice")
reslice.SetInputData(volume.dataset)
reslice.SetOutputDimensionality(2)
reslice.SetResliceAxes(Test_M)
#reslice.SetResliceAxesOrigin(p0)
reslice.SetOutputOrigin(p0) #both of the origin functions are not doing what I would expect them to do
reslice.SetInterpolationModeToLinear()
reslice.SetAutoCropOutput(False)
reslice.SetOutputExtent(0,128,0,128,0,0)
reslice.SetOutputSpacing(1,1,1)
reslice.Update()
vslice = vtk.new("ImageDataGeometryFilter")
vslice.SetInputData(reslice.GetOutput())
vslice.Update()
msh = Mesh(vslice.GetOutput())
msh.apply_transform(Test_M)
msh.pipeline = utils.OperationNode(
"slice_plane", parents=[volume], c="#4cc9f0:#e9c46a")
vslice = msh
vslice.cmap('Purples_r').lighting('off').add_scalarbar('Slice', c='w')
arr_shape = vslice.metadata["shape"]
arr = np.reshape(np.array([vslice.pointdata[0]]), arr_shape)
plot = Plotter(axes=9, bg='k', bg2='bb')
plot.show(volume, vslice, p0_vis, p1_vis, p2_vis, p3_vis, __doc__)
return arr |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi I just created an example for you:
https://github.com/marcomusy/vedo/blob/master/examples/volumetric/slice_plane3.py Hope it helps! |
Beta Was this translation helpful? Give feedback.
-
That's great, thank you! |
Beta Was this translation helpful? Give feedback.
Hi I just created an example for you:
https://github.com/marcomusy/vedo/blob/master/examples/volumetric/slice_plane3.py
Hope it helps!