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