Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxDataRepContainer.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 "cxDataRepContainer.h"
34 
35 #include "cxView.h"
36 #include "cxSliceProxy.h"
37 #include "cxGeometricRep2D.h"
38 #include "cxSettings.h"
39 #include "cxData.h"
40 #include "cxMesh.h"
41 #include "cxImage.h"
42 #include "cxPointMetricRep2D.h"
43 #include "cxSphereMetricRep2D.h"
44 #include "cxSphereMetric.h"
45 
46 namespace cx
47 {
48 
50 {
51  mSliceProxy = sliceProxy;
52 }
53 
55 {
56  mView = view;
57 }
58 
60 {
61  for (RepMap::iterator iter=mDataReps.begin(); iter!=mDataReps.end(); ++iter)
62  {
63  this->updateSettings(iter->second);
64  }
65 }
66 
68 {
69  if (boost::dynamic_pointer_cast<Mesh>(data))
70  {
71  this->meshAdded(boost::dynamic_pointer_cast<Mesh>(data));
72  }
73  else if (boost::dynamic_pointer_cast<PointMetric>(data))
74  {
75  this->pointMetricAdded(boost::dynamic_pointer_cast<PointMetric>(data));
76  }
77  else if (boost::dynamic_pointer_cast<SphereMetric>(data))
78  {
79  this->sphereMetricAdded(boost::dynamic_pointer_cast<SphereMetric>(data));
80  }
81 }
82 
84 {
85  if (!mDataReps.count(uid))
86  return;
87 
88  mView->removeRep(mDataReps[uid]);
89  mDataReps.erase(uid);
90 }
91 
92 void DataRepContainer::meshAdded(MeshPtr mesh)
93 {
94  if (!mesh)
95  return;
96  if (mDataReps.count(mesh->getUid()))
97  return;
98 
99  GeometricRep2DPtr rep = GeometricRep2D::New(mesh->getUid() + "_rep2D");
100  rep->setSliceProxy(mSliceProxy);
101  rep->setMesh(mesh);
102  mView->addRep(rep);
103  mDataReps[mesh->getUid()] = rep;
104 }
105 
106 void DataRepContainer::pointMetricAdded(PointMetricPtr mesh)
107 {
108  if (!mesh)
109  return;
110  if (mDataReps.count(mesh->getUid()))
111  return;
112 
113  PointMetricRep2DPtr rep = PointMetricRep2D::New(mesh->getUid() + "_rep2D");
114  rep->setSliceProxy(mSliceProxy);
115  rep->setDataMetric(mesh);
116  rep->setDynamicSize(true);
117  mView->addRep(rep);
118  mDataReps[mesh->getUid()] = rep;
119  this->updateSettings(rep);
120 }
121 
122 void DataRepContainer::sphereMetricAdded(SphereMetricPtr mesh)
123 {
124  if (!mesh)
125  return;
126  if (mDataReps.count(mesh->getUid()))
127  return;
128 
129  SphereMetricRep2DPtr rep = SphereMetricRep2D::New(mesh->getUid() + "_rep2D");
130  rep->setSliceProxy(mSliceProxy);
131  rep->setDataMetric(mesh);
132  mView->addRep(rep);
133  mDataReps[mesh->getUid()] = rep;
134  this->updateSettings(rep);
135 }
136 
138 {
139  DataMetricRepPtr val = boost::dynamic_pointer_cast<DataMetricRep>(rep);
140  if (!val)
141  return;
142 
143  val->setGraphicsSize(settings()->value("View3D/sphereRadius").toDouble());
144  val->setShowLabel(settings()->value("View/showLabels").toBool());
145  val->setLabelSize(settings()->value("View3D/labelSize").toDouble());
146  val->setShowAnnotation(!settings()->value("View/showMetricNamesInCorner").toBool());
147 }
148 
149 
150 } // namespace cx
void setSliceProxy(SliceProxyPtr sliceProxy)
boost::shared_ptr< class SliceProxy > SliceProxyPtr
void setView(ViewPtr view)
boost::shared_ptr< class SphereMetric > SphereMetricPtr
void addData(DataPtr data)
boost::shared_ptr< class PointMetricRep2D > PointMetricRep2DPtr
boost::shared_ptr< class DataMetricRep > DataMetricRepPtr
boost::shared_ptr< class View > ViewPtr
static PointMetricRep2DPtr New(const QString &uid="")
static SphereMetricRep2DPtr New(const QString &uid="")
void removeData(QString uid)
boost::shared_ptr< class Data > DataPtr
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:42
static GeometricRep2DPtr New(const QString &uid="")
boost::shared_ptr< class SphereMetricRep2D > SphereMetricRep2DPtr
boost::shared_ptr< class Mesh > MeshPtr
boost::shared_ptr< class Rep > RepPtr
Definition: cxRepManager.h:45
boost::shared_ptr< class GeometricRep2D > GeometricRep2DPtr
boost::shared_ptr< class PointMetric > PointMetricPtr