1 // Copyright (c) 1995-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.
17 #include <Standard_OutOfRange.hxx>
18 #include <Standard_ConstructionError.hxx>
20 inline gp_GTrsf::gp_GTrsf ()
23 matrix.SetScale (1.0);
24 loc.SetCoord (0.0, 0.0, 0.0);
28 inline gp_GTrsf::gp_GTrsf (const gp_Trsf& T)
32 loc = T.TranslationPart();
33 scale = T.ScaleFactor();
36 inline gp_GTrsf::gp_GTrsf (const gp_Mat& M,
37 const gp_XYZ& V) : matrix(M), loc(V)
43 inline void gp_GTrsf::SetAffinity (const gp_Ax1& A1,
44 const Standard_Real Ratio)
48 matrix.SetDot (A1.Direction().XYZ());
49 matrix.Multiply (1.0 - Ratio);
50 matrix.SetDiagonal (matrix.Value (1,1) + Ratio,
51 matrix.Value (2,2) + Ratio,
52 matrix.Value (3,3) + Ratio);
53 loc = A1.Location().XYZ();
55 loc.Multiply (matrix);
56 loc.Add (A1.Location().XYZ());
59 //=======================================================================
60 //function : SetAffinity
61 //history : AGV 2-05-06: Correct the implementation
62 //=======================================================================
63 inline void gp_GTrsf::SetAffinity (const gp_Ax2& A2,
64 const Standard_Real Ratio)
68 matrix.SetDot (A2.Direction().XYZ());
69 matrix.Multiply (Ratio - 1.);
70 loc = A2.Location().XYZ();
72 loc.Multiply (matrix);
73 matrix.SetDiagonal (matrix.Value (1,1) +1.,
74 matrix.Value (2,2) +1.,
75 matrix.Value (3,3) +1.);
78 inline void gp_GTrsf::SetValue (const Standard_Integer Row,
79 const Standard_Integer Col,
80 const Standard_Real Value)
82 Standard_OutOfRange_Raise_if
83 (Row < 1 || Row > 3 || Col < 1 || Col > 4, " ");
85 loc.SetCoord (Row, Value);
86 if (shape == gp_Identity) shape = gp_Translation;
90 if (!(shape == gp_Other) && !(scale == 1.0)) matrix.Multiply (scale);
91 matrix.SetValue (Row, Col, Value);
98 inline void gp_GTrsf::SetVectorialPart (const gp_Mat& Matrix)
105 inline void gp_GTrsf::SetTrsf (const gp_Trsf& T)
113 inline Standard_Boolean gp_GTrsf::IsNegative () const
114 { return matrix.Determinant() < 0.0; }
116 inline Standard_Boolean gp_GTrsf::IsSingular () const
117 { return matrix.IsSingular(); }
119 inline gp_TrsfForm gp_GTrsf::Form () const
122 inline const gp_XYZ& gp_GTrsf::TranslationPart () const
125 inline const gp_Mat& gp_GTrsf::VectorialPart () const
128 inline Standard_Real gp_GTrsf::Value (const Standard_Integer Row,
129 const Standard_Integer Col) const
131 Standard_OutOfRange_Raise_if
132 (Row < 1 || Row > 3 || Col < 1 || Col > 4, " ");
133 if (Col == 4) return loc.Coord (Row);
134 if (shape == gp_Other) return matrix.Value (Row, Col);
135 return scale * matrix.Value (Row, Col);
138 inline gp_GTrsf gp_GTrsf::Inverted () const
145 inline gp_GTrsf gp_GTrsf::Multiplied (const gp_GTrsf& T) const
147 gp_GTrsf Tres = *this;
152 inline gp_GTrsf gp_GTrsf::Powered (const Standard_Integer N) const
159 inline void gp_GTrsf::Transforms (gp_XYZ& Coord) const
161 Coord.Multiply (matrix);
162 if (!(shape == gp_Other) && !(scale == 1.0)) Coord.Multiply (scale);
166 inline void gp_GTrsf::Transforms (Standard_Real& X,
168 Standard_Real& Z) const
170 gp_XYZ Triplet (X, Y, Z);
171 Triplet.Multiply (matrix);
172 if (!(shape == gp_Other) && !(scale == 1.0)) Triplet.Multiply (scale);
174 Triplet.Coord (X, Y, Z);
177 inline gp_Trsf gp_GTrsf::Trsf () const
179 if ( Form() == gp_Other )
180 throw Standard_ConstructionError("gp_GTrsf::Trsf() - non-orthogonal GTrsf");