Salome HOME
23514: EDF 16031 - SMESH freezes
[modules/smesh.git] / src / SMESHUtils / SMESH_Octree.hxx
index 97d767a60cffb0d7bab10d123c625dd616c89273..6013c230a08c8e8a0807c78c5fb1193f8599f19c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // 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
@@ -20,7 +20,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-//  SMESH SMESH_Octree : global Octree implementation
+//  SMESH SMESH_Octree : Octree implementation
 //  File      : SMESH_Octree.hxx
 //  Created   : Tue Jan 16 16:00:00 2007
 //  Author    : Nicolas Geimer & AurĂ©lien Motteux (OCC)
 #define _SMESH_OCTREE_HXX_
 
 #include "SMESH_Utils.hxx"
+#include "SMESH_Tree.hxx"
 #include <Bnd_B3d.hxx>
 
-class SMESHUtils_EXPORT SMESH_Octree {
-
+//================================================================================
+/*!
+ * \brief 3D tree of anything.
+ * Methods to implement in a descendant are:
+ * - Bnd_B3d*       buildRootBox(); // box of a tree
+ * - descendant*    newChild() const; // a new child instance
+ * - void           buildChildrenData(); // distribute own data among children
+ */
+class SMESHUtils_EXPORT SMESH_Octree : public SMESH_Tree< Bnd_B3d, 8 >
+{
 public:
-
-  // Data limiting the tree height
-  struct Limit {
-    // MaxLevel of the Octree
-    int    myMaxLevel;
-    // Minimal size of the Box
-    double myMinBoxSize;
-
-    // Default:
-    // maxLevel-> 8^8 = 16777216 terminal trees
-    // minSize -> box size not checked
-    Limit(int maxLevel=8, double minSize=0.):myMaxLevel(maxLevel),myMinBoxSize(minSize) {}
-    virtual ~Limit() {} // it can be inherited
-  };
+  typedef SMESH_Tree< Bnd_B3d, 8> TBaseTree;
 
   // Constructor. limit must be provided at tree root construction.
   // limit will be deleted by SMESH_Octree
-  SMESH_Octree (Limit* limit=0);
-
-  // Destructor
-  virtual ~SMESH_Octree ();
-
-  // Compute the Octree. Must be called by constructor of inheriting class
-  void                   compute();
-
-  // Tell if Octree is a leaf or not.
-  // An inheriting class can influence it via myIsLeaf protected field
-  bool                   isLeaf() const;
-
-  // Return its level
-  int                    level() const { return myLevel; }
-
-  // Get box to the 3d Bounding Box of the Octree
-  const Bnd_B3d&         getBox() const { return *myBox; }
+  SMESH_Octree (SMESH_TreeLimit* limit=0);
+  virtual ~SMESH_Octree() {};
 
   // Compute the bigger dimension of my box
   double                 maxSize() const;
 
   // Return index of a child the given point is in
-  inline int             getChildIndex(double x, double y, double z, const gp_XYZ& boxMiddle)const;
+  inline static int      getChildIndex(double x, double y, double z, const gp_XYZ& boxMiddle);
 
-  // Return height of the tree, full or from this level to topest leaf
-  int                    getHeight(const bool full=true) const;
+ protected:
 
-protected:
-  // Return box of the whole tree
-  virtual Bnd_B3d*       buildRootBox() = 0;
+  // Allocate a bndbox according to childIndex. childIndex is zero based
+  virtual Bnd_B3d*       newChildBox(int childIndex) const;
 
-  // Constructor for children
-  virtual SMESH_Octree*  allocateOctreeChild() const = 0;
-
-  // Build the data in the 8 children
-  virtual void           buildChildrenData() = 0;
-
-  // members
-
-  // Array of 8 Octree children
-  SMESH_Octree** myChildren;
-
-  // Point the father, set to NULL for the level 0
-  SMESH_Octree*  myFather;
-
-  // Tell us if the Octree is a leaf or not
-  bool           myIsLeaf;
-
-  // Tree limit
-  const Limit*   myLimit;
-
-private:
-  // Build the 8 children boxes recursively
-  void                   buildChildren();
-
-  // Level of the Octree
-  int            myLevel;
-
-  Bnd_B3d*       myBox;
+  // Change size of a box by a factor; each dimension changes independently of others
+  virtual void           enlargeByFactor( Bnd_B3d* box, double factor ) const;
 };
 
 //================================================================================
 /*!
  * \brief Return index of a child the given point is in
  */
-//================================================================================
-
-inline int SMESH_Octree::getChildIndex(double x, double y, double z, const gp_XYZ& mid) const
+inline int SMESH_Octree::getChildIndex(double x, double y, double z, const gp_XYZ& mid)
 {
   return (x > mid.X()) + ( y > mid.Y())*2 + (z > mid.Z())*4;
 }