Salome HOME
PAL13460 (PAL EDF 301 force the mesh to go through a point)
authoreap <eap@opencascade.com>
Mon, 26 Feb 2007 13:39:01 +0000 (13:39 +0000)
committereap <eap@opencascade.com>
Mon, 26 Feb 2007 13:39:01 +0000 (13:39 +0000)
    +  SMESH_NodeSearcher* GetNodeSearcher();
    fix AddElement() with 4 nodes

src/SMESH/SMESH_MeshEditor.cxx
src/SMESH/SMESH_MeshEditor.hxx

index b35d55b0937da34dfe9ee4b395c2e884a0d30cab..3ff081cdafc47e8bbea6a93b1b82948ad09b6ec3 100644 (file)
@@ -86,6 +86,10 @@ typedef map<const SMDS_MeshElement*, vector<TNodeOfNodeListMapItr> > 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<const SMDS_MeshNode*> & 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<const SMDS_MeshNode*> & theNodes
 
 }
 
+//=======================================================================
+/*!
+ * \brief Implementation of search for the node closest to point
+ */
+//=======================================================================
+
+struct SMESH_NodeSearcherImpl: public SMESH_NodeSearcher
+{
+  SMESH_NodeSearcherImpl( const SMESHDS_Mesh* theMesh )
+  {
+    set<const SMDS_MeshNode*> 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<const SMDS_MeshNode*> nodes;
+    myOctreeNode->NodesAround( &tgtNode, &nodes, 1e-7);
+    const SMDS_MeshNode* closestNode = 0;
+    double minSqDist = DBL_MAX;
+    list<const SMDS_MeshNode*>::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  :
index 6d1b90a29c7401002fea565694d44330a4e3e2e0..5add2f1a29824802442caeb591385273c67e7dc7 100644 (file)
@@ -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<const SMDS_MeshNode *> faceNodes,
                     vector<const SMDS_MeshNode *>&      poly_nodes,
                     vector<int>&                        quantities) const;