16 #include "boost/bind.hpp"
17 #include "boost/function.hpp"
22 #include <vtkRenderWindow.h>
23 #include <vtkRenderer.h>
24 #include <vtkImageData.h>
97 view->getRenderer()->GetActiveCamera()->SetClippingRange(0.1, 2000);
98 if (!view->getRenderWindow()->GetStereoCapableWindow())
99 view->getRenderWindow()->StereoCapableWindowOn();
104 QString index = QString::number(startIndex);
105 QColor background =
settings()->
value(
"backgroundColor").value<QColor>();
106 mView->setBackgroundColor(background);
108 view->getRenderer()->GetActiveCamera()->SetParallelProjection(
false);
111 this->initializeMultiVolume3DRepProducer();
114 mLandmarkRep->setGraphicsSize(
settings()->value(
"View3D/sphereRadius").toDouble());
115 mLandmarkRep->setLabelSize(
settings()->value(
"View3D/labelSize").toDouble());
119 connect(mPickerRep.get(), SIGNAL(pointPicked(
Vector3D)),
this, SLOT(pickerRepPointPickedSlot(
Vector3D)));
121 mPickerRep->setSphereRadius(
settings()->value(
"View3D/sphereRadius").toDouble());
122 mPickerRep->setEnabled(
false);
123 mView->addRep(mPickerRep);
124 connect(
mServices->tracking().get(), SIGNAL(activeToolChanged(
const QString&)),
this, SLOT(activeToolChangedSlot()));
125 this->activeToolChangedSlot();
130 this->updateMetricNamesRep();
134 this->toolsAvailableSlot();
139 mView->addRep(mAnnotationMarker);
146 this->setStereoEyeAngle(
settings()->value(
"View3D/eyeAngle").toDouble());
148 setupTransparentMeshes();
158 mMultiVolume3DRepProducer->removeRepsFromView();
162 void ViewWrapper3D::setupTransparentMeshes()
171 this->setTranslucentRenderingToDepthPeeling(
settings()->value(
"View3D/depthPeeling").toBool());
175 void ViewWrapper3D::initializeMultiVolume3DRepProducer()
178 reportError(
"Missing View in initializeMultiVolume3DRepProducer");
180 if (!mMultiVolume3DRepProducer)
183 connect(mMultiVolume3DRepProducer.get(), SIGNAL(imagesChanged()),
this, SLOT(updateView()));
184 mMultiVolume3DRepProducer->setView(mView);
187 mMultiVolume3DRepProducer->setMaxRenderSize(
settings()->value(
"View3D/maxRenderSize").toInt());
188 mMultiVolume3DRepProducer->setVisualizerType(
settings()->value(
"View3D/ImageRender3DVisualizer").toString());
195 if (key ==
"View3D/stereoType")
199 if (key ==
"View3D/eyeAngle")
201 this->setStereoEyeAngle(
settings()->value(
"View3D/eyeAngle").toDouble());
203 if (key ==
"backgroundColor")
205 QColor background =
settings()->
value(
"backgroundColor").value<QColor>();
206 mView->setBackgroundColor(background);
208 if (( key==
"View3D/ImageRender3DVisualizer" )||( key==
"View3D/maxRenderSize" ))
210 this->initializeMultiVolume3DRepProducer();
212 if ((key ==
"View/showDataText")
213 || (key ==
"View/showOrientationAnnotation"))
217 if ((key ==
"View3D/annotationModelSize" )||( key ==
"View3D/annotationModel"))
219 QString annotationFile =
settings()->
value(
"View3D/annotationModel").toString();
221 mAnnotationMarker->setSize(
settings()->value(
"View3D/annotationModelSize").toDouble());
223 if (key ==
"View3D/showManualTool")
225 this->toolsAvailableSlot();
227 if ((key ==
"View3D/sphereRadius" )
228 ||( key ==
"View3D/labelSize" )
229 ||( key ==
"View/showLabels")
230 ||( key ==
"View/showMetricNamesInCorner"))
232 for (RepMap::iterator iter = mDataReps.begin(); iter != mDataReps.end(); ++iter)
234 this->readDataRepSettings(iter->second);
237 this->updateMetricNamesRep();
239 this->toolsAvailableSlot();
240 mLandmarkRep->setGraphicsSize(
settings()->value(
"View3D/sphereRadius").toDouble());
241 mLandmarkRep->setLabelSize(
settings()->value(
"View3D/labelSize").toDouble());
243 if (key ==
"View3D/depthPeeling")
244 this->setTranslucentRenderingToDepthPeeling(
settings()->value(
"View3D/depthPeeling").toBool());
247 void ViewWrapper3D::updateMetricNamesRep()
249 bool enabled =
settings()->
value(
"View/showMetricNamesInCorner").value<
bool>();
256 mView->addRep(mMetricNames);
264 mView->removeRep(mMetricNames);
265 mMetricNames.reset();
269 void ViewWrapper3D::pickerRepPointPickedSlot(
Vector3D p_r)
275 void ViewWrapper3D::pickerRepDataPickedSlot(QString uid)
280 void ViewWrapper3D::appendToContextMenu(QMenu& contextMenu)
282 QAction* slicePlanesAction = NULL;
283 QAction* fillSlicePlanesAction = NULL;
284 if (mSlicePlanes3DRep)
286 slicePlanesAction =
new QAction(
"Show Slice Planes", &contextMenu);
287 slicePlanesAction->setCheckable(
true);
288 slicePlanesAction->setChecked(mSlicePlanes3DRep->getProxy()->getVisible());
289 slicePlanesAction->setToolTip(
"Visialize the outline of the 2D views in 3D");
290 connect(slicePlanesAction, SIGNAL(triggered(
bool)),
this, SLOT(showSlicePlanesActionSlot(
bool)));
292 fillSlicePlanesAction =
new QAction(
"Fill Slice Planes", &contextMenu);
293 fillSlicePlanesAction->setCheckable(
true);
294 fillSlicePlanesAction->setEnabled(mSlicePlanes3DRep->getProxy()->getVisible());
295 fillSlicePlanesAction->setChecked(mSlicePlanes3DRep->getProxy()->getDrawPlanes());
296 slicePlanesAction->setToolTip(
"Fill the visualized 2D views with color");
297 connect(fillSlicePlanesAction, SIGNAL(triggered(
bool)),
this, SLOT(fillSlicePlanesActionSlot(
bool)));
300 QAction* resetCameraAction =
new QAction(
"Reset Camera (r)", &contextMenu);
301 resetCameraAction->setToolTip(
"Zoom out, and show all objects in the view");
302 connect(resetCameraAction, SIGNAL(triggered()),
this, SLOT(resetCameraActionSlot()));
304 QAction* centerImageAction =
new QAction(
"Center to image", &contextMenu);
305 centerImageAction->setToolTip(
"Move view to show center of active image in all views (no zoom)");
306 connect(centerImageAction, SIGNAL(triggered()),
this, SLOT(centerImageActionSlot()));
308 QAction* centerToolAction =
new QAction(
"Center to tool", &contextMenu);
309 centerToolAction->setToolTip(
"Move view to show active tool in all views (no zoom)");
310 connect(centerToolAction, SIGNAL(triggered()),
this, SLOT(centerToolActionSlot()));
312 QAction* showAxesAction =
new QAction(
"Show Coordinate Axes", &contextMenu);
313 showAxesAction->setCheckable(
true);
314 showAxesAction->setChecked(mShowAxes);
315 showAxesAction->setToolTip(
"Show coordinate axes for all objects in 3D scene.\n"
316 "Axes are placed in obejct origin.\n"
317 "Red = X, Green = Y, Blue = Z");
318 connect(showAxesAction, SIGNAL(triggered(
bool)),
this, SLOT(showAxesActionSlot(
bool)));
320 QAction* showManualTool =
new QAction(
"Show Manual Tool 3D", &contextMenu);
321 showManualTool->setCheckable(
true);
322 showManualTool->setChecked(
settings()->value(
"View3D/showManualTool").toBool());
323 showManualTool->setToolTip(
"Turn on/off visualization of the 3D vire cross");
324 connect(showManualTool, SIGNAL(triggered(
bool)),
this, SLOT(showManualToolSlot(
bool)));
326 QAction* showOrientation =
new QAction(
"Show Orientation", &contextMenu);
327 showOrientation->setCheckable(
true);
328 showOrientation->setChecked(mAnnotationMarker->getVisible());
329 showOrientation->setToolTip(
"Turn on/off visualization of the figure in the upper left corner in 3D,\n"
330 "and the orientation letters on the sides in 2D");
331 connect(showOrientation, SIGNAL(triggered(
bool)),
this, SLOT(showOrientationSlot(
bool)));
333 QAction* showToolPath =
new QAction(
"Show Tool Path", &contextMenu);
334 showToolPath->setCheckable(
true);
335 showToolPath->setChecked(
settings()->value(
"showToolPath").toBool());
336 showToolPath->setToolTip(
"Paint a line in 3D where the tool have been, as connected dots.\n"
337 "Turn off to reset");
338 connect(showToolPath, SIGNAL(triggered(
bool)),
this, SLOT(showToolPathSlot(
bool)));
340 QMenu* show3DSlicesMenu =
new QMenu(
"Show 3D slices");
341 show3DSlicesMenu->setToolTip(
"Visualize the 2D views in 3D for the selected image");
344 QMenu* showSlicesMenu =
new QMenu(
"Slice Type", &contextMenu);
345 showSlicesMenu->setToolTip(
"Specify which 2D slices to show in 3D,\n"
346 "when 3D sclices is turned on");
347 this->createSlicesActions(showSlicesMenu);
349 QAction* showRefTool =
new QAction(
"Show Reference Tool", &contextMenu);
350 showRefTool->setDisabled(
true);
351 showRefTool->setCheckable(
true);
352 showRefTool->setToolTip(
"Visualize the tool set as reference in 3D");
356 showRefTool->setText(
"Show " + refTool->getName());
357 showRefTool->setEnabled(
true);
358 showRefTool->setChecked(RepContainer(mView->getReps()).findFirst<ToolRep3D>(refTool) ?
true :
false);
359 connect(showRefTool, SIGNAL(toggled(
bool)),
this, SLOT(showRefToolSlot(
bool)));
362 contextMenu.addSeparator();
363 contextMenu.addMenu(show3DSlicesMenu);
364 contextMenu.addMenu(showSlicesMenu);
365 contextMenu.addSeparator();
366 contextMenu.addAction(resetCameraAction);
367 contextMenu.addAction(centerImageAction);
368 contextMenu.addAction(centerToolAction);
369 contextMenu.addAction(showAxesAction);
370 contextMenu.addAction(showOrientation);
371 contextMenu.addSeparator();
372 contextMenu.addAction(showManualTool);
373 contextMenu.addAction(showRefTool);
375 contextMenu.addAction(showToolPath);
376 contextMenu.addSeparator();
377 if (slicePlanesAction)
378 contextMenu.addAction(slicePlanesAction);
379 if (fillSlicePlanesAction)
380 contextMenu.addAction(fillSlicePlanesAction);
383 void ViewWrapper3D::createSlicesActions(QWidget* parent)
386 this->createSlicesAction(PlaneTypeCollection(
ptAXIAL), parent);
387 this->createSlicesAction(PlaneTypeCollection(
ptCORONAL), parent);
388 this->createSlicesAction(PlaneTypeCollection(
ptSAGITTAL), parent);
389 this->createSlicesAction(PlaneTypeCollection(
ptANYPLANE), parent);
391 this->createSlicesAction(PlaneTypeCollection(
ptRADIALPLANE), parent);
392 this->createSlicesAction(PlaneTypeCollection(
ptSIDEPLANE), parent);
393 this->createSlicesAction(PlaneTypeCollection(
ptTOOLSIDEPLANE), parent);
396 QAction* ViewWrapper3D::createSlicesAction(PlaneTypeCollection planes, QWidget* parent)
398 QString title = planes.toString();
399 QString active =
mGroupData->getSliceDefinitions().toString();
401 QAction* action =
new QAction(title, parent);
402 connect(action, SIGNAL(triggered()),
this, SLOT(showSlices()));
403 action->setData(title);
404 action->setCheckable(
true);
405 action->setChecked(active == title);
407 parent->addAction(action);
411 void ViewWrapper3D::showSlices()
413 QAction* action =
dynamic_cast<QAction*
>(sender());
419 if (!action->isChecked())
420 mGroupData->setSliceDefinitions(PlaneTypeCollection());
431 mView->getRenderer()->SetActiveCamera(
mGroupData->getCamera3D()->getCamera());
434 this->setStereoEyeAngle(
settings()->value(
"View3D/eyeAngle").toDouble());
435 this->optionChangedSlot();
439 void ViewWrapper3D::showToolPathSlot(
bool checked)
451 activeRep3D->getTracer()->stop();
452 activeRep3D->getTracer()->clear();
459 void ViewWrapper3D::showAxesActionSlot(
bool checked)
461 if (mShowAxes == checked)
467 for (
unsigned i=0; i<mAxis.size(); ++i)
468 mView->removeRep(mAxis[i]->mRep);
477 axis.reset(
new AxisConnector(CoordinateSystem(
csREF),
mServices->spaceProvider()));
478 axis->mRep->setAxisLength(0.12);
479 axis->mRep->setShowAxesLabels(
true);
480 axis->mRep->setCaption(
"ref",
Vector3D(1, 0, 0));
481 axis->mRep->setFontSize(0.03);
482 mAxis.push_back(axis);
485 std::vector<DataPtr> data =
mGroupData->getData();
486 for (
unsigned i = 0; i < data.size(); ++i)
488 axis.reset(
new AxisConnector(CoordinateSystem(
csDATA, data[i]->getUid()),
mServices->spaceProvider()));
489 axis->mRep->setAxisLength(0.08);
490 axis->mRep->setShowAxesLabels(
false);
491 axis->mRep->setCaption(data[i]->getName(),
Vector3D(1, 0, 0));
492 axis->mRep->setFontSize(0.03);
493 mAxis.push_back(axis);
498 TrackingService::ToolMap::iterator iter;
499 for (iter = tools.begin(); iter != tools.end(); ++iter)
503 axis.reset(
new AxisConnector(CoordinateSystem(
csTOOL, tool->getUid()),
mServices->spaceProvider()));
504 axis->mRep->setAxisLength(0.08);
505 axis->mRep->setShowAxesLabels(
false);
506 axis->mRep->setCaption(
"t",
Vector3D(0.7, 1, 0.7));
507 axis->mRep->setFontSize(0.03);
508 axis->connectTo(tool);
511 mAxis.push_back(axis);
513 axis.reset(
new AxisConnector(CoordinateSystem(
csSENSOR, tool->getUid()),
mServices->spaceProvider()));
514 axis->mRep->setAxisLength(0.05);
515 axis->mRep->setShowAxesLabels(
false);
516 axis->mRep->setCaption(
"s",
Vector3D(1, 1, 0));
517 axis->mRep->setFontSize(0.03);
518 axis->connectTo(tool);
519 axis->mergeWith(mToolListener);
520 mAxis.push_back(axis);
523 for (
unsigned i=0; i<mAxis.size(); ++i)
524 mView->addRep(mAxis[i]->mRep);
528 void ViewWrapper3D::showManualToolSlot(
bool visible)
533 void ViewWrapper3D::showOrientationSlot(
bool visible)
539 void ViewWrapper3D::resetCameraActionSlot()
541 mView->getRenderer()->ResetCamera();
543 this->setStereoEyeAngle(
settings()->value(
"View3D/eyeAngle").toDouble());
549 camera3D->setView(mView);
554 void ViewWrapper3D::centerImageActionSlot()
560 void ViewWrapper3D::centerToolActionSlot()
563 nav->centerToTooltip();
566 void ViewWrapper3D::showSlicePlanesActionSlot(
bool checked)
568 if (!mSlicePlanes3DRep)
570 mSlicePlanes3DRep->getProxy()->setVisible(checked);
574 void ViewWrapper3D::fillSlicePlanesActionSlot(
bool checked)
576 if (!mSlicePlanes3DRep)
578 mSlicePlanes3DRep->getProxy()->setDrawPlanes(checked);
587 this->addVolumeDataRep(data);
589 this->removeVolumeDataRep(uid);
591 this->updateSlices();
596 void ViewWrapper3D::addVolumeDataRep(
DataPtr data)
600 ImagePtr image = boost::dynamic_pointer_cast<Image>(data);
603 mMultiVolume3DRepProducer->addImage(image);
607 if (!mDataReps.count(data->getUid()))
609 RepPtr rep = this->createDataRep3D(data);
612 mDataReps[data->getUid()] = rep;
619 void ViewWrapper3D::removeVolumeDataRep(QString uid)
621 mMultiVolume3DRepProducer->removeImage(uid);
622 if (mDataReps.count(uid))
624 mView->removeRep(mDataReps[uid]);
625 mDataReps.erase(uid);
634 if (boost::dynamic_pointer_cast<Mesh>(data))
637 rep->setMesh(boost::dynamic_pointer_cast<Mesh>(data));
640 else if (boost::dynamic_pointer_cast<TrackedStream>(data))
642 TrackedStreamPtr trackedStream = boost::dynamic_pointer_cast<TrackedStream>(data);
643 return this->createTrackedStreamRep(trackedStream);
657 if(!trackedStream->hasVideo())
664 if(trackedStream->is3D())
667 rep->setTrackedStream(trackedStream);
670 else if (trackedStream->is2D())
673 rep->setTrackedStream(trackedStream);
678 reportWarning(
"ViewWrapper3D::createDataRep3D. TrackedStream is not 2D or 3D");
687 if (boost::dynamic_pointer_cast<PointMetric>(data))
689 else if (boost::dynamic_pointer_cast<FrameMetric>(data))
691 else if (boost::dynamic_pointer_cast<ToolMetric>(data))
693 else if (boost::dynamic_pointer_cast<DistanceMetric>(data))
695 else if (boost::dynamic_pointer_cast<AngleMetric>(data))
697 else if (boost::dynamic_pointer_cast<PlaneMetric>(data))
699 else if (boost::dynamic_pointer_cast<DonutMetric>(data))
701 else if (boost::dynamic_pointer_cast<CustomMetric>(data))
703 else if (boost::dynamic_pointer_cast<SphereMetric>(data))
705 else if (boost::dynamic_pointer_cast<RegionOfInterestMetric>(data))
710 this->readDataRepSettings(rep);
711 rep->setDataMetric(boost::dynamic_pointer_cast<DataMetric>(data));
719 void ViewWrapper3D::readDataRepSettings(
RepPtr rep)
725 val->setGraphicsSize(
settings()->value(
"View3D/sphereRadius").toDouble());
726 val->setShowLabel(
settings()->value(
"View/showLabels").toBool());
727 val->setLabelSize(
settings()->value(
"View3D/labelSize").toDouble());
728 val->setShowAnnotation(!
settings()->value(
"View/showMetricNamesInCorner").toBool());
741 void ViewWrapper3D::updateView()
748 this->updateMetricNamesRep();
750 mAnnotationMarker->setVisible(
settings()->value(
"View/showOrientationAnnotation").value<bool>());
756 manualToolRep->setToolOffsetPointColor(
settings()->
value(
"View/toolOffsetPointColor").value<QColor>());
757 manualToolRep->setToolOffsetLineColor(
settings()->
value(
"View/toolOffsetLineColor").value<QColor>());
761 void ViewWrapper3D::activeImageChangedSlot(QString uid)
769 if (!std::count(images.begin(), images.end(), image))
773 void ViewWrapper3D::showRefToolSlot(
bool checked)
778 ToolRep3DPtr refRep = RepContainer(mView->getReps()).findFirst<ToolRep3D>(refTool);
782 refRep->setTool(refTool);
786 mView->addRep(refRep);
789 mView->removeRep(refRep);
793 void ViewWrapper3D::updateSlices()
796 mView->removeRep(mSlices3DRep);
806 std::vector<PLANE_TYPE> planes =
mGroupData->getSliceDefinitions().get();
810 for (
unsigned i=0; i<planes.size(); ++i)
811 mSlices3DRep->addPlane(planes[i],
mServices->patient());
813 mSlices3DRep->setImages(images);
814 mSlices3DRep->setTool(
mServices->tracking()->getActiveTool());
815 mView->addRep(mSlices3DRep);
823 void ViewWrapper3D::activeToolChangedSlot()
828 mPickerRep->setTool(controllingTool);
830 mSlices3DRep->setTool(controllingTool);
833 void ViewWrapper3D::toolsAvailableSlot()
835 std::vector<ToolRep3DPtr> reps = RepContainer::findReps<ToolRep3D>(mView->getReps());
838 TrackingService::ToolMap::iterator iter;
839 for (iter = tools.begin(); iter != tools.end(); ++iter)
845 ToolRep3DPtr toolRep = RepContainer(mView->getReps()).findFirst<ToolRep3D>(tool);
847 std::vector<ToolRep3DPtr>::iterator oldRep = std::find(reps.begin(), reps.end(), toolRep);
848 if (oldRep!=reps.end())
854 mView->removeRep(toolRep);
861 if (
settings()->value(
"showToolPath").toBool())
862 toolRep->getTracer()->start();
865 toolRep->setSphereRadius(
settings()->value(
"View3D/sphereRadius").toDouble());
866 toolRep->setSphereRadiusInNormalizedViewport(
true);
868 toolRep->setTool(tool);
869 toolRep->setOffsetPointVisibleAtZeroOffset(
true);
870 mView->addRep(toolRep);
874 for (
unsigned i=0; i<reps.size(); ++i)
876 mView->removeRep(reps[i]);
880 void ViewWrapper3D::optionChangedSlot()
882 ViewGroupData::Options options =
mGroupData->getOptions();
884 this->showLandmarks(options.mShowLandmarks);
885 this->showPointPickerProbe(options.mShowPointPickerProbe);
886 mPickerRep->setGlyph(options.mPickerGlyph);
888 this->updateSlices();
891 void ViewWrapper3D::showLandmarks(
bool on)
893 if (mLandmarkRep->isConnectedToView(mView) == on)
898 mView->addRep(mLandmarkRep);
902 mView->removeRep(mLandmarkRep);
906 void ViewWrapper3D::showPointPickerProbe(
bool on)
908 mPickerRep->setEnabled(on);
914 mSlicePlanes3DRep->setProxy(proxy);
915 mSlicePlanes3DRep->setDynamicLabelSize(
true);
917 mSlicePlanes3DRep->getProxy()->setVisible(show);
919 mView->addRep(mSlicePlanes3DRep);
928 mView->getRenderWindow()->SetStereoTypeToCrystalEyes();
931 mView->getRenderWindow()->SetStereoTypeToInterlaced();
934 mView->getRenderWindow()->SetStereoTypeToDresden();
937 mView->getRenderWindow()->SetStereoTypeToRedBlue();
942 void ViewWrapper3D::setStereoEyeAngle(
double angle)
944 mView->getRenderer()->GetActiveCamera()->SetEyeAngle(angle);
947 void ViewWrapper3D::setTranslucentRenderingToDepthPeeling(
bool setDepthPeeling)
951 bool isDPSupported =
true;
957 reportWarning(
"GPU do not support depth peeling. Rendering of translucent surfaces is not supported");
958 isDPSupported =
false;
964 report(
"Set GPU depth peeling");
968 reportWarning(
"Error setting depth peeling. The GPU or operating system might not support it.");