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

0025806: Stack overflow during meshing

Test-case for issue #25806
This commit is contained in:
oan 2015-02-19 15:10:25 +03:00 committed by bugmaster
parent 40738f9ad7
commit 0a9b38ef44
4 changed files with 87 additions and 24 deletions

View File

@ -127,6 +127,8 @@ namespace BRepMesh
typedef NCollection_Handle<DMapOfVertexInteger> HDMapOfVertexInteger; typedef NCollection_Handle<DMapOfVertexInteger> HDMapOfVertexInteger;
typedef NCollection_Handle<DMapOfIntegerListOfXY> HDMapOfIntegerListOfXY; typedef NCollection_Handle<DMapOfIntegerListOfXY> HDMapOfIntegerListOfXY;
typedef NCollection_Handle<BRepMesh_VertexTool> HVertexTool; typedef NCollection_Handle<BRepMesh_VertexTool> HVertexTool;
typedef NCollection_Handle<SequenceOfBndB2d> HSequenceOfBndB2d;
typedef NCollection_Handle<SequenceOfInteger> HSequenceOfInteger;
//! Other data structures //! Other data structures
typedef std::pair<HArray1OfSegments, HBndBox2dTree> SegmentsTree; typedef std::pair<HArray1OfSegments, HBndBox2dTree> SegmentsTree;

View File

@ -1701,7 +1701,41 @@ void BRepMesh_Delaun::meshPolygon(BRepMesh::SequenceOfInteger& thePolygon,
} }
} }
meshSimplePolygon( thePolygon, thePolyBoxes ); BRepMesh::SequenceOfInteger* aPolygon1 = &thePolygon;
BRepMesh::SequenceOfBndB2d* aPolyBoxes1 = &thePolyBoxes;
BRepMesh::HSequenceOfInteger aPolygon2 = new BRepMesh::SequenceOfInteger;
BRepMesh::HSequenceOfBndB2d aPolyBoxes2 = new BRepMesh::SequenceOfBndB2d;
NCollection_Sequence<BRepMesh::HSequenceOfInteger> aPolyStack;
NCollection_Sequence<BRepMesh::HSequenceOfBndB2d> aPolyBoxStack;
for (;;)
{
decomposeSimplePolygon(*aPolygon1, *aPolyBoxes1, *aPolygon2, *aPolyBoxes2);
if (!aPolygon2->IsEmpty())
{
aPolyStack.Append(aPolygon2);
aPolyBoxStack.Append(aPolyBoxes2);
aPolygon2 = new BRepMesh::SequenceOfInteger;
aPolyBoxes2 = new BRepMesh::SequenceOfBndB2d;
}
if (aPolygon1->IsEmpty())
{
if (!aPolyStack.IsEmpty() && aPolygon1 == &(*aPolyStack.First()))
{
aPolyStack.Remove(1);
aPolyBoxStack.Remove(1);
}
if (aPolyStack.IsEmpty())
return;
aPolygon1 = &(*aPolyStack.ChangeFirst());
aPolyBoxes1 = &(*aPolyBoxStack.ChangeFirst());
}
}
} }
//======================================================================= //=======================================================================
@ -1746,18 +1780,21 @@ inline Standard_Boolean BRepMesh_Delaun::meshElementaryPolygon(
//======================================================================= //=======================================================================
//function : meshSimplePolygon //function : meshSimplePolygon
//purpose : Triangulatiion of a closed simple polygon (polygon without //purpose :
// glued edges and loops) described by the list of indexes of
// its edges in the structure.
// (negative index means reversed edge)
//======================================================================= //=======================================================================
void BRepMesh_Delaun::meshSimplePolygon(BRepMesh::SequenceOfInteger& thePolygon, void BRepMesh_Delaun::decomposeSimplePolygon(
BRepMesh::SequenceOfBndB2d& thePolyBoxes ) BRepMesh::SequenceOfInteger& thePolygon,
BRepMesh::SequenceOfBndB2d& thePolyBoxes,
BRepMesh::SequenceOfInteger& thePolygonCut,
BRepMesh::SequenceOfBndB2d& thePolyBoxesCut)
{ {
// Check is the given polygon elementary // Check is the given polygon elementary
if ( meshElementaryPolygon( thePolygon ) ) if ( meshElementaryPolygon( thePolygon ) )
{
thePolygon.Clear();
thePolyBoxes.Clear();
return; return;
}
// Polygon contains more than 3 links // Polygon contains more than 3 links
Standard_Integer aFirstEdgeInfo = thePolygon(1); Standard_Integer aFirstEdgeInfo = thePolygon(1);
@ -1774,7 +1811,11 @@ void BRepMesh_Delaun::meshSimplePolygon(BRepMesh::SequenceOfInteger& thePolygon,
Standard_Real aRefEdgeLen = aRefEdgeDir.Magnitude(); Standard_Real aRefEdgeLen = aRefEdgeDir.Magnitude();
if ( aRefEdgeLen < Precision ) if ( aRefEdgeLen < Precision )
{
thePolygon.Clear();
thePolyBoxes.Clear();
return; return;
}
aRefEdgeDir /= aRefEdgeLen; aRefEdgeDir /= aRefEdgeLen;
@ -1865,7 +1906,11 @@ void BRepMesh_Delaun::meshSimplePolygon(BRepMesh::SequenceOfInteger& thePolygon,
} }
if ( aUsedLinkId == 0 ) if ( aUsedLinkId == 0 )
{
thePolygon.Clear();
thePolyBoxes.Clear();
return; return;
}
BRepMesh_Edge aNewEdges[2] = { BRepMesh_Edge aNewEdges[2] = {
@ -1893,19 +1938,14 @@ void BRepMesh_Delaun::meshSimplePolygon(BRepMesh::SequenceOfInteger& thePolygon,
// polygon. // polygon.
if ( aUsedLinkId < aPolyLen ) if ( aUsedLinkId < aPolyLen )
{ {
BRepMesh::SequenceOfInteger aRightPolygon; thePolygon.Split(aUsedLinkId, thePolygonCut);
thePolygon.Split( aUsedLinkId, aRightPolygon ); thePolygonCut.Prepend( -aNewEdgesInfo[2] );
aRightPolygon.Prepend( -aNewEdgesInfo[2] ); thePolyBoxes.Split(aUsedLinkId, thePolyBoxesCut);
BRepMesh::SequenceOfBndB2d aRightPolyBoxes;
thePolyBoxes.Split( aUsedLinkId, aRightPolyBoxes );
Bnd_B2d aBox; Bnd_B2d aBox;
aBox.Add( aRefVertices[0] ); aBox.Add( aRefVertices[0] );
aBox.Add( aRefVertices[2] ); aBox.Add( aRefVertices[2] );
aRightPolyBoxes.Prepend( aBox ); thePolyBoxesCut.Prepend( aBox );
meshSimplePolygon( aRightPolygon, aRightPolyBoxes );
} }
else else
{ {
@ -1922,8 +1962,6 @@ void BRepMesh_Delaun::meshSimplePolygon(BRepMesh::SequenceOfInteger& thePolygon,
aBox.Add( aRefVertices[2] ); aBox.Add( aRefVertices[2] );
thePolyBoxes.SetValue( 1, aBox ); thePolyBoxes.SetValue( 1, aBox );
meshSimplePolygon( thePolygon, thePolyBoxes );
} }
} }

View File

@ -196,11 +196,20 @@ private:
BRepMesh::SequenceOfBndB2d& thePolyBoxes, BRepMesh::SequenceOfBndB2d& thePolyBoxes,
BRepMesh::HMapOfInteger theSkipped = NULL); BRepMesh::HMapOfInteger theSkipped = NULL);
//! Triangulatiion of a closed simple polygon (polygon without glued edges and loops) //! Decomposes the given closed simple polygon (polygon without glued edges
//! described by the list of indexes of its edges in the structure. //! and loops) on two simpler ones by adding new link at the most thin part
//! (negative index means reversed edge) //! in respect to end point of the first link.
void meshSimplePolygon (BRepMesh::SequenceOfInteger& thePolygon, //! In case if source polygon consists of three links, creates new triangle
BRepMesh::SequenceOfBndB2d& thePolyBoxes); //! and clears source container.
//! @param thePolygon source polygon to be decomposed (first part of decomposition).
//! @param thePolyBoxes bounding boxes corresponded to source polygon's links.
//! @param thePolygonCut product of decomposition of source polygon (second part of decomposition).
//! @param thePolyBoxesCut bounding boxes corresponded to resulting polygon's links.
void decomposeSimplePolygon (
BRepMesh::SequenceOfInteger& thePolygon,
BRepMesh::SequenceOfBndB2d& thePolyBoxes,
BRepMesh::SequenceOfInteger& thePolygonCut,
BRepMesh::SequenceOfBndB2d& thePolyBoxesCut);
//! Triangulation of closed polygon containing only three edges. //! Triangulation of closed polygon containing only three edges.
inline Standard_Boolean meshElementaryPolygon (const BRepMesh::SequenceOfInteger& thePolygon); inline Standard_Boolean meshElementaryPolygon (const BRepMesh::SequenceOfInteger& thePolygon);

14
tests/bugs/mesh/bug25806 Normal file
View File

@ -0,0 +1,14 @@
puts "========"
puts "OCC25806"
puts "========"
puts ""
#################################
# Stack overflow during meshing
#################################
restore [locate_data_file OCC25806_shape_1040739_1.brep] a
set bug_info [incmesh a 0.001]
if {[lindex $bug_info 6] != "NoError"} {
puts "ERROR: OCC25806 is reproduced. Errors during meshing."
}