[vtkusers] Visualizing populated voxels

Thommen Korah thkorah at hotmail.com
Tue May 10 17:26:24 EDT 2011


Hi,
I have a voxel grid (stored as vtkImageData). I would like to visualize the cells that are populated (greater than a particular threshold). I then want to convert the resulting surface into a polydata and write it as a PLY file. My code below that uses vtkThreshold followed by GeometryFilter doesn't work for some reason. Could anyone suggest a possible fix?
Thanks.Thommen

int VtkScene::addVoxelSurface( short* sampleGrid, double isoValue,
                              int dimX, int dimY, int dimZ,
                              double voxX, double voxY, double voxZ,
                              int minX, int minY, int minZ )
{
  
  vtkShortArray* sampleData = vtkShortArray::New();
  int numSamples = dimX * dimY * dimZ;
  sampleData->SetArray( sampleGrid, numSamples, 1 );
  sampleData->SetNumberOfComponents( 1 );
  sampleData->SetNumberOfTuples( numSamples );
  sampleData->SetName( "values" );


  // Set up sampled data space
  vtkImageData* sampledSpace = vtkImageData::New();
  sampledSpace->SetDimensions( dimX, dimY, dimZ );
  sampledSpace->SetScalarTypeToShort();
  sampledSpace->GetPointData()->SetScalars( sampleData );
  sampledSpace->SetSpacing( voxX, voxY, voxZ );  // set dimensions of a voxel
  sampledSpace->SetOrigin( (double)minX,
                           (double)minY,
                           (double)minZ );       // set lower left corner location

  vtkThreshold* threshold = vtkThreshold::New();
  threshold->SetInput(sampledSpace);
  threshold->SetInputArrayToProcess(0,0,0,vtkDataObject::FIELD_ASSOCIATION_CELLS,vtkDataSetAttributes::SCALARS);
  threshold->ThresholdBetween(5,100);
  threshold->Update();


  vtkGeometryFilter* geomFilter = vtkGeometryFilter::New();
  geomFilter->SetInput(threshold->GetOutput());
  geomFilter->Update();


  // Create mapper and actor, and add to renderer
  vtkPolyDataMapper* voxelMapper = vtkPolyDataMapper::New();
  voxelMapper->SetInput( geomFilter->GetOutput() );
  //voxelMapper->SetScalarRange(5,100);
  voxelMapper->SetScalarModeToUseCellData();
  //voxelMapper->SetColorModeToMapScalars();

  vtkActor* impGeoActor = vtkActor::New();
  impGeoActor->SetMapper( voxelMapper );
  //impGeoActor->GetProperty()->SetColor( 1.0, 0, 0 );
  //impGeoActor->GetProperty()->SetOpacity( alpha );


  int actorId = addActor( impGeoActor );


  voxelMapper->Delete();
  geomFilter->Delete();
  threshold->Delete();
  sampledSpace->Delete();
  sampleData->Delete();

  return actorId;
}
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110510/6cf60678/attachment.htm>


More information about the vtkusers mailing list