Reading voxels from Structured Points

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
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.

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.

1 Like

Also consider vtkDiscreteFlyingEdges3D which is faster

1 Like

Ok, thank you for your answers !