17 #include <vtkTransform.h> 18 #include <vtkAbstractVolumeMapper.h> 19 #include <vtkVolumeMapper.h> 20 #include <vtkRenderWindow.h> 21 #include <vtkRenderer.h> 22 #include <vtkImageData.h> 23 #include <vtkCommand.h> 24 #include <vtkBoxWidget2.h> 25 #include <vtkBoxWidget.h> 53 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
75 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
94 m_rMd = Transform3D::Identity();
101 mBoxWidget->SetInteractor(NULL);
107 mRenderWindow = renderWindow;
108 this->updateBoxWidgetInteractor();
124 this->updateWidgetFromBox();
134 this->updateWidgetFromBox();
143 this->updateWidgetFromBox();
154 if (mInteractive==on)
157 this->updateWidgetFromBox();
174 void GraphicalBox::updateWidgetFromBox()
176 this->updateBoxWidgetInteractor();
177 this->setBoxWidgetSize(mBox, m_rMd);
180 void GraphicalBox::updateBoxFromWidget()
187 void GraphicalBox::initialize()
192 mBoxWidget = vtkBoxWidgetPtr::New();
193 mBoxWidget->RotationEnabledOff();
196 { -1, 1, -1, 1, -1, 1 };
197 mBoxWidget->PlaceWidget(bb_hard);
199 mGraphicalBoxCallback = GraphicalBoxCallbackPtr::New();
200 mGraphicalBoxCallback->SetCropper(
this);
201 mGraphicalBoxEnableCallback = GraphicalBoxEnableCallbackPtr::New();
202 mGraphicalBoxEnableCallback->SetCropper(
true,
this);
203 mGraphicalBoxDisableCallback = GraphicalBoxEnableCallbackPtr::New();
204 mGraphicalBoxDisableCallback->SetCropper(
false,
this);
206 mBoxWidget->SetInteractor(mRenderWindow->GetInteractor());
208 mBoxWidget->SetEnabled(mVisible);
211 void GraphicalBox::updateBoxWidgetInteractor()
218 mBoxWidget->SetInteractor(mRenderWindow->GetInteractor());
220 if (this->getInteractive())
222 mBoxWidget->AddObserver(vtkCommand::InteractionEvent, mGraphicalBoxCallback);
223 mBoxWidget->AddObserver(vtkCommand::EnableEvent, mGraphicalBoxEnableCallback);
224 mBoxWidget->AddObserver(vtkCommand::DisableEvent, mGraphicalBoxDisableCallback);
227 if (!this->getInteractive())
229 mBoxWidget->RemoveObserver(vtkCommand::InteractionEvent);
230 mBoxWidget->RemoveObserver(vtkCommand::EnableEvent);
231 mBoxWidget->RemoveObserver(vtkCommand::DisableEvent);
234 mBoxWidget->SetScalingEnabled(mInteractive);
235 mBoxWidget->SetTranslationEnabled(mInteractive);
237 mBoxWidget->SetOutlineFaceWires(mInteractive);
238 mBoxWidget->SetOutlineCursorWires(mInteractive);
240 mBoxWidget->HandlesOn();
242 mBoxWidget->HandlesOff();
244 mBoxWidget->SetEnabled(mVisible);
254 double bb_hard[6] = { -0.5, 0.5, -0.5, 0.5, -0.5, 0.5 };
259 if (
similar(M, this->getBoxTransform()))
262 this->setBoxTransform(M);
268 mBoxWidget->GetTransform(transform);
272 void GraphicalBox::setBoxTransform(
const Transform3D& M)
275 transform->SetMatrix(M.getVtkMatrix());
276 mBoxWidget->SetTransform(transform);
289 { -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.