CustusX  18.04
An IGT application
cxViewGroup.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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxViewGroup.h"
13 
14 #include <vector>
15 #include <QtWidgets>
16 
17 #include <vtkRenderWindow.h>
18 #include "cxView.h"
19 #include "cxSliceProxy.h"
20 #include "cxSlicerRepSW.h"
21 #include "cxToolRep2D.h"
22 #include "cxUtilHelpers.h"
23 #include "cxSlicePlanes3DRep.h"
24 
25 #include "cxTrackingService.h"
26 #include "cxViewWrapper2D.h"
27 #include "cxCameraControl.h"
28 #include "cxData.h"
29 #include "cxViewWrapper.h"
30 #include "cxManualTool.h"
31 #include "cxVolumeHelpers.h"
32 #include "cxTypeConversions.h"
33 #include "cxCoreServices.h"
34 #include "cxCameraStyle.h"
35 #include "cxPatientModelService.h"
36 #include "cxImage.h"
37 #include "cxMesh.h"
38 #include "cxTrackedStream.h"
39 #include "cxActiveData.h"
40 #include "cxLogger.h"
41 
42 namespace cx
43 {
44 
45 
47 {
48  mBackend = backend;
49  mViewGroupData.reset(new ViewGroupData(backend, uid));
51 
52  connect(mViewGroupData.get(), &ViewGroupData::optionsChanged, this, &ViewGroup::optionChangedSlot);
53  this->optionChangedSlot();
54 }
55 
57 {
58 }
59 
60 void ViewGroup::optionChangedSlot()
61 {
62  mCameraStyle->setCameraStyle(mViewGroupData->getOptions().mCameraStyle);
63 }
64 
67 void ViewGroup::addView(ViewWrapperPtr wrapper, SharedOpenGLContextPtr sharedOpenGLContext)
68 {
69  wrapper->setSharedOpenGLContext(sharedOpenGLContext);
70  mViews.push_back(wrapper->getView());
71  mViewWrappers.push_back(wrapper);
72 
73  // add state
74  wrapper->setViewGroup(mViewGroupData);
75  mCameraStyle->addView(wrapper->getView());
76 
77  View* view = wrapper->getView().get();
78  // connect signals
79 // connect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(activateManualToolSlot()));
80  connect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(mouseClickInViewGroupSlot()));
81  connect(view, SIGNAL(focusChange(bool, Qt::FocusReason)), this, SLOT(mouseClickInViewGroupSlot()));
82 }
83 
85 {
86  for (unsigned i = 0; i < mViewWrappers.size(); ++i)
87  {
88  ViewWrapperPtr wrapper = mViewWrappers[i];
89  View* view = wrapper->getView().get();
90 
91 // disconnect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(activateManualToolSlot()));
92  disconnect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(mouseClickInViewGroupSlot()));
93  disconnect(view, SIGNAL(focusChange(bool, Qt::FocusReason)), this, SLOT(mouseClickInViewGroupSlot()));
94  }
95 
96  mViews.clear();
97  mViewWrappers.clear();
98  mCameraStyle->clearViews();
99 }
100 
102 {
103  for (unsigned i = 0; i < mViewWrappers.size(); ++i)
104  {
105  if (mViewWrappers[i]->getView()->getUid() == viewUid)
106  return mViewWrappers[i];
107  }
108  return ViewWrapperPtr();
109 }
110 
112 {
113  std::vector<ImagePtr> images = mViewGroupData->getImages(DataViewProperties::createFull());
114  std::vector<MeshPtr> meshes = mViewGroupData->getMeshes(DataViewProperties::createFull());
115  std::vector<TrackedStreamPtr> trackedStreams = mViewGroupData->getTrackedStreams(DataViewProperties::createFull());
116  ActiveDataPtr activeData = mBackend->patient()->getActiveData();
117 
118  if(shouldUpdateActiveData(activeData->getActive<Mesh>(), meshes))
119  activeData->setActive(meshes.front()->getUid());
120  if(shouldUpdateActiveData(activeData->getActive<Image>(), images))
121  activeData->setActive(images.front()->getUid());
122  if(shouldUpdateActiveData(activeData->getActive<TrackedStream>(), trackedStreams))
123  activeData->setActive(trackedStreams.front()->getUid());
124 
125  View* view = static_cast<View*>(this->sender());
126  if (view && mActiveView)
127  mActiveView->set(view->getUid());
128 }
129 
130 template<class T>
131 bool ViewGroup::shouldUpdateActiveData(T activeData, std::vector<T> datas) const
132 {
133  bool activeDataExistsInGroup = std::find(datas.begin(), datas.end(), activeData) != datas.end();
134  return !activeDataExistsInGroup && !datas.empty();
135 }
136 
137 std::vector<ViewPtr> ViewGroup::getViews() const
138 {
139  return mViews;
140 }
141 
143 {
144  mActiveView = val;
145 }
146 
147 void ViewGroup::addXml(QDomNode& dataNode)
148 {
149  mViewGroupData->addXml(dataNode);
150 }
151 
153 {
154  mViewGroupData->clearData();
155 }
156 
157 void ViewGroup::parseXml(QDomNode dataNode)
158 {
159  mViewGroupData->parseXml(dataNode);
160 }
161 
163 {
164  for (unsigned j = 0; j < mViews.size(); ++j)
165  {
166  if (mViews[j] && (mViews[j]->getType()==View::VIEW_3D))
167  return true;
168  }
169  return false;
170 }
171 
172 } //cx
ViewGroupDataPtr mViewGroupData
Definition: cxViewGroup.h:75
A mesh data set.
Definition: cxMesh.h:45
CameraStylePtr mCameraStyle
Definition: cxViewGroup.h:77
CoreServicesPtr mBackend
Definition: cxViewGroup.h:78
void clearPatientData()
std::vector< ViewPtr > mViews
Definition: cxViewGroup.h:73
boost::shared_ptr< class ViewWrapper > ViewWrapperPtr
void addView(ViewWrapperPtr wrapper, SharedOpenGLContextPtr sharedOpenGLContext)
Definition: cxViewGroup.cpp:67
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:21
Container for data shared between all members of a view group.
A data set for video streams (2D/3D).
void mouseClickInViewGroupSlot()
void removeViews()
Definition: cxViewGroup.cpp:84
boost::shared_ptr< class SharedOpenGLContext > SharedOpenGLContextPtr
A volumetric data set.
Definition: cxImage.h:45
bool contains3DView() const
static DataViewProperties createFull()
std::vector< ViewWrapperPtr > mViewWrappers
Definition: cxViewGroup.h:76
virtual void parseXml(QDomNode dataNode)
load internal state info from dataNode
ViewWrapperPtr getViewWrapperFromViewUid(QString viewUid)
virtual QString getUid()=0
Get a views unique id.
std::vector< ViewPtr > getViews() const
virtual ~ViewGroup()
Definition: cxViewGroup.cpp:56
SyncedValuePtr mActiveView
Definition: cxViewGroup.h:79
boost::shared_ptr< class CoreServices > CoreServicesPtr
Definition: cxCameraStyle.h:38
boost::shared_ptr< class SyncedValue > SyncedValuePtr
Definition: cxViewGroup.h:30
virtual void addXml(QDomNode &dataNode)
store internal state info in dataNode
void initializeActiveView(SyncedValuePtr val)
ViewGroup(CoreServicesPtr backend, QString uid)
Definition: cxViewGroup.cpp:46
Namespace for all CustusX production code.