38 #include <vtkTransform.h> 39 #include <vtkAbstractVolumeMapper.h> 40 #include <vtkVolumeMapper.h> 41 #include <vtkRenderWindow.h> 42 #include <vtkRenderer.h> 43 #include <vtkImageData.h> 44 #include <vtkCommand.h> 45 #include <vtkBoxWidget2.h> 46 #include <vtkBoxWidget.h> 74 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
96 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
115 m_rMd = Transform3D::Identity();
122 mBoxWidget->SetInteractor(NULL);
128 mRenderWindow = renderWindow;
129 this->updateBoxWidgetInteractor();
145 this->updateWidgetFromBox();
155 this->updateWidgetFromBox();
164 this->updateWidgetFromBox();
175 if (mInteractive==on)
178 this->updateWidgetFromBox();
195 void GraphicalBox::updateWidgetFromBox()
197 this->updateBoxWidgetInteractor();
198 this->setBoxWidgetSize(mBox, m_rMd);
201 void GraphicalBox::updateBoxFromWidget()
208 void GraphicalBox::initialize()
213 mBoxWidget = vtkBoxWidgetPtr::New();
214 mBoxWidget->RotationEnabledOff();
217 { -1, 1, -1, 1, -1, 1 };
218 mBoxWidget->PlaceWidget(bb_hard);
220 mGraphicalBoxCallback = GraphicalBoxCallbackPtr::New();
221 mGraphicalBoxCallback->SetCropper(
this);
222 mGraphicalBoxEnableCallback = GraphicalBoxEnableCallbackPtr::New();
223 mGraphicalBoxEnableCallback->SetCropper(
true,
this);
224 mGraphicalBoxDisableCallback = GraphicalBoxEnableCallbackPtr::New();
225 mGraphicalBoxDisableCallback->SetCropper(
false,
this);
227 mBoxWidget->SetInteractor(mRenderWindow->GetInteractor());
229 mBoxWidget->SetEnabled(mVisible);
232 void GraphicalBox::updateBoxWidgetInteractor()
239 mBoxWidget->SetInteractor(mRenderWindow->GetInteractor());
241 if (this->getInteractive())
243 mBoxWidget->AddObserver(vtkCommand::InteractionEvent, mGraphicalBoxCallback);
244 mBoxWidget->AddObserver(vtkCommand::EnableEvent, mGraphicalBoxEnableCallback);
245 mBoxWidget->AddObserver(vtkCommand::DisableEvent, mGraphicalBoxDisableCallback);
248 if (!this->getInteractive())
250 mBoxWidget->RemoveObserver(vtkCommand::InteractionEvent);
251 mBoxWidget->RemoveObserver(vtkCommand::EnableEvent);
252 mBoxWidget->RemoveObserver(vtkCommand::DisableEvent);
255 mBoxWidget->SetScalingEnabled(mInteractive);
256 mBoxWidget->SetTranslationEnabled(mInteractive);
258 mBoxWidget->SetOutlineFaceWires(mInteractive);
259 mBoxWidget->SetOutlineCursorWires(mInteractive);
261 mBoxWidget->HandlesOn();
263 mBoxWidget->HandlesOff();
265 mBoxWidget->SetEnabled(mVisible);
275 double bb_hard[6] = { -0.5, 0.5, -0.5, 0.5, -0.5, 0.5 };
280 if (
similar(M, this->getBoxTransform()))
283 this->setBoxTransform(M);
289 mBoxWidget->GetTransform(transform);
293 void GraphicalBox::setBoxTransform(
const Transform3D& M)
296 transform->SetMatrix(M.getVtkMatrix());
297 mBoxWidget->SetTransform(transform);
310 { -0.5, 0.5, -0.5, 0.5, -0.5, 0.5 };
virtual void Execute(vtkObject *caller, unsigned long, void *)
void SetCropper(bool val, GraphicalBox *cropper)
DoubleBoundingBox3D transform(const Transform3D &m, const DoubleBoundingBox3D &bb)
bool getInteractive() const
void SetCropper(GraphicalBox *cropper)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
GraphicalBoxEnableCallback()
vtkSmartPointer< class vtkRenderWindow > vtkRenderWindowPtr
void setBoundingBox(const DoubleBoundingBox3D &bb_d)
set BB in d space
virtual void Execute(vtkObject *caller, unsigned long, void *)
vtkSmartPointer< class vtkTransform > vtkTransformPtr
Transform3D createTransformNormalize(const DoubleBoundingBox3D &in, const DoubleBoundingBox3D &out)
void setPosition(const Transform3D &rMd)
set BB position
DoubleBoundingBox3D getBoundingBox()
get BB in data space
static DoubleBoundingBox3D zero()
DoubleBoundingBox3D getMaxBoundingBox()
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 setRenderWindow(vtkRenderWindowPtr renderWindow)
adds an interactive box widget to the view. Press 'I' to show
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
void setInteractive(bool on)
static GraphicalBoxCallback * New()
static GraphicalBoxEnableCallback * New()
Namespace for all CustusX production code.