Salome HOME
Improve swig generation process on Windows platform.
[tools/medcoupling.git] / src / INTERP_KERNEL / BBTree.txx
index 7b3d037825b49320d73732cd822032e503beab5e..c319c576f570db5ff357700ef58ed7338258b68a 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -52,7 +52,9 @@ public:
     \param elems array to the indices of the elements contained in the BBTree
     \param level level in the BBTree recursive structure
     \param nbelems nb of elements in the BBTree
-    \param epsilon precision to which points are decided to be coincident
+    \param epsilon precision to which points are decided to be coincident. Epsilon can be positive or negative.
+           If \a epsilon is positive the request method will enlarge the computed bounding box (more matching elems return).
+           If negative the given bounding box will be tighten (less matching elems return).
 
     Parameters \a elems and \a level are used only by BBTree itself for creating trees recursively. A typical use is therefore :
     \code
@@ -64,7 +66,7 @@ public:
     \endcode
   */
 
-  BBTree(const double* bbs, ConnType* elems, int level, ConnType nbelems, double epsilon=1E-12):
+  BBTree(const double* bbs, ConnType* elems, int level, ConnType nbelems, double epsilon=1e-12):
     _left(0), _right(0), _level(level), _bb(bbs), _terminal(false),_nbelems(nbelems),_epsilon(epsilon)
   {
     if (nbelems < MIN_NB_ELEMS || level> MAX_LEVEL)
@@ -192,6 +194,39 @@ public:
     _right->getIntersectingElems(bb,elems);
   }
 
+  /*!
+   * This method is very close to getIntersectingElems except that it returns number of elems instead of elems themselves.
+   */
+  int getNbOfIntersectingElems(const double* bb)
+  {
+    //  terminal node : return list of elements intersecting bb
+    int ret(0);
+    if (_terminal)
+      {
+        for (int i=0; i<_nbelems; i++)
+          {
+            const double* const  bb_ptr=_bb+_elems[i]*2*dim;
+            bool intersects = true;
+            for (int idim=0; idim<dim; idim++)
+              {
+                if (bb_ptr[idim*2]-bb[idim*2+1]>-_epsilon|| bb_ptr[idim*2+1]-bb[idim*2]<_epsilon)
+                  intersects=false;
+              }
+            if (intersects)
+              ret++;
+          }
+        return ret;
+      }
+    //non terminal node 
+    double min = bb[(_level%dim)*2];
+    double max = bb[(_level%dim)*2+1];
+    if (max < _min_right)
+      return _left->getNbOfIntersectingElems(bb);
+    if (min> _max_left)
+      return _right->getNbOfIntersectingElems(bb);
+    return _left->getNbOfIntersectingElems(bb)+_right->getNbOfIntersectingElems(bb);
+  }
+
  
   /*! returns in \a elems the list of elements potentially containing the point pointed to by \a xx
     \param xx pointer to query point coords