DATAKIT SDK  V2026.2
dtk_transfo.hpp
Go to the documentation of this file.
1 #ifndef __DTK_TRANSFO_HPP__
2 #define __DTK_TRANSFO_HPP__
3 
4 #include "struct/str_def.h"
9 #include "def/define.h"
10 
11 //! \ingroup base_types
12 //! \class Dtk_transfo
13 //! \brief This is the Transformation dedicated class.
14 //! \brief A transformation a matrix is a basis : it contain a point, 3 vectors X,Y,Z, and a global scale.
15 //! \brief Note that the implementation allow you to unnormalize the vectors if really needed (distortion matrix), but it is suggested that the X,Y,Z vectors are normalized, and the scale parameter define the global scale
16 //!
17 //! This class lets you use transformation.
18 class Dtk_transfo:public Dtk_Object
19 {
20 protected:
21  //enum { _typeID = DTK_TYPE_TRANSFO };
22  Dtk_dir v[ 3 ];
24  double sc;
25  void _init();
26  void _copy( const Dtk_transfo& s );
27  void _reset();
28 public:
29 
30  //downcasting
33 
36  //! \brief default constructor
38  //! \brief create a transfo from a double*
39  //! \param[in] d array of double
40  //! \param[in] typefill method to fill (see below)
41  //! \brief 0 (default) : 13 elements : Xx,Xy,Xz,Yx,Yy,Yz,Zx,Zy,Zz,Ox,Oy,Oz,GlobalScale
42  Dtk_transfo( Dtk_Double64* d, Dtk_Int32 typefill = 0 );
43  //! \brief copy constructor
44  //! \param[in] m the matrix to be copied
45  //!
46  //! \warning m must be a 4x4 or 4x3 Dtk_matrix
47  Dtk_transfo( const Dtk_matrix& m );
48  //! \brief Full featured constructor
49  //! \param[in] X the X direction.
50  //! \param[in] Y the Y direction.
51  //! \param[in] Z the Z direction.
52  //! \param[in] O the Origin.
53  //! \param[in] scale the scale factor : default is 1.0
54  Dtk_transfo( const Dtk_dir& X, const Dtk_dir& Y, const Dtk_dir& Z, const Dtk_pnt& O, const Dtk_Double64& scale = 1.0 );
55  //! \brief Destructor
56  //!
58  //! \brief Compare 2 Dtk_transfo matrix
59  //! \param[in] in the Dtk_transfo to test with this.
60  //! \return 1 if equal, 0 if not.
61  //!
62  int operator ==( const Dtk_transfo& in ) const;
63  //! \brief Is transformation Identity
64  //! \return 1 if is identity 0 if not.
65  //!
66  int is_identity() const;
67 
68  //! \brief Is normalized
69  //! \return 1 if rotation vector are normalized 0 if not.
70  //!
72 
73  //! \brief Is direct
74  //! \return 1 if transformation is direct 0 if not.
75  //!
76  Dtk_bool IsDirect() const;
77 
78  //! \brief Obsolete : use getScale instead.
79  //!
80  double scale() const;
81  //! \brief Retrieves the scale factor.
82  //! \return the scale factor.
83  //!
84  const double& getScale() const;
85  //! \brief Set a new scale
86  //! \param[in] scale the new scale.
87  //! \return the scale factor (get/set).
88  //!
90  //Dtk_pnt getO(); // deprecated.
91  //Dtk_dir getVect(int n,bool normalize=false); // deprecated.
92  //! \brief Return the X vector
93  //! \return the X Dtk_dir
94  //!
95  const Dtk_dir& getXdir() const;
96  //! \brief Return the Y vector
97  //! \return the Y Dtk_dir
98  //!
99  const Dtk_dir& getYdir() const;
100  //! \brief Return the Z vector
101  //! \return the Z Dtk_dir
102  //!
103  const Dtk_dir& getZdir() const;
104  //! \brief Return the O center point of the Dtk_transfo (the center O of the basis)
105  //! \return the O Dtk_pnt
106  //!
107  const Dtk_pnt& getOrigin() const;
108  //! \brief Return the n component of the X vector
109  //! \param[in] n coordinate of the X vector to return.
110  //! \return the n component of the X vector
111  //!
112  const double& getXcomponent( Dtk_Int32 n ) const;
113  //! \brief Return the n component of the Y vector
114  //! \param[in] n coordinate of the Y vector to return.
115  //! \return the n component of the Y vector
116  //!
117  const double& getYcomponent( Dtk_Int32 n ) const;
118  //! \brief Return the n component of the Z vector
119  //! \param[in] n coordinate of the Z vector to return.
120  //! \return the n component of the Z vector
121  //!
122  const double& getZcomponent( Dtk_Int32 n ) const;
123  //! \brief Return the n component of the O center point
124  //! \param[in] n coordinate of the O center point
125  //! \return the n component of the O center point
126  //!
127  const double& getOcomponent( Dtk_Int32 n ) const;
128  //! \brief Set a new X vector
129  //! \param[in] X the new X vector
130  //!
131  void setXdir( const Dtk_dir& X );
132  //! \brief Set a new Y vector
133  //! \param[in] Y the new Y vector
134  //!
135  void setYdir( const Dtk_dir& Y );
136  //! \brief Set a new Z vector
137  //! \param[in] Z the new Z vector
138  //!
139  void setZdir( const Dtk_dir& Z );
140  //! \brief Set a new O center point
141  //! \param[in] O the new O point
142  //!
143  void setOrigin( const Dtk_pnt& O );
144  //! \brief Set a new X vector by giving its components
145  //! \param[in] x the x component of the X vector
146  //! \param[in] y the y component of the X vector
147  //! \param[in] z the z component of the X vector
148  //!
150  //! \brief Set a new Y vector by giving its components
151  //! \param[in] x the x component of the Y vector
152  //! \param[in] y the y component of the Y vector
153  //! \param[in] z the z component of the Y vector
154  //!
156  //! \brief Set a new Z vector by giving its components
157  //! \param[in] x the x component of the Z vector
158  //! \param[in] y the y component of the Z vector
159  //! \param[in] z the z component of the Z vector
160  //!
162  //! \brief Set a new O center point by giving its components
163  //! \param[in] x the x component of the O center point
164  //! \param[in] y the y component of the O center point
165  //! \param[in] z the z component of the O center point
166  //!
168  //! \brief Inverse the current Matrix
169  //! \return 0 is success, -1 otherwise
170  //!
171  int inverse();
172  //! \brief Allow to multiply 2 Dtk_transfo (matrix multiplication)
173  //! \param[in] t1 first matrix to multiply
174  //! \param[in] t2 second matrix to multiply
175  //! \return the product t1*t2
176  //!
177  friend Dtk_transfo operator*( const Dtk_transfo&, const Dtk_transfo& );
178  //! \brief Allow to multiply a Dtk_transfo by a point
179  //! \param[in] M matrix to multiply
180  //! \param[in] P point to multiply by
181  //! \return the point M*P
182  //!
183  friend Dtk_pnt operator*( const Dtk_transfo& M, const Dtk_pnt& P );
184  //! \brief Allow to multiply a Dtk_transfo by a vector
185  //! \param[in] M matrix to multiply
186  //! \param[in] P vector to multiply by
187  //! \return the vector M*P
188  //!
189  friend Dtk_dir operator*( const Dtk_transfo& M, const Dtk_dir& P );
190  //! \brief Multiply a matrix by a scalar number
191  //! \brief whole datas are multiplied.
192  //! \param[in] M matrix to multiply
193  //! \param[in] d scalar
194  //! \return the vector M*d
195  //!
196  friend Dtk_transfo operator*( const Dtk_transfo& M, const Dtk_Double64 d );
197  //! \brief Divide a matrix by a scalar number
198  //! \brief whole datas are divided.
199  //! \param[in] M matrix to divide
200  //! \param[in] d scalar
201  //! \return the vector M/d
202  //!
204  //! \brief Allow to add 2 Dtk_transfo (matrix addition)
205  //! \param[in] t1 first matrix to add
206  //! \param[in] t2 second matrix to add
207  //! \return the sum t1+t2
208  //!
209  friend Dtk_transfo operator+( const Dtk_transfo& t1, const Dtk_transfo& t2 );
210  //! \brief Allow to substracte 2 Dtk_transfo (matrix difference)
211  //! \param[in] t1 first matrix to substracte
212  //! \param[in] t2 second matrix to substracte
213  //! \return the difference t1-t2
214  //!
215  friend Dtk_transfo operator-( const Dtk_transfo& t1, const Dtk_transfo& t2 );
216  //friend Dtk_transfo operator+=(Dtk_transfo& t1,const Dtk_transfo& t2); // deprecated
217  //friend Dtk_transfo operator-=(Dtk_transfo& t1,const Dtk_transfo& t2); // deprecated
218 
219  //void Decompose_TS(Dtk_transfo& T,Dtk_transfo& S); // deprecated
220  //void Decompose_ST(Dtk_transfo& S,Dtk_transfo& T); // deprecated
221 
222  //! \brief Translate the Dtk_transfo
223  //! \brief Mathematics : just sum the given vector to the O center point.
224  //! \param[in] V vector
225  //!
226  void addTranslate( const Dtk_dir& V );
227  //! \brief Add a scale
228  //! \brief Mathematics : just multiply the current scale by the given scale
229  //! \param[in] scale scale to add.
230  //!
232 
233  //! \brief turn the basis represented by Dtk_transfo around a given vector with origin on (0.0, 0.0, 0.0) and scale equal to 1.0
234  //! \param[in] axis axis of the ratation
235  //! \param[in] angle angle of rotation (radian)
236  //!
237  void setAxisRotation( Dtk_dir axis, Dtk_Double64 angle );
238 
239  //void addRotate_axeX(double angle);
240  //void addRotate_axeY(double angle);
241  //! \brief 2D operation, not yet generalized but soon
242  //! \brief turn the basis represented by Dtk_transfo around Z vector
243  //! \param[in] angle angle of rotation (radian)
244  //!
246 
247  //! \brief Dtk_matrix conversion
248  //! \return Dtk_matrix corresponding
249  //!
251 
252  void Normalize()
253  {
254  v[ 0 ].normalize();
255  v[ 1 ].normalize();
256  v[ 2 ].normalize();
257 
258  }
259 
260 
261 
262 private:
263  friend class Dtk_SmartPtr<Dtk_transfo>;
264  friend std::ostream& operator<<( std::ostream& o, const Dtk_transfo& d );
266 };
267 
268 
269 #endif //#ifndef __DTK_TRANSFO_HPP__
Dtk_transfo::o
Dtk_pnt o
Definition: dtk_transfo.hpp:23
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
dtk_matrix.hpp
Dtk_transfo::setOrigin
void setOrigin(Dtk_Double64 x, Dtk_Double64 y, Dtk_Double64 z)
Set a new O center point by giving its components.
dtk_dir.hpp
Dtk_transfo::operator*
friend Dtk_pnt operator*(const Dtk_transfo &M, const Dtk_pnt &P)
Allow to multiply a Dtk_transfo by a point.
DTK_TOLERANCE
#define DTK_TOLERANCE
Definition: str_def.h:7
Dtk_transfo::setAxisRotation
void setAxisRotation(Dtk_dir axis, Dtk_Double64 angle)
turn the basis represented by Dtk_transfo around a given vector with origin on (0....
Dtk_transfo::getOrigin
const Dtk_pnt & getOrigin() const
Return the O center point of the Dtk_transfo (the center O of the basis)
Dtk_transfo::setOrigin
void setOrigin(const Dtk_pnt &O)
Set a new O center point.
Dtk_transfo::create
static Dtk_SmartPtr< Dtk_transfo > create()
Dtk_transfo::setZdir
void setZdir(const Dtk_dir &Z)
Set a new Z vector.
Dtk_transfo::getOcomponent
const double & getOcomponent(Dtk_Int32 n) const
Return the n component of the O center point.
Dtk_transfo::Dtk_transfoPtr_to_Dtk_transfo
friend Dtk_transfo Dtk_transfoPtr_to_Dtk_transfo(Dtk_SmartPtr< Dtk_transfo > &t)
Dtk_transfo::_init
void _init()
Dtk_transfo::addRotate_axeZ
void addRotate_axeZ(Dtk_Double64 angle)
2D operation, not yet generalized but soon
Dtk_transfo::getZcomponent
const double & getZcomponent(Dtk_Int32 n) const
Return the n component of the Z vector.
Dtk_transfo::operator==
int operator==(const Dtk_transfo &in) const
Compare 2 Dtk_transfo matrix.
Dtk_bool
char Dtk_bool
Definition: define.h:717
Dtk_transfo::scale
double scale() const
Obsolete : use getScale instead.
Dtk_Double64
double Dtk_Double64
Definition: define.h:691
Dtk_transfo::setXdir
void setXdir(const Dtk_dir &X)
Set a new X vector.
Dtk_transfo::operator<<
friend std::ostream & operator<<(std::ostream &o, const Dtk_transfo &d)
Dtk_transfo::getZdir
const Dtk_dir & getZdir() const
Return the Z vector.
dtk_pnt.hpp
Dtk_transfo::GetDtkMatrix
Dtk_matrix * GetDtkMatrix()
Dtk_matrix conversion.
Dtk_transfo::_copy
void _copy(const Dtk_transfo &s)
Dtk_Int32
int32_t Dtk_Int32
Definition: define.h:679
Dtk_transfo::Dtk_transfo
Dtk_transfo(const Dtk_dir &X, const Dtk_dir &Y, const Dtk_dir &Z, const Dtk_pnt &O, const Dtk_Double64 &scale=1.0)
Full featured constructor.
Dtk_transfo::Normalize
void Normalize()
Definition: dtk_transfo.hpp:252
Dtk_transfo::operator-
friend Dtk_transfo operator-(const Dtk_transfo &t1, const Dtk_transfo &t2)
Allow to substracte 2 Dtk_transfo (matrix difference)
Dtk_transfo::v
Dtk_dir v[3]
Definition: dtk_transfo.hpp:22
Dtk_transfo::is_identity
int is_identity() const
Is transformation Identity.
Dtk_transfo::~Dtk_transfo
~Dtk_transfo()
Destructor.
Dtk_matrix
Definition: dtk_matrix.hpp:8
Dtk_transfo::IsDirect
Dtk_bool IsDirect() const
Is direct.
Dtk_transfo::getXdir
const Dtk_dir & getXdir() const
Return the X vector.
Dtk_transfo::setZdir
void setZdir(Dtk_Double64 x, Dtk_Double64 y, Dtk_Double64 z)
Set a new Z vector by giving its components.
Dtk_transfo::setScale
void setScale(Dtk_Double64 scale)
Set a new scale.
Dtk_SmartPtr
Definition: util_ptr_dtk.hpp:37
Dtk_transfo::_reset
void _reset()
Dtk_transfo::operator*
friend Dtk_transfo operator*(const Dtk_transfo &M, const Dtk_Double64 d)
Multiply a matrix by a scalar number.
Dtk_transfo::getScale
const double & getScale() const
Retrieves the scale factor.
Dtk_transfo::operator*
friend Dtk_dir operator*(const Dtk_transfo &M, const Dtk_dir &P)
Allow to multiply a Dtk_transfo by a vector.
Dtk_dir::normalize
int normalize()
Dtk_transfo::setYdir
void setYdir(const Dtk_dir &Y)
Set a new Y vector.
Dtk_pnt
This is a mathematical point class.
Definition: dtk_pnt.hpp:20
str_def.h
Dtk_transfo::getYcomponent
const double & getYcomponent(Dtk_Int32 n) const
Return the n component of the Y vector.
Dtk_transfo::Dtk_transfo
Dtk_transfo(const Dtk_matrix &m)
copy constructor
Dtk_transfo::getXcomponent
const double & getXcomponent(Dtk_Int32 n) const
Return the n component of the X vector.
Dtk_transfo::operator+
friend Dtk_transfo operator+(const Dtk_transfo &t1, const Dtk_transfo &t2)
Allow to add 2 Dtk_transfo (matrix addition)
Dtk_transfo::Dtk_transfo
Dtk_transfo()
default constructor
Dtk_transfo::DtkDynamicCast
static Dtk_transfo * DtkDynamicCast(Dtk_Object *s)
Dtk_transfo::setYdir
void setYdir(Dtk_Double64 x, Dtk_Double64 y, Dtk_Double64 z)
Set a new Y vector by giving its components.
Dtk_transfo::sc
double sc
Definition: dtk_transfo.hpp:24
define.h
Dtk_transfo::inverse
int inverse()
Inverse the current Matrix.
Dtk_transfo::addTranslate
void addTranslate(const Dtk_dir &V)
Translate the Dtk_transfo.
Dtk_transfo::addScale
void addScale(Dtk_Double64)
Add a scale.
Dtk_transfo::getYdir
const Dtk_dir & getYdir() const
Return the Y vector.
Dtk_transfo::create
static Dtk_SmartPtr< Dtk_transfo > create(const Dtk_transfo &)
Dtk_Object
Definition: dtk_object.hpp:8
Dtk_transfo::setXdir
void setXdir(Dtk_Double64 x, Dtk_Double64 y, Dtk_Double64 z)
Set a new X vector by giving its components.
Dtk_transfo::operator/
friend Dtk_transfo operator/(Dtk_transfo &M, Dtk_Double64 d)
Divide a matrix by a scalar number.
Dtk_transfo::DtkDynamicType
Dtk_Int32 DtkDynamicType(const Dtk_Int32 &inId)
Dtk_transfo::Dtk_transfo
Dtk_transfo(Dtk_Double64 *d, Dtk_Int32 typefill=0)
create a transfo from a double*
Dtk_transfo::IsNormalized
Dtk_bool IsNormalized(const Dtk_Double64 &inTol=DTK_TOLERANCE) const
Is normalized.
Dtk_transfo::operator*
friend Dtk_transfo operator*(const Dtk_transfo &, const Dtk_transfo &)
Allow to multiply 2 Dtk_transfo (matrix multiplication)
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:14
dtk_object.hpp