Fraxinus  17.12
An IGT application
cxViewImplService.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxViewImplService.h"
34 
35 #include <QAction>
36 #include <ctkPluginContext.h>
37 #include <vtkRenderWindow.h>
38 #include <vtkRenderWindowInteractor.h>
39 #include "cxViewGroup.h"
40 #include "cxRepManager.h"
41 #include "cxVisServices.h"
43 #include "cxXMLNodeWrapper.h"
44 #include "cxLogger.h"
45 #include "cxViewGroupData.h"
46 #include "cxClippers.h"
47 #include "cxRenderWindowFactory.h"
48 #include "cxRenderLoop.h"
49 #include "cxViewImplService.h"
50 #include "cxSlicePlanes3DRep.h"
51 #include "cxLayoutRepository.h"
52 #include "cxCameraControl.h"
54 #include "cxSettings.h"
55 #include "cxPatientModelService.h"
56 #include "cxSyncedValue.h"
57 #include "cxInteractiveCropper.h"
58 #include "cxNavigation.h"
59 #include "cxViewCollectionWidget.h"
60 #include "cxViewWrapper.h"
61 #include "cxViewWrapper2D.h"
62 #include "cxViewWrapper3D.h"
63 #include "cxViewWrapperVideo.h"
64 #include "cxProfile.h"
65 
66 namespace cx
67 {
68 
69 ViewImplService::ViewImplService(ctkPluginContext *context) :
70  mContext(context )
71 {
72  mServices = VisServices::create(context);
73  mSession = SessionStorageServiceProxy::create(mContext);
74  mClippers = ClippersPtr(new Clippers(mServices));
75 
76  connect(mSession.get(), &SessionStorageService::sessionChanged, this, &ViewImplService::onSessionChanged);
77  connect(mSession.get(), &SessionStorageService::cleared, this, &ViewImplService::onSessionCleared);
78  connect(mSession.get(), &SessionStorageService::isLoading, this, &ViewImplService::onSessionLoad);
79  connect(mSession.get(), &SessionStorageService::isSaving, this, &ViewImplService::onSessionSave);
80 
81  this->init();
82 }
83 
85 {
86 }
87 
88 void ViewImplService::init()
89 {
91 
92  mRenderLoop.reset(new RenderLoop());
93  connect(mRenderLoop.get(), &RenderLoop::preRender, this, &ViewImplService::updateViews);
94  connect(mRenderLoop.get(), &RenderLoop::fps, this, &ViewImplService::fps);
96 
97  mSlicePlanesProxy.reset(new SlicePlanesProxy());
98  mLayoutRepository.reset(new LayoutRepository());
99  mCameraControl.reset(new CameraControl());
100 
101  mRenderLoop->setLogging(settings()->value("renderSpeedLogging").toBool());
102  mRenderLoop->setSmartRender(settings()->value("smartRender", true).toBool());
103  connect(settings(), SIGNAL(valueChangedFor(QString)), this, SLOT(settingsChangedSlot(QString)));
104 
105  const unsigned VIEW_GROUP_COUNT = 5; // set this to enough
106  // initialize view groups:
107  for (unsigned i = 0; i < VIEW_GROUP_COUNT; ++i)
108  {
109  ViewGroupPtr group(new ViewGroup(mServices, QString::number(i)));
110  mViewGroups.push_back(group);
111  }
112 
113  // moved here from initialize() ... ensures object is fully callable after construction
114  mCameraStyleInteractor.reset(new CameraStyleInteractor);
115 
116  mActiveLayout = QStringList() << "" << "";
117  mLayoutWidgets.resize(mActiveLayout.size(), NULL);
118 
119  mInteractiveCropper.reset(new InteractiveCropper(mServices->patient()->getActiveData()));
120  connect(this, SIGNAL(activeViewChanged()), this, SLOT(updateCameraStyleActions()));
121 
122  this->loadGlobalSettings();
123  // connect to layoutrepo after load of global
124  connect(mLayoutRepository.get(), &LayoutRepository::layoutChanged, this, &ViewImplService::onLayoutRepositoryChanged);
125  this->initializeGlobal2DZoom();
126  this->initializeActiveView();
127 
128  // set start layout
129  this->setActiveLayout("LAYOUT_3D_ACS_SINGLE", 0);
130 
131  mRenderLoop->setRenderingInterval(settings()->value("renderingInterval").toInt());
132  this->enableRender(true);
133 }
134 
135 std::vector<ViewGroupPtr> ViewImplService::getViewGroups()
136 {
137  return mViewGroups;
138 }
139 
141 {
142  if (val)
143  mRenderLoop->start();
144  else
145  mRenderLoop->stop();
146 
148 }
149 
151 {
152  return mRenderLoop->isRunning();
153 }
154 
155 
156 void ViewImplService::initializeGlobal2DZoom()
157 {
158  mGlobal2DZoomVal = SyncedValue::create(1);
159 
160  for (unsigned i = 0; i < mViewGroups.size(); ++i)
161  mViewGroups[i]->getData()->initializeGlobal2DZoom(mGlobal2DZoomVal);
162 }
163 
164 void ViewImplService::initializeActiveView()
165 {
166  mActiveView = SyncedValue::create("");
167  connect(mActiveView.get(), SIGNAL(changed()), this, SIGNAL(activeViewChanged()));
168 
169  for (unsigned i = 0; i < mViewGroups.size(); ++i)
170  mViewGroups[i]->initializeActiveView(mActiveView);
171 }
172 
173 
175 {
176  mCameraControl->refreshView(this->get3DView(group));
177  return NavigationPtr(new Navigation(mServices, mCameraControl));
178 }
179 
181 {
182  if (index >= mLayoutWidgets.size())
183  return NULL;
184  return mLayoutWidgets[index];
185 }
186 
187 QWidget *ViewImplService::createLayoutWidget(QWidget* parent, int index)
188 {
189  if (index >= mLayoutWidgets.size())
190  return NULL;
191 
192  if (!mLayoutWidgets[index])
193  {
194  bool optimizedViews = settings()->value("optimizedViews").toBool();
195 
196  if (optimizedViews)
197  {
199  }
200  else
201  {
203  }
204 
205  connect(mLayoutWidgets[index].data(), &QObject::destroyed, this, &ViewImplService::layoutWidgetDestroyed);
206  mRenderLoop->addLayout(mLayoutWidgets[index]);
207 
208  this->rebuildLayouts();
209  }
210  return mLayoutWidgets[index];
211 }
212 
220 {
221  for (unsigned i=0; i<mLayoutWidgets.size(); ++i)
222  {
223  if (mLayoutWidgets[i] == object)
224  mLayoutWidgets[i] = NULL;
225  }
226 
227  for (unsigned i = 0; i < mViewGroups.size(); ++i)
228  {
229  mViewGroups[i]->removeViews();
230  }
231 
232  this->setActiveView("");
233  mSlicePlanesProxy->clearViewports();
234 
235  QString uid = this->getActiveLayout();
236  mActiveLayout[0] = ""; // hack: force trigger a change
237  this->setActiveLayout(uid, 0);
238 }
239 
240 void ViewImplService::updateViews()
241 {
242  for(unsigned i=0; i<mViewGroups.size(); ++i)
243  {
244  ViewGroupPtr group = mViewGroups[i];
245  for (unsigned j=0; j<group->getWrappers().size(); ++j)
246  group->getWrappers()[j]->updateView();
247  }
248 }
249 
250 void ViewImplService::settingsChangedSlot(QString key)
251 {
252  if (key == "smartRender")
253  {
254  mRenderLoop->setSmartRender(settings()->value("smartRender", true).toBool());
255  }
256  if (key == "renderingInterval")
257  {
258  mRenderLoop->setRenderingInterval(settings()->value("renderingInterval").toInt());
259  }
260  if (key == "renderSpeedLogging")
261  {
262  mRenderLoop->setLogging(settings()->value("renderSpeedLogging").toBool());
263  }
264 }
265 
267 {
268  return mInteractiveCropper;
269 }
270 
271 QString ViewImplService::getActiveLayout(int widgetIndex) const
272 {
273  CX_ASSERT(mActiveLayout.size() > widgetIndex);
274  return mActiveLayout[widgetIndex];
275 }
276 
277 QString ViewImplService::getActiveView() const
278 {
279  return mActiveView->get().value<QString>();
280 }
281 
282 void ViewImplService::setActiveView(QString uid)
283 {
284  mActiveView->set(uid);
285 }
286 
288 {
289  int retval = -1;
290  QString activeView = mActiveView->value<QString>();
291 
292  for (unsigned i = 0; i < mViewGroups.size(); ++i)
293  {
294  ViewWrapperPtr viewWrapper = mViewGroups[i]->getViewWrapperFromViewUid(activeView);
295  if (viewWrapper)
296  retval = i;
297  }
298 
299  return retval;
300 }
301 
302 void ViewImplService::addXml(QDomNode& parentNode)
303 {
304  XMLNodeAdder parent(parentNode);
305  XMLNodeAdder base(parent.addElement("viewManager"));
306 
307  base.addTextToElement("global2DZoom", qstring_cast(mGlobal2DZoomVal->get().toDouble()));
308 
309  QDomElement slicePlanes3DNode = base.addElement("slicePlanes3D");
310  slicePlanes3DNode.setAttribute("use", mSlicePlanesProxy->getVisible());
311  slicePlanes3DNode.setAttribute("opaque", mSlicePlanesProxy->getDrawPlanes());
312 
313  XMLNodeAdder viewGroupsNode(base.addElement("viewGroups"));
314  for (unsigned i = 0; i < mViewGroups.size(); ++i)
315  {
316  QDomElement viewGroupNode = viewGroupsNode.addElement("viewGroup");
317  viewGroupNode.setAttribute("index", i);
318  mViewGroups[i]->addXml(viewGroupNode);
319  }
320 }
321 
322 void ViewImplService::parseXml(QDomNode viewmanagerNode)
323 {
324  XMLNodeParser base(viewmanagerNode);
325 
326  QString clippedImage = base.parseTextFromElement("clippedImage");
327 
328  base.parseDoubleFromElementWithDefault("global2DZoom", mGlobal2DZoomVal->get().toDouble());
329 
330  QDomElement slicePlanes3DNode = base.parseElement("slicePlanes3D");
331  mSlicePlanesProxy->setVisible(slicePlanes3DNode.attribute("use").toInt());
332  mSlicePlanesProxy->setDrawPlanes(slicePlanes3DNode.attribute("opaque").toInt());
333 
334  QDomElement viewgroups = base.parseElement("viewGroups");
335  QDomNode viewgroup = viewgroups.firstChild();
336  while (!viewgroup.isNull())
337  {
338  if (viewgroup.toElement().tagName() != "viewGroup")
339  {
340  viewgroup = viewgroup.nextSibling();
341  continue;
342  }
343  int index = viewgroup.toElement().attribute("index").toInt();
344 
345  if (index < 0 || index >= int(mViewGroups.size()))
346  {
347  viewgroup = viewgroup.nextSibling();
348  continue;
349  }
350 
351  mViewGroups[index]->parseXml(viewgroup);
352 
353  viewgroup = viewgroup.nextSibling();
354  }
355 }
356 
357 void ViewImplService::clear()
358 {
359  for (unsigned i = 0; i < mViewGroups.size(); ++i)
360  {
361  mViewGroups[i]->clearPatientData();
362  }
363 }
364 
367 ViewPtr ViewImplService::get3DView(int group, int index)
368 {
369  int count = 0;
370  std::vector<ViewPtr> views = mViewGroups[group]->getViews();
371  for (unsigned i = 0; i < views.size(); ++i)
372  {
373  if(!views[i])
374  continue;
375  if (views[i]->getType()!=View::VIEW_3D)
376  continue;
377  if (index == count++)
378  return views[i];
379  }
380  return ViewPtr();
381 }
382 
383 
386 void ViewImplService::deactivateCurrentLayout()
387 {
388  for (unsigned i=0; i<mLayoutWidgets.size(); ++i)
389  {
390  if (mLayoutWidgets[i])
391  mLayoutWidgets[i]->clearViews();
392  }
393 
394  for (unsigned i = 0; i < mViewGroups.size(); ++i)
395  {
396  mViewGroups[i]->removeViews();
397  }
398 
399  this->setActiveView("");
400  mSlicePlanesProxy->clearViewports();
401 }
402 
404 {
405  if (( groupIdx>=0 )&&( groupIdx < mViewGroups.size() ))
406  return mViewGroups[groupIdx]->getData();
407  return ViewGroupDataPtr();
408 }
409 
410 unsigned ViewImplService::viewGroupCount() const
411 {
412  int count = 0;
413  while(this->getGroup(count))
414  ++count;
415  return count;
416 }
417 
420 void ViewImplService::setActiveLayout(const QString& layout, int widgetIndex)
421 {
422  if(!mLayoutRepository->exists(layout))
423  return;
424 
425  CX_ASSERT(mActiveLayout.size() > widgetIndex);
426 
427  if (mActiveLayout[widgetIndex] == layout)
428  return;
429 
430  mActiveLayout[widgetIndex] = layout;
431 
432  this->rebuildLayouts();
433 
434  if (!mViewGroups[0]->getViews().empty())
435  this->setActiveView(mViewGroups[0]->getViews()[0]->getUid());
436 
437  emit activeLayoutChanged();
438 
439  QString layoutName = mLayoutRepository->get(layout).getName();
440  report(QString("Layout %1 changed to %2").arg(widgetIndex).arg(layoutName));
441 }
442 
444 {
445  this->deactivateCurrentLayout();
446 
447  for (unsigned i=0; i<mLayoutWidgets.size(); ++i)
448  {
449  LayoutData next = mLayoutRepository->get(mActiveLayout[i]);
450  if (mLayoutWidgets[i] && !next.getUid().isEmpty())
451  this->activateViews(mLayoutWidgets[i], next);
452  }
453 
454  this->setSlicePlanesProxyInViewsUpTo2DViewgroup();
455 
456  mCameraControl->refreshView(this->get3DView());
457 }
458 
459 void ViewImplService::setSlicePlanesProxyInViewsUpTo2DViewgroup()
460 {
461  // Set the same proxy in all wrappers, but stop adding after the
462  // first group with 2D views are found.
463  // This works well _provided_ that the 3D view is in the first group.
464  for (unsigned i = 0; i < mViewGroups.size(); ++i)
465  {
466  bool foundSlice = false;
467  std::vector<ViewWrapperPtr> wrappers = mViewGroups[i]->getWrappers();
468  for (unsigned j = 0; j < wrappers.size(); ++j)
469  {
470  wrappers[j]->setSlicePlanesProxy(mSlicePlanesProxy);
471  foundSlice = foundSlice || wrappers[j]->getView()->getType() == View::VIEW_2D;
472  }
473  if (foundSlice)
474  break;
475  }
476 }
477 void ViewImplService::activateViews(ViewCollectionWidget *widget, LayoutData next)
478 {
479  if (!widget)
480  return;
481 
483 
484  for (LayoutData::iterator iter = next.begin(); iter != next.end(); ++iter)
485  this->activateView(widget, *iter);
486 }
487 
488 void ViewImplService::setRenderingInterval(int interval)
489 {
490  mRenderLoop->setRenderingInterval(interval);
491 }
492 
493 void ViewImplService::activateView(ViewCollectionWidget* widget, LayoutViewData viewData)
494 {
495  if (!viewData.isValid())
496  return;
497 
498  ViewPtr view = widget->addView(viewData.mType, viewData.mRegion);
499 
500 
501  vtkRenderWindowInteractorPtr interactor = view->getRenderWindow()->GetInteractor();
502  //Turn off rendering in vtkRenderWindowInteractor
503  interactor->EnableRenderOff();
504  //Increase the StillUpdateRate in the vtkRenderWindowInteractor (default is 0.0001 images per second)
505  double rate = settings()->value("stillUpdateRate").value<double>();
506  interactor->SetStillUpdateRate(rate);
507  // Set the same value when moving (seems counterintuitive, but for us, moving isnt really special.
508  // The real challenge is updating while the tracking is active, and this uses the still update rate.
509  interactor->SetDesiredUpdateRate(rate);
510 
511  ViewWrapperPtr wrapper = this->createViewWrapper(view, viewData);
512  if(!mRenderWindowFactory->getSharedOpenGLContext())
513  CX_LOG_WARNING() << "ViewImplService::activateView: got not shared OpenGL context";
514  mViewGroups[viewData.mGroup]->addView(wrapper, mRenderWindowFactory->getSharedOpenGLContext());
515 }
516 
517 ViewWrapperPtr ViewImplService::createViewWrapper(ViewPtr view, LayoutViewData viewData)
518 {
519  if (viewData.mType == View::VIEW_2D)
520  {
521  ViewWrapper2DPtr wrapper(new ViewWrapper2D(view, mServices));
522  wrapper->initializePlane(viewData.mPlane);
523  connect(wrapper.get(), &ViewWrapper2D::pointSampled, this, &ViewImplService::pointSampled);
524  return wrapper;
525  }
526  else if (viewData.mType == View::VIEW_3D)
527  {
528 
529  ViewWrapper3DPtr wrapper(new ViewWrapper3D(viewData.mGroup + 1, view, mServices));
530  if (viewData.mGroup == 0)
531  mInteractiveCropper->setView(view);
532  return wrapper;
533  }
534  else if (viewData.mType == View::VIEW_REAL_TIME)
535  {
536  ViewWrapperVideoPtr wrapper(new ViewWrapperVideo(view, mServices));
537  return wrapper;
538  }
539  else
540  {
541  reportError(QString("Unknown view type %1").arg(qstring_cast(viewData.mType)));
542  }
543 
544  return ViewWrapperPtr();
545 }
546 
548 {
549  return mLayoutRepository;
550 }
551 
552 void ViewImplService::onLayoutRepositoryChanged(QString uid)
553 {
554  this->saveGlobalSettings();
555 
556  bool activeChange = mActiveLayout[0] == uid;
557  if (activeChange)
558  {
559  mActiveLayout[0] = ""; // hack: force trigger a change
560  this->setActiveLayout(uid, 0);
561  }
562 }
563 
564 void ViewImplService::loadGlobalSettings()
565 {
566  XmlOptionFile file = profile()->getXmlSettings().descend("viewmanager");
567  mLayoutRepository->load(file);
568 }
569 
570 void ViewImplService::saveGlobalSettings()
571 {
572  XmlOptionFile file = profile()->getXmlSettings().descend("viewmanager");
573  mLayoutRepository->save(file);
574  file.save();
575 }
576 
578 {
579  return mCameraStyleInteractor->getInteractorStyleActionGroup();
580 }
581 
582 void ViewImplService::updateCameraStyleActions()
583 {
584  int active = this->getActiveGroupId();
585  int index = this->findGroupContaining3DViewGivenGuess(active);
586 
587  if (index<0)
588  {
589  mCameraStyleInteractor->connectCameraStyle(ViewGroupDataPtr());
590  }
591  else
592  {
593  ViewGroupPtr group = this->getViewGroups()[index];
594  mCameraStyleInteractor->connectCameraStyle(group->getData());
595  mCameraControl->setView(this->get3DView(index, 0));
596  }
597 }
598 
601 int ViewImplService::findGroupContaining3DViewGivenGuess(int preferredGroup)
602 {
603  if (preferredGroup>=0)
604  if (mViewGroups[preferredGroup]->contains3DView())
605  return preferredGroup;
606 
607  for (unsigned i=0; i<mViewGroups.size(); ++i)
608  if (mViewGroups[i]->contains3DView())
609  return i;
610  return -1;
611 }
612 
614 {
615  if (settings()->value("Automation/autoShowNewData").toBool() && data)
616  {
617  this->autoShowInViewGroups(data);
618  this->autoResetCameraToSuperiorView();
619  this->autoCenterToImageCenter();
620  }
621 }
622 
624 
625 void ViewImplService::autoShowInViewGroups(DataPtr data)
626 {
627  QList<unsigned> showInViewGroups = this->getViewGroupsToAutoShowIn();
628  foreach (unsigned i, showInViewGroups)
629  this->getViewGroups()[i]->getData()->addDataSorted(data->getUid());
630 }
631 
633 {
634  QList<unsigned> showInViewGroups;
635  if(settings()->value("Automation/autoShowNewDataInViewGroup0").toBool())
636  showInViewGroups << 0;
637  if(settings()->value("Automation/autoShowNewDataInViewGroup1").toBool())
638  showInViewGroups << 1;
639  if(settings()->value("Automation/autoShowNewDataInViewGroup2").toBool())
640  showInViewGroups << 2;
641  if(settings()->value("Automation/autoShowNewDataInViewGroup3").toBool())
642  showInViewGroups << 3;
643  if(settings()->value("Automation/autoShowNewDataInViewGroup4").toBool())
644  showInViewGroups << 4;
645  return showInViewGroups;
646 }
647 
648 void ViewImplService::autoResetCameraToSuperiorView()
649 {
650  if(settings()->value("Automation/autoResetCameraToSuperiorViewWhenAutoShowingNewData").toBool())
651  {
652  for (unsigned i=0; i<mViewGroups.size(); ++i)
653  if (mViewGroups[i]->contains3DView())
654  {
655  mCameraControl->setView(this->get3DView(i));
656  mCameraControl->setSuperiorView();
657  }
658  }
659 }
660 
661 void ViewImplService::autoCenterToImageCenter()
662 {
663  if(settings()->value("Automation/autoCenterToImageCenterViewWhenAutoShowingNewData").toBool())
664  {
665  QList<unsigned> showInViewGroups = this->getViewGroupsToAutoShowIn();
666 
667  foreach (unsigned i, showInViewGroups)
668  this->centerToImageCenterInViewGroup(i);
669  }
670 }
671 
672 void ViewImplService::centerToImageCenterInViewGroup(unsigned groupNr)
673 {
674  this->getNavigation(groupNr)->centerToDataInViewGroup(this->getGroup(groupNr));
675 }
676 
678 {
679  return mRenderLoop->getRenderTimer();
680 }
681 
682 void ViewImplService::setCameraStyle(CAMERA_STYLE_TYPE style, int groupIdx)
683 {
684  //Set active view before changing camerastyle
685  if (!mViewGroups[groupIdx]->getViews().empty())
686  this->setActiveView(mViewGroups[groupIdx]->getViews()[0]->getUid());
687 
688  QList<QAction*> actions = this->getInteractorStyleActionGroup()->actions();
689  for(int i = 0; i < actions.size(); ++i)
690  {
691  if (actions[i]->data().toString() == enum2string(style))
692  actions[i]->trigger();
693  }
694 }
695 
696 void ViewImplService::zoomCamera3D(int viewGroup3DNumber, int zoomFactor)
697 {
698  ViewGroupDataPtr viewGroup3D = this->getGroup(viewGroup3DNumber);
699  if(!viewGroup3D)
700  return;
701 
702  viewGroup3D->zoomCamera3D(zoomFactor);
703 }
704 
706 {
707  mLayoutRepository->addDefault(layoutData);
708 }
709 
711 {
712  for(int i=0; i<mLayoutWidgets.size(); ++i)
713  {
715  if(widget)
716  widget->enableContextMenuForViews(enable);
717  }
718 }
719 
720 void ViewImplService::setRegistrationMode(REGISTRATION_STATUS mode)
721 {
722  this->getGroup(0)->setRegistrationMode(mode);
723 }
724 
726 {
727  return false;
728 }
729 
731 {
732  this->enableRender(false);
733 }
734 
736 {
737  return this->mClippers;
738 }
739 
741 {
742  this->centerToImageCenterInViewGroup(this->getActiveGroupId());
743 }
744 
745 void ViewImplService::onSessionChanged()
746 {
747 }
748 void ViewImplService::onSessionCleared()
749 {
750  this->clear();
751 }
752 
753 //TODO: save/load clippers
754 void ViewImplService::onSessionLoad(QDomElement& node)
755 {
756  XMLNodeParser root(node);
757  QDomElement viewManagerNode = root.descend("managers/viewManager").node().toElement();
758  if (!viewManagerNode.isNull())
759  this->parseXml(viewManagerNode);
760 
761  mClippers->parseXml(node);
762 }
763 void ViewImplService::onSessionSave(QDomElement& node)
764 {
765  XMLNodeAdder root(node);
766  QDomElement managerNode = root.descend("managers").node().toElement();
767  this->addXml(managerNode);
768  mClippers->addXml(node);
769 }
770 
771 } /* namespace cx */
QString qstring_cast(const T &val)
double parseDoubleFromElementWithDefault(QString name, double defaultValue)
virtual QWidget * getLayoutWidget(int index)
Get the specified layout widget, NULL if not created.
int mGroup
what group to connect to. -1 means not set.
Definition: cxLayoutData.h:84
boost::shared_ptr< class CyclicActionLogger > CyclicActionLoggerPtr
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:181
boost::shared_ptr< class LayoutRepository > LayoutRepositoryPtr
RenderLoopPtr mRenderLoop
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:50
virtual void zoomCamera3D(int viewGroup3DNumber, int zoomFactor)
void reportError(QString msg)
Definition: cxLogger.cpp:92
void isLoading(QDomElement &root)
emitted while loading a session. Xml storage is available, getRootFolder() is set to loaded value...
RenderWindowFactoryPtr mRenderWindowFactory
virtual int getActiveGroupId() const
virtual ViewPtr get3DView(int group=0, int index=0)
ViewDataContainer::iterator iterator
Definition: cxLayoutData.h:101
void renderFinished()
#define CX_ASSERT(statement)
Definition: cxLogger.h:137
boost::shared_ptr< class CameraControl > CameraControlPtr
XMLNodeAdder descend(QString path)
QDomElement addElement(QString name)
QList< unsigned > getViewGroupsToAutoShowIn()
virtual InteractiveCropperPtr getCropper()
void fps(int number)
Emits number of frames per second.
virtual CyclicActionLoggerPtr getRenderTimer()
vtkSmartPointer< class vtkRenderWindowInteractor > vtkRenderWindowInteractorPtr
virtual ViewGroupDataPtr getGroup(int groupIdx) const
virtual QString getActiveLayout(int widgetIndex=0) const
virtual void enableContextMenuForViews(bool enable=true)
virtual bool renderingIsEnabled() const
virtual void setOffScreenRenderingAndClear(bool on)=0
VisServicesPtr mServices
boost::shared_ptr< class ViewWrapper > ViewWrapperPtr
virtual void setRegistrationMode(REGISTRATION_STATUS mode)
Use to create all vtkRenderWindows, and store a single shared render window.
static VisServicesPtr create(ctkPluginContext *context)
static SessionStorageServicePtr create(ctkPluginContext *pluginContext)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:87
virtual void centerToImageCenterInActiveViewGroup()
boost::shared_ptr< class InteractiveCropper > InteractiveCropperPtr
virtual void addDefaultLayout(LayoutData layoutData)
static QPointer< ViewCollectionWidget > createViewWidgetLayout(RenderWindowFactoryPtr factory, QWidget *parent=NULL)
QString getUid() const
Definition: cxLayoutData.h:109
boost::shared_ptr< class View > ViewPtr
boost::shared_ptr< class Clippers > ClippersPtr
iterator begin()
Definition: cxLayoutData.h:118
std::vector< QPointer< ViewCollectionWidget > > mLayoutWidgets
bool isValid() const
Definition: cxLayoutData.h:91
void pointSampled(Vector3D p_r)
void sessionChanged()
emitted after change to a new session (new or loaded or cleared)
virtual void autoShowData(DataPtr data)
boost::shared_ptr< ViewWrapper2D > ViewWrapper2DPtr
void renderingEnabledChanged()
emitted then rendering is enabled/disabled
boost::shared_ptr< class Data > DataPtr
virtual LayoutRepositoryPtr getLayoutRepository()
PLANE_TYPE mPlane
ptNOPLANE means 3D
Definition: cxLayoutData.h:85
LayoutRegion mRegion
Definition: cxLayoutData.h:87
void renderFinished()
virtual void enableContextMenuForViews(bool enable)=0
virtual ClippersPtr getClippers()
static SyncedValuePtr create(QVariant val=QVariant())
void layoutChanged(QString uid)
ViewImplService(ctkPluginContext *context)
void fps(int number)
Emits number of frames per second.
virtual void aboutToStop()
QDomElement addTextToElement(QString name, QString text)
XMLNodeParser descend(QString path)
void activeViewChanged()
emitted when the active view changes
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:42
void layoutWidgetDestroyed(QObject *object)
void cleared()
emitted when session is cleared, before isLoading is called
virtual QWidget * createLayoutWidget(QWidget *parent, int index)
Get the specified layout widget, create if necessary.
Helper class for managing a set of slice planes.
void activeLayoutChanged()
emitted when the active layout changes
Clipper container. Used by ClippersWidget.
Definition: cxClippers.h:49
boost::shared_ptr< ViewWrapperVideo > ViewWrapperVideoPtr
boost::shared_ptr< ViewWrapper3D > ViewWrapper3DPtr
void report(QString msg)
Definition: cxLogger.cpp:90
virtual NavigationPtr getNavigation(int group=0)
boost::shared_ptr< class ViewGroup > ViewGroupPtr
QString parseTextFromElement(QString name)
#define CX_LOG_WARNING
Definition: cxLogger.h:119
virtual CameraControlPtr getCameraControl()
virtual ViewPtr addView(View::Type type, LayoutRegion region)=0
void save()
save entire document.
iterator end()
Definition: cxLayoutData.h:119
View::Type mType
Definition: cxLayoutData.h:86
boost::shared_ptr< class Navigation > NavigationPtr
boost::shared_ptr< class RenderWindowFactory > RenderWindowFactoryPtr
virtual void setCameraStyle(CAMERA_STYLE_TYPE style, int groupIdx)
static QPointer< ViewCollectionWidget > createOptimizedLayout(RenderWindowFactoryPtr factory, QWidget *parent=NULL)
QString enum2string(const ENUM &val)
void isSaving(QDomElement &root)
xml storage is available
bool getOffScreenRendering() const
Definition: cxLayoutData.h:111
Helper class for xml files used to store ssc/cx data.
virtual void setActiveLayout(const QString &uid, int widgetIndex)
virtual void enableRender(bool val)
void pointSampled(Vector3D p_r)
QDomElement parseElement(QString name)
virtual QActionGroup * getInteractorStyleActionGroup()
Namespace for all CustusX production code.