Commit | Line | Data |
---|---|---|
42cf5bc1 | 1 | // Copyright (c) 1991-1999 Matra Datavision |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS | |
3 | // | |
4 | // This file is part of Open CASCADE Technology software library. | |
5 | // | |
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. | |
11 | // | |
12 | // Alternatively, this file may be used under the terms of Open CASCADE | |
13 | // commercial license or contractual agreement. | |
14 | ||
15 | #ifndef _gp_Trsf_HeaderFile | |
16 | #define _gp_Trsf_HeaderFile | |
17 | ||
42cf5bc1 | 18 | #include <gp_TrsfForm.hxx> |
19 | #include <gp_Mat.hxx> | |
20 | #include <gp_XYZ.hxx> | |
1f7f5a90 | 21 | #include <NCollection_Mat4.hxx> |
22 | #include <Standard.hxx> | |
42cf5bc1 | 23 | #include <Standard_Boolean.hxx> |
1f7f5a90 | 24 | #include <Standard_DefineAlloc.hxx> |
42cf5bc1 | 25 | #include <Standard_Integer.hxx> |
1f7f5a90 | 26 | #include <Standard_Handle.hxx> |
27 | #include <Standard_Real.hxx> | |
28 | ||
42cf5bc1 | 29 | class Standard_ConstructionError; |
30 | class Standard_OutOfRange; | |
42cf5bc1 | 31 | class gp_Pnt; |
32 | class gp_Ax1; | |
33 | class gp_Ax2; | |
34 | class gp_Quaternion; | |
35 | class gp_Ax3; | |
36 | class gp_Vec; | |
42cf5bc1 | 37 | |
896faa72 | 38 | // Avoid possible conflict with SetForm macro defined by windows.h |
39 | #ifdef SetForm | |
40 | #undef SetForm | |
41 | #endif | |
42 | ||
42cf5bc1 | 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 | |
49 | //! Multiply. | |
50 | //! The transformations can be represented as follow : | |
51 | //! | |
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 | | |
57 | //! | |
58 | //! where {V1, V2, V3} defines the vectorial part of the | |
59 | //! transformation and T defines the translation part of the | |
60 | //! transformation. | |
61 | //! This transformation never change the nature of the objects. | |
62 | class gp_Trsf | |
63 | { | |
64 | public: | |
65 | ||
66 | DEFINE_STANDARD_ALLOC | |
67 | ||
68 | ||
69 | //! Returns the identity transformation. | |
70 | gp_Trsf(); | |
71 | ||
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: | |
75 | //! a11 a12 | |
76 | //! 0 a13 | |
77 | //! V3 = a21 a22 0 T3 | |
78 | //! = a23 | |
79 | //! 0 0 1. | |
80 | //! 0 | |
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); | |
89 | ||
90 | ||
91 | //! Makes the transformation into a symmetrical transformation. | |
92 | //! P is the center of the symmetry. | |
93 | void SetMirror (const gp_Pnt& P); | |
94 | ||
95 | ||
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); | |
99 | ||
100 | ||
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); | |
106 | ||
107 | ||
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); | |
112 | ||
113 | ||
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); | |
118 | ||
119 | ||
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); | |
124 | ||
125 | ||
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. | |
137 | //! Warning | |
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); | |
147 | ||
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". | |
155 | //! Example : | |
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) | |
162 | //! Trsf T; | |
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); | |
167 | ||
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); | |
179 | ||
180 | ||
181 | //! Sets transformation by directly specified rotation and translation. | |
182 | Standard_EXPORT void SetTransformation (const gp_Quaternion& R, const gp_Vec& T); | |
183 | ||
184 | ||
185 | //! Changes the transformation into a translation. | |
186 | //! V is the vector of the translation. | |
187 | void SetTranslation (const gp_Vec& V); | |
188 | ||
189 | ||
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); | |
193 | ||
194 | //! Replaces the translation vector with the vector V. | |
195 | Standard_EXPORT void SetTranslationPart (const gp_Vec& V); | |
196 | ||
197 | //! Modifies the scale factor. | |
198 | //! Raises ConstructionError If S is null. | |
199 | Standard_EXPORT void SetScaleFactor (const Standard_Real S); | |
200 | ||
be5c3602 | 201 | void SetForm (const gp_TrsfForm P); |
42cf5bc1 | 202 | |
203 | //! Sets the coefficients of the transformation. The | |
204 | //! transformation of the point x,y,z is the point | |
205 | //! x',y',z' with : | |
206 | //! | |
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 | |
210 | //! | |
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); | |
215 | ||
216 | //! Returns true if the determinant of the vectorial part of | |
217 | //! this transformation is negative. | |
218 | Standard_Boolean IsNegative() const; | |
219 | ||
220 | ||
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; | |
226 | ||
227 | //! Returns the scale factor. | |
228 | Standard_Real ScaleFactor() const; | |
229 | ||
230 | ||
231 | //! Returns the translation part of the transformation's matrix | |
232 | const gp_XYZ& TranslationPart() const; | |
233 | ||
234 | ||
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; | |
243 | ||
244 | ||
245 | //! Returns quaternion representing rotational part of the transformation. | |
246 | Standard_EXPORT gp_Quaternion GetRotation() const; | |
247 | ||
248 | ||
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; | |
252 | ||
253 | ||
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; | |
261 | ||
262 | ||
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; | |
268 | ||
269 | Standard_EXPORT void Invert(); | |
270 | ||
271 | ||
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. | |
278 | //! Example : | |
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 !!! | |
0be7dbe1 | 285 | Standard_NODISCARD gp_Trsf Inverted() const; |
42cf5bc1 | 286 | |
0be7dbe1 BB |
287 | Standard_NODISCARD gp_Trsf Multiplied (const gp_Trsf& T) const; |
288 | Standard_NODISCARD gp_Trsf operator * (const gp_Trsf& T) const | |
42cf5bc1 | 289 | { |
290 | return Multiplied(T); | |
291 | } | |
292 | ||
293 | ||
294 | //! Computes the transformation composed with <me> and T. | |
295 | //! <me> = <me> * T | |
296 | Standard_EXPORT void Multiply (const gp_Trsf& T); | |
297 | void operator *= (const gp_Trsf& T) | |
298 | { | |
299 | Multiply(T); | |
300 | } | |
301 | ||
302 | ||
303 | //! Computes the transformation composed with <me> and T. | |
304 | //! <me> = T * <me> | |
305 | Standard_EXPORT void PreMultiply (const gp_Trsf& T); | |
306 | ||
307 | Standard_EXPORT void Power (const Standard_Integer N); | |
308 | ||
309 | ||
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(). | |
314 | //! | |
315 | //! Raises if N < 0 and if the matrix of the transformation not | |
316 | //! inversible. | |
0be7dbe1 | 317 | Standard_NODISCARD gp_Trsf Powered (const Standard_Integer N) const; |
42cf5bc1 | 318 | |
319 | void Transforms (Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const; | |
320 | ||
321 | //! Transformation of a triplet XYZ with a Trsf | |
322 | void Transforms (gp_XYZ& Coord) const; | |
323 | ||
1f7f5a90 | 324 | //! Convert transformation to 4x4 matrix. |
325 | template<class T> | |
326 | void GetMat4 (NCollection_Mat4<T>& theMat) const | |
327 | { | |
328 | if (shape == gp_Identity) | |
329 | { | |
330 | theMat.InitIdentity(); | |
331 | return; | |
332 | } | |
333 | ||
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)); | |
350 | } | |
42cf5bc1 | 351 | |
352 | friend class gp_GTrsf; | |
353 | ||
42cf5bc1 | 354 | protected: |
355 | ||
42cf5bc1 | 356 | //! Makes orthogonalization of "matrix" |
357 | Standard_EXPORT void Orthogonalize(); | |
358 | ||
42cf5bc1 | 359 | private: |
360 | ||
42cf5bc1 | 361 | Standard_Real scale; |
362 | gp_TrsfForm shape; | |
363 | gp_Mat matrix; | |
364 | gp_XYZ loc; | |
365 | ||
42cf5bc1 | 366 | }; |
367 | ||
42cf5bc1 | 368 | #include <gp_Trsf.lxx> |
369 | ||
42cf5bc1 | 370 | #endif // _gp_Trsf_HeaderFile |