CustusX  15.3.3-beta
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 
44 
48 namespace cx_transform3D_internal
49 {
50 cxResource_EXPORT boost::array<double, 16> flatten(const Eigen::Affine3d* self);
51 cxResource_EXPORT void fill(Eigen::Affine3d* self, vtkMatrix4x4Ptr m);
52 cxResource_EXPORT void fill(Eigen::Affine3d* self, const double* raw);
53 cxResource_EXPORT vtkMatrix4x4Ptr getVtkMatrix(const Eigen::Affine3d* self);
54 cxResource_EXPORT std::ostream& put(const Eigen::Affine3d* self, std::ostream& s, int indent, char newline);
55 cxResource_EXPORT Eigen::Affine3d fromString(const QString& text, bool* _ok);
56 cxResource_EXPORT vtkTransformPtr getVtkTransform(const Eigen::Affine3d* self);
57 }
58 
59 namespace Eigen
60 {
61 
62 template<typename _Scalar, int _Dim, int _Mode, int _Options>
63 std::ostream& operator<<(std::ostream& s, const Eigen::Transform<_Scalar, _Dim, _Mode, _Options>& t)
64 {
65  s << t.matrix().format(IOFormat()); // hack: force OK output even when the default in sscMathBase.h is Veector3D-centered.
66  // t.put(s);
67  return s;
68 }
69 
70 template<typename _Scalar, int _Dim, int _Mode, int _Options>
71 Vector3d Transform<_Scalar, _Dim, _Mode, _Options>::vector(const Vector3d& v) const
72 {
73  return this->linear() * v;
74 }
75 
76 template<typename _Scalar, int _Dim, int _Mode, int _Options>
77 Vector3d Transform<_Scalar, _Dim, _Mode, _Options>::unitVector(const Vector3d& v) const
78 {
79  return (this->linear() * v).normal();
80 }
81 
82 template<typename _Scalar, int _Dim, int _Mode, int _Options>
83 Vector3d Transform<_Scalar, _Dim, _Mode, _Options>::coord(const Vector3d& v) const
84 {
85  return (*this) * v;
86 }
87 
88 template<typename _Scalar, int _Dim, int _Mode, int _Options>
89 Transform<_Scalar, _Dim, _Mode, _Options> Transform<_Scalar, _Dim, _Mode, _Options>::inv() const
90 {
91  return this->inverse();
92 }
93 
94 template<typename _Scalar, int _Dim, int _Mode, int _Options>
95 boost::array<double, 16> Transform<_Scalar, _Dim, _Mode, _Options>::flatten() const
96 {
98 }
99 
100 template<typename _Scalar, int _Dim, int _Mode, int _Options>
102 {
104 }
105 
106 template<typename _Scalar, int _Dim, int _Mode, int _Options>
108 {
110 }
111 
112 template<typename _Scalar, int _Dim, int _Mode, int _Options>
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>
125 std::ostream& Transform<_Scalar, _Dim, _Mode, _Options>::put(std::ostream& s, int indent, char newline) const
126 {
127  return cx_transform3D_internal::put(this, s, indent, newline);
128 }
129 
130 template<typename _Scalar, int _Dim, int _Mode, int _Options>
131 Transform<_Scalar, _Dim, _Mode, _Options> Transform<_Scalar, _Dim, _Mode, _Options>::fromString(const QString& text,
132  bool* _ok)
133 {
134  return cx_transform3D_internal::fromString(text, _ok);
135 }
136 
137 template<typename _Scalar, int _Dim, int _Mode, int _Options>
138 Transform<_Scalar, _Dim, _Mode, _Options> Transform<_Scalar, _Dim, _Mode, _Options>::fromVtkMatrix(vtkMatrix4x4Ptr m)
139 {
140  Transform<_Scalar, _Dim, _Mode, _Options> retval;
141  cx_transform3D_internal::fill(&retval, m);
142  return retval;
143 }
144 
145 } // namespace Eigen
146 
147 // --------------------------------------------------------
148 namespace cx
149 {
150 class DoubleBoundingBox3D;
151 
166 typedef Eigen::Affine3d Transform3D;
167 
168 cxResource_EXPORT bool similar(const Transform3D& a, const Transform3D& b, double tol = 1.0E-4);
169 
170 cxResource_EXPORT DoubleBoundingBox3D transform(const Transform3D& m, const DoubleBoundingBox3D& bb);
171 
172 cxResource_EXPORT Transform3D createTransformNormalize(const DoubleBoundingBox3D& in, const DoubleBoundingBox3D& out);
173 cxResource_EXPORT Transform3D createTransformScale(const Vector3D& scale);
174 cxResource_EXPORT Transform3D createTransformTranslate(const Vector3D& translation);
175 cxResource_EXPORT Transform3D createTransformRotateX(const double angle);
176 cxResource_EXPORT Transform3D createTransformRotateY(const double angle);
177 cxResource_EXPORT Transform3D createTransformRotateZ(const double angle);
178 cxResource_EXPORT Transform3D createTransformIJC(const Vector3D& ivec, const Vector3D& jvec, const Vector3D& center);
180 
181 // --------------------------------------------------------
182 typedef boost::shared_ptr<Transform3D> Transform3DPtr;
183 
188 } // namespace cx
189 // --------------------------------------------------------
190 
191 #endif /*CXTRANSFORM3D_H_*/
vtkSmartPointer< class vtkMatrix4x4 > vtkMatrix4x4Ptr
Definition: cxMathBase.h:58
std::ostream & put(std::ostream &s, int indent=0, char newline='\n') const
DoubleBoundingBox3D transform(const Transform3D &m, const DoubleBoundingBox3D &bb)
Transform3D createTransformRotateY(const double angle)
Vector3d vector(const Vector3d &v) const
transform a free vector [x,y,z,0]
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)
boost::shared_ptr< Transform3D > Transform3DPtr
cxResource_EXPORT Transform3D createTransformRotationBetweenVectors(Vector3D from, Vector3D to)
vtkMatrix4x4Ptr getVtkMatrix() const
vtkSmartPointer< class vtkTransform > vtkTransformPtr
Definition: cxMathBase.h:62
Vector3d unitVector(const Vector3d &v) const
transform a unit vector [x,y,z,0], force |v|=1 after transform.
Transform(vtkMatrix4x4 *m)
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)
construct a transform matrix from a string containing 16 whitespace-separated numbers, vtk ordering
Vector3d coord(const Vector3d &v) const
transform a coordinate [x,y,z,1].
Transform3D createTransformTranslate(const Vector3D &translation)
Transform inv() const
return an inverted transform M^-1
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)
boost::array< double, 16 > flatten() const
return matrix as a flat array, vtk ordering
vtkTransformPtr getVtkTransform(const Eigen::Affine3d *self)
Transform3D createTransformRotateX(const double angle)
vtkTransformPtr getVtkTransform() const