Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxAngleMetric.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 
34 
35 #include "cxAngleMetric.h"
36 
37 #include "cxBoundingBox3D.h"
38 #include "cxTypeConversions.h"
39 
40 #include "cxPatientModelService.h"
41 
42 namespace cx
43 {
44 
45 AngleMetric::AngleMetric(const QString& uid, const QString& name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider) :
46  DataMetric(uid, name, dataManager, spaceProvider)
47 {
48  mUseSimpleVisualization = false;
49  mArguments.reset(new MetricReferenceArgumentList(QStringList() << "point 0" << "point 1" << "point 2" << "point 3"));
50  mArguments->setValidArgumentTypes(QStringList() << "pointMetric");
51  connect(mArguments.get(), SIGNAL(argumentsChanged()), this, SLOT(resetCachedValues()));
52  connect(mArguments.get(), SIGNAL(argumentsChanged()), this, SIGNAL(transformChanged()));
53 }
54 
55 AngleMetricPtr AngleMetric::create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
56 {
57  return AngleMetricPtr(new AngleMetric(uid, name, dataManager, spaceProvider));
58 }
59 
60 //AngleMetricPtr AngleMetric::create(QDomNode node)
61 //{
62 // AngleMetricPtr retval = AngleMetric::create("");
63 // retval->parseXml(node);
64 // return retval;
65 //}
66 
68 {
69 }
70 
71 void AngleMetric::addXml(QDomNode& dataNode)
72 {
73  DataMetric::addXml(dataNode);
74  mArguments->addXml(dataNode);
75  dataNode.toElement().setAttribute("useSimpleVisualization", QString::number(mUseSimpleVisualization));
76 }
77 
78 void AngleMetric::parseXml(QDomNode& dataNode)
79 {
80  DataMetric::parseXml(dataNode);
81 
82  mArguments->parseXml(dataNode, mDataManager->getData());
83 
84  mUseSimpleVisualization = dataNode.toElement().attribute("useSimpleVisualization", QString::number(mUseSimpleVisualization)).toInt();
85  this->resetCachedValues();
86 }
87 
88 void AngleMetric::resetCachedValues()
89 {
90  mCachedEndPoints.reset();
91 }
92 
94 {
95  return !this->getEndpoints().empty();
96 }
97 
98 std::vector<Vector3D> AngleMetric::getEndpoints() const
99 {
100  if (!mCachedEndPoints.isValid())
101  {
102  mCachedEndPoints.set(mArguments->getRefCoords());
103  }
104  return mCachedEndPoints.get();
105 }
106 
108 {
109  return this->boundingBox().center();
110 }
111 
112 double AngleMetric::getAngle() const
113 {
114  std::vector<Vector3D> p = this->getEndpoints();
115 
116  if (p.empty())
117  return -1;
118 
119  Vector3D a = (p[0] - p[1]).normalized();
120  Vector3D b = (p[3] - p[2]).normalized();
121 
122  double angle = acos(dot(a, b) / a.length() / b.length());
123  return angle;
124 }
125 
127 {
128  return QString("%1*").arg(this->getAngle() / M_PI * 180, 0, 'f', 1);
129 }
130 
132 {
134 }
135 
137 {
138  return QString("%1 %2")
139  .arg(this->getSingleLineHeader())
140  .arg(qstring_cast(this->getAngle()));
141 }
142 
144 {
145  return mUseSimpleVisualization;
146 }
147 
149 {
150  mUseSimpleVisualization = val;
151  emit propertiesChanged();
152 }
153 
154 
155 }
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
QString qstring_cast(const T &val)
bool isValid() const
void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
static AngleMetricPtr create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
void propertiesChanged()
emitted when one of the metadata properties (uid, name etc) changes
double getAngle() const
virtual Vector3D getRefCoord() const
PatientModelServicePtr mDataManager
Definition: cxDataMetric.h:88
boost::shared_ptr< class AngleMetric > AngleMetricPtr
Definition: cxAngleMetric.h:54
virtual QString getValueAsString() const
static DoubleBoundingBox3D fromCloud(std::vector< Vector3D > cloud)
bool getUseSimpleVisualization() const
virtual ~AngleMetric()
void parseXml(QDomNode &dataNode)
Use a XML node to load data.
virtual bool isValid() const
virtual DoubleBoundingBox3D boundingBox() const
void set(const T &val)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
QString getSingleLineHeader() const
double dot(const Vector3D &a, const Vector3D &b)
compute inner product (or dot product) of a and b.
Definition: cxVector3D.cpp:67
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.
void setUseSimpleVisualization(bool val)
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
std::vector< Vector3D > getEndpoints() const
Vector3D center() const
virtual QString getAsSingleLineString() const
const T & get() const
Data class that represents an angle between two lines.
Definition: cxAngleMetric.h:67
#define M_PI