0024157: Parallelization of assembly part of BO
[occt.git] / src / gp / gp_GTrsf.lxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19
20 #include <gp_Ax2.hxx>
21 #include <gp_Ax1.hxx>
22 #include <Standard_OutOfRange.hxx>
23 #include <Standard_ConstructionError.hxx>
24
25 inline gp_GTrsf::gp_GTrsf ()
26 {
27   shape = gp_Identity;
28   matrix.SetScale (1.0);
29   loc.SetCoord (0.0, 0.0, 0.0);
30   scale = 1.0;
31 }
32
33 inline gp_GTrsf::gp_GTrsf (const gp_Trsf& T)
34 {
35   shape  = T.Form();
36   matrix = T.matrix;
37   loc    = T.TranslationPart();
38   scale  = T.ScaleFactor();
39 }
40
41 inline gp_GTrsf::gp_GTrsf (const gp_Mat& M,
42                            const gp_XYZ& V) : matrix(M), loc(V)
43 {
44   shape = gp_Other;
45   scale = 0.0;
46 }
47
48 inline void gp_GTrsf::SetAffinity (const gp_Ax1& A1,
49                                    const Standard_Real Ratio)
50 {
51   shape = gp_Other;
52   scale = 0.0;
53   matrix.SetDot (A1.Direction().XYZ());
54   matrix.Multiply (1.0 - Ratio);
55   matrix.SetDiagonal (matrix.Value (1,1) + Ratio,
56                       matrix.Value (2,2) + Ratio,
57                       matrix.Value (3,3) + Ratio);
58   loc = A1.Location().XYZ();
59   loc.Reverse ();
60   loc.Multiply (matrix);
61   loc.Add (A1.Location().XYZ());
62 }
63
64 //=======================================================================
65 //function : SetAffinity
66 //history  : AGV 2-05-06: Correct the implementation
67 //=======================================================================
68 inline void gp_GTrsf::SetAffinity (const gp_Ax2& A2,
69                                    const Standard_Real Ratio)
70 {
71   shape = gp_Other;
72   scale = 0.0;
73   matrix.SetDot (A2.Direction().XYZ());
74   matrix.Multiply (Ratio - 1.);
75   loc = A2.Location().XYZ();
76   loc.Reverse ();
77   loc.Multiply (matrix);
78   matrix.SetDiagonal (matrix.Value (1,1) +1.,
79                       matrix.Value (2,2) +1.,
80                       matrix.Value (3,3) +1.);
81 }
82
83 inline void gp_GTrsf::SetValue (const Standard_Integer Row,
84                                 const Standard_Integer Col,
85                                 const Standard_Real Value)
86 {
87   Standard_OutOfRange_Raise_if
88     (Row < 1 || Row > 3 || Col < 1 || Col > 4, " ");
89   if (Col == 4) {
90     loc.SetCoord (Row, Value);
91     if (shape == gp_Identity) shape = gp_Translation;
92     return;
93   }
94   else { 
95     if (!(shape == gp_Other) && !(scale == 1.0)) matrix.Multiply (scale);
96     matrix.SetValue (Row, Col, Value);
97     shape = gp_Other;
98     scale = 0.0;
99     return;
100   }
101 }
102
103 inline void gp_GTrsf::SetVectorialPart (const gp_Mat& Matrix)
104
105   matrix = Matrix;
106   shape = gp_Other;
107   scale = 0.0;
108 }
109
110 inline void gp_GTrsf::SetTrsf (const gp_Trsf& T)
111 {
112   shape = T.shape;
113   matrix = T.matrix;
114   loc = T.loc;
115   scale = T.scale;
116 }
117
118 inline Standard_Boolean gp_GTrsf::IsNegative () const
119 { return matrix.Determinant() < 0.0; }
120
121 inline Standard_Boolean gp_GTrsf::IsSingular () const
122 { return matrix.IsSingular(); }
123
124 inline gp_TrsfForm gp_GTrsf::Form () const
125 { return shape; }
126
127 inline const gp_XYZ& gp_GTrsf::TranslationPart () const
128 { return loc; }
129
130 inline const gp_Mat& gp_GTrsf::VectorialPart () const
131 { return matrix; }
132
133 inline Standard_Real gp_GTrsf::Value (const Standard_Integer Row,
134                                       const Standard_Integer Col) const
135 {
136   Standard_OutOfRange_Raise_if
137     (Row < 1 || Row > 3 || Col < 1 || Col > 4, " ");
138   if (Col == 4) return loc.Coord (Row);
139   if (shape == gp_Other) return matrix.Value (Row, Col);
140   return scale * matrix.Value (Row, Col);
141 }
142
143 inline gp_GTrsf gp_GTrsf::Inverted () const
144 {
145   gp_GTrsf T = *this;
146   T.Invert ();
147   return T;
148 }
149
150 inline gp_GTrsf gp_GTrsf::Multiplied (const gp_GTrsf& T) const
151 {
152   gp_GTrsf Tres = *this;
153   Tres.Multiply (T);
154   return Tres;
155 }
156
157 inline gp_GTrsf gp_GTrsf::Powered (const Standard_Integer N) const
158 {
159   gp_GTrsf T = *this;
160   T.Power (N);
161   return T;
162 }
163
164 inline void gp_GTrsf::Transforms (gp_XYZ& Coord) const
165 {
166   Coord.Multiply (matrix);
167   if (!(shape == gp_Other) && !(scale == 1.0)) Coord.Multiply (scale);
168   Coord.Add(loc);
169 }
170
171 inline void gp_GTrsf::Transforms (Standard_Real& X,
172                                   Standard_Real& Y,
173                                   Standard_Real& Z) const
174 {
175   gp_XYZ Triplet (X, Y, Z);
176   Triplet.Multiply (matrix);
177   if (!(shape == gp_Other) && !(scale == 1.0)) Triplet.Multiply (scale); 
178   Triplet.Add(loc);
179   Triplet.Coord (X, Y, Z);
180 }
181
182 inline gp_Trsf gp_GTrsf::Trsf () const
183 {
184   gp_Trsf T;
185   Standard_ConstructionError_Raise_if
186     (Form() == gp_Other,"");
187   T.shape = shape;
188   T.scale = scale;
189   T.matrix = matrix;
190   T.loc = loc;
191   return T;
192 }
193