CustusX  18.04
An IGT application
cxPointMetric.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 #include "cxPointMetric.h"
14 #include "cxBoundingBox3D.h"
15 #include "cxTool.h"
16 #include "cxTypeConversions.h"
17 #include "cxSpaceProvider.h"
18 #include "cxSpaceListener.h"
20 #include "cxLogger.h"
21 
22 namespace cx
23 {
24 
25 PointMetric::PointMetric(const QString& uid, const QString& name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider) :
26  DataMetric(uid, name, dataManager, spaceProvider),
27  mCoordinate(0,0,0),
28  mSpace(CoordinateSystem::reference())
29 {
30  mSpaceListener = mSpaceProvider->createListener();
31  mSpaceListener->setSpace(mSpace);
32  connect(mSpaceListener.get(), SIGNAL(changed()), this, SLOT(resetCachedValues()));
33  connect(mSpaceListener.get(), SIGNAL(changed()), this, SIGNAL(transformChanged()));
34 }
35 
36 PointMetricPtr PointMetric::create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
37 {
38  return PointMetricPtr(new PointMetric(uid, name, dataManager, spaceProvider));
39 }
40 
42 {
43 }
44 
46 {
47  return mSpaceProvider->convertToSpecific(mSpace).mRefObject;
48 }
49 
51 {
52  if (p == mCoordinate)
53  return;
54 
55  mCoordinate = p;
56  this->resetCachedValues();
57  emit transformChanged();
58 }
59 
61 {
62  return mCoordinate;
63 }
64 
66 {
67  if (space == mSpace)
68  return;
69 
70  // keep the absolute position (in ref) constant when changing space.
71  Transform3D new_M_old = mSpaceProvider->get_toMfrom(this->getSpace(), space);
72  mCoordinate = new_M_old.coord(mCoordinate);
73 
74  mSpace = space;
75  this->resetCachedValues();
76  mSpaceListener->setSpace(space);
77 }
78 
80 {
81  return mSpace;
82 }
83 
84 void PointMetric::addXml(QDomNode& dataNode)
85 {
86  DataMetric::addXml(dataNode);
87 
88  dataNode.toElement().setAttribute("space", mSpace.toString());
89  dataNode.toElement().setAttribute("coord", qstring_cast(mCoordinate));
90 }
91 
92 void PointMetric::parseXml(QDomNode& dataNode)
93 {
94  DataMetric::parseXml(dataNode);
95 
96  this->setSpace(CoordinateSystem::fromString(dataNode.toElement().attribute("space", mSpace.toString())));
97  this->setCoordinate(Vector3D::fromString(dataNode.toElement().attribute("coord", qstring_cast(mCoordinate))));
98 }
99 
101 {
102  // convert both inputs to r space
103  Vector3D p0_r = this->getRefCoord();
104 
105  return DoubleBoundingBox3D(p0_r, p0_r);
106 }
107 
108 void PointMetric::resetCachedValues()
109 {
110  mCachedRefCoord.reset();
111 }
112 
117 {
118  if (!mCachedRefCoord.isValid())
119  {
120  Transform3D rM1 = mSpaceProvider->get_toMfrom(this->getSpace(), CoordinateSystem(csREF));
121  Vector3D val = rM1.coord(this->getCoordinate());
122  mCachedRefCoord.set(val);
123  }
124  return mCachedRefCoord.get();
125 }
126 
128 {
129  return prettyFormat(this->getRefCoord(), 1, 3);
130 }
131 
132 
133 }
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
QString qstring_cast(const T &val)
void setSpace(CoordinateSystem space)
void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
void transformChanged()
emitted when transform is changed
void setCoordinate(const Vector3D &p)
QString prettyFormat(Vector3D val, int decimals, int fieldWidth)
Definition: cxVector3D.cpp:98
csREF
the data reference space (r) using LPS (left-posterior-superior) coordinates.
Definition: cxDefinitions.h:88
virtual QString getSpace()
SpaceProviderPtr mSpaceProvider
Definition: cxDataMetric.h:68
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
void parseXml(QDomNode &dataNode)
Use a XML node to load data.
virtual ~PointMetric()
Vector3D getCoordinate() const
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
virtual QString getParentSpace()
Identification of a Coordinate system.
virtual DoubleBoundingBox3D boundingBox() const
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.
CoordinateSystem getSpace() const
Data class that represents a single point.
Definition: cxPointMetric.h:42
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
virtual QString getValueAsString() const
virtual Vector3D getRefCoord() const
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
virtual Vector3D getRefCoord() const
static PointMetricPtr create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
static CoordinateSystem fromString(QString text)
Namespace for all CustusX production code.
boost::shared_ptr< class PointMetric > PointMetricPtr