22 #include <vtkCamera.h> 23 #include <vtkRenderer.h> 24 #include <vtkRenderWindow.h> 27 #include <QActionGroup> 29 #include <QMouseEvent> 30 #include <QWheelEvent> 63 #include "vtkRenderWindowInteractor.h" 76 mOrientationActionGroup(new QActionGroup(view.get()))
78 qRegisterMetaType<Vector3D>(
"Vector3D");
83 mView->getRenderWindow()->GetInteractor()->Disable();
84 mView->getRenderer()->GetActiveCamera()->SetParallelProjection(
true);
85 double clipDepth = 1.0;
86 double length = clipDepth*10;
87 mView->getRenderer()->GetActiveCamera()->SetPosition(0,0,length);
88 mView->getRenderer()->GetActiveCamera()->SetClippingRange(length-clipDepth, length+0.1);
94 mDataRepContainer->setSliceProxy(mSliceProxy);
95 mDataRepContainer->setView(mView);
98 mViewFollower->setSliceProxy(mSliceProxy);
103 connect(mZoom2D.get(), SIGNAL(zoomChanged()),
this, SLOT(viewportChanged()));
105 connect(
mServices->tracking().get(), SIGNAL(activeToolChanged(
const QString&)),
this, SLOT(activeToolChangedSlot()));
106 connect(mView.get(), SIGNAL(resized(QSize)),
this, SLOT(viewportChanged()));
107 connect(mView.get(), SIGNAL(shown()),
this, SLOT(showSlot()));
108 connect(mView.get(), SIGNAL(mousePress(
int,
int, Qt::MouseButtons)),
this, SLOT(mousePressSlot(
int,
int, Qt::MouseButtons)));
109 connect(mView.get(), SIGNAL(mouseMove(
int,
int, Qt::MouseButtons)),
this, SLOT(mouseMoveSlot(
int,
int, Qt::MouseButtons)));
110 connect(mView.get(), SIGNAL(mouseWheel(
int,
int,
int,
int, Qt::MouseButtons)),
this, SLOT(mouseWheelSlot(
int,
int,
int,
int, Qt::MouseButtons)));
114 this->activeToolChangedSlot();
124 void ViewWrapper2D::changeZoom(
double delta)
129 double zoom = mZoom2D->getFactor();
133 mZoom2D->setFactor(zoom);
139 if(!this->isAnyplane())
145 Vector3D p_s = vpMs.inv().coord(click_vp);
146 Vector3D p_r = sMr.inv().coord(p_s);
151 void ViewWrapper2D::appendToContextMenu(QMenu& contextMenu)
153 contextMenu.addSeparator();
154 mZoom2D->addActionsToMenu(&contextMenu);
156 contextMenu.addSeparator();
157 QAction* showManualTool =
new QAction(
"Show Manual Tool 2D", &contextMenu);
158 showManualTool->setCheckable(
true);
159 showManualTool->setChecked(
settings()->value(
"View2D/showManualTool").toBool());
160 connect(showManualTool, SIGNAL(triggered(
bool)),
this, SLOT(showManualToolSlot(
bool)));
161 contextMenu.addAction(showManualTool);
168 mZoom2D->setGroupData(group);
169 connect(group.get(), SIGNAL(optionsChanged()),
this, SLOT(optionChangedSlot()));
170 this->optionChangedSlot();
173 void ViewWrapper2D::optionChangedSlot()
183 void ViewWrapper2D::addReps()
187 mView->addRep(mOrientationAnnotationRep);
193 mToolRep2D->setSliceProxy(mSliceProxy);
194 mToolRep2D->setUseCrosshair(
true);
195 this->toggleShowManualTool();
198 mPickerGlyphRep->setSliceProxy(mSliceProxy);
201 mPickerGlyphRep->setMesh(
mGroupData->getOptions().mPickerGlyph);
203 mView->addRep(mPickerGlyphRep);
210 if (key ==
"View2D/useGPU2DRendering")
214 if (key ==
"View2D/useLinearInterpolationIn2DRendering")
218 if (key ==
"Navigation/anyplaneViewOffset")
222 if (key ==
"View2D/showManualTool")
224 this->toggleShowManualTool();
228 void ViewWrapper2D::toggleShowManualTool()
230 if (
settings()->value(
"View2D/showManualTool").toBool())
231 mView->addRep(mToolRep2D);
233 mView->removeRep(mToolRep2D);
236 void ViewWrapper2D::removeAndResetSliceRep()
240 mView->removeRep(mSliceRep);
245 void ViewWrapper2D::removeAndResetMultiSliceRep()
249 mView->removeRep(mMultiSliceRep);
250 mMultiSliceRep.reset();
254 bool ViewWrapper2D::createAndAddMultiSliceRep()
258 CX_LOG_WARNING() <<
"ViewWrapper2D::createAndAddMultiSliceRep(): Got no mSharedOpenGLContext";
266 mMultiSliceRep->setSliceProxy(mSliceProxy);
267 mMultiSliceRep->setRenderWindow(mView->getRenderWindow());
269 mView->addRep(mMultiSliceRep);
279 void ViewWrapper2D::recreateMultiSlicer()
281 this->removeAndResetSliceRep();
283 if (!this->useGPU2DRendering())
285 this->removeAndResetMultiSliceRep();
289 if(!this->createAndAddMultiSliceRep())
295 mMultiSliceRep->setImages(this->getImagesToView());
297 mMultiSliceRep->setImages(std::vector<ImagePtr>());
299 this->viewportChanged();
302 std::vector<ImagePtr> ViewWrapper2D::getImagesToView()
304 bool include2D = this->isAnyplane();
309 bool ViewWrapper2D::isAnyplane()
311 PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType();
318 void ViewWrapper2D::viewportChanged()
320 if (!mView->getRenderer()->IsActiveCameraCreated())
323 mView->setZoomFactor(mZoom2D->getFactor());
325 double viewHeight = mView->getViewport_s().range()[1];
326 mView->getRenderer()->GetActiveCamera()->SetParallelScale(viewHeight / 2);
330 double clipDepth = 2.0;
331 double length = clipDepth*10;
332 clipDepth = viewHeight/120 + 1.5;
333 mView->getRenderer()->GetActiveCamera()->SetPosition(0,0,length);
334 mView->getRenderer()->GetActiveCamera()->SetClippingRange(length-clipDepth, length+0.1);
336 mSliceProxy->setToolViewportHeight(viewHeight);
337 double anyplaneViewOffset =
settings()->
value(
"Navigation/anyplaneViewOffset").toDouble();
338 mSliceProxy->initializeFromPlane(mSliceProxy->getComputer().getPlaneType(),
false,
true, viewHeight, anyplaneViewOffset);
343 PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType();
345 mToolRep2D->setViewportData(vpMs, BB_vp);
346 if (mSlicePlanes3DMarker)
348 mSlicePlanes3DMarker->getProxy()->setViewportData(plane, mSliceProxy, BB_s);
352 void ViewWrapper2D::applyViewFollower()
356 QString roiUid =
mGroupData->getOptions().mCameraStyle.mAutoZoomROI;
357 mViewFollower->setAutoZoomROI(roiUid);
358 mViewFollower->setView(this->getViewport_s());
363 this->changeZoom(result.
zoom);
365 mServices->patient()->setCenter(newcenter_r);
372 QSize size = mView->size();
374 Vector3D p1_d(size.width(), size.height(), 0);
379 void ViewWrapper2D::showSlot()
381 activeToolChangedSlot();
387 double viewHeight = mView->getViewport_s().range()[1];
388 mSliceProxy->initializeFromPlane(plane,
false,
true, viewHeight, 0.25);
389 mOrientationAnnotationRep->setSliceProxy(mSliceProxy);
394 ORIENTATION_TYPE ViewWrapper2D::getOrientationType()
const 396 return mSliceProxy->getComputer().getOrientationType();
406 void ViewWrapper2D::imageAdded(
ImagePtr image)
422 image = images.back();
427 bool ViewWrapper2D::useGPU2DRendering()
429 return settings()->
value(
"View2D/useGPU2DRendering").toBool();
432 void ViewWrapper2D::createAndAddSliceRep()
437 mSliceRep->setSliceProxy(mSliceProxy);
438 mView->addRep(mSliceRep);
445 if (this->useGPU2DRendering())
455 QStringList textList;
457 for (
unsigned i = 0; i < mesh.size(); ++i)
460 textList << image->getName();
461 text = textList.join(
"\n");
468 return qstring_cast(mSliceProxy->getComputer().getPlaneType());
471 void ViewWrapper2D::updateItemsFromViewGroup()
480 Vector3D c = image->get_rMd().coord(image->boundingBox().center());
481 mSliceProxy->setDefaultCenter(c);
483 if (this->useGPU2DRendering())
485 this->recreateMultiSlicer();
489 this->removeAndResetMultiSliceRep();
490 this->createAndAddSliceRep();
492 mSliceRep->setImage(image);
497 this->removeAndResetSliceRep();
498 this->removeAndResetMultiSliceRep();
506 this->updateItemsFromViewGroup();
511 mOrientationAnnotationRep->setVisible(
settings()->value(
"View/showOrientationAnnotation").value<bool>());
514 mDataRepContainer->updateSettings();
518 bool isOblique = mSliceProxy->getComputer().getOrientationType() ==
otOBLIQUE;
519 bool useCrosshair =
settings()->
value(
"View2D/showToolCrosshair",
true).toBool();
520 mToolRep2D->setUseCrosshair(!isOblique && useCrosshair);
521 mToolRep2D->setCrosshairColor(
settings()->value(
"View2D/toolCrossHairColor").value<QColor>());
522 mToolRep2D->setTooltipLineColor(
settings()->value(
"View2D/toolColor").value<QColor>());
523 mToolRep2D->setTooltipPointColor(
settings()->value(
"View/toolTipPointColor").value<QColor>());
524 mToolRep2D->setToolOffsetPointColor(
settings()->value(
"View/toolOffsetPointColor").value<QColor>());
525 mToolRep2D->setToolOffsetLineColor(
settings()->value(
"View/toolOffsetLineColor").value<QColor>());
528 this->applyViewFollower();
545 this->dataAdded(data);
547 this->dataRemoved(uid);
550 void ViewWrapper2D::dataAdded(
DataPtr data)
552 if (boost::dynamic_pointer_cast<Image>(data))
554 this->imageAdded(boost::dynamic_pointer_cast<Image>(data));
558 mDataRepContainer->addData(data);
563 void ViewWrapper2D::dataRemoved(
const QString& uid)
565 mDataRepContainer->removeData(uid);
569 void ViewWrapper2D::activeToolChangedSlot()
572 mSliceProxy->setTool(activeTool);
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)
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