Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxMetricReferenceArgumentList.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 
13 #include "cxData.h"
14 #include "cxPointMetric.h"
15 #include <QDomNode>
16 #include "cxTypeConversions.h"
17 
18 namespace cx
19 {
20 
22  QObject(NULL)
23 {
24  mArgument.resize(descriptions.size());
25  mDescriptions = descriptions;
26  this->setValidArgumentTypes(QStringList() << PointMetric::getTypeName());
27 }
28 
30 {
31  mValidTypes = types;
32 }
33 
35 {
36  if (mArgument[index] == p)
37  return;
38 
39  if (mArgument[index])
40  {
41  disconnect(mArgument[index].get(), SIGNAL(transformChanged()), this, SIGNAL(argumentsChanged()));
42  disconnect(mArgument[index].get(), SIGNAL(propertiesChanged()), this, SIGNAL(argumentsChanged()));
43  }
44 
45  mArgument[index] = p;
46 
47  if (mArgument[index])
48  {
49  connect(mArgument[index].get(), SIGNAL(transformChanged()), this, SIGNAL(argumentsChanged()));
50  connect(mArgument[index].get(), SIGNAL(propertiesChanged()), this, SIGNAL(argumentsChanged()));
51  }
52 
53  emit argumentsChanged();
54 }
55 
57 {
58  return mArgument[index];
59 }
60 
62 {
63  if (!p)
64  return false;
65  return mValidTypes.contains(p->getType());
66 }
67 
69 {
70  return (unsigned)mArgument.size();
71 }
72 
74 {
75  return mDescriptions[index];
76 }
77 
78 std::vector<Vector3D> MetricReferenceArgumentList::getRefCoords() const
79 {
80  std::vector<Vector3D> p(this->getCount());
81  for (unsigned i = 0; i < p.size(); ++i)
82  {
83  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(mArgument[i]);
84  if (!metric)
85  return std::vector<Vector3D>();
86  p[i] = metric->getRefCoord();
87  }
88  return p;
89 }
90 
91 std::vector<Transform3D> MetricReferenceArgumentList::getRefFrames() const
92 {
93  std::vector<Transform3D> p(this->getCount());
94  for (unsigned i = 0; i < p.size(); ++i)
95  {
96  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(mArgument[i]);
97  if (!metric)
98  return std::vector<Transform3D>();
99  p[i] = metric->getRefFrame();
100  }
101  return p;
102 }
103 
104 void MetricReferenceArgumentList::addXml(QDomNode& dataNode)
105 {
106  for (unsigned i = 0; i < mArgument.size(); ++i)
107  {
108  if (mArgument[i])
109  dataNode.toElement().setAttribute(QString("p%1").arg(i), mArgument[i]->getUid());
110  }
111 }
112 
113 void MetricReferenceArgumentList::parseXml(QDomNode& dataNode, const std::map<QString, DataPtr>& data)
114 {
115  for (unsigned i = 0; i < mArgument.size(); ++i)
116  {
117  QString uid = dataNode.toElement().attribute(QString("p%1").arg(i), "");
118  if (!data.count(uid))
119  continue;
120  this->set(i, data.find(uid)->second);
121  }
122 }
123 
125 {
126  QString retval;
127  for (unsigned i = 0; i < mArgument.size(); ++i)
128  {
129  retval += mArgument[i]->getUid();
130  retval += " ";
131  }
132 
133  retval.chop(1);
134  return retval;
135 }
136 
137 } // namespace cx
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:73
virtual void parseXml(QDomNode &dataNode, const std::map< QString, DataPtr > &data)
std::vector< Transform3D > getRefFrames() const
virtual void addXml(QDomNode &dataNode)
boost::shared_ptr< class Data > DataPtr
std::vector< Vector3D > getRefCoords() const
virtual Transform3D getRefFrame() const
Definition: cxDataMetric.h:53
MetricReferenceArgumentList(QStringList descriptions)
static QString getTypeName()
Definition: cxPointMetric.h:58
Base class for all Data Metrics.
Definition: cxDataMetric.h:43
virtual Vector3D getRefCoord() const =0
Namespace for all CustusX production code.