23 #include <vtkTransform.h>
24 #include <vtkAbstractVolumeMapper.h>
25 #include <vtkVolumeMapper.h>
26 #include <vtkRenderWindow.h>
27 #include <vtkRenderer.h>
28 #include <vtkImageData.h>
29 #include <vtkCommand.h>
30 #include <vtkBoxWidget2.h>
31 #include <vtkBoxWidget.h>
58 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
81 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
96 mActiveData(activeData)
100 connect(mActiveImageProxy.get(), SIGNAL(cropBoxChanged()),
this, SLOT(imageCropChangedSlot()));
103 void InteractiveCropper::initialize()
108 mBoxWidget = vtkBoxWidgetPtr::New();
109 mBoxWidget->RotationEnabledOff();
112 { -1, 1, -1, 1, -1, 1 };
113 mBoxWidget->PlaceWidget(bb_hard);
115 mCropBoxCallback = CropBoxCallbackPtr::New();
116 mCropBoxCallback->SetCropper(
this);
117 mCropBoxEnableCallback = CropBoxEnableCallbackPtr::New();
118 mCropBoxEnableCallback->SetCropper(
true,
this);
119 mCropBoxDisableCallback = CropBoxEnableCallbackPtr::New();
120 mCropBoxDisableCallback->SetCropper(
false,
this);
122 mBoxWidget->SetInteractor(mView->getRenderWindow()->GetInteractor());
124 mBoxWidget->SetEnabled(
false);
130 this->updateBoxWidgetInteractor();
133 void InteractiveCropper::updateBoxWidgetInteractor()
142 mBoxWidget->SetInteractor(mView->getRenderWindow()->GetInteractor());
143 mBoxWidget->AddObserver(vtkCommand::InteractionEvent, mCropBoxCallback);
144 mBoxWidget->AddObserver(vtkCommand::EnableEvent, mCropBoxEnableCallback);
145 mBoxWidget->AddObserver(vtkCommand::DisableEvent, mCropBoxDisableCallback);
149 mBoxWidget->RemoveObserver(vtkCommand::InteractionEvent);
150 mBoxWidget->RemoveObserver(vtkCommand::EnableEvent);
151 mBoxWidget->RemoveObserver(vtkCommand::DisableEvent);
165 if (!mImage->getCropping() && on)
168 mBoxWidget->SetEnabled(on);
176 if (!mImage || !mBoxWidget)
178 return mImage->getCroppingBox();
183 this->setCroppingRegion(bb_d);
184 this->setBoxWidgetSize(bb_d);
195 mImage->setCropping(on);
198 void InteractiveCropper::imageCropChangedSlot()
204 this->setBoxWidgetSize(bb_d);
205 this->updateBoxWidgetInteractor();
207 if (!mImage->getCropping())
218 void InteractiveCropper::imageChangedSlot()
221 mImage = mActiveData->getActive<
Image>();
223 this->imageCropChangedSlot();
231 return mImage->getCropping();
238 return mBoxWidget->GetEnabled();
243 std::vector<int> dimensions;
247 double spacing_x = 1;
248 double spacing_y = 1;
249 double spacing_z = 1;
250 mImage->getBaseVtkImageData()->GetSpacing(spacing_x, spacing_y, spacing_z);
253 int dim_x = (bb.begin()[1] - bb.begin()[0])/spacing_x + 1;
254 int dim_y = (bb.begin()[3] - bb.begin()[2])/spacing_y + 1;
255 int dim_z = (bb.begin()[5] - bb.begin()[4])/spacing_z + 1;
256 dimensions.push_back(dim_x);
257 dimensions.push_back(dim_y);
258 dimensions.push_back(dim_z);
267 if (!mImage || !mBoxWidget)
271 { -0.5, 0.5, -0.5, 0.5, -0.5, 0.5 };
272 DoubleBoundingBox3D bb_unit(bb_hard);
284 DoubleBoundingBox3D InteractiveCropper::getBoxWidgetSize()
286 if (!mImage || !mBoxWidget)
292 { -0.5, 0.5, -0.5, 0.5, -0.5, 0.5 };
293 DoubleBoundingBox3D bb_unit(bb_hard);
307 void InteractiveCropper::setCroppingRegion(DoubleBoundingBox3D bb_d)
311 mImage->setCroppingBox(bb_d);
315 void InteractiveCropper::boxWasShown(
bool val)
327 return mImage->boundingBox();