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 | #define EpsAng 1.e-8 |
16 | #define EpsAng2 1.e-16 |
17 | #define Tolpetit 1.e-16 |
18 | |
0797d9d3 |
19 | #ifndef OCCT_DEBUG |
7fd59977 |
20 | #define No_Standard_RangeError |
21 | #define No_Standard_OutOfRange |
22 | #endif |
23 | |
24 | #define SURF (*((ThePSurface *)(surf))) |
25 | #define FUNC (*((TheISurface *)(func))) |
26 | |
27 | |
28 | IntImp_ZerImpFunc::IntImp_ZerImpFunc() : |
d533dafb |
29 | surf(NULL), |
30 | func(NULL), |
31 | u(0.0), |
32 | v(0.0), |
33 | tol(0.0), |
34 | valf(0.0), |
7fd59977 |
35 | computed(Standard_False), |
d533dafb |
36 | tangent(Standard_False), |
37 | tgdu(0.0), |
38 | tgdv(0.0), |
7fd59977 |
39 | derived(Standard_False) |
40 | { |
41 | } |
42 | |
43 | IntImp_ZerImpFunc::IntImp_ZerImpFunc(const ThePSurface& PS , |
44 | const TheISurface& IS) : |
d533dafb |
45 | u(0.0), |
46 | v(0.0), |
47 | tol(0.0), |
48 | valf(0.0), |
7fd59977 |
49 | computed(Standard_False), |
d533dafb |
50 | tangent(Standard_False), |
51 | tgdu(0.0), |
52 | tgdv(0.0), |
7fd59977 |
53 | derived(Standard_False) |
54 | { |
55 | surf = (Standard_Address)(&PS); |
56 | func = (Standard_Address)(&IS); |
57 | } |
58 | |
59 | IntImp_ZerImpFunc::IntImp_ZerImpFunc(const TheISurface& IS) : |
d533dafb |
60 | surf(NULL), |
61 | u(0.0), |
62 | v(0.0), |
63 | tol(0.0), |
64 | valf(0.0), |
7fd59977 |
65 | computed(Standard_False), |
d533dafb |
66 | tangent(Standard_False), |
67 | tgdu(0.0), |
68 | tgdv(0.0), |
7fd59977 |
69 | derived(Standard_False) |
70 | { |
71 | func = (Standard_Address)(&IS); |
72 | } |
73 | |
74 | Standard_Integer IntImp_ZerImpFunc::NbVariables() const |
75 | { |
76 | return 2; |
77 | } |
78 | |
79 | Standard_Integer IntImp_ZerImpFunc::NbEquations() const |
80 | { |
81 | return 1; |
82 | } |
83 | |
84 | Standard_Boolean IntImp_ZerImpFunc::Value(const math_Vector& X, |
85 | math_Vector& F) |
86 | { |
87 | u = X(1); |
88 | v = X(2); |
89 | pntsol = ThePSurfaceTool::Value(SURF, u, v); |
90 | valf = TheISurfaceTool::Value(FUNC, pntsol.X(), pntsol.Y(), pntsol.Z()); |
91 | F(1) = valf; |
92 | computed = Standard_False; |
93 | derived = Standard_False; |
94 | return Standard_True; |
95 | } |
96 | |
97 | Standard_Boolean IntImp_ZerImpFunc::Derivatives(const math_Vector& X, |
98 | math_Matrix& D) |
99 | { |
100 | u = X(1); |
101 | v = X(2); |
102 | ThePSurfaceTool::D1(SURF, u, v, pntsol, d1u, d1v); |
103 | TheISurfaceTool::Gradient(FUNC, pntsol.X(), pntsol.Y(), pntsol.Z(),gradient); |
104 | D(1,1) = d1u.Dot(gradient); |
105 | D(1,2) = d1v.Dot(gradient); |
106 | computed = Standard_False; |
107 | derived = Standard_True; |
108 | return Standard_True; |
109 | } |
110 | |
111 | Standard_Boolean IntImp_ZerImpFunc::Values(const math_Vector& X, |
112 | math_Vector& F, |
113 | math_Matrix& D) |
114 | { |
115 | u = X(1); |
116 | v = X(2); |
117 | ThePSurfaceTool::D1(SURF, u, v, pntsol, d1u, d1v); |
118 | TheISurfaceTool::ValueAndGradient(FUNC, pntsol.X(), pntsol.Y(), pntsol.Z(), |
119 | valf, gradient); |
120 | F(1) = valf; |
121 | D(1,1) = d1u.Dot(gradient); |
122 | D(1,2) = d1v.Dot(gradient); |
123 | computed = Standard_False; |
124 | derived = Standard_True; |
125 | return Standard_True; |
126 | } |
127 | |
128 | Standard_Boolean IntImp_ZerImpFunc::IsTangent() |
129 | { |
130 | if (!computed) { |
131 | computed = Standard_True; |
132 | if(!derived) { |
133 | ThePSurfaceTool::D1(SURF, u, v, pntsol, d1u, d1v); |
134 | derived = Standard_True; |
135 | } |
136 | |
137 | tgdu = gradient.Dot(d1v); |
138 | tgdv = -gradient.Dot(d1u); |
139 | Standard_Real N2grad = gradient.SquareMagnitude(); |
140 | Standard_Real N2grad_EpsAng2 = N2grad * EpsAng2; |
141 | Standard_Real N2d1u = d1u.SquareMagnitude(); |
142 | Standard_Real N2d1v = d1v.SquareMagnitude(); |
143 | tangent =(tgdu * tgdu <= N2grad_EpsAng2 * N2d1v) && |
144 | (tgdv * tgdv <= N2grad_EpsAng2 * N2d1u); |
145 | if(!tangent) { |
146 | d3d.SetLinearForm(tgdu,d1u,tgdv,d1v); |
147 | d2d = gp_Dir2d(tgdu, tgdv); |
148 | if (d3d.Magnitude() <= Tolpetit) { // jag |
b92f3572 |
149 | tangent = Standard_True; |
7fd59977 |
150 | } |
151 | } |
152 | } |
153 | return tangent; |
154 | } |
155 | |
156 | #undef EpsAng |
157 | #undef EpsAng2 |
158 | #undef Tolpetit |
159 | #undef FUNC |
160 | #undef SURF |