From e406de3c309fb99a0d9034c3a2ecb5fd4d406e44 Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 26 Feb 2007 13:39:01 +0000 Subject: [PATCH] PAL13460 (PAL EDF 301 force the mesh to go through a point) + SMESH_NodeSearcher* GetNodeSearcher(); fix AddElement() with 4 nodes --- src/SMESH/SMESH_MeshEditor.cxx | 63 +++++++++++++++++++++++++++++++--- src/SMESH/SMESH_MeshEditor.hxx | 16 +++++++++ 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/SMESH/SMESH_MeshEditor.cxx b/src/SMESH/SMESH_MeshEditor.cxx index b35d55b09..3ff081cda 100644 --- a/src/SMESH/SMESH_MeshEditor.cxx +++ b/src/SMESH/SMESH_MeshEditor.cxx @@ -86,6 +86,10 @@ typedef map > TElemOfVecO typedef pair< const SMDS_MeshNode*, const SMDS_MeshNode* > NLink; +struct TNodeXYZ : public gp_XYZ { + TNodeXYZ( const SMDS_MeshNode* n ):gp_XYZ( n->X(), n->Y(), n->Z() ) {} +}; + //======================================================================= //function : SMESH_MeshEditor //purpose : @@ -134,10 +138,10 @@ SMESH_MeshEditor::AddElement(const vector & node, else e = mesh->AddFace (node[0], node[1], node[2], node[3], node[4], node[5] ); else if (nbnode == 8) - if ( ID ) e = mesh->AddFaceWithID(node[0], node[1], node[2], node[2], - node[3], node[4], node[5], node[2], ID); - else e = mesh->AddFace (node[0], node[1], node[2], node[2], - node[3], node[4], node[5], node[2] ); + if ( ID ) e = mesh->AddFaceWithID(node[0], node[1], node[2], node[3], + node[4], node[5], node[6], node[7], ID); + else e = mesh->AddFace (node[0], node[1], node[2], node[3], + node[4], node[5], node[6], node[7] ); } else { if ( ID ) e = mesh->AddPolygonalFaceWithID(node, ID); else e = mesh->AddPolygonalFace (node ); @@ -4301,6 +4305,57 @@ void SMESH_MeshEditor::FindCoincidentNodes (set & theNodes } +//======================================================================= +/*! + * \brief Implementation of search for the node closest to point + */ +//======================================================================= + +struct SMESH_NodeSearcherImpl: public SMESH_NodeSearcher +{ + SMESH_NodeSearcherImpl( const SMESHDS_Mesh* theMesh ) + { + set nodes; + if ( theMesh ) { + SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator(); + while ( nIt->more() ) + nodes.insert( nodes.end(), nIt->next() ); + } + myOctreeNode = new SMESH_OctreeNode(nodes) ; + } + const SMDS_MeshNode* FindClosestTo( const gp_Pnt& thePnt ) + { + SMDS_MeshNode tgtNode( thePnt.X(), thePnt.Y(), thePnt.Z() ); + list nodes; + myOctreeNode->NodesAround( &tgtNode, &nodes, 1e-7); + const SMDS_MeshNode* closestNode = 0; + double minSqDist = DBL_MAX; + list::iterator nIt = nodes.begin(); + for ( ; nIt != nodes.end(); ++nIt ) { + double sqDist = thePnt.SquareDistance( TNodeXYZ( *nIt ) ); + if ( minSqDist > sqDist ) { + closestNode = *nIt; + minSqDist = sqDist; + } + } + return closestNode; + } + ~SMESH_NodeSearcherImpl() { delete myOctreeNode; } +private: + SMESH_OctreeNode* myOctreeNode; +}; + +//======================================================================= +/*! + * \brief Return SMESH_NodeSearcher + */ +//======================================================================= + +SMESH_NodeSearcher* SMESH_MeshEditor::GetNodeSearcher() +{ + return new SMESH_NodeSearcherImpl( GetMeshDS() ); +} + //======================================================================= //function : SimplifyFace //purpose : diff --git a/src/SMESH/SMESH_MeshEditor.hxx b/src/SMESH/SMESH_MeshEditor.hxx index 6d1b90a29..5add2f1a2 100644 --- a/src/SMESH/SMESH_MeshEditor.hxx +++ b/src/SMESH/SMESH_MeshEditor.hxx @@ -67,6 +67,17 @@ struct TIDCompare { }; typedef std::set< const SMDS_MeshElement*, TIDCompare< SMDS_MeshElement> > TIDSortedElemSet; +// ============================================================ +/*! + * \brief Searcher for the node closest to point + */ +// ============================================================ + +struct SMESH_NodeSearcher +{ + virtual const SMDS_MeshNode* FindClosestTo( const gp_Pnt& pnt ) = 0; +}; + // ============================================================ /*! * \brief Editor of a mesh @@ -289,6 +300,11 @@ public: // Return list of group of nodes close to each other within theTolerance. // Search among theNodes or in the whole mesh if theNodes is empty. + /*! + * \brief Return SMESH_NodeSearcher + */ + SMESH_NodeSearcher* GetNodeSearcher(); + int SimplifyFace (const vector faceNodes, vector& poly_nodes, vector& quantities) const;