1 // Created on: 1995-08-07
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor2d_Curve2d.hxx>
19 #include <Adaptor3d_IsoCurve.hxx>
20 #include <Bnd_Box.hxx>
21 #include <Bnd_Box2d.hxx>
22 #include <BndLib_Add2dCurve.hxx>
23 #include <BRepAdaptor_HSurface.hxx>
24 #include <GCPnts_QuasiUniformDeflection.hxx>
25 #include <Geom_BezierSurface.hxx>
26 #include <Geom_BSplineSurface.hxx>
27 #include <Geom_Surface.hxx>
28 #include <GeomAbs_SurfaceType.hxx>
29 #include <GeomAdaptor_Curve.hxx>
31 #include <gp_Pnt2d.hxx>
32 #include <Graphic3d_ArrayOfPolylines.hxx>
33 #include <Graphic3d_AspectLine3d.hxx>
34 #include <Graphic3d_Group.hxx>
35 #include <Hatch_Hatcher.hxx>
36 #include <Precision.hxx>
37 #include <Prs3d_IsoAspect.hxx>
38 #include <Prs3d_Presentation.hxx>
39 #include <StdPrs_DeflectionCurve.hxx>
40 #include <StdPrs_ToolRFace.hxx>
41 #include <StdPrs_WFDeflectionRestrictedFace.hxx>
42 #include <TColgp_SequenceOfPnt2d.hxx>
44 #ifdef OCCT_DEBUG_MESH
45 #include <OSD_Chronometer.hxx>
46 extern OSD_Chronometer FFaceTimer1,FFaceTimer2,FFaceTimer3,FFaceTimer4;
50 //==================================================================
51 // function: FindLimits
53 //==================================================================
54 static void FindLimits(const Adaptor3d_Curve& aCurve,
55 const Standard_Real aLimit,
59 First = Max(aCurve.FirstParameter(), First);
60 Last = Min(aCurve.LastParameter(), Last);
61 Standard_Boolean firstInf = Precision::IsNegativeInfinite(First);
62 Standard_Boolean lastInf = Precision::IsPositiveInfinite(Last);
64 if (firstInf || lastInf) {
66 Standard_Real delta = 1;
67 if (firstInf && lastInf) {
74 } while (P1.Distance(P2) < aLimit);
82 } while (P1.Distance(P2) < aLimit);
90 } while (P1.Distance(P2) < aLimit);
97 //=========================================================================
100 //=========================================================================
101 void StdPrs_WFDeflectionRestrictedFace::Add
102 (const Handle (Prs3d_Presentation)& aPresentation,
103 const Handle(BRepAdaptor_HSurface)& aFace,
104 const Standard_Boolean DrawUIso,
105 const Standard_Boolean DrawVIso,
106 const Quantity_Length Deflection,
107 const Standard_Integer NBUiso,
108 const Standard_Integer NBViso,
109 const Handle(Prs3d_Drawer)& aDrawer,
110 Prs3d_NListOfSequenceOfPnt& Curves) {
112 #ifdef OCCT_DEBUG_MESH
116 StdPrs_ToolRFace ToolRst (aFace);
117 Standard_Real UF, UL, VF, VL;
118 UF = aFace->FirstUParameter();
119 UL = aFace->LastUParameter();
120 VF = aFace->FirstVParameter();
121 VL = aFace->LastVParameter();
123 Standard_Real aLimit = aDrawer->MaximalParameterValue();
125 // compute bounds of the restriction
126 Standard_Real UMin,UMax,VMin,VMax;
127 //Standard_Real u,v,step;
128 Standard_Integer i;//,nbPoints = 10;
130 UMin = Max(UF, -aLimit);
131 UMax = Min(UL, aLimit);
132 VMin = Max(VF, -aLimit);
133 VMax = Min(VL, aLimit);
136 // update min max for the hatcher.
138 Standard_Real U1, U2;
140 Standard_Real ddefle= Max(UMax-UMin, VMax-VMin) * aDrawer->DeviationCoefficient();
141 TColgp_SequenceOfPnt2d tabP;
142 Standard_Real aHatchingTol = 1.e100;
144 UMin = VMin = 1.e100;
145 UMax = VMax = -1.e100;
147 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
148 TopAbs_Orientation Orient = ToolRst.Orientation();
149 if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
150 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
151 if (TheRCurve->GetType() != GeomAbs_Line) {
152 GCPnts_QuasiUniformDeflection UDP(*TheRCurve, ddefle);
154 Standard_Integer NumberOfPoints = UDP.NbPoints();
155 if ( NumberOfPoints >= 2 ) {
156 dummypnt = UDP.Value(1);
157 P2.SetCoord(dummypnt.X(), dummypnt.Y());
158 UMin = Min(P2.X(), UMin);
159 UMax = Max(P2.X(), UMax);
160 VMin = Min(P2.Y(), VMin);
161 VMax = Max(P2.Y(), VMax);
162 for (i = 2; i <= NumberOfPoints; i++) {
164 dummypnt = UDP.Value(i);
165 P2.SetCoord(dummypnt.X(), dummypnt.Y());
166 UMin = Min(P2.X(), UMin);
167 UMax = Max(P2.X(), UMax);
168 VMin = Min(P2.Y(), VMin);
169 VMax = Max(P2.Y(), VMax);
170 aHatchingTol = Min(P1.SquareDistance(P2), aHatchingTol);
172 if(Orient == TopAbs_FORWARD ) {
173 //isobuild.Trim(P1,P2);
178 //isobuild.Trim(P2,P1);
187 cout << "Cannot evaluate curve on surface"<<endl;
192 U1 = TheRCurve->FirstParameter();
193 U2 = TheRCurve->LastParameter();
194 // MSV 17.08.06 OCC13144: U2 occured less than U1, to overcome it
195 // ensure that distance U2-U1 is not greater than aLimit*2,
196 // if greater then choose an origin and use aLimit to define
198 Standard_Real aOrigin = 0.;
199 if (!Precision::IsNegativeInfinite(U1) || !Precision::IsPositiveInfinite(U2)) {
200 if (Precision::IsNegativeInfinite(U1))
201 aOrigin = U2 - aLimit;
202 else if (Precision::IsPositiveInfinite(U2))
203 aOrigin = U1 + aLimit;
205 aOrigin = (U1 + U2) * 0.5;
207 U1 = Max(aOrigin - aLimit, U1);
208 U2 = Min(aOrigin + aLimit, U2);
209 P1 = TheRCurve->Value(U1);
210 P2 = TheRCurve->Value(U2);
211 UMin = Min(P1.X(), UMin);
212 UMax = Max(P1.X(), UMax);
213 VMin = Min(P1.Y(), VMin);
214 VMax = Max(P1.Y(), VMax);
215 UMin = Min(P2.X(), UMin);
216 UMax = Max(P2.X(), UMax);
217 VMin = Min(P2.Y(), VMin);
218 VMax = Max(P2.Y(), VMax);
219 aHatchingTol = Min(P1.SquareDistance(P2), aHatchingTol);
221 if(Orient == TopAbs_FORWARD ) {
222 // isobuild.Trim(P1,P2);
227 //isobuild.Trim(P2,P1);
236 #ifdef OCCT_DEBUG_MESH
242 // Compute the hatching tolerance.
244 aHatchingTol = Max(Precision::Confusion(), aHatchingTol);
245 aHatchingTol = Min(1.e-5, aHatchingTol);
248 Hatch_Hatcher isobuild(aHatchingTol, ToolRst.IsOriented());
249 Standard_Boolean UClosed = aFace->IsUClosed();
250 Standard_Boolean VClosed = aFace->IsVClosed();
253 UMin = UMin + ( UMax - UMin) /1000.;
254 UMax = UMax - ( UMax - UMin) /1000.;
258 VMin = VMin + ( VMax - VMin) /1000.;
259 VMax = VMax - ( VMax - VMin) /1000.;
264 UClosed = Standard_False; // En attendant un hatcher de course.
265 Standard_Real du= UClosed ? (UMax-UMin)/NBUiso : (UMax-UMin)/(1+NBUiso);
266 for (i=1; i<=NBUiso;i++){
267 isobuild.AddXLine(UMin+du*i);
273 VClosed = Standard_False;
274 Standard_Real dv= VClosed ?(VMax-VMin)/NBViso : (VMax-VMin)/(1+NBViso);
275 for (i=1; i<=NBViso;i++){
276 isobuild.AddYLine(VMin+dv*i);
281 #ifdef OCCT_DEBUG_MESH
287 Standard_Integer ll = tabP.Length();
288 for (i = 1; i <= ll; i+=2) {
289 isobuild.Trim(tabP(i),tabP(i+1));
293 #ifdef OCCT_DEBUG_MESH
300 Adaptor3d_IsoCurve anIso;
302 Handle(Geom_Curve) BC;
303 const BRepAdaptor_Surface& BS = *(BRepAdaptor_Surface*)&(aFace->Surface());
304 GeomAbs_SurfaceType thetype = aFace->GetType();
306 Standard_Integer NumberOfLines = isobuild.NbLines();
307 Handle(Geom_Surface) GB;
308 if (thetype == GeomAbs_BezierSurface) {
311 else if (thetype == GeomAbs_BSplineSurface){
315 Standard_Real anAngle = aDrawer->DeviationAngle();
317 for (i = 1; i <= NumberOfLines; i++) {
318 Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i);
319 Standard_Real Coord = isobuild.Coordinate(i);
320 for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) {
321 Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j);
325 if (isobuild.IsXLine(i))
326 BC = GB->UIso(Coord);
328 BC = GB->VIso(Coord);
329 GeomAdaptor_Curve GC(BC);
330 FindLimits(GC, aLimit,b1, b2);
331 if (b2-b1>Precision::Confusion()) {
332 Handle(TColgp_HSequenceOfPnt) Points = new TColgp_HSequenceOfPnt;
333 StdPrs_DeflectionCurve::Add (aPresentation, GC, b1, b2, Deflection,
334 Points->ChangeSequence(), anAngle, Standard_False);
335 Curves.Append(Points);
339 if (isobuild.IsXLine(i))
340 anIso.Load(GeomAbs_IsoU,Coord,b1,b2);
342 anIso.Load(GeomAbs_IsoV,Coord,b1,b2);
343 FindLimits(anIso, aLimit,b1, b2);
344 if (b2-b1>Precision::Confusion()) {
345 Handle(TColgp_HSequenceOfPnt) Points = new TColgp_HSequenceOfPnt;
346 StdPrs_DeflectionCurve::Add (aPresentation, anIso, b1, b2, Deflection,
347 Points->ChangeSequence(), anAngle, Standard_False);
348 Curves.Append(Points);
353 #ifdef OCCT_DEBUG_MESH
359 //=========================================================================
362 //=========================================================================
363 Standard_Boolean StdPrs_WFDeflectionRestrictedFace::Match
364 (const Quantity_Length X,
365 const Quantity_Length Y,
366 const Quantity_Length Z,
367 const Quantity_Length aDistance,
368 const Handle(BRepAdaptor_HSurface)& aFace,
369 const Handle(Prs3d_Drawer)& aDrawer,
370 const Standard_Boolean DrawUIso,
371 const Standard_Boolean DrawVIso,
372 const Quantity_Length Deflection,
373 const Standard_Integer NBUiso,
374 const Standard_Integer NBViso)
377 StdPrs_ToolRFace ToolRst (aFace);
378 const Standard_Real aLimit = aDrawer->MaximalParameterValue();
380 // compute bounds of the restriction
381 Standard_Real UMin,UMax,VMin,VMax;
382 Standard_Real u,v,step;
383 Standard_Integer i,nbPoints = 10;
384 UMin = VMin = RealLast();
385 UMax = VMax = RealFirst();
387 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
388 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
389 u = TheRCurve->FirstParameter();
390 v = TheRCurve->LastParameter();
391 step = ( v - u) / nbPoints;
392 for (i = 0; i <= nbPoints; i++) {
393 gp_Pnt2d P = TheRCurve->Value(u);
394 if (P.X() < UMin) UMin = P.X();
395 if (P.X() > UMax) UMax = P.X();
396 if (P.Y() < VMin) VMin = P.Y();
397 if (P.Y() > VMax) VMax = P.Y();
403 Hatch_Hatcher isobuild(1.e-5,ToolRst.IsOriented());
404 Standard_Boolean UClosed = aFace->IsUClosed();
405 Standard_Boolean VClosed = aFace->IsVClosed();
408 UMin = UMin + ( UMax - UMin) /1000.;
409 UMax = UMax - ( UMax - UMin) /1000.;
413 VMin = VMin + ( VMax - VMin) /1000.;
414 VMax = VMax - ( VMax - VMin) /1000.;
419 UClosed = Standard_False; // En attendant un hatcher de course.
420 Standard_Real du= UClosed ? (UMax-UMin)/NBUiso : (UMax-UMin)/(1+NBUiso);
421 for (i=1; i<=NBUiso;i++){
422 isobuild.AddXLine(UMin+du*i);
428 VClosed = Standard_False;
429 Standard_Real dv= VClosed ?(VMax-VMin)/NBViso : (VMax-VMin)/(1+NBViso);
430 for (i=1; i<=NBViso;i++){
431 isobuild.AddYLine(VMin+dv*i);
439 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
440 TopAbs_Orientation Orient = ToolRst.Orientation();
441 if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
442 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
443 GCPnts_QuasiUniformDeflection UDP(*TheRCurve, Deflection);
445 Standard_Integer NumberOfPoints = UDP.NbPoints();
446 if ( NumberOfPoints >= 2 ) {
447 dummypnt = UDP.Value(1);
448 P2.SetCoord(dummypnt.X(), dummypnt.Y());
449 for (i = 2; i <= NumberOfPoints; i++) {
451 dummypnt = UDP.Value(i);
452 P2.SetCoord(dummypnt.X(), dummypnt.Y());
453 if(Orient == TopAbs_FORWARD )
454 isobuild.Trim(P1,P2);
456 isobuild.Trim(P2,P1);
462 cout << "Cannot evaluate curve on surface"<<endl;
470 Adaptor3d_IsoCurve anIso;
472 Standard_Integer NumberOfLines = isobuild.NbLines();
473 Standard_Real anAngle = aDrawer->DeviationAngle();
475 for (i = 1; i <= NumberOfLines; i++) {
476 Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i);
477 Standard_Real Coord = isobuild.Coordinate(i);
478 for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) {
479 Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j);
481 b1 = b1 == RealFirst() ? - aLimit : b1;
482 b2 = b2 == RealLast() ? aLimit : b2;
484 if (isobuild.IsXLine(i))
485 anIso.Load(GeomAbs_IsoU,Coord,b1,b2);
487 anIso.Load(GeomAbs_IsoV,Coord,b1,b2);
489 if (StdPrs_DeflectionCurve::Match(X,Y,Z,aDistance,anIso, b1, b2, Deflection, anAngle))
490 return Standard_True;
493 return Standard_False;
497 //=========================================================================
500 //=========================================================================
501 void StdPrs_WFDeflectionRestrictedFace::Add
502 (const Handle (Prs3d_Presentation)& aPresentation,
503 const Handle(BRepAdaptor_HSurface)& aFace,
504 const Handle (Prs3d_Drawer)& aDrawer)
506 Prs3d_NListOfSequenceOfPnt Curves;
507 StdPrs_WFDeflectionRestrictedFace::Add (aPresentation,
511 aDrawer->MaximalChordialDeviation(),
512 aDrawer->UIsoAspect()->Number(),
513 aDrawer->VIsoAspect()->Number(),
519 //=========================================================================
522 //=========================================================================
523 void StdPrs_WFDeflectionRestrictedFace::AddUIso
524 (const Handle (Prs3d_Presentation)& aPresentation,
525 const Handle(BRepAdaptor_HSurface)& aFace,
526 const Handle (Prs3d_Drawer)& aDrawer)
528 Prs3d_NListOfSequenceOfPnt Curves;
529 StdPrs_WFDeflectionRestrictedFace::Add (
534 aDrawer->MaximalChordialDeviation(),
535 aDrawer->UIsoAspect()->Number(),
536 aDrawer->VIsoAspect()->Number(),
542 //=========================================================================
545 //=========================================================================
546 void StdPrs_WFDeflectionRestrictedFace::AddVIso
547 (const Handle (Prs3d_Presentation)& aPresentation,
548 const Handle(BRepAdaptor_HSurface)& aFace,
549 const Handle (Prs3d_Drawer)& aDrawer)
551 Prs3d_NListOfSequenceOfPnt Curves;
552 StdPrs_WFDeflectionRestrictedFace::Add (
557 aDrawer->MaximalChordialDeviation(),
558 aDrawer->UIsoAspect()->Number(),
559 aDrawer->VIsoAspect()->Number(),
565 //=========================================================================
568 //=========================================================================
569 Standard_Boolean StdPrs_WFDeflectionRestrictedFace::Match
570 (const Quantity_Length X,
571 const Quantity_Length Y,
572 const Quantity_Length Z,
573 const Quantity_Length aDistance,
574 const Handle(BRepAdaptor_HSurface)& aFace,
575 const Handle (Prs3d_Drawer)& aDrawer)
577 return StdPrs_WFDeflectionRestrictedFace::Match (
583 aDrawer->MaximalChordialDeviation(),
584 aDrawer->UIsoAspect()->Number(),
585 aDrawer->VIsoAspect()->Number());
589 //=========================================================================
590 // function: MatchUIso
592 //=========================================================================
593 Standard_Boolean StdPrs_WFDeflectionRestrictedFace::MatchUIso
594 (const Quantity_Length X,
595 const Quantity_Length Y,
596 const Quantity_Length Z,
597 const Quantity_Length aDistance,
598 const Handle(BRepAdaptor_HSurface)& aFace,
599 const Handle (Prs3d_Drawer)& aDrawer)
601 return StdPrs_WFDeflectionRestrictedFace::Match (
607 aDrawer->MaximalChordialDeviation(),
608 aDrawer->UIsoAspect()->Number(),
609 aDrawer->VIsoAspect()->Number());
613 //=========================================================================
614 // function: MatchVIso
616 //=========================================================================
617 Standard_Boolean StdPrs_WFDeflectionRestrictedFace::MatchVIso
618 (const Quantity_Length X,
619 const Quantity_Length Y,
620 const Quantity_Length Z,
621 const Quantity_Length aDistance,
622 const Handle(BRepAdaptor_HSurface)& aFace,
623 const Handle (Prs3d_Drawer)& aDrawer)
625 return StdPrs_WFDeflectionRestrictedFace::Match (
631 aDrawer->MaximalChordialDeviation(),
632 aDrawer->UIsoAspect()->Number(),
633 aDrawer->VIsoAspect()->Number());