origin = planeNew.GetOrigin()
planeNew.SetNormal(1, 0, 0)
clipedData = vtk.vtkPolyData()
clipedData.DeepCopy(cliper.GetOutput())
####################################
cutter = vtk.vtkCutter()
cutter.SetCutFunction(planeNew)
cutter.SetInputConnection(cliper.GetOutputPort())
cutter.Update()
cutData = vtk.vtkPolyData()
cutData.DeepCopy(cutter.GetOutput())
cutterMapper=vtk.vtkPolyDataMapper()
cutterMapper.SetInputConnection(cutter.GetOutputPort())
####################################
reslicematrix = vtk.vtkMatrix4x4()
reslicematrix.DeepCopy((
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
))
reslice = vtk.vtkImageReslice()
reslice.SetOutputExtent(0,150,0,150,0,0);
reslice.SetOutputSpacing(1,1,1);
reslice.SetOutputOrigin(origin[0], origin[1], origin[2]);
reslice.SetInputData(cutData)
reslice.SetResliceAxes(reslicematrix)
reslice.SetOutputDimensionality(2)
#print("Origin = "+str(reslice.GetOutput().GetOrigin()))
reslice.AutoCropOutputOn();#!!!make output extent large enough
reslice.SetInterpolationModeToLinear()
resliceMapper=vtk.vtkPolyDataMapper()
resliceMapper.SetInputConnection(reslice.GetOutputPort())
reslice.Update()
print("reslice.GetOutput ="+str(reslice.GetOutput()))
writer = vtk.vtkPNGWriter()
writer.SetInputData(reslice.GetOutput())
writer.SetFileName('D:/nn/Output.png')
writer.Write()
The python code above is for generating a reslice from 3D volume, the code can show 3D volume and show clipped and cut section but no png image is generated.
Any help is appreciated for the following questions:
- I have set the reslice origin to cut plane origin, but the printed reslice origin is (0,0,0), please let me know if it is correct?
- what is the reason for no png image is generated?
- Is SetResliceAxes(reslicematrix) used properly to get randomly slice from 3D volume?
Many thanks for your generous helps.
David.