# How to convert a model into a volume and then compress it into a plane (volume) in a direction?

How to convert a model into a volume and then compress it into a plane (a volume with one slice) in a direction?

@lassoan@pieper@Juicy@jamesobutler @jcfr

You can load it as a segmentation and then get the numpy array so you can use sum or similar.

At 1St, convert a model into a segmentation…as👇… the model the segmentation

The segmentation converted is not the desired result on the two-dimensional slice… This is the attachment:

test.mrb

The stl is not a closed surface so the rasterization fails. Probably you can fix it in some cad tool or your could try rotating it so that the open ends align with the rasterization planes.

You can project a model node to the current slice plane by setting in Models module: Display / Slice display / Mode → Projection. Also enable Visibility and reduce Opacity a bit in that section.

Distance encoded projection option may be useful, too:

Note that these projection modes can be also used for visualizing the pedical screws.

Another solution: I attempted to project this model onto a plane in one direction, resulting in an array containing all coordinate points Then, project these point coordinates onto an empty volume. However, the current problem is how to generate a `schalar volume` (or `binary labelmap`) from a set of point clouds located on a certain plane in 3D space? My failed code, got a empty volume:

``````def ps2vol(ps, modName='vol'):
ps = np.asarray(ps)
# psX轴的最大值-最小值
l = len(ps)
norm = Helper.p3Nor(ps, ps[int(l/3)], ps[int(l/3*2)])
dimX = int(ps[:, 0].max() - ps[:, 0].min())+1
dimY = int(ps[:, 1].max() - ps[:, 1].min())+1
dimZ = int(ps[:, 2].max() - ps[:, 2].min())+1
# 创建vtkImageData数据
imageSize = [dimX, dimY, dimZ]
voxelType=vtk.VTK_UNSIGNED_CHAR
imageOrigin = [ps[:, 0].min(), ps[:, 1].min(), ps[:, 2].min()]
imageSpacing = [1.0, 1.0, 1.0]
imageDirections = np.diag(norm)
fillVoxelValue = 0
# Create an empty image volume, filled with fillVoxelValue
imageData = vtk.vtkImageData()
imageData.SetDimensions(imageSize)
imageData.AllocateScalars(voxelType, 1)
imageData.GetPointData().GetScalars().Fill(fillVoxelValue)
# 将有点的位置设置为1
for point in ps:
i, j, k = int(point), int(point), int(point)
imageData.SetScalarComponentFromDouble(i, j, k, 0, 1) #
imageData.Modified()
#     writer = vtk.vtkXMLImageDataWriter()
#     writer.SetInputData(imageData)
#     writer.SetFileName(modName+'.vti')
#     writer.Write()
#     # Create volume node
volumeNode.SetOrigin(imageOrigin)
volumeNode.SetSpacing(imageSpacing)
volumeNode.SetIJKToRASDirections(imageDirections)
volumeNode.SetAndObserveImageData(imageData)
volumeNode.CreateDefaultDisplayNodes()
volumeNode.CreateDefaultStorageNode()
return volumeNode
``````

Point cloud files: pjArr.npy

pointCloud with markPoint: ??? what’s wrong?