//================================================================================
/*!
- \brief Identify the elements that will be affected by node duplication (actual duplication is not performed.
+ \brief Identify the elements that will be affected by node duplication (actual duplication is not performed).
This method is the first step of DoubleNodeElemGroupsInRegion.
\param theElems - list of groups of elements (edges or faces) to be replicated
\param theNodesNot - list of groups of nodes not to replicated
\param theShape - shape to detect affected elements (element which geometric center
- located on or inside shape).
+ located on or inside shape). If the shape is null, detection is done on faces orientations
+ (select elements with a gravity center on the side given by faces normals).
+ This mode (null shape) is faster, but works only when theElems are faces, with coherents orientations.
The replicated nodes should be associated to affected elements.
\return groups of affected elements
\sa DoubleNodeElemGroupsInRegion()
TIDSortedElemSet& theAffectedElems)
{
if ( theShape.IsNull() )
- return false;
-
- const double aTol = Precision::Confusion();
- auto_ptr< BRepClass3d_SolidClassifier> bsc3d;
- auto_ptr<_FaceClassifier> aFaceClassifier;
- if ( theShape.ShapeType() == TopAbs_SOLID )
- {
- bsc3d.reset( new BRepClass3d_SolidClassifier(theShape));;
- bsc3d->PerformInfinitePoint(aTol);
- }
- else if (theShape.ShapeType() == TopAbs_FACE )
{
- aFaceClassifier.reset( new _FaceClassifier(TopoDS::Face(theShape)));
+ std::set<const SMDS_MeshNode*> alreadyCheckedNodes;
+ std::set<const SMDS_MeshElement*> alreadyCheckedElems;
+ std::set<const SMDS_MeshElement*> edgesToCheck;
+ alreadyCheckedNodes.clear();
+ alreadyCheckedElems.clear();
+ edgesToCheck.clear();
+
+ // --- iterates on elements to be replicated and get elements by back references from their nodes
+
+ TIDSortedElemSet::const_iterator elemItr = theElems.begin();
+ int ielem = 1;
+ for ( ; elemItr != theElems.end(); ++elemItr )
+ {
+ SMDS_MeshElement* anElem = (SMDS_MeshElement*)*elemItr;
+ if (!anElem || (anElem->GetType() != SMDSAbs_Face))
+ continue;
+ gp_XYZ normal;
+ SMESH_MeshAlgos::FaceNormal( anElem, normal, /*normalized=*/true );
+ MESSAGE("element " << ielem++ << " normal " << normal.X() << " " << normal.Y() << " " << normal.Z());
+ std::set<const SMDS_MeshNode*> nodesElem;
+ nodesElem.clear();
+ SMDS_ElemIteratorPtr nodeItr = anElem->nodesIterator();
+ while ( nodeItr->more() )
+ {
+ const SMDS_MeshNode* aNode = cast2Node(nodeItr->next());
+ nodesElem.insert(aNode);
+ }
+ std::set<const SMDS_MeshNode*>::iterator nodit = nodesElem.begin();
+ for (; nodit != nodesElem.end(); nodit++)
+ {
+ MESSAGE(" noeud ");
+ const SMDS_MeshNode* aNode = *nodit;
+ if ( !aNode || theNodesNot.find(aNode) != theNodesNot.end() )
+ continue;
+ if (alreadyCheckedNodes.find(aNode) != alreadyCheckedNodes.end())
+ continue;
+ alreadyCheckedNodes.insert(aNode);
+ SMDS_ElemIteratorPtr backElemItr = aNode->GetInverseElementIterator();
+ while ( backElemItr->more() )
+ {
+ MESSAGE(" backelem ");
+ const SMDS_MeshElement* curElem = backElemItr->next();
+ if (alreadyCheckedElems.find(curElem) != alreadyCheckedElems.end())
+ continue;
+ if (theElems.find(curElem) != theElems.end())
+ continue;
+ alreadyCheckedElems.insert(curElem);
+ double x=0, y=0, z=0;
+ int nb = 0;
+ SMDS_ElemIteratorPtr nodeItr2 = curElem->nodesIterator();
+ while ( nodeItr2->more() )
+ {
+ const SMDS_MeshNode* anotherNode = cast2Node(nodeItr2->next());
+ x += anotherNode->X();
+ y += anotherNode->Y();
+ z += anotherNode->Z();
+ nb++;
+ }
+ gp_XYZ p;
+ p.SetCoord( x/nb -aNode->X(),
+ y/nb -aNode->Y(),
+ z/nb -aNode->Z() );
+ MESSAGE(" check " << p.X() << " " << p.Y() << " " << p.Z());
+ if (normal*p > 0)
+ {
+ MESSAGE(" --- inserted")
+ theAffectedElems.insert( curElem );
+ }
+ else if (curElem->GetType() == SMDSAbs_Edge)
+ edgesToCheck.insert(curElem);
+ }
+ }
+ }
+ // --- add also edges lying on the set of faces (all nodes in alreadyCheckedNodes)
+ std::set<const SMDS_MeshElement*>::iterator eit = edgesToCheck.begin();
+ for( ; eit != edgesToCheck.end(); eit++)
+ {
+ bool onside = true;
+ const SMDS_MeshElement* anEdge = *eit;
+ SMDS_ElemIteratorPtr nodeItr = anEdge->nodesIterator();
+ while ( nodeItr->more() )
+ {
+ const SMDS_MeshNode* aNode = cast2Node(nodeItr->next());
+ if (alreadyCheckedNodes.find(aNode) == alreadyCheckedNodes.end())
+ {
+ onside = false;
+ break;
+ }
+ }
+ if (onside)
+ {
+ MESSAGE(" --- edge onside inserted")
+ theAffectedElems.insert(anEdge);
+ }
+ }
}
-
- // iterates on indicated elements and get elements by back references from their nodes
- TIDSortedElemSet::const_iterator elemItr = theElems.begin();
- for ( ; elemItr != theElems.end(); ++elemItr )
+ else
{
- SMDS_MeshElement* anElem = (SMDS_MeshElement*)*elemItr;
- if (!anElem)
- continue;
+ const double aTol = Precision::Confusion();
+ auto_ptr< BRepClass3d_SolidClassifier> bsc3d;
+ auto_ptr<_FaceClassifier> aFaceClassifier;
+ if ( theShape.ShapeType() == TopAbs_SOLID )
+ {
+ bsc3d.reset( new BRepClass3d_SolidClassifier(theShape));;
+ bsc3d->PerformInfinitePoint(aTol);
+ }
+ else if (theShape.ShapeType() == TopAbs_FACE )
+ {
+ aFaceClassifier.reset( new _FaceClassifier(TopoDS::Face(theShape)));
+ }
- SMDS_ElemIteratorPtr nodeItr = anElem->nodesIterator();
- while ( nodeItr->more() )
+ // iterates on indicated elements and get elements by back references from their nodes
+ TIDSortedElemSet::const_iterator elemItr = theElems.begin();
+ int ielem = 1;
+ for ( ; elemItr != theElems.end(); ++elemItr )
{
- const SMDS_MeshNode* aNode = cast2Node(nodeItr->next());
- if ( !aNode || theNodesNot.find(aNode) != theNodesNot.end() )
+ MESSAGE("element " << ielem++);
+ SMDS_MeshElement* anElem = (SMDS_MeshElement*)*elemItr;
+ if (!anElem)
continue;
- SMDS_ElemIteratorPtr backElemItr = aNode->GetInverseElementIterator();
- while ( backElemItr->more() )
+ SMDS_ElemIteratorPtr nodeItr = anElem->nodesIterator();
+ while ( nodeItr->more() )
{
- const SMDS_MeshElement* curElem = backElemItr->next();
- if ( curElem && theElems.find(curElem) == theElems.end() &&
- ( bsc3d.get() ?
- isInside( curElem, *bsc3d, aTol ) :
- isInside( curElem, *aFaceClassifier, aTol )))
- theAffectedElems.insert( curElem );
+ MESSAGE(" noeud ");
+ const SMDS_MeshNode* aNode = cast2Node(nodeItr->next());
+ if ( !aNode || theNodesNot.find(aNode) != theNodesNot.end() )
+ continue;
+ SMDS_ElemIteratorPtr backElemItr = aNode->GetInverseElementIterator();
+ while ( backElemItr->more() )
+ {
+ MESSAGE(" backelem ");
+ const SMDS_MeshElement* curElem = backElemItr->next();
+ if ( curElem && theElems.find(curElem) == theElems.end() &&
+ ( bsc3d.get() ?
+ isInside( curElem, *bsc3d, aTol ) :
+ isInside( curElem, *aFaceClassifier, aTol )))
+ theAffectedElems.insert( curElem );
+ }
}
}
}
{
if ( !_sourceHyp ) return false;
+ //MESSAGE("---------> StdMeshers_Import_1D::Compute");
const vector<SMESH_Group*>& srcGroups = _sourceHyp->GetGroups(/*loaded=*/true);
if ( srcGroups.empty() )
return error("Invalid source groups");
{
_gen->Compute(theMesh,v,/*anUpward=*/true);
n = SMESH_Algo::VertexNode( v, tgtMesh );
+ //MESSAGE("_gen->Compute " << n);
if ( !n ) return false; // very strange
}
vertexNodes.push_back( SMESH_TNodeXYZ( n ));
+ //MESSAGE("SMESH_Algo::VertexNode " << n->GetID() << " " << n->X() << " " << n->Y() << " " << n->Z() );
}
// import edges from groups
SMDS_ElemIteratorPtr srcElems = srcGroup->GetElements();
vector<const SMDS_MeshNode*> newNodes;
SMDS_MeshNode *tmpNode = helper.AddNode(0,0,0);
- double u = 0;
+ double u = 0.314159; // "random" value between 0 and 1, avoid 0 and 1, false detection possible on edge restrictions
while ( srcElems->more() ) // loop on group contents
{
const SMDS_MeshElement* edge = srcElems->next();
// find or create nodes of a new edge
newNodes.resize( edge->NbNodes() );
+ //MESSAGE("edge->NbNodes " << edge->NbNodes());
newNodes.back() = 0;
SMDS_MeshElement::iterator node = edge->begin_nodes();
SMESH_TNodeXYZ a(edge->GetNode(0));
// --- define a tolerance relative to the length of an edge
double mytol = a.Distance(edge->GetNode(edge->NbNodes()-1))/25;
+ //mytol = max(1.E-5, 10*edgeTol); // too strict and not necessary
//MESSAGE("mytol = " << mytol);
for ( unsigned i = 0; i < newNodes.size(); ++i, ++node )
{
for ( vNIt = vertexNodes.begin(); vNIt != vertexNodes.end(); ++vNIt)
if ( vNIt->SquareDistance( *node ) < checktol)
{
- //MESSAGE("SquareDistance " << vNIt->SquareDistance( *node ) << " checktol " << checktol);
+ //MESSAGE("SquareDistance " << vNIt->SquareDistance( *node ) << " checktol " << checktol <<" "<<vNIt->X()<<" "<<vNIt->Y()<<" "<<vNIt->Z());
(*n2nIt).second = vNIt->_node;
vertexNodes.erase( vNIt );
break;
}
+ else if ( vNIt->SquareDistance( *node ) < 10*checktol)
+ MESSAGE("SquareDistance missed" << vNIt->SquareDistance( *node ) << " checktol " << checktol <<" "<<vNIt->X()<<" "<<vNIt->Y()<<" "<<vNIt->Z());
}
if ( !n2nIt->second )
{
// find out if node lies on theShape
+ //double dxyz[4];
tmpNode->setXYZ( (*node)->X(), (*node)->Y(), (*node)->Z());
- if ( helper.CheckNodeU( geomEdge, tmpNode, u, mytol, /*force=*/true ))
+ if ( helper.CheckNodeU( geomEdge, tmpNode, u, mytol, /*force=*/true)) // , dxyz )) // dxyz used for debug purposes
{
SMDS_MeshNode* newNode = tgtMesh->AddNode( (*node)->X(), (*node)->Y(), (*node)->Z());
n2nIt->second = newNode;
tgtMesh->SetNodeOnEdge( newNode, shapeID, u );
- //MESSAGE("u=" << u);
+ //MESSAGE("u=" << u << " " << newNode->X()<< " " << newNode->Y()<< " " << newNode->Z());
+ //MESSAGE("d=" << dxyz[0] << " " << dxyz[1] << " " << dxyz[2] << " " << dxyz[3]);
}
}
if ( !(newNodes[i] = n2nIt->second ))
newEdge = tgtMesh->AddEdge( newNodes[0], newNodes[1], newNodes[2] );
else
newEdge = tgtMesh->AddEdge( newNodes[0], newNodes[1]);
- //MESSAGE("add Edge");
+ //MESSAGE("add Edge " << newNodes[0]->GetID() << " " << newNodes[1]->GetID());
tgtMesh->SetMeshElementOnShape( newEdge, shapeID );
e2e->insert( make_pair( edge, newEdge ));
}