CustusX  20.03-rc1
An IGT application
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) 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 #ifndef CXTRANSFORM3D_H_
13 #define CXTRANSFORM3D_H_
14 
15 #include "cxResourceExport.h"
16 #include "cxPrecompiledHeader.h"
17 
18 #include <boost/array.hpp>
19 #include <boost/shared_ptr.hpp>
20 #include <QString>
21 #include "cxVector3D.h"
22 #include "cxDefinitions.h"
23 
24 
29 {
32 cxResource_EXPORT boost::array<double, 16> flatten(const Eigen::Affine3d* self);
33 
34 cxResource_EXPORT void fill(Eigen::Affine3d* self, vtkMatrix4x4Ptr m);
35 cxResource_EXPORT void fill(Eigen::Affine3d* self, float m[4][4]);
36 cxResource_EXPORT void fill(Eigen::Affine3d* self, const double* raw);
37 cxResource_EXPORT vtkMatrix4x4Ptr getVtkMatrix(const Eigen::Affine3d* self);
38 cxResource_EXPORT std::ostream& put(const Eigen::Affine3d* self, std::ostream& s, int indent, char newline);
39 cxResource_EXPORT Eigen::Affine3d fromString(const QString& text, bool* _ok);
40 cxResource_EXPORT vtkTransformPtr getVtkTransform(const Eigen::Affine3d* self);
41 }
42 
44 namespace Eigen
45 {
46 
47 template<typename _Scalar, int _Dim, int _Mode, int _Options>
48 std::ostream& operator<<(std::ostream& s, const Eigen::Transform<_Scalar, _Dim, _Mode, _Options>& t)
49 {
50  s << t.matrix().format(IOFormat()); // hack: force OK output even when the default in sscMathBase.h is Veector3D-centered.
51  // t.put(s);
52  return s;
53 }
54 
55 template<typename _Scalar, int _Dim, int _Mode, int _Options>
56 Vector3d Transform<_Scalar, _Dim, _Mode, _Options>::vector(const Vector3d& v) const
57 {
58  return this->linear() * v;
59 }
60 
61 template<typename _Scalar, int _Dim, int _Mode, int _Options>
62 Vector3d Transform<_Scalar, _Dim, _Mode, _Options>::unitVector(const Vector3d& v) const
63 {
64  return (this->linear() * v).normal();
65 }
66 
67 template<typename _Scalar, int _Dim, int _Mode, int _Options>
68 Vector3d Transform<_Scalar, _Dim, _Mode, _Options>::coord(const Vector3d& v) const
69 {
70  return (*this) * v;
71 }
72 
73 template<typename _Scalar, int _Dim, int _Mode, int _Options>
74 Transform<_Scalar, _Dim, _Mode, _Options> Transform<_Scalar, _Dim, _Mode, _Options>::inv() const
75 {
76  return this->inverse();
77 }
78 
79 template<typename _Scalar, int _Dim, int _Mode, int _Options>
80 boost::array<double, 16> Transform<_Scalar, _Dim, _Mode, _Options>::flatten() const
81 {
83 }
84 
85 template<typename _Scalar, int _Dim, int _Mode, int _Options>
86 Transform<_Scalar, _Dim, _Mode, _Options>::Transform(vtkMatrix4x4* m)
87 {
89 }
90 
91 template<typename _Scalar, int _Dim, int _Mode, int _Options>
92 Transform<_Scalar, _Dim, _Mode, _Options>::Transform(double* raw)
93 {
95 }
96 
97 template<typename _Scalar, int _Dim, int _Mode, int _Options>
99 {
101 }
102 
103 template<typename _Scalar, int _Dim, int _Mode, int _Options>
105 {
107 }
108 
109 template<typename _Scalar, int _Dim, int _Mode, int _Options>
110 std::ostream& Transform<_Scalar, _Dim, _Mode, _Options>::put(std::ostream& s, int indent, char newline) const
111 {
112  return cx_transform3D_internal::put(this, s, indent, newline);
113 }
114 
115 template<typename _Scalar, int _Dim, int _Mode, int _Options>
116 Transform<_Scalar, _Dim, _Mode, _Options> Transform<_Scalar, _Dim, _Mode, _Options>::fromString(const QString& text,
117  bool* _ok)
118 {
119  return cx_transform3D_internal::fromString(text, _ok);
120 }
121 
122 template<typename _Scalar, int _Dim, int _Mode, int _Options>
123 Transform<_Scalar, _Dim, _Mode, _Options> Transform<_Scalar, _Dim, _Mode, _Options>::fromVtkMatrix(vtkMatrix4x4Ptr m)
124 {
125  Transform<_Scalar, _Dim, _Mode, _Options> retval;
126  cx_transform3D_internal::fill(&retval, m);
127  return retval;
128 }
129 
130 template<typename _Scalar, int _Dim, int _Mode, int _Options>
131 Transform<_Scalar, _Dim, _Mode, _Options> Transform<_Scalar, _Dim, _Mode, _Options>::fromFloatArray(float m[4][4])
132 {
133  Transform<_Scalar, _Dim, _Mode, _Options> retval;
134  cx_transform3D_internal::fill(&retval, m);
135  return retval;
136 }
137 
138 
139 } // namespace Eigen
141 
142 // --------------------------------------------------------
143 namespace cx
144 {
145 class DoubleBoundingBox3D;
146 
161 typedef Eigen::Affine3d Transform3D;
162 
163 cxResource_EXPORT bool similar(const Transform3D& a, const Transform3D& b, double tol = 1.0E-4);
164 
168 cxResource_EXPORT DoubleBoundingBox3D transform(const Transform3D& m, const DoubleBoundingBox3D& bb);
169 
175 cxResource_EXPORT Transform3D createTransformNormalize(const DoubleBoundingBox3D& in, const DoubleBoundingBox3D& out);
176 
179 cxResource_EXPORT Transform3D createTransformScale(const Vector3D& scale);
180 
183 cxResource_EXPORT Transform3D createTransformTranslate(const Vector3D& translation);
184 
187 cxResource_EXPORT Transform3D createTransformRotateX(const double angle);
188 
191 cxResource_EXPORT Transform3D createTransformRotateY(const double angle);
192 
195 cxResource_EXPORT Transform3D createTransformRotateZ(const double angle);
196 
203 cxResource_EXPORT Transform3D createTransformIJC(const Vector3D& ivec, const Vector3D& jvec, const Vector3D& center);
204 
205 cxResource_EXPORT Transform3D createTransformRotationBetweenVectors(Vector3D from, Vector3D to);
206 
207 
213 cxResource_EXPORT Transform3D createTransformLPS2RAS();
214 
220 cxResource_EXPORT Transform3D createTransformFromReferenceToExternal(PATIENT_COORDINATE_SYSTEM external);
221 
222 
223 
224 // --------------------------------------------------------
225 typedef boost::shared_ptr<Transform3D> Transform3DPtr;
226 
233 cxResource_EXPORT std::string matrixAsSingleLineString(Transform3D transform);
234 
239 } // namespace cx
240 // --------------------------------------------------------
241 
242 #endif /*CXTRANSFORM3D_H_*/
vtkSmartPointer< class vtkMatrix4x4 > vtkMatrix4x4Ptr
Definition: cxMathBase.h:37
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
Transform3D createTransformRotationBetweenVectors(Vector3D from, Vector3D to)
cxResource_EXPORT Transform3D createTransformLPS2RAS()
std::string matrixAsSingleLineString(cx::Transform3D transform)
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:56
vtkSmartPointer< class vtkTransform > vtkTransformPtr
Definition: cxMathBase.h:41
Transform3D createTransformNormalize(const DoubleBoundingBox3D &in, const DoubleBoundingBox3D &out)
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:42
void fill(Eigen::Affine3d *self, vtkMatrix4x4Ptr m)
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
Transform3D createTransformRotateZ(const double angle)
vtkTransformPtr getVtkTransform(const Eigen::Affine3d *self)
Transform3D createTransformRotateX(const double angle)
float4 transform(float16 matrix, float4 voxel)
Namespace for all CustusX production code.