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> |
0904aa63 | 27 | #include <Standard_OStream.hxx> |
1f7f5a90 | 28 | #include <Standard_Real.hxx> |
29 | ||
42cf5bc1 | 30 | class Standard_ConstructionError; |
31 | class Standard_OutOfRange; | |
42cf5bc1 | 32 | class gp_Pnt; |
33 | class gp_Ax1; | |
34 | class gp_Ax2; | |
35 | class gp_Quaternion; | |
36 | class gp_Ax3; | |
37 | class gp_Vec; | |
42cf5bc1 | 38 | |
896faa72 | 39 | // Avoid possible conflict with SetForm macro defined by windows.h |
40 | #ifdef SetForm | |
41 | #undef SetForm | |
42 | #endif | |
43 | ||
42cf5bc1 | 44 | //! Defines a non-persistent transformation in 3D space. |
45 | //! The following transformations are implemented : | |
46 | //! . Translation, Rotation, Scale | |
47 | //! . Symmetry with respect to a point, a line, a plane. | |
48 | //! Complex transformations can be obtained by combining the | |
49 | //! previous elementary transformations using the method | |
50 | //! Multiply. | |
51 | //! The transformations can be represented as follow : | |
52 | //! | |
53 | //! V1 V2 V3 T XYZ XYZ | |
54 | //! | a11 a12 a13 a14 | | x | | x'| | |
55 | //! | a21 a22 a23 a24 | | y | | y'| | |
56 | //! | a31 a32 a33 a34 | | z | = | z'| | |
57 | //! | 0 0 0 1 | | 1 | | 1 | | |
58 | //! | |
59 | //! where {V1, V2, V3} defines the vectorial part of the | |
60 | //! transformation and T defines the translation part of the | |
61 | //! transformation. | |
62 | //! This transformation never change the nature of the objects. | |
63 | class gp_Trsf | |
64 | { | |
65 | public: | |
66 | ||
67 | DEFINE_STANDARD_ALLOC | |
68 | ||
69 | ||
70 | //! Returns the identity transformation. | |
71 | gp_Trsf(); | |
72 | ||
73 | //! Creates a 3D transformation from the 2D transformation T. | |
74 | //! The resulting transformation has a homogeneous | |
75 | //! vectorial part, V3, and a translation part, T3, built from T: | |
76 | //! a11 a12 | |
77 | //! 0 a13 | |
78 | //! V3 = a21 a22 0 T3 | |
79 | //! = a23 | |
80 | //! 0 0 1. | |
81 | //! 0 | |
82 | //! It also has the same scale factor as T. This | |
83 | //! guarantees (by projection) that the transformation | |
84 | //! which would be performed by T in a plane (2D space) | |
85 | //! is performed by the resulting transformation in the xOy | |
86 | //! plane of the 3D space, (i.e. in the plane defined by the | |
87 | //! origin (0., 0., 0.) and the vectors DX (1., 0., 0.), and DY | |
88 | //! (0., 1., 0.)). The scale factor is applied to the entire space. | |
89 | Standard_EXPORT gp_Trsf(const gp_Trsf2d& T); | |
90 | ||
91 | ||
92 | //! Makes the transformation into a symmetrical transformation. | |
93 | //! P is the center of the symmetry. | |
94 | void SetMirror (const gp_Pnt& P); | |
95 | ||
96 | ||
97 | //! Makes the transformation into a symmetrical transformation. | |
98 | //! A1 is the center of the axial symmetry. | |
99 | Standard_EXPORT void SetMirror (const gp_Ax1& A1); | |
100 | ||
101 | ||
102 | //! Makes the transformation into a symmetrical transformation. | |
103 | //! A2 is the center of the planar symmetry | |
104 | //! and defines the plane of symmetry by its origin, "X | |
105 | //! Direction" and "Y Direction". | |
106 | Standard_EXPORT void SetMirror (const gp_Ax2& A2); | |
107 | ||
108 | ||
109 | //! Changes the transformation into a rotation. | |
110 | //! A1 is the rotation axis and Ang is the angular value of the | |
111 | //! rotation in radians. | |
112 | Standard_EXPORT void SetRotation (const gp_Ax1& A1, const Standard_Real Ang); | |
113 | ||
114 | ||
115 | //! Changes the transformation into a rotation defined by quaternion. | |
116 | //! Note that rotation is performed around origin, i.e. | |
117 | //! no translation is involved. | |
118 | Standard_EXPORT void SetRotation (const gp_Quaternion& R); | |
119 | ||
120 | ||
121 | //! Changes the transformation into a scale. | |
122 | //! P is the center of the scale and S is the scaling value. | |
123 | //! Raises ConstructionError If <S> is null. | |
124 | Standard_EXPORT void SetScale (const gp_Pnt& P, const Standard_Real S); | |
125 | ||
126 | ||
127 | //! Modifies this transformation so that it transforms the | |
128 | //! coordinate system defined by FromSystem1 into the | |
129 | //! one defined by ToSystem2. After this modification, this | |
130 | //! transformation transforms: | |
131 | //! - the origin of FromSystem1 into the origin of ToSystem2, | |
132 | //! - the "X Direction" of FromSystem1 into the "X | |
133 | //! Direction" of ToSystem2, | |
134 | //! - the "Y Direction" of FromSystem1 into the "Y | |
135 | //! Direction" of ToSystem2, and | |
136 | //! - the "main Direction" of FromSystem1 into the "main | |
137 | //! Direction" of ToSystem2. | |
138 | //! Warning | |
139 | //! When you know the coordinates of a point in one | |
140 | //! coordinate system and you want to express these | |
141 | //! coordinates in another one, do not use the | |
142 | //! transformation resulting from this function. Use the | |
143 | //! transformation that results from SetTransformation instead. | |
144 | //! SetDisplacement and SetTransformation create | |
145 | //! related transformations: the vectorial part of one is the | |
146 | //! inverse of the vectorial part of the other. | |
147 | Standard_EXPORT void SetDisplacement (const gp_Ax3& FromSystem1, const gp_Ax3& ToSystem2); | |
148 | ||
149 | //! Modifies this transformation so that it transforms the | |
150 | //! coordinates of any point, (x, y, z), relative to a source | |
151 | //! coordinate system into the coordinates (x', y', z') which | |
152 | //! are relative to a target coordinate system, but which | |
153 | //! represent the same point | |
154 | //! The transformation is from the coordinate | |
155 | //! system "FromSystem1" to the coordinate system "ToSystem2". | |
156 | //! Example : | |
157 | //! In a C++ implementation : | |
158 | //! Real x1, y1, z1; // are the coordinates of a point in the | |
159 | //! // local system FromSystem1 | |
160 | //! Real x2, y2, z2; // are the coordinates of a point in the | |
161 | //! // local system ToSystem2 | |
162 | //! gp_Pnt P1 (x1, y1, z1) | |
163 | //! Trsf T; | |
164 | //! T.SetTransformation (FromSystem1, ToSystem2); | |
165 | //! gp_Pnt P2 = P1.Transformed (T); | |
166 | //! P2.Coord (x2, y2, z2); | |
167 | Standard_EXPORT void SetTransformation (const gp_Ax3& FromSystem1, const gp_Ax3& ToSystem2); | |
168 | ||
169 | //! Modifies this transformation so that it transforms the | |
170 | //! coordinates of any point, (x, y, z), relative to a source | |
171 | //! coordinate system into the coordinates (x', y', z') which | |
172 | //! are relative to a target coordinate system, but which | |
173 | //! represent the same point | |
174 | //! The transformation is from the default coordinate system | |
175 | //! {P(0.,0.,0.), VX (1.,0.,0.), VY (0.,1.,0.), VZ (0., 0. ,1.) } | |
176 | //! to the local coordinate system defined with the Ax3 ToSystem. | |
177 | //! Use in the same way as the previous method. FromSystem1 is | |
178 | //! defaulted to the absolute coordinate system. | |
179 | Standard_EXPORT void SetTransformation (const gp_Ax3& ToSystem); | |
180 | ||
181 | ||
182 | //! Sets transformation by directly specified rotation and translation. | |
183 | Standard_EXPORT void SetTransformation (const gp_Quaternion& R, const gp_Vec& T); | |
184 | ||
185 | ||
186 | //! Changes the transformation into a translation. | |
187 | //! V is the vector of the translation. | |
188 | void SetTranslation (const gp_Vec& V); | |
189 | ||
190 | ||
191 | //! Makes the transformation into a translation where the translation vector | |
192 | //! is the vector (P1, P2) defined from point P1 to point P2. | |
193 | void SetTranslation (const gp_Pnt& P1, const gp_Pnt& P2); | |
194 | ||
195 | //! Replaces the translation vector with the vector V. | |
196 | Standard_EXPORT void SetTranslationPart (const gp_Vec& V); | |
197 | ||
198 | //! Modifies the scale factor. | |
199 | //! Raises ConstructionError If S is null. | |
200 | Standard_EXPORT void SetScaleFactor (const Standard_Real S); | |
201 | ||
be5c3602 | 202 | void SetForm (const gp_TrsfForm P); |
42cf5bc1 | 203 | |
204 | //! Sets the coefficients of the transformation. The | |
205 | //! transformation of the point x,y,z is the point | |
206 | //! x',y',z' with : | |
207 | //! | |
208 | //! x' = a11 x + a12 y + a13 z + a14 | |
209 | //! y' = a21 x + a22 y + a23 z + a24 | |
210 | //! z' = a31 x + a32 y + a33 z + a34 | |
211 | //! | |
212 | //! The method Value(i,j) will return aij. | |
213 | //! Raises ConstructionError if the determinant of the aij is null. | |
214 | //! The matrix is orthogonalized before future using. | |
215 | 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 | ||
217 | //! Returns true if the determinant of the vectorial part of | |
218 | //! this transformation is negative. | |
219 | Standard_Boolean IsNegative() const; | |
220 | ||
221 | ||
222 | //! Returns the nature of the transformation. It can be: an | |
223 | //! identity transformation, a rotation, a translation, a mirror | |
224 | //! transformation (relative to a point, an axis or a plane), a | |
225 | //! scaling transformation, or a compound transformation. | |
226 | gp_TrsfForm Form() const; | |
227 | ||
228 | //! Returns the scale factor. | |
229 | Standard_Real ScaleFactor() const; | |
230 | ||
231 | ||
232 | //! Returns the translation part of the transformation's matrix | |
233 | const gp_XYZ& TranslationPart() const; | |
234 | ||
235 | ||
236 | //! Returns the boolean True if there is non-zero rotation. | |
237 | //! In the presence of rotation, the output parameters store the axis | |
238 | //! and the angle of rotation. The method always returns positive | |
239 | //! value "theAngle", i.e., 0. < theAngle <= PI. | |
240 | //! Note that this rotation is defined only by the vectorial part of | |
241 | //! the transformation; generally you would need to check also the | |
242 | //! translational part to obtain the axis (gp_Ax1) of rotation. | |
243 | Standard_EXPORT Standard_Boolean GetRotation (gp_XYZ& theAxis, Standard_Real& theAngle) const; | |
244 | ||
245 | ||
246 | //! Returns quaternion representing rotational part of the transformation. | |
247 | Standard_EXPORT gp_Quaternion GetRotation() const; | |
248 | ||
249 | ||
250 | //! Returns the vectorial part of the transformation. It is | |
251 | //! a 3*3 matrix which includes the scale factor. | |
252 | Standard_EXPORT gp_Mat VectorialPart() const; | |
253 | ||
254 | ||
255 | //! Computes the homogeneous vectorial part of the transformation. | |
256 | //! It is a 3*3 matrix which doesn't include the scale factor. | |
257 | //! In other words, the vectorial part of this transformation is equal | |
258 | //! to its homogeneous vectorial part, multiplied by the scale factor. | |
259 | //! The coefficients of this matrix must be multiplied by the | |
260 | //! scale factor to obtain the coefficients of the transformation. | |
261 | const gp_Mat& HVectorialPart() const; | |
262 | ||
263 | ||
264 | //! Returns the coefficients of the transformation's matrix. | |
265 | //! It is a 3 rows * 4 columns matrix. | |
266 | //! This coefficient includes the scale factor. | |
267 | //! Raises OutOfRanged if Row < 1 or Row > 3 or Col < 1 or Col > 4 | |
268 | Standard_Real Value (const Standard_Integer Row, const Standard_Integer Col) const; | |
269 | ||
270 | Standard_EXPORT void Invert(); | |
271 | ||
272 | ||
273 | //! Computes the reverse transformation | |
274 | //! Raises an exception if the matrix of the transformation | |
275 | //! is not inversible, it means that the scale factor is lower | |
276 | //! or equal to Resolution from package gp. | |
277 | //! Computes the transformation composed with T and <me>. | |
278 | //! In a C++ implementation you can also write Tcomposed = <me> * T. | |
279 | //! Example : | |
280 | //! Trsf T1, T2, Tcomp; ............... | |
281 | //! Tcomp = T2.Multiplied(T1); // or (Tcomp = T2 * T1) | |
282 | //! Pnt P1(10.,3.,4.); | |
283 | //! Pnt P2 = P1.Transformed(Tcomp); //using Tcomp | |
284 | //! Pnt P3 = P1.Transformed(T1); //using T1 then T2 | |
285 | //! P3.Transform(T2); // P3 = P2 !!! | |
0be7dbe1 | 286 | Standard_NODISCARD gp_Trsf Inverted() const; |
42cf5bc1 | 287 | |
0be7dbe1 BB |
288 | Standard_NODISCARD gp_Trsf Multiplied (const gp_Trsf& T) const; |
289 | Standard_NODISCARD gp_Trsf operator * (const gp_Trsf& T) const | |
42cf5bc1 | 290 | { |
291 | return Multiplied(T); | |
292 | } | |
293 | ||
294 | ||
295 | //! Computes the transformation composed with <me> and T. | |
296 | //! <me> = <me> * T | |
297 | Standard_EXPORT void Multiply (const gp_Trsf& T); | |
298 | void operator *= (const gp_Trsf& T) | |
299 | { | |
300 | Multiply(T); | |
301 | } | |
302 | ||
303 | ||
304 | //! Computes the transformation composed with <me> and T. | |
305 | //! <me> = T * <me> | |
306 | Standard_EXPORT void PreMultiply (const gp_Trsf& T); | |
307 | ||
308 | Standard_EXPORT void Power (const Standard_Integer N); | |
309 | ||
310 | ||
311 | //! Computes the following composition of transformations | |
312 | //! <me> * <me> * .......* <me>, N time. | |
313 | //! if N = 0 <me> = Identity | |
314 | //! if N < 0 <me> = <me>.Inverse() *...........* <me>.Inverse(). | |
315 | //! | |
316 | //! Raises if N < 0 and if the matrix of the transformation not | |
317 | //! inversible. | |
0be7dbe1 | 318 | Standard_NODISCARD gp_Trsf Powered (const Standard_Integer N) const; |
42cf5bc1 | 319 | |
320 | void Transforms (Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const; | |
321 | ||
322 | //! Transformation of a triplet XYZ with a Trsf | |
323 | void Transforms (gp_XYZ& Coord) const; | |
324 | ||
1f7f5a90 | 325 | //! Convert transformation to 4x4 matrix. |
326 | template<class T> | |
327 | void GetMat4 (NCollection_Mat4<T>& theMat) const | |
328 | { | |
329 | if (shape == gp_Identity) | |
330 | { | |
331 | theMat.InitIdentity(); | |
332 | return; | |
333 | } | |
334 | ||
335 | theMat.SetValue (0, 0, static_cast<T> (Value (1, 1))); | |
336 | theMat.SetValue (0, 1, static_cast<T> (Value (1, 2))); | |
337 | theMat.SetValue (0, 2, static_cast<T> (Value (1, 3))); | |
338 | theMat.SetValue (0, 3, static_cast<T> (Value (1, 4))); | |
339 | theMat.SetValue (1, 0, static_cast<T> (Value (2, 1))); | |
340 | theMat.SetValue (1, 1, static_cast<T> (Value (2, 2))); | |
341 | theMat.SetValue (1, 2, static_cast<T> (Value (2, 3))); | |
342 | theMat.SetValue (1, 3, static_cast<T> (Value (2, 4))); | |
343 | theMat.SetValue (2, 0, static_cast<T> (Value (3, 1))); | |
344 | theMat.SetValue (2, 1, static_cast<T> (Value (3, 2))); | |
345 | theMat.SetValue (2, 2, static_cast<T> (Value (3, 3))); | |
346 | theMat.SetValue (2, 3, static_cast<T> (Value (3, 4))); | |
347 | theMat.SetValue (3, 0, static_cast<T> (0)); | |
348 | theMat.SetValue (3, 1, static_cast<T> (0)); | |
349 | theMat.SetValue (3, 2, static_cast<T> (0)); | |
350 | theMat.SetValue (3, 3, static_cast<T> (1)); | |
351 | } | |
42cf5bc1 | 352 | |
0904aa63 | 353 | //! Dumps the content of me into the stream |
354 | Standard_EXPORT void DumpJson (Standard_OStream& theOStream, const Standard_Integer theDepth = -1) const; | |
355 | ||
42cf5bc1 | 356 | friend class gp_GTrsf; |
357 | ||
42cf5bc1 | 358 | protected: |
359 | ||
42cf5bc1 | 360 | //! Makes orthogonalization of "matrix" |
361 | Standard_EXPORT void Orthogonalize(); | |
362 | ||
42cf5bc1 | 363 | private: |
364 | ||
42cf5bc1 | 365 | Standard_Real scale; |
366 | gp_TrsfForm shape; | |
367 | gp_Mat matrix; | |
368 | gp_XYZ loc; | |
369 | ||
42cf5bc1 | 370 | }; |
371 | ||
42cf5bc1 | 372 | #include <gp_Trsf.lxx> |
373 | ||
42cf5bc1 | 374 | #endif // _gp_Trsf_HeaderFile |