1 // Created on: 1996-06-03
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578
26 #define OPTIMISATION 1
29 #include <IntCurvesFace_Intersector.ixx>
31 #include <IntCurveSurface_ThePolyhedronToolOfHInter.hxx>
32 #include <Bnd_BoundSortBox.hxx>
34 #include <IntCurveSurface_IntersectionPoint.hxx>
36 #include <TopoDS_Face.hxx>
40 #include <IntCurveSurface_HInter.hxx>
41 #include <BRepAdaptor_HSurface.hxx>
42 #include <Geom_Line.hxx>
43 #include <gp_Pnt2d.hxx>
44 #include <BRepClass_FaceClassifier.hxx>
46 #include <GeomAdaptor_Curve.hxx>
48 #include <GeomAdaptor_HCurve.hxx>
49 #include <BRepAdaptor_HSurface.hxx>
53 #include <Adaptor3d_HSurfaceTool.hxx>
54 #include <IntCurveSurface_TheHCurveTool.hxx>
55 #include <Adaptor3d_HCurve.hxx>
56 #include <Bnd_Box.hxx>
57 #include <Intf_Tool.hxx>
58 #include <IntCurveSurface_ThePolyhedronOfHInter.hxx>
59 #include <IntCurveSurface_ThePolygonOfHInter.hxx>
60 #include <IntCurveSurface_SequenceOfPnt.hxx>
64 GeomAbs_SurfaceType IntCurvesFace_Intersector::SurfaceType() const {
65 return(Adaptor3d_HSurfaceTool::GetType(Hsurface));
69 //============================================================================
70 IntCurvesFace_Intersector::IntCurvesFace_Intersector(const TopoDS_Face& Face,
71 const Standard_Real aTol)
73 Tol(aTol),done(Standard_False),nbpnt(0),PtrOnPolyhedron(NULL),PtrOnBndBounding(NULL)
75 BRepAdaptor_Surface surface;
77 surface.Initialize(Face,Standard_True);
78 Hsurface = new BRepAdaptor_HSurface(surface);
79 myTopolTool = new BRepTopAdaptor_TopolTool(Hsurface);
81 GeomAbs_SurfaceType SurfaceType = Adaptor3d_HSurfaceTool::GetType(Hsurface);
82 if( (SurfaceType != GeomAbs_Plane)
83 && (SurfaceType != GeomAbs_Cylinder)
84 && (SurfaceType != GeomAbs_Cone)
85 && (SurfaceType != GeomAbs_Sphere)
86 && (SurfaceType != GeomAbs_Torus)) {
87 Standard_Integer nbsu,nbsv;
88 Standard_Real U0,V0,U1,V1;
89 U0 = Hsurface->FirstUParameter();
90 U1 = Hsurface->LastUParameter();
91 V0 = Hsurface->FirstVParameter();
92 V1 = Hsurface->LastVParameter();
93 //-- nbsu = Adaptor3d_HSurfaceTool::NbSamplesU(Hsurface,U0,U1);
94 //-- nbsv = Adaptor3d_HSurfaceTool::NbSamplesV(Hsurface,V0,V1);
95 nbsu = myTopolTool->NbSamplesU();
96 nbsv = myTopolTool->NbSamplesV();
97 if(nbsu>40) nbsu = 40;
98 if(nbsv>40) nbsv = 40;
99 //-- printf("\n IntCurvesFace_Intersector : nbsu=(%3d)->%3d nbsv=(%3d)->%3d",myTopolTool->NbSamplesU(),nbsu,myTopolTool->NbSamplesV(),nbsv);
100 PtrOnPolyhedron = (IntCurveSurface_ThePolyhedronOfHInter *) new IntCurveSurface_ThePolyhedronOfHInter(Hsurface,nbsu,nbsv,U0,V0,U1,V1);
103 //============================================================================
105 void IntCurvesFace_Intersector::InternalCall(const IntCurveSurface_HInter &HICS,
106 const Standard_Real parinf,const Standard_Real parsup) {
108 for(Standard_Integer index=HICS.NbPoints(); index>=1; index--) {
109 const IntCurveSurface_IntersectionPoint& HICSPointindex = HICS.Point(index);
110 gp_Pnt2d Puv(HICSPointindex.U(),HICSPointindex.V());
112 TopAbs_State currentstate = myTopolTool->Classify(Puv,Tol);
113 if(currentstate==TopAbs_IN || currentstate==TopAbs_ON) {
114 Standard_Real HICSW = HICSPointindex.W();
115 if(HICSW >= parinf && HICSW <= parsup ) {
116 Standard_Real U = HICSPointindex.U();
117 Standard_Real V = HICSPointindex.V();
118 Standard_Real W = HICSW;
119 IntCurveSurface_TransitionOnCurve transition = HICSPointindex.Transition();
120 gp_Pnt pnt = HICSPointindex.Pnt();
121 // state = currentstate;
122 // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin
123 Standard_Integer anIntState = (currentstate == TopAbs_IN) ? 0 : 1;
124 // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End
126 if(transition != IntCurveSurface_Tangent && face.Orientation()==TopAbs_REVERSED) {
127 if(transition == IntCurveSurface_In)
128 transition = IntCurveSurface_Out;
130 transition = IntCurveSurface_In;
132 //----- Insertion du point
134 IntCurveSurface_IntersectionPoint PPP(pnt,U,V,W,transition);
136 // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin
137 mySeqState.Append(anIntState);
138 // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End
141 Standard_Integer i = 1;
142 Standard_Integer b = nbpnt+1;
144 const IntCurveSurface_IntersectionPoint& Pnti=SeqPnt.Value(i);
145 Standard_Real wi = Pnti.W();
146 if(wi >= W) { b=i; i=nbpnt; }
149 IntCurveSurface_IntersectionPoint PPP(pnt,U,V,W,transition);
150 // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin
151 // if(b>nbpnt) { SeqPnt.Append(PPP); }
152 // else if(b>0) { SeqPnt.InsertBefore(b,PPP); }
155 mySeqState.Append(anIntState);
157 SeqPnt.InsertBefore(b,PPP);
158 mySeqState.InsertBefore(b, anIntState);
160 // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End
166 } //-- classifier state is IN or ON
167 } //-- Loop on Intersection points.
171 //--------------------------------------------------------------------------------
176 void IntCurvesFace_Intersector::Perform(const gp_Lin& L,const Standard_Real ParMin,const Standard_Real ParMax) {
177 done = Standard_True;
179 // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin
181 // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End
183 IntCurveSurface_HInter HICS;
185 Handle(Geom_Line) geomline = new Geom_Line(L);
186 GeomAdaptor_Curve LL(geomline);
189 Handle(GeomAdaptor_HCurve) HLL = new GeomAdaptor_HCurve(LL);
191 Standard_Real parinf=ParMin;
192 Standard_Real parsup=ParMax;
194 if(PtrOnPolyhedron == NULL) {
195 HICS.Perform(HLL,Hsurface);
200 bndTool.LinBox(L,((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron)->Bounding(),boxLine);
201 if(bndTool.NbSegments() == 0)
203 for(Standard_Integer nbseg=1; nbseg<= bndTool.NbSegments(); nbseg++) {
204 Standard_Real pinf = bndTool.BeginParam(nbseg);
205 Standard_Real psup = bndTool.EndParam(nbseg);
206 Standard_Real pppp = 0.05*(psup-pinf);
209 if((psup - pinf)<1e-10) { pinf-=1e-10; psup+=1e-10; }
210 if(nbseg==1) { parinf=pinf; parsup=psup; }
212 if(parinf>pinf) parinf = pinf;
213 if(parsup<psup) parsup = psup;
216 if(parinf>ParMax) { return; }
217 if(parsup<ParMin) { return; }
218 if(parinf<ParMin) parinf=ParMin;
219 if(parsup>ParMax) parsup=ParMax;
220 if(parinf>(parsup-1e-9)) return;
221 IntCurveSurface_ThePolygonOfHInter polygon(HLL,
226 if(PtrOnBndBounding==NULL) {
227 PtrOnBndBounding = (Bnd_BoundSortBox *) new Bnd_BoundSortBox();
228 IntCurveSurface_ThePolyhedronOfHInter *thePolyh=(IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron;
229 ((Bnd_BoundSortBox *)(PtrOnBndBounding))->Initialize(IntCurveSurface_ThePolyhedronToolOfHInter::Bounding(*thePolyh),
230 IntCurveSurface_ThePolyhedronToolOfHInter::ComponentsBounding(*thePolyh));
235 *((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron),
236 *((Bnd_BoundSortBox *)PtrOnBndBounding));
241 *((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron));
245 InternalCall(HICS,parinf,parsup);
249 for(Standard_Integer index=HICS.NbPoints(); index>=1; index--) {
250 const IntCurveSurface_IntersectionPoint& HICSPointindex = HICS.Point(index);
251 gp_Pnt2d Puv(HICSPointindex.U(),HICSPointindex.V());
253 TopAbs_State currentstate = myTopolTool->Classify(Puv,Tol);
254 if(currentstate==TopAbs_IN || currentstate==TopAbs_ON) {
255 Standard_Real HICSW = HICSPointindex.W();
256 if(HICSW >= parinf && HICSW <= parsup ) {
257 Standard_Real U = HICSPointindex.U();
258 Standard_Real V = HICSPointindex.V();
259 Standard_Real W = HICSW;
260 IntCurveSurface_TransitionOnCurve transition = HICSPointindex.Transition();
261 gp_Pnt pnt = HICSPointindex.Pnt();
262 // state = currentstate;
263 // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin
264 Standard_Integer anIntState = (currentstate == TopAbs_IN) ? 0 : 1;
265 // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End
267 if(face.Orientation()==TopAbs_REVERSED) {
268 if(transition == IntCurveSurface_In)
269 transition = IntCurveSurface_Out;
271 transition = IntCurveSurface_In;
273 //----- Insertion du point
275 IntCurveSurface_IntersectionPoint PPP(pnt,U,V,W,transition);
277 // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin
278 mySeqState.Append(anIntState);
279 // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End
282 Standard_Integer i = 1;
283 Standard_Integer b = nbpnt+1;
285 const IntCurveSurface_IntersectionPoint& Pnti=SeqPnt.Value(i);
286 Standard_Real wi = Pnti.W();
287 if(wi >= W) { b=i; i=nbpnt; }
290 IntCurveSurface_IntersectionPoint PPP(pnt,U,V,W,transition);
291 // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin
292 // if(b>nbpnt) { SeqPnt.Append(PPP); }
293 // else if(b>0) { SeqPnt.InsertBefore(b,PPP); }
296 mySeqState.Append(anIntState);
298 SeqPnt.InsertBefore(b,PPP);
299 mySeqState.InsertBefore(b, anIntState);
301 // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End
307 } //-- classifier state is IN or ON
308 } //-- Loop on Intersection points.
315 //============================================================================
316 void IntCurvesFace_Intersector::Perform(const Handle(Adaptor3d_HCurve)& HCu,const Standard_Real ParMin,const Standard_Real ParMax) {
317 done = Standard_True;
319 // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin
321 // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End
323 IntCurveSurface_HInter HICS;
326 Standard_Real parinf=ParMin;
327 Standard_Real parsup=ParMax;
329 if(PtrOnPolyhedron == NULL) {
330 HICS.Perform(HCu,Hsurface);
333 parinf = IntCurveSurface_TheHCurveTool::FirstParameter(HCu);
334 parsup = IntCurveSurface_TheHCurveTool::LastParameter(HCu);
335 if(parinf<ParMin) parinf = ParMin;
336 if(parsup>ParMax) parsup = ParMax;
337 if(parinf>(parsup-1e-9)) return;
338 Standard_Integer nbs;
339 nbs = IntCurveSurface_TheHCurveTool::NbSamples(HCu,parinf,parsup);
341 IntCurveSurface_ThePolygonOfHInter polygon(HCu,
346 if(PtrOnBndBounding==NULL) {
347 PtrOnBndBounding = (Bnd_BoundSortBox *) new Bnd_BoundSortBox();
348 IntCurveSurface_ThePolyhedronOfHInter *thePolyh=(IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron;
349 ((Bnd_BoundSortBox *)(PtrOnBndBounding))->Initialize(IntCurveSurface_ThePolyhedronToolOfHInter::Bounding(*thePolyh),
350 IntCurveSurface_ThePolyhedronToolOfHInter::ComponentsBounding(*thePolyh));
355 *((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron),
356 *((Bnd_BoundSortBox *)PtrOnBndBounding));
361 *((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron));
364 InternalCall(HICS,parinf,parsup);
367 //============================================================================
368 Bnd_Box IntCurvesFace_Intersector::Bounding() const {
369 if(PtrOnPolyhedron !=NULL) {
370 return(((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron)->Bounding());
377 TopAbs_State IntCurvesFace_Intersector::ClassifyUVPoint(const gp_Pnt2d& Puv) const {
378 TopAbs_State state = myTopolTool->Classify(Puv,1e-7);
381 //============================================================================
382 void IntCurvesFace_Intersector::Destroy() {
383 if(PtrOnPolyhedron !=NULL) {
384 delete (IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron;
385 PtrOnPolyhedron = NULL;
387 if(PtrOnBndBounding !=NULL) {
388 delete (Bnd_BoundSortBox *)PtrOnBndBounding;
389 PtrOnBndBounding=NULL;