1 // Copyright (c) 2013-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <Hatch_Hatcher.hxx>
15 #include <Graphic3d_Group.hxx>
17 #include <Prs3d_IsoAspect.hxx>
18 #include <Adaptor3d_IsoCurve.hxx>
19 #include <Bnd_Box2d.hxx>
20 #include <BndLib_Add2dCurve.hxx>
21 #include <Precision.hxx>
22 #include <GeomAdaptor_Curve.hxx>
23 #include <Geom_BezierSurface.hxx>
24 #include <Geom_BSplineSurface.hxx>
25 #include <GeomAbs_SurfaceType.hxx>
26 #include <Geom_Surface.hxx>
27 #include <StdPrs_WFRestrictedFace.hxx>
28 #include <StdPrs_ToolRFace.hxx>
29 #include <StdPrs_Curve.hxx>
30 #include <Prs3d_NListOfSequenceOfPnt.hxx>
32 //=========================================================================
35 //=========================================================================
37 void StdPrs_WFRestrictedFace::Add
38 (const Handle (Prs3d_Presentation)& thePresentation,
39 const Handle(BRepAdaptor_HSurface)& theFace,
40 const Standard_Boolean theDrawUIso,
41 const Standard_Boolean theDrawVIso,
42 const Standard_Integer theNbUIso,
43 const Standard_Integer theNBVIso,
44 const Handle(Prs3d_Drawer)& theDrawer,
45 Prs3d_NListOfSequenceOfPnt& theCurves)
47 Standard_Integer aNbPoints = theDrawer->Discretisation();
48 StdPrs_ToolRFace aToolRst (theFace);
50 // Compute bounds of the restriction
51 Standard_Real aUMin,aUMax,aVMin,aVMax;
53 gp_Pnt2d aPoint1,aPoint2;
56 for (aToolRst.Init(); aToolRst.More(); aToolRst.Next())
58 Adaptor2d_Curve2dPtr aRCurve = aToolRst.Value();
59 BndLib_Add2dCurve::Add(*aRCurve, Precision::PConfusion(), aBndBox);
61 if (!aBndBox.IsVoid())
62 aBndBox.Get(aUMin, aVMin, aUMax, aVMax);
64 { // No pcurves -- take natural bounds
65 aUMin = theFace->Surface().FirstUParameter();
66 aVMin = theFace->Surface().FirstVParameter();
67 aUMax = theFace->Surface().LastUParameter();
68 aVMax = theFace->Surface().LastVParameter();
72 Hatch_Hatcher anIsoBuild(1.e-5,aToolRst.IsOriented());
73 Standard_Boolean isFaceUClosed = theFace->IsUClosed();
74 Standard_Boolean isFaceVClosed = theFace->IsVClosed();
78 aUMin = aUMin + ( aUMax - aUMin) /1000.;
79 aUMax = aUMax - ( aUMax - aUMin) /1000.;
84 aVMin = aVMin + ( aVMax - aVMin) /1000.;
85 aVMax = aVMax - ( aVMax - aVMin) /1000.;
92 isFaceUClosed = Standard_False;
93 Standard_Real du= isFaceUClosed ? (aUMax-aUMin)/theNbUIso : (aUMax-aUMin)/(1+theNbUIso);
94 for (anI=1; anI<=theNbUIso;anI++)
96 anIsoBuild.AddXLine(aUMin+du*anI);
104 isFaceVClosed = Standard_False;
105 Standard_Real dv= isFaceVClosed ?(aVMax-aVMin)/theNBVIso : (aVMax-aVMin)/(1+theNBVIso);
106 for (anI=1; anI<=theNBVIso;anI++)
108 anIsoBuild.AddYLine(aVMin+dv*anI);
114 Standard_Real anU1, anU2, anU, aDU;
116 for (aToolRst.Init(); aToolRst.More(); aToolRst.Next())
118 TopAbs_Orientation anOrientation = aToolRst.Orientation();
119 if (anOrientation == TopAbs_FORWARD || anOrientation == TopAbs_REVERSED)
121 Adaptor2d_Curve2dPtr aRCurve = aToolRst.Value();
122 anU1 = aRCurve->FirstParameter();
123 anU2 = aRCurve->LastParameter();
124 if (aRCurve->GetType() != GeomAbs_Line)
126 aDU = (anU2-anU1)/(aNbPoints-1);
127 aPoint2 = aRCurve->Value(anU1);
128 for (anI = 2; anI <= aNbPoints; ++anI)
130 anU = anU1 + (anI-1)*aDU;
132 aPoint2 = aRCurve->Value(anU);
133 if(anOrientation == TopAbs_FORWARD )
134 anIsoBuild.Trim(aPoint1,aPoint2);
136 anIsoBuild.Trim(aPoint2,aPoint1);
140 aPoint1 = aRCurve->Value(anU1);
141 aPoint2 = aRCurve->Value(anU2);
142 if(anOrientation == TopAbs_FORWARD )
143 anIsoBuild.Trim(aPoint1,aPoint2);
145 anIsoBuild.Trim(aPoint2,aPoint1);
151 Adaptor3d_IsoCurve anIsoCurve;
152 anIsoCurve.Load(theFace);
153 Handle(Geom_Curve) aBCurve;
154 const BRepAdaptor_Surface& aBSurface = *(BRepAdaptor_Surface*)&(theFace->Surface());
155 GeomAbs_SurfaceType aFaceType = theFace->GetType();
157 Standard_Integer aNbLines = anIsoBuild.NbLines();
158 Handle(Geom_Surface) aGeomBSurface;
159 if (aFaceType == GeomAbs_BezierSurface)
161 aGeomBSurface = aBSurface.Bezier();
163 else if (aFaceType == GeomAbs_BSplineSurface)
165 aGeomBSurface = aBSurface.BSpline();
168 for (anI = 1; anI <= aNbLines; ++anI)
170 Standard_Integer NumberOfIntervals = anIsoBuild.NbIntervals(anI);
171 Standard_Real anIsoCoord = anIsoBuild.Coordinate(anI);
172 for (Standard_Integer aJ = 1; aJ <= NumberOfIntervals; aJ++)
174 Standard_Real b1=anIsoBuild.Start(anI,aJ),b2=anIsoBuild.End(anI,aJ);
176 if(b1 == RealFirst() || b2 == RealLast())
179 Handle(TColgp_HSequenceOfPnt) aPoints = new TColgp_HSequenceOfPnt;
180 if (!aGeomBSurface.IsNull())
182 if (anIsoBuild.IsXLine (anI))
184 aBCurve = aGeomBSurface->UIso (anIsoCoord);
188 aBCurve = aGeomBSurface->VIso (anIsoCoord);
191 //Note that the isos are the part of the shape, it will be displayed after a computation the whole shape
192 //NbPoints = 30 - default parameter for computation of such curves
193 StdPrs_Curve::Add (thePresentation, GeomAdaptor_Curve (aBCurve), b1, b2, aPoints->ChangeSequence(), 30, Standard_False);
194 theCurves.Append (aPoints);
198 if (anIsoBuild.IsXLine (anI))
200 anIsoCurve.Load (GeomAbs_IsoU, anIsoCoord, b1, b2);
204 anIsoCurve.Load(GeomAbs_IsoV, anIsoCoord, b1, b2);
206 StdPrs_Curve::Add (thePresentation, anIsoCurve, theDrawer, aPoints->ChangeSequence(), Standard_False);
207 theCurves.Append (aPoints);
214 //=========================================================================
217 //=========================================================================
219 Standard_Boolean StdPrs_WFRestrictedFace::Match
220 (const Standard_Real theX,
221 const Standard_Real theY,
222 const Standard_Real theZ,
223 const Standard_Real theDistance,
224 const Handle(BRepAdaptor_HSurface)& theFace,
225 const Standard_Boolean theDrawUIso,
226 const Standard_Boolean theDrawVIso,
227 const Standard_Real theDeflection,
228 const Standard_Integer theNbUIso,
229 const Standard_Integer theNBVIso,
230 const Handle(Prs3d_Drawer)& theDrawer)
232 Standard_Real aLimit = theDrawer->MaximalParameterValue();
233 Standard_Integer aNbPoints = theDrawer->Discretisation();
234 StdPrs_ToolRFace aToolRst (theFace);
236 // Compute bounds of the restriction
237 Standard_Real anUMin,anUMax,aVMin,aVMax;
238 Standard_Real anU,aV,aStep;
239 Standard_Integer anI,anNbP = 10;
240 anUMin = aVMin = RealLast();
241 anUMax = aVMax = RealFirst();
242 gp_Pnt2d aPoint1,aPoint2;
244 for (aToolRst.Init(); aToolRst.More(); aToolRst.Next())
246 Adaptor2d_Curve2dPtr aRCurve = aToolRst.Value();
247 anU = aRCurve->FirstParameter();
248 aV = aRCurve->LastParameter();
249 if (aRCurve->GetType() != GeomAbs_Line)
251 aStep = ( aV - anU) / anNbP;
252 for (anI = 0; anI <= anNbP; ++anI)
254 gp_Pnt2d aRCurvePoint = aRCurve->Value(anU);
255 if (aRCurvePoint.X() < anUMin) anUMin = aRCurvePoint.X();
256 if (aRCurvePoint.X() > anUMax) anUMax = aRCurvePoint.X();
257 if (aRCurvePoint.Y() < aVMin) aVMin = aRCurvePoint.Y();
258 if (aRCurvePoint.Y() > aVMax) aVMax = aRCurvePoint.Y();
264 aPoint1 = aRCurve->Value(anU);
265 if (aPoint1.X() < anUMin) anUMin = aPoint1.X();
266 if (aPoint1.X() > anUMax) anUMax = aPoint1.X();
267 if (aPoint1.Y() < aVMin) aVMin = aPoint1.Y();
268 if (aPoint1.Y() > aVMax) aVMax = aPoint1.Y();
270 aPoint2 = aRCurve->Value(aV);
271 if (aPoint2.X() < anUMin) anUMin = aPoint2.X();
272 if (aPoint2.X() > anUMax) anUMax = aPoint2.X();
273 if (aPoint2.Y() < aVMin) aVMin = aPoint2.Y();
274 if (aPoint2.Y() > aVMax) aVMax = aPoint2.Y();
279 Hatch_Hatcher anIsoBuild(1.e-5,aToolRst.IsOriented());
280 Standard_Boolean anUClosed = theFace->IsUClosed();
281 Standard_Boolean aVClosed = theFace->IsVClosed();
285 anUMin = anUMin + ( anUMax - anUMin) /1000.;
286 anUMax = anUMax - ( anUMax - anUMin) /1000.;
291 aVMin = aVMin + ( aVMax - aVMin) /1000.;
292 aVMax = aVMax - ( aVMax - aVMin) /1000.;
299 anUClosed = Standard_False;
300 Standard_Real du= anUClosed ? (anUMax-anUMin)/theNbUIso : (anUMax-anUMin)/(1+theNbUIso);
301 for (anI=1; anI<=theNbUIso;anI++){
302 anIsoBuild.AddXLine(anUMin+du*anI);
307 if ( theNBVIso > 0) {
308 aVClosed = Standard_False;
309 Standard_Real dv= aVClosed ?(aVMax-aVMin)/theNBVIso : (aVMax-aVMin)/(1+theNBVIso);
310 for (anI=1; anI<=theNBVIso;anI++){
311 anIsoBuild.AddYLine(aVMin+dv*anI);
317 Standard_Real anU1, anU2, aDU;
319 for (aToolRst.Init(); aToolRst.More(); aToolRst.Next())
321 TopAbs_Orientation Orient = aToolRst.Orientation();
322 if (Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED)
324 Adaptor2d_Curve2dPtr aRCurve = aToolRst.Value();
325 anU1 = aRCurve->FirstParameter();
326 anU2 = aRCurve->LastParameter();
327 if (aRCurve->GetType() != GeomAbs_Line) {
328 aDU = (anU2-anU1)/(aNbPoints-1);
329 aPoint2 = aRCurve->Value(anU1);
330 for (anI = 2; anI <= aNbPoints; anI++) {
331 anU = anU1 + (anI-1)*aDU;
333 aPoint2 = aRCurve->Value(anU);
334 if(Orient == TopAbs_FORWARD )
335 anIsoBuild.Trim(aPoint1,aPoint2);
337 anIsoBuild.Trim(aPoint2,aPoint1);
341 aPoint1 = aRCurve->Value(anU1);
342 aPoint2 = aRCurve->Value(anU2);
343 if(Orient == TopAbs_FORWARD )
344 anIsoBuild.Trim(aPoint1,aPoint2);
346 anIsoBuild.Trim(aPoint2,aPoint1);
353 Adaptor3d_IsoCurve anIso;
355 Standard_Integer aNbLines = anIsoBuild.NbLines();
357 for (anI = 1; anI <= aNbLines; anI++)
359 Standard_Integer aNbIntervals = anIsoBuild.NbIntervals(anI);
360 Standard_Real aCoord = anIsoBuild.Coordinate(anI);
361 for (Standard_Integer j = 1; j <= aNbIntervals; j++)
363 Standard_Real anIsoStart=anIsoBuild.Start(anI,j),anIsoEnd=anIsoBuild.End(anI,j);
365 anIsoStart = anIsoStart == RealFirst() ? - aLimit : anIsoStart;
366 anIsoEnd = anIsoEnd == RealLast() ? aLimit : anIsoEnd;
369 if (anIsoBuild.IsXLine(anI))
370 anIso.Load(GeomAbs_IsoU,aCoord,anIsoStart,anIsoEnd);
372 anIso.Load(GeomAbs_IsoV,aCoord,anIsoStart,anIsoEnd);
374 if (StdPrs_Curve::Match(theX,theY,theZ,theDistance,anIso,
375 theDeflection, aLimit, aNbPoints))
376 return Standard_True;
381 return Standard_False;
385 //=========================================================================
388 //=========================================================================
390 void StdPrs_WFRestrictedFace::Add
391 (const Handle (Prs3d_Presentation)& thePresentation,
392 const Handle(BRepAdaptor_HSurface)& theFace,
393 const Handle (Prs3d_Drawer)& theDrawer)
395 Prs3d_NListOfSequenceOfPnt aCurves;
396 StdPrs_WFRestrictedFace::Add (thePresentation,
400 theDrawer->UIsoAspect()->Number(),
401 theDrawer->VIsoAspect()->Number(),
407 //=========================================================================
410 //=========================================================================
412 void StdPrs_WFRestrictedFace::AddUIso
413 (const Handle (Prs3d_Presentation)& thePresentation,
414 const Handle(BRepAdaptor_HSurface)& theFace,
415 const Handle (Prs3d_Drawer)& theDrawer)
417 Prs3d_NListOfSequenceOfPnt aCurves;
418 StdPrs_WFRestrictedFace::Add (thePresentation,
422 theDrawer->UIsoAspect()->Number(),
423 theDrawer->VIsoAspect()->Number(),
429 //=========================================================================
432 //=========================================================================
434 void StdPrs_WFRestrictedFace::AddVIso
435 (const Handle (Prs3d_Presentation)& thePresentation,
436 const Handle(BRepAdaptor_HSurface)& theFace,
437 const Handle (Prs3d_Drawer)& theDrawer)
439 Prs3d_NListOfSequenceOfPnt aCurves;
440 StdPrs_WFRestrictedFace::Add (thePresentation,
444 theDrawer->UIsoAspect()->Number(),
445 theDrawer->VIsoAspect()->Number(),
451 //=========================================================================
454 //=========================================================================
456 Standard_Boolean StdPrs_WFRestrictedFace::Match
457 (const Standard_Real theX,
458 const Standard_Real theY,
459 const Standard_Real theZ,
460 const Standard_Real theDistance,
461 const Handle(BRepAdaptor_HSurface)& theFace,
462 const Handle (Prs3d_Drawer)& theDrawer)
464 return StdPrs_WFRestrictedFace::Match (
465 theX, theY, theZ, theDistance,
469 theDrawer->MaximalChordialDeviation(),
470 theDrawer->UIsoAspect()->Number(),
471 theDrawer->VIsoAspect()->Number(),
476 //=========================================================================
477 // function: MatchUIso
479 //=========================================================================
481 Standard_Boolean StdPrs_WFRestrictedFace::MatchUIso
482 (const Standard_Real theX,
483 const Standard_Real theY,
484 const Standard_Real theZ,
485 const Standard_Real theDistance,
486 const Handle(BRepAdaptor_HSurface)& theFace,
487 const Handle (Prs3d_Drawer)& theDrawer)
489 return StdPrs_WFRestrictedFace::Match (
490 theX, theY, theZ,theDistance,
494 theDrawer->MaximalChordialDeviation(),
495 theDrawer->UIsoAspect()->Number(),
496 theDrawer->VIsoAspect()->Number(),
501 //=========================================================================
502 // function: MatchVIso
504 //=========================================================================
506 Standard_Boolean StdPrs_WFRestrictedFace::MatchVIso
507 (const Standard_Real theX,
508 const Standard_Real theY,
509 const Standard_Real theZ,
510 const Standard_Real theDistance,
511 const Handle(BRepAdaptor_HSurface)& theFace,
512 const Handle (Prs3d_Drawer)& theDrawer)
514 return StdPrs_WFRestrictedFace::Match (
515 theX, theY, theZ, theDistance,
519 theDrawer->MaximalChordialDeviation(),
520 theDrawer->UIsoAspect()->Number(),
521 theDrawer->VIsoAspect()->Number(),