b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
7fd59977 |
14 | |
15 | #include <gp_Ax2.hxx> |
16 | #include <gp_Ax1.hxx> |
17 | #include <Standard_OutOfRange.hxx> |
18 | #include <Standard_ConstructionError.hxx> |
19 | |
20 | inline gp_GTrsf::gp_GTrsf () |
21 | { |
22 | shape = gp_Identity; |
23 | matrix.SetScale (1.0); |
24 | loc.SetCoord (0.0, 0.0, 0.0); |
25 | scale = 1.0; |
26 | } |
27 | |
28 | inline gp_GTrsf::gp_GTrsf (const gp_Trsf& T) |
29 | { |
30 | shape = T.Form(); |
31 | matrix = T.matrix; |
32 | loc = T.TranslationPart(); |
33 | scale = T.ScaleFactor(); |
34 | } |
35 | |
36 | inline gp_GTrsf::gp_GTrsf (const gp_Mat& M, |
37 | const gp_XYZ& V) : matrix(M), loc(V) |
38 | { |
39 | shape = gp_Other; |
40 | scale = 0.0; |
41 | } |
42 | |
43 | inline void gp_GTrsf::SetAffinity (const gp_Ax1& A1, |
44 | const Standard_Real Ratio) |
45 | { |
46 | shape = gp_Other; |
47 | scale = 0.0; |
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(); |
54 | loc.Reverse (); |
55 | loc.Multiply (matrix); |
56 | loc.Add (A1.Location().XYZ()); |
57 | } |
58 | |
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) |
65 | { |
66 | shape = gp_Other; |
67 | scale = 0.0; |
68 | matrix.SetDot (A2.Direction().XYZ()); |
69 | matrix.Multiply (Ratio - 1.); |
70 | loc = A2.Location().XYZ(); |
71 | loc.Reverse (); |
72 | loc.Multiply (matrix); |
73 | matrix.SetDiagonal (matrix.Value (1,1) +1., |
74 | matrix.Value (2,2) +1., |
75 | matrix.Value (3,3) +1.); |
76 | } |
77 | |
78 | inline void gp_GTrsf::SetValue (const Standard_Integer Row, |
79 | const Standard_Integer Col, |
80 | const Standard_Real Value) |
81 | { |
82 | Standard_OutOfRange_Raise_if |
83 | (Row < 1 || Row > 3 || Col < 1 || Col > 4, " "); |
84 | if (Col == 4) { |
85 | loc.SetCoord (Row, Value); |
86 | if (shape == gp_Identity) shape = gp_Translation; |
87 | return; |
88 | } |
89 | else { |
90 | if (!(shape == gp_Other) && !(scale == 1.0)) matrix.Multiply (scale); |
91 | matrix.SetValue (Row, Col, Value); |
92 | shape = gp_Other; |
93 | scale = 0.0; |
94 | return; |
95 | } |
96 | } |
97 | |
98 | inline void gp_GTrsf::SetVectorialPart (const gp_Mat& Matrix) |
99 | { |
100 | matrix = Matrix; |
101 | shape = gp_Other; |
102 | scale = 0.0; |
103 | } |
104 | |
105 | inline void gp_GTrsf::SetTrsf (const gp_Trsf& T) |
106 | { |
107 | shape = T.shape; |
108 | matrix = T.matrix; |
109 | loc = T.loc; |
110 | scale = T.scale; |
111 | } |
112 | |
113 | inline Standard_Boolean gp_GTrsf::IsNegative () const |
114 | { return matrix.Determinant() < 0.0; } |
115 | |
116 | inline Standard_Boolean gp_GTrsf::IsSingular () const |
117 | { return matrix.IsSingular(); } |
118 | |
119 | inline gp_TrsfForm gp_GTrsf::Form () const |
120 | { return shape; } |
121 | |
122 | inline const gp_XYZ& gp_GTrsf::TranslationPart () const |
123 | { return loc; } |
124 | |
125 | inline const gp_Mat& gp_GTrsf::VectorialPart () const |
126 | { return matrix; } |
127 | |
128 | inline Standard_Real gp_GTrsf::Value (const Standard_Integer Row, |
129 | const Standard_Integer Col) const |
130 | { |
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); |
136 | } |
137 | |
138 | inline gp_GTrsf gp_GTrsf::Inverted () const |
139 | { |
140 | gp_GTrsf T = *this; |
141 | T.Invert (); |
142 | return T; |
143 | } |
144 | |
145 | inline gp_GTrsf gp_GTrsf::Multiplied (const gp_GTrsf& T) const |
146 | { |
147 | gp_GTrsf Tres = *this; |
148 | Tres.Multiply (T); |
149 | return Tres; |
150 | } |
151 | |
152 | inline gp_GTrsf gp_GTrsf::Powered (const Standard_Integer N) const |
153 | { |
154 | gp_GTrsf T = *this; |
155 | T.Power (N); |
156 | return T; |
157 | } |
158 | |
159 | inline void gp_GTrsf::Transforms (gp_XYZ& Coord) const |
160 | { |
161 | Coord.Multiply (matrix); |
162 | if (!(shape == gp_Other) && !(scale == 1.0)) Coord.Multiply (scale); |
163 | Coord.Add(loc); |
164 | } |
165 | |
166 | inline void gp_GTrsf::Transforms (Standard_Real& X, |
167 | Standard_Real& Y, |
168 | Standard_Real& Z) const |
169 | { |
170 | gp_XYZ Triplet (X, Y, Z); |
171 | Triplet.Multiply (matrix); |
172 | if (!(shape == gp_Other) && !(scale == 1.0)) Triplet.Multiply (scale); |
173 | Triplet.Add(loc); |
174 | Triplet.Coord (X, Y, Z); |
175 | } |
176 | |
177 | inline gp_Trsf gp_GTrsf::Trsf () const |
178 | { |
18ee2939 |
179 | if ( Form() == gp_Other ) |
180 | Standard_ConstructionError::Raise("gp_GTrsf::Trsf() - non-orthogonal GTrsf"); |
181 | |
7fd59977 |
182 | gp_Trsf T; |
7fd59977 |
183 | T.shape = shape; |
184 | T.scale = scale; |
185 | T.matrix = matrix; |
186 | T.loc = loc; |
187 | return T; |
188 | } |
189 | |