0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / BlendFunc / BlendFunc_GenChamfer.cxx
CommitLineData
1d54b807 1// Created by: Julia GERASIMOVA
2// Copyright (c) 2015 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
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.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
15#include <Adaptor3d_HCurve.hxx>
16#include <Adaptor3d_HSurface.hxx>
17#include <Blend_Point.hxx>
18#include <BlendFunc.hxx>
19#include <BlendFunc_Chamfer.hxx>
20#include <ElCLib.hxx>
21#include <gp_Lin.hxx>
22#include <gp_Pnt.hxx>
23#include <gp_Vec.hxx>
24#include <gp_Vec2d.hxx>
25#include <math_Matrix.hxx>
26#include <Precision.hxx>
27#include <Standard_NotImplemented.hxx>
28
29
30//=======================================================================
31//function : BlendFunc_GenChamfer
32//purpose :
33//=======================================================================
34BlendFunc_GenChamfer::BlendFunc_GenChamfer(const Handle(Adaptor3d_HSurface)& S1,
35 const Handle(Adaptor3d_HSurface)& S2,
36 const Handle(Adaptor3d_HCurve)& CG)
37 : surf1(S1),surf2(S2),curv(CG),
38 distmin(RealLast())
39{
40}
41
42//=======================================================================
43//function : NbEquations
44//purpose :
45//=======================================================================
46
47Standard_Integer BlendFunc_GenChamfer::NbEquations () const
48{
49 return 4;
50}
51
52//=======================================================================
53//function : Set
54//purpose :
55//=======================================================================
56
57void BlendFunc_GenChamfer::Set(const Standard_Real, const Standard_Real)
58{
59}
60
61//=======================================================================
62//function : GetTolerance
63//purpose :
64//=======================================================================
65
66void BlendFunc_GenChamfer::GetTolerance(math_Vector& Tolerance, const Standard_Real Tol) const
67{
68 Tolerance(1) = surf1->UResolution(Tol);
69 Tolerance(2) = surf1->VResolution(Tol);
70 Tolerance(3) = surf2->UResolution(Tol);
71 Tolerance(4) = surf2->VResolution(Tol);
72}
73
74//=======================================================================
75//function : GetBounds
76//purpose :
77//=======================================================================
78
79void BlendFunc_GenChamfer::GetBounds(math_Vector& InfBound, math_Vector& SupBound) const
80{
81 InfBound(1) = surf1->FirstUParameter();
82 InfBound(2) = surf1->FirstVParameter();
83 InfBound(3) = surf2->FirstUParameter();
84 InfBound(4) = surf2->FirstVParameter();
85 SupBound(1) = surf1->LastUParameter();
86 SupBound(2) = surf1->LastVParameter();
87 SupBound(3) = surf2->LastUParameter();
88 SupBound(4) = surf2->LastVParameter();
89
90 for(Standard_Integer i = 1; i <= 4; i++){
91 if(!Precision::IsInfinite(InfBound(i)) &&
92 !Precision::IsInfinite(SupBound(i))) {
93 const Standard_Real range = (SupBound(i) - InfBound(i));
94 InfBound(i) -= range;
95 SupBound(i) += range;
96 }
97 }
98}
99
100//=======================================================================
101//function : GetMinimalDistance
102//purpose :
103//=======================================================================
104
105Standard_Real BlendFunc_GenChamfer::GetMinimalDistance() const
106{
107 return distmin;
108}
109
110//=======================================================================
111//function : Values
112//purpose :
113//=======================================================================
114
115Standard_Boolean BlendFunc_GenChamfer::Values(const math_Vector& X, math_Vector& F, math_Matrix& D)
116{
117 Standard_Boolean val = Value(X,F);
118 return (val && Derivatives(X,D));
119}
120
121//=======================================================================
122//function : Section
123//purpose :
124//=======================================================================
125
126void BlendFunc_GenChamfer::Section(const Standard_Real /*Param*/,
127 const Standard_Real U1,
128 const Standard_Real V1,
129 const Standard_Real U2,
130 const Standard_Real V2,
131 Standard_Real& Pdeb,
132 Standard_Real& Pfin,
133 gp_Lin& C)
134{
135 const gp_Pnt pts1 = surf1->Value(U1,V1);
136 const gp_Pnt pts2 = surf2->Value(U2,V2);
137 const gp_Dir dir( gp_Vec(pts1,pts2) );
138
139 C.SetLocation(pts1);
140 C.SetDirection(dir);
141
142 Pdeb = 0.;
143 Pfin = ElCLib::Parameter(C,pts2);
144}
145
146//=======================================================================
147//function : IsRational
148//purpose :
149//=======================================================================
150
151Standard_Boolean BlendFunc_GenChamfer::IsRational() const
152{
153 return Standard_False;
154}
155
156//=======================================================================
157//function : GetMinimalWeight
158//purpose :
159//=======================================================================
160void BlendFunc_GenChamfer::GetMinimalWeight(TColStd_Array1OfReal& Weights) const
161{
162 Weights.Init(1);
163}
164
165
166//=======================================================================
167//function : NbIntervals
168//purpose :
169//=======================================================================
170
171Standard_Integer BlendFunc_GenChamfer::NbIntervals (const GeomAbs_Shape S) const
172{
173 return curv->NbIntervals(BlendFunc::NextShape(S));
174}
175
176
177//=======================================================================
178//function : Intervals
179//purpose :
180//=======================================================================
181
182void BlendFunc_GenChamfer::Intervals (TColStd_Array1OfReal& T, const GeomAbs_Shape S) const
183{
184 curv->Intervals(T, BlendFunc::NextShape(S));
185}
186
187//=======================================================================
188//function : GetShape
189//purpose :
190//=======================================================================
191
192void BlendFunc_GenChamfer::GetShape (Standard_Integer& NbPoles,
193 Standard_Integer& NbKnots,
194 Standard_Integer& Degree,
195 Standard_Integer& NbPoles2d)
196{
197 NbPoles = 2;
198 NbPoles2d = 2;
199 NbKnots = 2;
200 Degree = 1;
201}
202
203//=======================================================================
204//function : GetTolerance
205//purpose : Determine les Tolerance a utiliser dans les approximations.
206//=======================================================================
207void BlendFunc_GenChamfer::GetTolerance(const Standard_Real BoundTol,
208 const Standard_Real,
209 const Standard_Real,
210 math_Vector& Tol3d,
211 math_Vector&) const
212{
213 Tol3d.Init(BoundTol);
214}
215
216//=======================================================================
217//function : Knots
218//purpose :
219//=======================================================================
220
221void BlendFunc_GenChamfer::Knots(TColStd_Array1OfReal& TKnots)
222{
223 TKnots(1) = 0.;
224 TKnots(2) = 1.;
225}
226
227
228//=======================================================================
229//function : Mults
230//purpose :
231//=======================================================================
232
233void BlendFunc_GenChamfer::Mults(TColStd_Array1OfInteger& TMults)
234{
235 TMults(1) = 2;
236 TMults(2) = 2;
237}
238
239//=======================================================================
240//function : Section
241//purpose :
242//=======================================================================
243
244Standard_Boolean BlendFunc_GenChamfer::Section
245 (const Blend_Point& /*P*/,
246 TColgp_Array1OfPnt& /*Poles*/,
247 TColgp_Array1OfVec& /*DPoles*/,
248 TColgp_Array1OfVec& /*D2Poles*/,
249 TColgp_Array1OfPnt2d& /*Poles2d*/,
250 TColgp_Array1OfVec2d& /*DPoles2d*/,
251 TColgp_Array1OfVec2d& /*D2Poles2d*/,
252 TColStd_Array1OfReal& /*Weights*/,
253 TColStd_Array1OfReal& /*DWeights*/,
254 TColStd_Array1OfReal& /*D2Weights*/)
255{
256 return Standard_False;
257}
258
259//=======================================================================
260//function : Section
261//purpose :
262//=======================================================================
263
264Standard_Boolean BlendFunc_GenChamfer::Section
265 (const Blend_Point& P,
266 TColgp_Array1OfPnt& Poles,
267 TColgp_Array1OfVec& DPoles,
268 TColgp_Array1OfPnt2d& Poles2d,
269 TColgp_Array1OfVec2d& DPoles2d,
270 TColStd_Array1OfReal& Weights,
271 TColStd_Array1OfReal& DWeights)
272{
273 math_Vector sol(1,4),valsol(1,4),secmember(1,4);
274 math_Matrix gradsol(1,4,1,4);
275
276 Standard_Real prm = P.Parameter();
277 Standard_Integer low = Poles.Lower();
278 Standard_Integer upp = Poles.Upper();
279 Standard_Boolean istgt;
280
281 P.ParametersOnS1(sol(1),sol(2));
282 P.ParametersOnS2(sol(3),sol(4));
283
284 Set(prm);
285
286 Values(sol,valsol,gradsol);
287 IsSolution(sol,tol);
288
289 istgt = IsTangencyPoint();
290
291 Poles2d(Poles2d.Lower()).SetCoord(sol(1),sol(2));
292 Poles2d(Poles2d.Upper()).SetCoord(sol(3),sol(4));
293 if (!istgt) {
294 DPoles2d(Poles2d.Lower()).SetCoord(Tangent2dOnS1().X(),
295 Tangent2dOnS1().Y());
296 DPoles2d(Poles2d.Upper()).SetCoord(Tangent2dOnS2().X(),
297 Tangent2dOnS2().Y());
298 }
299 Poles(low) = PointOnS1();
300 Poles(upp) = PointOnS2();
301 Weights(low) = 1.0;
302 Weights(upp) = 1.0;
303 if (!istgt) {
304 DPoles(low) = TangentOnS1();
305 DPoles(upp) = TangentOnS2();
306 DWeights(low) = 0.0;
307 DWeights(upp) = 0.0;
308 }
309
310 return (!istgt);
311}
312
313//=======================================================================
314//function : Section
315//purpose :
316//=======================================================================
317
318void BlendFunc_GenChamfer::Section(const Blend_Point& P,
319 TColgp_Array1OfPnt& Poles,
320 TColgp_Array1OfPnt2d& Poles2d,
321 TColStd_Array1OfReal& Weights)
322{
323 Standard_Real u1,v1,u2,v2,prm = P.Parameter();
324 Standard_Integer low = Poles.Lower();
325 Standard_Integer upp = Poles.Upper();
326 math_Vector X(1,4), F(1,4);
327
328 P.ParametersOnS1(u1,v1);
329 P.ParametersOnS2(u2,v2);
330 X(1)=u1;
331 X(2)=v1;
332 X(3)=u2;
333 X(4)=v2;
334 Poles2d(Poles2d.Lower()).SetCoord(u1,v1);
335 Poles2d(Poles2d.Upper()).SetCoord(u2,v2);
336
337 Set(prm);
338 Value(X,F);
339 Poles(low) = PointOnS1();
340 Poles(upp) = PointOnS2();
341 Weights(low) = 1.0;
342 Weights(upp) = 1.0;
343}
344
345void BlendFunc_GenChamfer::Resolution(const Standard_Integer IC2d, const Standard_Real Tol,
346 Standard_Real& TolU, Standard_Real& TolV) const
347{
348 if(IC2d == 1){
349 TolU = surf1->UResolution(Tol);
350 TolV = surf1->VResolution(Tol);
351 }
352 else {
353 TolU = surf2->UResolution(Tol);
354 TolV = surf2->VResolution(Tol);
355 }
356}