NorMIT-nav  2023.01.05-dev+develop.0da12
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 }
cxLogger.h
qstring_cast
QString qstring_cast(const T &val)
Definition: cxTypeConversions.h:46
cx::DoubleBoundingBox3D
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,...
Definition: cxBoundingBox3D.h:63
cx::PointMetric::getCoordinate
Vector3D getCoordinate() const
Definition: cxPointMetric.cpp:60
cxSpaceListener.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::PointMetric::~PointMetric
virtual ~PointMetric()
Definition: cxPointMetric.cpp:41
cx::OptionalValue::isValid
bool isValid() const
Definition: cxOptionalValue.h:33
cx::OptionalValue::get
const T & get() const
Definition: cxOptionalValue.h:31
cx::PointMetric::parseXml
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxPointMetric.cpp:92
cx::PointMetric::setCoordinate
void setCoordinate(const Vector3D &p)
Definition: cxPointMetric.cpp:50
cx::DataMetric::addXml
void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxDataMetric.cpp:55
cxBoundingBox3D.h
cx::PointMetric::getValueAsString
virtual QString getValueAsString() const
Definition: cxPointMetric.cpp:127
cx::PointMetric::getRefCoord
virtual Vector3D getRefCoord() const
Definition: cxPointMetric.cpp:116
cx::Data::transformChanged
void transformChanged()
emitted when transform is changed
cx::OptionalValue::set
void set(const T &val)
Definition: cxOptionalValue.h:32
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
csREF
csREF
the data reference space (r) using LPS (left-posterior-superior) coordinates.
Definition: cxDefinitions.h:90
cx::PointMetric::addXml
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxPointMetric.cpp:84
cx::PatientModelServicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Definition: cxLogicManager.h:25
cxTool.h
cx::DataMetric::mSpaceProvider
SpaceProviderPtr mSpaceProvider
Definition: cxDataMetric.h:68
cxTypeConversions.h
cxCoordinateSystemHelpers.h
cx::PointMetric::getParentSpace
virtual QString getParentSpace()
Definition: cxPointMetric.cpp:45
cx::OptionalValue::reset
void reset()
Definition: cxOptionalValue.h:34
cx::PointMetric::boundingBox
virtual DoubleBoundingBox3D boundingBox() const
Definition: cxPointMetric.cpp:100
cxPointMetric.h
cx::PointMetric::create
static PointMetricPtr create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
Definition: cxPointMetric.cpp:36
cx::CoordinateSystem::fromString
static CoordinateSystem fromString(QString text)
Definition: cxCoordinateSystemHelpers.cpp:24
cx::CoordinateSystem::toString
QString toString() const
Definition: cxCoordinateSystemHelpers.cpp:19
cx::PointMetric
Data class that represents a single point.
Definition: cxPointMetric.h:42
cx::PointMetric::getSpace
CoordinateSystem getSpace() const
Definition: cxPointMetric.cpp:79
cx::PointMetricPtr
boost::shared_ptr< class PointMetric > PointMetricPtr
Definition: cxForwardDeclarations.h:84
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
cx::CoordinateSystem
Identification of a Coordinate system.
Definition: cxCoordinateSystemHelpers.h:31
cxSpaceProvider.h
cx::PointMetric::setSpace
void setSpace(CoordinateSystem space)
Definition: cxPointMetric.cpp:65
cx::prettyFormat
QString prettyFormat(Vector3D val, int decimals, int fieldWidth)
Definition: cxVector3D.cpp:98