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_GTrsf_HeaderFile
16 #define _gp_GTrsf_HeaderFile
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
24 #include <gp_TrsfForm.hxx>
25 #include <Standard_Real.hxx>
26 #include <Standard_Integer.hxx>
27 #include <Standard_Boolean.hxx>
28 #include <gp_Trsf.hxx>
29 class Standard_ConstructionError;
30 class Standard_OutOfRange;
37 // Avoid possible conflict with SetForm macro defined by windows.h
42 //! Defines a non-persistent transformation in 3D space.
43 //! This transformation is a general transformation.
44 //! It can be a Trsf from gp, an affinity, or you can define
45 //! your own transformation giving the matrix of transformation.
47 //! With a Gtrsf you can transform only a triplet of coordinates
48 //! XYZ. It is not possible to transform other geometric objects
49 //! because these transformations can change the nature of non-
50 //! elementary geometric objects.
51 //! The transformation GTrsf can be represented as follow :
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 |
59 //! where {V1, V2, V3} define the vectorial part of the
60 //! transformation and T defines the translation part of the
63 //! A GTrsf transformation is only applicable to
64 //! coordinates. Be careful if you apply such a
65 //! transformation to all points of a geometric object, as
66 //! this can change the nature of the object and thus
67 //! render it incoherent!
68 //! Typically, a circle is transformed into an ellipse by an
69 //! affinity transformation. To avoid modifying the nature of
70 //! an object, use a gp_Trsf transformation instead, as
71 //! objects of this class respect the nature of geometric objects.
79 //! Returns the Identity transformation.
83 //! Converts the gp_Trsf transformation T into a
84 //! general transformation, i.e. Returns a GTrsf with
85 //! the same matrix of coefficients as the Trsf T.
86 gp_GTrsf(const gp_Trsf& T);
89 //! Creates a transformation based on the matrix M and the
90 //! vector V where M defines the vectorial part of
91 //! the transformation, and V the translation part, or
92 gp_GTrsf(const gp_Mat& M, const gp_XYZ& V);
94 //! Changes this transformation into an affinity of ratio Ratio
95 //! with respect to the axis A1.
96 //! Note: an affinity is a point-by-point transformation that
97 //! transforms any point P into a point P' such that if H is
98 //! the orthogonal projection of P on the axis A1 or the
99 //! plane A2, the vectors HP and HP' satisfy:
100 //! HP' = Ratio * HP.
101 void SetAffinity (const gp_Ax1& A1, const Standard_Real Ratio);
103 //! Changes this transformation into an affinity of ratio Ratio
104 //! with respect to the plane defined by the origin, the "X Direction" and
105 //! the "Y Direction" of coordinate system A2.
106 //! Note: an affinity is a point-by-point transformation that
107 //! transforms any point P into a point P' such that if H is
108 //! the orthogonal projection of P on the axis A1 or the
109 //! plane A2, the vectors HP and HP' satisfy:
110 //! HP' = Ratio * HP.
111 void SetAffinity (const gp_Ax2& A2, const Standard_Real Ratio);
114 //! Replaces the coefficient (Row, Col) of the matrix representing
115 //! this transformation by Value. Raises OutOfRange
116 //! if Row < 1 or Row > 3 or Col < 1 or Col > 4
117 void SetValue (const Standard_Integer Row, const Standard_Integer Col, const Standard_Real Value);
119 //! Replaces the vectorial part of this transformation by Matrix.
120 void SetVectorialPart (const gp_Mat& Matrix);
122 //! Replaces the translation part of
123 //! this transformation by the coordinates of the number triple Coord.
124 Standard_EXPORT void SetTranslationPart (const gp_XYZ& Coord);
126 //! Assigns the vectorial and translation parts of T to this transformation.
127 void SetTrsf (const gp_Trsf& T);
130 //! Returns true if the determinant of the vectorial part of
131 //! this transformation is negative.
132 Standard_Boolean IsNegative() const;
135 //! Returns true if this transformation is singular (and
136 //! therefore, cannot be inverted).
137 //! Note: The Gauss LU decomposition is used to invert the
138 //! transformation matrix. Consequently, the transformation
139 //! is considered as singular if the largest pivot found is less
140 //! than or equal to gp::Resolution().
142 //! If this transformation is singular, it cannot be inverted.
143 Standard_Boolean IsSingular() const;
146 //! Returns the nature of the transformation. It can be an
147 //! identity transformation, a rotation, a translation, a mirror
148 //! transformation (relative to a point, an axis or a plane), a
149 //! scaling transformation, a compound transformation or
150 //! some other type of transformation.
151 gp_TrsfForm Form() const;
154 //! verify and set the shape of the GTrsf Other or CompoundTrsf
156 //! myGTrsf.SetValue(row1,col1,val1);
157 //! myGTrsf.SetValue(row2,col2,val2);
159 //! myGTrsf.SetForm();
160 Standard_EXPORT void SetForm();
162 //! Returns the translation part of the GTrsf.
163 const gp_XYZ& TranslationPart() const;
166 //! Computes the vectorial part of the GTrsf. The returned Matrix
168 const gp_Mat& VectorialPart() const;
171 //! Returns the coefficients of the global matrix of transformation.
172 //! Raises OutOfRange if Row < 1 or Row > 3 or Col < 1 or Col > 4
173 Standard_Real Value (const Standard_Integer Row, const Standard_Integer Col) const;
174 Standard_Real operator() (const Standard_Integer Row, const Standard_Integer Col) const
176 return Value(Row,Col);
179 Standard_EXPORT void Invert();
182 //! Computes the reverse transformation.
183 //! Raises an exception if the matrix of the transformation
184 //! is not inversible.
185 gp_GTrsf Inverted() const;
188 //! Computes the transformation composed from T and <me>.
189 //! In a C++ implementation you can also write Tcomposed = <me> * T.
191 //! GTrsf T1, T2, Tcomp; ...............
193 //! Tcomp = T2.Multiplied(T1); // or (Tcomp = T2 * T1)
194 //! // transformation of a point
195 //! XYZ P(10.,3.,4.);
197 //! Tcomp.Transforms(P1); //using Tcomp
199 //! T1.Transforms(P2); //using T1 then T2
200 //! T2.Transforms(P2); // P1 = P2 !!!
201 gp_GTrsf Multiplied (const gp_GTrsf& T) const;
202 gp_GTrsf operator * (const gp_GTrsf& T) const
204 return Multiplied(T);
208 //! Computes the transformation composed with <me> and T.
210 Standard_EXPORT void Multiply (const gp_GTrsf& T);
211 void operator *= (const gp_GTrsf& T)
217 //! Computes the product of the transformation T and this
218 //! transformation and assigns the result to this transformation.
220 Standard_EXPORT void PreMultiply (const gp_GTrsf& T);
222 Standard_EXPORT void Power (const Standard_Integer N);
226 //! - the product of this transformation multiplied by itself
227 //! N times, if N is positive, or
228 //! - the product of the inverse of this transformation
229 //! multiplied by itself |N| times, if N is negative.
230 //! If N equals zero, the result is equal to the Identity
232 //! I.e.: <me> * <me> * .......* <me>, N time.
233 //! if N =0 <me> = Identity
234 //! if N < 0 <me> = <me>.Inverse() *...........* <me>.Inverse().
236 //! Raises an exception if N < 0 and if the matrix of the
237 //! transformation not inversible.
238 gp_GTrsf Powered (const Standard_Integer N) const;
240 void Transforms (gp_XYZ& Coord) const;
242 //! Transforms a triplet XYZ with a GTrsf.
243 void Transforms (Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const;
245 gp_Trsf Trsf() const;
269 #include <gp_GTrsf.lxx>
275 #endif // _gp_GTrsf_HeaderFile