Back to index

salome-smesh  6.5.0
Public Member Functions | Private Attributes
SMESH_NodeSearcherImpl Struct Reference

Implementation of search for the node closest to point. More...

Inheritance diagram for SMESH_NodeSearcherImpl:
Inheritance graph
[legend]
Collaboration diagram for SMESH_NodeSearcherImpl:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SMESH_NodeSearcherImpl (const SMESHDS_Mesh *theMesh)
 Constructor.
void MoveNode (const SMDS_MeshNode *node, const gp_Pnt &toPnt)
 Move node and update myOctreeNode accordingly.
const SMDS_MeshNode * FindClosestTo (const gp_Pnt &thePnt)
 Do it's job.
 ~SMESH_NodeSearcherImpl ()
 Destructor.
const SMESH_OctreeNode * getTree () const
 Return the node tree.

Private Attributes

SMESH_OctreeNode * myOctreeNode
SMESHDS_Mesh * myMesh
double myHalfLeafSize

Detailed Description

Implementation of search for the node closest to point.

Definition at line 5908 of file SMESH_MeshEditor.cxx.


Constructor & Destructor Documentation

SMESH_NodeSearcherImpl::SMESH_NodeSearcherImpl ( const SMESHDS_Mesh *  theMesh) [inline]

Constructor.

Definition at line 5914 of file SMESH_MeshEditor.cxx.

  {
    myMesh = ( SMESHDS_Mesh* ) theMesh;

    TIDSortedNodeSet nodes;
    if ( theMesh ) {
      SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator(/*idInceasingOrder=*/true);
      while ( nIt->more() )
        nodes.insert( nodes.end(), nIt->next() );
    }
    myOctreeNode = new SMESH_OctreeNode(nodes) ;

    // get max size of a leaf box
    SMESH_OctreeNode* tree = myOctreeNode;
    while ( !tree->isLeaf() )
    {
      SMESH_OctreeNodeIteratorPtr cIt = tree->GetChildrenIterator();
      if ( cIt->more() )
        tree = cIt->next();
    }
    myHalfLeafSize = tree->maxSize() / 2.;
  }

Destructor.

Definition at line 6026 of file SMESH_MeshEditor.cxx.

{ delete myOctreeNode; }

Member Function Documentation

const SMDS_MeshNode* SMESH_NodeSearcherImpl::FindClosestTo ( const gp_Pnt &  thePnt) [inline, virtual]

Do it's job.

Implements SMESH_NodeSearcher.

Definition at line 5951 of file SMESH_MeshEditor.cxx.

  {
    map<double, const SMDS_MeshNode*> dist2Nodes;
    myOctreeNode->NodesAround( thePnt.Coord(), dist2Nodes, myHalfLeafSize );
    if ( !dist2Nodes.empty() )
      return dist2Nodes.begin()->second;
    list<const SMDS_MeshNode*> nodes;
    //myOctreeNode->NodesAround( &tgtNode, &nodes, myHalfLeafSize );

    double minSqDist = DBL_MAX;
    if ( nodes.empty() )  // get all nodes of OctreeNode's closest to thePnt
    {
      // sort leafs by their distance from thePnt
      typedef map< double, SMESH_OctreeNode* > TDistTreeMap;
      TDistTreeMap treeMap;
      list< SMESH_OctreeNode* > treeList;
      list< SMESH_OctreeNode* >::iterator trIt;
      treeList.push_back( myOctreeNode );

      gp_XYZ pointNode( thePnt.X(), thePnt.Y(), thePnt.Z() );
      bool pointInside = myOctreeNode->isInside( pointNode, myHalfLeafSize );
      for ( trIt = treeList.begin(); trIt != treeList.end(); ++trIt)
      {
        SMESH_OctreeNode* tree = *trIt;
        if ( !tree->isLeaf() ) // put children to the queue
        {
          if ( pointInside && !tree->isInside( pointNode, myHalfLeafSize )) continue;
          SMESH_OctreeNodeIteratorPtr cIt = tree->GetChildrenIterator();
          while ( cIt->more() )
            treeList.push_back( cIt->next() );
        }
        else if ( tree->NbNodes() ) // put a tree to the treeMap
        {
          const Bnd_B3d& box = tree->getBox();
          double sqDist = thePnt.SquareDistance( 0.5 * ( box.CornerMin() + box.CornerMax() ));
          pair<TDistTreeMap::iterator,bool> it_in = treeMap.insert( make_pair( sqDist, tree ));
          if ( !it_in.second ) // not unique distance to box center
            treeMap.insert( it_in.first, make_pair( sqDist + 1e-13*treeMap.size(), tree ));
        }
      }
      // find distance after which there is no sense to check tree's
      double sqLimit = DBL_MAX;
      TDistTreeMap::iterator sqDist_tree = treeMap.begin();
      if ( treeMap.size() > 5 ) {
        SMESH_OctreeNode* closestTree = sqDist_tree->second;
        const Bnd_B3d& box = closestTree->getBox();
        double limit = sqrt( sqDist_tree->first ) + sqrt ( box.SquareExtent() );
        sqLimit = limit * limit;
      }
      // get all nodes from trees
      for ( ; sqDist_tree != treeMap.end(); ++sqDist_tree) {
        if ( sqDist_tree->first > sqLimit )
          break;
        SMESH_OctreeNode* tree = sqDist_tree->second;
        tree->NodesAround( tree->GetNodeIterator()->next(), &nodes );
      }
    }
    // find closest among nodes
    minSqDist = DBL_MAX;
    const SMDS_MeshNode* closestNode = 0;
    list<const SMDS_MeshNode*>::iterator nIt = nodes.begin();
    for ( ; nIt != nodes.end(); ++nIt ) {
      double sqDist = thePnt.SquareDistance( SMESH_TNodeXYZ( *nIt ) );
      if ( minSqDist > sqDist ) {
        closestNode = *nIt;
        minSqDist = sqDist;
      }
    }
    return closestNode;
  }

Here is the caller graph for this function:

const SMESH_OctreeNode* SMESH_NodeSearcherImpl::getTree ( ) const [inline]

Return the node tree.

Definition at line 6032 of file SMESH_MeshEditor.cxx.

{ return myOctreeNode; }

Here is the caller graph for this function:

void SMESH_NodeSearcherImpl::MoveNode ( const SMDS_MeshNode *  node,
const gp_Pnt &  toPnt 
) [inline, virtual]

Move node and update myOctreeNode accordingly.

Implements SMESH_NodeSearcher.

Definition at line 5941 of file SMESH_MeshEditor.cxx.

  {
    myOctreeNode->UpdateByMoveNode( node, toPnt );
    myMesh->MoveNode( node, toPnt.X(), toPnt.Y(), toPnt.Z() );
  }

Member Data Documentation

Definition at line 6037 of file SMESH_MeshEditor.cxx.

SMESHDS_Mesh* SMESH_NodeSearcherImpl::myMesh [private]

Definition at line 6036 of file SMESH_MeshEditor.cxx.

SMESH_OctreeNode* SMESH_NodeSearcherImpl::myOctreeNode [private]

Definition at line 6035 of file SMESH_MeshEditor.cxx.


The documentation for this struct was generated from the following file: