#include <Geom2d_Curve.hxx>
#include <Geom_Curve.hxx>
#include <Geom_Surface.hxx>
+#include <ShapeAnalysis.hxx>
+#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_MapOfShape.hxx>
+#include <TopoDS.hxx>
#include <gp_Pnt2d.hxx>
-#include <ShapeAnalysis.hxx>
+
+#include <Standard_Failure.hxx>
+#include <Standard_ErrorHandler.hxx>
#include <utilities.h>
//================================================================================
SMESH_MesherHelper::SMESH_MesherHelper(SMESH_Mesh& theMesh)
- : myMesh(&theMesh), myShapeID(-1), myCreateQuadratic(false), mySetElemOnShape(false)
-{}
+ : myMesh(&theMesh), myShapeID(-1), myCreateQuadratic(false)
+{
+ mySetElemOnShape = ( ! myMesh->HasShapeToMesh() );
+}
//=======================================================================
//function : CheckShape
// also we have to fill myNLinkNodeMap
myCreateQuadratic = true;
mySeamShapeIds.clear();
+ myDegenShapeIds.clear();
TopAbs_ShapeEnum subType( aSh.ShapeType()==TopAbs_FACE ? TopAbs_EDGE : TopAbs_FACE );
SMDSAbs_ElementType elemType( subType==TopAbs_FACE ? SMDSAbs_Face : SMDSAbs_Edge );
myShape = aSh;
mySeamShapeIds.clear();
+ myDegenShapeIds.clear();
if ( myShape.IsNull() ) {
myShapeID = -1;
BRepAdaptor_Surface surface( face );
if ( surface.IsUPeriodic() || surface.IsVPeriodic() )
{
- // look for a seam edge
- 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
const TopoDS_Edge& edge = TopoDS::Edge( exp.Current() );
if ( BRep_Tool::IsClosed( edge, face )) {
// initialize myPar1, myPar2 and myParIndex
}
}
// store shapes indices
- mySeamShapeIds.insert( meshDS->ShapeToIndex( exp.Current() ));
- for ( TopExp_Explorer v( exp.Current(), TopAbs_VERTEX ); v.More(); v.Next() )
+ mySeamShapeIds.insert( meshDS->ShapeToIndex( edge ));
+ for ( TopExp_Explorer v( edge, TopAbs_VERTEX ); v.More(); v.Next() )
mySeamShapeIds.insert( meshDS->ShapeToIndex( v.Current() ));
}
+
+ // look for a degenerated edge
+ if ( BRep_Tool::Degenerated( edge )) {
+ myDegenShapeIds.insert( meshDS->ShapeToIndex( edge ));
+ for ( TopExp_Explorer v( edge, TopAbs_VERTEX ); v.More(); v.Next() )
+ myDegenShapeIds.insert( meshDS->ShapeToIndex( v.Current() ));
+ }
}
}
}
}
else if(Pos->GetTypeOfPosition()==SMDS_TOP_VERTEX)
{
- int vertexID = n->GetPosition()->GetShapeId();
- const TopoDS_Vertex& V = TopoDS::Vertex(GetMeshDS()->IndexToShape(vertexID));
- uv = BRep_Tool::Parameters( V, F );
- if ( n2 && mySeamShapeIds.find( vertexID ) != mySeamShapeIds.end() )
- uv = GetUVOnSeam( uv, GetNodeUV( F, n2, 0 ));
+ if ( int vertexID = n->GetPosition()->GetShapeId() ) {
+ bool ok = true;
+ const TopoDS_Vertex& V = TopoDS::Vertex(GetMeshDS()->IndexToShape(vertexID));
+ try {
+ uv = BRep_Tool::Parameters( V, F );
+ }
+ catch (Standard_Failure& exc) {
+ ok = false;
+ }
+ if ( !ok ) {
+ for ( TopExp_Explorer vert(F,TopAbs_VERTEX); !ok && vert.More(); vert.Next() )
+ ok = ( V == vert.Current() );
+ if ( !ok ) {
+#ifdef _DEBUG_
+ cout << "SMESH_MesherHelper::GetNodeUV(); Vertex " << vertexID
+ << " not in face " << GetMeshDS()->ShapeToIndex( F ) << endl;
+#endif
+ // get UV of a vertex closest to the node
+ double dist = 1e100;
+ gp_Pnt pn ( n->X(),n->Y(),n->Z() );
+ for ( TopExp_Explorer vert(F,TopAbs_VERTEX); !ok && vert.More(); vert.Next() ) {
+ TopoDS_Vertex curV = TopoDS::Vertex( vert.Current() );
+ gp_Pnt p = BRep_Tool::Pnt( curV );
+ double curDist = p.SquareDistance( pn );
+ if ( curDist < dist ) {
+ dist = curDist;
+ uv = BRep_Tool::Parameters( curV, F );
+ if ( dist < DBL_MIN ) break;
+ }
+ }
+ }
+ else {
+ TopTools_ListIteratorOfListOfShape it( myMesh->GetAncestors( V ));
+ for ( ; it.More(); it.Next() ) {
+ if ( it.Value().ShapeType() == TopAbs_EDGE ) {
+ const TopoDS_Edge & edge = TopoDS::Edge( it.Value() );
+ double f,l;
+ Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(edge, F, f, l);
+ if ( !C2d.IsNull() ) {
+ double u = ( V == TopExp::FirstVertex( edge ) ) ? f : l;
+ uv = C2d->Value( u );
+ break;
+ }
+ }
+ }
+ }
+ }
+ if ( n2 && mySeamShapeIds.find( vertexID ) != mySeamShapeIds.end() )
+ uv = GetUVOnSeam( uv, GetNodeUV( F, n2, 0 ));
+ }
}
return uv.XY();
}
const SMDS_MeshNode* node;
while ( nIt->more() ) {
node = nIt->next();
- if(IsMedium(node))
+ if(IsMedium(node, SMDSAbs_Edge))
continue;
const SMDS_EdgePosition* pos =
dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
allFaces.insert( e );
}
// Starting from 2 neighbour nodes on theBaseEdge, look for a face
- // the nodes belong to, and between the nodes of the found face,
+ // the nodes belong to, and among the nodes of the found face,
// look for a not loaded node considering this node to be the next
// in a column of the starting second node. Repeat, starting
// from nodes next to the previous starting nodes in their columns,