Fraxinus  17.12-rc2
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) 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 
34 #include "cxData.h"
35 #include "cxPointMetric.h"
36 #include <QDomNode>
37 #include "cxTypeConversions.h"
38 
39 namespace cx
40 {
41 
43  QObject(NULL)
44 {
45  mArgument.resize(descriptions.size());
46  mDescriptions = descriptions;
47  this->setValidArgumentTypes(QStringList() << "pointMetric");
48 }
49 
51 {
52  mValidTypes = types;
53 }
54 
56 {
57  if (mArgument[index] == p)
58  return;
59 
60  if (mArgument[index])
61  {
62  disconnect(mArgument[index].get(), SIGNAL(transformChanged()), this, SIGNAL(argumentsChanged()));
63  disconnect(mArgument[index].get(), SIGNAL(propertiesChanged()), this, SIGNAL(argumentsChanged()));
64  }
65 
66  mArgument[index] = p;
67 
68  if (mArgument[index])
69  {
70  connect(mArgument[index].get(), SIGNAL(transformChanged()), this, SIGNAL(argumentsChanged()));
71  connect(mArgument[index].get(), SIGNAL(propertiesChanged()), this, SIGNAL(argumentsChanged()));
72  }
73 
74  emit argumentsChanged();
75 }
76 
78 {
79  return mArgument[index];
80 }
81 
83 {
84  if (!p)
85  return false;
86  return mValidTypes.contains(p->getType());
87 }
88 
90 {
91  return (unsigned)mArgument.size();
92 }
93 
95 {
96  return mDescriptions[index];
97 }
98 
99 std::vector<Vector3D> MetricReferenceArgumentList::getRefCoords() const
100 {
101  std::vector<Vector3D> p(this->getCount());
102  for (unsigned i = 0; i < p.size(); ++i)
103  {
104  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(mArgument[i]);
105  if (!metric)
106  return std::vector<Vector3D>();
107  p[i] = metric->getRefCoord();
108  }
109  return p;
110 }
111 
112 std::vector<Transform3D> MetricReferenceArgumentList::getRefFrames() const
113 {
114  std::vector<Transform3D> p(this->getCount());
115  for (unsigned i = 0; i < p.size(); ++i)
116  {
117  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(mArgument[i]);
118  if (!metric)
119  return std::vector<Transform3D>();
120  p[i] = metric->getRefFrame();
121  }
122  return p;
123 }
124 
125 void MetricReferenceArgumentList::addXml(QDomNode& dataNode)
126 {
127  for (unsigned i = 0; i < mArgument.size(); ++i)
128  {
129  if (mArgument[i])
130  dataNode.toElement().setAttribute(QString("p%1").arg(i), mArgument[i]->getUid());
131  }
132 }
133 
134 void MetricReferenceArgumentList::parseXml(QDomNode& dataNode, const std::map<QString, DataPtr>& data)
135 {
136  for (unsigned i = 0; i < mArgument.size(); ++i)
137  {
138  QString uid = dataNode.toElement().attribute(QString("p%1").arg(i), "");
139  if (!data.count(uid))
140  continue;
141  this->set(i, data.find(uid)->second);
142  }
143 }
144 
146 {
147  QString retval;
148  for (unsigned i = 0; i < mArgument.size(); ++i)
149  {
150  retval += mArgument[i]->getUid();
151  retval += " ";
152  }
153 
154  retval.chop(1);
155  return retval;
156 }
157 
158 } // namespace cx
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:94
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:74
MetricReferenceArgumentList(QStringList descriptions)
Base class for all Data Metrics.
Definition: cxDataMetric.h:64
virtual Vector3D getRefCoord() const =0
Namespace for all CustusX production code.