1 // File: Prs3d_WFRestrictedFace.gxx
2 // Created: Fri Jun 10 11:31:42 1994
3 // Author: Laurent PAINNOT
8 #include <OSD_Timer.hxx>
9 extern OSD_Timer RestrictedFaceTimer1,RestrictedFaceTimer2,RestrictedFaceTimer3,RestrictedFaceTimer4;
12 #include <Hatch_Hatcher.hxx>
13 #include <Graphic3d_Array1OfVertex.hxx>
14 #include <Graphic3d_ArrayOfPrimitives.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_Curve.hxx>
24 #include <GeomAbs_SurfaceType.hxx>
25 #include <Geom_Surface.hxx>
27 //=========================================================================
30 //=========================================================================
31 void Prs3d_WFRestrictedFace::Add
32 (const Handle (Prs3d_Presentation)& aPresentation,
33 const Handle(BRepAdaptor_HSurface)& aFace,
34 const Standard_Boolean DrawUIso,
35 const Standard_Boolean DrawVIso,
36 const Quantity_Length aDeflection,
37 const Standard_Integer NBUiso,
38 const Standard_Integer NBViso,
39 const Handle(Prs3d_Drawer)& aDrawer,
40 Prs3d_NListOfSequenceOfPnt& Curves)
42 Standard_Boolean isPA = Graphic3d_ArrayOfPrimitives::IsEnable();
43 Standard_Real aLimit = aDrawer->MaximalParameterValue();
44 Standard_Integer nbPoints = aDrawer->Discretisation();
47 RestrictedFaceTimer1.Start();
50 RestrictionTool ToolRst (aFace);
52 // compute bounds of the restriction
53 Standard_Real UMin,UMax,VMin,VMax;
54 // Standard_Real u,v,step;
55 // Standard_Integer i, nbp= 10;
60 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
61 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
62 BndLib_Add2dCurve::Add(*TheRCurve, Precision::PConfusion(), B);
65 B.Get(UMin, VMin, UMax, VMax);
67 { // no pcurves -- take natural bounds
68 UMin = aFace->Surface().FirstUParameter();
69 VMin = aFace->Surface().FirstVParameter();
70 UMax = aFace->Surface().LastUParameter();
71 VMax = aFace->Surface().LastVParameter();
75 RestrictedFaceTimer1.Stop();
77 RestrictedFaceTimer2.Start();
81 Hatch_Hatcher isobuild(1.e-5,ToolRst.IsOriented());
82 Standard_Boolean UClosed = aFace->IsUClosed();
83 Standard_Boolean VClosed = aFace->IsVClosed();
86 UMin = UMin + ( UMax - UMin) /1000.;
87 UMax = UMax - ( UMax - UMin) /1000.;
91 VMin = VMin + ( VMax - VMin) /1000.;
92 VMax = VMax - ( VMax - VMin) /1000.;
97 UClosed = Standard_False; // En attendant un hatcher de course.
98 Standard_Real du= UClosed ? (UMax-UMin)/NBUiso : (UMax-UMin)/(1+NBUiso);
99 for (i=1; i<=NBUiso;i++){
100 isobuild.AddXLine(UMin+du*i);
106 VClosed = Standard_False;
107 Standard_Real dv= VClosed ?(VMax-VMin)/NBViso : (VMax-VMin)/(1+NBViso);
108 for (i=1; i<=NBViso;i++){
109 isobuild.AddYLine(VMin+dv*i);
115 RestrictedFaceTimer2.Stop();
116 RestrictedFaceTimer3.Start();
120 Standard_Real U1, U2, U, DU;
122 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
123 TopAbs_Orientation Orient = ToolRst.Orientation();
124 if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
125 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
126 U1 = TheRCurve->FirstParameter();
127 U2 = TheRCurve->LastParameter();
128 if (TheRCurve->GetType() != GeomAbs_Line) {
129 DU = (U2-U1)/(nbPoints-1);
130 P2 = TheRCurve->Value(U1);
131 for (i = 2; i <= nbPoints; i++) {
134 P2 = TheRCurve->Value(U);
135 if(Orient == TopAbs_FORWARD )
136 isobuild.Trim(P1,P2);
138 isobuild.Trim(P2,P1);
142 P1 = TheRCurve->Value(U1);
143 P2 = TheRCurve->Value(U2);
144 if(Orient == TopAbs_FORWARD )
145 isobuild.Trim(P1,P2);
147 isobuild.Trim(P2,P1);
153 RestrictedFaceTimer3.Stop();
154 RestrictedFaceTimer4.Start();
160 Adaptor3d_IsoCurve anIso;
162 Handle(Geom_Curve) BC;
163 const BRepAdaptor_Surface& BS = *(BRepAdaptor_Surface*)&(aFace->Surface());
164 GeomAbs_SurfaceType thetype = aFace->GetType();
166 Standard_Integer NumberOfLines = isobuild.NbLines();
167 Handle(Geom_Surface) GB;
168 if (thetype == GeomAbs_BezierSurface) {
171 else if (thetype == GeomAbs_BSplineSurface){
175 for (i = 1; i <= NumberOfLines; i++) {
176 Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i);
177 Standard_Real Coord = isobuild.Coordinate(i);
178 for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) {
179 Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j);
181 if(b1 == RealFirst() || b2 == RealLast())
183 //b1 = b1 == RealFirst() ? - aLimit : b1;
184 //b2 = b2 == RealLast() ? aLimit : b2;
186 TColgp_SequenceOfPnt Pnts;
188 if (isobuild.IsXLine(i))
189 BC = GB->UIso(Coord);
191 BC = GB->VIso(Coord);
192 //Note that the isos are the part of the shape, it will be displayed after a computation the whole shape
193 //NbPoints = 30 - default parameter for computation of such curves
194 DrawFaceIso::Add(aPresentation,GeomAdaptor_Curve(BC), b1, b2, aDeflection, Pnts, 30, !isPA);
198 if (isobuild.IsXLine(i))
199 anIso.Load(GeomAbs_IsoU,Coord,b1,b2);
201 anIso.Load(GeomAbs_IsoV,Coord,b1,b2);
202 DrawFaceIso::Add(aPresentation,anIso, aDeflection, aDrawer, Pnts, !isPA);
208 RestrictedFaceTimer4.Stop();
213 //=========================================================================
216 //=========================================================================
217 Standard_Boolean Prs3d_WFRestrictedFace::Match
218 (const Quantity_Length X,
219 const Quantity_Length Y,
220 const Quantity_Length Z,
221 const Quantity_Length aDistance,
222 const Handle(BRepAdaptor_HSurface)& aFace,
223 const Standard_Boolean DrawUIso,
224 const Standard_Boolean DrawVIso,
225 const Quantity_Length aDeflection,
226 const Standard_Integer NBUiso,
227 const Standard_Integer NBViso,
228 const Handle(Prs3d_Drawer)& aDrawer)
230 Standard_Real aLimit = aDrawer->MaximalParameterValue();
231 Standard_Integer nbPoints = aDrawer->Discretisation();
232 RestrictionTool ToolRst (aFace);
234 // compute bounds of the restriction
235 Standard_Real UMin,UMax,VMin,VMax;
236 Standard_Real u,v,step;
237 Standard_Integer i,nbP = 10;
238 UMin = VMin = RealLast();
239 UMax = VMax = RealFirst();
242 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
243 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
244 u = TheRCurve->FirstParameter();
245 v = TheRCurve->LastParameter();
246 if (TheRCurve->GetType() != GeomAbs_Line) {
247 step = ( v - u) / nbP;
248 for (i = 0; i <= nbP; i++) {
249 gp_Pnt2d P = TheRCurve->Value(u);
250 if (P.X() < UMin) UMin = P.X();
251 if (P.X() > UMax) UMax = P.X();
252 if (P.Y() < VMin) VMin = P.Y();
253 if (P.Y() > VMax) VMax = P.Y();
258 P1 = TheRCurve->Value(u);
259 if (P1.X() < UMin) UMin = P1.X();
260 if (P1.X() > UMax) UMax = P1.X();
261 if (P1.Y() < VMin) VMin = P1.Y();
262 if (P1.Y() > VMax) VMax = P1.Y();
264 P2 = TheRCurve->Value(v);
265 if (P2.X() < UMin) UMin = P2.X();
266 if (P2.X() > UMax) UMax = P2.X();
267 if (P2.Y() < VMin) VMin = P2.Y();
268 if (P2.Y() > VMax) VMax = P2.Y();
273 Hatch_Hatcher isobuild(1.e-5,ToolRst.IsOriented());
274 Standard_Boolean UClosed = aFace->IsUClosed();
275 Standard_Boolean VClosed = aFace->IsVClosed();
278 UMin = UMin + ( UMax - UMin) /1000.;
279 UMax = UMax - ( UMax - UMin) /1000.;
283 VMin = VMin + ( VMax - VMin) /1000.;
284 VMax = VMax - ( VMax - VMin) /1000.;
289 UClosed = Standard_False; // En attendant un hatcher de course.
290 Standard_Real du= UClosed ? (UMax-UMin)/NBUiso : (UMax-UMin)/(1+NBUiso);
291 for (i=1; i<=NBUiso;i++){
292 isobuild.AddXLine(UMin+du*i);
298 VClosed = Standard_False;
299 Standard_Real dv= VClosed ?(VMax-VMin)/NBViso : (VMax-VMin)/(1+NBViso);
300 for (i=1; i<=NBViso;i++){
301 isobuild.AddYLine(VMin+dv*i);
307 Standard_Real U1, U2, U, DU;
309 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
310 TopAbs_Orientation Orient = ToolRst.Orientation();
311 if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
312 Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
313 U1 = TheRCurve->FirstParameter();
314 U2 = TheRCurve->LastParameter();
315 if (TheRCurve->GetType() != GeomAbs_Line) {
316 DU = (U2-U1)/(nbPoints-1);
317 P2 = TheRCurve->Value(U1);
318 for (i = 2; i <= nbPoints; i++) {
321 P2 = TheRCurve->Value(U);
322 if(Orient == TopAbs_FORWARD )
323 isobuild.Trim(P1,P2);
325 isobuild.Trim(P2,P1);
329 P1 = TheRCurve->Value(U1);
330 P2 = TheRCurve->Value(U2);
331 if(Orient == TopAbs_FORWARD )
332 isobuild.Trim(P1,P2);
334 isobuild.Trim(P2,P1);
341 Adaptor3d_IsoCurve anIso;
343 Standard_Integer NumberOfLines = isobuild.NbLines();
345 for (i = 1; i <= NumberOfLines; i++) {
346 Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i);
347 Standard_Real Coord = isobuild.Coordinate(i);
348 for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) {
349 Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j);
351 b1 = b1 == RealFirst() ? - aLimit : b1;
352 b2 = b2 == RealLast() ? aLimit : b2;
355 if (isobuild.IsXLine(i))
356 anIso.Load(GeomAbs_IsoU,Coord,b1,b2);
358 anIso.Load(GeomAbs_IsoV,Coord,b1,b2);
360 if (DrawFaceIso::Match(X,Y,Z,aDistance,anIso,
361 aDeflection, aLimit, nbPoints))
362 return Standard_True;
368 return Standard_False;
373 //=========================================================================
376 //=========================================================================
377 void Prs3d_WFRestrictedFace::Add
378 (const Handle (Prs3d_Presentation)& aPresentation,
379 const Handle(BRepAdaptor_HSurface)& aFace,
380 const Handle (Prs3d_Drawer)& aDrawer){
382 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
383 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
384 Quantity_Length aDeflection = aDrawer->MaximalChordialDeviation();
386 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
387 TheGroup->BeginPrimitives();
388 Prs3d_NListOfSequenceOfPnt Curves;
389 Prs3d_WFRestrictedFace::Add (
400 TheGroup->EndPrimitives();
404 //=========================================================================
407 //=========================================================================
408 void Prs3d_WFRestrictedFace::AddUIso
409 (const Handle (Prs3d_Presentation)& aPresentation,
410 const Handle(BRepAdaptor_HSurface)& aFace,
411 const Handle (Prs3d_Drawer)& aDrawer) {
413 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
414 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
415 Quantity_Length aDeflection = aDrawer->MaximalChordialDeviation();
416 Prs3d_NListOfSequenceOfPnt Curves;
417 Prs3d_WFRestrictedFace::Add (
430 //=========================================================================
433 //=========================================================================
434 void Prs3d_WFRestrictedFace::AddVIso
435 (const Handle (Prs3d_Presentation)& aPresentation,
436 const Handle(BRepAdaptor_HSurface)& aFace,
437 const Handle (Prs3d_Drawer)& aDrawer) {
439 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
440 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
441 Quantity_Length aDeflection = aDrawer->MaximalChordialDeviation();
442 Prs3d_NListOfSequenceOfPnt Curves;
443 Prs3d_WFRestrictedFace::Add (
456 //=========================================================================
459 //=========================================================================
460 Standard_Boolean Prs3d_WFRestrictedFace::Match
461 (const Quantity_Length X,
462 const Quantity_Length Y,
463 const Quantity_Length Z,
464 const Quantity_Length aDistance,
465 const Handle(BRepAdaptor_HSurface)& aFace,
466 const Handle (Prs3d_Drawer)& aDrawer){
468 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
469 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
470 Quantity_Length aDeflection = aDrawer->MaximalChordialDeviation();
471 return Prs3d_WFRestrictedFace::Match (
483 //=========================================================================
484 // function: MatchUIso
486 //=========================================================================
487 Standard_Boolean Prs3d_WFRestrictedFace::MatchUIso
488 (const Quantity_Length X,
489 const Quantity_Length Y,
490 const Quantity_Length Z,
491 const Quantity_Length aDistance,
492 const Handle(BRepAdaptor_HSurface)& aFace,
493 const Handle (Prs3d_Drawer)& aDrawer) {
495 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
496 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
497 Quantity_Length aDeflection = aDrawer->MaximalChordialDeviation();
498 return Prs3d_WFRestrictedFace::Match (
510 //=========================================================================
511 // function: MatchVIso
513 //=========================================================================
514 Standard_Boolean Prs3d_WFRestrictedFace::MatchVIso
515 (const Quantity_Length X,
516 const Quantity_Length Y,
517 const Quantity_Length Z,
518 const Quantity_Length aDistance,
519 const Handle(BRepAdaptor_HSurface)& aFace,
520 const Handle (Prs3d_Drawer)& aDrawer) {
522 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
523 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
524 Quantity_Length aDeflection = aDrawer->MaximalChordialDeviation();
525 return Prs3d_WFRestrictedFace::Match (