CustusX  15.8
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 
60 namespace Eigen
61 {
62 
63 template<typename _Scalar, int _Dim, int _Mode, int _Options>
64 std::ostream& operator<<(std::ostream& s, const Eigen::Transform<_Scalar, _Dim, _Mode, _Options>& t)
65 {
66  s << t.matrix().format(IOFormat()); // hack: force OK output even when the default in sscMathBase.h is Veector3D-centered.
67  // t.put(s);
68  return s;
69 }
70 
71 template<typename _Scalar, int _Dim, int _Mode, int _Options>
72 Vector3d Transform<_Scalar, _Dim, _Mode, _Options>::vector(const Vector3d& v) const
73 {
74  return this->linear() * v;
75 }
76 
77 template<typename _Scalar, int _Dim, int _Mode, int _Options>
78 Vector3d Transform<_Scalar, _Dim, _Mode, _Options>::unitVector(const Vector3d& v) const
79 {
80  return (this->linear() * v).normal();
81 }
82 
83 template<typename _Scalar, int _Dim, int _Mode, int _Options>
84 Vector3d Transform<_Scalar, _Dim, _Mode, _Options>::coord(const Vector3d& v) const
85 {
86  return (*this) * v;
87 }
88 
89 template<typename _Scalar, int _Dim, int _Mode, int _Options>
90 Transform<_Scalar, _Dim, _Mode, _Options> Transform<_Scalar, _Dim, _Mode, _Options>::inv() const
91 {
92  return this->inverse();
93 }
94 
95 template<typename _Scalar, int _Dim, int _Mode, int _Options>
96 boost::array<double, 16> Transform<_Scalar, _Dim, _Mode, _Options>::flatten() const
97 {
99 }
100 
101 template<typename _Scalar, int _Dim, int _Mode, int _Options>
102 Transform<_Scalar, _Dim, _Mode, _Options>::Transform(vtkMatrix4x4* m)
103 {
105 }
106 
107 template<typename _Scalar, int _Dim, int _Mode, int _Options>
108 Transform<_Scalar, _Dim, _Mode, _Options>::Transform(double* raw)
109 {
111 }
112 
113 template<typename _Scalar, int _Dim, int _Mode, int _Options>
115 {
117 }
118 
119 template<typename _Scalar, int _Dim, int _Mode, int _Options>
121 {
123 }
124 
125 template<typename _Scalar, int _Dim, int _Mode, int _Options>
126 std::ostream& Transform<_Scalar, _Dim, _Mode, _Options>::put(std::ostream& s, int indent, char newline) const
127 {
128  return cx_transform3D_internal::put(this, s, indent, newline);
129 }
130 
131 template<typename _Scalar, int _Dim, int _Mode, int _Options>
132 Transform<_Scalar, _Dim, _Mode, _Options> Transform<_Scalar, _Dim, _Mode, _Options>::fromString(const QString& text,
133  bool* _ok)
134 {
135  return cx_transform3D_internal::fromString(text, _ok);
136 }
137 
138 template<typename _Scalar, int _Dim, int _Mode, int _Options>
139 Transform<_Scalar, _Dim, _Mode, _Options> Transform<_Scalar, _Dim, _Mode, _Options>::fromVtkMatrix(vtkMatrix4x4Ptr m)
140 {
141  Transform<_Scalar, _Dim, _Mode, _Options> retval;
142  cx_transform3D_internal::fill(&retval, m);
143  return retval;
144 }
145 
146 } // namespace Eigen
148 
149 // --------------------------------------------------------
150 namespace cx
151 {
152 class DoubleBoundingBox3D;
153 
168 typedef Eigen::Affine3d Transform3D;
169 
170 cxResource_EXPORT bool similar(const Transform3D& a, const Transform3D& b, double tol = 1.0E-4);
171 
172 cxResource_EXPORT DoubleBoundingBox3D transform(const Transform3D& m, const DoubleBoundingBox3D& bb);
173 
174 cxResource_EXPORT Transform3D createTransformNormalize(const DoubleBoundingBox3D& in, const DoubleBoundingBox3D& out);
175 cxResource_EXPORT Transform3D createTransformScale(const Vector3D& scale);
176 cxResource_EXPORT Transform3D createTransformTranslate(const Vector3D& translation);
177 cxResource_EXPORT Transform3D createTransformRotateX(const double angle);
178 cxResource_EXPORT Transform3D createTransformRotateY(const double angle);
179 cxResource_EXPORT Transform3D createTransformRotateZ(const double angle);
180 cxResource_EXPORT Transform3D createTransformIJC(const Vector3D& ivec, const Vector3D& jvec, const Vector3D& center);
182 
183 // --------------------------------------------------------
184 typedef boost::shared_ptr<Transform3D> Transform3DPtr;
185 
190 } // namespace cx
191 // --------------------------------------------------------
192 
193 #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)
boost::shared_ptr< Transform3D > Transform3DPtr
cxResource_EXPORT Transform3D createTransformRotationBetweenVectors(Vector3D from, Vector3D to)
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)