15 #include <ctkPluginContext.h> 16 #include <vtkRenderWindow.h> 17 #include <vtkRenderWindowInteractor.h> 67 void ViewImplService::init()
82 connect(
settings(), SIGNAL(valueChangedFor(QString)),
this, SLOT(settingsChangedSlot(QString)));
84 const unsigned VIEW_GROUP_COUNT = 5;
86 for (
unsigned i = 0; i < VIEW_GROUP_COUNT; ++i)
89 mViewGroups.push_back(group);
95 mActiveLayout = QStringList() <<
"" <<
"";
99 connect(
this, SIGNAL(
activeViewChanged()),
this, SLOT(updateCameraStyleActions()));
101 this->loadGlobalSettings();
104 this->initializeGlobal2DZoom();
105 this->initializeActiveView();
114 std::vector<ViewGroupPtr> ViewImplService::getViewGroups()
135 void ViewImplService::initializeGlobal2DZoom()
139 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
140 mViewGroups[i]->getData()->initializeGlobal2DZoom(mGlobal2DZoomVal);
143 void ViewImplService::initializeActiveView()
146 connect(mActiveView.get(), SIGNAL(changed()),
this, SIGNAL(
activeViewChanged()));
148 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
149 mViewGroups[i]->initializeActiveView(mActiveView);
155 mCameraControl->refreshView(this->
get3DView(group));
173 bool optimizedViews =
settings()->
value(
"optimizedViews").toBool();
206 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
208 mViewGroups[i]->removeViews();
211 this->setActiveView(
"");
212 mSlicePlanesProxy->clearViewports();
215 mActiveLayout[0] =
"";
219 void ViewImplService::updateViews()
221 for(
unsigned i=0; i<mViewGroups.size(); ++i)
224 for (
unsigned j=0; j<group->getWrappers().size(); ++j)
225 group->getWrappers()[j]->updateView();
229 void ViewImplService::settingsChangedSlot(QString key)
231 if (key ==
"smartRender")
235 if (key ==
"renderingInterval")
239 if (key ==
"renderSpeedLogging")
247 return mInteractiveCropper;
252 CX_ASSERT(mActiveLayout.size() > widgetIndex);
253 return mActiveLayout[widgetIndex];
256 QString ViewImplService::getActiveView()
const 258 return mActiveView->get().value<QString>();
261 void ViewImplService::setActiveView(QString uid)
263 mActiveView->set(uid);
269 QString activeView = mActiveView->value<QString>();
271 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
273 ViewWrapperPtr viewWrapper = mViewGroups[i]->getViewWrapperFromViewUid(activeView);
281 void ViewImplService::addXml(QDomNode& parentNode)
288 QDomElement slicePlanes3DNode = base.addElement(
"slicePlanes3D");
289 slicePlanes3DNode.setAttribute(
"use", mSlicePlanesProxy->getVisible());
290 slicePlanes3DNode.setAttribute(
"opaque", mSlicePlanesProxy->getDrawPlanes());
292 XMLNodeAdder viewGroupsNode(base.addElement(
"viewGroups"));
293 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
295 QDomElement viewGroupNode = viewGroupsNode.
addElement(
"viewGroup");
296 viewGroupNode.setAttribute(
"index", i);
297 mViewGroups[i]->addXml(viewGroupNode);
301 void ViewImplService::parseXml(QDomNode viewmanagerNode)
309 QDomElement slicePlanes3DNode = base.
parseElement(
"slicePlanes3D");
310 mSlicePlanesProxy->setVisible(slicePlanes3DNode.attribute(
"use").toInt());
311 mSlicePlanesProxy->setDrawPlanes(slicePlanes3DNode.attribute(
"opaque").toInt());
313 QDomElement viewgroups = base.
parseElement(
"viewGroups");
314 QDomNode viewgroup = viewgroups.firstChild();
315 while (!viewgroup.isNull())
317 if (viewgroup.toElement().tagName() !=
"viewGroup")
319 viewgroup = viewgroup.nextSibling();
322 int index = viewgroup.toElement().attribute(
"index").toInt();
324 if (index < 0 || index >=
int(mViewGroups.size()))
326 viewgroup = viewgroup.nextSibling();
330 mViewGroups[index]->parseXml(viewgroup);
332 viewgroup = viewgroup.nextSibling();
336 void ViewImplService::clear()
338 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
340 mViewGroups[i]->clearPatientData();
349 std::vector<ViewPtr> views = mViewGroups[group]->getViews();
350 for (
unsigned i = 0; i < views.size(); ++i)
356 if (index == count++)
365 void ViewImplService::deactivateCurrentLayout()
373 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
375 mViewGroups[i]->removeViews();
378 this->setActiveView(
"");
379 mSlicePlanesProxy->clearViewports();
384 if (( groupIdx>=0 )&&( groupIdx < mViewGroups.size() ))
385 return mViewGroups[groupIdx]->getData();
389 unsigned ViewImplService::viewGroupCount()
const 401 if(!mLayoutRepository->exists(layout))
404 CX_ASSERT(mActiveLayout.size() > widgetIndex);
406 if (mActiveLayout[widgetIndex] == layout)
409 mActiveLayout[widgetIndex] = layout;
413 if (!mViewGroups[0]->getViews().empty())
414 this->setActiveView(mViewGroups[0]->getViews()[0]->getUid());
418 QString layoutName = mLayoutRepository->get(layout).getName();
419 report(QString(
"Layout %1 changed to %2").arg(widgetIndex).arg(layoutName));
424 this->deactivateCurrentLayout();
428 LayoutData next = mLayoutRepository->get(mActiveLayout[i]);
433 this->setSlicePlanesProxyInViewsUpTo2DViewgroup();
435 mCameraControl->refreshView(this->
get3DView());
438 void ViewImplService::setSlicePlanesProxyInViewsUpTo2DViewgroup()
443 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
445 bool foundSlice =
false;
446 std::vector<ViewWrapperPtr> wrappers = mViewGroups[i]->getWrappers();
447 for (
unsigned j = 0; j < wrappers.size(); ++j)
449 wrappers[j]->setSlicePlanesProxy(mSlicePlanesProxy);
450 foundSlice = foundSlice || wrappers[j]->getView()->getType() ==
View::VIEW_2D;
464 this->activateView(widget, *iter);
467 void ViewImplService::setRenderingInterval(
int interval)
482 interactor->EnableRenderOff();
484 double rate =
settings()->
value(
"stillUpdateRate").value<
double>();
485 interactor->SetStillUpdateRate(rate);
488 interactor->SetDesiredUpdateRate(rate);
492 CX_LOG_WARNING() <<
"ViewImplService::activateView: got not shared OpenGL context";
501 wrapper->initializePlane(viewData.
mPlane);
510 mInteractiveCropper->setView(view);
528 return mLayoutRepository;
531 void ViewImplService::onLayoutRepositoryChanged(QString uid)
533 this->saveGlobalSettings();
535 bool activeChange = mActiveLayout[0] == uid;
538 mActiveLayout[0] =
"";
543 void ViewImplService::loadGlobalSettings()
546 mLayoutRepository->load(file);
549 void ViewImplService::saveGlobalSettings()
552 mLayoutRepository->save(file);
558 return mCameraStyleInteractor->getInteractorStyleActionGroup();
561 void ViewImplService::updateCameraStyleActions()
564 int index = this->findGroupContaining3DViewGivenGuess(active);
573 mCameraStyleInteractor->connectCameraStyle(group->getData());
574 mCameraControl->setView(this->
get3DView(index, 0));
580 int ViewImplService::findGroupContaining3DViewGivenGuess(
int preferredGroup)
582 if (preferredGroup>=0)
583 if (mViewGroups[preferredGroup]->contains3DView())
584 return preferredGroup;
586 for (
unsigned i=0; i<mViewGroups.size(); ++i)
587 if (mViewGroups[i]->contains3DView())
594 if (
settings()->value(
"Automation/autoShowNewData").toBool() && data)
596 this->autoShowInViewGroups(data);
597 this->autoResetCameraToSuperiorView();
598 this->autoCenterToImageCenter();
604 void ViewImplService::autoShowInViewGroups(
DataPtr data)
607 foreach (
unsigned i, showInViewGroups)
608 this->getViewGroups()[i]->getData()->addDataSorted(data->getUid());
613 QList<unsigned> showInViewGroups;
614 if(
settings()->value(
"Automation/autoShowNewDataInViewGroup0").toBool())
615 showInViewGroups << 0;
616 if(
settings()->value(
"Automation/autoShowNewDataInViewGroup1").toBool())
617 showInViewGroups << 1;
618 if(
settings()->value(
"Automation/autoShowNewDataInViewGroup2").toBool())
619 showInViewGroups << 2;
620 if(
settings()->value(
"Automation/autoShowNewDataInViewGroup3").toBool())
621 showInViewGroups << 3;
622 if(
settings()->value(
"Automation/autoShowNewDataInViewGroup4").toBool())
623 showInViewGroups << 4;
624 return showInViewGroups;
627 void ViewImplService::autoResetCameraToSuperiorView()
629 if(
settings()->value(
"Automation/autoResetCameraToSuperiorViewWhenAutoShowingNewData").toBool())
631 for (
unsigned i=0; i<mViewGroups.size(); ++i)
632 if (mViewGroups[i]->contains3DView())
634 mCameraControl->setView(this->
get3DView(i));
635 mCameraControl->setSuperiorView();
640 void ViewImplService::autoCenterToImageCenter()
642 if(
settings()->value(
"Automation/autoCenterToImageCenterViewWhenAutoShowingNewData").toBool())
646 foreach (
unsigned i, showInViewGroups)
647 this->centerToImageCenterInViewGroup(i);
651 void ViewImplService::centerToImageCenterInViewGroup(
unsigned groupNr)
664 if (!mViewGroups[groupIdx]->getViews().empty())
665 this->setActiveView(mViewGroups[groupIdx]->getViews()[0]->getUid());
668 for(
int i = 0; i < actions.size(); ++i)
670 if (actions[i]->data().toString() ==
enum2string(style))
671 actions[i]->trigger();
681 viewGroup3D->zoomCamera3D(zoomFactor);
686 mLayoutRepository->addDefault(layoutData);
701 this->
getGroup(0)->setRegistrationMode(mode);
716 return this->mClippers;
724 void ViewImplService::onSessionChanged()
727 void ViewImplService::onSessionCleared()
733 void ViewImplService::onSessionLoad(QDomElement& node)
736 QDomElement viewManagerNode = root.
descend(
"managers/viewManager").
node().toElement();
737 if (!viewManagerNode.isNull())
738 this->parseXml(viewManagerNode);
740 mClippers->parseXml(node);
742 void ViewImplService::onSessionSave(QDomElement& node)
745 QDomElement managerNode = root.
descend(
"managers").
node().toElement();
746 this->addXml(managerNode);
747 mClippers->addXml(node);
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.
boost::shared_ptr< class CyclicActionLogger > CyclicActionLoggerPtr
cxResource_EXPORT ProfilePtr profile()
boost::shared_ptr< class LayoutRepository > LayoutRepositoryPtr
RenderLoopPtr mRenderLoop
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
virtual void zoomCamera3D(int viewGroup3DNumber, int zoomFactor)
void reportError(QString msg)
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
#define CX_ASSERT(statement)
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
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
virtual void centerToImageCenterInActiveViewGroup()
boost::shared_ptr< class InteractiveCropper > InteractiveCropperPtr
virtual void addDefaultLayout(LayoutData layoutData)
boost::shared_ptr< class View > ViewPtr
boost::shared_ptr< class Clippers > ClippersPtr
std::vector< QPointer< ViewCollectionWidget > > mLayoutWidgets
void pointSampled(Vector3D p_r)
void sessionChanged()
emitted after change to a new session (new or loaded or cleared)
virtual ~ViewImplService()
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
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.
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.
boost::shared_ptr< ViewWrapperVideo > ViewWrapperVideoPtr
boost::shared_ptr< ViewWrapper3D > ViewWrapper3DPtr
virtual NavigationPtr getNavigation(int group=0)
boost::shared_ptr< class ViewGroup > ViewGroupPtr
QString parseTextFromElement(QString name)
virtual CameraControlPtr getCameraControl()
void save()
save entire document.
boost::shared_ptr< class Navigation > NavigationPtr
boost::shared_ptr< class RenderWindowFactory > RenderWindowFactoryPtr
virtual void setCameraStyle(CAMERA_STYLE_TYPE style, int groupIdx)
QString enum2string(const ENUM &val)
void isSaving(QDomElement &root)
xml storage is available
bool getOffScreenRendering() const
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.