43 #include <vtkCamera.h> 44 #include <vtkRenderer.h> 45 #include <vtkRenderWindow.h> 48 #include <QActionGroup> 50 #include <QMouseEvent> 51 #include <QWheelEvent> 84 #include "vtkRenderWindowInteractor.h" 97 mOrientationActionGroup(new QActionGroup(view.get()))
99 qRegisterMetaType<Vector3D>(
"Vector3D");
104 mView->getRenderWindow()->GetInteractor()->Disable();
105 mView->getRenderer()->GetActiveCamera()->SetParallelProjection(
true);
106 double clipDepth = 1.0;
107 double length = clipDepth*10;
108 mView->getRenderer()->GetActiveCamera()->SetPosition(0,0,length);
109 mView->getRenderer()->GetActiveCamera()->SetClippingRange(length-clipDepth, length+0.1);
115 mDataRepContainer->setSliceProxy(mSliceProxy);
116 mDataRepContainer->setView(mView);
119 mViewFollower->setSliceProxy(mSliceProxy);
124 connect(mZoom2D.get(), SIGNAL(zoomChanged()),
this, SLOT(viewportChanged()));
126 connect(
mServices->tracking().get(), SIGNAL(activeToolChanged(
const QString&)),
this, SLOT(activeToolChangedSlot()));
127 connect(mView.get(), SIGNAL(resized(QSize)),
this, SLOT(viewportChanged()));
128 connect(mView.get(), SIGNAL(shown()),
this, SLOT(showSlot()));
129 connect(mView.get(), SIGNAL(mousePress(
int,
int, Qt::MouseButtons)),
this, SLOT(mousePressSlot(
int,
int, Qt::MouseButtons)));
130 connect(mView.get(), SIGNAL(mouseMove(
int,
int, Qt::MouseButtons)),
this, SLOT(mouseMoveSlot(
int,
int, Qt::MouseButtons)));
131 connect(mView.get(), SIGNAL(mouseWheel(
int,
int,
int,
int, Qt::MouseButtons)),
this, SLOT(mouseWheelSlot(
int,
int,
int,
int, Qt::MouseButtons)));
135 this->activeToolChangedSlot();
145 void ViewWrapper2D::changeZoom(
double delta)
150 double zoom = mZoom2D->getFactor();
154 mZoom2D->setFactor(zoom);
160 if(!this->isAnyplane())
166 Vector3D p_s = vpMs.inv().coord(click_vp);
167 Vector3D p_r = sMr.inv().coord(p_s);
172 void ViewWrapper2D::appendToContextMenu(QMenu& contextMenu)
174 contextMenu.addSeparator();
175 mZoom2D->addActionsToMenu(&contextMenu);
177 contextMenu.addSeparator();
178 QAction* showManualTool =
new QAction(
"Show Manual Tool 2D", &contextMenu);
179 showManualTool->setCheckable(
true);
180 showManualTool->setChecked(
settings()->value(
"View2D/showManualTool").toBool());
181 connect(showManualTool, SIGNAL(triggered(
bool)),
this, SLOT(showManualToolSlot(
bool)));
182 contextMenu.addAction(showManualTool);
189 mZoom2D->setGroupData(group);
190 connect(group.get(), SIGNAL(optionsChanged()),
this, SLOT(optionChangedSlot()));
191 this->optionChangedSlot();
194 void ViewWrapper2D::optionChangedSlot()
204 void ViewWrapper2D::addReps()
208 mView->addRep(mOrientationAnnotationRep);
214 mToolRep2D->setSliceProxy(mSliceProxy);
215 mToolRep2D->setUseCrosshair(
true);
216 this->toggleShowManualTool();
219 mPickerGlyphRep->setSliceProxy(mSliceProxy);
222 mPickerGlyphRep->setMesh(
mGroupData->getOptions().mPickerGlyph);
224 mView->addRep(mPickerGlyphRep);
231 if (key ==
"View2D/useGPU2DRendering")
235 if (key ==
"View2D/useLinearInterpolationIn2DRendering")
239 if (key ==
"Navigation/anyplaneViewOffset")
243 if (key ==
"View2D/showManualTool")
245 this->toggleShowManualTool();
249 void ViewWrapper2D::toggleShowManualTool()
251 if (
settings()->value(
"View2D/showManualTool").toBool())
252 mView->addRep(mToolRep2D);
254 mView->removeRep(mToolRep2D);
257 void ViewWrapper2D::removeAndResetSliceRep()
261 mView->removeRep(mSliceRep);
266 void ViewWrapper2D::removeAndResetMultiSliceRep()
270 mView->removeRep(mMultiSliceRep);
271 mMultiSliceRep.reset();
275 bool ViewWrapper2D::createAndAddMultiSliceRep()
279 CX_LOG_WARNING() <<
"ViewWrapper2D::createAndAddMultiSliceRep(): Got no mSharedOpenGLContext";
287 mMultiSliceRep->setSliceProxy(mSliceProxy);
288 mMultiSliceRep->setRenderWindow(mView->getRenderWindow());
290 mView->addRep(mMultiSliceRep);
300 void ViewWrapper2D::recreateMultiSlicer()
302 this->removeAndResetSliceRep();
304 if (!this->useGPU2DRendering())
306 this->removeAndResetMultiSliceRep();
310 if(!this->createAndAddMultiSliceRep())
316 mMultiSliceRep->setImages(this->getImagesToView());
318 mMultiSliceRep->setImages(std::vector<ImagePtr>());
320 this->viewportChanged();
323 std::vector<ImagePtr> ViewWrapper2D::getImagesToView()
327 if(this->isAnyplane())
330 for(
int i = 0; i < streams.size(); ++i)
331 images.push_back(streams[i]->getChangingImage());
336 bool ViewWrapper2D::isAnyplane()
338 PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType();
345 void ViewWrapper2D::viewportChanged()
347 if (!mView->getRenderer()->IsActiveCameraCreated())
350 mView->setZoomFactor(mZoom2D->getFactor());
352 double viewHeight = mView->getViewport_s().range()[1];
353 mView->getRenderer()->GetActiveCamera()->SetParallelScale(viewHeight / 2);
357 double clipDepth = 2.0;
358 double length = clipDepth*10;
359 clipDepth = viewHeight/120 + 1.5;
360 mView->getRenderer()->GetActiveCamera()->SetPosition(0,0,length);
361 mView->getRenderer()->GetActiveCamera()->SetClippingRange(length-clipDepth, length+0.1);
363 mSliceProxy->setToolViewportHeight(viewHeight);
364 double anyplaneViewOffset =
settings()->
value(
"Navigation/anyplaneViewOffset").toDouble();
365 mSliceProxy->initializeFromPlane(mSliceProxy->getComputer().getPlaneType(),
false,
true, viewHeight, anyplaneViewOffset);
370 PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType();
372 mToolRep2D->setViewportData(vpMs, BB_vp);
373 if (mSlicePlanes3DMarker)
375 mSlicePlanes3DMarker->getProxy()->setViewportData(plane, mSliceProxy, BB_s);
379 void ViewWrapper2D::applyViewFollower()
383 QString roiUid =
mGroupData->getOptions().mCameraStyle.mAutoZoomROI;
384 mViewFollower->setAutoZoomROI(roiUid);
385 mViewFollower->setView(this->getViewport_s());
390 this->changeZoom(result.
zoom);
392 mServices->patient()->setCenter(newcenter_r);
399 QSize size = mView->size();
401 Vector3D p1_d(size.width(), size.height(), 0);
406 void ViewWrapper2D::showSlot()
408 activeToolChangedSlot();
414 double viewHeight = mView->getViewport_s().range()[1];
415 mSliceProxy->initializeFromPlane(plane,
false,
true, viewHeight, 0.25);
416 mOrientationAnnotationRep->setSliceProxy(mSliceProxy);
421 ORIENTATION_TYPE ViewWrapper2D::getOrientationType()
const 423 return mSliceProxy->getComputer().getOrientationType();
433 void ViewWrapper2D::imageAdded(
ImagePtr image)
449 image = images.back();
454 bool ViewWrapper2D::useGPU2DRendering()
456 return settings()->
value(
"View2D/useGPU2DRendering").toBool();
459 void ViewWrapper2D::createAndAddSliceRep()
464 mSliceRep->setSliceProxy(mSliceProxy);
465 mView->addRep(mSliceRep);
472 if (this->useGPU2DRendering())
482 QStringList textList;
484 for (
unsigned i = 0; i < mesh.size(); ++i)
487 textList << image->getName();
488 text = textList.join(
"\n");
495 return qstring_cast(mSliceProxy->getComputer().getPlaneType());
498 void ViewWrapper2D::updateItemsFromViewGroup()
507 Vector3D c = image->get_rMd().coord(image->boundingBox().center());
508 mSliceProxy->setDefaultCenter(c);
510 if (this->useGPU2DRendering())
512 this->recreateMultiSlicer();
516 this->removeAndResetMultiSliceRep();
517 this->createAndAddSliceRep();
519 mSliceRep->setImage(image);
524 this->removeAndResetSliceRep();
525 this->removeAndResetMultiSliceRep();
533 this->updateItemsFromViewGroup();
538 mOrientationAnnotationRep->setVisible(
settings()->value(
"View/showOrientationAnnotation").value<bool>());
541 mDataRepContainer->updateSettings();
545 bool isOblique = mSliceProxy->getComputer().getOrientationType() ==
otOBLIQUE;
546 bool useCrosshair =
settings()->
value(
"View2D/showToolCrosshair",
true).toBool();
547 mToolRep2D->setUseCrosshair(!isOblique && useCrosshair);
548 mToolRep2D->setCrosshairColor(
settings()->value(
"View2D/toolCrossHairColor").value<QColor>());
549 mToolRep2D->setTooltipLineColor(
settings()->value(
"View2D/toolColor").value<QColor>());
550 mToolRep2D->setTooltipPointColor(
settings()->value(
"View/toolTipPointColor").value<QColor>());
551 mToolRep2D->setToolOffsetPointColor(
settings()->value(
"View/toolOffsetPointColor").value<QColor>());
552 mToolRep2D->setToolOffsetLineColor(
settings()->value(
"View/toolOffsetLineColor").value<QColor>());
555 this->applyViewFollower();
572 this->dataAdded(data);
574 this->dataRemoved(uid);
577 void ViewWrapper2D::dataAdded(
DataPtr data)
579 if (boost::dynamic_pointer_cast<Image>(data))
581 this->imageAdded(boost::dynamic_pointer_cast<Image>(data));
585 mDataRepContainer->addData(data);
590 void ViewWrapper2D::dataRemoved(
const QString& uid)
592 mDataRepContainer->removeData(uid);
596 void ViewWrapper2D::activeToolChangedSlot()
599 mSliceProxy->setTool(activeTool);
606 void ViewWrapper2D::mousePressSlot(
int x,
int y, Qt::MouseButtons buttons)
608 if (buttons & Qt::LeftButton)
610 Vector3D clickPos_vp = qvp2vp(QPoint(x,y));
611 moveManualTool(clickPos_vp,
Vector3D(0,0,0));
620 void ViewWrapper2D::mouseMoveSlot(
int x,
int y, Qt::MouseButtons buttons)
622 if (buttons & Qt::LeftButton)
624 Vector3D clickPos_vp = qvp2vp(QPoint(x,y));
625 moveManualTool(clickPos_vp, clickPos_vp - mLastClickPos_vp);
635 this->shiftAxisPos(delta_vp);
636 mLastClickPos_vp = vp;
643 void ViewWrapper2D::mouseWheelSlot(
int x,
int y,
int delta,
int orientation, Qt::MouseButtons buttons)
646 double val = log10(mZoom2D->getFactor());
647 val += delta / 120.0 / 20.0;
648 double newZoom = pow(10.0, val);
650 mZoom2D->setFactor(newZoom);
658 Vector3D ViewWrapper2D::qvp2vp(QPoint pos_qvp)
660 QSize size = mView->size();
661 Vector3D pos_vp(pos_qvp.x(), size.height()-1 - pos_qvp.y(), 0.0);
668 void ViewWrapper2D::shiftAxisPos(
Vector3D delta_vp)
670 delta_vp = -delta_vp;
677 Vector3D delta_s = vpMs.inv().vector(delta_vp);
679 Vector3D delta_pr = (rMpr.inv() * sMr.inv()).vector(delta_s);
684 tool->set_prMt(MD * prMt);
690 void ViewWrapper2D::setAxisPos(
Vector3D click_vp)
699 Vector3D tool_t(0, 0, tool->getTooltipOffset());
700 Vector3D tool_s = (sMr * rMpr * prMt).coord(tool_t);
704 Vector3D click_s = vpMs.inv().coord(click_vp);
707 Vector3D cross_s(click_s[0], click_s[1], tool_s[2]);
709 Vector3D delta_s = cross_s - tool_s;
710 Vector3D delta_pr = (rMpr.inv() * sMr.inv()).vector(delta_s);
715 tool->set_prMt(MD * prMt);
721 PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType();
722 mSlicePlanes3DMarker->setProxy(plane, proxy);
727 mSlicePlanes3DMarker->getProxy()->setViewportData(plane, mSliceProxy, this->getViewport_s());
729 mView->addRep(mSlicePlanes3DMarker);
737 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