Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
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) 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 "cxDataRepContainer.h"
13 
14 #include "cxView.h"
15 #include "cxSliceProxy.h"
16 #include "cxGeometricRep2D.h"
17 #include "cxSettings.h"
18 #include "cxData.h"
19 #include "cxMesh.h"
20 #include "cxImage.h"
21 #include "cxPointMetricRep2D.h"
22 #include "cxSphereMetricRep2D.h"
23 #include "cxSphereMetric.h"
24 #include "cxDistanceMetricRep2D.h"
25 #include "cxLogger.h"
26 
27 namespace cx
28 {
29 
31 {
32  mSliceProxy = sliceProxy;
33 }
34 
36 {
37  mView = view;
38 }
39 
41 {
42  for (RepMap::iterator iter=mDataReps.begin(); iter!=mDataReps.end(); ++iter)
43  {
44  this->updateSettings(iter->second);
45  }
46 }
47 
49 {
50  if (boost::dynamic_pointer_cast<Mesh>(data))
51  {
52  this->meshAdded(boost::dynamic_pointer_cast<Mesh>(data));
53  }
54  else if (boost::dynamic_pointer_cast<PointMetric>(data))
55  {
56  this->pointMetricAdded(boost::dynamic_pointer_cast<PointMetric>(data));
57  }
58  else if (boost::dynamic_pointer_cast<SphereMetric>(data))
59  {
60  this->sphereMetricAdded(boost::dynamic_pointer_cast<SphereMetric>(data));
61  }
62  else if (boost::dynamic_pointer_cast<DistanceMetric>(data))
63  {
64  this->distanceMetricAdded(boost::dynamic_pointer_cast<DistanceMetric>(data));
65  }
66 }
67 
69 {
70  if (!mDataReps.count(uid))
71  return;
72 
73  mView->removeRep(mDataReps[uid]);
74  mDataReps.erase(uid);
75 }
76 
77 void DataRepContainer::meshAdded(MeshPtr mesh)
78 {
79  if (!mesh)
80  return;
81  if (mDataReps.count(mesh->getUid()))
82  return;
83 
84  GeometricRep2DPtr rep = GeometricRep2D::New(mesh->getUid() + "_rep2D");
85  rep->setSliceProxy(mSliceProxy);
86  rep->setMesh(mesh);
87  mView->addRep(rep);
88  mDataReps[mesh->getUid()] = rep;
89 }
90 
91 void DataRepContainer::pointMetricAdded(PointMetricPtr mesh)
92 {
93  if (!mesh)
94  return;
95  if (mDataReps.count(mesh->getUid()))
96  return;
97 
98  PointMetricRep2DPtr rep = PointMetricRep2D::New(mesh->getUid() + "_rep2D");
99  rep->setSliceProxy(mSliceProxy);
100  rep->setDataMetric(mesh);
101  rep->setDynamicSize(true);
102  mView->addRep(rep);
103  mDataReps[mesh->getUid()] = rep;
104  this->updateSettings(rep);
105 }
106 
107 void DataRepContainer::distanceMetricAdded(DistanceMetricPtr mesh)
108 {
109  if (!mesh)
110  return;
111  if (mDataReps.count(mesh->getUid()))
112  return;
113 
114  DistanceMetricRep2DPtr rep = DistanceMetricRep2D::New(mesh->getUid() + "_rep2D");
115  rep->setSliceProxy(mSliceProxy);
116  rep->setDataMetric(mesh);
117  rep->setDynamicSize(true);
118  mView->addRep(rep);
119  mDataReps[mesh->getUid()] = rep;
120  this->updateSettings(rep);
121 }
122 
123 void DataRepContainer::sphereMetricAdded(SphereMetricPtr mesh)
124 {
125  if (!mesh)
126  return;
127  if (mDataReps.count(mesh->getUid()))
128  return;
129 
130  SphereMetricRep2DPtr rep = SphereMetricRep2D::New(mesh->getUid() + "_rep2D");
131  rep->setSliceProxy(mSliceProxy);
132  rep->setDataMetric(mesh);
133  mView->addRep(rep);
134  mDataReps[mesh->getUid()] = rep;
135  this->updateSettings(rep);
136 }
137 
139 {
140  DataMetricRepPtr val = boost::dynamic_pointer_cast<DataMetricRep>(rep);
141  if (!val)
142  return;
143 
144  val->setGraphicsSize(settings()->value("View3D/sphereRadius").toDouble());
145  val->setShowLabel(settings()->value("View/showLabels").toBool());
146  val->setLabelSize(settings()->value("View3D/labelSize").toDouble());
147  val->setShowAnnotation(!settings()->value("View/showMetricNamesInCorner").toBool());
148 }
149 
150 
151 } // namespace cx
boost::shared_ptr< class DistanceMetricRep2D > DistanceMetricRep2DPtr
boost::shared_ptr< class DistanceMetric > DistanceMetricPtr
void setSliceProxy(SliceProxyPtr sliceProxy)
boost::shared_ptr< class SliceProxy > SliceProxyPtr
static DistanceMetricRep2DPtr New(const QString &uid="")
void setView(ViewPtr view)
boost::shared_ptr< class SphereMetric > SphereMetricPtr
void addData(DataPtr data)
boost::shared_ptr< class PointMetricRep2D > PointMetricRep2DPtr
Base class for all Data Metric reps.
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:21
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:24
boost::shared_ptr< class GeometricRep2D > GeometricRep2DPtr
void setGraphicsSize(double size)
Namespace for all CustusX production code.
boost::shared_ptr< class PointMetric > PointMetricPtr