[vtkusers] Visualizing populated voxels
Bill Lorensen
bill.lorensen at gmail.com
Wed May 11 08:00:02 EDT 2011
A voxel consists of 8 points. By default, scalars for all points in a cell
must pass the threshold criteria. Try setting:
threshold->AllScalarsOff();
On Tue, May 10, 2011 at 10:06 PM, Thommen Korah <thkorah at hotmail.com> wrote:
> Hi Bill,
>
> Thanks for the reply. I made the change as you suggested. It does something
> now. The resulting scene has 10-20 polygonal structures that seem to be
> randomly located. They definitely don't represent the data. If I replace the
> thresholding and geometryfilter construction with a contourfilter,
> everything works fine; I get a surface reconstruction of the underlying cell
> population generated by marching cubes. What I need now is a visualization
> of the actual voxels that are ON, and to convert that to a polydata. Is
> vtkGeometryFilter the right class for that?
>
> Any ideas?
>
> Thanks,
> Thommen
>
> ------------------------------
> Date: Tue, 10 May 2011 19:49:13 -0400
> Subject: Re: [vtkusers] Visualizing populated voxels
> From: bill.lorensen at gmail.com
> To: thkorah at hotmail.com
> CC: vtkusers at vtk.org
>
>
> 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/20110511/b935cae5/attachment.htm>
More information about the vtkusers
mailing list