22 #include <vtkCamera.h> 23 #include <vtkRenderer.h> 24 #include <vtkRenderWindow.h> 27 #include <QActionGroup> 29 #include <QMouseEvent> 30 #include <QWheelEvent> 61 #include "vtkRenderWindowInteractor.h" 74 mOrientationActionGroup(new QActionGroup(view.get()))
76 qRegisterMetaType<Vector3D>(
"Vector3D");
81 mView->getRenderWindow()->GetInteractor()->Disable();
82 mView->getRenderer()->GetActiveCamera()->SetParallelProjection(
true);
83 double clipDepth = 1.0;
84 double length = clipDepth*10;
85 mView->getRenderer()->GetActiveCamera()->SetPosition(0,0,length);
86 mView->getRenderer()->GetActiveCamera()->SetClippingRange(length-clipDepth, length+0.1);
92 mDataRepContainer->setSliceProxy(mSliceProxy);
93 mDataRepContainer->setView(mView);
96 mViewFollower->setSliceProxy(mSliceProxy);
101 connect(mZoom2D.get(), SIGNAL(zoomChanged()),
this, SLOT(viewportChanged()));
103 connect(
mServices->tracking().get(), SIGNAL(activeToolChanged(
const QString&)),
this, SLOT(activeToolChangedSlot()));
104 connect(mView.get(), SIGNAL(resized(QSize)),
this, SLOT(viewportChanged()));
105 connect(mView.get(), SIGNAL(shown()),
this, SLOT(showSlot()));
106 connect(mView.get(), SIGNAL(mousePress(
int,
int, Qt::MouseButtons)),
this, SLOT(mousePressSlot(
int,
int, Qt::MouseButtons)));
107 connect(mView.get(), SIGNAL(mouseMove(
int,
int, Qt::MouseButtons)),
this, SLOT(mouseMoveSlot(
int,
int, Qt::MouseButtons)));
108 connect(mView.get(), SIGNAL(mouseWheel(
int,
int,
int,
int, Qt::MouseButtons)),
this, SLOT(mouseWheelSlot(
int,
int,
int,
int, Qt::MouseButtons)));
112 this->activeToolChangedSlot();
122 void ViewWrapper2D::changeZoom(
double delta)
127 double zoom = mZoom2D->getFactor();
131 mZoom2D->setFactor(zoom);
137 if(!this->isAnyplane())
143 Vector3D p_s = vpMs.inv().coord(click_vp);
144 Vector3D p_r = sMr.inv().coord(p_s);
149 void ViewWrapper2D::appendToContextMenu(QMenu& contextMenu)
151 contextMenu.addSeparator();
152 mZoom2D->addActionsToMenu(&contextMenu);
154 contextMenu.addSeparator();
155 QAction* showManualTool =
new QAction(
"Show Manual Tool 2D", &contextMenu);
156 showManualTool->setCheckable(
true);
157 showManualTool->setChecked(
settings()->value(
"View2D/showManualTool").toBool());
158 showManualTool->setToolTip(
"Turn on/off visualization of the vire cross in 2D");
159 connect(showManualTool, SIGNAL(triggered(
bool)),
this, SLOT(showManualToolSlot(
bool)));
160 contextMenu.addAction(showManualTool);
167 mZoom2D->setGroupData(group);
168 connect(group.get(), SIGNAL(optionsChanged()),
this, SLOT(optionChangedSlot()));
169 this->optionChangedSlot();
172 void ViewWrapper2D::optionChangedSlot()
182 void ViewWrapper2D::addReps()
186 mView->addRep(mOrientationAnnotationRep);
192 mToolRep2D->setSliceProxy(mSliceProxy);
193 mToolRep2D->setUseCrosshair(
true);
194 this->toggleShowManualTool();
197 mPickerGlyphRep->setSliceProxy(mSliceProxy);
200 mPickerGlyphRep->setMesh(
mGroupData->getOptions().mPickerGlyph);
202 mView->addRep(mPickerGlyphRep);
209 if (key ==
"View2D/useGPU2DRendering")
213 if (key ==
"View2D/useLinearInterpolationIn2DRendering")
217 if (key ==
"Navigation/anyplaneViewOffset")
221 if (key ==
"View2D/showManualTool")
223 this->toggleShowManualTool();
227 void ViewWrapper2D::toggleShowManualTool()
229 if (
settings()->value(
"View2D/showManualTool").toBool())
230 mView->addRep(mToolRep2D);
232 mView->removeRep(mToolRep2D);
235 void ViewWrapper2D::removeAndResetSliceRep()
239 mView->removeRep(mSliceRep);
244 void ViewWrapper2D::removeAndResetMultiSliceRep()
248 mView->removeRep(mMultiSliceRep);
249 mMultiSliceRep.reset();
253 bool ViewWrapper2D::createAndAddMultiSliceRep()
257 CX_LOG_WARNING() <<
"ViewWrapper2D::createAndAddMultiSliceRep(): Got no mSharedOpenGLContext";
265 mMultiSliceRep->setSliceProxy(mSliceProxy);
266 mMultiSliceRep->setRenderWindow(mView->getRenderWindow());
268 mView->addRep(mMultiSliceRep);
278 void ViewWrapper2D::recreateMultiSlicer()
280 this->removeAndResetSliceRep();
282 if (!this->useGPU2DRendering())
284 this->removeAndResetMultiSliceRep();
288 if(!this->createAndAddMultiSliceRep())
294 mMultiSliceRep->setImages(this->getImagesToView());
296 mMultiSliceRep->setImages(std::vector<ImagePtr>());
298 this->viewportChanged();
301 std::vector<ImagePtr> ViewWrapper2D::getImagesToView()
303 bool include2D = this->isAnyplane();
308 bool ViewWrapper2D::isAnyplane()
310 PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType();
317 void ViewWrapper2D::viewportChanged()
319 if (!mView->getRenderer()->IsActiveCameraCreated())
322 mView->setZoomFactor(mZoom2D->getFactor());
324 double viewHeight = mView->getViewport_s().range()[1];
325 mView->getRenderer()->GetActiveCamera()->SetParallelScale(viewHeight / 2);
329 double clipDepth = 2.0;
330 double length = clipDepth*10;
331 clipDepth = viewHeight/120 + 1.5;
332 mView->getRenderer()->GetActiveCamera()->SetPosition(0,0,length);
333 mView->getRenderer()->GetActiveCamera()->SetClippingRange(length-clipDepth, length+0.1);
335 mSliceProxy->setToolViewportHeight(viewHeight);
336 double anyplaneViewOffset =
settings()->
value(
"Navigation/anyplaneViewOffset").toDouble();
337 mSliceProxy->initializeFromPlane(mSliceProxy->getComputer().getPlaneType(),
false,
true, viewHeight, anyplaneViewOffset);
342 PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType();
344 mToolRep2D->setViewportData(vpMs, BB_vp);
345 if (mSlicePlanes3DMarker)
347 mSlicePlanes3DMarker->getProxy()->setViewportData(plane, mSliceProxy, BB_s);
351 void ViewWrapper2D::applyViewFollower()
355 QString roiUid =
mGroupData->getOptions().mCameraStyle.mAutoZoomROI;
356 mViewFollower->setAutoZoomROI(roiUid);
357 mViewFollower->setView(this->getViewport_s());
362 this->changeZoom(result.
zoom);
364 mServices->patient()->setCenter(newcenter_r);
371 QSize size = mView->size();
373 Vector3D p1_d(size.width(), size.height(), 0);
378 void ViewWrapper2D::showSlot()
380 activeToolChangedSlot();
386 double viewHeight = mView->getViewport_s().range()[1];
387 mSliceProxy->initializeFromPlane(plane,
false,
true, viewHeight, 0.25);
388 mOrientationAnnotationRep->setSliceProxy(mSliceProxy);
393 ORIENTATION_TYPE ViewWrapper2D::getOrientationType()
const 395 return mSliceProxy->getComputer().getOrientationType();
405 void ViewWrapper2D::imageAdded(
ImagePtr image)
421 image = images.back();
426 bool ViewWrapper2D::useGPU2DRendering()
428 return settings()->
value(
"View2D/useGPU2DRendering").toBool();
431 void ViewWrapper2D::createAndAddSliceRep()
436 mSliceRep->setSliceProxy(mSliceProxy);
437 mView->addRep(mSliceRep);
444 if (this->useGPU2DRendering())
454 QStringList textList;
456 for (
unsigned i = 0; i < mesh.size(); ++i)
459 textList << image->getName();
460 text = textList.join(
"\n");
467 return qstring_cast(mSliceProxy->getComputer().getPlaneType());
470 void ViewWrapper2D::updateItemsFromViewGroup()
479 Vector3D c = image->get_rMd().coord(image->boundingBox().center());
480 mSliceProxy->setDefaultCenter(c);
482 if (this->useGPU2DRendering())
484 this->recreateMultiSlicer();
488 this->removeAndResetMultiSliceRep();
489 this->createAndAddSliceRep();
491 mSliceRep->setImage(image);
496 this->removeAndResetSliceRep();
497 this->removeAndResetMultiSliceRep();
505 this->updateItemsFromViewGroup();
510 mOrientationAnnotationRep->setVisible(
settings()->value(
"View/showOrientationAnnotation").value<bool>());
513 mDataRepContainer->updateSettings();
517 bool isOblique = mSliceProxy->getComputer().getOrientationType() ==
otOBLIQUE;
518 bool useCrosshair =
settings()->
value(
"View2D/showToolCrosshair",
true).toBool();
519 mToolRep2D->setUseCrosshair(!isOblique && useCrosshair);
520 mToolRep2D->setCrosshairColor(
settings()->value(
"View2D/toolCrossHairColor").value<QColor>());
521 mToolRep2D->setTooltipLineColor(
settings()->value(
"View2D/toolColor").value<QColor>());
522 mToolRep2D->setTooltipPointColor(
settings()->value(
"View/toolTipPointColor").value<QColor>());
523 mToolRep2D->setToolOffsetPointColor(
settings()->value(
"View/toolOffsetPointColor").value<QColor>());
524 mToolRep2D->setToolOffsetLineColor(
settings()->value(
"View/toolOffsetLineColor").value<QColor>());
527 this->applyViewFollower();
544 this->dataAdded(data);
546 this->dataRemoved(uid);
549 void ViewWrapper2D::dataAdded(
DataPtr data)
551 if (boost::dynamic_pointer_cast<Image>(data))
553 this->imageAdded(boost::dynamic_pointer_cast<Image>(data));
557 mDataRepContainer->addData(data);
562 void ViewWrapper2D::dataRemoved(
const QString& uid)
564 mDataRepContainer->removeData(uid);
568 void ViewWrapper2D::activeToolChangedSlot()
572 mSliceProxy->setTool(controllingTool);
579 void ViewWrapper2D::mousePressSlot(
int x,
int y, Qt::MouseButtons buttons)
581 if (buttons & Qt::LeftButton)
583 Vector3D clickPos_vp = qvp2vp(QPoint(x,y));
584 moveManualTool(clickPos_vp,
Vector3D(0,0,0));
593 void ViewWrapper2D::mouseMoveSlot(
int x,
int y, Qt::MouseButtons buttons)
595 if (buttons & Qt::LeftButton)
597 Vector3D clickPos_vp = qvp2vp(QPoint(x,y));
598 moveManualTool(clickPos_vp, clickPos_vp - mLastClickPos_vp);
608 this->shiftAxisPos(delta_vp);
609 mLastClickPos_vp = vp;
616 void ViewWrapper2D::mouseWheelSlot(
int x,
int y,
int delta,
int orientation, Qt::MouseButtons buttons)
619 double val = log10(mZoom2D->getFactor());
620 val += delta / 120.0 / 20.0;
621 double newZoom = pow(10.0, val);
623 mZoom2D->setFactor(newZoom);
631 Vector3D ViewWrapper2D::qvp2vp(QPoint pos_qvp)
633 QSize size = mView->size();
634 Vector3D pos_vp(pos_qvp.x(), size.height()-1 - pos_qvp.y(), 0.0);
641 void ViewWrapper2D::shiftAxisPos(
Vector3D delta_vp)
643 delta_vp = -delta_vp;
650 Vector3D delta_s = vpMs.inv().vector(delta_vp);
652 Vector3D delta_pr = (rMpr.inv() * sMr.inv()).vector(delta_s);
657 tool->set_prMt(MD * prMt);
663 void ViewWrapper2D::setAxisPos(
Vector3D click_vp)
672 Vector3D tool_t(0, 0, tool->getTooltipOffset());
673 Vector3D tool_s = (sMr * rMpr * prMt).coord(tool_t);
677 Vector3D click_s = vpMs.inv().coord(click_vp);
680 Vector3D cross_s(click_s[0], click_s[1], tool_s[2]);
682 Vector3D delta_s = cross_s - tool_s;
683 Vector3D delta_pr = (rMpr.inv() * sMr.inv()).vector(delta_s);
688 tool->set_prMt(MD * prMt);
694 PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType();
695 mSlicePlanes3DMarker->setProxy(plane, proxy);
700 mSlicePlanes3DMarker->getProxy()->setViewportData(plane, mSliceProxy, this->getViewport_s());
702 mView->addRep(mSlicePlanes3DMarker);
710 void ViewWrapper2D::showManualToolSlot(
bool visible)
QString qstring_cast(const T &val)
ToolPtr getControllingTool()
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.
SharedOpenGLContextPtr mSharedOpenGLContext
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
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="")
void setValue(const QString &key, const QVariant &value)
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 Texture3DSlicerRepPtr New(SharedOpenGLContextPtr context, const QString &uid="")
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)
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr