DATAKIT SDK  V2026.4
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 
34  //! \CreateBase
36  //! \deprecated use Create instead
37  SetAsDeprecated( "2026.4", "Use Create instead" )
38  static Dtk_SmartPtr<Dtk_transfo> create();
39  //! \CreateCopy
41  //! \deprecated use Create instead
42  SetAsDeprecated( "2026.4", "Use Create instead" )
43  static Dtk_SmartPtr<Dtk_transfo> create( const Dtk_transfo& );
44  //! \brief default constructor
46  //! \brief create a transfo from a double*
47  //! \param[in] d array of double
48  //! \param[in] typefill method to fill (see below)
49  //! \brief 0 (default) : 13 elements : Xx,Xy,Xz,Yx,Yy,Yz,Zx,Zy,Zz,Ox,Oy,Oz,GlobalScale
50  Dtk_transfo( Dtk_Double64* d, Dtk_Int32 typefill = 0 );
51  //! \brief copy constructor
52  //! \param[in] m the matrix to be copied
53  //!
54  //! \warning m must be a 4x4 or 4x3 Dtk_matrix
55  Dtk_transfo( const Dtk_matrix& m );
56  //! \brief Full featured constructor
57  //! \param[in] X the X direction.
58  //! \param[in] Y the Y direction.
59  //! \param[in] Z the Z direction.
60  //! \param[in] O the Origin.
61  //! \param[in] scale the scale factor : default is 1.0
62  Dtk_transfo( const Dtk_dir& X, const Dtk_dir& Y, const Dtk_dir& Z, const Dtk_pnt& O, const Dtk_Double64& scale = 1.0 );
63  //! \brief Destructor
64  //!
66  //! \brief Compare 2 Dtk_transfo matrix
67  //! \param[in] in the Dtk_transfo to test with this.
68  //! \return 1 if equal, 0 if not.
69  //!
70  int operator ==( const Dtk_transfo& in ) const;
71  //! \brief Is transformation Identity
72  //! \return 1 if is identity 0 if not.
73  //!
74  int is_identity() const;
75 
76  //! \brief Is normalized
77  //! \return 1 if rotation vector are normalized 0 if not.
78  //!
80 
81  //! \brief Is direct
82  //! \return 1 if transformation is direct 0 if not.
83  //!
84  Dtk_bool IsDirect() const;
85 
86  //! \brief Obsolete : use getScale instead.
87  //!
88  double scale() const;
89  //! \brief Retrieves the scale factor.
90  //! \return the scale factor.
91  //!
92  const double& getScale() const;
93  //! \brief Set a new scale
94  //! \param[in] scale the new scale.
95  //! \return the scale factor (get/set).
96  //!
98  //Dtk_pnt getO(); // deprecated.
99  //Dtk_dir getVect(int n,bool normalize=false); // deprecated.
100  //! \brief Return the X vector
101  //! \return the X Dtk_dir
102  //!
103  const Dtk_dir& getXdir() const;
104  //! \brief Return the Y vector
105  //! \return the Y Dtk_dir
106  //!
107  const Dtk_dir& getYdir() const;
108  //! \brief Return the Z vector
109  //! \return the Z Dtk_dir
110  //!
111  const Dtk_dir& getZdir() const;
112  //! \brief Return the O center point of the Dtk_transfo (the center O of the basis)
113  //! \return the O Dtk_pnt
114  //!
115  const Dtk_pnt& getOrigin() const;
116  //! \brief Return the n component of the X vector
117  //! \param[in] n coordinate of the X vector to return.
118  //! \return the n component of the X vector
119  //!
120  const double& getXcomponent( Dtk_Int32 n ) const;
121  //! \brief Return the n component of the Y vector
122  //! \param[in] n coordinate of the Y vector to return.
123  //! \return the n component of the Y vector
124  //!
125  const double& getYcomponent( Dtk_Int32 n ) const;
126  //! \brief Return the n component of the Z vector
127  //! \param[in] n coordinate of the Z vector to return.
128  //! \return the n component of the Z vector
129  //!
130  const double& getZcomponent( Dtk_Int32 n ) const;
131  //! \brief Return the n component of the O center point
132  //! \param[in] n coordinate of the O center point
133  //! \return the n component of the O center point
134  //!
135  const double& getOcomponent( Dtk_Int32 n ) const;
136  //! \brief Set a new X vector
137  //! \param[in] X the new X vector
138  //!
139  void setXdir( const Dtk_dir& X );
140  //! \brief Set a new Y vector
141  //! \param[in] Y the new Y vector
142  //!
143  void setYdir( const Dtk_dir& Y );
144  //! \brief Set a new Z vector
145  //! \param[in] Z the new Z vector
146  //!
147  void setZdir( const Dtk_dir& Z );
148  //! \brief Set a new O center point
149  //! \param[in] O the new O point
150  //!
151  void setOrigin( const Dtk_pnt& O );
152  //! \brief Set a new X vector by giving its components
153  //! \param[in] x the x component of the X vector
154  //! \param[in] y the y component of the X vector
155  //! \param[in] z the z component of the X vector
156  //!
158  //! \brief Set a new Y vector by giving its components
159  //! \param[in] x the x component of the Y vector
160  //! \param[in] y the y component of the Y vector
161  //! \param[in] z the z component of the Y vector
162  //!
164  //! \brief Set a new Z vector by giving its components
165  //! \param[in] x the x component of the Z vector
166  //! \param[in] y the y component of the Z vector
167  //! \param[in] z the z component of the Z vector
168  //!
170  //! \brief Set a new O center point by giving its components
171  //! \param[in] x the x component of the O center point
172  //! \param[in] y the y component of the O center point
173  //! \param[in] z the z component of the O center point
174  //!
176  //! \brief Inverse the current Matrix
177  //! \return 0 is success, -1 otherwise
178  //!
179  int inverse();
180  //! \brief Allow to multiply 2 Dtk_transfo (matrix multiplication)
181  //! \param[in] t1 first matrix to multiply
182  //! \param[in] t2 second matrix to multiply
183  //! \return the product t1*t2
184  //!
185  friend Dtk_transfo operator*( const Dtk_transfo&, const Dtk_transfo& );
186  //! \brief Allow to multiply a Dtk_transfo by a point
187  //! \param[in] M matrix to multiply
188  //! \param[in] P point to multiply by
189  //! \return the point M*P
190  //!
191  friend Dtk_pnt operator*( const Dtk_transfo& M, const Dtk_pnt& P );
192  //! \brief Allow to multiply a Dtk_transfo by a vector
193  //! \param[in] M matrix to multiply
194  //! \param[in] P vector to multiply by
195  //! \return the vector M*P
196  //!
197  friend Dtk_dir operator*( const Dtk_transfo& M, const Dtk_dir& P );
198  //! \brief Multiply a matrix by a scalar number
199  //! \brief whole datas are multiplied.
200  //! \param[in] M matrix to multiply
201  //! \param[in] d scalar
202  //! \return the vector M*d
203  //!
204  friend Dtk_transfo operator*( const Dtk_transfo& M, const Dtk_Double64 d );
205  //! \brief Divide a matrix by a scalar number
206  //! \brief whole datas are divided.
207  //! \param[in] M matrix to divide
208  //! \param[in] d scalar
209  //! \return the vector M/d
210  //!
211  friend Dtk_transfo operator/( Dtk_transfo& M, Dtk_Double64 d );
212  //! \brief Allow to add 2 Dtk_transfo (matrix addition)
213  //! \param[in] t1 first matrix to add
214  //! \param[in] t2 second matrix to add
215  //! \return the sum t1+t2
216  //!
217  friend Dtk_transfo operator+( const Dtk_transfo& t1, const Dtk_transfo& t2 );
218  //! \brief Allow to substracte 2 Dtk_transfo (matrix difference)
219  //! \param[in] t1 first matrix to substracte
220  //! \param[in] t2 second matrix to substracte
221  //! \return the difference t1-t2
222  //!
223  friend Dtk_transfo operator-( const Dtk_transfo& t1, const Dtk_transfo& t2 );
224  //friend Dtk_transfo operator+=(Dtk_transfo& t1,const Dtk_transfo& t2); // deprecated
225  //friend Dtk_transfo operator-=(Dtk_transfo& t1,const Dtk_transfo& t2); // deprecated
226 
227  //void Decompose_TS(Dtk_transfo& T,Dtk_transfo& S); // deprecated
228  //void Decompose_ST(Dtk_transfo& S,Dtk_transfo& T); // deprecated
229 
230  //! \brief Translate the Dtk_transfo
231  //! \brief Mathematics : just sum the given vector to the O center point.
232  //! \param[in] V vector
233  //!
234  void addTranslate( const Dtk_dir& V );
235  //! \brief Add a scale
236  //! \brief Mathematics : just multiply the current scale by the given scale
237  //! \param[in] scale scale to add.
238  //!
240 
241  //! \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
242  //! \param[in] axis axis of the ratation
243  //! \param[in] angle angle of rotation (radian)
244  //!
245  void setAxisRotation( Dtk_dir axis, Dtk_Double64 angle );
246 
247  //void addRotate_axeX(double angle);
248  //void addRotate_axeY(double angle);
249  //! \brief 2D operation, not yet generalized but soon
250  //! \brief turn the basis represented by Dtk_transfo around Z vector
251  //! \param[in] angle angle of rotation (radian)
252  //!
254 
255  //! \brief Dtk_matrix conversion
256  //! \return Dtk_matrix corresponding
257  //!
259 
260  void Normalize()
261  {
262  v[ 0 ].normalize();
263  v[ 1 ].normalize();
264  v[ 2 ].normalize();
265 
266  }
267 
268 
269 
270 private:
271  friend class Dtk_SmartPtr<Dtk_transfo>;
272  friend std::ostream& operator<<( std::ostream& o, const Dtk_transfo& d );
274 };
275 
276 
277 #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_dir.hpp
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::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::SetAsDeprecated
SetAsDeprecated("2026.4", "Use Create instead") static Dtk_SmartPtr< Dtk_transfo > create()
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_bool
char Dtk_bool
Definition: define.h:724
Dtk_transfo::scale
double scale() const
Obsolete : use getScale instead.
Dtk_Double64
double Dtk_Double64
Definition: define.h:698
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_transfo::Create
static Dtk_SmartPtr< Dtk_transfo > Create()
Calls default constructor to allocate a new object.
Dtk_Int32
int32_t Dtk_Int32
Definition: define.h:686
Dtk_transfo::Normalize
void Normalize()
Definition: dtk_transfo.hpp:260
Dtk_transfo::v
Dtk_dir v[3]
Definition: dtk_transfo.hpp:22
Dtk_transfo::is_identity
int is_identity() const
Is transformation Identity.
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::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::getScale
const double & getScale() const
Retrieves the scale factor.
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::getXcomponent
const double & getXcomponent(Dtk_Int32 n) const
Return the n component of the X vector.
Dtk_transfo::DtkDynamicCast
static Dtk_transfo * DtkDynamicCast(Dtk_Object *s)
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_Object
Definition: dtk_object.hpp:8
Dtk_transfo::DtkDynamicType
Dtk_Int32 DtkDynamicType(const Dtk_Int32 &inId)
Dtk_transfo::IsNormalized
Dtk_bool IsNormalized(const Dtk_Double64 &inTol=DTK_TOLERANCE) const
Is normalized.
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:14
dtk_object.hpp