// File: Prs3d_WFRestrictedFace.gxx // Created: Fri Jun 10 11:31:42 1994 // Author: Laurent PAINNOT // #ifdef DEBUG #include extern OSD_Timer RestrictedFaceTimer1,RestrictedFaceTimer2,RestrictedFaceTimer3,RestrictedFaceTimer4; #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include //========================================================================= // function: Add // purpose //========================================================================= void Prs3d_WFRestrictedFace::Add (const Handle (Prs3d_Presentation)& aPresentation, const Handle(BRepAdaptor_HSurface)& aFace, const Standard_Boolean DrawUIso, const Standard_Boolean DrawVIso, const Quantity_Length aDeflection, const Standard_Integer NBUiso, const Standard_Integer NBViso, const Handle(Prs3d_Drawer)& aDrawer, Prs3d_NListOfSequenceOfPnt& Curves) { Standard_Boolean isPA = Graphic3d_ArrayOfPrimitives::IsEnable(); Standard_Real aLimit = aDrawer->MaximalParameterValue(); Standard_Integer nbPoints = aDrawer->Discretisation(); #ifdef DEBUG RestrictedFaceTimer1.Start(); #endif RestrictionTool ToolRst (aFace); // compute bounds of the restriction Standard_Real UMin,UMax,VMin,VMax; // Standard_Real u,v,step; // Standard_Integer i, nbp= 10; Standard_Integer i; gp_Pnt2d P1,P2; Bnd_Box2d B; for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) { Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value(); BndLib_Add2dCurve::Add(*TheRCurve, Precision::PConfusion(), B); } if ( ! B.IsVoid() ) B.Get(UMin, VMin, UMax, VMax); else { // no pcurves -- take natural bounds UMin = aFace->Surface().FirstUParameter(); VMin = aFace->Surface().FirstVParameter(); UMax = aFace->Surface().LastUParameter(); VMax = aFace->Surface().LastVParameter(); } #ifdef DEBUG RestrictedFaceTimer1.Stop(); RestrictedFaceTimer2.Start(); #endif // load the isos Hatch_Hatcher isobuild(1.e-5,ToolRst.IsOriented()); Standard_Boolean UClosed = aFace->IsUClosed(); Standard_Boolean VClosed = aFace->IsVClosed(); if ( ! UClosed ) { UMin = UMin + ( UMax - UMin) /1000.; UMax = UMax - ( UMax - UMin) /1000.; } if ( ! VClosed ) { VMin = VMin + ( VMax - VMin) /1000.; VMax = VMax - ( VMax - VMin) /1000.; } if (DrawUIso){ if (NBUiso > 0) { UClosed = Standard_False; // En attendant un hatcher de course. Standard_Real du= UClosed ? (UMax-UMin)/NBUiso : (UMax-UMin)/(1+NBUiso); for (i=1; i<=NBUiso;i++){ isobuild.AddXLine(UMin+du*i); } } } if (DrawVIso){ if ( NBViso > 0) { VClosed = Standard_False; Standard_Real dv= VClosed ?(VMax-VMin)/NBViso : (VMax-VMin)/(1+NBViso); for (i=1; i<=NBViso;i++){ isobuild.AddYLine(VMin+dv*i); } } } #ifdef DEBUG RestrictedFaceTimer2.Stop(); RestrictedFaceTimer3.Start(); #endif // trim the isos Standard_Real U1, U2, U, DU; for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) { TopAbs_Orientation Orient = ToolRst.Orientation(); if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) { Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value(); U1 = TheRCurve->FirstParameter(); U2 = TheRCurve->LastParameter(); if (TheRCurve->GetType() != GeomAbs_Line) { DU = (U2-U1)/(nbPoints-1); P2 = TheRCurve->Value(U1); for (i = 2; i <= nbPoints; i++) { U = U1 + (i-1)*DU; P1 = P2; P2 = TheRCurve->Value(U); if(Orient == TopAbs_FORWARD ) isobuild.Trim(P1,P2); else isobuild.Trim(P2,P1); } } else { P1 = TheRCurve->Value(U1); P2 = TheRCurve->Value(U2); if(Orient == TopAbs_FORWARD ) isobuild.Trim(P1,P2); else isobuild.Trim(P2,P1); } } } #ifdef DEBUG RestrictedFaceTimer3.Stop(); RestrictedFaceTimer4.Start(); #endif // draw the isos Adaptor3d_IsoCurve anIso; anIso.Load(aFace); Handle(Geom_Curve) BC; const BRepAdaptor_Surface& BS = *(BRepAdaptor_Surface*)&(aFace->Surface()); GeomAbs_SurfaceType thetype = aFace->GetType(); Standard_Integer NumberOfLines = isobuild.NbLines(); Handle(Geom_Surface) GB; if (thetype == GeomAbs_BezierSurface) { GB = BS.Bezier(); } else if (thetype == GeomAbs_BSplineSurface){ GB = BS.BSpline(); } for (i = 1; i <= NumberOfLines; i++) { Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i); Standard_Real Coord = isobuild.Coordinate(i); for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) { Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j); if(b1 == RealFirst() || b2 == RealLast()) continue; //b1 = b1 == RealFirst() ? - aLimit : b1; //b2 = b2 == RealLast() ? aLimit : b2; TColgp_SequenceOfPnt Pnts; if (!GB.IsNull()) { if (isobuild.IsXLine(i)) BC = GB->UIso(Coord); else BC = GB->VIso(Coord); //Note that the isos are the part of the shape, it will be displayed after a computation the whole shape //NbPoints = 30 - default parameter for computation of such curves DrawFaceIso::Add(aPresentation,GeomAdaptor_Curve(BC), b1, b2, aDeflection, Pnts, 30, !isPA); Curves.Append(Pnts); } else { if (isobuild.IsXLine(i)) anIso.Load(GeomAbs_IsoU,Coord,b1,b2); else anIso.Load(GeomAbs_IsoV,Coord,b1,b2); DrawFaceIso::Add(aPresentation,anIso, aDeflection, aDrawer, Pnts, !isPA); Curves.Append(Pnts); } } } #ifdef DEBUG RestrictedFaceTimer4.Stop(); #endif } //========================================================================= // function: Match // purpose //========================================================================= Standard_Boolean Prs3d_WFRestrictedFace::Match (const Quantity_Length X, const Quantity_Length Y, const Quantity_Length Z, const Quantity_Length aDistance, const Handle(BRepAdaptor_HSurface)& aFace, const Standard_Boolean DrawUIso, const Standard_Boolean DrawVIso, const Quantity_Length aDeflection, const Standard_Integer NBUiso, const Standard_Integer NBViso, const Handle(Prs3d_Drawer)& aDrawer) { Standard_Real aLimit = aDrawer->MaximalParameterValue(); Standard_Integer nbPoints = aDrawer->Discretisation(); RestrictionTool ToolRst (aFace); // compute bounds of the restriction Standard_Real UMin,UMax,VMin,VMax; Standard_Real u,v,step; Standard_Integer i,nbP = 10; UMin = VMin = RealLast(); UMax = VMax = RealFirst(); gp_Pnt2d P1,P2; for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) { Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value(); u = TheRCurve->FirstParameter(); v = TheRCurve->LastParameter(); if (TheRCurve->GetType() != GeomAbs_Line) { step = ( v - u) / nbP; for (i = 0; i <= nbP; i++) { gp_Pnt2d P = TheRCurve->Value(u); if (P.X() < UMin) UMin = P.X(); if (P.X() > UMax) UMax = P.X(); if (P.Y() < VMin) VMin = P.Y(); if (P.Y() > VMax) VMax = P.Y(); u += step; } } else { P1 = TheRCurve->Value(u); if (P1.X() < UMin) UMin = P1.X(); if (P1.X() > UMax) UMax = P1.X(); if (P1.Y() < VMin) VMin = P1.Y(); if (P1.Y() > VMax) VMax = P1.Y(); P2 = TheRCurve->Value(v); if (P2.X() < UMin) UMin = P2.X(); if (P2.X() > UMax) UMax = P2.X(); if (P2.Y() < VMin) VMin = P2.Y(); if (P2.Y() > VMax) VMax = P2.Y(); } } // load the isos Hatch_Hatcher isobuild(1.e-5,ToolRst.IsOriented()); Standard_Boolean UClosed = aFace->IsUClosed(); Standard_Boolean VClosed = aFace->IsVClosed(); if ( ! UClosed ) { UMin = UMin + ( UMax - UMin) /1000.; UMax = UMax - ( UMax - UMin) /1000.; } if ( ! VClosed ) { VMin = VMin + ( VMax - VMin) /1000.; VMax = VMax - ( VMax - VMin) /1000.; } if (DrawUIso){ if (NBUiso > 0) { UClosed = Standard_False; // En attendant un hatcher de course. Standard_Real du= UClosed ? (UMax-UMin)/NBUiso : (UMax-UMin)/(1+NBUiso); for (i=1; i<=NBUiso;i++){ isobuild.AddXLine(UMin+du*i); } } } if (DrawVIso){ if ( NBViso > 0) { VClosed = Standard_False; Standard_Real dv= VClosed ?(VMax-VMin)/NBViso : (VMax-VMin)/(1+NBViso); for (i=1; i<=NBViso;i++){ isobuild.AddYLine(VMin+dv*i); } } } // trim the isos Standard_Real U1, U2, U, DU; for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) { TopAbs_Orientation Orient = ToolRst.Orientation(); if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) { Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value(); U1 = TheRCurve->FirstParameter(); U2 = TheRCurve->LastParameter(); if (TheRCurve->GetType() != GeomAbs_Line) { DU = (U2-U1)/(nbPoints-1); P2 = TheRCurve->Value(U1); for (i = 2; i <= nbPoints; i++) { U = U1 + (i-1)*DU; P1 = P2; P2 = TheRCurve->Value(U); if(Orient == TopAbs_FORWARD ) isobuild.Trim(P1,P2); else isobuild.Trim(P2,P1); } } else { P1 = TheRCurve->Value(U1); P2 = TheRCurve->Value(U2); if(Orient == TopAbs_FORWARD ) isobuild.Trim(P1,P2); else isobuild.Trim(P2,P1); } } } // draw the isos Adaptor3d_IsoCurve anIso; anIso.Load(aFace); Standard_Integer NumberOfLines = isobuild.NbLines(); for (i = 1; i <= NumberOfLines; i++) { Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i); Standard_Real Coord = isobuild.Coordinate(i); for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) { Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j); b1 = b1 == RealFirst() ? - aLimit : b1; b2 = b2 == RealLast() ? aLimit : b2; if (isobuild.IsXLine(i)) anIso.Load(GeomAbs_IsoU,Coord,b1,b2); else anIso.Load(GeomAbs_IsoV,Coord,b1,b2); if (DrawFaceIso::Match(X,Y,Z,aDistance,anIso, aDeflection, aLimit, nbPoints)) return Standard_True; } } return Standard_False; } //========================================================================= // function: Add // purpose //========================================================================= void Prs3d_WFRestrictedFace::Add (const Handle (Prs3d_Presentation)& aPresentation, const Handle(BRepAdaptor_HSurface)& aFace, const Handle (Prs3d_Drawer)& aDrawer){ Standard_Integer finu = aDrawer->UIsoAspect()->Number(); Standard_Integer finv = aDrawer->VIsoAspect()->Number(); Quantity_Length aDeflection = aDrawer->MaximalChordialDeviation(); Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation); TheGroup->BeginPrimitives(); Prs3d_NListOfSequenceOfPnt Curves; Prs3d_WFRestrictedFace::Add ( aPresentation, aFace, Standard_True, Standard_True, aDeflection, finu, finv, aDrawer, Curves); TheGroup->EndPrimitives(); } //========================================================================= // function: AddUIso // purpose //========================================================================= void Prs3d_WFRestrictedFace::AddUIso (const Handle (Prs3d_Presentation)& aPresentation, const Handle(BRepAdaptor_HSurface)& aFace, const Handle (Prs3d_Drawer)& aDrawer) { Standard_Integer finu = aDrawer->UIsoAspect()->Number(); Standard_Integer finv = aDrawer->VIsoAspect()->Number(); Quantity_Length aDeflection = aDrawer->MaximalChordialDeviation(); Prs3d_NListOfSequenceOfPnt Curves; Prs3d_WFRestrictedFace::Add ( aPresentation, aFace, Standard_True, Standard_False, aDeflection, finu, finv, aDrawer, Curves); } //========================================================================= // function: AddVIso // purpose //========================================================================= void Prs3d_WFRestrictedFace::AddVIso (const Handle (Prs3d_Presentation)& aPresentation, const Handle(BRepAdaptor_HSurface)& aFace, const Handle (Prs3d_Drawer)& aDrawer) { Standard_Integer finu = aDrawer->UIsoAspect()->Number(); Standard_Integer finv = aDrawer->VIsoAspect()->Number(); Quantity_Length aDeflection = aDrawer->MaximalChordialDeviation(); Prs3d_NListOfSequenceOfPnt Curves; Prs3d_WFRestrictedFace::Add ( aPresentation, aFace, Standard_False, Standard_True, aDeflection, finu, finv, aDrawer, Curves); } //========================================================================= // function: Match // purpose //========================================================================= Standard_Boolean Prs3d_WFRestrictedFace::Match (const Quantity_Length X, const Quantity_Length Y, const Quantity_Length Z, const Quantity_Length aDistance, const Handle(BRepAdaptor_HSurface)& aFace, const Handle (Prs3d_Drawer)& aDrawer){ Standard_Integer finu = aDrawer->UIsoAspect()->Number(); Standard_Integer finv = aDrawer->VIsoAspect()->Number(); Quantity_Length aDeflection = aDrawer->MaximalChordialDeviation(); return Prs3d_WFRestrictedFace::Match ( X,Y,Z,aDistance, aFace, Standard_True, Standard_True, aDeflection, finu, finv, aDrawer); } //========================================================================= // function: MatchUIso // purpose //========================================================================= Standard_Boolean Prs3d_WFRestrictedFace::MatchUIso (const Quantity_Length X, const Quantity_Length Y, const Quantity_Length Z, const Quantity_Length aDistance, const Handle(BRepAdaptor_HSurface)& aFace, const Handle (Prs3d_Drawer)& aDrawer) { Standard_Integer finu = aDrawer->UIsoAspect()->Number(); Standard_Integer finv = aDrawer->VIsoAspect()->Number(); Quantity_Length aDeflection = aDrawer->MaximalChordialDeviation(); return Prs3d_WFRestrictedFace::Match ( X,Y,Z,aDistance, aFace, Standard_True, Standard_False, aDeflection, finu, finv, aDrawer); } //========================================================================= // function: MatchVIso // purpose //========================================================================= Standard_Boolean Prs3d_WFRestrictedFace::MatchVIso (const Quantity_Length X, const Quantity_Length Y, const Quantity_Length Z, const Quantity_Length aDistance, const Handle(BRepAdaptor_HSurface)& aFace, const Handle (Prs3d_Drawer)& aDrawer) { Standard_Integer finu = aDrawer->UIsoAspect()->Number(); Standard_Integer finv = aDrawer->VIsoAspect()->Number(); Quantity_Length aDeflection = aDrawer->MaximalChordialDeviation(); return Prs3d_WFRestrictedFace::Match ( X,Y,Z,aDistance, aFace, Standard_False, Standard_True, aDeflection, finu, finv, aDrawer); }