Fraxinus  22.04-rc5
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 {
105  return DoubleBoundingBox3D::fromCloud(this->getEndpoints());
106 }
107 
109 {
110  return mUseSimpleVisualization;
111 }
112 
114 {
115  mUseSimpleVisualization = val;
116  emit propertiesChanged();
117 }
118 
119 
120 }
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:33
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:46
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:42
std::vector< Vector3D > getEndpoints() const
static QString getTypeName()
Definition: cxPointMetric.h:58
Data class that represents an angle between two lines.
Definition: cxAngleMetric.h:46
#define M_PI
Namespace for all CustusX production code.