Version: 6.3.1
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]

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_MeshNodeFindClosestTo (const gp_Pnt &thePnt)
 Do it's job.
 ~SMESH_NodeSearcherImpl ()
 Destructor.
const SMESH_OctreeNodegetTree () const
 Return the node tree.

Private Attributes

SMESH_OctreeNodemyOctreeNode
SMESHDS_MeshmyMesh
double myHalfLeafSize

Detailed Description

Implementation of search for the node closest to point.

Definition at line 6139 of file SMESH_MeshEditor.cxx.


Constructor & Destructor Documentation

SMESH_NodeSearcherImpl.SMESH_NodeSearcherImpl ( const SMESHDS_Mesh theMesh)

Constructor.

Definition at line 6145 of file SMESH_MeshEditor.cxx.

References SMESH_OctreeNode.GetChildrenIterator(), SMESH_Octree.isLeaf(), SMESH_Octree.maxSize(), SMESH_AdvancedEditor.nodes, and SMDS_Mesh.nodesIterator().

  {
    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.;
  }
SMESH_NodeSearcherImpl.~SMESH_NodeSearcherImpl ( )

Destructor.

Definition at line 6257 of file SMESH_MeshEditor.cxx.

{ delete myOctreeNode; }

Member Function Documentation

const SMDS_MeshNode* SMESH_NodeSearcherImpl.FindClosestTo ( const gp_Pnt &  thePnt) [virtual]

Do it's job.

Implements SMESH_NodeSearcher.

Definition at line 6182 of file SMESH_MeshEditor.cxx.

References ex13_hole1partial.box, SMESH_Octree.getBox(), SMESH_OctreeNode.GetChildrenIterator(), SMESH_OctreeNode.GetNodeIterator(), SMESH_OctreeNode.isInside(), SMESH_Octree.isLeaf(), SMESH_OctreeNode.NbNodes(), SMESH_AdvancedEditor.nodes, and SMESH_OctreeNode.NodesAround().

Referenced by SMESH_ElementSearcherImpl.FindElementsByPoint().

  {
    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;
  }
const SMESH_OctreeNode* SMESH_NodeSearcherImpl.getTree ( ) const

Return the node tree.

Definition at line 6263 of file SMESH_MeshEditor.cxx.

Referenced by SMESH_ElementSearcherImpl.getTolerance().

{ return myOctreeNode; }
void SMESH_NodeSearcherImpl.MoveNode ( const SMDS_MeshNode node,
const gp_Pnt &  toPnt 
) [virtual]

Move node and update myOctreeNode accordingly.

Implements SMESH_NodeSearcher.

Definition at line 6172 of file SMESH_MeshEditor.cxx.

References SMDS_MeshNode.X().

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

Field Documentation

Definition at line 6268 of file SMESH_MeshEditor.cxx.

Definition at line 6267 of file SMESH_MeshEditor.cxx.

Definition at line 6266 of file SMESH_MeshEditor.cxx.

Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS