Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/opencascade/gp_GTrsf2d.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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_GTrsf2d_HeaderFile
0016 #define _gp_GTrsf2d_HeaderFile
0017 
0018 #include <gp_Ax2d.hxx>
0019 #include <gp_Mat2d.hxx>
0020 #include <gp_TrsfForm.hxx>
0021 #include <gp_XY.hxx>
0022 #include <Standard_OutOfRange.hxx>
0023 
0024 //! Defines a non persistent transformation in 2D space.
0025 //! This transformation is a general transformation.
0026 //! It can be a gp_Trsf2d, an affinity, or you can
0027 //! define your own transformation giving the corresponding matrix of transformation.
0028 //!
0029 //! With a gp_GTrsf2d you can transform only a doublet of coordinates gp_XY.
0030 //! It is not possible to transform other geometric objects
0031 //! because these transformations can change the nature of non-elementary geometric objects.
0032 //! A gp_GTrsf2d is represented with a 2 rows * 3 columns matrix:
0033 //! @code
0034 //!    V1   V2   T        XY         XY
0035 //! | a11  a12  a14 |   | x |      | x'|
0036 //! | a21  a22  a24 |   | y |   =  | y'|
0037 //! |  0    0    1  |   | 1 |      | 1 |
0038 //! @endcode
0039 //! where {V1, V2} defines the vectorial part of the
0040 //! transformation and T defines the translation part of the transformation.
0041 //! Warning
0042 //! A gp_GTrsf2d transformation is only applicable on coordinates.
0043 //! Be careful if you apply such a transformation to all the points of a geometric object,
0044 //! as this can change the nature of the object and thus render it incoherent!
0045 //! Typically, a circle is transformed into an ellipse by an affinity transformation.
0046 //! To avoid modifying the nature of an object, use a gp_Trsf2d transformation instead,
0047 //! as objects of this class respect the nature of geometric objects.
0048 class gp_GTrsf2d
0049 {
0050 public:
0051   DEFINE_STANDARD_ALLOC
0052 
0053   //! returns identity transformation.
0054   constexpr gp_GTrsf2d() noexcept
0055       : loc(0.0, 0.0),
0056         shape(gp_Identity),
0057         scale(1.0)
0058   {
0059     matrix.SetScale(1.0);
0060   }
0061 
0062   //! Converts the gp_Trsf2d transformation theT into a
0063   //! general transformation.
0064   gp_GTrsf2d(const gp_Trsf2d& theT);
0065 
0066   //! Creates a transformation based on the matrix theM and the
0067   //! vector theV where theM defines the vectorial part of the
0068   //! transformation, and theV the translation part.
0069   constexpr gp_GTrsf2d(const gp_Mat2d& theM, const gp_XY& theV) noexcept
0070       : matrix(theM),
0071         loc(theV),
0072         shape(gp_Other),
0073         scale(0.0)
0074   {
0075   }
0076 
0077   //! Changes this transformation into an affinity of ratio theRatio
0078   //! with respect to the axis theA.
0079   //! Note: An affinity is a point-by-point transformation that
0080   //! transforms any point P into a point P' such that if H is
0081   //! the orthogonal projection of P on the axis theA, the vectors
0082   //! HP and HP' satisfy: HP' = theRatio * HP.
0083   Standard_EXPORT void SetAffinity(const gp_Ax2d& theA, const double theRatio);
0084 
0085   //! Replaces the coefficient (theRow, theCol) of the matrix representing
0086   //! this transformation by theValue,
0087   //! Raises OutOfRange if theRow < 1 or theRow > 2 or theCol < 1 or theCol > 3
0088   void SetValue(const int theRow, const int theCol, const double theValue);
0089 
0090   //! Replaces the translation part of this
0091   //! transformation by the coordinates of the number pair theCoord.
0092   Standard_EXPORT void SetTranslationPart(const gp_XY& theCoord);
0093 
0094   //! Assigns the vectorial and translation parts of theT to this transformation.
0095   void SetTrsf2d(const gp_Trsf2d& theT);
0096 
0097   //! Replaces the vectorial part of this transformation by theMatrix.
0098   constexpr void SetVectorialPart(const gp_Mat2d& theMatrix) noexcept
0099   {
0100     matrix = theMatrix;
0101     shape  = gp_Other;
0102     scale  = 0.0;
0103   }
0104 
0105   //! Returns true if the determinant of the vectorial part of
0106   //! this transformation is negative.
0107   constexpr bool IsNegative() const noexcept { return matrix.Determinant() < 0.0; }
0108 
0109   //! Returns true if this transformation is singular (and
0110   //! therefore, cannot be inverted).
0111   //! Note: The Gauss LU decomposition is used to invert the
0112   //! transformation matrix. Consequently, the transformation
0113   //! is considered as singular if the largest pivot found is less
0114   //! than or equal to gp::Resolution().
0115   //! Warning
0116   //! If this transformation is singular, it cannot be inverted.
0117   constexpr bool IsSingular() const noexcept { return matrix.IsSingular(); }
0118 
0119   //! Returns the nature of the transformation. It can be
0120   //! an identity transformation, a rotation, a translation, a mirror
0121   //! transformation (relative to a point or axis), a scaling
0122   //! transformation, a compound transformation or some
0123   //! other type of transformation.
0124   constexpr gp_TrsfForm Form() const noexcept { return shape; }
0125 
0126   //! Returns the translation part of the GTrsf2d.
0127   constexpr const gp_XY& TranslationPart() const noexcept { return loc; }
0128 
0129   //! Computes the vectorial part of the GTrsf2d. The returned
0130   //! Matrix is a 2*2 matrix.
0131   constexpr const gp_Mat2d& VectorialPart() const noexcept { return matrix; }
0132 
0133   //! Returns the coefficients of the global matrix of transformation.
0134   //! Raised OutOfRange if theRow < 1 or theRow > 2 or theCol < 1 or theCol > 3
0135   constexpr double Value(const int theRow, const int theCol) const;
0136 
0137   double operator()(const int theRow, const int theCol) const { return Value(theRow, theCol); }
0138 
0139   Standard_EXPORT void Invert();
0140 
0141   //! Computes the reverse transformation.
0142   //! Raised an exception if the matrix of the transformation
0143   //! is not inversible.
0144   [[nodiscard]] gp_GTrsf2d Inverted() const
0145   {
0146     gp_GTrsf2d aT = *this;
0147     aT.Invert();
0148     return aT;
0149   }
0150 
0151   //! Computes the transformation composed with theT and <me>.
0152   //! In a C++ implementation you can also write Tcomposed = <me> * theT.
0153   //! Example :
0154   //! @code
0155   //! gp_GTrsf2d T1, T2, Tcomp; ...............
0156   //! //composition :
0157   //! Tcomp = T2.Multiplied(T1);         // or   (Tcomp = T2 * T1)
0158   //! // transformation of a point
0159   //! gp_XY P(10.,3.);
0160   //! gp_XY P1(P);
0161   //! Tcomp.Transforms(P1);               //using Tcomp
0162   //! gp_XY P2(P);
0163   //! T1.Transforms(P2);                  //using T1 then T2
0164   //! T2.Transforms(P2);                  // P1 = P2 !!!
0165   //! @endcode
0166   [[nodiscard]] gp_GTrsf2d Multiplied(const gp_GTrsf2d& theT) const
0167   {
0168     gp_GTrsf2d aTres = *this;
0169     aTres.Multiply(theT);
0170     return aTres;
0171   }
0172 
0173   [[nodiscard]] gp_GTrsf2d operator*(const gp_GTrsf2d& theT) const { return Multiplied(theT); }
0174 
0175   Standard_EXPORT void Multiply(const gp_GTrsf2d& theT);
0176 
0177   void operator*=(const gp_GTrsf2d& theT) { Multiply(theT); }
0178 
0179   //! Computes the product of the transformation theT and this
0180   //! transformation, and assigns the result to this transformation:
0181   //! this = theT * this
0182   Standard_EXPORT void PreMultiply(const gp_GTrsf2d& theT);
0183 
0184   Standard_EXPORT void Power(const int theN);
0185 
0186   //! Computes the following composition of transformations
0187   //! <me> * <me> * .......* <me>, theN time.
0188   //! if theN = 0 <me> = Identity
0189   //! if theN < 0 <me> = <me>.Inverse() *...........* <me>.Inverse().
0190   //!
0191   //! Raises an exception if theN < 0 and if the matrix of the
0192   //! transformation is not inversible.
0193   [[nodiscard]] gp_GTrsf2d Powered(const int theN) const
0194   {
0195     gp_GTrsf2d aT = *this;
0196     aT.Power(theN);
0197     return aT;
0198   }
0199 
0200   constexpr void Transforms(gp_XY& theCoord) const noexcept;
0201 
0202   [[nodiscard]] constexpr gp_XY Transformed(const gp_XY& theCoord) const noexcept
0203   {
0204     gp_XY aNewCoord = theCoord;
0205     Transforms(aNewCoord);
0206     return aNewCoord;
0207   }
0208 
0209   //! Applies this transformation to the coordinates:
0210   //! -   of the number pair Coord, or
0211   //! -   X and Y.
0212   //!
0213   //! Note:
0214   //! -   Transforms modifies theX, theY, or the coordinate pair Coord, while
0215   //! -   Transformed creates a new coordinate pair.
0216   constexpr void Transforms(double& theX, double& theY) const noexcept;
0217 
0218   //! Converts this transformation into a gp_Trsf2d transformation.
0219   //! Exceptions
0220   //! Standard_ConstructionError if this transformation
0221   //! cannot be converted, i.e. if its form is gp_Other.
0222   Standard_EXPORT gp_Trsf2d Trsf2d() const;
0223 
0224 private:
0225   gp_Mat2d    matrix;
0226   gp_XY       loc;
0227   gp_TrsfForm shape;
0228   double      scale;
0229 };
0230 
0231 #include <gp_Trsf2d.hxx>
0232 
0233 //=================================================================================================
0234 
0235 inline void gp_GTrsf2d::SetTrsf2d(const gp_Trsf2d& theT)
0236 {
0237   shape  = theT.shape;
0238   matrix = theT.matrix;
0239   loc    = theT.loc;
0240   scale  = theT.scale;
0241 }
0242 
0243 //=================================================================================================
0244 
0245 inline gp_GTrsf2d::gp_GTrsf2d(const gp_Trsf2d& theT)
0246 {
0247   shape  = theT.shape;
0248   matrix = theT.matrix;
0249   loc    = theT.loc;
0250   scale  = theT.scale;
0251 }
0252 
0253 //=================================================================================================
0254 
0255 inline void gp_GTrsf2d::SetValue(const int theRow, const int theCol, const double theValue)
0256 {
0257   Standard_OutOfRange_Raise_if(theRow < 1 || theRow > 2 || theCol < 1 || theCol > 3, " ");
0258   if (theCol == 3)
0259   {
0260     loc.SetCoord(theRow, theValue);
0261   }
0262   else
0263   {
0264     matrix.SetValue(theRow, theCol, theValue);
0265   }
0266   shape = gp_Other;
0267 }
0268 
0269 //=================================================================================================
0270 
0271 inline constexpr double gp_GTrsf2d::Value(const int theRow, const int theCol) const
0272 {
0273   Standard_OutOfRange_Raise_if(theRow < 1 || theRow > 2 || theCol < 1 || theCol > 3, " ");
0274   if (theCol == 3)
0275   {
0276     return loc.Coord(theRow);
0277   }
0278   if (shape == gp_Other)
0279   {
0280     return matrix.myMat[theRow - 1][theCol - 1];
0281   }
0282   return scale * matrix.myMat[theRow - 1][theCol - 1];
0283 }
0284 
0285 //=================================================================================================
0286 
0287 inline constexpr void gp_GTrsf2d::Transforms(gp_XY& theCoord) const noexcept
0288 {
0289   theCoord.Multiply(matrix);
0290   if (!(shape == gp_Other) && !(scale == 1.0))
0291   {
0292     theCoord.Multiply(scale);
0293   }
0294   theCoord.Add(loc);
0295 }
0296 
0297 //=================================================================================================
0298 
0299 inline constexpr void gp_GTrsf2d::Transforms(double& theX, double& theY) const noexcept
0300 {
0301   gp_XY aDoublet(theX, theY);
0302   aDoublet.Multiply(matrix);
0303   if (!(shape == gp_Other) && !(scale == 1.0))
0304   {
0305     aDoublet.Multiply(scale);
0306   }
0307   aDoublet.Add(loc);
0308   aDoublet.Coord(theX, theY);
0309 }
0310 
0311 #endif // _gp_GTrsf2d_HeaderFile