1 // Copyright (c) 1991-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _gp_Trsf_HeaderFile
16 #define _gp_Trsf_HeaderFile
18 #include <gp_TrsfForm.hxx>
21 #include <NCollection_Mat4.hxx>
22 #include <Standard.hxx>
23 #include <Standard_Boolean.hxx>
24 #include <Standard_DefineAlloc.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_Handle.hxx>
27 #include <Standard_Real.hxx>
29 class Standard_ConstructionError;
30 class Standard_OutOfRange;
38 // Avoid possible conflict with SetForm macro defined by windows.h
43 //! Defines a non-persistent transformation in 3D space.
44 //! The following transformations are implemented :
45 //! . Translation, Rotation, Scale
46 //! . Symmetry with respect to a point, a line, a plane.
47 //! Complex transformations can be obtained by combining the
48 //! previous elementary transformations using the method
50 //! The transformations can be represented as follow :
52 //! V1 V2 V3 T XYZ XYZ
53 //! | a11 a12 a13 a14 | | x | | x'|
54 //! | a21 a22 a23 a24 | | y | | y'|
55 //! | a31 a32 a33 a34 | | z | = | z'|
56 //! | 0 0 0 1 | | 1 | | 1 |
58 //! where {V1, V2, V3} defines the vectorial part of the
59 //! transformation and T defines the translation part of the
61 //! This transformation never change the nature of the objects.
69 //! Returns the identity transformation.
72 //! Creates a 3D transformation from the 2D transformation T.
73 //! The resulting transformation has a homogeneous
74 //! vectorial part, V3, and a translation part, T3, built from T:
81 //! It also has the same scale factor as T. This
82 //! guarantees (by projection) that the transformation
83 //! which would be performed by T in a plane (2D space)
84 //! is performed by the resulting transformation in the xOy
85 //! plane of the 3D space, (i.e. in the plane defined by the
86 //! origin (0., 0., 0.) and the vectors DX (1., 0., 0.), and DY
87 //! (0., 1., 0.)). The scale factor is applied to the entire space.
88 Standard_EXPORT gp_Trsf(const gp_Trsf2d& T);
91 //! Makes the transformation into a symmetrical transformation.
92 //! P is the center of the symmetry.
93 void SetMirror (const gp_Pnt& P);
96 //! Makes the transformation into a symmetrical transformation.
97 //! A1 is the center of the axial symmetry.
98 Standard_EXPORT void SetMirror (const gp_Ax1& A1);
101 //! Makes the transformation into a symmetrical transformation.
102 //! A2 is the center of the planar symmetry
103 //! and defines the plane of symmetry by its origin, "X
104 //! Direction" and "Y Direction".
105 Standard_EXPORT void SetMirror (const gp_Ax2& A2);
108 //! Changes the transformation into a rotation.
109 //! A1 is the rotation axis and Ang is the angular value of the
110 //! rotation in radians.
111 Standard_EXPORT void SetRotation (const gp_Ax1& A1, const Standard_Real Ang);
114 //! Changes the transformation into a rotation defined by quaternion.
115 //! Note that rotation is performed around origin, i.e.
116 //! no translation is involved.
117 Standard_EXPORT void SetRotation (const gp_Quaternion& R);
120 //! Changes the transformation into a scale.
121 //! P is the center of the scale and S is the scaling value.
122 //! Raises ConstructionError If <S> is null.
123 Standard_EXPORT void SetScale (const gp_Pnt& P, const Standard_Real S);
126 //! Modifies this transformation so that it transforms the
127 //! coordinate system defined by FromSystem1 into the
128 //! one defined by ToSystem2. After this modification, this
129 //! transformation transforms:
130 //! - the origin of FromSystem1 into the origin of ToSystem2,
131 //! - the "X Direction" of FromSystem1 into the "X
132 //! Direction" of ToSystem2,
133 //! - the "Y Direction" of FromSystem1 into the "Y
134 //! Direction" of ToSystem2, and
135 //! - the "main Direction" of FromSystem1 into the "main
136 //! Direction" of ToSystem2.
138 //! When you know the coordinates of a point in one
139 //! coordinate system and you want to express these
140 //! coordinates in another one, do not use the
141 //! transformation resulting from this function. Use the
142 //! transformation that results from SetTransformation instead.
143 //! SetDisplacement and SetTransformation create
144 //! related transformations: the vectorial part of one is the
145 //! inverse of the vectorial part of the other.
146 Standard_EXPORT void SetDisplacement (const gp_Ax3& FromSystem1, const gp_Ax3& ToSystem2);
148 //! Modifies this transformation so that it transforms the
149 //! coordinates of any point, (x, y, z), relative to a source
150 //! coordinate system into the coordinates (x', y', z') which
151 //! are relative to a target coordinate system, but which
152 //! represent the same point
153 //! The transformation is from the coordinate
154 //! system "FromSystem1" to the coordinate system "ToSystem2".
156 //! In a C++ implementation :
157 //! Real x1, y1, z1; // are the coordinates of a point in the
158 //! // local system FromSystem1
159 //! Real x2, y2, z2; // are the coordinates of a point in the
160 //! // local system ToSystem2
161 //! gp_Pnt P1 (x1, y1, z1)
163 //! T.SetTransformation (FromSystem1, ToSystem2);
164 //! gp_Pnt P2 = P1.Transformed (T);
165 //! P2.Coord (x2, y2, z2);
166 Standard_EXPORT void SetTransformation (const gp_Ax3& FromSystem1, const gp_Ax3& ToSystem2);
168 //! Modifies this transformation so that it transforms the
169 //! coordinates of any point, (x, y, z), relative to a source
170 //! coordinate system into the coordinates (x', y', z') which
171 //! are relative to a target coordinate system, but which
172 //! represent the same point
173 //! The transformation is from the default coordinate system
174 //! {P(0.,0.,0.), VX (1.,0.,0.), VY (0.,1.,0.), VZ (0., 0. ,1.) }
175 //! to the local coordinate system defined with the Ax3 ToSystem.
176 //! Use in the same way as the previous method. FromSystem1 is
177 //! defaulted to the absolute coordinate system.
178 Standard_EXPORT void SetTransformation (const gp_Ax3& ToSystem);
181 //! Sets transformation by directly specified rotation and translation.
182 Standard_EXPORT void SetTransformation (const gp_Quaternion& R, const gp_Vec& T);
185 //! Changes the transformation into a translation.
186 //! V is the vector of the translation.
187 void SetTranslation (const gp_Vec& V);
190 //! Makes the transformation into a translation where the translation vector
191 //! is the vector (P1, P2) defined from point P1 to point P2.
192 void SetTranslation (const gp_Pnt& P1, const gp_Pnt& P2);
194 //! Replaces the translation vector with the vector V.
195 Standard_EXPORT void SetTranslationPart (const gp_Vec& V);
197 //! Modifies the scale factor.
198 //! Raises ConstructionError If S is null.
199 Standard_EXPORT void SetScaleFactor (const Standard_Real S);
201 void SetForm (const gp_TrsfForm P);
203 //! Sets the coefficients of the transformation. The
204 //! transformation of the point x,y,z is the point
207 //! x' = a11 x + a12 y + a13 z + a14
208 //! y' = a21 x + a22 y + a23 z + a24
209 //! z' = a31 x + a32 y + a33 z + a34
211 //! The method Value(i,j) will return aij.
212 //! Raises ConstructionError if the determinant of the aij is null.
213 //! The matrix is orthogonalized before future using.
214 Standard_EXPORT void SetValues (const Standard_Real a11, const Standard_Real a12, const Standard_Real a13, const Standard_Real a14, const Standard_Real a21, const Standard_Real a22, const Standard_Real a23, const Standard_Real a24, const Standard_Real a31, const Standard_Real a32, const Standard_Real a33, const Standard_Real a34);
216 //! Returns true if the determinant of the vectorial part of
217 //! this transformation is negative.
218 Standard_Boolean IsNegative() const;
221 //! Returns the nature of the transformation. It can be: an
222 //! identity transformation, a rotation, a translation, a mirror
223 //! transformation (relative to a point, an axis or a plane), a
224 //! scaling transformation, or a compound transformation.
225 gp_TrsfForm Form() const;
227 //! Returns the scale factor.
228 Standard_Real ScaleFactor() const;
231 //! Returns the translation part of the transformation's matrix
232 const gp_XYZ& TranslationPart() const;
235 //! Returns the boolean True if there is non-zero rotation.
236 //! In the presence of rotation, the output parameters store the axis
237 //! and the angle of rotation. The method always returns positive
238 //! value "theAngle", i.e., 0. < theAngle <= PI.
239 //! Note that this rotation is defined only by the vectorial part of
240 //! the transformation; generally you would need to check also the
241 //! translational part to obtain the axis (gp_Ax1) of rotation.
242 Standard_EXPORT Standard_Boolean GetRotation (gp_XYZ& theAxis, Standard_Real& theAngle) const;
245 //! Returns quaternion representing rotational part of the transformation.
246 Standard_EXPORT gp_Quaternion GetRotation() const;
249 //! Returns the vectorial part of the transformation. It is
250 //! a 3*3 matrix which includes the scale factor.
251 Standard_EXPORT gp_Mat VectorialPart() const;
254 //! Computes the homogeneous vectorial part of the transformation.
255 //! It is a 3*3 matrix which doesn't include the scale factor.
256 //! In other words, the vectorial part of this transformation is equal
257 //! to its homogeneous vectorial part, multiplied by the scale factor.
258 //! The coefficients of this matrix must be multiplied by the
259 //! scale factor to obtain the coefficients of the transformation.
260 const gp_Mat& HVectorialPart() const;
263 //! Returns the coefficients of the transformation's matrix.
264 //! It is a 3 rows * 4 columns matrix.
265 //! This coefficient includes the scale factor.
266 //! Raises OutOfRanged if Row < 1 or Row > 3 or Col < 1 or Col > 4
267 Standard_Real Value (const Standard_Integer Row, const Standard_Integer Col) const;
269 Standard_EXPORT void Invert();
272 //! Computes the reverse transformation
273 //! Raises an exception if the matrix of the transformation
274 //! is not inversible, it means that the scale factor is lower
275 //! or equal to Resolution from package gp.
276 //! Computes the transformation composed with T and <me>.
277 //! In a C++ implementation you can also write Tcomposed = <me> * T.
279 //! Trsf T1, T2, Tcomp; ...............
280 //! Tcomp = T2.Multiplied(T1); // or (Tcomp = T2 * T1)
281 //! Pnt P1(10.,3.,4.);
282 //! Pnt P2 = P1.Transformed(Tcomp); //using Tcomp
283 //! Pnt P3 = P1.Transformed(T1); //using T1 then T2
284 //! P3.Transform(T2); // P3 = P2 !!!
285 Standard_NODISCARD gp_Trsf Inverted() const;
287 Standard_NODISCARD gp_Trsf Multiplied (const gp_Trsf& T) const;
288 Standard_NODISCARD gp_Trsf operator * (const gp_Trsf& T) const
290 return Multiplied(T);
294 //! Computes the transformation composed with <me> and T.
296 Standard_EXPORT void Multiply (const gp_Trsf& T);
297 void operator *= (const gp_Trsf& T)
303 //! Computes the transformation composed with <me> and T.
305 Standard_EXPORT void PreMultiply (const gp_Trsf& T);
307 Standard_EXPORT void Power (const Standard_Integer N);
310 //! Computes the following composition of transformations
311 //! <me> * <me> * .......* <me>, N time.
312 //! if N = 0 <me> = Identity
313 //! if N < 0 <me> = <me>.Inverse() *...........* <me>.Inverse().
315 //! Raises if N < 0 and if the matrix of the transformation not
317 Standard_NODISCARD gp_Trsf Powered (const Standard_Integer N) const;
319 void Transforms (Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const;
321 //! Transformation of a triplet XYZ with a Trsf
322 void Transforms (gp_XYZ& Coord) const;
324 //! Convert transformation to 4x4 matrix.
326 void GetMat4 (NCollection_Mat4<T>& theMat) const
328 if (shape == gp_Identity)
330 theMat.InitIdentity();
334 theMat.SetValue (0, 0, static_cast<T> (Value (1, 1)));
335 theMat.SetValue (0, 1, static_cast<T> (Value (1, 2)));
336 theMat.SetValue (0, 2, static_cast<T> (Value (1, 3)));
337 theMat.SetValue (0, 3, static_cast<T> (Value (1, 4)));
338 theMat.SetValue (1, 0, static_cast<T> (Value (2, 1)));
339 theMat.SetValue (1, 1, static_cast<T> (Value (2, 2)));
340 theMat.SetValue (1, 2, static_cast<T> (Value (2, 3)));
341 theMat.SetValue (1, 3, static_cast<T> (Value (2, 4)));
342 theMat.SetValue (2, 0, static_cast<T> (Value (3, 1)));
343 theMat.SetValue (2, 1, static_cast<T> (Value (3, 2)));
344 theMat.SetValue (2, 2, static_cast<T> (Value (3, 3)));
345 theMat.SetValue (2, 3, static_cast<T> (Value (3, 4)));
346 theMat.SetValue (3, 0, static_cast<T> (0));
347 theMat.SetValue (3, 1, static_cast<T> (0));
348 theMat.SetValue (3, 2, static_cast<T> (0));
349 theMat.SetValue (3, 3, static_cast<T> (1));
352 friend class gp_GTrsf;
356 //! Makes orthogonalization of "matrix"
357 Standard_EXPORT void Orthogonalize();
368 #include <gp_Trsf.lxx>
370 #endif // _gp_Trsf_HeaderFile