X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FStdMeshers%2FStdMeshers_Import_1D2D.cxx;h=8cc97b6e017243dd4296e504c46d93fdd823b610;hp=17b5b5a9d0ae0f6194e3b016ee9d2fe1ecbd6850;hb=30ce546b0c5099ad1112929e2db94810e683e54b;hpb=066f625a46b60642f228a0c10fc6c2dcdc20d304 diff --git a/src/StdMeshers/StdMeshers_Import_1D2D.cxx b/src/StdMeshers/StdMeshers_Import_1D2D.cxx index 17b5b5a9d..8cc97b6e0 100644 --- a/src/StdMeshers/StdMeshers_Import_1D2D.cxx +++ b/src/StdMeshers/StdMeshers_Import_1D2D.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -34,6 +34,7 @@ #include "SMESHDS_Group.hxx" #include "SMESHDS_Mesh.hxx" #include "SMESH_Comment.hxx" +#include "SMESH_ControlsDef.hxx" #include "SMESH_Gen.hxx" #include "SMESH_Group.hxx" #include "SMESH_Mesh.hxx" @@ -44,11 +45,13 @@ #include "Utils_SALOME_Exception.hxx" #include "utilities.h" +#include #include #include #include #include #include +#include #include #include #include @@ -96,7 +99,6 @@ namespace StdMeshers_Import_1D2D::StdMeshers_Import_1D2D(int hypId, int studyId, SMESH_Gen * gen) :SMESH_2D_Algo(hypId, studyId, gen), _sourceHyp(0) { - MESSAGE("StdMeshers_Import_1D2D::StdMeshers_Import_1D2D"); _name = "Import_1D2D"; _shapeType = (1 << TopAbs_FACE); @@ -186,17 +188,20 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & SMESHDS_Mesh* tgtMesh = theMesh.GetMeshDS(); const TopoDS_Face& geomFace = TopoDS::Face( theShape ); - const double faceTol = helper.MaxTolerance( geomFace ); - const int shapeID = tgtMesh->ShapeToIndex( geomFace ); + const double faceTol = helper.MaxTolerance( geomFace ); + const int shapeID = tgtMesh->ShapeToIndex( geomFace ); const bool toCheckOri = (helper.NbAncestors( geomFace, theMesh, TopAbs_SOLID ) == 1 ); + Handle(Geom_Surface) surface = BRep_Tool::Surface( geomFace ); - const bool reverse = + const bool reverse = ( helper.GetSubShapeOri( tgtMesh->ShapeToMesh(), geomFace ) == TopAbs_REVERSED ); gp_Pnt p; gp_Vec du, dv; + // BRepClass_FaceClassifier is most time consuming, so minimize its usage BRepClass_FaceClassifier classifier; Bnd_B2d bndBox2d; + Bnd_Box bndBox3d; { Standard_Real umin,umax,vmin,vmax; BRepTools::UVBounds(geomFace,umin,umax,vmin,vmax); @@ -212,6 +217,9 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & bndBox2d.Add( pmax ); } bndBox2d.Enlarge( 1e-2 * Sqrt( bndBox2d.SquareExtent() )); + + BRepBndLib::Add( geomFace, bndBox3d ); + bndBox3d.Enlarge( 1e-2 * sqrt( bndBox3d.SquareExtent() )); } set subShapeIDs; @@ -262,15 +270,29 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & map::iterator link2Nb; double minGroupTol = Precision::Infinite(); + SMESH::Controls::ElementsOnShape onEdgeClassifier; + if ( helper.HasSeam() ) + { + TopoDS_Compound edgesCompound; + BRep_Builder builder; + builder.MakeCompound( edgesCompound ); + for ( size_t iE = 0; iE < edges.size(); ++iE ) + builder.Add( edgesCompound, edges[ iE ]); + onEdgeClassifier.SetShape( edgesCompound, SMDSAbs_Node ); + } + // ========================= // Import faces from groups // ========================= StdMeshers_Import_1D::TNodeNodeMap* n2n; StdMeshers_Import_1D::TElemElemMap* e2e; + StdMeshers_Import_1D::TNodeNodeMap::iterator n2nIt; + pair< StdMeshers_Import_1D::TNodeNodeMap::iterator, bool > it_isnew; vector nodeState; vector newNodes; // of a face set bndNodes; // nodes classified ON + vector isNodeIn; // nodes classified IN, by node ID for ( size_t iG = 0; iG < srcGroups.size(); ++iG ) { @@ -284,29 +306,34 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & const double groupTol = 0.5 * sqrt( getMinElemSize2( srcGroup )); minGroupTol = std::min( groupTol, minGroupTol ); - GeomAdaptor_Surface S( surface ); - const double clsfTol = Min( S.UResolution( 0.1 * groupTol ), - S.VResolution( 0.1 * groupTol )); + //GeomAdaptor_Surface S( surface ); + // const double clsfTol = Min( S.UResolution( 0.1 * groupTol ), -- issue 0023092 + // S.VResolution( 0.1 * groupTol )); + const double clsfTol = BRep_Tool::Tolerance( geomFace ); - StdMeshers_Import_1D::TNodeNodeMap::iterator n2nIt; - pair< StdMeshers_Import_1D::TNodeNodeMap::iterator, bool > it_isnew; + if ( helper.HasSeam() ) + onEdgeClassifier.SetMesh( srcMesh->GetMeshDS() ); SMDS_ElemIteratorPtr srcElems = srcGroup->GetElements(); while ( srcElems->more() ) // loop on group contents { const SMDS_MeshElement* face = srcElems->next(); + SMDS_MeshElement::iterator node = face->begin_nodes(); + if ( bndBox3d.IsOut( SMESH_TNodeXYZ( *node ))) + continue; + // find or create nodes of a new face nodeState.resize( face->NbNodes() ); newNodes.resize( nodeState.size() ); newNodes.back() = 0; int nbCreatedNodes = 0; bool isOut = false, isIn = false; // if at least one node isIn - do not classify other nodes - SMDS_MeshElement::iterator node = face->begin_nodes(); for ( size_t i = 0; i < newNodes.size(); ++i, ++node ) { SMESH_TNodeXYZ nXYZ = *node; nodeState[ i ] = TopAbs_UNKNOWN; + newNodes [ i ] = 0; it_isnew = n2n->insert( make_pair( *node, (SMDS_MeshNode*)0 )); n2nIt = it_isnew.first; @@ -319,6 +346,9 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & { if ( !subShapeIDs.count( newNode->getshapeId() )) break; // node is Imported onto other FACE + if ( newNode->GetID() < (int) isNodeIn.size() && + isNodeIn[ newNode->GetID() ]) + isIn = true; if ( !isIn && bndNodes.count( *node )) nodeState[ i ] = TopAbs_ON; } @@ -340,26 +370,42 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & gp_XY uv( Precision::Infinite(), 0 ); isOut = ( !helper.CheckNodeUV( geomFace, *node, uv, groupTol, /*force=*/true ) || bndBox2d.IsOut( uv )); + //int iCoo; if ( !isOut && !isIn ) // classify { classifier.Perform( geomFace, uv, clsfTol ); nodeState[i] = classifier.State(); isOut = ( nodeState[i] == TopAbs_OUT ); + if ( isOut && helper.IsOnSeam( uv ) && onEdgeClassifier.IsSatisfy( (*node)->GetID() )) + { + // uv.SetCoord( iCoo, helper.GetOtherParam( uv.Coord( iCoo ))); + // classifier.Perform( geomFace, uv, clsfTol ); + // nodeState[i] = classifier.State(); + // isOut = ( nodeState[i] == TopAbs_OUT ); + nodeState[i] = TopAbs_ON; + isOut = false; + } } if ( !isOut ) // create a new node { newNode = tgtMesh->AddNode( nXYZ.X(), nXYZ.Y(), nXYZ.Z()); tgtMesh->SetNodeOnFace( newNode, shapeID, uv.X(), uv.Y() ); nbCreatedNodes++; + if ( newNode->GetID() >= (int) isNodeIn.size() ) + { + isNodeIn.push_back( false ); // allow allocate more than newNode->GetID() + isNodeIn.resize( newNode->GetID() + 1, false ); + } if ( nodeState[i] == TopAbs_ON ) bndNodes.insert( *node ); - else - isIn = true; + else if ( nodeState[i] != TopAbs_UNKNOWN ) + isNodeIn[ newNode->GetID() ] = isIn = true; } } if ( !(newNodes[i] = newNode ) || isOut ) break; - } + + } // loop on face nodes if ( !newNodes.back() ) continue; // not all nodes of the face lie on theShape @@ -390,7 +436,7 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & proj.Perform( gc ); if ( !proj.IsDone() || proj.NbPoints() < 1 ) continue; - Quantity_Parameter U,V; + Standard_Real U,V; proj.LowerDistanceParameters(U,V); gp_XY uv( U,V ); classifier.Perform( geomFace, uv, clsfTol ); @@ -432,7 +478,7 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & if ( geomNorm * meshNorm < 0 ) SMDS_MeshCell::applyInterlace - ( SMDS_MeshCell::reverseSmdsOrder( face->GetEntityType() ), newNodes ); + ( SMDS_MeshCell::reverseSmdsOrder( face->GetEntityType(), newNodes.size() ), newNodes ); } // make a new face @@ -470,23 +516,32 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & medium = newNodes[i+nbCorners]; link2Nb = linkCount.insert( make_pair( TLink( n1, n2, medium ), 0)).first; ++link2Nb->second; - // if ( link2Nb->second == 1 ) - // { - // // measure link length - // double len2 = SMESH_TNodeXYZ( n1 ).SquareDistance( n2 ); - // if ( len2 < minGroupTol ) - // minGroupTol = len2; - // } } - } + } // loop on group contents + // Remove OUT nodes from n2n map for ( n2nIt = n2n->begin(); n2nIt != n2n->end(); ) if ( !n2nIt->second ) n2n->erase( n2nIt++ ); else ++n2nIt; - } + } // loop on src groups + + // remove free nodes created on EDGEs + { + set::iterator node = bndNodes.begin(); + for ( ; node != bndNodes.end(); ++node ) + { + n2nIt = n2n->find( *node ); + const SMDS_MeshNode* newNode = n2nIt->second; + if ( newNode && newNode->NbInverseElements() == 0 ) + { + tgtMesh->RemoveFreeNode( newNode, 0, false ); + n2n->erase( n2nIt ); + } + } + } // ========================================================== // Put nodes on geom edges and create edges on them; @@ -679,7 +734,7 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & seamHelper.SetSubShape( edges[ iE ]); seamHelper.SetElementsOnShape( true ); - if ( (*checkedFaces.begin())->IsQuadratic() ) + if ( !checkedFaces.empty() && (*checkedFaces.begin())->IsQuadratic() ) for ( set< const SMDS_MeshElement* >::iterator fIt = checkedFaces.begin(); fIt != checkedFaces.end(); ++fIt ) seamHelper.AddTLinks( static_cast( *fIt )); @@ -708,8 +763,7 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & // sm->SetIsAlwaysComputed( true ); sm->ComputeStateEngine(SMESH_subMesh::CHECK_COMPUTE_STATE); if ( sm->GetComputeState() != SMESH_subMesh::COMPUTE_OK ) - return error(SMESH_Comment("Failed to create segments on the edge ") - << tgtMesh->ShapeToIndex( edges[iE ])); + return error(SMESH_Comment("Failed to create segments on the edge #") << sm->GetId()); } // ============ @@ -803,7 +857,7 @@ bool StdMeshers_Import_1D2D::Evaluate(SMESH_Mesh & theMesh, set allNodes; gp_XY uv; double minGroupTol = 1e100; - for ( int iG = 0; iG < srcGroups.size(); ++iG ) + for ( size_t iG = 0; iG < srcGroups.size(); ++iG ) { const SMESHDS_GroupBase* srcGroup = srcGroups[iG]->GetGroupDS(); const double groupTol = 0.5 * sqrt( getMinElemSize2( srcGroup ));