0022627: Change OCCT memory management defaults
[occt.git] / src / BRepFill / BRepFill_NSections.cxx
CommitLineData
7fd59977 1// File: BRepFill_NSections.cxx
2// Created: Tue Dec 29 17:01:25 1998
3// Author: Joelle CHAUVET
4// <jct@sgi64>
5
6#include <stdio.h>
7
8#include <BRepFill_NSections.ixx>
9
10#include <BRepFill.hxx>
11#include <BRepTools_WireExplorer.hxx>
12#include <BRep_Builder.hxx>
13#include <BRep_Tool.hxx>
14#include <BRepAdaptor_Curve.hxx>
15#include <BRepLProp.hxx>
16
17#include <BRepLib_MakeWire.hxx>
18#include <BRepLib_MakeEdge.hxx>
19#include <TopExp.hxx>
20#include <TopoDS.hxx>
21#include <TopoDS_Vertex.hxx>
22#include <TopoDS_Wire.hxx>
23
24#include <Geom_Curve.hxx>
25#include <Geom_Line.hxx>
26#include <Geom_TrimmedCurve.hxx>
27#include <Geom_BSplineCurve.hxx>
28#include <Geom_Conic.hxx>
29#include <GeomFill_UniformSection.hxx>
30#include <GeomFill_EvolvedSection.hxx>
31#include <GeomFill_HArray1OfSectionLaw.hxx>
32#include <GeomFill_NSections.hxx>
33#include <TColGeom_SequenceOfCurve.hxx>
34#include <GeomFill_SectionGenerator.hxx>
35#include <GeomFill_Line.hxx>
36#include <GeomFill_AppSurf.hxx>
37#include <GeomConvert.hxx>
38#include <GeomConvert_ApproxCurve.hxx>
39#include <GeomConvert_CompCurveToBSplineCurve.hxx>
40#include <Geom_BSplineSurface.hxx>
41#include <BSplCLib.hxx>
42
43#include <TColgp_HArray1OfPnt.hxx>
44#include <TColStd_HArray1OfReal.hxx>
45#include <TColStd_HArray1OfInteger.hxx>
46#include <Geom_BezierCurve.hxx>
47#include <TopTools_Array1OfShape.hxx>
48
49#include <Precision.hxx>
50
51#ifdef DEB
52static Standard_Boolean Affich = 0;
53#endif
54
55#ifdef DRAW
56#include <DrawTrSurf.hxx>
57#include <DBRep.hxx>
58#endif
59
60//=======================================================================
61//function : totalsurf
62//purpose :
63//=======================================================================
64
65static Handle(Geom_BSplineSurface) totalsurf(const TopTools_Array2OfShape& shapes,
66 const Standard_Integer NbSects,
67 const Standard_Integer NbEdges,
68 const TColStd_SequenceOfReal& params,
69 const Standard_Boolean w1Point,
70 const Standard_Boolean w2Point,
71 const Standard_Boolean uClosed,
72 const Standard_Boolean vClosed,
73 const Standard_Real myPres3d)
74{
75 Standard_Integer i,j,jdeb=1,jfin=NbSects;
76 TopoDS_Edge edge;
77 TopLoc_Location loc;
78 Standard_Real first, last;
79 TopoDS_Vertex vf,vl;
80
81 GeomFill_SectionGenerator section;
82 Handle(Geom_BSplineSurface) surface;
83 Handle(Geom_BSplineCurve) BS, BS1;
84 Handle(Geom_TrimmedCurve) curvTrim;
85 Handle(Geom_BSplineCurve) curvBS;
86
87 if (w1Point) {
88 jdeb++;
89 edge = TopoDS::Edge(shapes.Value(1,1));
90 TopExp::Vertices(edge,vl,vf);
91 TColgp_Array1OfPnt Extremities(1,2);
92 Extremities(1) = BRep_Tool::Pnt(vf);
93 Extremities(2) = BRep_Tool::Pnt(vl);
94 TColStd_Array1OfReal Bounds(1,2);
95 Bounds(1) = 0.;
96 Bounds(2) = 1.;
97 Standard_Real Deg = 1;
98 TColStd_Array1OfInteger Mult(1,2);
99 Mult(1) = (Standard_Integer) Deg+1;
100 Mult(2) = (Standard_Integer) Deg+1;
101 Handle(Geom_BSplineCurve) BSPoint
102 = new Geom_BSplineCurve(Extremities,Bounds,Mult,(Standard_Integer ) Deg);
103 section.AddCurve(BSPoint);
104 }
105
106 if (w2Point) {
107 jfin--;
108 }
109
110 for (j=jdeb; j<=jfin; j++) {
111
0d969553 112 // case of looping sections
7fd59977 113 if (j==jfin && vClosed) {
114 section.AddCurve(BS1);
115 }
116
117 else {
118 // read the first edge to initialise CompBS;
119 edge = TopoDS::Edge(shapes.Value(1,j));
120 if (BRep_Tool::Degenerated(edge)) {
0d969553 121 // degenerated edge : construction of a point curve
7fd59977 122 TopExp::Vertices(edge,vl,vf);
123 TColgp_Array1OfPnt Extremities(1,2);
124 Extremities(1) = BRep_Tool::Pnt(vf);
125 Extremities(2) = BRep_Tool::Pnt(vl);
126 Handle(Geom_Curve) curv = new Geom_BezierCurve(Extremities);
127 curvTrim = new Geom_TrimmedCurve(curv,
128 curv->FirstParameter(),
129 curv->LastParameter());
130 }
131 else {
0d969553 132 // return the curve on the edge
7fd59977 133 Handle(Geom_Curve) curv = BRep_Tool::Curve(edge, loc, first, last);
134 curvTrim = new Geom_TrimmedCurve(curv, first, last);
135 curvTrim->Transform(loc.Transformation());
136 }
137 if (edge.Orientation() == TopAbs_REVERSED) {
138 curvTrim->Reverse();
139 }
140
0d969553 141 // transformation into BSpline reparameterized on [i-1,i]
7fd59977 142 curvBS = Handle(Geom_BSplineCurve)::DownCast(curvTrim);
143 if (curvBS.IsNull()) {
144 Handle(Geom_Curve) theCurve = curvTrim->BasisCurve();
145 if (theCurve->IsKind(STANDARD_TYPE(Geom_Conic)))
146 {
147 GeomConvert_ApproxCurve appr(curvTrim, Precision::Confusion(), GeomAbs_C1, 16, 14);
148 if (appr.HasResult())
149 curvBS = appr.Curve();
150 }
151 if (curvBS.IsNull())
152 curvBS = GeomConvert::CurveToBSplineCurve(curvTrim);
153 }
154 TColStd_Array1OfReal BSK(1,curvBS->NbKnots());
155 curvBS->Knots(BSK);
156 BSplCLib::Reparametrize(0.,1.,BSK);
157 curvBS->SetKnots(BSK);
158
0d969553 159 // initialization
7fd59977 160 GeomConvert_CompCurveToBSplineCurve CompBS(curvBS);
161
162 for (i=2; i<=NbEdges; i++) {
163 // read the edge
164 edge = TopoDS::Edge(shapes.Value(i,j));
165 if (BRep_Tool::Degenerated(edge)) {
0d969553 166 // degenerated edge : construction of a point curve
7fd59977 167 TopExp::Vertices(edge,vl,vf);
168 TColgp_Array1OfPnt Extremities(1,2);
169 Extremities(1) = BRep_Tool::Pnt(vf);
170 Extremities(2) = BRep_Tool::Pnt(vl);
171 Handle(Geom_Curve) curv = new Geom_BezierCurve(Extremities);
172 curvTrim = new Geom_TrimmedCurve(curv,
173 curv->FirstParameter(),
174 curv->LastParameter());
175 }
176 else {
0d969553 177 // return the curve on the edge
7fd59977 178 Handle(Geom_Curve) curv = BRep_Tool::Curve(edge, loc, first, last);
179 curvTrim = new Geom_TrimmedCurve(curv, first, last);
180 curvTrim->Transform(loc.Transformation());
181 }
182 if (edge.Orientation() == TopAbs_REVERSED) {
183 curvTrim->Reverse();
184 }
185
0d969553 186 // transformation into BSpline reparameterized on [i-1,i]
7fd59977 187 curvBS = Handle(Geom_BSplineCurve)::DownCast(curvTrim);
188 if (curvBS.IsNull()) {
189 Handle(Geom_Curve) theCurve = curvTrim->BasisCurve();
190 if (theCurve->IsKind(STANDARD_TYPE(Geom_Conic)))
191 {
192 GeomConvert_ApproxCurve appr(curvTrim, Precision::Confusion(), GeomAbs_C1, 16, 14);
193 if (appr.HasResult())
194 curvBS = appr.Curve();
195 }
196 if (curvBS.IsNull())
197 curvBS = GeomConvert::CurveToBSplineCurve(curvTrim);
198 }
199 TColStd_Array1OfReal BSK(1,curvBS->NbKnots());
200 curvBS->Knots(BSK);
201 BSplCLib::Reparametrize(i-1,i,BSK);
202 curvBS->SetKnots(BSK);
203
204 // concatenation
205 TopoDS_Vertex ComV;
206 Standard_Real epsV;
207 Standard_Boolean Bof =
208 TopExp::CommonVertex(TopoDS::Edge(shapes.Value(i-1,j)), edge, ComV);
209 if (Bof) epsV = BRep_Tool::Tolerance(ComV);
210 else epsV = Precision::Confusion();
211 Bof = CompBS.Add(curvBS, epsV, Standard_True, Standard_False, 1);
212 if (!Bof) Bof = CompBS.Add(curvBS, 200*epsV,
213 Standard_True, Standard_False, 1);
214 }
215
0d969553 216 // return the final section
7fd59977 217 BS = CompBS.BSplineCurve();
218 section.AddCurve(BS);
219
0d969553 220 // case of looping sections
7fd59977 221 if (j==jdeb && vClosed) {
222 BS1 = BS;
223 }
224
225 }
226 }
227
228 if (w2Point) {
229 edge = TopoDS::Edge(shapes.Value(NbEdges,NbSects));
230 TopExp::Vertices(edge,vl,vf);
231 TColgp_Array1OfPnt Extremities(1,2);
232 Extremities(1) = BRep_Tool::Pnt(vf);
233 Extremities(2) = BRep_Tool::Pnt(vl);
234 TColStd_Array1OfReal Bounds(1,2);
235 Bounds(1) = 0.;
236 Bounds(2) = 1.;
237 Standard_Real Deg = 1;
238 TColStd_Array1OfInteger Mult(1,2);
239 Mult(1) = (Standard_Integer) Deg+1;
240 Mult(2) = (Standard_Integer) Deg+1;
241 Handle(Geom_BSplineCurve) BSPoint
242 = new Geom_BSplineCurve(Extremities,Bounds,Mult,(Standard_Integer ) Deg);
243 section.AddCurve(BSPoint);
244 }
245
246 Handle(TColStd_HArray1OfReal) HPar
247 = new TColStd_HArray1OfReal(1,params.Length());
248 for (i=1; i<=params.Length(); i++) {
249 HPar->SetValue(i,params(i));
250 }
251 section.SetParam(HPar);
252 section.Perform(Precision::PConfusion());
253 Handle(GeomFill_Line) line = new GeomFill_Line(NbSects);
254 Standard_Integer nbIt = 0, degmin = 2, degmax = 6;
255 Standard_Boolean knownP = Standard_True;
256 GeomFill_AppSurf anApprox(degmin, degmax, myPres3d, myPres3d, nbIt, knownP);
257 Standard_Boolean SpApprox = Standard_True;
258 anApprox.Perform(line, section, SpApprox);
259 Standard_Boolean uperiodic = uClosed;
260 Standard_Boolean vperiodic = vClosed;
261 Standard_Integer nup = anApprox.SurfPoles().ColLength(),
262 nvp = anApprox.SurfPoles().RowLength();
263 TColStd_Array1OfInteger Umults(1,anApprox.SurfUKnots().Length());
264 Umults = anApprox.SurfUMults();
265 TColStd_Array1OfInteger Vmults(1,anApprox.SurfVKnots().Length());
266 Vmults = anApprox.SurfVMults();
267
268 if (uperiodic) {
269 Standard_Integer nbuk = anApprox.SurfUKnots().Length();
270 Umults(1) --;
271 Umults(nbuk) --;
272 nup --;
273 }
274
275 if (vperiodic) {
276 Standard_Integer nbvk = anApprox.SurfVKnots().Length();
277 Vmults(1) --;
278 Vmults(nbvk) --;
279 nvp --;
280 }
281
282 TColgp_Array2OfPnt poles (1, nup, 1, nvp);
283 TColStd_Array2OfReal weights(1, nup, 1, nvp);
284 for (j = 1; j <= nvp; j++) {
285 for (i = 1; i <= nup; i++) {
286 poles(i, j) = anApprox.SurfPoles()(i,j);
287 weights(i, j) = anApprox.SurfWeights()(i,j);
288 }
289 }
290
291 // To create non-rational surface if possible
292 Standard_Real TolEps = 1.e-13;
293 Standard_Boolean Vrational = Standard_False, Urational = Standard_False;
294 for (j = 1; j <= weights.UpperCol(); j++)
295 if (!Vrational)
296 for (i = 1; i <= weights.UpperRow()-1; i++)
297 {
298 //Standard_Real signeddelta = weights(i,j) - weights(i+1,j);
299 Standard_Real delta = Abs( weights(i,j) - weights(i+1,j) );
300// Standard_Real eps = Epsilon( Abs(weights(i,j)) );
301 if (delta > TolEps/* || delta > 3.*eps*/)
302 {
303 Vrational = Standard_True;
304 break;
305 }
306 }
307 for (i = 1; i <= weights.UpperRow(); i++)
308 if (!Urational)
309 for (j = 1; j <= weights.UpperCol()-1; j++)
310 {
311 //Standard_Real signeddelta = weights(i,j) - weights(i,j+1);
312 Standard_Real delta = Abs( weights(i,j) - weights(i,j+1) );
313// Standard_Real eps = Epsilon( Abs(weights(i,j)) );
314 if (delta > TolEps/* || delta > 3.*eps*/)
315 {
316 Urational = Standard_True;
317 break;
318 }
319 }
320 if (!Vrational && !Urational)
321 {
322 Standard_Real theWeight = weights(1,1);
323 for (i = 1; i <= weights.UpperRow(); i++)
324 for (j = 1; j <= weights.UpperCol(); j++)
325 weights(i,j) = theWeight;
326 }
327
328 surface =
329 new Geom_BSplineSurface(poles, weights,
330 anApprox.SurfUKnots(), anApprox.SurfVKnots(),
331 Umults, Vmults,
332 anApprox.UDegree(), anApprox.VDegree(),
333 uperiodic, vperiodic);
334 return surface;
335
336}
337
338
339//=======================================================================
340//function : Create
341//purpose : WSeq
342//=======================================================================
343
344BRepFill_NSections::BRepFill_NSections(const TopTools_SequenceOfShape& S,
345 const Standard_Boolean Build)
346
347{
348 myShapes = S;
349 VFirst = 0.;
350 VLast = 1.;
351 TColStd_SequenceOfReal par;
352 par.Clear();
353 for (Standard_Integer i=1;i<=S.Length();i++) {
354 par.Append(i-1);
355 }
356 myParams = par;
357 Init(par,Build);
358}
359
360//=======================================================================
361//function : Create
362//purpose : WSeq + Param
363//=======================================================================
364
365BRepFill_NSections::BRepFill_NSections(const TopTools_SequenceOfShape& S,
d7325741 366 const GeomFill_SequenceOfTrsf& Transformations,
7fd59977 367 const TColStd_SequenceOfReal & P,
368 const Standard_Real VF,
369 const Standard_Real VL,
370 const Standard_Boolean Build)
371
372{
373#ifdef DEB
374 if ( Affich) {
375#ifdef DRAW
376 Standard_Integer NBSECT = 0;
377 for (Standard_Integer i=1;i<=S.Length();i++) {
378 NBSECT++;
379 char name[256];
380 sprintf(name,"WIRE_%d",NBSECT);
381 DBRep::Set(name,TopoDS::Wire(S.Value(i)));
382 }
383#endif
384 }
385#endif
386 Standard_Boolean ok = Standard_True;
387 for (Standard_Integer iseq=1;iseq<P.Length();iseq++) {
388 ok = ok && (P.Value(iseq)<P.Value(iseq+1));
389 }
390 if (ok) {
391 myParams = P;
392 myShapes = S;
d7325741 393 myTrsfs = Transformations;
7fd59977 394 VFirst = VF;
395 VLast = VL;
396 Init(P,Build);
397 }
398}
399
400//=======================================================================
401//function : Init
0d969553 402//purpose : Create a table of GeomFill_SectionLaw
7fd59977 403//=======================================================================
404void BRepFill_NSections::Init(const TColStd_SequenceOfReal & P,
405 const Standard_Boolean Build)
406{
407 BRepTools_WireExplorer wexp;
408// Class BRep_Tool without fields and without Constructor :
409// BRep_Tool B;
410 TopoDS_Edge E;
411 Standard_Integer ii, NbEdge, jj, NbSects = P.Length();
412 Standard_Integer ideb = 1, ifin = NbSects;
413 Standard_Boolean wClosed, w1Point = Standard_True,
414 w2Point = Standard_True;
415 Standard_Real First, Last;
416 TopoDS_Wire W;
417
0d969553 418 // Check if the start and end wires are punctual
7fd59977 419 W = TopoDS::Wire(myShapes(1));
420 for (wexp.Init(W); wexp.More(); wexp.Next())
421// w1Point = w1Point && B.Degenerated(wexp.Current());
422 w1Point = w1Point && BRep_Tool::Degenerated(wexp.Current());
423 if (w1Point) ideb++;
424 W = TopoDS::Wire(myShapes(NbSects));
425 for (wexp.Init(W); wexp.More(); wexp.Next())
426// w2Point = w2Point && B.Degenerated(wexp.Current());
427 w2Point = w2Point && BRep_Tool::Degenerated(wexp.Current());
428 if (w2Point) ifin--;
429
0d969553 430 // Check if the start and end wires are identical
7fd59977 431 vclosed = myShapes(1).IsSame(myShapes(NbSects));
432
0d969553 433 // Count the number of non-degenerated edges
7fd59977 434 W = TopoDS::Wire(myShapes(ideb));
435 for (NbEdge=0, wexp.Init(W); wexp.More(); wexp.Next())
436// if (! B.Degenerated(wexp.Current())) NbEdge++;
437 if (! BRep_Tool::Degenerated(wexp.Current())) NbEdge++;
438
7fd59977 439 myEdges = new (TopTools_HArray2OfShape) (1, NbEdge, 1, NbSects);
440
0d969553 441 // Fill tables
7fd59977 442 uclosed = Standard_True;
443 for (jj=ideb;jj<=ifin;jj++){
444
445 W = TopoDS::Wire(myShapes(jj));
446
447 for (ii=1, wexp.Init(W); ii<=NbEdge ; wexp.Next(), ii++) {
448 E = wexp.Current();
449
450// if ( ! B.Degenerated(E)) {
451 if ( ! BRep_Tool::Degenerated(E)) {
452 myEdges->SetValue(ii,jj, E);
453 }
454 }
455
0d969553 456 // Is the law closed by U ?
7fd59977 457
458 wClosed = W.Closed();
459 if (!wClosed) {
0d969553 460 // if unsure about the flag, make check
7fd59977 461 TopoDS_Edge Edge1, Edge2;
462 TopoDS_Vertex V1,V2;
463 Edge1 = TopoDS::Edge (myEdges->Value(NbEdge,jj));
464 Edge2 = TopoDS::Edge (myEdges->Value(1,jj));
465
466 if ( Edge1.Orientation() == TopAbs_REVERSED) {
467 V1 = TopExp::FirstVertex(Edge1);
468 }
469 else {
470 V1 = TopExp::LastVertex(Edge1);
471 }
472 if ( Edge2.Orientation() == TopAbs_REVERSED) {
473 V2 = TopExp::LastVertex(Edge2);
474 }
475 else {
476 V2 = TopExp::FirstVertex(Edge2);
477 }
478 if (V1.IsSame(V2)) {
479 wClosed = Standard_True;
480 }
481 else {
482 BRepAdaptor_Curve Curve1(Edge1);
483 BRepAdaptor_Curve Curve2(Edge2);
484 Standard_Real U1 = BRep_Tool::Parameter(V1,Edge1);
485 Standard_Real U2 = BRep_Tool::Parameter(V2,Edge2);
486 Standard_Real Eps = BRep_Tool::Tolerance(V2) +
487 BRep_Tool::Tolerance(V1);
488
489 wClosed = Curve1.Value(U1).IsEqual(Curve2.Value(U2), Eps);
490 }
491 }
492 if (!wClosed) uclosed = Standard_False;
493 }
494
0d969553 495 // point sections at end
7fd59977 496 if (w1Point) {
497 W = TopoDS::Wire(myShapes(1));
498 wexp.Init(W);
499 E = wexp.Current();
500 for (ii=1; ii<=NbEdge ; ii++) {
501 myEdges->SetValue(ii, 1, E);
502 }
503 }
504
505 if (w2Point) {
506 W = TopoDS::Wire(myShapes(NbSects));
507 wexp.Init(W);
508 E = wexp.Current();
509 for (ii=1; ii<=NbEdge ; ii++) {
510 myEdges->SetValue(ii, NbSects, E);
511 }
512 }
513
514
515 myLaws = new (GeomFill_HArray1OfSectionLaw) (1, NbEdge);
516
517 Standard_Real tol = Precision::Confusion();
518 mySurface = totalsurf(myEdges->Array2(),myShapes.Length(),NbEdge,
519 myParams,w1Point,w2Point,uclosed,vclosed,tol);
520
0d969553
Y
521 // Increase the degree so that the position D2
522 // on GeomFill_NSections could be correct
523 // see comments in GeomFill_NSections
7fd59977 524 if (mySurface->VDegree()<2) {
525 mySurface->IncreaseDegree(mySurface->UDegree(),2);
526 }
527#ifdef DRAW
528 if ( Affich) {
529 char* name = new char[100];
530 sprintf(name,"Ref_Surf");
531 DrawTrSurf::Set(name,mySurface);
532 }
533#endif
534
0d969553 535 // Fill tables
7fd59977 536 if (Build) {
537 for (ii=1; ii<=NbEdge ; ii++) {
538 TColGeom_SequenceOfCurve NC;
539 NC.Clear();
540 for (jj=1;jj<=NbSects;jj++) {
541 E = TopoDS::Edge (myEdges->Value(ii,jj));
542 Handle(Geom_Curve) C;
543// if (B.Degenerated(E)) {
544 if (BRep_Tool::Degenerated(E)) {
545 TopoDS_Vertex vf,vl;
546 TopExp::Vertices(E,vl,vf);
547 TColgp_Array1OfPnt Extremities(1,2);
548 Extremities(1) = BRep_Tool::Pnt(vf);
549 Extremities(2) = BRep_Tool::Pnt(vl);
550 TColStd_Array1OfReal Bounds(1,2);
551 Bounds(1) = 0.;
552 Bounds(2) = 1.;
553 TColStd_Array1OfInteger Mult(1,2);
554 Mult(1) = 2;
555 Mult(2) = 2;
556 Handle(Geom_BSplineCurve) BSPoint
557 = new Geom_BSplineCurve(Extremities,Bounds,Mult,1);
558 C = BSPoint;
559 }
560 else {
561 C = BRep_Tool::Curve(E,First,Last);
562
563 if (E.Orientation() == TopAbs_REVERSED) {
564 Standard_Real aux;
565 Handle(Geom_Curve) CBis;
0d969553 566 CBis = C->Reversed(); // To avoid the spoiling of the topology
7fd59977 567 aux = C->ReversedParameter(First);
568 First = C->ReversedParameter(Last);
569 Last = aux;
570 C = CBis;
571 }
0d969553 572 if ((ii>1) || (!E.Closed()) ) { // Cut C
7fd59977 573 Handle(Geom_TrimmedCurve) TC =
574 new (Geom_TrimmedCurve) (C,First, Last);
575 C = TC;
576 }
0d969553 577 // otherwise preserve the integrity of the curve
7fd59977 578 }
579 NC.Append(C);
580 }
581
582 Standard_Real Ufirst = ii-1;
583 Standard_Real Ulast = ii;
d7325741 584 myLaws->ChangeValue(ii) = new (GeomFill_NSections)(NC, myTrsfs, myParams,
7fd59977 585 Ufirst,Ulast,
586 VFirst,VLast,
587 mySurface);
588 }
589
590 }
591
592}
593
594
595//=======================================================================
596//function : IsVertex
597//purpose :
598//=======================================================================
599 Standard_Boolean BRepFill_NSections::IsVertex() const
600{
601 return Standard_False;
602}
603
604//=======================================================================
605//function : IsConstant
606//purpose :
607//=======================================================================
608 Standard_Boolean BRepFill_NSections::IsConstant() const
609{
610 return Standard_False;
611}
612
613//=======================================================================
614//function : Vertex
615//purpose :
616//=======================================================================
617 TopoDS_Vertex
618 BRepFill_NSections::Vertex(const Standard_Integer Index,
619 const Standard_Real Param) const
620{
621 BRep_Builder B;
622 TopoDS_Vertex V;
623 B.MakeVertex(V);
624 gp_Pnt P;
625
626 if (Index <= myEdges->ColLength()) {
627 Handle(Geom_BSplineCurve) Curve
628 = Handle(Geom_BSplineCurve)::DownCast(myLaws->Value(Index)->
629 BSplineSurface()->VIso(Param));
630 Standard_Real first = Curve ->FirstParameter();
631 Curve->D0(first, P);
632 B.UpdateVertex(V, P, Precision::Confusion());
633 }
634 else if (Index == myEdges->ColLength()+1) {
635 Handle(Geom_BSplineCurve) Curve
636 = Handle(Geom_BSplineCurve)::DownCast(myLaws->Value(Index-1)->
637 BSplineSurface()->VIso(Param));
638 Standard_Real last = Curve ->LastParameter();
639 Curve->D0(last, P);
640 B.UpdateVertex(V, P, Precision::Confusion());
641 }
642
643 return V;
644}
645
646
647///=======================================================================
648//function : VertexTol
0d969553 649//purpose : Evaluate the hole between 2 edges of the section
7fd59977 650//=======================================================================
651 Standard_Real BRepFill_NSections::VertexTol(const Standard_Integer Index,
652 const Standard_Real Param) const
653{
654 Standard_Real Tol = Precision::Confusion();
655 Standard_Integer I1, I2;
656 if ( (Index==0) || (Index==myEdges->ColLength()) ) {
0d969553 657 if (!uclosed) return Tol; //The least possible error
7fd59977 658 I1 = myEdges->ColLength();
659 I2 = 1;
660 }
661 else {
662 I1 = Index;
663 I2 = I1 +1;
664 }
665
666 Handle(GeomFill_SectionLaw) Loi;
667 Standard_Integer NbPoles, NbKnots, Degree;
668 Handle(TColgp_HArray1OfPnt) Poles;
669 Handle(TColStd_HArray1OfReal) Knots, Weigth;
670 Handle(TColStd_HArray1OfInteger) Mults;
671 Handle(Geom_BSplineCurve) BS;
672 gp_Pnt PFirst;
673
674 Loi = myLaws->Value(I1);
675 Loi->SectionShape( NbPoles, NbKnots, Degree);
676 Poles = new (TColgp_HArray1OfPnt) (1, NbPoles);
677 Weigth = new (TColStd_HArray1OfReal) (1, NbPoles);
678 Loi->D0(Param, Poles->ChangeArray1(), Weigth->ChangeArray1());
679 Knots = new (TColStd_HArray1OfReal) (1, NbKnots);
680 Loi->Knots(Knots->ChangeArray1());
681 Mults = new (TColStd_HArray1OfInteger) (1, NbKnots);
682 Loi->Mults(Mults->ChangeArray1());
683 BS = new (Geom_BSplineCurve) (Poles->Array1(),
684 Weigth->Array1(),
685 Knots->Array1(),
686 Mults->Array1(),
687 Degree,
688 Loi->IsUPeriodic());
689 PFirst = BS->Value( Knots->Value(Knots->Length()) );
690
691 Loi = myLaws->Value(I2);
692 Loi->SectionShape( NbPoles, NbKnots, Degree);
693 Poles = new (TColgp_HArray1OfPnt) (1, NbPoles);
694 Weigth = new (TColStd_HArray1OfReal) (1, NbPoles);
695 Loi->D0(Param, Poles->ChangeArray1(), Weigth->ChangeArray1());
696 Knots = new (TColStd_HArray1OfReal) (1, NbKnots);
697 Loi->Knots(Knots->ChangeArray1());
698 Mults = new (TColStd_HArray1OfInteger) (1, NbKnots);
699 Loi->Mults(Mults->ChangeArray1());
700 BS = new (Geom_BSplineCurve) (Poles->Array1(),
701 Weigth->Array1(),
702 Knots->Array1(),
703 Mults->Array1(),
704 Degree,
705 Loi->IsUPeriodic());
706 Tol += PFirst.Distance(BS->Value( Knots->Value(1)));
707 return Tol;
708}
709
710//=======================================================================
711//function : ConcatenedLaw
712//purpose :
713//=======================================================================
714
715 Handle(GeomFill_SectionLaw) BRepFill_NSections::ConcatenedLaw() const
716{
717 Handle(GeomFill_SectionLaw) Law;
718 if (myLaws->Length() == 1)
719 return myLaws->Value(1);
720 else {
721 Standard_Real Ufirst, Ulast, Vfirst, Vlast;
722 mySurface->Bounds(Ufirst, Ulast, Vfirst, Vlast);
723 TColGeom_SequenceOfCurve NCompo;
724 NCompo.Clear();
725 for (Standard_Integer jj=1; jj<=myShapes.Length(); jj++) {
726 NCompo.Append(mySurface->VIso(myParams(jj)));
727 }
d7325741 728 Law = new (GeomFill_NSections)(NCompo, myTrsfs, myParams,
7fd59977 729 Ufirst, Ulast,
730 Vfirst, Vlast,
731 mySurface);
732 }
733 return Law;
734}
735
736//=======================================================================
737//function : Continuity
738//purpose :
739//=======================================================================
740 GeomAbs_Shape BRepFill_NSections::Continuity(const Standard_Integer Index,
741 const Standard_Real TolAngular) const
742{
743
744 Standard_Integer jj;
745 GeomAbs_Shape cont_jj;
746#ifndef DEB
747 GeomAbs_Shape cont = GeomAbs_C0;
748#else
749 GeomAbs_Shape cont;
750#endif
751
752 for (jj=1; jj<=myShapes.Length(); jj++) {
753
754 TopoDS_Edge Edge1, Edge2;
755 if ( (Index==0) || (Index==myEdges->ColLength()) ) {
0d969553 756 if (!uclosed) return GeomAbs_C0; //The least possible error
7fd59977 757
758 Edge1 = TopoDS::Edge (myEdges->Value(myEdges->ColLength(),jj));
759 Edge2 = TopoDS::Edge (myEdges->Value(1,jj));
760 }
761 else {
762 Edge1 = TopoDS::Edge (myEdges->Value(Index,jj));
763 Edge2 = TopoDS::Edge (myEdges->Value(Index+1,jj));
764 }
765
766 TopoDS_Vertex V1,V2;
767 if ( Edge1.Orientation() == TopAbs_REVERSED) {
768 V1 = TopExp::FirstVertex(Edge1);
769 }
770 else {
771 V1 = TopExp::LastVertex(Edge1);
772 }
773 if ( Edge2.Orientation() == TopAbs_REVERSED) {
774 V2 = TopExp::LastVertex(Edge2);
775 }
776 else {
777 V2 = TopExp::FirstVertex(Edge2);
778 }
779
780 if (BRep_Tool::Degenerated(Edge1) || BRep_Tool::Degenerated(Edge2))
781 cont_jj = GeomAbs_CN;
782 else
783 {
784 Standard_Real U1 = BRep_Tool::Parameter(V1,Edge1);
785 Standard_Real U2 = BRep_Tool::Parameter(V2,Edge2);
786 BRepAdaptor_Curve Curve1(Edge1);
787 BRepAdaptor_Curve Curve2(Edge2);
788 Standard_Real Eps = BRep_Tool::Tolerance(V2) +
789 BRep_Tool::Tolerance(V1);
790 cont_jj = BRepLProp::Continuity(Curve1,Curve2,U1,U2, Eps, TolAngular);
791 }
792
793 if (jj==1) cont = cont_jj;
794 if (cont>cont_jj) cont = cont_jj;
795
796 }
797
798 return cont;
799}
800
801//=======================================================================
802//function : D0
803//purpose :
804//=======================================================================
805 void BRepFill_NSections::D0(const Standard_Real V, TopoDS_Shape& S)
806{
807 TopoDS_Wire W;
808 BRepLib_MakeWire MW;
809 Standard_Integer ii, NbEdge = myLaws->Length();
810 for (ii=1; ii<=NbEdge ; ii++) {
811 Handle(Geom_BSplineCurve) Curve
812 = Handle(Geom_BSplineCurve)::DownCast(myLaws->Value(ii)->BSplineSurface()->VIso(V));
813 Standard_Real first = Curve ->FirstParameter(),
814 last = Curve ->LastParameter();
815 TopoDS_Edge E = BRepLib_MakeEdge(Curve,first,last);
816 MW.Add(E);
817 }
818 TopAbs_Orientation Orien = TopAbs_FORWARD;
819 TopoDS_Shape aLocalShape = MW.Wire().Oriented(Orien);
820 S = TopoDS::Wire(aLocalShape);
821// S = TopoDS::Wire(MW.Wire().Oriented(Orien));
822
823}
824