0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / HLRTopoBRep / HLRTopoBRep_DSFiller.cxx
CommitLineData
b311480e 1// Created on: 1993-08-10
2// Created by: Christophe MARION
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
7fd59977 18#include <AppDef_BSplineCompute.hxx>
19#include <AppDef_MultiLine.hxx>
20#include <AppDef_MultiPointConstraint.hxx>
21#include <AppParCurves_MultiBSpCurve.hxx>
7fd59977 22#include <BRep_Builder.hxx>
42cf5bc1 23#include <BRep_CurveRepresentation.hxx>
24#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
25#include <BRep_TEdge.hxx>
26#include <BRep_Tool.hxx>
7fd59977 27#include <BRepAdaptor_Curve.hxx>
28#include <BRepAdaptor_Curve2d.hxx>
29#include <BRepAdaptor_HCurve2d.hxx>
42cf5bc1 30#include <BRepApprox_Approx.hxx>
31#include <BRepApprox_ApproxLine.hxx>
32#include <BRepExtrema_ExtPC.hxx>
7fd59977 33#include <BRepTopAdaptor_HVertex.hxx>
7fd59977 34#include <BRepTopAdaptor_Tool.hxx>
42cf5bc1 35#include <BRepTopAdaptor_TopolTool.hxx>
36#include <Contap_Contour.hxx>
e2065c2f 37#include <Contap_Line.hxx>
42cf5bc1 38#include <Contap_Point.hxx>
7fd59977 39#include <Extrema_LocateExtPC.hxx>
42cf5bc1 40#include <Geom2d_BSplineCurve.hxx>
41#include <Geom2d_Curve.hxx>
42#include <Geom_BSplineCurve.hxx>
43#include <Geom_Circle.hxx>
44#include <Geom_Line.hxx>
45#include <Geom_Surface.hxx>
46#include <GeomProjLib.hxx>
47#include <HLRTopoBRep_Data.hxx>
48#include <HLRTopoBRep_DSFiller.hxx>
49#include <HLRTopoBRep_FaceIsoLiner.hxx>
50#include <math_Vector.hxx>
7fd59977 51#include <Precision.hxx>
42cf5bc1 52#include <Standard_ProgramError.hxx>
53#include <TColgp_Array1OfPnt.hxx>
54#include <TColgp_Array1OfPnt2d.hxx>
55#include <TColStd_Array1OfInteger.hxx>
56#include <TColStd_Array1OfReal.hxx>
57#include <TopExp.hxx>
58#include <TopExp_Explorer.hxx>
59#include <TopoDS.hxx>
60#include <TopoDS_Edge.hxx>
61#include <TopoDS_Face.hxx>
62#include <TopoDS_Shape.hxx>
63#include <TopoDS_Vertex.hxx>
bda83605 64#include <TopTools_ListIteratorOfListOfShape.hxx>
7fd59977 65
7fd59977 66//=======================================================================
67//function : Insert
68//purpose : explore the faces and insert them
69//=======================================================================
70
71void HLRTopoBRep_DSFiller::Insert (const TopoDS_Shape& S,
72 Contap_Contour& FO,
73 HLRTopoBRep_Data& DS,
74 BRepTopAdaptor_MapOfShapeTool& MST,
75 const Standard_Integer nbIso)
76{
77 TopTools_MapOfShape ShapeMap;
78 TopExp_Explorer ex(S,TopAbs_FACE);
79 DS.Clear();
80 Standard_Boolean withPCurve = Standard_True; // instead of nbIso != 0;
81 Standard_Integer f = 0;
82
83 while (ex.More()) {
84 if (ShapeMap.Add(ex.Current())) {
85 f++;
86 TopoDS_Face S1 = TopoDS::Face(ex.Current());
87 S1.Orientation(TopAbs_FORWARD);
88 Handle(BRepTopAdaptor_TopolTool) Domain;
89 Handle(Adaptor3d_HSurface) Surface;
90 if(MST.IsBound(S1)) {
91 BRepTopAdaptor_Tool& BRT = MST.ChangeFind(S1);
92 Domain = BRT.GetTopolTool();
93 Surface = BRT.GetSurface();
94 }
95 else {
96 BRepTopAdaptor_Tool BRT(S1,Precision::PConfusion());
97 MST.Bind(S1,BRT);
98 Domain = BRT.GetTopolTool();
99 Surface = BRT.GetSurface();
100 }
bda83605 101 FO.Perform(Surface, Domain);
7fd59977 102 if (FO.IsDone()) {
103 if (!FO.IsEmpty())
104 InsertFace(f,S1,FO,DS,withPCurve);
105 }
106 if (nbIso != 0) HLRTopoBRep_FaceIsoLiner::Perform(f,S1,DS,nbIso);
107 }
108 ex.Next();
109 }
110 ProcessEdges(DS);
111}
112
113//=======================================================================
114//function : InsertFace
115//purpose : private, insert the outlines of a face
116//=======================================================================
117
35e08fe8 118void HLRTopoBRep_DSFiller::InsertFace (const Standard_Integer /*FI*/,
7fd59977 119 const TopoDS_Face& F,
120 Contap_Contour& FO,
121 HLRTopoBRep_Data& DS,
122 const Standard_Boolean withPCurve)
123{
124 // Insert the intersections of FO in DS
125
5c953701 126 const Standard_Real tol = BRep_Tool::Tolerance(F);
7fd59977 127 TopTools_ListOfShape& IntL = DS.AddIntL(F);
128 TopTools_ListOfShape& OutL = DS.AddOutL(F);
5c953701 129
7fd59977 130 TopoDS_Vertex VF,VL;
5c953701 131 /*
132 TopTools_MapOfShape VM;
7fd59977 133 TopExp_Explorer ex(F,TopAbs_EDGE);
7fd59977 134 while (ex.More()) {
135 const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
136 if (BRep_Tool::IsClosed(E,F)) {
137 TopExp::Vertices(E,VF,VL);
138 VM.Add(VF);
139 VM.Add(VL);
140 }
141 ex.Next();
142 }
5c953701 143 */
7fd59977 144
5c953701 145 const Standard_Integer NbLines = FO.NbLines();
bda83605 146 Standard_Integer CurLine;
147 for (CurLine = 1; CurLine <= NbLines; CurLine++)
5c953701 148 {
e2065c2f 149 const Contap_Line& Line = FO.Line(CurLine);
5c953701 150 const Standard_Integer NbPoints = Line.NbVertex();
7fd59977 151 Standard_Integer CurPoint;
5c953701 152 if (Line.TypeContour() == Contap_Restriction)
153 {
7fd59977 154 // OutLine on restriction
5c953701 155 TopoDS_Edge E = (*(BRepAdaptor_Curve2d*)&(Line.Arc()->Curve2d())).Edge();
7fd59977 156 OutL.Append(E);
157 TopExp::Vertices(E,VF,VL);
158 // insert the Internal points.
159
160 for (CurPoint = 1; CurPoint <= NbPoints; CurPoint++) {
e2065c2f 161 Contap_Point P = Line.Vertex(CurPoint);
5c953701 162 if (P.IsInternal()) {
163 if (P.Value().IsEqual(BRep_Tool::Pnt(VF),BRep_Tool::Tolerance(VF))) {
164 if (P.Value().IsEqual(BRep_Tool::Pnt(VL),BRep_Tool::Tolerance(VL))) {
165 InsertVertex(P,tol,E,DS);
166 }
167 }
168 }
7fd59977 169 }
170 }
5c953701 171 else
172 {
7fd59977 173 for (CurPoint = 1; CurPoint <= NbPoints; CurPoint++) {
7fd59977 174
e2065c2f 175 const Contap_Point PF = Line.Vertex(CurPoint);
5c953701 176 if (PF.IsInternal() && CurPoint != 1)
177 VF = VL;
178 else
179 VF = MakeVertex(PF,tol,DS);
180 const Standard_Real parF = PF.ParameterOnLine();
7fd59977 181
5c953701 182 if (CurPoint < NbPoints) {
e2065c2f 183 const Contap_Point PL = Line.Vertex(CurPoint+1);
5c953701 184 VL = MakeVertex(PL,tol,DS);
185 const Standard_Real parL = PL.ParameterOnLine();
186
187 if( (parL-parF) > Precision::PConfusion() ) {
188
189 Handle(Geom_Curve) C;
190 Handle(Geom2d_Curve) C2d;
191 Standard_Real first = parF;
192 Standard_Real last = parL;
193 Standard_Boolean InsuffisantNumberOfPoints=Standard_False;
194
195 switch (Line.TypeContour()) {
7fd59977 196
5c953701 197 case Contap_Lin :
198 {
199 C = new Geom_Line(Line.Line());
200 if (withPCurve) {
201 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
202 Standard_Real Tol = 1e-7;
203 C2d = GeomProjLib::Curve2d(C,first,last,S,Tol);
204 }
205 }
206 break;
7fd59977 207
5c953701 208 case Contap_Circle :
209 {
210 C = new Geom_Circle(Line.Circle());
211 if (withPCurve) {
212 TopLoc_Location Loc;
213 Handle(Geom_Surface) S = BRep_Tool::Surface(F,Loc);
214 if (!Loc.IsIdentity()) {
215 S = Handle(Geom_Surface)::DownCast(S->Transformed(Loc.Transformation()));
216 }
217 Standard_Real Tol = 1e-7;
218 C2d = GeomProjLib::Curve2d(C,first,last,S,Tol);
219 }
220 }
221 break;
7fd59977 222
5c953701 223 case Contap_Walking :
224 {
225 // copy the points
226 Standard_Integer ipF = Standard_Integer(parF);
227 Standard_Integer ipL = Standard_Integer(parL);
7fd59977 228
5c953701 229 if(ipL-ipF < 1) {
230 InsuffisantNumberOfPoints=Standard_True;
04232180 231 //std::cout<<"\n !! Pb ds HLRTopoBRep_DSFiller.cxx (Contour App Nbp <3)"<<std::endl;
5c953701 232 }
233/*
7fd59977 234 else if(ipL-ipF < 6) {
235 // compute the tangents
e2065c2f 236 Contap_SurfFunction& SFunc =
7fd59977 237 FO.SurfaceFunction();
238
239 Standard_Boolean isTg1,isTg2;
240 gp_Vec tg1,tg2;
241 gp_Vec2d uv1,uv2;
242 math_Vector UV(1,2),F(1,1);
243
244 Line.Point(ipF).ParametersOnS2(UV(1),UV(2));
245 SFunc.Value(UV,F);
246 isTg1 = SFunc.IsTangent();
247 if (!isTg1) {
248 tg1 = SFunc.Direction3d();
249 if (withPCurve) uv1 = SFunc.Direction2d();
250 }
251
252 Line.Point(ipL).ParametersOnS2(UV(1),UV(2));
253 SFunc.Value(UV,F);
254 isTg2 = SFunc.IsTangent();
255 if (!isTg2) {
256 tg2 = SFunc.Direction3d();
257 if (withPCurve) uv2 = SFunc.Direction2d();
258 }
259 // interpolate
260 Standard_Integer nbp = ipL - ipF + 1;
261 AppDef_MultiLine MLine(nbp);
262 Standard_Integer nb2d = 0;
263 if (withPCurve) nb2d = 1;
264
265 for (Standard_Integer i = 1; i <= nbp; i++) {
266 AppDef_MultiPointConstraint MP(1, nb2d);
267 MP.SetPoint(1,Line.Point(i + ipF - 1).Value());
268 if (withPCurve) {
269 Line.Point(i + ipF - 1).ParametersOnS2(UV(1),UV(2));
270 MP.SetPoint2d(2,gp_Pnt2d(UV(1),UV(2)));
271 }
272
273 if (i == 1 && !isTg1) {
274 MP.SetTang (1,tg1);
275 if (withPCurve) MP.SetTang2d(2,uv1);
276 }
277 if (i == nbp && !isTg2) {
278 MP.SetTang (1,tg2);
279 if (withPCurve) MP.SetTang2d(2,uv2);
280 }
281 MLine.SetValue(i,MP);
282 }
283 AppDef_BSplineCompute interp;
284 interp.Interpol(MLine);
285 AppParCurves_MultiBSpCurve TheCurve = interp.Value();
286 Standard_Integer Degree = TheCurve.Degree();
287 TColgp_Array1OfPnt Poles(1,TheCurve.NbPoles());
288 TheCurve.Curve(1,Poles);
289 C = new Geom_BSplineCurve(Poles,
290 TheCurve.Knots(),
291 TheCurve.Multiplicities(),
292 Degree);
293 if (withPCurve) {
294 TColgp_Array1OfPnt2d Pol2d(1,TheCurve.NbPoles());
295 TheCurve.Curve(2,Pol2d);
296 C2d = new Geom2d_BSplineCurve(Pol2d,
297 TheCurve.Knots(),
298 TheCurve.Multiplicities(),
299 Degree);
300 }
301 first = 0;
302 last = 1;
303 }
5c953701 304*/
305 else if(ipL-ipF < 5) {
306 const Standard_Integer nbp = ipL - ipF + 1;
307 TColStd_Array1OfReal knots(1,nbp);
308 TColStd_Array1OfInteger mults(1,nbp);
309 TColgp_Array1OfPnt Points(1,nbp);
7fd59977 310
5c953701 311 for(Standard_Integer i=1;i<=nbp;i++) {
312 knots.SetValue(i,(Standard_Real)i);
313 mults.SetValue(i,1);
314 Points.SetValue(i,Line.Point(i+ipF-1).Value());
315 }
316 mults(1)=mults(nbp)=2;
317 C = new Geom_BSplineCurve(Points,knots,mults,1);
7fd59977 318
5c953701 319 if(withPCurve) {
320 TColgp_Array1OfPnt2d Points2d(1,nbp);
321 for(Standard_Integer i=1;i<=nbp;i++) {
322 Standard_Real u,v;
323 Line.Point(i+ipF-1).ParametersOnS2(u,v);
324 Points2d.SetValue(i,gp_Pnt2d(u,v));
325 }
326 C2d = new Geom2d_BSplineCurve(Points2d,knots,mults,1);
327 }
328 first = 1;
329 last = nbp;
330 }
331 else {
332 const Standard_Integer nbp = ipL - ipF + 1;
333 TColStd_Array1OfReal knots(1,nbp);
334 TColStd_Array1OfInteger mults(1,nbp);
335 TColgp_Array1OfPnt Points(1,nbp);
336
337 Standard_Real Maxx,Maxy,Maxz,Maxu,Maxv;
338 Standard_Real Minx,Miny,Minz,Minu,Minv;
339 Maxx=Maxy=Maxz=Maxu=Maxv=-RealLast();
340 Minx=Miny=Minz=Minu=Minv=RealLast();
7fd59977 341
5c953701 342 for(Standard_Integer i=1;i<=nbp;i++) {
343 knots.SetValue(i,(Standard_Real)i);
344 mults.SetValue(i,1);
345 const gp_Pnt& P= Line.Point(i+ipF-1).Value();
346 if(P.X()<Minx) Minx=P.X();
347 if(P.Y()<Miny) Miny=P.Y();
348 if(P.Z()<Minz) Minz=P.Z();
349 if(P.X()>Maxx) Maxx=P.X();
350 if(P.Y()>Maxy) Maxy=P.Y();
351 if(P.Z()>Maxz) Maxz=P.Z();
352 Points.SetValue(i,P);
353 }
354 mults(1)=mults(nbp)=2;
355 Handle(Geom_BSplineCurve) AppC;
356 Handle(Geom2d_BSplineCurve) AppC2d;
357 AppC = new Geom_BSplineCurve(Points,knots,mults,1);
358
359 if(withPCurve) {
360 TColgp_Array1OfPnt2d Points2d(1,nbp);
361 for(Standard_Integer i=1;i<=nbp;i++) {
362 Standard_Real u,v;
363 Line.Point(i+ipF-1).ParametersOnS2(u,v);
364 if(u<Minu) Minu=u;
365 if(v<Minv) Minv=v;
366 if(u>Maxu) Maxu=u;
367 if(v>Maxv) Maxv=v;
368 Points2d.SetValue(i,gp_Pnt2d(u,v));
369 }
370 AppC2d = new Geom2d_BSplineCurve(Points2d,knots,mults,1);
371 }
372 first = 1;
373 last = nbp;
7fd59977 374
5c953701 375 Handle(BRepApprox_ApproxLine) AppLine;
376 Handle(Geom2d_BSplineCurve) CNull;
377 AppLine = new BRepApprox_ApproxLine(AppC,AppC2d,CNull);
7fd59977 378
5c953701 379 Standard_Integer dmin=4,dmax=8,niter=0;
380 Standard_Boolean tg= Standard_False;
381 BRepApprox_Approx Approx;
382 Standard_Real TOL3d,TOL2d,TOL=0.0001;
7fd59977 383
5c953701 384 Maxx-=Minx; Maxy-=Miny; Maxz-=Minz;
385 Maxu-=Minu; Maxv-=Minv;
386 if(Maxy>Maxx) Maxx=Maxy;
387 if(Maxz>Maxx) Maxx=Maxy;
388 if(Maxv>Maxu) Maxu=Maxv;
7fd59977 389
5c953701 390 TOL3d=TOL*Maxx; if(TOL3d<1e-12) TOL3d=1e-12; else if(TOL3d>0.1) TOL3d=0.1;
391 TOL2d=TOL*Maxu; if(TOL2d<1e-12) TOL2d=1e-12; else if(TOL2d>0.1) TOL2d=0.1;
7fd59977 392
04232180 393 //-- std::cout<<"\nHLRTopoBRep_DSFiller : nbp="<<nbp<<" Tol3d="<<TOL3d<<" Tol2d="<<TOL2d<<std::endl;
7fd59977 394
4e14c88f 395 Approx.SetParameters(TOL3d, TOL2d, dmin, dmax, niter, 30, tg);
5c953701 396 Approx.Perform(AppLine,Standard_True,Standard_True,Standard_False,1,nbp);
397 if (!Approx.IsDone()) {
398 C = AppC;
399 C2d=AppC2d;
400 first = 1;
401 last = nbp;
402 }
403 else {
404 const AppParCurves_MultiBSpCurve& AppVal = Approx.Value(1);
405 TColgp_Array1OfPnt poles3d(1,AppVal.NbPoles());
406 AppVal.Curve(1,poles3d);
407 C = new Geom_BSplineCurve(poles3d,AppVal.Knots(),AppVal.Multiplicities(),AppVal.Degree());
7fd59977 408
5c953701 409 const AppParCurves_MultiBSpCurve& AppVal2 = Approx.Value(2);
410 TColgp_Array1OfPnt2d poles2d(1,AppVal2.NbPoles());
411 AppVal2.Curve(2,poles2d);
412 C2d = new Geom2d_BSplineCurve(poles2d,AppVal2.Knots(),AppVal2.Multiplicities(),AppVal2.Degree());
413 first = C2d->FirstParameter();
414 last = C2d->LastParameter();
415 }
416 }
417 }
418 break;
7fd59977 419
5c953701 420 case Contap_Restriction :
421 {
9775fa61 422 throw Standard_ProgramError("HLRTopoBRep_DSFiller::InsertFace : Restriction");
5c953701 423 }
424 break;
425 }
7fd59977 426
5c953701 427 // compute the PCurve
428 // make the edge
429 if (!InsuffisantNumberOfPoints) {
430 TopoDS_Edge E;
431 BRep_Builder B;
432 B.MakeEdge(E,C,tol);
433 VF.Orientation(TopAbs_FORWARD);
434 VL.Orientation(TopAbs_REVERSED);
435 B.Add(E,VF);
436 B.Add(E,VL);
437 B.Range(E,first,last);
438
439 if (!C2d.IsNull()) {
5c953701 440 B.UpdateEdge(E,C2d,F,BRep_Tool::Tolerance(F));
441 }
7fd59977 442
5c953701 443 // add the edge in the DS
444 if (!E.IsNull())
445 IntL.Append(E);
446 }
447 }
448 }
7fd59977 449 }
450 }
451 }
854e0d4a 452
453 //Correction of internal outlines: unite coinciding vertices
454 const Standard_Real SqTol = tol*tol;
455 TopTools_ListIteratorOfListOfShape itl1(IntL);
456 for (; itl1.More(); itl1.Next())
457 {
458 TopoDS_Edge anIntLine = TopoDS::Edge(itl1.Value());
459 anIntLine.Orientation(TopAbs_FORWARD);
460 TopoDS_Vertex aVer [2];
461 TopExp::Vertices(anIntLine, aVer[0], aVer[1]);
462 TopTools_ListIteratorOfListOfShape itl2 = itl1;
463 for (; itl2.More(); itl2.Next())
464 {
465 TopoDS_Edge anIntLine2 = TopoDS::Edge(itl2.Value());
466 anIntLine2.Orientation(TopAbs_FORWARD);
467 if (anIntLine2.IsSame(anIntLine))
468 continue;
469 TopoDS_Vertex aVer2 [2];
470 TopExp::Vertices(anIntLine2, aVer2[0], aVer2[1]);
471 for (Standard_Integer i = 0; i < 2; i++)
472 {
473 if (i == 1 && aVer[0].IsSame(aVer[1]))
474 continue;
475 gp_Pnt Pnt1 = BRep_Tool::Pnt(aVer[i]);
476 for (Standard_Integer j = 0; j < 2; j++)
477 {
478 if (aVer[i].IsSame(aVer2[j]))
479 continue;
480 gp_Pnt Pnt2 = BRep_Tool::Pnt(aVer2[j]);
481 if (Pnt1.SquareDistance(Pnt2) <= SqTol)
482 {
483 BRep_Builder aBB;
484 aBB.Remove(anIntLine2, aVer2[j]);
485 aVer[i].Orientation((j==0)? TopAbs_FORWARD : TopAbs_REVERSED);
486 aBB.Add(anIntLine2, aVer[i]);
487 }
488 }
489 }
490 }
491 }
7fd59977 492}
493
494//=======================================================================
495//function : MakeVertex
496//purpose : private, make a vertex from an intersection point
497//=======================================================================
498
499TopoDS_Vertex
e2065c2f 500HLRTopoBRep_DSFiller::MakeVertex (const Contap_Point& P,
7fd59977 501 const Standard_Real tol,
502 HLRTopoBRep_Data& DS)
503{
504 BRep_Builder B;
505 TopoDS_Vertex V;
506 if (P.IsVertex()) {
507 V = Handle(BRepTopAdaptor_HVertex)::DownCast(P.Vertex())->Vertex();
508 DS.AddOutV(V);
509 }
510 else {
511 // if on arc, insert in the DS
512 if (P.IsOnArc()) {
513 const TopoDS_Edge& E =
514 (*(BRepAdaptor_Curve2d*)&((P.Arc())->Curve2d())).Edge();
515 Standard_Real Par = P.ParameterOnArc();
516 const gp_Pnt& P3d = P.Value();
517
518 for (DS.InitVertex(E); DS.MoreVertex(); DS.NextVertex()) {
519 TopoDS_Vertex curV = DS.Vertex();
520 Standard_Real curP = DS.Parameter();
521 const gp_Pnt& PPP=BRep_Tool::Pnt(curV);
522 Standard_Real TTT=BRep_Tool::Tolerance(curV);
523 if (P3d.IsEqual(PPP,TTT)) {
524 V = curV;
525 break;
526 }
527 else if (Par < curP) {
528 B.MakeVertex(V,P.Value(),tol);
529 DS.InsertBefore(V,Par);
530 break;
531 }
532 }
533 if (!DS.MoreVertex()) {
534 B.MakeVertex(V,P.Value(),tol);
535 DS.Append(V,Par);
536 }
537 DS.AddOutV(V);
538 }
539 // if internal create a vertex and insert in the DS
540 else {
541 B.MakeVertex(V,P.Value(),tol);
542 if (P.IsInternal())
543 DS.AddIntV(V);
544 else
545 DS.AddOutV(V);
546 }
547 }
548 return V;
549}
550
551//=======================================================================
552//function : InsertVertex
553//purpose : private, insert a vertex from an internal intersection point
554// on resctriction
555//=======================================================================
556
557void
e2065c2f 558HLRTopoBRep_DSFiller::InsertVertex (const Contap_Point& P,
7fd59977 559 const Standard_Real tol,
560 const TopoDS_Edge& E,
561 HLRTopoBRep_Data& DS)
562{
563 BRep_Builder B;
564 TopoDS_Vertex V;
565
566 if (P.IsVertex()) {
567 V = Handle(BRepTopAdaptor_HVertex)::DownCast(P.Vertex())->Vertex();
568 }
569 else {
570 Standard_Real Par = P.ParameterOnLine();
571
572 for (DS.InitVertex(E); DS.MoreVertex(); DS.NextVertex()) {
573 TopoDS_Vertex curV = DS.Vertex();
574 Standard_Real curP = DS.Parameter();
575 if (P.Value().IsEqual(BRep_Tool::Pnt(curV),
576 BRep_Tool::Tolerance(curV))) {
577 V = curV;
578 break;
579 }
580 else if (Par < curP) {
581 B.MakeVertex(V,P.Value(),tol);
582 DS.InsertBefore(V,Par);
583 break;
584 }
585 }
586 if (!DS.MoreVertex()) {
587 B.MakeVertex(V,P.Value(),tol);
588 DS.Append(V,Par);
589 }
590 }
591 DS.AddIntV(V);
592}
593
594//=======================================================================
595//function : ProcessEdges
596//purpose : private, split edges with outline vertices
597//=======================================================================
598
599void HLRTopoBRep_DSFiller::ProcessEdges (HLRTopoBRep_Data& DS)
600{
601 BRep_Builder B;
602 TopoDS_Edge newE;
603 TopoDS_Vertex VF,VL,VI;
604 Standard_Real PF,PL,PI;
605
606 for (DS.InitEdge(); DS.MoreEdge(); DS.NextEdge()) {
607 TopoDS_Edge E = DS.Edge();
608 TopTools_ListOfShape& SplE = DS.AddSplE(E);
609 VF = TopExp::FirstVertex(E);
610 VL = TopExp::LastVertex(E);
611 BRep_Tool::Range(E,PF,PL);
612 VF.Orientation(TopAbs_FORWARD);
613 VL.Orientation(TopAbs_REVERSED);
614
615 for (DS.InitVertex(E); DS.MoreVertex(); DS.NextVertex()) {
616 VI = DS.Vertex();
617 PI = DS.Parameter();
618 VI.Orientation(TopAbs_REVERSED);
619 newE = E;
620 newE.EmptyCopy();
621 newE.Orientation(TopAbs_FORWARD);
622 B.Add(newE,VF);
623 B.UpdateVertex(VF,PF,newE,BRep_Tool::Tolerance(VF));
624 B.Add(newE,VI);
625 B.UpdateVertex(VI,PI,newE,BRep_Tool::Tolerance(VI));
626 newE.Orientation(E.Orientation());
627 SplE.Append(newE);
628 VF = VI;
629 PF = PI;
630 VF.Orientation(TopAbs_FORWARD);
631 }
632 newE = E;
633 newE.EmptyCopy();
634 newE.Orientation(TopAbs_FORWARD);
635 B.Add(newE,VF);
636 B.UpdateVertex(VF,PF,newE,BRep_Tool::Tolerance(VF));
637 B.Add(newE,VL);
638 B.UpdateVertex(VL,PL,newE,BRep_Tool::Tolerance(VL));
639 newE.Orientation(E.Orientation());
640 SplE.Append(newE);
641 }
642}
643