Bug 0020228: [CEA 331] the geompy.RemoveExtraEdges crash with the attached brep shape file.

This commit is contained in:
jfa 2009-04-10 09:14:35 +00:00
parent cca851206f
commit 268965c6d9
2 changed files with 116 additions and 97 deletions

View File

@ -19,10 +19,10 @@
// //
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
// //
// File: BlockFix_CheckTool.cxx // File: BlockFix_CheckTool.cxx
// Created: 17.12.04 11:15:25 // Created: 17.12.04 11:15:25
// Author: Sergey KUUL // Author: Sergey KUUL
//
#include <BlockFix_CheckTool.ixx> #include <BlockFix_CheckTool.ixx>
#include <BRep_Tool.hxx> #include <BRep_Tool.hxx>
@ -78,33 +78,43 @@ void BlockFix_CheckTool::Perform()
myNbUF=0; myNbUF=0;
myNbUE=0; myNbUE=0;
myNbUFUE=0; myNbUFUE=0;
TopExp_Explorer exps;
for(exps.Init(myShape, TopAbs_SOLID); exps.More(); exps.Next()) { TopExp_Explorer exps (myShape, TopAbs_SOLID);
TopTools_MapOfShape mapS;
for (; exps.More(); exps.Next()) {
TopoDS_Solid aSolid = TopoDS::Solid(exps.Current()); TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
if (!mapS.Add(aSolid)) continue;
myNbSolids++; myNbSolids++;
Standard_Boolean IsBlock=Standard_True; Standard_Boolean IsBlock=Standard_True;
Standard_Boolean MayBeUF=Standard_False; Standard_Boolean MayBeUF=Standard_False;
Standard_Boolean MayBeUE=Standard_False; Standard_Boolean MayBeUE=Standard_False;
Standard_Integer nf=0; Standard_Integer nf=0;
TopExp_Explorer expf; TopExp_Explorer expf (aSolid, TopAbs_FACE);
for(expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) nf++; TopTools_MapOfShape mapF;
for (; expf.More(); expf.Next()) {
if(nf<6) { if (mapF.Add(expf.Current()))
IsBlock=Standard_False; nf++;
} }
else if(nf>6) {
IsBlock=Standard_False; if (nf < 6) {
IsBlock = Standard_False;
}
else if (nf > 6) {
IsBlock = Standard_False;
// check faces unification // check faces unification
TopTools_SequenceOfShape faces; TopTools_SequenceOfShape faces;
for( expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) { mapF.Clear();
TopoDS_Face aFace = TopoDS::Face(expf.Current()); for (expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
faces.Append(aFace); if (mapF.Add(expf.Current())) {
TopoDS_Face aFace = TopoDS::Face(expf.Current());
faces.Append(aFace);
}
} }
Standard_Boolean HasFacesForUnification = Standard_False; Standard_Boolean HasFacesForUnification = Standard_False;
for(Standard_Integer i=1; i<faces.Length() && !HasFacesForUnification; i++) { for (Standard_Integer i=1; i<faces.Length() && !HasFacesForUnification; i++) {
TopoDS_Face F1 = TopoDS::Face(faces.Value(i)); TopoDS_Face F1 = TopoDS::Face(faces.Value(i));
TopTools_MapOfShape Edges; TopTools_MapOfShape Edges;
for(TopExp_Explorer expe(F1,TopAbs_EDGE); expe.More(); expe.Next()) for (TopExp_Explorer expe(F1,TopAbs_EDGE); expe.More(); expe.Next())
Edges.Add(expe.Current().Oriented(TopAbs_FORWARD)); Edges.Add(expe.Current().Oriented(TopAbs_FORWARD));
TopLoc_Location L1; TopLoc_Location L1;
Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1,L1); Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1,L1);
@ -124,51 +134,57 @@ void BlockFix_CheckTool::Perform()
} }
} }
} }
if(HasFacesForUnification) { if (HasFacesForUnification) {
MayBeUF=Standard_True; MayBeUF=Standard_True;
} }
} }
Standard_Integer nbe=0; Standard_Integer nbe=0;
TopTools_MapOfShape DegenEdges; TopTools_MapOfShape DegenEdges;
TopExp_Explorer expe; TopExp_Explorer expe (aSolid, TopAbs_EDGE);
for(expe.Init(aSolid, TopAbs_EDGE); expe.More(); expe.Next()) { TopTools_MapOfShape mapE;
for (; expe.More(); expe.Next()) {
TopoDS_Edge E = TopoDS::Edge(expe.Current()); TopoDS_Edge E = TopoDS::Edge(expe.Current());
if(BRep_Tool::Degenerated(E)) { if (!mapE.Add(E)) continue;
if(!DegenEdges.Contains(E)) { if (BRep_Tool::Degenerated(E)) {
DegenEdges.Add(E); DegenEdges.Add(E);
}
} }
else { else {
nbe++; nbe++;
} }
} }
if( nbe==24 && DegenEdges.Extent()>0 ) { if (nbe == 12 && DegenEdges.Extent() > 0) {
IsBlock=Standard_False; IsBlock = Standard_False;
myNbDegen++; myNbDegen++;
myPossibleBlocks.Append(aSolid); myPossibleBlocks.Append(aSolid);
continue; continue;
} }
if(nbe<24) if (nbe < 12)
IsBlock=Standard_False; IsBlock = Standard_False;
if(nbe>24) { if (nbe > 12) {
IsBlock=Standard_False; IsBlock = Standard_False;
// check edges unification // check edges unification
// creating map of edge faces // creating map of edge faces
TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces; TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces); TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
for(expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
mapF.Clear();
for (expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
TopoDS_Face aFace = TopoDS::Face(expf.Current()); TopoDS_Face aFace = TopoDS::Face(expf.Current());
if (!mapF.Add(aFace)) continue;
TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges; TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
for(expe.Init(aFace,TopAbs_EDGE); expe.More(); expe.Next()) {
TopTools_MapOfShape mapEe;
for (expe.Init(aFace, TopAbs_EDGE); expe.More(); expe.Next()) {
TopoDS_Edge edge = TopoDS::Edge(expe.Current()); TopoDS_Edge edge = TopoDS::Edge(expe.Current());
if(!aMapEdgeFaces.Contains(edge)) continue; if (!mapEe.Add(edge)) continue;
if (!aMapEdgeFaces.Contains(edge)) continue;
const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge); const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
TopTools_ListIteratorOfListOfShape anIter(aList); TopTools_ListIteratorOfListOfShape anIter (aList);
for( ; anIter.More(); anIter.Next()) { for (; anIter.More(); anIter.Next()) {
TopoDS_Face face = TopoDS::Face(anIter.Value()); TopoDS_Face face = TopoDS::Face(anIter.Value());
if(face.IsSame(aFace)) continue; if (face.IsSame(aFace)) continue;
if(aMapFacesEdges.Contains(face)) { if (aMapFacesEdges.Contains(face)) {
aMapFacesEdges.ChangeFromKey(face).Append(edge); aMapFacesEdges.ChangeFromKey(face).Append(edge);
} }
else { else {
@ -178,34 +194,33 @@ void BlockFix_CheckTool::Perform()
} }
} }
} }
Standard_Integer i=1; Standard_Integer i = 1;
for(; i<=aMapFacesEdges.Extent(); i++) { for (; i <= aMapFacesEdges.Extent(); i++) {
const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i); const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
if(ListEdges.Extent()>1) break; if (ListEdges.Extent() > 1) break;
} }
if(i<=aMapFacesEdges.Extent()) { if (i <= aMapFacesEdges.Extent()) {
MayBeUE=Standard_True; MayBeUE = Standard_True;
break; break;
} }
} }
} }
if(IsBlock) if (IsBlock)
myNbBlocks++; myNbBlocks++;
else { else {
if(MayBeUF) { if (MayBeUF) {
myPossibleBlocks.Append(aSolid); myPossibleBlocks.Append(aSolid);
if(MayBeUE) if (MayBeUE)
myNbUFUE++; myNbUFUE++;
else else
myNbUF++; myNbUF++;
} }
else if(MayBeUE) { else if (MayBeUE) {
myNbUE++; myNbUE++;
myPossibleBlocks.Append(aSolid); myPossibleBlocks.Append(aSolid);
} }
} }
} }
myHasCheck = Standard_True; myHasCheck = Standard_True;

View File

@ -176,7 +176,7 @@ TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape)
// processing each solid // processing each solid
TopExp_Explorer exps; TopExp_Explorer exps;
for(exps.Init(Shape, TopAbs_SOLID); exps.More(); exps.Next()) { for (exps.Init(Shape, TopAbs_SOLID); exps.More(); exps.Next()) {
TopoDS_Solid aSolid = TopoDS::Solid(exps.Current()); TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
// creating map of edge faces // creating map of edge faces
@ -185,28 +185,37 @@ TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape)
// map of processed shapes // map of processed shapes
TopTools_MapOfShape aProcessed; TopTools_MapOfShape aProcessed;
Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape; Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
Standard_Integer NbModif=0; Standard_Integer NbModif = 0;
Standard_Boolean hasFailed = Standard_False; Standard_Boolean hasFailed = Standard_False;
Standard_Real tol = Min(Max(Precision::Confusion(), myTolerance/10.),0.1); Standard_Real tol = Min(Max(Precision::Confusion(), myTolerance/10.), 0.1);
// processing each face
// count faces
int nbf = 0;
TopExp_Explorer exp; TopExp_Explorer exp;
//for( exp.Init(Shape, TopAbs_FACE); exp.More(); exp.Next()) { TopTools_MapOfShape mapF;
for( exp.Init(aSolid, TopAbs_FACE); exp.More(); exp.Next()) { for (exp.Init(aSolid, TopAbs_FACE); exp.More(); exp.Next()) {
if (mapF.Add(exp.Current()))
nbf++;
}
// processing each face
mapF.Clear();
for (exp.Init(aSolid, TopAbs_FACE); exp.More() && nbf > 6; exp.Next()) {
TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD)); TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
if(aProcessed.Contains(aFace)) if (aProcessed.Contains(aFace))
continue; continue;
Standard_Integer dummy; Standard_Integer dummy;
TopTools_SequenceOfShape edges; TopTools_SequenceOfShape edges;
AddOrdinaryEdges(edges,aFace,dummy); AddOrdinaryEdges(edges,aFace,dummy);
TopTools_SequenceOfShape faces; TopTools_SequenceOfShape faces;
faces.Append(aFace); faces.Append(aFace);
//surface and location to construct result //surface and location to construct result
TopLoc_Location aBaseLocation; TopLoc_Location aBaseLocation;
Handle(Geom_Surface) aBaseSurface = BRep_Tool::Surface(aFace,aBaseLocation); Handle(Geom_Surface) aBaseSurface = BRep_Tool::Surface(aFace,aBaseLocation);
@ -214,24 +223,24 @@ TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape)
// find adjacent faces to union // find adjacent faces to union
Standard_Integer i; Standard_Integer i;
for( i = 1; i <= edges.Length(); i++) { for (i = 1; i <= edges.Length(); i++) {
TopoDS_Edge edge = TopoDS::Edge(edges(i)); TopoDS_Edge edge = TopoDS::Edge(edges(i));
if(BRep_Tool::Degenerated(edge)) if (BRep_Tool::Degenerated(edge))
continue; continue;
const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge); const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
TopTools_ListIteratorOfListOfShape anIter(aList); TopTools_ListIteratorOfListOfShape anIter(aList);
for( ; anIter.More(); anIter.Next()) { for (; anIter.More(); anIter.Next()) {
TopoDS_Face anCheckedFace = TopoDS::Face(anIter.Value().Oriented(TopAbs_FORWARD)); TopoDS_Face anCheckedFace = TopoDS::Face(anIter.Value().Oriented(TopAbs_FORWARD));
if(anCheckedFace.IsSame(aFace)) if (anCheckedFace.IsSame(aFace))
continue; continue;
if(aProcessed.Contains(anCheckedFace)) if (aProcessed.Contains(anCheckedFace))
continue; continue;
if(IsSameDomain(aFace,anCheckedFace)) { if (IsSameDomain(aFace,anCheckedFace)) {
if(aList.Extent() != 2) { if (aList.Extent() != 2) {
// non mainfold case is not processed // non mainfold case is not processed
continue; continue;
} }
@ -242,7 +251,7 @@ TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape)
B.MakeFace(aMockUpFace,aBaseSurface,aBaseLocation,0.); B.MakeFace(aMockUpFace,aBaseSurface,aBaseLocation,0.);
MovePCurves(aMockUpFace,anCheckedFace); MovePCurves(aMockUpFace,anCheckedFace);
if(AddOrdinaryEdges(edges,aMockUpFace,dummy)) { if (AddOrdinaryEdges(edges,aMockUpFace,dummy)) {
// sequence edges is modified // sequence edges is modified
i = dummy; i = dummy;
} }
@ -255,7 +264,7 @@ TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape)
} }
// all faces collected in the sequence. Perform union of faces // all faces collected in the sequence. Perform union of faces
if(faces.Length() > 1) { if (faces.Length() > 1) {
NbModif++; NbModif++;
TopoDS_Face aResult; TopoDS_Face aResult;
BRep_Builder B; BRep_Builder B;
@ -263,7 +272,7 @@ TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape)
Standard_Integer nbWires = 0; Standard_Integer nbWires = 0;
// connecting wires // connecting wires
while(edges.Length()>0) { while (edges.Length()>0) {
Standard_Boolean isEdge3d = Standard_False; Standard_Boolean isEdge3d = Standard_False;
nbWires++; nbWires++;
@ -372,13 +381,11 @@ TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape)
B.Add(aW,E); B.Add(aW,E);
B.Add(aResult,aW); B.Add(aResult,aW);
} }
} }
// perform substitution of face // perform substitution of face
aContext->Replace(aContext->Apply(aFace),aResult); aContext->Replace(aContext->Apply(aFace),aResult);
ShapeFix_Face sff (aResult); ShapeFix_Face sff (aResult);
//Intializing by tolerances //Intializing by tolerances
sff.SetPrecision(myTolerance); sff.SetPrecision(myTolerance);
@ -395,7 +402,7 @@ TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape)
// breaking down to several faces // breaking down to several faces
TopoDS_Shape theResult = aContext->Apply(aResult); TopoDS_Shape theResult = aContext->Apply(aResult);
for(TopExp_Explorer aFaceExp(theResult,TopAbs_FACE);aFaceExp.More();aFaceExp.Next()) { for (TopExp_Explorer aFaceExp (theResult,TopAbs_FACE); aFaceExp.More(); aFaceExp.Next()) {
TopoDS_Face aCurrent = TopoDS::Face(aFaceExp.Current().Oriented(TopAbs_FORWARD)); TopoDS_Face aCurrent = TopoDS::Face(aFaceExp.Current().Oriented(TopAbs_FORWARD));
Handle(TColGeom_HArray2OfSurface) grid = new TColGeom_HArray2OfSurface ( 1, 1, 1, 1 ); Handle(TColGeom_HArray2OfSurface) grid = new TColGeom_HArray2OfSurface ( 1, 1, 1, 1 );
grid->SetValue ( 1, 1, aBaseSurface ); grid->SetValue ( 1, 1, aBaseSurface );
@ -437,27 +444,25 @@ TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape)
for(i = 2; i <= faces.Length(); i++) for(i = 2; i <= faces.Length(); i++)
aContext->Remove(faces(i)); aContext->Remove(faces(i));
} }
} } // end processing each face
//TopoDS_Shape aResult = Shape; //TopoDS_Shape aResult = Shape;
if(NbModif>0) { if (NbModif > 0 && !hasFailed) {
TopoDS_Shape aResult = aSolid; TopoDS_Shape aResult = aContext->Apply(aSolid);
if(!hasFailed) {
aResult = aContext->Apply(aSolid); ShapeFix_Edge sfe;
for (exp.Init(aResult,TopAbs_EDGE); exp.More(); exp.Next()) {
ShapeFix_Edge sfe; TopoDS_Edge E = TopoDS::Edge(exp.Current());
for(exp.Init(aResult,TopAbs_EDGE); exp.More(); exp.Next()) { sfe.FixVertexTolerance (E);
TopoDS_Edge E = TopoDS::Edge(exp.Current()); // ptv add fix same parameter
sfe.FixVertexTolerance (E); sfe.FixSameParameter(E, myTolerance);
// ptv add fix same parameter
sfe.FixSameParameter(E, myTolerance);
}
myContext->Replace(aSolid,aResult);
} }
myContext->Replace(aSolid, aResult);
} }
// else { //else
for( exp.Init(aSolid, TopAbs_FACE); exp.More(); exp.Next()) { {
for (exp.Init(aSolid, TopAbs_FACE); exp.More(); exp.Next()) {
TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD)); TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire; Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
sfw->SetContext(myContext); sfw->SetContext(myContext);
@ -465,15 +470,14 @@ TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape)
sfw->SetMinTolerance(myTolerance); sfw->SetMinTolerance(myTolerance);
sfw->SetMaxTolerance(Max(1.,myTolerance*1000.)); sfw->SetMaxTolerance(Max(1.,myTolerance*1000.));
sfw->SetFace(aFace); sfw->SetFace(aFace);
for ( TopoDS_Iterator iter(aFace,Standard_False); iter.More(); iter.Next()) { for (TopoDS_Iterator iter (aFace,Standard_False); iter.More(); iter.Next()) {
TopoDS_Wire wire = TopoDS::Wire ( iter.Value() ); TopoDS_Wire wire = TopoDS::Wire(iter.Value());
sfw->Load(wire); sfw->Load(wire);
sfw->FixReorder(); sfw->FixReorder();
sfw->FixShifted(); sfw->FixShifted();
} }
} }
// } }
} // end processing each solid } // end processing each solid
aResShape = myContext->Apply(Shape); aResShape = myContext->Apply(Shape);