[vtkusers] How to crop a vtkImageData volume?

allan.martin at utoronto.ca allan.martin at utoronto.ca
Tue Sep 16 10:58:17 EDT 2008


Hi all,

I'm trying to take a vtkImageData volume and crop it with a box widget  
to make a smaller volume, so that when I subsequently render an  
isosurface it isn't so slow.  I think I'm close, but I can't seem to  
get something that vtkMarchingCubes will eat (it wants a vtkImageData  
object, and I don't know how to copy my vtkUnstructuredGrid back to a  
vtkImageData object).  Anyone have an example of how to do this?

Here is my broken code:

//Start with a volume, and make it smaller with a box widget
boxVOI = vtkBoxWidget::New();
VoxelData = vtkImageData::New();
...
//Now take the region defined by the box widget, and make a new volume  
data set
//that is smaller
vtkPlanes* boxVOIPlanes = vtkPlanes::New();
boxVOI->GetPlanes(boxVOIPlanes);
vtkExtractGeometry* clipDataSet = vtkExtractGeometry::New();
clipDataSet->SetInput(VoxelData);
clipDataSet->SetImplicitFunction(boxVOIPlanes);
vtkDataSet* output = (vtkDataSet*) clipDataSet->GetOutput();
vtkImageData* croppedVoxelData = vtkImageData::New();

//This copy doesn't seem to be sufficient as it doesn't copy the  
number of dimensions and other vtkImageData fields
croppedVoxelData->ShallowCopy(output);
croppedVoxelData->AllocateScalars(); //It complains if scalars aren't  
allocated
mc->SetInput(croppedVoxelData);


Thanks for your help,

Al Martin




More information about the vtkusers mailing list