1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-16 10:08:36 +03:00

0022302: BRepMesh_IncrimentalMesh calls for each face of shape on vdisplay

This commit is contained in:
OAN 2011-08-19 08:23:45 +00:00 committed by bugmaster
parent f10018adfe
commit 3c34883cdc
6 changed files with 330 additions and 344 deletions

View File

@ -87,10 +87,10 @@ 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 // 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) { if (aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) {
Bnd_Box B; Bnd_Box B;
BRepBndLib::Add(aShape, B); BRepBndLib::Add(aShape, B, Standard_False);
if ( ! B.IsVoid() ) if ( ! B.IsVoid() )
{ {
Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
@ -98,11 +98,7 @@ Standard_Real AIS_Shape::GetDeflection(const TopoDS_Shape& aShape,
aDeflection = Max( aXmax-aXmin, Max(aYmax-aYmin, aZmax-aZmin)) * aDeflection = Max( aXmax-aXmin, Max(aYmax-aYmin, aZmax-aZmin)) *
aDrawer->DeviationCoefficient() * 4; aDrawer->DeviationCoefficient() * 4;
} }
else
aDeflection = aDrawer->MaximalChordialDeviation();
} }
else
aDeflection = aDrawer->MaximalChordialDeviation();
return aDeflection; return aDeflection;
} }
@ -496,20 +492,7 @@ void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
// POP protection against crash in low layers // POP protection against crash in low layers
Standard_Real aDeflection = myDrawer->MaximalChordialDeviation(); Standard_Real aDeflection = GetDeflection(shape, myDrawer);
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_Boolean autoTriangulation = Standard_True; Standard_Boolean autoTriangulation = Standard_True;
try { try {
OCC_CATCH_SIGNALS OCC_CATCH_SIGNALS
@ -518,7 +501,7 @@ void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
shape, shape,
TypOfSel, TypOfSel,
aDeflection, aDeflection,
myDrawer->DeviationAngle(), myDrawer->HLRAngle(),
autoTriangulation); autoTriangulation);
} catch ( Standard_Failure ) { } catch ( Standard_Failure ) {
// cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl; // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
@ -1178,5 +1161,4 @@ Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
anAngle = myDrawer->HLRAngle(); anAngle = myDrawer->HLRAngle();
aPreviousAngle = myDrawer->PreviousHLRDeviationAngle (); aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
return myDrawer->IsOwnHLRDeviationAngle(); return myDrawer->IsOwnHLRDeviationAngle();
} }

View File

@ -24,7 +24,9 @@ is
-- Package methods for shapes -- 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. ---Purpose:Adds the shape S to the bounding box B.
-- More precisely are successively added to B: -- More precisely are successively added to B:
-- - each face of S; the triangulation of the face is used if it exists, -- - each face of S; the triangulation of the face is used if it exists,

View File

@ -26,12 +26,11 @@
//purpose : Add a shape bounding to a box //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; TopExp_Explorer ex;
// Add the faces // Add the faces
BRepAdaptor_Surface BS; BRepAdaptor_Surface BS;
Handle(Geom_Surface) GS; Handle(Geom_Surface) GS;
Handle(Poly_Triangulation) T; Handle(Poly_Triangulation) T;
@ -42,7 +41,8 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B)
for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next()) { for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next()) {
const TopoDS_Face& F = TopoDS::Face(ex.Current()); const TopoDS_Face& F = TopoDS::Face(ex.Current());
T = BRep_Tool::Triangulation(F, l); T = BRep_Tool::Triangulation(F, l);
if (!T.IsNull()) { if (useTriangulation && !T.IsNull())
{
nbNodes = T->NbNodes(); nbNodes = T->NbNodes();
const TColgp_Array1OfPnt& Nodes = T->Nodes(); const TColgp_Array1OfPnt& Nodes = T->Nodes();
for (i = 1; i <= nbNodes; i++) { for (i = 1; i <= nbNodes; i++) {
@ -51,8 +51,8 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B)
} }
// B.Enlarge(T->Deflection()); // B.Enlarge(T->Deflection());
B.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F)); B.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F));
} } else
else { {
GS = BRep_Tool::Surface(F, l); GS = BRep_Tool::Surface(F, l);
if (!GS.IsNull()) { if (!GS.IsNull()) {
BS.Initialize(F, Standard_False); BS.Initialize(F, Standard_False);
@ -80,31 +80,35 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B)
} }
// Add the edges not in faces // Add the edges not in faces
Handle(TColStd_HArray1OfInteger) HIndices; Handle(TColStd_HArray1OfInteger) HIndices;
Handle(Poly_PolygonOnTriangulation) Poly; 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()); const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
Handle(Poly_Polygon3D) P3d = BRep_Tool::Polygon3D(E, l); Handle(Poly_Polygon3D) P3d = BRep_Tool::Polygon3D(E, l);
if (!P3d.IsNull()) { if (!P3d.IsNull())
{
const TColgp_Array1OfPnt& Nodes = P3d->Nodes(); const TColgp_Array1OfPnt& Nodes = P3d->Nodes();
nbNodes = P3d->NbNodes(); nbNodes = P3d->NbNodes();
for (i = 1; i <= nbNodes; i++) { for (i = 1; i <= nbNodes; i++)
{
if (l.IsIdentity()) B.Add(Nodes(i)); if (l.IsIdentity()) B.Add(Nodes(i));
else B.Add(Nodes(i).Transformed(l)); else B.Add(Nodes(i).Transformed(l));
} }
// B.Enlarge(P3d->Deflection()); // B.Enlarge(P3d->Deflection());
B.Enlarge(P3d->Deflection() + BRep_Tool::Tolerance(E)); B.Enlarge(P3d->Deflection() + BRep_Tool::Tolerance(E));
} }
else { else
{
BRep_Tool::PolygonOnTriangulation(E, Poly, T, l); BRep_Tool::PolygonOnTriangulation(E, Poly, T, l);
if (!Poly.IsNull()) { if (useTriangulation && !Poly.IsNull())
{
const TColStd_Array1OfInteger& Indices = Poly->Nodes(); const TColStd_Array1OfInteger& Indices = Poly->Nodes();
const TColgp_Array1OfPnt& Nodes = T->Nodes(); const TColgp_Array1OfPnt& Nodes = T->Nodes();
nbNodes = Indices.Length(); nbNodes = Indices.Length();
for (i = 1; i <= nbNodes; i++) { for (i = 1; i <= nbNodes; i++)
{
if (l.IsIdentity()) B.Add(Nodes(Indices(i))); if (l.IsIdentity()) B.Add(Nodes(Indices(i)));
else B.Add(Nodes(Indices(i)).Transformed(l)); else B.Add(Nodes(Indices(i)).Transformed(l));
} }
@ -112,7 +116,8 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B)
B.Enlarge(Poly->Deflection() + BRep_Tool::Tolerance(E)); B.Enlarge(Poly->Deflection() + BRep_Tool::Tolerance(E));
} }
else { else {
if (BRep_Tool::IsGeometric(E)) { if (BRep_Tool::IsGeometric(E))
{
BC.Initialize(E); BC.Initialize(E);
BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(E), B); BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(E), B);
} }

View File

@ -54,10 +54,10 @@
static Standard_Real GetDeflection(const anyShape& aShape, 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) { if (aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) {
Bnd_Box B; Bnd_Box B;
BRepBndLib::Add(aShape, B); BRepBndLib::Add(aShape, B, Standard_False);
if ( ! B.IsVoid() ) if ( ! B.IsVoid() )
{ {
Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
@ -65,12 +65,7 @@ static Standard_Real GetDeflection(const anyShape& aShape,
aDeflection = MAX3( aXmax-aXmin , aYmax-aYmin , aZmax-aZmin) aDeflection = MAX3( aXmax-aXmin , aYmax-aYmin , aZmax-aZmin)
* aDrawer->DeviationCoefficient()*4; * aDrawer->DeviationCoefficient()*4;
} }
else
aDeflection = aDrawer->MaximalChordialDeviation();
} }
else
aDeflection = aDrawer->MaximalChordialDeviation();
return aDeflection; return aDeflection;
} }
@ -81,7 +76,6 @@ static Standard_Boolean ShadeFromShape(const anyShape& aShape
const Handle (Prs3d_Presentation)& aPresentation, const Handle (Prs3d_Presentation)& aPresentation,
const Handle (Prs3d_Drawer)& aDrawer) const Handle (Prs3d_Drawer)& aDrawer)
{ {
anyShadedShapeTool SST; anyShadedShapeTool SST;
Handle(Poly_Triangulation) T; Handle(Poly_Triangulation) T;
TopLoc_Location loc; TopLoc_Location loc;
@ -187,7 +181,6 @@ static Standard_Boolean ShadeFromShape(const anyShape& aShape
const anyTopFace& F = SST.CurrentFace(); const anyTopFace& F = SST.CurrentFace();
T = SST.Triangulation(F, loc); T = SST.Triangulation(F, loc);
if (!T.IsNull()) { if (!T.IsNull()) {
nnn = T->NbTriangles(); nnn = T->NbTriangles();
const TColgp_Array1OfPnt& Nodes = T->Nodes(); const TColgp_Array1OfPnt& Nodes = T->Nodes();
const Poly_Array1OfTriangle& triangles = T->Triangles(); const Poly_Array1OfTriangle& triangles = T->Triangles();
@ -324,14 +317,18 @@ void Prs3d_ShadedShape::Add(const Handle (Prs3d_Presentation)& aPresentation,
} }
Standard_Real aDeflection = GetDeflection(aShape, aDrawer); Standard_Real aDeflection = GetDeflection(aShape, aDrawer);
//using of plugin //using of plugin
// Check if it is possible to avoid unnecessary recomputation
// of shape triangulation
if( !BRepTools::Triangulation(aShape, aDeflection) )
{
BRepTools::Clean(aShape);
BRepMesh_PDiscretRoot pAlgo; BRepMesh_PDiscretRoot pAlgo;
pAlgo=BRepMesh_DiscretFactory::Get().Discret(aShape, pAlgo=BRepMesh_DiscretFactory::Get().Discret(aShape,
aDeflection, aDeflection,
aDrawer->HLRAngle()); aDrawer->HLRAngle());
if (pAlgo) if (pAlgo)
pAlgo->Perform(); pAlgo->Perform();
}
ShadeFromShape(aShape, aDeflection, Standard_True, aPresentation, aDrawer); ShadeFromShape(aShape, aDeflection, Standard_True, aPresentation, aDrawer);
} }

View File

@ -94,7 +94,7 @@ Matches (const Standard_Real XMin,
Bnd_Box2d BoundBox; Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol); BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
for(Standard_Integer j=0; j<mynbpoints-1; j++) for(Standard_Integer j=0; j<mynbpoints; j++)
{ {
if(BoundBox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[j])) return Standard_False; if(BoundBox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[j])) return Standard_False;
} }

View File

@ -67,6 +67,12 @@ void StdSelect_BRepSelectionTool
const Standard_Real theMaxParam) const Standard_Real theMaxParam)
{ {
Standard_Integer aPriority = (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority; Standard_Integer aPriority = (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority;
if( isAutoTriangulation && !BRepTools::Triangulation (theShape, Precision::Infinite()) )
{
BRepMesh_IncrementalMesh(theShape, theDeflection, Standard_False, theDeviationAngle);
}
Handle(StdSelect_BRepOwner) aBrepOwner; Handle(StdSelect_BRepOwner) aBrepOwner;
switch (theType) switch (theType)
{ {
@ -586,13 +592,7 @@ Standard_Boolean StdSelect_BRepSelectionTool
// check if there is triangulation of the face... // check if there is triangulation of the face...
TopLoc_Location aLoc; TopLoc_Location aLoc;
Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (theFace, aLoc); Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (theFace, aLoc);
if (aTriangulation.IsNull() && theAutoTriangulation)
{
Standard_Real aDefaultDefl = 0.2;
Standard_Real aDefaultAng = 30 * PI / 180.0;
BRepMesh_IncrementalMesh (theFace, aDefaultDefl, Standard_True, aDefaultAng);
aTriangulation = BRep_Tool::Triangulation (theFace, aLoc);
}
if (!aTriangulation.IsNull()) if (!aTriangulation.IsNull())
{ {
Handle(Select3D_SensitiveTriangulation) STG = new Select3D_SensitiveTriangulation (theOwner, aTriangulation, aLoc, theInteriorFlag); Handle(Select3D_SensitiveTriangulation) STG = new Select3D_SensitiveTriangulation (theOwner, aTriangulation, aLoc, theInteriorFlag);