[vtkusers] Visualizing populated voxels

Bill Lorensen bill.lorensen at gmail.com
Tue May 10 19:49:13 EDT 2011


Try,

vtkDataObject::FIELD_ASSOCIATION_POINTS
instead of
vtkDataObject::FIELD_ASSOCIATION_CELLS





On Tue, May 10, 2011 at 5:26 PM, Thommen Korah <thkorah at hotmail.com> wrote:

>  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;
>
> }
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110510/12039060/attachment.htm>


More information about the vtkusers mailing list