Fraxinus  16.5.0-fx-rc5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 #include "cxFrameMetricBase.h"
34 #include "cxBoundingBox3D.h"
35 #include "cxTypeConversions.h"
36 #include "cxSpaceProvider.h"
37 #include "cxSpaceListener.h"
38 
39 namespace cx {
40 
41 FrameMetricBase::FrameMetricBase(const QString& uid, const QString& name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider) :
42  DataMetric(uid, name, dataManager, spaceProvider),
43  mSpace(CoordinateSystem::reference()),
44  mFrame(Transform3D::Identity())
45 {
46  mSpaceListener = mSpaceProvider->createListener();
47  mSpaceListener->setSpace(mSpace);
48 // mSpaceListener.reset(new SpaceListener(mSpace));
49  connect(mSpaceListener.get(), SIGNAL(changed()), this, SIGNAL(transformChanged()));
50 }
51 
53 {
54 }
55 
57 {
58  return mSpaceProvider->convertToSpecific(mSpace).mRefObject;
59 }
60 
62 {
63  mFrame = rMt;
64  emit transformChanged();
65 }
66 
68 {
69  return mFrame;
70 }
71 
73 {
74  Vector3D point_t = Vector3D(0,0,0);
75  return mFrame.coord(point_t);
76 }
77 
81 {
82  Transform3D rMq = mSpaceProvider->get_toMfrom(this->getSpace(), CoordinateSystem(csREF));
83  return rMq * mFrame;
84 }
85 
89 {
90  Transform3D rMq = this->getRefFrame();
91  Vector3D p_r = rMq.coord(Vector3D(0,0,0));
92  return p_r;
93 }
94 
96 {
97  if (space == mSpace)
98  return;
99 
100  // keep the absolute position (in ref) constant when changing space.
101  Transform3D new_M_old = mSpaceProvider->get_toMfrom(this->getSpace(), space);
102  mFrame = new_M_old*mFrame;
103 
104  mSpace = space;
105  mSpaceListener->setSpace(space);
106 }
107 
109 {
110  return mSpace;
111 }
112 
114 {
115  // convert both inputs to r space
116  Transform3D rM0 = mSpaceProvider->get_toMfrom(this->getSpace(), CoordinateSystem(csREF));
117  Vector3D p0_r = rM0.coord(this->getCoordinate());
118 
119  return DoubleBoundingBox3D(p0_r, p0_r);
120 }
121 
123 {
124  std::stringstream stream;
125  mFrame.put(stream, 0, ' ');
126  return qstring_cast(stream.str());
127 }
128 
129 } //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.
QString matrixAsSingleLineString() const
SpaceProviderPtr mSpaceProvider
Definition: cxDataMetric.h:89
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
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
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:64
virtual Transform3D getFrame()
Transform3D mFrame
frame qFt described in local space q = mSpace