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"
90 #ifndef CX_VTK_OPENGL2
99 mOrientationActionGroup(new QActionGroup(view.get()))
101 qRegisterMetaType<Vector3D>(
"Vector3D");
106 mView->getRenderWindow()->GetInteractor()->Disable();
107 mView->getRenderer()->GetActiveCamera()->SetParallelProjection(
true);
108 double clipDepth = 1.0;
109 double length = clipDepth*10;
110 mView->getRenderer()->GetActiveCamera()->SetPosition(0,0,length);
111 mView->getRenderer()->GetActiveCamera()->SetClippingRange(length-clipDepth, length+0.1);
112 connect(
settings(), SIGNAL(valueChangedFor(QString)),
this, SLOT(settingsChangedSlot(QString)));
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();
150 if(!this->isAnyplane())
156 Vector3D p_s = vpMs.inv().coord(click_vp);
157 Vector3D p_r = sMr.inv().coord(p_s);
162 void ViewWrapper2D::appendToContextMenu(QMenu& contextMenu)
164 contextMenu.addSeparator();
165 mZoom2D->addActionsToMenu(&contextMenu);
172 mZoom2D->setGroupData(group);
173 connect(group.get(), SIGNAL(optionsChanged()),
this, SLOT(optionChangedSlot()));
174 this->optionChangedSlot();
177 void ViewWrapper2D::optionChangedSlot()
187 void ViewWrapper2D::addReps()
191 mView->addRep(mOrientationAnnotationRep);
195 mPlaneTypeText->addText(QColor(Qt::green),
"not initialized",
Vector3D(0.98, 0.02, 0.0));
196 mView->addRep(mPlaneTypeText);
200 mDataNameText->addText(QColor(Qt::green),
"not initialized",
Vector3D(0.02, 0.02, 0.0));
201 mView->addRep(mDataNameText);
205 mToolRep2D->setSliceProxy(mSliceProxy);
206 mToolRep2D->setUseCrosshair(
true);
208 mView->addRep(mToolRep2D);
211 mPickerGlyphRep->setSliceProxy(mSliceProxy);
214 mPickerGlyphRep->setMesh(
mGroupData->getOptions().mPickerGlyph);
216 mView->addRep(mPickerGlyphRep);
219 void ViewWrapper2D::settingsChangedSlot(QString key)
221 if (key ==
"View/showDataText")
225 if (key ==
"View/showOrientationAnnotation")
229 if (key ==
"useGPU2DRendering")
233 if (key ==
"Navigation/anyplaneViewOffset")
240 void ViewWrapper2D::removeAndResetSliceRep()
244 mView->removeRep(mSliceRep);
249 void ViewWrapper2D::removeAndResetMultiSliceRep()
251 #ifndef CX_VTK_OPENGL2
254 mView->removeRep(mMultiSliceRep);
255 mMultiSliceRep.reset();
260 void ViewWrapper2D::createAndAddMultiSliceRep()
262 #ifndef CX_VTK_OPENGL2
265 mMultiSliceRep->setSliceProxy(mSliceProxy);
267 mView->addRep(mMultiSliceRep);
275 void ViewWrapper2D::recreateMultiSlicer()
277 this->removeAndResetSliceRep();
278 this->removeAndResetMultiSliceRep();
280 if (!this->useGPU2DRendering())
283 this->createAndAddMultiSliceRep();
285 #ifndef CX_VTK_OPENGL2
287 mMultiSliceRep->setImages(this->getImagesToView());
290 this->viewportChanged();
293 std::vector<ImagePtr> ViewWrapper2D::getImagesToView()
297 if(this->isAnyplane())
300 for(
int i = 0; i < streams.size(); ++i)
301 images.push_back(streams[i]->getChangingImage());
306 bool ViewWrapper2D::isAnyplane()
308 PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType();
315 void ViewWrapper2D::viewportChanged()
317 if (!mView->getRenderer()->IsActiveCameraCreated())
320 mView->setZoomFactor(mZoom2D->getFactor());
322 double viewHeight = mView->getViewport_s().range()[1];
323 mView->getRenderer()->GetActiveCamera()->SetParallelScale(viewHeight / 2);
327 double clipDepth = 2.0;
328 double length = clipDepth*10;
329 clipDepth = viewHeight/120 + 1.5;
330 mView->getRenderer()->GetActiveCamera()->SetPosition(0,0,length);
331 mView->getRenderer()->GetActiveCamera()->SetClippingRange(length-clipDepth, length+0.1);
333 mSliceProxy->setToolViewportHeight(viewHeight);
334 double anyplaneViewOffset =
settings()->
value(
"Navigation/anyplaneViewOffset").toDouble();
335 mSliceProxy->initializeFromPlane(mSliceProxy->getComputer().getPlaneType(),
false,
Vector3D(0, 0, 1),
true, viewHeight, anyplaneViewOffset,
true);
337 DoubleBoundingBox3D BB_vp = getViewport();
339 DoubleBoundingBox3D BB_s =
transform(vpMs.inv(), BB_vp);
340 PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType();
342 mToolRep2D->setViewportData(vpMs, BB_vp);
343 if (mSlicePlanes3DMarker)
345 mSlicePlanes3DMarker->getProxy()->setViewportData(plane, mSliceProxy, BB_s);
348 mViewFollower->setView(BB_s);
353 DoubleBoundingBox3D ViewWrapper2D::getViewport()
const
355 QSize size = mView->size();
357 Vector3D p1_d(size.width(), size.height(), 0);
358 DoubleBoundingBox3D BB_vp(p0_d, p1_d);
362 void ViewWrapper2D::showSlot()
364 activeToolChangedSlot();
373 double viewHeight = mView->getViewport_s().range()[1];
374 mSliceProxy->initializeFromPlane(plane,
false,
Vector3D(0, 0, 1),
true, viewHeight, 0.25);
377 mOrientationAnnotationRep->setSliceProxy(mSliceProxy);
379 bool isOblique = mSliceProxy->getComputer().getOrientationType() ==
otOBLIQUE;
380 mToolRep2D->setUseCrosshair(!isOblique);
387 ORIENTATION_TYPE ViewWrapper2D::getOrientationType()
const
389 return mSliceProxy->getComputer().getOrientationType();
399 void ViewWrapper2D::imageAdded(
ImagePtr image)
412 image = images.back();
417 bool ViewWrapper2D::useGPU2DRendering()
419 #ifdef CX_VTK_OPENGL2
421 #endif //CX_VTK_OPENGL2
426 void ViewWrapper2D::createAndAddSliceRep()
431 mSliceRep->setSliceProxy(mSliceProxy);
432 mView->addRep(mSliceRep);
436 void ViewWrapper2D::updateItemsFromViewGroup(QString &text)
442 Vector3D c = image->get_rMd().coord(image->boundingBox().center());
443 mSliceProxy->setDefaultCenter(c);
445 if (this->useGPU2DRendering())
447 this->recreateMultiSlicer();
452 this->removeAndResetMultiSliceRep();
453 this->createAndAddSliceRep();
455 mSliceRep->setImage(image);
458 QStringList textList;
460 for (
unsigned i = 0; i < mesh.size(); ++i)
463 textList << image->getName();
464 text = textList.join(
"\n");
469 this->removeAndResetSliceRep();
470 this->removeAndResetMultiSliceRep();
479 void ViewWrapper2D::setDataNameText(QString &text)
481 mDataNameText->setText(0, text);
482 mDataNameText->setFontSize(std::max(12, 22 - 2 * text.size()));
489 void ViewWrapper2D::updateDataNameText(QString &text)
491 bool show =
settings()->
value(
"View/showDataText").value<
bool>();
495 this->setDataNameText(text);
500 QString annotationTextForLowerLeftCorner;
503 this->updateItemsFromViewGroup(annotationTextForLowerLeftCorner);
507 this->updateDataNameText(annotationTextForLowerLeftCorner);
510 mOrientationAnnotationRep->setVisible(
settings()->value(
"View/showOrientationAnnotation").value<bool>());
513 mDataRepContainer->updateSettings();
530 this->dataAdded(data);
532 this->dataRemoved(uid);
536 void ViewWrapper2D::dataAdded(
DataPtr data)
538 if (boost::dynamic_pointer_cast<Image>(data))
540 this->imageAdded(boost::dynamic_pointer_cast<Image>(data));
544 mDataRepContainer->addData(data);
549 void ViewWrapper2D::dataRemoved(
const QString& uid)
551 mDataRepContainer->removeData(uid);
555 void ViewWrapper2D::activeToolChangedSlot()
558 mSliceProxy->setTool(activeTool);
565 void ViewWrapper2D::mousePressSlot(
int x,
int y, Qt::MouseButtons buttons)
567 if (buttons & Qt::LeftButton)
569 Vector3D clickPos_vp = qvp2vp(QPoint(x,y));
570 moveManualTool(clickPos_vp,
Vector3D(0,0,0));
579 void ViewWrapper2D::mouseMoveSlot(
int x,
int y, Qt::MouseButtons buttons)
581 if (buttons & Qt::LeftButton)
583 Vector3D clickPos_vp = qvp2vp(QPoint(x,y));
584 moveManualTool(clickPos_vp, clickPos_vp - mLastClickPos_vp);
594 this->shiftAxisPos(delta_vp);
595 mLastClickPos_vp = vp;
602 void ViewWrapper2D::mouseWheelSlot(
int x,
int y,
int delta,
int orientation, Qt::MouseButtons buttons)
605 double val = log10(mZoom2D->getFactor());
606 val += delta / 120.0 / 20.0;
607 double newZoom = pow(10.0, val);
609 mZoom2D->setFactor(newZoom);
617 Vector3D ViewWrapper2D::qvp2vp(QPoint pos_qvp)
619 QSize size = mView->size();
620 Vector3D pos_vp(pos_qvp.x(), size.height()-1 - pos_qvp.y(), 0.0);
627 void ViewWrapper2D::shiftAxisPos(
Vector3D delta_vp)
629 delta_vp = -delta_vp;
636 Vector3D delta_s = vpMs.inv().vector(delta_vp);
638 Vector3D delta_pr = (rMpr.inv() * sMr.inv()).vector(delta_s);
643 tool->set_prMt(MD * prMt);
649 void ViewWrapper2D::setAxisPos(
Vector3D click_vp)
658 Vector3D tool_t(0, 0, tool->getTooltipOffset());
659 Vector3D tool_s = (sMr * rMpr * prMt).coord(tool_t);
663 Vector3D click_s = vpMs.inv().coord(click_vp);
666 Vector3D cross_s(click_s[0], click_s[1], tool_s[2]);
668 Vector3D delta_s = cross_s - tool_s;
669 Vector3D delta_pr = (rMpr.inv() * sMr.inv()).vector(delta_s);
674 tool->set_prMt(MD * prMt);
680 PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType();
681 mSlicePlanes3DMarker->setProxy(plane, proxy);
685 mSlicePlanes3DMarker->getProxy()->setViewportData(plane, mSliceProxy,
transform(vpMs.inv(), BB_vp));
687 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()
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 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="")
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)
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
RealScalar length() const
static DisplayTextRepPtr New(const QString &uid="")
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