CustusX  2023.01.05-dev+develop.0da12
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
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
QString qstring_cast(const T &val)
virtual void setFrame(const Transform3D &qMt)
virtual Vector3D getCoordinate() const
CoordinateSystem mSpace
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
virtual QString getParentSpace()
void transformChanged()
emitted when transform is changed
virtual void setSpace(CoordinateSystem space)
csREF
the data reference space (r) using LPS (left-posterior-superior) coordinates.
Definition: cxDefinitions.h:90
QString matrixAsSingleLineString() const
SpaceProviderPtr mSpaceProvider
Definition: cxDataMetric.h:68
SpaceListenerPtr mSpaceListener
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Identification of a Coordinate system.
FrameMetricBase(const QString &uid, const QString &name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
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.
virtual CoordinateSystem getSpace() const
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
virtual Vector3D getRefCoord() const
as getRefFrame, but coord only.
virtual Transform3D getRefFrame() const
return frame described in ref space r : rFt = rMq * qFt
virtual DoubleBoundingBox3D boundingBox() const
Base class for all Data Metrics.
Definition: cxDataMetric.h:43
virtual Transform3D getFrame()
Namespace for all CustusX production code.
Transform3D mFrame
frame qFt described in local space q = mSpace