44 #include <vtkTransform.h>
45 #include <vtkAbstractVolumeMapper.h>
46 #include <vtkVolumeMapper.h>
47 #include <vtkRenderWindow.h>
48 #include <vtkRenderer.h>
49 #include <vtkImageData.h>
50 #include <vtkCommand.h>
51 #include <vtkBoxWidget2.h>
52 #include <vtkBoxWidget.h>
79 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
102 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
117 mActiveData(activeData)
121 connect(mActiveImageProxy.get(), SIGNAL(cropBoxChanged()),
this, SLOT(imageCropChangedSlot()));
124 void InteractiveCropper::initialize()
129 mBoxWidget = vtkBoxWidgetPtr::New();
130 mBoxWidget->RotationEnabledOff();
133 { -1, 1, -1, 1, -1, 1 };
134 mBoxWidget->PlaceWidget(bb_hard);
136 mCropBoxCallback = CropBoxCallbackPtr::New();
137 mCropBoxCallback->SetCropper(
this);
138 mCropBoxEnableCallback = CropBoxEnableCallbackPtr::New();
139 mCropBoxEnableCallback->SetCropper(
true,
this);
140 mCropBoxDisableCallback = CropBoxEnableCallbackPtr::New();
141 mCropBoxDisableCallback->SetCropper(
false,
this);
143 mBoxWidget->SetInteractor(mView->getRenderWindow()->GetInteractor());
145 mBoxWidget->SetEnabled(
false);
151 this->updateBoxWidgetInteractor();
154 void InteractiveCropper::updateBoxWidgetInteractor()
163 mBoxWidget->SetInteractor(mView->getRenderWindow()->GetInteractor());
164 mBoxWidget->AddObserver(vtkCommand::InteractionEvent, mCropBoxCallback);
165 mBoxWidget->AddObserver(vtkCommand::EnableEvent, mCropBoxEnableCallback);
166 mBoxWidget->AddObserver(vtkCommand::DisableEvent, mCropBoxDisableCallback);
170 mBoxWidget->RemoveObserver(vtkCommand::InteractionEvent);
171 mBoxWidget->RemoveObserver(vtkCommand::EnableEvent);
172 mBoxWidget->RemoveObserver(vtkCommand::DisableEvent);
186 if (!mImage->getCropping() && on)
189 mBoxWidget->SetEnabled(on);
197 if (!mImage || !mBoxWidget)
199 return mImage->getCroppingBox();
204 this->setCroppingRegion(bb_d);
205 this->setBoxWidgetSize(bb_d);
216 mImage->setCropping(on);
219 void InteractiveCropper::imageCropChangedSlot()
225 this->setBoxWidgetSize(bb_d);
226 this->updateBoxWidgetInteractor();
228 if (!mImage->getCropping())
239 void InteractiveCropper::imageChangedSlot()
242 mImage = mActiveData->getActive<
Image>();
244 this->imageCropChangedSlot();
252 return mImage->getCropping();
259 return mBoxWidget->GetEnabled();
264 std::vector<int> dimensions;
268 double spacing_x = 1;
269 double spacing_y = 1;
270 double spacing_z = 1;
271 mImage->getBaseVtkImageData()->GetSpacing(spacing_x, spacing_y, spacing_z);
274 int dim_x = (bb.begin()[1] - bb.begin()[0])/spacing_x + 1;
275 int dim_y = (bb.begin()[3] - bb.begin()[2])/spacing_y + 1;
276 int dim_z = (bb.begin()[5] - bb.begin()[4])/spacing_z + 1;
277 dimensions.push_back(dim_x);
278 dimensions.push_back(dim_y);
279 dimensions.push_back(dim_z);
288 if (!mImage || !mBoxWidget)
292 { -0.5, 0.5, -0.5, 0.5, -0.5, 0.5 };
293 DoubleBoundingBox3D bb_unit(bb_hard);
299 transform->SetMatrix(M.getVtkMatrix());
300 mBoxWidget->SetTransform(transform);
305 DoubleBoundingBox3D InteractiveCropper::getBoxWidgetSize()
307 if (!mImage || !mBoxWidget)
313 { -0.5, 0.5, -0.5, 0.5, -0.5, 0.5 };
314 DoubleBoundingBox3D bb_unit(bb_hard);
317 mBoxWidget->GetTransform(transform);
328 void InteractiveCropper::setCroppingRegion(DoubleBoundingBox3D bb_d)
332 mImage->setCroppingBox(bb_d);
336 void InteractiveCropper::boxWasShown(
bool val)
348 return mImage->boundingBox();
DoubleBoundingBox3D transform(const Transform3D &m, const DoubleBoundingBox3D &bb)
virtual void Execute(vtkObject *caller, unsigned long, void *)
InteractiveCropper * mCropper
static CropBoxEnableCallback * New()
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
DoubleBoundingBox3D getBoundingBox()
get BB in data space
boost::shared_ptr< class ActiveData > ActiveDataPtr
boost::shared_ptr< class View > ViewPtr
vtkSmartPointer< class vtkTransform > vtkTransformPtr
void SetCropper(InteractiveCropper *cropper)
Transform3D createTransformNormalize(const DoubleBoundingBox3D &in, const DoubleBoundingBox3D &out)
void useCropping(bool on)
InteractiveCropper * mCropper
bool getShowBoxWidget() const
DoubleBoundingBox3D getMaxBoundingBox()
static ActiveImageProxyPtr New(ActiveDataPtr activeData)
void showBoxWidget(bool on)
virtual void Execute(vtkObject *caller, unsigned long, void *)
static DoubleBoundingBox3D zero()
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
void resetBoundingBox()
set bounding box back to initial size (entire volume)
void setView(ViewPtr view)
adds an interactive box widget to the view. Press 'I' to show
InteractiveCropper(ActiveDataPtr activeData)
void SetCropper(bool val, InteractiveCropper *cropper)
void activeImageChanged(const QString &uid)
The original image changed signal from DataManager.
void setBoundingBox(const DoubleBoundingBox3D &bb_d)
set BB in reference space
static CropBoxCallback * New()
std::vector< int > getDimensions()