NorMIT-nav  22.09
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) 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 
12 
13 
14 #include "cxAngleMetric.h"
15 
16 #include "cxBoundingBox3D.h"
17 #include "cxTypeConversions.h"
18 
19 #include "cxPatientModelService.h"
20 
21 namespace cx
22 {
23 
24 AngleMetric::AngleMetric(const QString& uid, const QString& name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider) :
25  DataMetric(uid, name, dataManager, spaceProvider)
26 {
27  mUseSimpleVisualization = false;
28  mArguments.reset(new MetricReferenceArgumentList(QStringList() << "point 0" << "point 1" << "point 2" << "point 3"));
29  mArguments->setValidArgumentTypes(QStringList() << PointMetric::getTypeName());
30  connect(mArguments.get(), SIGNAL(argumentsChanged()), this, SLOT(resetCachedValues()));
31  connect(mArguments.get(), SIGNAL(argumentsChanged()), this, SIGNAL(transformChanged()));
32 }
33 
34 AngleMetricPtr AngleMetric::create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
35 {
36  return AngleMetricPtr(new AngleMetric(uid, name, dataManager, spaceProvider));
37 }
38 
40 {
41 }
42 
43 void AngleMetric::addXml(QDomNode& dataNode)
44 {
45  DataMetric::addXml(dataNode);
46  mArguments->addXml(dataNode);
47  dataNode.toElement().setAttribute("useSimpleVisualization", QString::number(mUseSimpleVisualization));
48 }
49 
50 void AngleMetric::parseXml(QDomNode& dataNode)
51 {
52  DataMetric::parseXml(dataNode);
53 
54  mArguments->parseXml(dataNode, mDataManager->getDatas());
55 
56  mUseSimpleVisualization = dataNode.toElement().attribute("useSimpleVisualization", QString::number(mUseSimpleVisualization)).toInt();
57  this->resetCachedValues();
58 }
59 
60 void AngleMetric::resetCachedValues()
61 {
62  mCachedEndPoints.reset();
63 }
64 
66 {
67  return !this->getEndpoints().empty();
68 }
69 
70 std::vector<Vector3D> AngleMetric::getEndpoints() const
71 {
72  if (!mCachedEndPoints.isValid())
73  {
74  mCachedEndPoints.set(mArguments->getRefCoords());
75  }
76  return mCachedEndPoints.get();
77 }
78 
80 {
81  return this->boundingBox().center();
82 }
83 
84 double AngleMetric::getAngle() const
85 {
86  std::vector<Vector3D> p = this->getEndpoints();
87 
88  if (p.empty())
89  return -1;
90 
91  Vector3D a = (p[0] - p[1]).normalized();
92  Vector3D b = (p[3] - p[2]).normalized();
93 
94  double angle = acos(dot(a, b) / a.length() / b.length());
95  return angle;
96 }
97 
99 {
100  return QString("%1*").arg(this->getAngle() / M_PI * 180, 0, 'f', 1);
101 }
102 
104 {
106 }
107 
109 {
110  return mUseSimpleVisualization;
111 }
112 
114 {
115  mUseSimpleVisualization = val;
116  emit propertiesChanged();
117 }
118 
119 
120 }
cx::DoubleBoundingBox3D
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,...
Definition: cxBoundingBox3D.h:63
cx::DoubleBoundingBox3D::center
Vector3D center() const
Definition: cxBoundingBox3D.cpp:196
cx::AngleMetric::getUseSimpleVisualization
bool getUseSimpleVisualization() const
Definition: cxAngleMetric.cpp:108
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::DataMetric::mDataManager
PatientModelServicePtr mDataManager
Definition: cxDataMetric.h:67
cx::AngleMetric::getRefCoord
virtual Vector3D getRefCoord() const
Definition: cxAngleMetric.cpp:79
cx::PointMetric::getTypeName
static QString getTypeName()
Definition: cxPointMetric.h:58
cx::AngleMetric::setUseSimpleVisualization
void setUseSimpleVisualization(bool val)
Definition: cxAngleMetric.cpp:113
cx::OptionalValue::isValid
bool isValid() const
Definition: cxOptionalValue.h:33
cx::OptionalValue::get
const T & get() const
Definition: cxOptionalValue.h:31
cx::ActiveImageProxy::transformChanged
void transformChanged()
cx::DataMetric::addXml
void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxDataMetric.cpp:55
cxBoundingBox3D.h
cx::AngleMetric::boundingBox
virtual DoubleBoundingBox3D boundingBox() const
Definition: cxAngleMetric.cpp:103
cx::AngleMetric::parseXml
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxAngleMetric.cpp:50
cx::AngleMetric::getValueAsString
virtual QString getValueAsString() const
Definition: cxAngleMetric.cpp:98
cx::OptionalValue::set
void set(const T &val)
Definition: cxOptionalValue.h:32
cx::DoubleBoundingBox3D::fromCloud
static DoubleBoundingBox3D fromCloud(std::vector< Vector3D > cloud)
Definition: cxBoundingBox3D.cpp:239
cx::AngleMetric::create
static AngleMetricPtr create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
Definition: cxAngleMetric.cpp:34
cx::PatientModelServicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Definition: cxLogicManager.h:25
cxTypeConversions.h
cxPatientModelService.h
cx::AngleMetric::getEndpoints
std::vector< Vector3D > getEndpoints() const
Definition: cxAngleMetric.cpp:70
cx::AngleMetric
Data class that represents an angle between two lines.
Definition: cxAngleMetric.h:46
cx::OptionalValue::reset
void reset()
Definition: cxOptionalValue.h:34
cx::AngleMetric::addXml
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxAngleMetric.cpp:43
cx::AngleMetricPtr
boost::shared_ptr< class AngleMetric > AngleMetricPtr
Definition: cxAngleMetric.h:33
cx::AngleMetric::~AngleMetric
virtual ~AngleMetric()
Definition: cxAngleMetric.cpp:39
M_PI
#define M_PI
Definition: cxReconstructParams.cpp:25
cx::Data::propertiesChanged
void propertiesChanged()
emitted when one of the metadata properties (uid, name etc) changes
cx::AngleMetric::getAngle
double getAngle() const
Definition: cxAngleMetric.cpp:84
cxAngleMetric.h
cx::dot
double dot(const Vector3D &a, const Vector3D &b)
compute inner product (or dot product) of a and b.
Definition: cxVector3D.cpp:46
cx::AngleMetric::isValid
virtual bool isValid() const
Definition: cxAngleMetric.cpp:65
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
cx::DataMetric::parseXml
void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxDataMetric.cpp:65
cx::SpaceProviderPtr
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
Definition: cxLogicManager.h:23