# Reading voxels from Structured Points

**URL:** https://discourse.vtk.org/t/reading-voxels-from-structured-points/5591
**Category:** Development
**Created:** [April 20, 2021, 9:19am UTC](https://discourse.vtk.org/t/reading-voxels-from-structured-points/5591 "2021-04-20T09:19:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ABWassim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/abwassim/32/3268_2.png) [@ABWassim](https://discourse.vtk.org/u/ABWassim)
#### Post date: [April 20, 2021, 9:19am UTC](https://discourse.vtk.org/t/reading-voxels-from-structured-points/5591/1 "2021-04-20T09:19:36Z")

</div>

Hello everyone,

I’ve been using Binvox which is a tool that voxelizes 3D models and outputs the result in a Binary Structured Points VTK file. I wanted to some treatments on the voxels, so I used the vtkStructuredPointsReader and the vtkStructuredPoints classes. But when I parse the file, it tells me that I have 250047 voxels instead of the 4475 that I’m supposed to have. So basically, I have a huge 64x64x64 (which is the ‘DIMENSIONS’ is the header) cube made of voxels instead of the voxelized 3D model.

I feel like it has something to do with the SCALARS defined in the header because when i visualize the model on Paraview, every voxel of the 3D model is colored with the ‘voxel\_data’ value.

So my question is, how do I only get the voxels of the 3D model instead of every voxel inside the 64x64x64 box ?

Here is my code :

vtkNew reader;  
reader-\>SetFileName(“FinalBaseMesh.vtk”);  
reader-\>Update();  
vtkStructuredPoints\* structuredPoints = reader-\>GetOutput();  
cout \<\< structuredPoints-\>GetNumberOfPoints() \<\< endl; //262144  
cout \<\< structuredPoints-\>GetNumberOfCells() \<\< endl; //250047

Here is the header of the VTK file (I can’t upload it) :

# vtk DataFile Version 3.0

#generated by [binvox], [http://www.google.com/search?q=binvox](http://www.google.com/search?q=binvox)  
BINARY  
DATASET STRUCTURED\_POINTS  
DIMENSIONS 64 64 64  
ORIGIN 0 0 0  
SPACING 1 1 1  
POINT\_DATA 262144  
SCALARS voxel\_data unsigned\_char  
LOOKUP\_TABLE default

The body is only spaces and ‘#’.

Thank you for your time,  
Wassim.

 ![Paraview](https://discourse.vtk.org/uploads/default/original/2X/7/720b76f05cd414387463394f9a426436dd3348be.png)

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [April 20, 2021, 3:17pm UTC](https://discourse.vtk.org/t/reading-voxels-from-structured-points/5591/2 "2021-04-20T15:17:28Z")

</div>

The definition of vtkStructuredPoints is a full rectangular grid of points, so it always provides all the voxels. In the master branch, there have recently been changes that allow a mask to be included with the voxels, but that’s still not a geometrical model in the conventional sense.

The vtkDiscreteMarchingCubes filter can create a boxy geometrical model from vtkStructuredPoints, it might be the best approach.

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [April 20, 2021, 3:21pm UTC](https://discourse.vtk.org/t/reading-voxels-from-structured-points/5591/3 "2021-04-20T15:21:31Z")

</div>

Also consider vtkDiscreteFlyingEdges3D which is faster

---

<div class="post-metadata">

### Author: ![ABWassim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/abwassim/32/3268_2.png) [@ABWassim](https://discourse.vtk.org/u/ABWassim)
#### Post date: [April 21, 2021, 9:12am UTC](https://discourse.vtk.org/t/reading-voxels-from-structured-points/5591/4 "2021-04-21T09:12:52Z")

</div>

Ok, thank you for your answers !
