From 3c34883cdc59600715d41b59404cdb4fa030d084 Mon Sep 17 00:00:00 2001 From: OAN <> Date: Fri, 19 Aug 2011 08:23:45 +0000 Subject: [PATCH] 0022302: BRepMesh_IncrimentalMesh calls for each face of shape on vdisplay --- src/AIS/AIS_Shape.cxx | 130 +++--- src/BRepBndLib/BRepBndLib.cdl | 4 +- src/BRepBndLib/BRepBndLib.cxx | 103 +++-- src/Prs3d/Prs3d_ShadedShape.gxx | 421 +++++++++--------- src/Select3D/Select3D_SensitiveCurve.cxx | 2 +- src/StdSelect/StdSelect_BRepSelectionTool.cxx | 14 +- 6 files changed, 330 insertions(+), 344 deletions(-) diff --git a/src/AIS/AIS_Shape.cxx b/src/AIS/AIS_Shape.cxx index 7c3f35f3f8..4c62c9bb38 100755 --- a/src/AIS/AIS_Shape.cxx +++ b/src/AIS/AIS_Shape.cxx @@ -84,13 +84,13 @@ static Standard_Boolean myFirstCompute; Standard_Real AIS_Shape::GetDeflection(const TopoDS_Shape& aShape, - const Handle(Prs3d_Drawer)& aDrawer) + const Handle(Prs3d_Drawer)& aDrawer) { // WARNING: this same piece of code appears several times in Prs3d classes - Standard_Real aDeflection; + Standard_Real aDeflection = aDrawer->MaximalChordialDeviation(); if (aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) { Bnd_Box B; - BRepBndLib::Add(aShape, B); + BRepBndLib::Add(aShape, B, Standard_False); if ( ! B.IsVoid() ) { Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; @@ -98,17 +98,13 @@ Standard_Real AIS_Shape::GetDeflection(const TopoDS_Shape& aShape, aDeflection = Max( aXmax-aXmin, Max(aYmax-aYmin, aZmax-aZmin)) * aDrawer->DeviationCoefficient() * 4; } - else - aDeflection = aDrawer->MaximalChordialDeviation(); } - else - aDeflection = aDrawer->MaximalChordialDeviation(); return aDeflection; } void AIS_Shape::DisplayBox(const Handle(Prs3d_Presentation)& aPrs, - const Bnd_Box& B, - const Handle(Prs3d_Drawer)& aDrawer) + const Bnd_Box& B, + const Handle(Prs3d_Drawer)& aDrawer) { Standard_Real X[2],Y[2],Z[2]; Standard_Integer Indx [16] ; @@ -133,7 +129,7 @@ void AIS_Shape::DisplayBox(const Handle(Prs3d_Presentation)& aPrs, for(Standard_Integer k=0;k<=1;k++) for(Standard_Integer j=0;j<=1;j++) for(Standard_Integer i=0;i<=1;i++) - V(++Rank) = Graphic3d_Vertex(X[i],Y[j],Z[k]); + V(++Rank) = Graphic3d_Vertex(X[i],Y[j],Z[k]); Handle(Graphic3d_Group) G = Prs3d_Root::CurrentGroup(aPrs); @@ -156,7 +152,7 @@ void AIS_Shape::DisplayBox(const Handle(Prs3d_Presentation)& aPrs, } G->EndPrimitives(); } - + static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode) { TColStd_ListIteratorOfListOfInteger It(LL); @@ -210,8 +206,8 @@ Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const //purpose : //======================================================================= void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, - const Handle(Prs3d_Presentation)& aPrs, - const Standard_Integer aMode) + const Handle(Prs3d_Presentation)& aPrs, + const Standard_Integer aMode) { aPrs->Clear(); if(myshape.IsNull()) return; @@ -258,42 +254,42 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat if (OwnDeviationAngle(newangle,prevangle) || - OwnDeviationCoefficient(newcoeff,prevcoeff)) - if (Abs (newangle - prevangle) > Precision::Angular() || - Abs (newcoeff - prevcoeff) > Precision::Confusion() ) { + OwnDeviationCoefficient(newcoeff,prevcoeff)) + if (Abs (newangle - prevangle) > Precision::Angular() || + Abs (newcoeff - prevcoeff) > Precision::Confusion() ) { #ifdef DEB - cout << "AIS_Shape : compute"<4) - StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer); + StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer); else { - myDrawer->SetShadingAspectGlobal(Standard_False); - if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer); - else { - { - try { - OCC_CATCH_SIGNALS - StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer); - } - catch (Standard_Failure) { + myDrawer->SetShadingAspectGlobal(Standard_False); + if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer); + else { + { + try { + OCC_CATCH_SIGNALS + StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer); + } + catch (Standard_Failure) { #ifdef DEB - cout << "AIS_Shape::Compute() in ShadingMode failed"<< endl; + cout << "AIS_Shape::Compute() in ShadingMode failed"<< endl; #endif - StdPrs_WFShape::Add(aPrs,myshape,myDrawer); - } - } - } + StdPrs_WFShape::Add(aPrs,myshape,myDrawer); + } + } + } } #ifdef BUC60918 Standard_Real value = Transparency() ; if( value > 0. ) { - SetTransparency( value ); + SetTransparency( value ); } #endif break; @@ -317,8 +313,8 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat //======================================================================= void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager2d)& /*aPresentationManager*/, - const Handle(Graphic2d_GraphicObject)& /*aGRO*/, - const Standard_Integer /*aMode*/) + const Handle(Graphic2d_GraphicObject)& /*aGRO*/, + const Standard_Integer /*aMode*/) { } @@ -327,7 +323,7 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager2d)& /*aPresentat //purpose : Hidden Line Removal //======================================================================= void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector, - const Handle(Prs3d_Presentation)& aPresentation) + const Handle(Prs3d_Presentation)& aPresentation) { Compute(aProjector,aPresentation,myshape); } @@ -338,8 +334,8 @@ void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector, //======================================================================= void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector, - const Handle(Geom_Transformation)& TheTrsf, - const Handle(Prs3d_Presentation)& aPresentation) + const Handle(Geom_Transformation)& TheTrsf, + const Handle(Prs3d_Presentation)& aPresentation) { const TopLoc_Location& loc = myshape.Location(); TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc); @@ -352,8 +348,8 @@ void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector, //======================================================================= void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector, - const Handle(Prs3d_Presentation)& aPresentation, - const TopoDS_Shape& SH) + const Handle(Prs3d_Presentation)& aPresentation, + const TopoDS_Shape& SH) { if (SH.ShapeType() == TopAbs_COMPOUND) { #ifdef BUC60547 @@ -379,7 +375,7 @@ void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector, if (OwnHLRDeviationAngle(newangle,prevangle) || OwnHLRDeviationCoefficient(newcoeff, prevcoeff)) if (Abs (newangle - prevangle) > Precision::Angular() || - Abs (newcoeff - prevcoeff) > Precision::Confusion() ) { + Abs (newcoeff - prevcoeff) > Precision::Confusion() ) { #ifdef DEB cout << "AIS_Shape : compute"<MaximalChordialDeviation(); - if (myDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) - { - // Vector is calculated depending on global min max of the part: - Bnd_Box aBndBox; //= BoundingBox(); ? - BRepBndLib::Add (shape, aBndBox); - if (!aBndBox.IsVoid()) - { - Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; - aBndBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); - aDeflection = Max (aXmax - aXmin, Max (aYmax - aYmin, aZmax - aZmin)) * myDrawer->DeviationCoefficient(); - } - } - + Standard_Real aDeflection = GetDeflection(shape, myDrawer); Standard_Boolean autoTriangulation = Standard_True; try { OCC_CATCH_SIGNALS @@ -518,7 +501,7 @@ void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, shape, TypOfSel, aDeflection, - myDrawer->DeviationAngle(), + myDrawer->HLRAngle(), autoTriangulation); } catch ( Standard_Failure ) { // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<SetShadingAspect(new Prs3d_ShadingAspect()); + myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); } #else myOwnColor = aCol; @@ -786,7 +769,7 @@ void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat) { #ifdef GER61351 if( !HasColor() && !IsTransparent() && !HasMaterial() ) { - myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); + myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); } myDrawer->ShadingAspect()->SetMaterial(aMat,myCurrentFacingModel); hasOwnMaterial = Standard_True; @@ -814,7 +797,7 @@ void AIS_Shape::SetMaterial(const Graphic3d_MaterialAspect& aMat) { #ifdef GER61351 if( !HasColor() && !IsTransparent() && !HasMaterial() ) { - myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); + myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); } myDrawer->ShadingAspect()->SetMaterial(aMat,myCurrentFacingModel); hasOwnMaterial = Standard_True; @@ -846,11 +829,11 @@ void AIS_Shape::UnsetMaterial() if( HasColor() || IsTransparent()) { Graphic3d_MaterialAspect mat = AIS_GraphicTool::GetMaterial(myDrawer->Link()); if( HasColor() ) { - Quantity_Color color = myDrawer->ShadingAspect()->Color(myCurrentFacingModel); + Quantity_Color color = myDrawer->ShadingAspect()->Color(myCurrentFacingModel); mat.SetColor(color); } if( IsTransparent() ) { - Standard_Real trans = myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel); + Standard_Real trans = myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel); mat.SetTransparency(trans); } myDrawer->ShadingAspect()->SetMaterial(mat,myCurrentFacingModel); @@ -900,8 +883,8 @@ void AIS_Shape::SetTransparency(const Standard_Real AValue) Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect(); P->SetPrimitivesAspect(a4bis); -#ifdef BUC60918 //force highest priority for transparent objects - P->SetDisplayPriority(10); +#ifdef BUC60918 //force highest priority for transparent objects + P->SetDisplayPriority(10); #endif G->SetGroupPrimitivesAspect(a4bis); } @@ -937,7 +920,7 @@ void AIS_Shape::UnsetTransparency() Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect(); P->SetPrimitivesAspect(a4bis); G->SetGroupPrimitivesAspect(a4bis); -#ifdef BUC60918 +#ifdef BUC60918 P->ResetDisplayPriority(); #endif } @@ -1133,7 +1116,7 @@ void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle ) //======================================================================= Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient, - Standard_Real & aPreviousCoefficient ) const + Standard_Real & aPreviousCoefficient ) const { aCoefficient = myDrawer->DeviationCoefficient(); aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient (); @@ -1146,7 +1129,7 @@ Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoeffici //======================================================================= Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient, - Standard_Real & aPreviousCoefficient ) const + Standard_Real & aPreviousCoefficient ) const { aCoefficient = myDrawer->HLRDeviationCoefficient(); aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient (); @@ -1160,7 +1143,7 @@ Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoeffi //======================================================================= Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle, - Standard_Real & aPreviousAngle ) const + Standard_Real & aPreviousAngle ) const { anAngle = myDrawer->DeviationAngle(); aPreviousAngle = myDrawer->PreviousDeviationAngle (); @@ -1173,10 +1156,9 @@ Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle, //======================================================================= Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle, - Standard_Real & aPreviousAngle ) const + Standard_Real & aPreviousAngle ) const { anAngle = myDrawer->HLRAngle(); aPreviousAngle = myDrawer->PreviousHLRDeviationAngle (); return myDrawer->IsOwnHLRDeviationAngle(); - } diff --git a/src/BRepBndLib/BRepBndLib.cdl b/src/BRepBndLib/BRepBndLib.cdl index 02472e5b95..13bbe1f48e 100755 --- a/src/BRepBndLib/BRepBndLib.cdl +++ b/src/BRepBndLib/BRepBndLib.cdl @@ -24,7 +24,9 @@ is -- Package methods for shapes -- - Add(S : Shape from TopoDS; B : in out Box from Bnd); + Add(S : Shape from TopoDS; + B : in out Box from Bnd; + useTriangulation: Boolean from Standard = Standard_True); ---Purpose:Adds the shape S to the bounding box B. -- More precisely are successively added to B: -- - each face of S; the triangulation of the face is used if it exists, diff --git a/src/BRepBndLib/BRepBndLib.cxx b/src/BRepBndLib/BRepBndLib.cxx index 28bc3b500a..cbc4e4eee7 100755 --- a/src/BRepBndLib/BRepBndLib.cxx +++ b/src/BRepBndLib/BRepBndLib.cxx @@ -26,12 +26,11 @@ //purpose : Add a shape bounding to a box //======================================================================= -void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B) +void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTriangulation) { TopExp_Explorer ex; // Add the faces - BRepAdaptor_Surface BS; Handle(Geom_Surface) GS; Handle(Poly_Triangulation) T; @@ -42,80 +41,86 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B) for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next()) { const TopoDS_Face& F = TopoDS::Face(ex.Current()); T = BRep_Tool::Triangulation(F, l); - if (!T.IsNull()) { + if (useTriangulation && !T.IsNull()) + { nbNodes = T->NbNodes(); const TColgp_Array1OfPnt& Nodes = T->Nodes(); for (i = 1; i <= nbNodes; i++) { - if (l.IsIdentity()) B.Add(Nodes(i)); - else B.Add(Nodes(i).Transformed(l)); + if (l.IsIdentity()) B.Add(Nodes(i)); + else B.Add(Nodes(i).Transformed(l)); } // B.Enlarge(T->Deflection()); B.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F)); - } - else { + } else + { GS = BRep_Tool::Surface(F, l); if (!GS.IsNull()) { - BS.Initialize(F, Standard_False); - if (BS.GetType() != GeomAbs_Plane) { - BS.Initialize(F); - BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B); - } - else { - // on travaille directement sur les courbes 3d. - TopExp_Explorer ex2(F, TopAbs_EDGE); - if (!ex2.More()) { - BS.Initialize(F); - BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B); - } - else { - for (;ex2.More();ex2.Next()) { - BC.Initialize(TopoDS::Edge(ex2.Current())); - BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(F), B); - } - B.Enlarge(BRep_Tool::Tolerance(F)); - } - } + BS.Initialize(F, Standard_False); + if (BS.GetType() != GeomAbs_Plane) { + BS.Initialize(F); + BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B); + } + else { + // on travaille directement sur les courbes 3d. + TopExp_Explorer ex2(F, TopAbs_EDGE); + if (!ex2.More()) { + BS.Initialize(F); + BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B); + } + else { + for (;ex2.More();ex2.Next()) { + BC.Initialize(TopoDS::Edge(ex2.Current())); + BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(F), B); + } + B.Enlarge(BRep_Tool::Tolerance(F)); + } + } } } } // Add the edges not in faces - - Handle(TColStd_HArray1OfInteger) HIndices; Handle(Poly_PolygonOnTriangulation) Poly; - for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE); ex.More(); ex.Next()) { + for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE); ex.More(); ex.Next()) + { const TopoDS_Edge& E = TopoDS::Edge(ex.Current()); Handle(Poly_Polygon3D) P3d = BRep_Tool::Polygon3D(E, l); - if (!P3d.IsNull()) { + if (!P3d.IsNull()) + { const TColgp_Array1OfPnt& Nodes = P3d->Nodes(); nbNodes = P3d->NbNodes(); - for (i = 1; i <= nbNodes; i++) { - if (l.IsIdentity()) B.Add(Nodes(i)); - else B.Add(Nodes(i).Transformed(l)); + for (i = 1; i <= nbNodes; i++) + { + if (l.IsIdentity()) B.Add(Nodes(i)); + else B.Add(Nodes(i).Transformed(l)); } // B.Enlarge(P3d->Deflection()); B.Enlarge(P3d->Deflection() + BRep_Tool::Tolerance(E)); } - else { + else + { BRep_Tool::PolygonOnTriangulation(E, Poly, T, l); - if (!Poly.IsNull()) { - const TColStd_Array1OfInteger& Indices = Poly->Nodes(); - const TColgp_Array1OfPnt& Nodes = T->Nodes(); - nbNodes = Indices.Length(); - for (i = 1; i <= nbNodes; i++) { - if (l.IsIdentity()) B.Add(Nodes(Indices(i))); - else B.Add(Nodes(Indices(i)).Transformed(l)); - } - // B.Enlarge(T->Deflection()); - B.Enlarge(Poly->Deflection() + BRep_Tool::Tolerance(E)); + if (useTriangulation && !Poly.IsNull()) + { + const TColStd_Array1OfInteger& Indices = Poly->Nodes(); + const TColgp_Array1OfPnt& Nodes = T->Nodes(); + nbNodes = Indices.Length(); + for (i = 1; i <= nbNodes; i++) + { + if (l.IsIdentity()) B.Add(Nodes(Indices(i))); + else B.Add(Nodes(Indices(i)).Transformed(l)); + } + // B.Enlarge(T->Deflection()); + B.Enlarge(Poly->Deflection() + BRep_Tool::Tolerance(E)); } else { - if (BRep_Tool::IsGeometric(E)) { - BC.Initialize(E); - BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(E), B); - } + if (BRep_Tool::IsGeometric(E)) + { + BC.Initialize(E); + BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(E), B); + } } } } diff --git a/src/Prs3d/Prs3d_ShadedShape.gxx b/src/Prs3d/Prs3d_ShadedShape.gxx index a2edd47329..a6d57ea9dd 100755 --- a/src/Prs3d/Prs3d_ShadedShape.gxx +++ b/src/Prs3d/Prs3d_ShadedShape.gxx @@ -52,245 +52,238 @@ static Standard_Real GetDeflection(const anyShape& aShape, - const Handle(Prs3d_Drawer)& aDrawer) + const Handle(Prs3d_Drawer)& aDrawer) { - Standard_Real aDeflection; + Standard_Real aDeflection = aDrawer->MaximalChordialDeviation(); if (aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) { Bnd_Box B; - BRepBndLib::Add(aShape, B); + BRepBndLib::Add(aShape, B, Standard_False); if ( ! B.IsVoid() ) { Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); aDeflection = MAX3( aXmax-aXmin , aYmax-aYmin , aZmax-aZmin) - * aDrawer->DeviationCoefficient()*4; + * aDrawer->DeviationCoefficient()*4; } - else - aDeflection = aDrawer->MaximalChordialDeviation(); } - else - aDeflection = aDrawer->MaximalChordialDeviation(); - return aDeflection; } static Standard_Boolean ShadeFromShape(const anyShape& aShape, - const Standard_Real /*defle*/, - const Standard_Boolean /*share*/, - const Handle (Prs3d_Presentation)& aPresentation, - const Handle (Prs3d_Drawer)& aDrawer) + const Standard_Real /*defle*/, + const Standard_Boolean /*share*/, + const Handle (Prs3d_Presentation)& aPresentation, + const Handle (Prs3d_Drawer)& aDrawer) { + anyShadedShapeTool SST; + Handle(Poly_Triangulation) T; + TopLoc_Location loc; + gp_Pnt p; + Standard_Integer i,j,k,decal ; + Standard_Integer t[3], n[3]; + Standard_Integer nbTriangles = 0, nbVertices = 0; - anyShadedShapeTool SST; - Handle(Poly_Triangulation) T; - TopLoc_Location loc; - gp_Pnt p; - Standard_Integer i,j,k,decal ; - Standard_Integer t[3], n[3]; - Standard_Integer nbTriangles = 0, nbVertices = 0; + // precision for compare square distances + double dPreci = Precision::Confusion()*Precision::Confusion(); - // precision for compare square distances - double dPreci = Precision::Confusion()*Precision::Confusion(); + if ( !aDrawer->ShadingAspectGlobal() ) { - if ( !aDrawer->ShadingAspectGlobal() ) { - - Handle(Graphic3d_AspectFillArea3d) Asp = aDrawer->ShadingAspect()->Aspect(); - if(anyShadedShapeTool::IsClosed(aShape)) { - Asp->SuppressBackFace(); - } else { - Asp->AllowBackFace(); - } - Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(Asp); + Handle(Graphic3d_AspectFillArea3d) Asp = aDrawer->ShadingAspect()->Aspect(); + if(anyShadedShapeTool::IsClosed(aShape)) { + Asp->SuppressBackFace(); + } else { + Asp->AllowBackFace(); } + Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(Asp); + } #ifdef G005 - if( Graphic3d_ArrayOfPrimitives::IsEnable() ) { + if( Graphic3d_ArrayOfPrimitives::IsEnable() ) { - for (SST.Init(aShape); SST.MoreFace(); SST.NextFace()) { - const anyTopFace& F = SST.CurrentFace(); - T = SST.Triangulation(F, loc); - if (!T.IsNull()) { - nbTriangles += T->NbTriangles(); - nbVertices += T->NbNodes(); - } - } - - if (nbVertices > 2 && nbTriangles > 0) { - Handle(Graphic3d_ArrayOfTriangles) parray = - new Graphic3d_ArrayOfTriangles(nbVertices,3*nbTriangles, - Standard_True,Standard_False,Standard_False,Standard_True); - for (SST.Init(aShape); SST.MoreFace(); SST.NextFace()) { - const anyTopFace& F = SST.CurrentFace(); - T = SST.Triangulation(F, loc); - if (!T.IsNull()) { - const gp_Trsf& trsf = loc.Transformation(); - Poly_Connect pc(T); - // Extracts vertices & normals from nodes - const TColgp_Array1OfPnt& Nodes = T->Nodes(); - TColgp_Array1OfDir NORMAL(Nodes.Lower(), Nodes.Upper()); - SST.Normal(F, pc, NORMAL); - - decal = parray->VertexNumber(); - for (i= Nodes.Lower(); i<= Nodes.Upper(); i++) { - p = Nodes(i); - if( !loc.IsIdentity() ) { - p.Transform(trsf); - NORMAL(i).Transform(trsf); - } - parray->AddVertex(p,NORMAL(i)); - } - - // Fill parray with vertex and edge visibillity info - const Poly_Array1OfTriangle& triangles = T->Triangles(); - for (i = 1; i <= T->NbTriangles(); i++) { - pc.Triangles(i,t[0],t[1],t[2]); - if (SST.Orientation(F) == TopAbs_REVERSED) - triangles(i).Get(n[0],n[2],n[1]); - else - triangles(i).Get(n[0],n[1],n[2]); - gp_Pnt P1 = Nodes(n[0]); - gp_Pnt P2 = Nodes(n[1]); - gp_Pnt P3 = Nodes(n[2]); - gp_Vec V1(P1,P2); - if ( V1.SquareMagnitude() > dPreci ) { - gp_Vec V2(P2,P3); - if ( V2.SquareMagnitude() > dPreci ) { - gp_Vec V3(P3,P1); - if ( V3.SquareMagnitude() > dPreci ) { - V1.Normalize(); - V2.Normalize(); - V1.Cross(V2); - if ( V1.SquareMagnitude() > dPreci ) { - parray->AddEdge(n[0]+decal,t[0] == 0); - parray->AddEdge(n[1]+decal,t[1] == 0); - parray->AddEdge(n[2]+decal,t[2] == 0); - } - } - } - } - } - } - } - Prs3d_Root::CurrentGroup(aPresentation)->BeginPrimitives(); - Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(parray); - Prs3d_Root::CurrentGroup(aPresentation)->EndPrimitives(); - } - return Standard_True; - } -#endif - - // phase de comptage: - Standard_Integer nt, nnn, n1, n2, n3, nnv, EI; - static Standard_Integer plus1mod3[3] = {1, 2, 0}; for (SST.Init(aShape); SST.MoreFace(); SST.NextFace()) { const anyTopFace& F = SST.CurrentFace(); T = SST.Triangulation(F, loc); if (!T.IsNull()) { - - nnn = T->NbTriangles(); - const TColgp_Array1OfPnt& Nodes = T->Nodes(); - const Poly_Array1OfTriangle& triangles = T->Triangles(); - for (nt = 1; nt <= nnn; nt++) { - if (SST.Orientation(F) == TopAbs_REVERSED) - triangles(nt).Get(n1,n3,n2); - else - triangles(nt).Get(n1,n2,n3); - const gp_Pnt& P1 = Nodes(n1); - const gp_Pnt& P2 = Nodes(n2); - const gp_Pnt& P3 = Nodes(n3); - gp_Vec V1(P1,P2); - if ( V1.SquareMagnitude() > dPreci ) { - gp_Vec V2(P2,P3); - if (V2.SquareMagnitude() > dPreci ) { - gp_Vec V3(P3,P1); - if (V3.SquareMagnitude() > dPreci ) { - V1.Normalize(); - V2.Normalize(); - V1.Cross(V2); - if (V1.SquareMagnitude() > dPreci ) { - nbTriangles++; - } - } - } - } - } - nbVertices += T->NbNodes(); + nbTriangles += T->NbTriangles(); + nbVertices += T->NbNodes(); } - } + } if (nbVertices > 2 && nbTriangles > 0) { - Graphic3d_Array1OfVertexN AVN(1, nbVertices); - Aspect_Array1OfEdge AE(1, 3*nbTriangles); - - EI = 1; - nnv = 1; - + Handle(Graphic3d_ArrayOfTriangles) parray = + new Graphic3d_ArrayOfTriangles(nbVertices,3*nbTriangles, + Standard_True,Standard_False,Standard_False,Standard_True); for (SST.Init(aShape); SST.MoreFace(); SST.NextFace()) { - const anyTopFace& F = SST.CurrentFace(); - T = SST.Triangulation(F, loc); - if (!T.IsNull()) { - Poly_Connect pc(T); - // 1- les noeuds. - const TColgp_Array1OfPnt& Nodes = T->Nodes(); - TColgp_Array1OfDir NORMAL(Nodes.Lower(), Nodes.Upper()); - SST.Normal(F, pc, NORMAL); - decal = nnv-1; - - for (j= Nodes.Lower(); j<= Nodes.Upper(); j++) { - p = Nodes(j).Transformed(loc.Transformation()); - AVN(nnv).SetCoord(p.X(), p.Y(), p.Z()); - AVN(nnv).SetNormal(NORMAL(j).X(), NORMAL(j).Y(), NORMAL(j).Z()); - nnv++; - } - // 2- les edges. - nbTriangles = T->NbTriangles(); - const Poly_Array1OfTriangle& triangles = T->Triangles(); - - for (i = 1; i <= nbTriangles; i++) { - pc.Triangles(i,t[0],t[1],t[2]); - if (SST.Orientation(F) == TopAbs_REVERSED) - triangles(i).Get(n[0],n[2],n[1]); - else - triangles(i).Get(n[0],n[1],n[2]); - const gp_Pnt& P1 = Nodes(n[0]); - const gp_Pnt& P2 = Nodes(n[1]); - const gp_Pnt& P3 = Nodes(n[2]); - gp_Vec V1(P1,P2); - if (V1.SquareMagnitude() > 1.e-10) { - gp_Vec V2(P2,P3); - if (V2.SquareMagnitude() > 1.e-10) { - gp_Vec V3(P3,P1); - if (V3.SquareMagnitude() > 1.e-10) { - V1.Normalize(); - V2.Normalize(); - V1.Cross(V2); - if (V1.SquareMagnitude() > 1.e-10) { - for (j = 0; j < 3; j++) { - k = plus1mod3[j]; - if (t[j] == 0) - AE(EI).SetValues(n[j]+decal, n[k]+decal, Aspect_TOE_VISIBLE); - else - AE(EI).SetValues(n[j]+decal, n[k]+decal, Aspect_TOE_INVISIBLE); - EI++; - } - } - } - } - } - } + const anyTopFace& F = SST.CurrentFace(); + T = SST.Triangulation(F, loc); + if (!T.IsNull()) { + const gp_Trsf& trsf = loc.Transformation(); + Poly_Connect pc(T); + // Extracts vertices & normals from nodes + const TColgp_Array1OfPnt& Nodes = T->Nodes(); + TColgp_Array1OfDir NORMAL(Nodes.Lower(), Nodes.Upper()); + SST.Normal(F, pc, NORMAL); + + decal = parray->VertexNumber(); + for (i= Nodes.Lower(); i<= Nodes.Upper(); i++) { + p = Nodes(i); + if( !loc.IsIdentity() ) { + p.Transform(trsf); + NORMAL(i).Transform(trsf); + } + parray->AddVertex(p,NORMAL(i)); + } + + // Fill parray with vertex and edge visibillity info + const Poly_Array1OfTriangle& triangles = T->Triangles(); + for (i = 1; i <= T->NbTriangles(); i++) { + pc.Triangles(i,t[0],t[1],t[2]); + if (SST.Orientation(F) == TopAbs_REVERSED) + triangles(i).Get(n[0],n[2],n[1]); + else + triangles(i).Get(n[0],n[1],n[2]); + gp_Pnt P1 = Nodes(n[0]); + gp_Pnt P2 = Nodes(n[1]); + gp_Pnt P3 = Nodes(n[2]); + gp_Vec V1(P1,P2); + if ( V1.SquareMagnitude() > dPreci ) { + gp_Vec V2(P2,P3); + if ( V2.SquareMagnitude() > dPreci ) { + gp_Vec V3(P3,P1); + if ( V3.SquareMagnitude() > dPreci ) { + V1.Normalize(); + V2.Normalize(); + V1.Cross(V2); + if ( V1.SquareMagnitude() > dPreci ) { + parray->AddEdge(n[0]+decal,t[0] == 0); + parray->AddEdge(n[1]+decal,t[1] == 0); + parray->AddEdge(n[2]+decal,t[2] == 0); + } + } + } + } + } } - } - Prs3d_Root::CurrentGroup(aPresentation)->TriangleSet(AVN, AE); + } + Prs3d_Root::CurrentGroup(aPresentation)->BeginPrimitives(); + Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(parray); + Prs3d_Root::CurrentGroup(aPresentation)->EndPrimitives(); } return Standard_True; + } +#endif + + // phase de comptage: + Standard_Integer nt, nnn, n1, n2, n3, nnv, EI; + static Standard_Integer plus1mod3[3] = {1, 2, 0}; + for (SST.Init(aShape); SST.MoreFace(); SST.NextFace()) { + const anyTopFace& F = SST.CurrentFace(); + T = SST.Triangulation(F, loc); + if (!T.IsNull()) { + nnn = T->NbTriangles(); + const TColgp_Array1OfPnt& Nodes = T->Nodes(); + const Poly_Array1OfTriangle& triangles = T->Triangles(); + for (nt = 1; nt <= nnn; nt++) { + if (SST.Orientation(F) == TopAbs_REVERSED) + triangles(nt).Get(n1,n3,n2); + else + triangles(nt).Get(n1,n2,n3); + const gp_Pnt& P1 = Nodes(n1); + const gp_Pnt& P2 = Nodes(n2); + const gp_Pnt& P3 = Nodes(n3); + gp_Vec V1(P1,P2); + if ( V1.SquareMagnitude() > dPreci ) { + gp_Vec V2(P2,P3); + if (V2.SquareMagnitude() > dPreci ) { + gp_Vec V3(P3,P1); + if (V3.SquareMagnitude() > dPreci ) { + V1.Normalize(); + V2.Normalize(); + V1.Cross(V2); + if (V1.SquareMagnitude() > dPreci ) { + nbTriangles++; + } + } + } + } + } + nbVertices += T->NbNodes(); + } + } + + if (nbVertices > 2 && nbTriangles > 0) { + Graphic3d_Array1OfVertexN AVN(1, nbVertices); + Aspect_Array1OfEdge AE(1, 3*nbTriangles); + + EI = 1; + nnv = 1; + + for (SST.Init(aShape); SST.MoreFace(); SST.NextFace()) { + const anyTopFace& F = SST.CurrentFace(); + T = SST.Triangulation(F, loc); + if (!T.IsNull()) { + Poly_Connect pc(T); + // 1- les noeuds. + const TColgp_Array1OfPnt& Nodes = T->Nodes(); + TColgp_Array1OfDir NORMAL(Nodes.Lower(), Nodes.Upper()); + SST.Normal(F, pc, NORMAL); + decal = nnv-1; + + for (j= Nodes.Lower(); j<= Nodes.Upper(); j++) { + p = Nodes(j).Transformed(loc.Transformation()); + AVN(nnv).SetCoord(p.X(), p.Y(), p.Z()); + AVN(nnv).SetNormal(NORMAL(j).X(), NORMAL(j).Y(), NORMAL(j).Z()); + nnv++; + } + // 2- les edges. + nbTriangles = T->NbTriangles(); + const Poly_Array1OfTriangle& triangles = T->Triangles(); + + for (i = 1; i <= nbTriangles; i++) { + pc.Triangles(i,t[0],t[1],t[2]); + if (SST.Orientation(F) == TopAbs_REVERSED) + triangles(i).Get(n[0],n[2],n[1]); + else + triangles(i).Get(n[0],n[1],n[2]); + const gp_Pnt& P1 = Nodes(n[0]); + const gp_Pnt& P2 = Nodes(n[1]); + const gp_Pnt& P3 = Nodes(n[2]); + gp_Vec V1(P1,P2); + if (V1.SquareMagnitude() > 1.e-10) { + gp_Vec V2(P2,P3); + if (V2.SquareMagnitude() > 1.e-10) { + gp_Vec V3(P3,P1); + if (V3.SquareMagnitude() > 1.e-10) { + V1.Normalize(); + V2.Normalize(); + V1.Cross(V2); + if (V1.SquareMagnitude() > 1.e-10) { + for (j = 0; j < 3; j++) { + k = plus1mod3[j]; + if (t[j] == 0) + AE(EI).SetValues(n[j]+decal, n[k]+decal, Aspect_TOE_VISIBLE); + else + AE(EI).SetValues(n[j]+decal, n[k]+decal, Aspect_TOE_INVISIBLE); + EI++; + } + } + } + } + } + } + } + } + Prs3d_Root::CurrentGroup(aPresentation)->TriangleSet(AVN, AE); + } + return Standard_True; } void Prs3d_ShadedShape::Add(const Handle (Prs3d_Presentation)& aPresentation, - const anyShape& aShape, - const Handle (Prs3d_Drawer)& aDrawer) + const anyShape& aShape, + const Handle (Prs3d_Drawer)& aDrawer) { if (aShape.IsNull()) return; @@ -308,13 +301,13 @@ void Prs3d_ShadedShape::Add(const Handle (Prs3d_Presentation)& aPresentation, // il faut presenter les edges isoles. for (ex.Init(aShape, TopAbs_EDGE, TopAbs_FACE); ex.More(); ex.Next()) { - haselement = Standard_True; - B.Add(CO, ex.Current()); + haselement = Standard_True; + B.Add(CO, ex.Current()); } // il faut presenter les vertex isoles. for (ex.Init(aShape, TopAbs_VERTEX, TopAbs_EDGE); ex.More(); ex.Next()) { - haselement = Standard_True; - B.Add(CO, ex.Current()); + haselement = Standard_True; + B.Add(CO, ex.Current()); } if (haselement) StdPrs_WFShape::Add(aPresentation, CO, aDrawer); } @@ -324,14 +317,18 @@ void Prs3d_ShadedShape::Add(const Handle (Prs3d_Presentation)& aPresentation, } Standard_Real aDeflection = GetDeflection(aShape, aDrawer); //using of plugin - BRepMesh_PDiscretRoot pAlgo; - pAlgo=BRepMesh_DiscretFactory::Get().Discret(aShape, - aDeflection, - aDrawer->HLRAngle()); - if (pAlgo) - pAlgo->Perform(); + // Check if it is possible to avoid unnecessary recomputation + // of shape triangulation + if( !BRepTools::Triangulation(aShape, aDeflection) ) + { + BRepTools::Clean(aShape); + BRepMesh_PDiscretRoot pAlgo; + pAlgo=BRepMesh_DiscretFactory::Get().Discret(aShape, + aDeflection, + aDrawer->HLRAngle()); + if (pAlgo) + pAlgo->Perform(); + } ShadeFromShape(aShape, aDeflection, Standard_True, aPresentation, aDrawer); } - - diff --git a/src/Select3D/Select3D_SensitiveCurve.cxx b/src/Select3D/Select3D_SensitiveCurve.cxx index 8259ac9673..b338ee628c 100755 --- a/src/Select3D/Select3D_SensitiveCurve.cxx +++ b/src/Select3D/Select3D_SensitiveCurve.cxx @@ -94,7 +94,7 @@ Matches (const Standard_Real XMin, Bnd_Box2d BoundBox; BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol); - for(Standard_Integer j=0; j