#include "vtkImage3DCroppingBoxCallback.h" #include #include void vtkImage3DCroppingBoxCallback::Execute ( vtkObject *caller, unsigned long, void* ) { if( !this->VolumeMapper ) { return; } // get the box widget vtkBoxWidget *widget = reinterpret_cast(caller); if( !widget ) { return; } // Get the poly data defined by the vtkBoxWidget vtkPolyData* myBox = vtkPolyData::New(); widget->GetPolyData(myBox); double bounds[6]={0.0,0.0,0.0,0.0,0.0,0.0}; this->VolumeMapper->GetBounds(bounds); // myBox contains 15 points and points 8 to 13 // define the bounding box double xmin, xmax, ymin, ymax, zmin, zmax; double* pt = myBox->GetPoint(8); xmin = pt[0]; pt = myBox->GetPoint(9); xmax = pt[0]; pt = myBox->GetPoint(10); ymin = pt[1]; pt = myBox->GetPoint(11); ymax = pt[1]; pt = myBox->GetPoint(12); zmin = pt[2]; pt = myBox->GetPoint(13); zmax = pt[2]; if(xminbounds[1]) xmax=bounds[1]; if(ymax>bounds[3]) ymax=bounds[3]; if(zmax>bounds[5]) zmax=bounds[5]; this->VolumeMapper->SetCroppingRegionPlanes(xmin, xmax, ymin, ymax, zmin, zmax); myBox->Delete(); }