|
||||
File indexing completed on 2025-01-18 10:03:45
0001 // Copyright (c) 1991-1999 Matra Datavision 0002 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0003 // 0004 // This file is part of Open CASCADE Technology software library. 0005 // 0006 // This library is free software; you can redistribute it and/or modify it under 0007 // the terms of the GNU Lesser General Public License version 2.1 as published 0008 // by the Free Software Foundation, with special exception defined in the file 0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0010 // distribution for complete text of the license and disclaimer of any warranty. 0011 // 0012 // Alternatively, this file may be used under the terms of Open CASCADE 0013 // commercial license or contractual agreement. 0014 0015 #ifndef _gp_Trsf2d_HeaderFile 0016 #define _gp_Trsf2d_HeaderFile 0017 0018 #include <gp_TrsfForm.hxx> 0019 #include <gp_Mat2d.hxx> 0020 #include <gp_XY.hxx> 0021 #include <Standard_OutOfRange.hxx> 0022 0023 class gp_Trsf; 0024 class gp_Pnt2d; 0025 class gp_Ax2d; 0026 class gp_Vec2d; 0027 0028 //! Defines a non-persistent transformation in 2D space. 0029 //! The following transformations are implemented : 0030 //! - Translation, Rotation, Scale 0031 //! - Symmetry with respect to a point and a line. 0032 //! Complex transformations can be obtained by combining the 0033 //! previous elementary transformations using the method Multiply. 0034 //! The transformations can be represented as follow : 0035 //! @code 0036 //! V1 V2 T XY XY 0037 //! | a11 a12 a13 | | x | | x'| 0038 //! | a21 a22 a23 | | y | | y'| 0039 //! | 0 0 1 | | 1 | | 1 | 0040 //! @endcode 0041 //! where {V1, V2} defines the vectorial part of the transformation 0042 //! and T defines the translation part of the transformation. 0043 //! This transformation never change the nature of the objects. 0044 class gp_Trsf2d 0045 { 0046 public: 0047 0048 DEFINE_STANDARD_ALLOC 0049 0050 //! Returns identity transformation. 0051 gp_Trsf2d(); 0052 0053 //! Creates a 2d transformation in the XY plane from a 0054 //! 3d transformation . 0055 gp_Trsf2d (const gp_Trsf& theT); 0056 0057 //! Changes the transformation into a symmetrical transformation. 0058 //! theP is the center of the symmetry. 0059 void SetMirror (const gp_Pnt2d& theP); 0060 0061 //! Changes the transformation into a symmetrical transformation. 0062 //! theA is the center of the axial symmetry. 0063 Standard_EXPORT void SetMirror (const gp_Ax2d& theA); 0064 0065 //! Changes the transformation into a rotation. 0066 //! theP is the rotation's center and theAng is the angular value of the 0067 //! rotation in radian. 0068 void SetRotation (const gp_Pnt2d& theP, const Standard_Real theAng); 0069 0070 //! Changes the transformation into a scale. 0071 //! theP is the center of the scale and theS is the scaling value. 0072 void SetScale (const gp_Pnt2d& theP, const Standard_Real theS); 0073 0074 //! Changes a transformation allowing passage from the coordinate 0075 //! system "theFromSystem1" to the coordinate system "theToSystem2". 0076 Standard_EXPORT void SetTransformation (const gp_Ax2d& theFromSystem1, const gp_Ax2d& theToSystem2); 0077 0078 //! Changes the transformation allowing passage from the basic 0079 //! coordinate system 0080 //! {P(0.,0.,0.), VX (1.,0.,0.), VY (0.,1.,0.)} 0081 //! to the local coordinate system defined with the Ax2d theToSystem. 0082 Standard_EXPORT void SetTransformation (const gp_Ax2d& theToSystem); 0083 0084 //! Changes the transformation into a translation. 0085 //! theV is the vector of the translation. 0086 void SetTranslation (const gp_Vec2d& theV); 0087 0088 //! Makes the transformation into a translation from 0089 //! the point theP1 to the point theP2. 0090 void SetTranslation (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2); 0091 0092 //! Replaces the translation vector with theV. 0093 Standard_EXPORT void SetTranslationPart (const gp_Vec2d& theV); 0094 0095 //! Modifies the scale factor. 0096 Standard_EXPORT void SetScaleFactor (const Standard_Real theS); 0097 0098 //! Returns true if the determinant of the vectorial part of 0099 //! this transformation is negative.. 0100 Standard_Boolean IsNegative() const { return (matrix.Determinant() < 0.0); } 0101 0102 //! Returns the nature of the transformation. It can be an 0103 //! identity transformation, a rotation, a translation, a mirror 0104 //! (relative to a point or an axis), a scaling transformation, 0105 //! or a compound transformation. 0106 gp_TrsfForm Form() const { return shape; } 0107 0108 //! Returns the scale factor. 0109 Standard_Real ScaleFactor() const { return scale; } 0110 0111 //! Returns the translation part of the transformation's matrix 0112 const gp_XY& TranslationPart() const { return loc; } 0113 0114 //! Returns the vectorial part of the transformation. It is a 0115 //! 2*2 matrix which includes the scale factor. 0116 Standard_EXPORT gp_Mat2d VectorialPart() const; 0117 0118 //! Returns the homogeneous vectorial part of the transformation. 0119 //! It is a 2*2 matrix which doesn't include the scale factor. 0120 //! The coefficients of this matrix must be multiplied by the 0121 //! scale factor to obtain the coefficients of the transformation. 0122 const gp_Mat2d& HVectorialPart() const { return matrix; } 0123 0124 //! Returns the angle corresponding to the rotational component 0125 //! of the transformation matrix (operation opposite to SetRotation()). 0126 Standard_EXPORT Standard_Real RotationPart() const; 0127 0128 //! Returns the coefficients of the transformation's matrix. 0129 //! It is a 2 rows * 3 columns matrix. 0130 //! Raises OutOfRange if theRow < 1 or theRow > 2 or theCol < 1 or theCol > 3 0131 Standard_Real Value (const Standard_Integer theRow, const Standard_Integer theCol) const; 0132 0133 Standard_EXPORT void Invert(); 0134 0135 //! Computes the reverse transformation. 0136 //! Raises an exception if the matrix of the transformation 0137 //! is not inversible, it means that the scale factor is lower 0138 //! or equal to Resolution from package gp. 0139 Standard_NODISCARD gp_Trsf2d Inverted() const 0140 { 0141 gp_Trsf2d aT = *this; 0142 aT.Invert(); 0143 return aT; 0144 } 0145 0146 Standard_NODISCARD gp_Trsf2d Multiplied (const gp_Trsf2d& theT) const 0147 { 0148 gp_Trsf2d aTresult (*this); 0149 aTresult.Multiply (theT); 0150 return aTresult; 0151 } 0152 0153 Standard_NODISCARD gp_Trsf2d operator * (const gp_Trsf2d& theT) const { return Multiplied (theT); } 0154 0155 //! Computes the transformation composed from <me> and theT. 0156 //! <me> = <me> * theT 0157 Standard_EXPORT void Multiply (const gp_Trsf2d& theT); 0158 0159 void operator *= (const gp_Trsf2d& theT) { Multiply (theT); } 0160 0161 //! Computes the transformation composed from <me> and theT. 0162 //! <me> = theT * <me> 0163 Standard_EXPORT void PreMultiply (const gp_Trsf2d& theT); 0164 0165 Standard_EXPORT void Power (const Standard_Integer theN); 0166 0167 //! Computes the following composition of transformations 0168 //! <me> * <me> * .......* <me>, theN time. 0169 //! if theN = 0 <me> = Identity 0170 //! if theN < 0 <me> = <me>.Inverse() *...........* <me>.Inverse(). 0171 //! 0172 //! Raises if theN < 0 and if the matrix of the transformation not 0173 //! inversible. 0174 gp_Trsf2d Powered (const Standard_Integer theN) 0175 { 0176 gp_Trsf2d aT = *this; 0177 aT.Power (theN); 0178 return aT; 0179 } 0180 0181 void Transforms (Standard_Real& theX, Standard_Real& theY) const; 0182 0183 //! Transforms a doublet XY with a Trsf2d 0184 void Transforms (gp_XY& theCoord) const; 0185 0186 //! Sets the coefficients of the transformation. The 0187 //! transformation of the point x,y is the point 0188 //! x',y' with : 0189 //! @code 0190 //! x' = a11 x + a12 y + a13 0191 //! y' = a21 x + a22 y + a23 0192 //! @endcode 0193 //! The method Value(i,j) will return aij. 0194 //! Raises ConstructionError if the determinant of the aij is null. 0195 //! If the matrix as not a uniform scale it will be orthogonalized before future using. 0196 Standard_EXPORT void SetValues (const Standard_Real a11, const Standard_Real a12, const Standard_Real a13, const Standard_Real a21, const Standard_Real a22, const Standard_Real a23); 0197 0198 friend class gp_GTrsf2d; 0199 0200 protected: 0201 0202 //! Makes orthogonalization of "matrix" 0203 Standard_EXPORT void Orthogonalize(); 0204 0205 private: 0206 0207 Standard_Real scale; 0208 gp_TrsfForm shape; 0209 gp_Mat2d matrix; 0210 gp_XY loc; 0211 0212 }; 0213 0214 #include <gp_Trsf.hxx> 0215 #include <gp_Pnt2d.hxx> 0216 0217 //======================================================================= 0218 //function : gp_Trsf2d 0219 // purpose : 0220 //======================================================================= 0221 inline gp_Trsf2d::gp_Trsf2d() 0222 { 0223 shape = gp_Identity; 0224 scale = 1.0; 0225 matrix.SetIdentity(); 0226 loc.SetCoord (0.0, 0.0); 0227 } 0228 0229 //======================================================================= 0230 //function : gp_Trsf2d 0231 // purpose : 0232 //======================================================================= 0233 inline gp_Trsf2d::gp_Trsf2d (const gp_Trsf& theT) 0234 : scale (theT.ScaleFactor()), 0235 shape (theT.Form()), 0236 loc (theT.TranslationPart().X(), theT.TranslationPart().Y()) 0237 { 0238 const gp_Mat& M = theT.HVectorialPart(); 0239 matrix(1,1) = M(1,1); 0240 matrix(1,2) = M(1,2); 0241 matrix(2,1) = M(2,1); 0242 matrix(2,2) = M(2,2); 0243 } 0244 0245 //======================================================================= 0246 //function : SetRotation 0247 // purpose : 0248 //======================================================================= 0249 inline void gp_Trsf2d::SetRotation (const gp_Pnt2d& theP, 0250 const Standard_Real theAng) 0251 { 0252 shape = gp_Rotation; 0253 scale = 1.0; 0254 loc = theP.XY (); 0255 loc.Reverse (); 0256 matrix.SetRotation (theAng); 0257 loc.Multiply (matrix); 0258 loc.Add (theP.XY()); 0259 } 0260 0261 //======================================================================= 0262 //function : SetMirror 0263 // purpose : 0264 //======================================================================= 0265 inline void gp_Trsf2d::SetMirror (const gp_Pnt2d& theP) 0266 { 0267 shape = gp_PntMirror; 0268 scale = -1.0; 0269 matrix.SetIdentity(); 0270 loc = theP.XY(); 0271 loc.Multiply (2.0); 0272 } 0273 0274 //======================================================================= 0275 //function : SetScale 0276 // purpose : 0277 //======================================================================= 0278 inline void gp_Trsf2d::SetScale (const gp_Pnt2d& theP, const Standard_Real theS) 0279 { 0280 shape = gp_Scale; 0281 scale = theS; 0282 matrix.SetIdentity(); 0283 loc = theP.XY(); 0284 loc.Multiply (1.0 - theS); 0285 } 0286 0287 //======================================================================= 0288 //function : SetTranslation 0289 // purpose : 0290 //======================================================================= 0291 inline void gp_Trsf2d::SetTranslation (const gp_Vec2d& theV) 0292 { 0293 shape = gp_Translation; 0294 scale = 1.0; 0295 matrix.SetIdentity(); 0296 loc = theV.XY(); 0297 } 0298 0299 //======================================================================= 0300 //function : SetTranslation 0301 // purpose : 0302 //======================================================================= 0303 inline void gp_Trsf2d::SetTranslation (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) 0304 { 0305 shape = gp_Translation; 0306 scale = 1.0; 0307 matrix.SetIdentity(); 0308 loc = (theP2.XY()).Subtracted (theP1.XY()); 0309 } 0310 0311 //======================================================================= 0312 //function : Value 0313 // purpose : 0314 //======================================================================= 0315 inline Standard_Real gp_Trsf2d::Value (const Standard_Integer theRow, const Standard_Integer theCol) const 0316 { 0317 Standard_OutOfRange_Raise_if (theRow < 1 || theRow > 2 || theCol < 1 || theCol > 3, " "); 0318 if (theCol < 3) 0319 { 0320 return scale * matrix.Value (theRow, theCol); 0321 } 0322 else 0323 { 0324 return loc.Coord (theRow); 0325 } 0326 } 0327 0328 //======================================================================= 0329 //function : Transforms 0330 // purpose : 0331 //======================================================================= 0332 inline void gp_Trsf2d::Transforms (Standard_Real& theX, Standard_Real& theY) const 0333 { 0334 gp_XY aDoublet(theX, theY); 0335 aDoublet.Multiply (matrix); 0336 if (scale != 1.0) 0337 { 0338 aDoublet.Multiply (scale); 0339 } 0340 aDoublet.Add (loc); 0341 aDoublet.Coord (theX, theY); 0342 } 0343 0344 //======================================================================= 0345 //function : Transforms 0346 // purpose : 0347 //======================================================================= 0348 inline void gp_Trsf2d::Transforms (gp_XY& theCoord) const 0349 { 0350 theCoord.Multiply (matrix); 0351 if (scale != 1.0) 0352 { 0353 theCoord.Multiply (scale); 0354 } 0355 theCoord.Add (loc); 0356 } 0357 0358 #endif // _gp_Trsf2d_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |