NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxTransform3D.h
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 #ifndef CXTRANSFORM3D_H_
34 #define CXTRANSFORM3D_H_
35 
36 #include "cxResourceExport.h"
37 #include "cxPrecompiledHeader.h"
38 
39 #include <boost/array.hpp>
40 #include <boost/shared_ptr.hpp>
41 #include <QString>
42 #include "cxVector3D.h"
43 #include "cxDefinitions.h"
44 
45 
49 namespace cx_transform3D_internal
50 {
53 cxResource_EXPORT boost::array<double, 16> flatten(const Eigen::Affine3d* self);
54 
55 cxResource_EXPORT void fill(Eigen::Affine3d* self, vtkMatrix4x4Ptr m);
56 cxResource_EXPORT void fill(Eigen::Affine3d* self, float m[4][4]);
57 cxResource_EXPORT void fill(Eigen::Affine3d* self, const double* raw);
58 cxResource_EXPORT vtkMatrix4x4Ptr getVtkMatrix(const Eigen::Affine3d* self);
59 cxResource_EXPORT std::ostream& put(const Eigen::Affine3d* self, std::ostream& s, int indent, char newline);
60 cxResource_EXPORT Eigen::Affine3d fromString(const QString& text, bool* _ok);
61 cxResource_EXPORT vtkTransformPtr getVtkTransform(const Eigen::Affine3d* self);
62 }
63 
65 namespace Eigen
66 {
67 
68 template<typename _Scalar, int _Dim, int _Mode, int _Options>
69 std::ostream& operator<<(std::ostream& s, const Eigen::Transform<_Scalar, _Dim, _Mode, _Options>& t)
70 {
71  s << t.matrix().format(IOFormat()); // hack: force OK output even when the default in sscMathBase.h is Veector3D-centered.
72  // t.put(s);
73  return s;
74 }
75 
76 template<typename _Scalar, int _Dim, int _Mode, int _Options>
77 Vector3d Transform<_Scalar, _Dim, _Mode, _Options>::vector(const Vector3d& v) const
78 {
79  return this->linear() * v;
80 }
81 
82 template<typename _Scalar, int _Dim, int _Mode, int _Options>
83 Vector3d Transform<_Scalar, _Dim, _Mode, _Options>::unitVector(const Vector3d& v) const
84 {
85  return (this->linear() * v).normal();
86 }
87 
88 template<typename _Scalar, int _Dim, int _Mode, int _Options>
89 Vector3d Transform<_Scalar, _Dim, _Mode, _Options>::coord(const Vector3d& v) const
90 {
91  return (*this) * v;
92 }
93 
94 template<typename _Scalar, int _Dim, int _Mode, int _Options>
95 Transform<_Scalar, _Dim, _Mode, _Options> Transform<_Scalar, _Dim, _Mode, _Options>::inv() const
96 {
97  return this->inverse();
98 }
99 
100 template<typename _Scalar, int _Dim, int _Mode, int _Options>
101 boost::array<double, 16> Transform<_Scalar, _Dim, _Mode, _Options>::flatten() const
102 {
104 }
105 
106 template<typename _Scalar, int _Dim, int _Mode, int _Options>
107 Transform<_Scalar, _Dim, _Mode, _Options>::Transform(vtkMatrix4x4* m)
108 {
110 }
111 
112 template<typename _Scalar, int _Dim, int _Mode, int _Options>
113 Transform<_Scalar, _Dim, _Mode, _Options>::Transform(double* raw)
114 {
116 }
117 
118 template<typename _Scalar, int _Dim, int _Mode, int _Options>
120 {
122 }
123 
124 template<typename _Scalar, int _Dim, int _Mode, int _Options>
126 {
128 }
129 
130 template<typename _Scalar, int _Dim, int _Mode, int _Options>
131 std::ostream& Transform<_Scalar, _Dim, _Mode, _Options>::put(std::ostream& s, int indent, char newline) const
132 {
133  return cx_transform3D_internal::put(this, s, indent, newline);
134 }
135 
136 template<typename _Scalar, int _Dim, int _Mode, int _Options>
137 Transform<_Scalar, _Dim, _Mode, _Options> Transform<_Scalar, _Dim, _Mode, _Options>::fromString(const QString& text,
138  bool* _ok)
139 {
140  return cx_transform3D_internal::fromString(text, _ok);
141 }
142 
143 template<typename _Scalar, int _Dim, int _Mode, int _Options>
144 Transform<_Scalar, _Dim, _Mode, _Options> Transform<_Scalar, _Dim, _Mode, _Options>::fromVtkMatrix(vtkMatrix4x4Ptr m)
145 {
146  Transform<_Scalar, _Dim, _Mode, _Options> retval;
147  cx_transform3D_internal::fill(&retval, m);
148  return retval;
149 }
150 
151 template<typename _Scalar, int _Dim, int _Mode, int _Options>
152 Transform<_Scalar, _Dim, _Mode, _Options> Transform<_Scalar, _Dim, _Mode, _Options>::fromFloatArray(float m[4][4])
153 {
154  Transform<_Scalar, _Dim, _Mode, _Options> retval;
155  cx_transform3D_internal::fill(&retval, m);
156  return retval;
157 }
158 
159 
160 } // namespace Eigen
162 
163 // --------------------------------------------------------
164 namespace cx
165 {
166 class DoubleBoundingBox3D;
167 
182 typedef Eigen::Affine3d Transform3D;
183 
184 cxResource_EXPORT bool similar(const Transform3D& a, const Transform3D& b, double tol = 1.0E-4);
185 
189 cxResource_EXPORT DoubleBoundingBox3D transform(const Transform3D& m, const DoubleBoundingBox3D& bb);
190 
196 cxResource_EXPORT Transform3D createTransformNormalize(const DoubleBoundingBox3D& in, const DoubleBoundingBox3D& out);
197 
200 cxResource_EXPORT Transform3D createTransformScale(const Vector3D& scale);
201 
204 cxResource_EXPORT Transform3D createTransformTranslate(const Vector3D& translation);
205 
208 cxResource_EXPORT Transform3D createTransformRotateX(const double angle);
209 
212 cxResource_EXPORT Transform3D createTransformRotateY(const double angle);
213 
216 cxResource_EXPORT Transform3D createTransformRotateZ(const double angle);
217 
224 cxResource_EXPORT Transform3D createTransformIJC(const Vector3D& ivec, const Vector3D& jvec, const Vector3D& center);
225 
227 
228 
234 cxResource_EXPORT Transform3D createTransformLPS2RAS();
235 
241 cxResource_EXPORT Transform3D createTransformFromReferenceToExternal(PATIENT_COORDINATE_SYSTEM external);
242 
243 
244 
245 // --------------------------------------------------------
246 typedef boost::shared_ptr<Transform3D> Transform3DPtr;
247 
252 } // namespace cx
253 // --------------------------------------------------------
254 
255 #endif /*CXTRANSFORM3D_H_*/
vtkSmartPointer< class vtkMatrix4x4 > vtkMatrix4x4Ptr
Definition: cxMathBase.h:58
DoubleBoundingBox3D transform(const Transform3D &m, const DoubleBoundingBox3D &bb)
Transform3D createTransformRotateY(const double angle)
std::ostream & put(const Eigen::Affine3d *self, std::ostream &s, int indent, char newline)
Transform3D createTransformScale(const Vector3D &scale_)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::array< double, 16 > flatten(const Eigen::Affine3d *self)
cxResource_EXPORT Transform3D createTransformFromReferenceToExternal(PATIENT_COORDINATE_SYSTEM external)
boost::shared_ptr< Transform3D > Transform3DPtr
cxResource_EXPORT Transform3D createTransformRotationBetweenVectors(Vector3D from, Vector3D to)
cxResource_EXPORT Transform3D createTransformLPS2RAS()
Vector3D unitVector(double thetaXY, double thetaZ)
compute a unit vector given angles xy in the xy plane and z meaning the elevation from the xy plane...
Definition: cxVector3D.cpp:77
vtkSmartPointer< class vtkTransform > vtkTransformPtr
Definition: cxMathBase.h:62
Transform3D createTransformNormalize(const DoubleBoundingBox3D &in, const DoubleBoundingBox3D &out)
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
vtkMatrix4x4Ptr getVtkMatrix(const Eigen::Affine3d *self)
Transform3D createTransformIJC(const Vector3D &ivec, const Vector3D &jvec, const Vector3D &center)
Eigen::Affine3d fromString(const QString &text, bool *_ok)
Transform3D createTransformTranslate(const Vector3D &translation)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
void fill(Eigen::Affine3d *self, vtkMatrix4x4Ptr m)
Transform3D createTransformRotateZ(const double angle)
vtkTransformPtr getVtkTransform(const Eigen::Affine3d *self)
Transform3D createTransformRotateX(const double angle)