Fraxinus  17.12-rc4
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) 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 "cxViewGroup.h"
34 
35 #include <vector>
36 #include <QtWidgets>
37 
38 #include <vtkRenderWindow.h>
39 #include "cxView.h"
40 #include "cxSliceProxy.h"
41 #include "cxSlicerRepSW.h"
42 #include "cxToolRep2D.h"
43 #include "cxUtilHelpers.h"
44 #include "cxSlicePlanes3DRep.h"
45 
46 #include "cxTrackingService.h"
47 #include "cxViewWrapper2D.h"
48 #include "cxCameraControl.h"
49 #include "cxData.h"
50 #include "cxViewWrapper.h"
51 #include "cxManualTool.h"
52 #include "cxVolumeHelpers.h"
53 #include "cxTypeConversions.h"
54 #include "cxCoreServices.h"
55 #include "cxCameraStyle.h"
56 #include "cxPatientModelService.h"
57 #include "cxImage.h"
58 #include "cxMesh.h"
59 #include "cxTrackedStream.h"
60 #include "cxActiveData.h"
61 #include "cxLogger.h"
62 
63 namespace cx
64 {
65 
66 
68 {
69  mBackend = backend;
70  mViewGroupData.reset(new ViewGroupData(backend, uid));
72 
73  connect(mViewGroupData.get(), &ViewGroupData::optionsChanged, this, &ViewGroup::optionChangedSlot);
74  this->optionChangedSlot();
75 }
76 
78 {
79 }
80 
81 void ViewGroup::optionChangedSlot()
82 {
83  mCameraStyle->setCameraStyle(mViewGroupData->getOptions().mCameraStyle);
84 }
85 
88 void ViewGroup::addView(ViewWrapperPtr wrapper, SharedOpenGLContextPtr sharedOpenGLContext)
89 {
90  wrapper->setSharedOpenGLContext(sharedOpenGLContext);
91  mViews.push_back(wrapper->getView());
92  mViewWrappers.push_back(wrapper);
93 
94  // add state
95  wrapper->setViewGroup(mViewGroupData);
96  mCameraStyle->addView(wrapper->getView());
97 
98  View* view = wrapper->getView().get();
99  // connect signals
100 // connect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(activateManualToolSlot()));
101  connect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(mouseClickInViewGroupSlot()));
102  connect(view, SIGNAL(focusChange(bool, Qt::FocusReason)), this, SLOT(mouseClickInViewGroupSlot()));
103 }
104 
106 {
107  for (unsigned i = 0; i < mViewWrappers.size(); ++i)
108  {
109  ViewWrapperPtr wrapper = mViewWrappers[i];
110  View* view = wrapper->getView().get();
111 
112 // disconnect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(activateManualToolSlot()));
113  disconnect(view, SIGNAL(mousePress(int, int, Qt::MouseButtons)), this, SLOT(mouseClickInViewGroupSlot()));
114  disconnect(view, SIGNAL(focusChange(bool, Qt::FocusReason)), this, SLOT(mouseClickInViewGroupSlot()));
115  }
116 
117  mViews.clear();
118  mViewWrappers.clear();
119  mCameraStyle->clearViews();
120 }
121 
123 {
124  for (unsigned i = 0; i < mViewWrappers.size(); ++i)
125  {
126  if (mViewWrappers[i]->getView()->getUid() == viewUid)
127  return mViewWrappers[i];
128  }
129  return ViewWrapperPtr();
130 }
131 
133 {
134  std::vector<ImagePtr> images = mViewGroupData->getImages(DataViewProperties::createFull());
135  std::vector<MeshPtr> meshes = mViewGroupData->getMeshes(DataViewProperties::createFull());
136  std::vector<TrackedStreamPtr> trackedStreams = mViewGroupData->getTrackedStreams(DataViewProperties::createFull());
137  ActiveDataPtr activeData = mBackend->patient()->getActiveData();
138 
139  if(shouldUpdateActiveData(activeData->getActive<Mesh>(), meshes))
140  activeData->setActive(meshes.front()->getUid());
141  if(shouldUpdateActiveData(activeData->getActive<Image>(), images))
142  activeData->setActive(images.front()->getUid());
143  if(shouldUpdateActiveData(activeData->getActive<TrackedStream>(), trackedStreams))
144  activeData->setActive(trackedStreams.front()->getUid());
145 
146  View* view = static_cast<View*>(this->sender());
147  if (view && mActiveView)
148  mActiveView->set(view->getUid());
149 }
150 
151 template<class T>
152 bool ViewGroup::shouldUpdateActiveData(T activeData, std::vector<T> datas) const
153 {
154  bool activeDataExistsInGroup = std::find(datas.begin(), datas.end(), activeData) != datas.end();
155  return !activeDataExistsInGroup && !datas.empty();
156 }
157 
158 std::vector<ViewPtr> ViewGroup::getViews() const
159 {
160  return mViews;
161 }
162 
164 {
165  mActiveView = val;
166 }
167 
168 void ViewGroup::addXml(QDomNode& dataNode)
169 {
170  mViewGroupData->addXml(dataNode);
171 }
172 
174 {
175  mViewGroupData->clearData();
176 }
177 
178 void ViewGroup::parseXml(QDomNode dataNode)
179 {
180  mViewGroupData->parseXml(dataNode);
181 }
182 
184 {
185  for (unsigned j = 0; j < mViews.size(); ++j)
186  {
187  if (mViews[j] && (mViews[j]->getType()==View::VIEW_3D))
188  return true;
189  }
190  return false;
191 }
192 
193 } //cx
ViewGroupDataPtr mViewGroupData
Definition: cxViewGroup.h:96
A mesh data set.
Definition: cxMesh.h:66
CameraStylePtr mCameraStyle
Definition: cxViewGroup.h:98
CoreServicesPtr mBackend
Definition: cxViewGroup.h:99
void clearPatientData()
std::vector< ViewPtr > mViews
Definition: cxViewGroup.h:94
boost::shared_ptr< class ViewWrapper > ViewWrapperPtr
void addView(ViewWrapperPtr wrapper, SharedOpenGLContextPtr sharedOpenGLContext)
Definition: cxViewGroup.cpp:88
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:42
Container for data shared between all members of a view group.
A data set for video streams (2D/3D).
void mouseClickInViewGroupSlot()
void removeViews()
boost::shared_ptr< class SharedOpenGLContext > SharedOpenGLContextPtr
A volumetric data set.
Definition: cxImage.h:66
bool contains3DView() const
static DataViewProperties createFull()
std::vector< ViewWrapperPtr > mViewWrappers
Definition: cxViewGroup.h:97
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:77
SyncedValuePtr mActiveView
Definition: cxViewGroup.h:100
boost::shared_ptr< class CoreServices > CoreServicesPtr
Definition: cxCameraStyle.h:59
boost::shared_ptr< class SyncedValue > SyncedValuePtr
Definition: cxViewGroup.h:51
virtual void addXml(QDomNode &dataNode)
store internal state info in dataNode
void initializeActiveView(SyncedValuePtr val)
ViewGroup(CoreServicesPtr backend, QString uid)
Definition: cxViewGroup.cpp:67
Namespace for all CustusX production code.