43 #include <vtkCamera.h>
44 #include <vtkRenderer.h>
45 #include <vtkRenderWindow.h>
48 #include <QActionGroup>
50 #include <QMouseEvent>
51 #include <QWheelEvent>
85 #include "vtkRenderWindowInteractor.h"
91 #ifndef CX_VTK_OPENGL2
100 mOrientationActionGroup(new QActionGroup(view.get()))
102 qRegisterMetaType<Vector3D>(
"Vector3D");
107 mView->getRenderWindow()->GetInteractor()->Disable();
108 mView->getRenderer()->GetActiveCamera()->SetParallelProjection(
true);
109 double clipDepth = 1.0;
110 double length = clipDepth*10;
111 mView->getRenderer()->GetActiveCamera()->SetPosition(0,0,length);
112 mView->getRenderer()->GetActiveCamera()->SetClippingRange(length-clipDepth, length+0.1);
118 mDataRepContainer->setSliceProxy(mSliceProxy);
119 mDataRepContainer->setView(mView);
122 mViewFollower->setSliceProxy(mSliceProxy);
127 connect(mZoom2D.get(), SIGNAL(zoomChanged()),
this, SLOT(viewportChanged()));
129 connect(
mServices->tracking().get(), SIGNAL(activeToolChanged(
const QString&)),
this, SLOT(activeToolChangedSlot()));
130 connect(mView.get(), SIGNAL(resized(QSize)),
this, SLOT(viewportChanged()));
131 connect(mView.get(), SIGNAL(shown()),
this, SLOT(showSlot()));
132 connect(mView.get(), SIGNAL(mousePress(
int,
int, Qt::MouseButtons)),
this, SLOT(mousePressSlot(
int,
int, Qt::MouseButtons)));
133 connect(mView.get(), SIGNAL(mouseMove(
int,
int, Qt::MouseButtons)),
this, SLOT(mouseMoveSlot(
int,
int, Qt::MouseButtons)));
134 connect(mView.get(), SIGNAL(mouseWheel(
int,
int,
int,
int, Qt::MouseButtons)),
this, SLOT(mouseWheelSlot(
int,
int,
int,
int, Qt::MouseButtons)));
138 this->activeToolChangedSlot();
148 void ViewWrapper2D::changeZoom(
double delta)
153 double zoom = mZoom2D->getFactor();
157 mZoom2D->setFactor(zoom);
163 if(!this->isAnyplane())
169 Vector3D p_s = vpMs.inv().coord(click_vp);
170 Vector3D p_r = sMr.inv().coord(p_s);
175 void ViewWrapper2D::appendToContextMenu(QMenu& contextMenu)
177 contextMenu.addSeparator();
178 mZoom2D->addActionsToMenu(&contextMenu);
185 mZoom2D->setGroupData(group);
186 connect(group.get(), SIGNAL(optionsChanged()),
this, SLOT(optionChangedSlot()));
187 this->optionChangedSlot();
190 void ViewWrapper2D::optionChangedSlot()
200 void ViewWrapper2D::addReps()
204 mView->addRep(mOrientationAnnotationRep);
210 mToolRep2D->setSliceProxy(mSliceProxy);
211 mToolRep2D->setUseCrosshair(
true);
213 mView->addRep(mToolRep2D);
216 mPickerGlyphRep->setSliceProxy(mSliceProxy);
219 mPickerGlyphRep->setMesh(
mGroupData->getOptions().mPickerGlyph);
221 mView->addRep(mPickerGlyphRep);
228 if (key ==
"useGPU2DRendering")
232 if (key ==
"Navigation/anyplaneViewOffset")
238 void ViewWrapper2D::removeAndResetSliceRep()
242 mView->removeRep(mSliceRep);
247 void ViewWrapper2D::removeAndResetMultiSliceRep()
249 #ifndef CX_VTK_OPENGL2
252 mView->removeRep(mMultiSliceRep);
253 mMultiSliceRep.reset();
258 void ViewWrapper2D::createAndAddMultiSliceRep()
260 #ifndef CX_VTK_OPENGL2
265 mMultiSliceRep->setSliceProxy(mSliceProxy);
267 mView->addRep(mMultiSliceRep);
276 void ViewWrapper2D::recreateMultiSlicer()
278 this->removeAndResetSliceRep();
280 if (!this->useGPU2DRendering())
282 this->removeAndResetMultiSliceRep();
286 this->createAndAddMultiSliceRep();
288 #ifndef CX_VTK_OPENGL2
290 mMultiSliceRep->setImages(this->getImagesToView());
292 mMultiSliceRep->setImages(std::vector<ImagePtr>());
295 this->viewportChanged();
298 std::vector<ImagePtr> ViewWrapper2D::getImagesToView()
302 if(this->isAnyplane())
305 for(
int i = 0; i < streams.size(); ++i)
306 images.push_back(streams[i]->getChangingImage());
311 bool ViewWrapper2D::isAnyplane()
313 PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType();
320 void ViewWrapper2D::viewportChanged()
322 if (!mView->getRenderer()->IsActiveCameraCreated())
325 mView->setZoomFactor(mZoom2D->getFactor());
327 double viewHeight = mView->getViewport_s().range()[1];
328 mView->getRenderer()->GetActiveCamera()->SetParallelScale(viewHeight / 2);
332 double clipDepth = 2.0;
333 double length = clipDepth*10;
334 clipDepth = viewHeight/120 + 1.5;
335 mView->getRenderer()->GetActiveCamera()->SetPosition(0,0,length);
336 mView->getRenderer()->GetActiveCamera()->SetClippingRange(length-clipDepth, length+0.1);
338 mSliceProxy->setToolViewportHeight(viewHeight);
339 double anyplaneViewOffset =
settings()->
value(
"Navigation/anyplaneViewOffset").toDouble();
340 mSliceProxy->initializeFromPlane(mSliceProxy->getComputer().getPlaneType(),
false,
true, viewHeight, anyplaneViewOffset);
342 DoubleBoundingBox3D BB_vp = getViewport();
344 DoubleBoundingBox3D BB_s =
transform(vpMs.inv(), BB_vp);
345 PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType();
347 mToolRep2D->setViewportData(vpMs, BB_vp);
348 if (mSlicePlanes3DMarker)
350 mSlicePlanes3DMarker->getProxy()->setViewportData(plane, mSliceProxy, BB_s);
354 void ViewWrapper2D::applyViewFollower()
358 QString roiUid =
mGroupData->getOptions().mCameraStyle.mAutoZoomROI;
359 mViewFollower->setAutoZoomROI(roiUid);
360 mViewFollower->setView(this->getViewport_s());
361 SliceAutoViewportCalculator::ReturnType result = mViewFollower->calculate();
365 this->changeZoom(result.zoom);
366 Vector3D newcenter_r = mViewFollower->findCenter_r_fromShift_s(result.center_shift_s);
367 mServices->patient()->setCenter(newcenter_r);
372 DoubleBoundingBox3D ViewWrapper2D::getViewport()
const
374 QSize size = mView->size();
376 Vector3D p1_d(size.width(), size.height(), 0);
377 DoubleBoundingBox3D BB_vp(p0_d, p1_d);
381 void ViewWrapper2D::showSlot()
383 activeToolChangedSlot();
389 double viewHeight = mView->getViewport_s().range()[1];
390 mSliceProxy->initializeFromPlane(plane,
false,
true, viewHeight, 0.25);
391 mOrientationAnnotationRep->setSliceProxy(mSliceProxy);
396 ORIENTATION_TYPE ViewWrapper2D::getOrientationType()
const
398 return mSliceProxy->getComputer().getOrientationType();
408 void ViewWrapper2D::imageAdded(
ImagePtr image)
424 image = images.back();
429 bool ViewWrapper2D::useGPU2DRendering()
431 #ifdef CX_VTK_OPENGL2
433 #endif //CX_VTK_OPENGL2
438 void ViewWrapper2D::createAndAddSliceRep()
443 mSliceRep->setSliceProxy(mSliceProxy);
444 mView->addRep(mSliceRep);
451 if (this->useGPU2DRendering())
461 QStringList textList;
463 for (
unsigned i = 0; i < mesh.size(); ++i)
466 textList << image->getName();
467 text = textList.join(
"\n");
474 return qstring_cast(mSliceProxy->getComputer().getPlaneType());
477 void ViewWrapper2D::updateItemsFromViewGroup()
486 Vector3D c = image->get_rMd().coord(image->boundingBox().center());
487 mSliceProxy->setDefaultCenter(c);
489 if (this->useGPU2DRendering())
491 this->recreateMultiSlicer();
495 this->removeAndResetMultiSliceRep();
496 this->createAndAddSliceRep();
498 mSliceRep->setImage(image);
503 this->removeAndResetSliceRep();
504 this->removeAndResetMultiSliceRep();
512 this->updateItemsFromViewGroup();
517 mOrientationAnnotationRep->setVisible(
settings()->value(
"View/showOrientationAnnotation").value<bool>());
520 mDataRepContainer->updateSettings();
524 bool isOblique = mSliceProxy->getComputer().getOrientationType() ==
otOBLIQUE;
525 bool useCrosshair =
settings()->
value(
"View/toolCrosshair",
true).toBool();
526 mToolRep2D->setUseCrosshair(!isOblique && useCrosshair);
529 this->applyViewFollower();
546 this->dataAdded(data);
548 this->dataRemoved(uid);
551 void ViewWrapper2D::dataAdded(
DataPtr data)
553 if (boost::dynamic_pointer_cast<Image>(data))
555 this->imageAdded(boost::dynamic_pointer_cast<Image>(data));
559 mDataRepContainer->addData(data);
564 void ViewWrapper2D::dataRemoved(
const QString& uid)
566 mDataRepContainer->removeData(uid);
570 void ViewWrapper2D::activeToolChangedSlot()
573 mSliceProxy->setTool(activeTool);
580 void ViewWrapper2D::mousePressSlot(
int x,
int y, Qt::MouseButtons buttons)
582 if (buttons & Qt::LeftButton)
584 Vector3D clickPos_vp = qvp2vp(QPoint(x,y));
585 moveManualTool(clickPos_vp,
Vector3D(0,0,0));
594 void ViewWrapper2D::mouseMoveSlot(
int x,
int y, Qt::MouseButtons buttons)
596 if (buttons & Qt::LeftButton)
598 Vector3D clickPos_vp = qvp2vp(QPoint(x,y));
599 moveManualTool(clickPos_vp, clickPos_vp - mLastClickPos_vp);
609 this->shiftAxisPos(delta_vp);
610 mLastClickPos_vp = vp;
617 void ViewWrapper2D::mouseWheelSlot(
int x,
int y,
int delta,
int orientation, Qt::MouseButtons buttons)
620 double val = log10(mZoom2D->getFactor());
621 val += delta / 120.0 / 20.0;
622 double newZoom = pow(10.0, val);
624 mZoom2D->setFactor(newZoom);
632 Vector3D ViewWrapper2D::qvp2vp(QPoint pos_qvp)
634 QSize size = mView->size();
635 Vector3D pos_vp(pos_qvp.x(), size.height()-1 - pos_qvp.y(), 0.0);
642 void ViewWrapper2D::shiftAxisPos(
Vector3D delta_vp)
644 delta_vp = -delta_vp;
651 Vector3D delta_s = vpMs.inv().vector(delta_vp);
653 Vector3D delta_pr = (rMpr.inv() * sMr.inv()).vector(delta_s);
658 tool->set_prMt(MD * prMt);
664 void ViewWrapper2D::setAxisPos(
Vector3D click_vp)
673 Vector3D tool_t(0, 0, tool->getTooltipOffset());
674 Vector3D tool_s = (sMr * rMpr * prMt).coord(tool_t);
678 Vector3D click_s = vpMs.inv().coord(click_vp);
681 Vector3D cross_s(click_s[0], click_s[1], tool_s[2]);
683 Vector3D delta_s = cross_s - tool_s;
684 Vector3D delta_pr = (rMpr.inv() * sMr.inv()).vector(delta_s);
689 tool->set_prMt(MD * prMt);
695 PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType();
696 mSlicePlanes3DMarker->setProxy(plane, proxy);
701 mSlicePlanes3DMarker->getProxy()->setViewportData(plane, mSliceProxy, this->getViewport_s());
703 mView->addRep(mSlicePlanes3DMarker);
QString qstring_cast(const T &val)
DoubleBoundingBox3D transform(const Transform3D &m, const DoubleBoundingBox3D &bb)
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
static SliceProxyPtr create(PatientModelServicePtr dataManager)
boost::shared_ptr< class SlicePlanesProxy > SlicePlanesProxyPtr
virtual void videoSourcesChangedSlot()
virtual QString getViewDescription()
otOBLIQUE
orient planes relative to the tool space
boost::shared_ptr< class VisServices > VisServicesPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
virtual ViewPtr getView()
boost::shared_ptr< class Image > ImagePtr
Superclass for ViewWrappers.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
static Texture3DSlicerRepPtr New(const QString &uid="")
boost::shared_ptr< class View > ViewPtr
virtual QString getDataDescription()
virtual void setViewGroup(ViewGroupDataPtr group)
static DataViewProperties createSlice2D()
static SlicePlanes3DMarkerIn2DRepPtr New(const QString &uid="")
static OrientationAnnotationSmartRepPtr New(const QString &uid="")
virtual void setViewGroup(ViewGroupDataPtr group)
boost::shared_ptr< class Data > DataPtr
virtual void updateView()
static QString findConfigFolder(QString pathRelativeToConfigRoot, QString alternativeAbsolutePath="")
void settingsChangedSlot(QString key)
otORTHOGONAL
orient planes relative to the image/reference space.
ViewGroupDataPtr mGroupData
static SliceRepSWPtr New(const QString &uid="")
void videoAddedToTrackedStream()
Transform3D createTransformTranslate(const Vector3D &translation)
virtual void dataViewPropertiesChangedSlot(QString uid)
virtual void initializePlane(PLANE_TYPE plane)
virtual void settingsChangedSlot(QString key)
Settings * settings()
Shortcut for accessing the settings instance.
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.
virtual void setSlicePlanesProxy(SlicePlanesProxyPtr proxy)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
static GeometricRep2DPtr New(const QString &uid="")
void samplePoint(Vector3D click_vp)
QStringList getAllDataNames(DataViewProperties properties) const
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
RealScalar length() const
virtual void updateView()
ImagePtr getImageToDisplay()
ptANYPLANE
a plane aligned with the tool base plane
void connectContextMenu(ViewPtr view)
static ViewFollowerPtr create(PatientModelServicePtr dataManager)
ViewWrapper2D(ViewPtr view, VisServicesPtr backend)
void pointSampled(Vector3D p_r)
boost::shared_ptr< class Tool > ToolPtr