NorMIT-nav  22.09
An IGT application
cxFrameMetricBase.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 #include "cxFrameMetricBase.h"
13 #include "cxBoundingBox3D.h"
14 #include "cxTypeConversions.h"
15 #include "cxSpaceProvider.h"
16 #include "cxSpaceListener.h"
17 
18 namespace cx {
19 
20 FrameMetricBase::FrameMetricBase(const QString& uid, const QString& name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider) :
21  DataMetric(uid, name, dataManager, spaceProvider),
22  mSpace(CoordinateSystem::reference()),
23  mFrame(Transform3D::Identity())
24 {
25  mSpaceListener = mSpaceProvider->createListener();
26  mSpaceListener->setSpace(mSpace);
27 // mSpaceListener.reset(new SpaceListener(mSpace));
28  connect(mSpaceListener.get(), SIGNAL(changed()), this, SIGNAL(transformChanged()));
29 }
30 
32 {
33 }
34 
36 {
37  return mSpaceProvider->convertToSpecific(mSpace).mRefObject;
38 }
39 
41 {
42  mFrame = rMt;
43  emit transformChanged();
44 }
45 
47 {
48  return mFrame;
49 }
50 
52 {
53  Vector3D point_t = Vector3D(0,0,0);
54  return mFrame.coord(point_t);
55 }
56 
60 {
61  Transform3D rMq = mSpaceProvider->get_toMfrom(this->getSpace(), CoordinateSystem(csREF));
62  return rMq * mFrame;
63 }
64 
68 {
69  Transform3D rMq = this->getRefFrame();
70  Vector3D p_r = rMq.coord(Vector3D(0,0,0));
71  return p_r;
72 }
73 
75 {
76  if (space == mSpace)
77  return;
78 
79  // keep the absolute position (in ref) constant when changing space.
80  Transform3D new_M_old = mSpaceProvider->get_toMfrom(this->getSpace(), space);
81  mFrame = new_M_old*mFrame;
82 
83  mSpace = space;
84  mSpaceListener->setSpace(space);
85 }
86 
88 {
89  return mSpace;
90 }
91 
93 {
94  // convert both inputs to r space
95  Transform3D rM0 = mSpaceProvider->get_toMfrom(this->getSpace(), CoordinateSystem(csREF));
96  Vector3D p0_r = rM0.coord(this->getCoordinate());
97 
98  return DoubleBoundingBox3D(p0_r, p0_r);
99 }
100 
102 {
103  std::stringstream stream;
104  mFrame.put(stream, 0, ' ');
105  return qstring_cast(stream.str());
106 }
107 
108 } //namespace cx
cx::FrameMetricBase::getFrame
virtual Transform3D getFrame()
Definition: cxFrameMetricBase.cpp:46
cxFrameMetricBase.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::FrameMetricBase::FrameMetricBase
FrameMetricBase(const QString &uid, const QString &name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
Definition: cxFrameMetricBase.cpp:20
cxSpaceListener.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::FrameMetricBase::mFrame
Transform3D mFrame
frame qFt described in local space q = mSpace
Definition: cxFrameMetricBase.h:55
cx::FrameMetricBase::matrixAsSingleLineString
QString matrixAsSingleLineString() const
Definition: cxFrameMetricBase.cpp:101
cxBoundingBox3D.h
cx::FrameMetricBase::setSpace
virtual void setSpace(CoordinateSystem space)
Definition: cxFrameMetricBase.cpp:74
cx::Data::transformChanged
void transformChanged()
emitted when transform is changed
cx::FrameMetricBase::setFrame
virtual void setFrame(const Transform3D &qMt)
Definition: cxFrameMetricBase.cpp:40
cx::FrameMetricBase::getCoordinate
virtual Vector3D getCoordinate() const
Definition: cxFrameMetricBase.cpp:51
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::FrameMetricBase::~FrameMetricBase
virtual ~FrameMetricBase()
Definition: cxFrameMetricBase.cpp:31
cx::PatientModelServicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Definition: cxLogicManager.h:25
cx::DataMetric::mSpaceProvider
SpaceProviderPtr mSpaceProvider
Definition: cxDataMetric.h:68
cxTypeConversions.h
cx::FrameMetricBase::getParentSpace
virtual QString getParentSpace()
Definition: cxFrameMetricBase.cpp:35
cx::FrameMetricBase::getRefCoord
virtual Vector3D getRefCoord() const
as getRefFrame, but coord only.
Definition: cxFrameMetricBase.cpp:67
cx::DataMetric
Base class for all Data Metrics.
Definition: cxDataMetric.h:43
cx::FrameMetricBase::getSpace
virtual CoordinateSystem getSpace() const
Definition: cxFrameMetricBase.cpp:87
cx::FrameMetricBase::boundingBox
virtual DoubleBoundingBox3D boundingBox() const
Definition: cxFrameMetricBase.cpp:92
cx::FrameMetricBase::getRefFrame
virtual Transform3D getRefFrame() const
return frame described in ref space r : rFt = rMq * qFt
Definition: cxFrameMetricBase.cpp:59
cx::FrameMetricBase::mSpace
CoordinateSystem mSpace
Definition: cxFrameMetricBase.h:53
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
cx::SpaceProviderPtr
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
Definition: cxLogicManager.h:23
cx::CoordinateSystem
Identification of a Coordinate system.
Definition: cxCoordinateSystemHelpers.h:31
cx::FrameMetricBase::mSpaceListener
SpaceListenerPtr mSpaceListener
Definition: cxFrameMetricBase.h:54
cxSpaceProvider.h