Bug 0019943: Pb with projection 2d. Fix for a seam edge on not really closed face.

This commit is contained in:
jfa 2008-07-25 10:32:18 +00:00
parent 08ba46c116
commit 4b33363430
2 changed files with 101 additions and 32 deletions

View File

@ -32,6 +32,7 @@
#include <BRepAdaptor_Surface.hxx> #include <BRepAdaptor_Surface.hxx>
#include <BRepTools.hxx> #include <BRepTools.hxx>
#include <BRep_Tool.hxx> #include <BRep_Tool.hxx>
#include <BRepTools_WireExplorer.hxx>
#include <Geom2d_Curve.hxx> #include <Geom2d_Curve.hxx>
#include <Geom_Curve.hxx> #include <Geom_Curve.hxx>
#include <Geom_Surface.hxx> #include <Geom_Surface.hxx>
@ -169,11 +170,29 @@ void SMESH_MesherHelper::SetSubShape(const TopoDS_Shape& aSh)
BRepAdaptor_Surface surface( face ); BRepAdaptor_Surface surface( face );
if ( surface.IsUPeriodic() || surface.IsVPeriodic() ) if ( surface.IsUPeriodic() || surface.IsVPeriodic() )
{ {
for ( TopExp_Explorer exp( face, TopAbs_EDGE ); exp.More(); exp.Next()) for (TopExp_Explorer exp( face, TopAbs_EDGE ); exp.More(); exp.Next())
{ {
// look for a seam edge // look for a seam edge
const TopoDS_Edge& edge = TopoDS::Edge( exp.Current() ); const TopoDS_Edge& edge = TopoDS::Edge( exp.Current() );
if ( BRep_Tool::IsClosed( edge, face )) { bool isClosed = BRep_Tool::IsClosed( edge, face );
// BEGIN: jfa for bug 0019943
if (isClosed) {
MESSAGE("$$$ CLOSED 1 $$$")
isClosed = false;
for (TopExp_Explorer expw (face, TopAbs_WIRE); expw.More() && !isClosed; expw.Next()) {
const TopoDS_Wire& wire = TopoDS::Wire(expw.Current());
int nbe = 0;
for (BRepTools_WireExplorer we (wire, face); we.More() && !isClosed; we.Next()) {
if (we.Current().IsSame(edge)) {
nbe++;
if (nbe == 2) isClosed = true;
}
}
}
}
// END: jfa for bug 0019943
if (isClosed) {
MESSAGE("$$$ CLOSED 2 $$$")
// initialize myPar1, myPar2 and myParIndex // initialize myPar1, myPar2 and myParIndex
if ( mySeamShapeIds.empty() ) { if ( mySeamShapeIds.empty() ) {
gp_Pnt2d uv1, uv2; gp_Pnt2d uv1, uv2;

View File

@ -251,7 +251,7 @@ bool SMESH_Pattern::Load (const char* theFileContents)
MESSAGE(" Too few points "); MESSAGE(" Too few points ");
return setErrorCode( ERR_READ_TOO_FEW_POINTS ); return setErrorCode( ERR_READ_TOO_FEW_POINTS );
} }
// read the rest points // read the rest points
int iPoint; int iPoint;
for ( iPoint = 1; iPoint < nbPoints; iPoint++ ) for ( iPoint = 1; iPoint < nbPoints; iPoint++ )
@ -398,7 +398,7 @@ bool SMESH_Pattern::Save (ostream& theFile)
} }
theFile << endl; theFile << endl;
return setErrorCode( ERR_OK ); return setErrorCode( ERR_OK );
} }
@ -634,7 +634,23 @@ bool SMESH_Pattern::Load (SMESH_Mesh* theMesh,
// vertices // vertices
for ( elIt = eList.begin(); elIt != eList.end(); elIt++ ) { for ( elIt = eList.begin(); elIt != eList.end(); elIt++ ) {
myShapeIDMap.Add( TopExp::FirstVertex( *elIt, true )); myShapeIDMap.Add( TopExp::FirstVertex( *elIt, true ));
if ( BRep_Tool::IsClosed( *elIt, theFace ) ) bool isClosed1 = BRep_Tool::IsClosed( *elIt, theFace );
// BEGIN: jfa for bug 0019943
if (isClosed1) {
isClosed1 = false;
for (TopExp_Explorer expw (theFace, TopAbs_WIRE); expw.More() && !isClosed1; expw.Next()) {
const TopoDS_Wire& wire = TopoDS::Wire(expw.Current());
int nbe = 0;
for (BRepTools_WireExplorer we (wire, theFace); we.More() && !isClosed1; we.Next()) {
if (we.Current().IsSame(*elIt)) {
nbe++;
if (nbe == 2) isClosed1 = true;
}
}
}
}
// END: jfa for bug 0019943
if (isClosed1)
myShapeIDMap.Add( TopExp::LastVertex( *elIt, true )); myShapeIDMap.Add( TopExp::LastVertex( *elIt, true ));
SMESHDS_SubMesh * eSubMesh = aMeshDS->MeshElements( *elIt ); SMESHDS_SubMesh * eSubMesh = aMeshDS->MeshElements( *elIt );
if ( eSubMesh ) if ( eSubMesh )
@ -999,7 +1015,7 @@ static bool intersectIsolines(const gp_XY& uv11, const gp_XY& uv12, const double
// resUV = loc1 * len2 / ( len1 + len2 ) + loc2 * len1 / ( len1 + len2 ); // resUV = loc1 * len2 / ( len1 + len2 ) + loc2 * len1 / ( len1 + len2 );
// return true; // return true;
// gp_Lin2d line1( uv11, uv12 - uv11 ); // gp_Lin2d line1( uv11, uv12 - uv11 );
// gp_Lin2d line2( uv21, uv22 - uv21 ); // gp_Lin2d line2( uv21, uv22 - uv21 );
// double angle = Abs( line1.Angle( line2 ) ); // double angle = Abs( line1.Angle( line2 ) );
@ -1013,7 +1029,7 @@ static bool intersectIsolines(const gp_XY& uv11, const gp_XY& uv12, const double
// inter.Perform( line1, line2 ); // inter.Perform( line1, line2 );
// interUV = inter.Point(1).Value(); // interUV = inter.Point(1).Value();
// resUV += interUV.XY(); // resUV += interUV.XY();
// resUV /= 2.; // resUV /= 2.;
// } // }
if ( isDeformed ) { if ( isDeformed ) {
@ -1053,7 +1069,7 @@ bool SMESH_Pattern::compUVByIsoIntersection (const list< list< TPoint* > >& theB
const list< TPoint* > & bndPoints = * bndIt; const list< TPoint* > & bndPoints = * bndIt;
TPoint* prevP = bndPoints.back(); // this is the first point TPoint* prevP = bndPoints.back(); // this is the first point
list< TPoint* >::const_iterator pIt = bndPoints.begin(); list< TPoint* >::const_iterator pIt = bndPoints.begin();
bool coincPrev = false; bool coincPrev = false;
// loop on the edge-points // loop on the edge-points
for ( ; pIt != bndPoints.end(); pIt++ ) for ( ; pIt != bndPoints.end(); pIt++ )
{ {
@ -1318,7 +1334,7 @@ static bool checkQuads (const TIsoNode* node,
gp_XY uv1, uv2 = node->myUV; gp_XY uv1, uv2 = node->myUV;
for ( i = isTriangle ? 2 : 0; i < 3; i++ ) // mark not computed vectors for ( i = isTriangle ? 2 : 0; i < 3; i++ ) // mark not computed vectors
if ( wasOk[i] ) if ( wasOk[i] )
moveVec[ i ].SetCoord( 1, 2e100); // not use this vector moveVec[ i ].SetCoord( 1, 2e100); // not use this vector
while ( !isOldOk ) { while ( !isOldOk ) {
// find the least moveVec // find the least moveVec
int i, iMin = 4; int i, iMin = 4;
@ -1749,7 +1765,7 @@ bool SMESH_Pattern::
aNorm[1-iDir].Normalize(); aNorm[1-iDir].Normalize();
double r = Abs ( ratio[iDir] - 0.5 ) * 2.0; // [0,1] - distance from the middle double r = Abs ( ratio[iDir] - 0.5 ) * 2.0; // [0,1] - distance from the middle
r *= r; r *= r;
node->myDir[iDir] = //aTgt[iDir]; node->myDir[iDir] = //aTgt[iDir];
aNorm[1-iDir] * r + aTgt[iDir] * ( 1. - r ); aNorm[1-iDir] * r + aTgt[iDir] * ( 1. - r );
} }
@ -1950,7 +1966,7 @@ bool SMESH_Pattern::
} }
internNodes.push_back( node ); internNodes.push_back( node );
} }
// Move nodes // Move nodes
static int maxNbIter = 100; static int maxNbIter = 100;
@ -1962,7 +1978,7 @@ bool SMESH_Pattern::
int nbNodeMove = 0; int nbNodeMove = 0;
if ( !useNbMoveNode ) if ( !useNbMoveNode )
maxNbIter = ( maxNbIter < 0 ) ? 100 : -1; maxNbIter = ( maxNbIter < 0 ) ? 100 : -1;
#endif #endif
double maxMove; double maxMove;
int nbIter = 0; int nbIter = 0;
do { do {
@ -2059,8 +2075,7 @@ bool SMESH_Pattern::
} }
} }
} }
return true; return true;
} }
@ -2086,7 +2101,7 @@ double SMESH_Pattern::setFirstEdge (list< TopoDS_Edge > & theWire, int theFirstE
int eID = theFirstEdgeID; int eID = theFirstEdgeID;
for ( iE = 0; iE < nbEdges; iE++ ) for ( iE = 0; iE < nbEdges; iE++ )
maxNbPnt = Max ( maxNbPnt, getShapePoints( eID++ ).size() ); maxNbPnt = Max ( maxNbPnt, getShapePoints( eID++ ).size() );
// compute bnd boxes // compute bnd boxes
TopoDS_Face face = TopoDS::Face( myShape ); TopoDS_Face face = TopoDS::Face( myShape );
Bnd_Box2d bndBox, eBndBox; Bnd_Box2d bndBox, eBndBox;
@ -2281,7 +2296,7 @@ bool SMESH_Pattern::sortSameSizeWires (TListOfEdgesList & theWire
bndIndWirePosMap.insert( TIntWirePosMap::value_type( bIndex, wlIt )); bndIndWirePosMap.insert( TIntWirePosMap::value_type( bIndex, wlIt ));
} }
// Treat each wire // Treat each wire
TIntWirePosMap::iterator bIndWPosIt = bndIndWirePosMap.begin(); TIntWirePosMap::iterator bIndWPosIt = bndIndWirePosMap.begin();
eID = theFirstEdgeID; eID = theFirstEdgeID;
@ -2292,7 +2307,7 @@ bool SMESH_Pattern::sortSameSizeWires (TListOfEdgesList & theWire
// choose the best first edge of a wire // choose the best first edge of a wire
setFirstEdge( wire, eID ); setFirstEdge( wire, eID );
// compute eventual UV and fill theEdgesPointsList // compute eventual UV and fill theEdgesPointsList
theEdgesPointsList.push_back( list< TPoint* >() ); theEdgesPointsList.push_back( list< TPoint* >() );
list< TPoint* > & edgesPoints = theEdgesPointsList.back(); list< TPoint* > & edgesPoints = theEdgesPointsList.back();
@ -2354,7 +2369,23 @@ bool SMESH_Pattern::Apply (const TopoDS_Face& theFace,
list<TopoDS_Edge>::iterator elIt = eList.begin(); list<TopoDS_Edge>::iterator elIt = eList.begin();
for ( ; elIt != eList.end(); elIt++ ) { for ( ; elIt != eList.end(); elIt++ ) {
myShapeIDMap.Add( TopExp::FirstVertex( *elIt, true )); myShapeIDMap.Add( TopExp::FirstVertex( *elIt, true ));
if ( BRep_Tool::IsClosed( *elIt, theFace ) ) bool isClosed1 = BRep_Tool::IsClosed( *elIt, theFace );
// BEGIN: jfa for bug 0019943
if (isClosed1) {
isClosed1 = false;
for (TopExp_Explorer expw (theFace, TopAbs_WIRE); expw.More() && !isClosed1; expw.Next()) {
const TopoDS_Wire& wire = TopoDS::Wire(expw.Current());
int nbe = 0;
for (BRepTools_WireExplorer we (wire, theFace); we.More() && !isClosed1; we.Next()) {
if (we.Current().IsSame(*elIt)) {
nbe++;
if (nbe == 2) isClosed1 = true;
}
}
}
}
// END: jfa for bug 0019943
if (isClosed1)
myShapeIDMap.Add( TopExp::LastVertex( *elIt, true )); myShapeIDMap.Add( TopExp::LastVertex( *elIt, true ));
} }
int nbVertices = myShapeIDMap.Extent(); int nbVertices = myShapeIDMap.Extent();
@ -2461,7 +2492,7 @@ bool SMESH_Pattern::Apply (const TopoDS_Face& theFace,
} }
// find boundary - wire correspondence for several wires of same size // find boundary - wire correspondence for several wires of same size
id1 = nbVertices + nbEdgesInOuterWire + 1; id1 = nbVertices + nbEdgesInOuterWire + 1;
wlIt = wireList.begin(); wlIt = wireList.begin();
while ( wlIt != wireList.end() ) while ( wlIt != wireList.end() )
@ -2481,7 +2512,7 @@ bool SMESH_Pattern::Apply (const TopoDS_Face& theFace,
} }
// add well-ordered edges to eList // add well-ordered edges to eList
for ( wlIt = wireList.begin(); wlIt != wireList.end(); wlIt++ ) for ( wlIt = wireList.begin(); wlIt != wireList.end(); wlIt++ )
{ {
list< TopoDS_Edge >& wire = (*wlIt); list< TopoDS_Edge >& wire = (*wlIt);
@ -2496,7 +2527,7 @@ bool SMESH_Pattern::Apply (const TopoDS_Face& theFace,
for ( elIt = eList.begin(); elIt != eList.end(); elIt++ ) for ( elIt = eList.begin(); elIt != eList.end(); elIt++ )
myShapeIDMap.Add( *elIt ); myShapeIDMap.Add( *elIt );
myShapeIDMap.Add( face ); myShapeIDMap.Add( face );
} // there are inner wires } // there are inner wires
// Compute XYZ of on-edge points // Compute XYZ of on-edge points
@ -2646,7 +2677,7 @@ bool SMESH_Pattern::Apply (const SMDS_MeshFace* theFace,
{ {
gp_XYZ& xyz1 = *xyzIt++; gp_XYZ& xyz1 = *xyzIt++;
gp_XYZ& xyz2 = ( xyzIt != xyzList.end() ) ? *xyzIt : xyzList.front(); gp_XYZ& xyz2 = ( xyzIt != xyzList.end() ) ? *xyzIt : xyzList.front();
list< TPoint* > & ePoints = getShapePoints( iSub ); list< TPoint* > & ePoints = getShapePoints( iSub );
ePoints.back()->myInitU = 1.0; ePoints.back()->myInitU = 1.0;
list< TPoint* >::const_iterator pIt = ++ePoints.begin(); list< TPoint* >::const_iterator pIt = ++ePoints.begin();
@ -2920,7 +2951,7 @@ bool SMESH_Pattern::Apply (SMESH_Mesh* theMesh,
// meshed geometry // meshed geometry
TopoDS_Shape shape; TopoDS_Shape shape;
// int shapeID = 0; // int shapeID = 0;
// SMESH_MeshEditor editor( theMesh ); // SMESH_MeshEditor editor( theMesh );
// apply to each face in theFaces set // apply to each face in theFaces set
set<const SMDS_MeshFace*>::iterator face = theFaces.begin(); set<const SMDS_MeshFace*>::iterator face = theFaces.begin();
@ -3701,7 +3732,7 @@ bool SMESH_Pattern::
bndId = nn_IdList->second.front().front(); bndId = nn_IdList->second.front().front();
ids.insert( bndId ); ids.insert( bndId );
} }
else else
myXYZIdToNodeMap.insert( make_pair( bndId, theBndNodes[ iN ] )); myXYZIdToNodeMap.insert( make_pair( bndId, theBndNodes[ iN ] ));
faceDef.push_back( bndId ); faceDef.push_back( bndId );
// add ids on a link // add ids on a link
@ -3969,7 +4000,7 @@ void SMESH_Pattern::createElements(SMESH_Mesh* theMes
const vector<const SMDS_MeshElement*>& theElements) const vector<const SMDS_MeshElement*>& theElements)
{ {
SMESHDS_Mesh* aMeshDS = theMesh->GetMeshDS(); SMESHDS_Mesh* aMeshDS = theMesh->GetMeshDS();
SMESH_MeshEditor editor( theMesh ); SMESH_MeshEditor editor( theMesh );
bool onMeshElements = !theElements.empty(); bool onMeshElements = !theElements.empty();
@ -4185,7 +4216,7 @@ void SMESH_Pattern::arrangeBoundaries (list< list< TPoint* > >& boundaryList)
if ( nbBoundaries > 2 ) if ( nbBoundaries > 2 )
{ {
// move boundaries in tmp list // move boundaries in tmp list
list< list< TPoint* > > tmpList; list< list< TPoint* > > tmpList;
tmpList.splice( tmpList.begin(), boundaryList, boundaryList.begin(), boundaryList.end()); tmpList.splice( tmpList.begin(), boundaryList, boundaryList.begin(), boundaryList.end());
// make a map nb-key-points to boundary-position-in-tmpList, // make a map nb-key-points to boundary-position-in-tmpList,
// boundary-positions get ordered in it // boundary-positions get ordered in it
@ -4228,7 +4259,7 @@ void SMESH_Pattern::arrangeBoundaries (list< list< TPoint* > >& boundaryList)
boundaryList.splice( boundaryList.begin(), boundaryList, outerBndPos, ++outerBndPos ); boundaryList.splice( boundaryList.begin(), boundaryList, outerBndPos, ++outerBndPos );
} // if nbBoundaries > 1 } // if nbBoundaries > 1
// Check boundaries orientation and re-fill myKeyPointIDs // Check boundaries orientation and re-fill myKeyPointIDs
set< TPoint* > keyPointSet; set< TPoint* > keyPointSet;
@ -4499,7 +4530,7 @@ bool SMESH_Pattern::findBoundaryPoints()
getShapePoints( shapeID ).push_back( point ); getShapePoints( shapeID ).push_back( point );
// detect key-points // detect key-points
if ( SMESH_Block::IsVertexID( shapeID )) if ( SMESH_Block::IsVertexID( shapeID ))
myKeyPointIDs.push_back( i ); myKeyPointIDs.push_back( i );
} }
} }
@ -4549,11 +4580,30 @@ bool SMESH_Pattern::setShapeToMesh(const TopoDS_Shape& theShape)
if ( myIs2D ) { if ( myIs2D ) {
TopoDS_Face face = TopoDS::Face( theShape ); TopoDS_Face face = TopoDS::Face( theShape );
TopExp_Explorer eExp( theShape, TopAbs_EDGE ); TopExp_Explorer eExp( theShape, TopAbs_EDGE );
for ( ; eExp.More() && nbNodeOnSeamEdge == 0; eExp.Next() ) for ( ; eExp.More() && nbNodeOnSeamEdge == 0; eExp.Next() ) {
if ( BRep_Tool::IsClosed( TopoDS::Edge( eExp.Current() ), face )) const TopoDS_Edge& ee = TopoDS::Edge(eExp.Current());
bool isClosed1 = BRep_Tool::IsClosed(ee, face);
// BEGIN: jfa for bug 0019943
if (isClosed1) {
isClosed1 = false;
for (TopExp_Explorer expw (face, TopAbs_WIRE); expw.More() && !isClosed1; expw.Next()) {
const TopoDS_Wire& wire = TopoDS::Wire(expw.Current());
int nbe = 0;
for (BRepTools_WireExplorer we (wire, face); we.More() && !isClosed1; we.Next()) {
if (we.Current().IsSame(ee)) {
nbe++;
if (nbe == 2) isClosed1 = true;
}
}
}
}
// END: jfa for bug 0019943
if (isClosed1) {
nbNodeOnSeamEdge = 2; nbNodeOnSeamEdge = 2;
}
}
} }
// check nb of vertices // check nb of vertices
TopTools_IndexedMapOfShape vMap; TopTools_IndexedMapOfShape vMap;
TopExp::MapShapes( theShape, TopAbs_VERTEX, vMap ); TopExp::MapShapes( theShape, TopAbs_VERTEX, vMap );
@ -4695,6 +4745,6 @@ ostream & operator <<(ostream & OS, const SMESH_Pattern::TPoint& p)
OS << " uv( " << xy.X() << " " << xy.Y() << " )"; OS << " uv( " << xy.X() << " " << xy.Y() << " )";
u = p.myU; u = p.myU;
OS << " u( " << u << " ))" << endl; OS << " u( " << u << " ))" << endl;
return OS; return OS;
} }