Fraxinus  17.12
An IGT application
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 
61 {
62 }
63 
64 void AngleMetric::addXml(QDomNode& dataNode)
65 {
66  DataMetric::addXml(dataNode);
67  mArguments->addXml(dataNode);
68  dataNode.toElement().setAttribute("useSimpleVisualization", QString::number(mUseSimpleVisualization));
69 }
70 
71 void AngleMetric::parseXml(QDomNode& dataNode)
72 {
73  DataMetric::parseXml(dataNode);
74 
75  mArguments->parseXml(dataNode, mDataManager->getDatas());
76 
77  mUseSimpleVisualization = dataNode.toElement().attribute("useSimpleVisualization", QString::number(mUseSimpleVisualization)).toInt();
78  this->resetCachedValues();
79 }
80 
81 void AngleMetric::resetCachedValues()
82 {
83  mCachedEndPoints.reset();
84 }
85 
87 {
88  return !this->getEndpoints().empty();
89 }
90 
91 std::vector<Vector3D> AngleMetric::getEndpoints() const
92 {
93  if (!mCachedEndPoints.isValid())
94  {
95  mCachedEndPoints.set(mArguments->getRefCoords());
96  }
97  return mCachedEndPoints.get();
98 }
99 
101 {
102  return this->boundingBox().center();
103 }
104 
105 double AngleMetric::getAngle() const
106 {
107  std::vector<Vector3D> p = this->getEndpoints();
108 
109  if (p.empty())
110  return -1;
111 
112  Vector3D a = (p[0] - p[1]).normalized();
113  Vector3D b = (p[3] - p[2]).normalized();
114 
115  double angle = acos(dot(a, b) / a.length() / b.length());
116  return angle;
117 }
118 
120 {
121  return QString("%1*").arg(this->getAngle() / M_PI * 180, 0, 'f', 1);
122 }
123 
125 {
126  return DoubleBoundingBox3D::fromCloud(this->getEndpoints());
127 }
128 
130 {
131  return mUseSimpleVisualization;
132 }
133 
135 {
136  mUseSimpleVisualization = val;
137  emit propertiesChanged();
138 }
139 
140 
141 }
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
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
double getAngle() const
virtual Vector3D getRefCoord() const
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
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
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)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
std::vector< Vector3D > getEndpoints() const
Data class that represents an angle between two lines.
Definition: cxAngleMetric.h:67
#define M_PI
Namespace for all CustusX production code.