Transfer result of vtkVoxelModeller to STL format.

Hello Team,
I have some voxelisation and want to save it to STL format.
Why code below doesn’t generate STL-file?
Thanks in advance.

vtkSmartPointer voxelModeller = vtkSmartPointer::New();
voxelModeller->SetModelBounds( bounds );
voxelModeller->SetInputConnection( pDataSource->GetOutputPort() );
voxelModeller->Update();
vtkSmartPointer writer = vtkSmartPointer::New();
writer->SetInputConnection( voxelModeller->GetOutputPort() );
writer->SetFileName( “voxel.stl” );
const int iResult = writer->Write();

vtkVoxelModeller produces a vtkImageData output, which is a regular grid data structure. STL supports only polygonal meshes, which is quite different from a regular grid, so I don’t see how it would be possible to save a vtkImageData to an STL file.

Hello Cory,
Thank you for an answer.
My plan is read cell by cell and union to single solid.

For the problem now is - after voxalisation all cells in bounds are built. I expected only cells inside geometry are built. Shoul I post-process it? In the code below number of cells is 1000. It means all bounds here.

Thanks in advance.
With respects, Eugene.

vtkSmartPointer pDataSource = vtkSmartPointer::New();
double bounds[6] = { 0.0 };
pDataSource->GetOutput()->GetBounds( bounds );
vtkSmartPointer voxelModeller = vtkSmartPointer::New();
voxelModeller->SetModelBounds( bounds );
voxelModeller->SetInputConnection( pDataSource->GetOutputPort() );
voxelModeller->SetSampleDimensions( 11, 11, 11 );
voxelModeller->Update();

vtkImageData* pData = voxelModeller->GetOutput();
if ( !pData )
{
	return;
}

const vtkIdType iSize = pData->GetNumberOfCells();

Voxels will be generated inside and outside the geometry, and the resulting data has a 1 for every voxel inside the geometry and 0 outside. You need to do some processing of this to get only the inside of the model, but since I’m not sure what you are ultimately trying to achieve, I’m not sure what advice to give you. Can you elaborate on your goal? Do you need a polygonal dataset to write into an STL file?

Sorry, I didn’t find this flag.

It is part of the point data, accessible with

vtkDataArray* array = pData->GetPointData()->GetScalars();

Okey, thank you.
My target is to substitute some geometry by more rough volume to make less weight of geometry.

Hi Cory,
Thank you a lot for support.
I implemented voxelisation by my own code from scratch.

With respects, Eugene.