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 };
278 transform->SetMatrix(M.getVtkMatrix());
279 mBoxWidget->SetTransform(transform);
286 if (!mImage || !mBoxWidget)
292 { -0.5, 0.5, -0.5, 0.5, -0.5, 0.5 };
296 mBoxWidget->GetTransform(transform);
311 mImage->setCroppingBox(bb_d);
315 void InteractiveCropper::boxWasShown(
bool val)
327 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()
Namespace for all CustusX production code.