CustusX  16.5.0-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxShapedMetric.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 "cxShapedMetric.h"
34 
35 #include "cxBoundingBox3D.h"
36 #include "cxTypeConversions.h"
37 #include "cxPatientModelService.h"
38 #include "cxTypeConversions.h"
39 
40 namespace cx
41 {
42 
43 DonutMetric::DonutMetric(const QString& uid, const QString& name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider) :
44  DataMetric(uid, name, dataManager, spaceProvider)
45 {
46  mArguments.reset(new MetricReferenceArgumentList(QStringList() << "position" << "direction"));
47  connect(mArguments.get(), SIGNAL(argumentsChanged()), this, SIGNAL(transformChanged()));
48  mRadius = 5;
49  mThickness = 2;
50  mHeight = 0;
51  mFlat = true;
52 }
53 
54 DonutMetricPtr DonutMetric::create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
55 {
56  return DonutMetricPtr(new DonutMetric(uid, name, dataManager, spaceProvider));
57 }
58 
60 {
61 }
62 
63 void DonutMetric::addXml(QDomNode& dataNode)
64 {
65  DataMetric::addXml(dataNode);
66 
67  mArguments->addXml(dataNode);
68  dataNode.toElement().setAttribute("radius", mRadius);
69  dataNode.toElement().setAttribute("thickness", mThickness);
70  dataNode.toElement().setAttribute("height", mHeight);
71  dataNode.toElement().setAttribute("flat", mFlat);
72 }
73 
74 void DonutMetric::parseXml(QDomNode& dataNode)
75 {
76  DataMetric::parseXml(dataNode);
77 
78  mArguments->parseXml(dataNode, mDataManager->getData());
79  mRadius = dataNode.toElement().attribute("radius", qstring_cast(mRadius)).toDouble();
80  mThickness = dataNode.toElement().attribute("thickness", qstring_cast(mThickness)).toDouble();
81  mHeight = dataNode.toElement().attribute("height", qstring_cast(mHeight)).toDouble();
82  mFlat = dataNode.toElement().attribute("flat", qstring_cast(mFlat)).toInt();
83 }
84 
86 {
87  return !mArguments->getRefCoords().empty();
88 }
89 
91 {
92  return mArguments->getRefCoords().front();
93 }
94 
96 {
97  return DoubleBoundingBox3D::fromCloud(mArguments->getRefCoords());
98 }
99 
101 {
102  std::vector<Vector3D> coords = mArguments->getRefCoords();
103  if (coords.empty())
104  return Vector3D::Zero();
105  return coords[0];
106 }
107 
109 {
110  std::vector<Vector3D> coords = mArguments->getRefCoords();
111  if (coords.size()<2)
112  return Vector3D::UnitZ();
113  Vector3D diff = (coords[1]-coords[0]);
114  if (similar(diff.length(), 0.0))
115  return Vector3D(0,1,0);
116  return diff.normal();
117 }
118 
119 
121 {
122  return QString("%1 %2")
123  .arg(this->getSingleLineHeader())
124  .arg(qstring_cast(""));
125 }
126 
127 void DonutMetric::setRadius(double val)
128 {
129  mRadius = val;
130  emit propertiesChanged();
131 }
132 
134 {
135  return mRadius;
136 }
137 
139 {
140  mThickness = val;
141  emit propertiesChanged();
142 }
143 
145 {
146  return mThickness;
147 }
148 
149 void DonutMetric::setHeight(double val)
150 {
151  mHeight = val;
152 }
153 
155 {
156  return mHeight;
157 }
158 
159 void DonutMetric::setFlat(bool val)
160 {
161  mFlat = val;
162  emit propertiesChanged();
163 }
164 
166 {
167  return mFlat;
168 }
169 
170 }
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
QString qstring_cast(const T &val)
virtual DoubleBoundingBox3D boundingBox() const
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
boost::shared_ptr< class DonutMetric > DonutMetricPtr
void propertiesChanged()
emitted when one of the metadata properties (uid, name etc) changes
virtual Vector3D getRefCoord() const
double getThickness() const
PatientModelServicePtr mDataManager
Definition: cxDataMetric.h:88
static DoubleBoundingBox3D fromCloud(std::vector< Vector3D > cloud)
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
double getRadius() const
void parseXml(QDomNode &dataNode)
Use a XML node to load data.
virtual QString getAsSingleLineString() const
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Data class that represents a donut.
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
bool getFlat() const
static DonutMetricPtr create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
QString getSingleLineHeader() const
virtual ~DonutMetric()
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
Vector3D getPosition()
double getHeight() const
void setRadius(double val)
void setThickness(double val)
void setHeight(double val)
virtual bool isValid() const
void setFlat(bool val)
Vector3D getDirection()