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_Surface)& 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 const Adaptor2d_Curve2d& 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 const Adaptor2d_Curve2d* aRCurve = &aToolRst.Value();
120 anU1 = aRCurve->FirstParameter();
121 anU2 = aRCurve->LastParameter();
122 if (aRCurve->GetType() != GeomAbs_Line)
124 aDU = (anU2-anU1)/(aNbPoints-1);
125 aPoint2 = aRCurve->Value(anU1);
126 for (anI = 2; anI <= aNbPoints; ++anI)
128 anU = anU1 + (anI-1)*aDU;
130 aPoint2 = aRCurve->Value(anU);
131 if(anOrientation == TopAbs_FORWARD )
132 anIsoBuild.Trim(aPoint1,aPoint2);
134 anIsoBuild.Trim(aPoint2,aPoint1);
138 aPoint1 = aRCurve->Value(anU1);
139 aPoint2 = aRCurve->Value(anU2);
140 if(anOrientation == TopAbs_FORWARD )
141 anIsoBuild.Trim(aPoint1,aPoint2);
143 anIsoBuild.Trim(aPoint2,aPoint1);
148 Adaptor3d_IsoCurve anIsoCurve;
149 anIsoCurve.Load(theFace);
150 Handle(Geom_Curve) aBCurve;
151 const BRepAdaptor_Surface& aBSurface = *theFace;
152 GeomAbs_SurfaceType aFaceType = theFace->GetType();
154 Standard_Integer aNbLines = anIsoBuild.NbLines();
155 Handle(Geom_Surface) aGeomBSurface;
156 if (aFaceType == GeomAbs_BezierSurface)
158 aGeomBSurface = aBSurface.Bezier();
160 else if (aFaceType == GeomAbs_BSplineSurface)
162 aGeomBSurface = aBSurface.BSpline();
165 for (anI = 1; anI <= aNbLines; ++anI)
167 Standard_Integer NumberOfIntervals = anIsoBuild.NbIntervals(anI);
168 Standard_Real anIsoCoord = anIsoBuild.Coordinate(anI);
169 for (Standard_Integer aJ = 1; aJ <= NumberOfIntervals; aJ++)
171 Standard_Real b1=anIsoBuild.Start(anI,aJ),b2=anIsoBuild.End(anI,aJ);
173 if(b1 == RealFirst() || b2 == RealLast())
176 Handle(TColgp_HSequenceOfPnt) aPoints = new TColgp_HSequenceOfPnt;
177 if (!aGeomBSurface.IsNull())
179 if (anIsoBuild.IsXLine (anI))
181 aBCurve = aGeomBSurface->UIso (anIsoCoord);
185 aBCurve = aGeomBSurface->VIso (anIsoCoord);
188 //Note that the isos are the part of the shape, it will be displayed after a computation the whole shape
189 //NbPoints = 30 - default parameter for computation of such curves
190 StdPrs_Curve::Add (thePresentation, GeomAdaptor_Curve (aBCurve), b1, b2, aPoints->ChangeSequence(), 30, Standard_False);
191 theCurves.Append (aPoints);
195 if (anIsoBuild.IsXLine (anI))
197 anIsoCurve.Load (GeomAbs_IsoU, anIsoCoord, b1, b2);
201 anIsoCurve.Load(GeomAbs_IsoV, anIsoCoord, b1, b2);
203 StdPrs_Curve::Add (thePresentation, anIsoCurve, theDrawer, aPoints->ChangeSequence(), Standard_False);
204 theCurves.Append (aPoints);
211 //=========================================================================
214 //=========================================================================
216 Standard_Boolean StdPrs_WFRestrictedFace::Match
217 (const Standard_Real theX,
218 const Standard_Real theY,
219 const Standard_Real theZ,
220 const Standard_Real theDistance,
221 const Handle(BRepAdaptor_Surface)& theFace,
222 const Standard_Boolean theDrawUIso,
223 const Standard_Boolean theDrawVIso,
224 const Standard_Real theDeflection,
225 const Standard_Integer theNbUIso,
226 const Standard_Integer theNBVIso,
227 const Handle(Prs3d_Drawer)& theDrawer)
229 Standard_Real aLimit = theDrawer->MaximalParameterValue();
230 Standard_Integer aNbPoints = theDrawer->Discretisation();
231 StdPrs_ToolRFace aToolRst (theFace);
233 // Compute bounds of the restriction
234 Standard_Real anUMin,anUMax,aVMin,aVMax;
235 Standard_Real anU,aV,aStep;
236 Standard_Integer anI,anNbP = 10;
237 anUMin = aVMin = RealLast();
238 anUMax = aVMax = RealFirst();
239 gp_Pnt2d aPoint1,aPoint2;
241 for (aToolRst.Init(); aToolRst.More(); aToolRst.Next())
243 const Adaptor2d_Curve2d* aRCurve = &aToolRst.Value();
244 anU = aRCurve->FirstParameter();
245 aV = aRCurve->LastParameter();
246 if (aRCurve->GetType() != GeomAbs_Line)
248 aStep = ( aV - anU) / anNbP;
249 for (anI = 0; anI <= anNbP; ++anI)
251 gp_Pnt2d aRCurvePoint = aRCurve->Value(anU);
252 if (aRCurvePoint.X() < anUMin) anUMin = aRCurvePoint.X();
253 if (aRCurvePoint.X() > anUMax) anUMax = aRCurvePoint.X();
254 if (aRCurvePoint.Y() < aVMin) aVMin = aRCurvePoint.Y();
255 if (aRCurvePoint.Y() > aVMax) aVMax = aRCurvePoint.Y();
261 aPoint1 = aRCurve->Value(anU);
262 if (aPoint1.X() < anUMin) anUMin = aPoint1.X();
263 if (aPoint1.X() > anUMax) anUMax = aPoint1.X();
264 if (aPoint1.Y() < aVMin) aVMin = aPoint1.Y();
265 if (aPoint1.Y() > aVMax) aVMax = aPoint1.Y();
267 aPoint2 = aRCurve->Value(aV);
268 if (aPoint2.X() < anUMin) anUMin = aPoint2.X();
269 if (aPoint2.X() > anUMax) anUMax = aPoint2.X();
270 if (aPoint2.Y() < aVMin) aVMin = aPoint2.Y();
271 if (aPoint2.Y() > aVMax) aVMax = aPoint2.Y();
276 Hatch_Hatcher anIsoBuild(1.e-5,aToolRst.IsOriented());
277 Standard_Boolean anUClosed = theFace->IsUClosed();
278 Standard_Boolean aVClosed = theFace->IsVClosed();
282 anUMin = anUMin + ( anUMax - anUMin) /1000.;
283 anUMax = anUMax - ( anUMax - anUMin) /1000.;
288 aVMin = aVMin + ( aVMax - aVMin) /1000.;
289 aVMax = aVMax - ( aVMax - aVMin) /1000.;
296 anUClosed = Standard_False;
297 Standard_Real du= anUClosed ? (anUMax-anUMin)/theNbUIso : (anUMax-anUMin)/(1+theNbUIso);
298 for (anI=1; anI<=theNbUIso;anI++){
299 anIsoBuild.AddXLine(anUMin+du*anI);
304 if ( theNBVIso > 0) {
305 aVClosed = Standard_False;
306 Standard_Real dv= aVClosed ?(aVMax-aVMin)/theNBVIso : (aVMax-aVMin)/(1+theNBVIso);
307 for (anI=1; anI<=theNBVIso;anI++){
308 anIsoBuild.AddYLine(aVMin+dv*anI);
314 Standard_Real anU1, anU2, aDU;
316 for (aToolRst.Init(); aToolRst.More(); aToolRst.Next())
318 TopAbs_Orientation Orient = aToolRst.Orientation();
319 const Adaptor2d_Curve2d* aRCurve = &aToolRst.Value();
320 anU1 = aRCurve->FirstParameter();
321 anU2 = aRCurve->LastParameter();
322 if (aRCurve->GetType() != GeomAbs_Line) {
323 aDU = (anU2-anU1)/(aNbPoints-1);
324 aPoint2 = aRCurve->Value(anU1);
325 for (anI = 2; anI <= aNbPoints; anI++) {
326 anU = anU1 + (anI-1)*aDU;
328 aPoint2 = aRCurve->Value(anU);
329 if(Orient == TopAbs_FORWARD )
330 anIsoBuild.Trim(aPoint1,aPoint2);
332 anIsoBuild.Trim(aPoint2,aPoint1);
336 aPoint1 = aRCurve->Value(anU1);
337 aPoint2 = aRCurve->Value(anU2);
338 if(Orient == TopAbs_FORWARD )
339 anIsoBuild.Trim(aPoint1,aPoint2);
341 anIsoBuild.Trim(aPoint2,aPoint1);
347 Adaptor3d_IsoCurve anIso;
349 Standard_Integer aNbLines = anIsoBuild.NbLines();
351 for (anI = 1; anI <= aNbLines; anI++)
353 Standard_Integer aNbIntervals = anIsoBuild.NbIntervals(anI);
354 Standard_Real aCoord = anIsoBuild.Coordinate(anI);
355 for (Standard_Integer j = 1; j <= aNbIntervals; j++)
357 Standard_Real anIsoStart=anIsoBuild.Start(anI,j),anIsoEnd=anIsoBuild.End(anI,j);
359 anIsoStart = anIsoStart == RealFirst() ? - aLimit : anIsoStart;
360 anIsoEnd = anIsoEnd == RealLast() ? aLimit : anIsoEnd;
363 if (anIsoBuild.IsXLine(anI))
364 anIso.Load(GeomAbs_IsoU,aCoord,anIsoStart,anIsoEnd);
366 anIso.Load(GeomAbs_IsoV,aCoord,anIsoStart,anIsoEnd);
368 if (StdPrs_Curve::Match(theX,theY,theZ,theDistance,anIso,
369 theDeflection, aLimit, aNbPoints))
370 return Standard_True;
375 return Standard_False;
379 //=========================================================================
382 //=========================================================================
384 void StdPrs_WFRestrictedFace::Add
385 (const Handle (Prs3d_Presentation)& thePresentation,
386 const Handle(BRepAdaptor_Surface)& theFace,
387 const Handle (Prs3d_Drawer)& theDrawer)
389 Prs3d_NListOfSequenceOfPnt aCurves;
390 StdPrs_WFRestrictedFace::Add (thePresentation,
394 theDrawer->UIsoAspect()->Number(),
395 theDrawer->VIsoAspect()->Number(),
401 //=========================================================================
404 //=========================================================================
406 void StdPrs_WFRestrictedFace::AddUIso
407 (const Handle (Prs3d_Presentation)& thePresentation,
408 const Handle(BRepAdaptor_Surface)& theFace,
409 const Handle (Prs3d_Drawer)& theDrawer)
411 Prs3d_NListOfSequenceOfPnt aCurves;
412 StdPrs_WFRestrictedFace::Add (thePresentation,
416 theDrawer->UIsoAspect()->Number(),
417 theDrawer->VIsoAspect()->Number(),
423 //=========================================================================
426 //=========================================================================
428 void StdPrs_WFRestrictedFace::AddVIso
429 (const Handle (Prs3d_Presentation)& thePresentation,
430 const Handle(BRepAdaptor_Surface)& theFace,
431 const Handle (Prs3d_Drawer)& theDrawer)
433 Prs3d_NListOfSequenceOfPnt aCurves;
434 StdPrs_WFRestrictedFace::Add (thePresentation,
438 theDrawer->UIsoAspect()->Number(),
439 theDrawer->VIsoAspect()->Number(),
445 //=========================================================================
448 //=========================================================================
450 Standard_Boolean StdPrs_WFRestrictedFace::Match
451 (const Standard_Real theX,
452 const Standard_Real theY,
453 const Standard_Real theZ,
454 const Standard_Real theDistance,
455 const Handle(BRepAdaptor_Surface)& theFace,
456 const Handle (Prs3d_Drawer)& theDrawer)
458 return StdPrs_WFRestrictedFace::Match (
459 theX, theY, theZ, theDistance,
463 theDrawer->MaximalChordialDeviation(),
464 theDrawer->UIsoAspect()->Number(),
465 theDrawer->VIsoAspect()->Number(),
470 //=========================================================================
471 // function: MatchUIso
473 //=========================================================================
475 Standard_Boolean StdPrs_WFRestrictedFace::MatchUIso
476 (const Standard_Real theX,
477 const Standard_Real theY,
478 const Standard_Real theZ,
479 const Standard_Real theDistance,
480 const Handle(BRepAdaptor_Surface)& theFace,
481 const Handle (Prs3d_Drawer)& theDrawer)
483 return StdPrs_WFRestrictedFace::Match (
484 theX, theY, theZ,theDistance,
488 theDrawer->MaximalChordialDeviation(),
489 theDrawer->UIsoAspect()->Number(),
490 theDrawer->VIsoAspect()->Number(),
495 //=========================================================================
496 // function: MatchVIso
498 //=========================================================================
500 Standard_Boolean StdPrs_WFRestrictedFace::MatchVIso
501 (const Standard_Real theX,
502 const Standard_Real theY,
503 const Standard_Real theZ,
504 const Standard_Real theDistance,
505 const Handle(BRepAdaptor_Surface)& theFace,
506 const Handle (Prs3d_Drawer)& theDrawer)
508 return StdPrs_WFRestrictedFace::Match (
509 theX, theY, theZ, theDistance,
513 theDrawer->MaximalChordialDeviation(),
514 theDrawer->UIsoAspect()->Number(),
515 theDrawer->VIsoAspect()->Number(),