NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 #include "cxPointMetric.h"
35 #include "cxBoundingBox3D.h"
36 #include "cxTool.h"
37 #include "cxTypeConversions.h"
38 #include "cxSpaceProvider.h"
39 #include "cxSpaceListener.h"
41 #include "cxLogger.h"
42 
43 namespace cx
44 {
45 
46 PointMetric::PointMetric(const QString& uid, const QString& name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider) :
47  DataMetric(uid, name, dataManager, spaceProvider),
48  mCoordinate(0,0,0),
49  mSpace(CoordinateSystem::reference())
50 {
51  mSpaceListener = mSpaceProvider->createListener();
52  mSpaceListener->setSpace(mSpace);
53  connect(mSpaceListener.get(), SIGNAL(changed()), this, SLOT(resetCachedValues()));
54  connect(mSpaceListener.get(), SIGNAL(changed()), this, SIGNAL(transformChanged()));
55 }
56 
57 PointMetricPtr PointMetric::create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
58 {
59  return PointMetricPtr(new PointMetric(uid, name, dataManager, spaceProvider));
60 }
61 
63 {
64 }
65 
67 {
68  return mSpaceProvider->convertToSpecific(mSpace).mRefObject;
69 }
70 
72 {
73  if (p == mCoordinate)
74  return;
75 
76  mCoordinate = p;
77  this->resetCachedValues();
78  emit transformChanged();
79 }
80 
82 {
83  return mCoordinate;
84 }
85 
87 {
88  if (space == mSpace)
89  return;
90 
91  // keep the absolute position (in ref) constant when changing space.
92  Transform3D new_M_old = mSpaceProvider->get_toMfrom(this->getSpace(), space);
93  mCoordinate = new_M_old.coord(mCoordinate);
94 
95  mSpace = space;
96  this->resetCachedValues();
97  mSpaceListener->setSpace(space);
98 }
99 
101 {
102  return mSpace;
103 }
104 
105 void PointMetric::addXml(QDomNode& dataNode)
106 {
107  DataMetric::addXml(dataNode);
108 
109  dataNode.toElement().setAttribute("space", mSpace.toString());
110  dataNode.toElement().setAttribute("coord", qstring_cast(mCoordinate));
111 }
112 
113 void PointMetric::parseXml(QDomNode& dataNode)
114 {
115  DataMetric::parseXml(dataNode);
116 
117  this->setSpace(CoordinateSystem::fromString(dataNode.toElement().attribute("space", mSpace.toString())));
118  this->setCoordinate(Vector3D::fromString(dataNode.toElement().attribute("coord", qstring_cast(mCoordinate))));
119 }
120 
122 {
123  // convert both inputs to r space
124  Vector3D p0_r = this->getRefCoord();
125 
126  return DoubleBoundingBox3D(p0_r, p0_r);
127 }
128 
129 void PointMetric::resetCachedValues()
130 {
131  mCachedRefCoord.reset();
132 }
133 
138 {
139  if (!mCachedRefCoord.isValid())
140  {
141  Transform3D rM1 = mSpaceProvider->get_toMfrom(this->getSpace(), CoordinateSystem(csREF));
142  Vector3D val = rM1.coord(this->getCoordinate());
143  mCachedRefCoord.set(val);
144  }
145  return mCachedRefCoord.get();
146 }
147 
149 {
150  return prettyFormat(this->getRefCoord(), 1, 3);
151 }
152 
154 {
155  return QString("%1 \"%2\" %3")
156  .arg(this->getSingleLineHeader())
157  .arg(mSpace.toString())
158  .arg(qstring_cast(this->getCoordinate()));
159 }
160 
161 }
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
QString qstring_cast(const T &val)
void setSpace(CoordinateSystem space)
bool isValid() const
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:119
csREF
the data reference space (r) using LPS (left-posterior-superior) coordinates.
SpaceProviderPtr mSpaceProvider
Definition: cxDataMetric.h:89
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
void parseXml(QDomNode &dataNode)
Use a XML node to load data.
void set(const T &val)
virtual ~PointMetric()
Vector3D getCoordinate() const
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
virtual QString getParentSpace()
Identification of a Coordinate system.
QString getSingleLineHeader() const
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
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
Data class that represents a single point.
Definition: cxPointMetric.h:63
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
virtual QString getValueAsString() const
virtual Vector3D getRefCoord() const
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
virtual QString getAsSingleLineString() const
static PointMetricPtr create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
const T & get() const
static CoordinateSystem fromString(QString text)
boost::shared_ptr< class PointMetric > PointMetricPtr