Back to index

salome-smesh  6.5.0
SMESH_Octree.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMESH_Octree : global Octree implementation
00024 //  File      : SMESH_Octree.hxx
00025 //  Created   : Tue Jan 16 16:00:00 2007
00026 //  Author    : Nicolas Geimer & Aurélien Motteux (OCC)
00027 //  Module    : SMESH
00028 //
00029 #ifndef _SMESH_OCTREE_HXX_
00030 #define _SMESH_OCTREE_HXX_
00031 
00032 #include "SMESH_Utils.hxx"
00033 #include <Bnd_B3d.hxx>
00034 
00035 class SMESHUtils_EXPORT SMESH_Octree {
00036 
00037 public:
00038 
00039   // Data limiting the tree height
00040   struct Limit {
00041     // MaxLevel of the Octree
00042     int    myMaxLevel;
00043     // Minimal size of the Box
00044     double myMinBoxSize;
00045 
00046     // Default:
00047     // maxLevel-> 8^8 = 16777216 terminal trees
00048     // minSize -> box size not checked
00049     Limit(int maxLevel=8, double minSize=0.):myMaxLevel(maxLevel),myMinBoxSize(minSize) {}
00050     virtual ~Limit() {} // it can be inherited
00051   };
00052 
00053   // Constructor. limit must be provided at tree root construction.
00054   // limit will be deleted by SMESH_Octree
00055   SMESH_Octree (Limit* limit=0);
00056 
00057   // Destructor
00058   virtual ~SMESH_Octree ();
00059 
00060   // Compute the Octree. Must be called by constructor of inheriting class
00061   void                   compute();
00062 
00063   // Tell if Octree is a leaf or not.
00064   // An inheriting class can influence it via myIsLeaf protected field
00065   bool                   isLeaf() const;
00066 
00067   // Return its level
00068   int                    level() const { return myLevel; }
00069 
00070   // Get box to the 3d Bounding Box of the Octree
00071   const Bnd_B3d&         getBox() const { return *myBox; }
00072 
00073   // Compute the bigger dimension of my box
00074   double                 maxSize() const;
00075 
00076   // Return index of a child the given point is in
00077   inline int             getChildIndex(double x, double y, double z, const gp_XYZ& boxMiddle)const;
00078 
00079 protected:
00080   // Return box of the whole tree
00081   virtual Bnd_B3d*       buildRootBox() = 0;
00082 
00083   // Constructor for children
00084   virtual SMESH_Octree*  allocateOctreeChild() const = 0;
00085 
00086   // Build the data in the 8 children
00087   virtual void           buildChildrenData() = 0;
00088 
00089   // members
00090 
00091   // Array of 8 Octree children
00092   SMESH_Octree** myChildren;
00093 
00094   // Point the father, set to NULL for the level 0
00095   SMESH_Octree*  myFather;
00096 
00097   // Tell us if the Octree is a leaf or not
00098   bool           myIsLeaf;
00099 
00100   // Tree limit
00101   const Limit*   myLimit;
00102 
00103 private:
00104   // Build the 8 children boxes recursively
00105   void                   buildChildren();
00106 
00107   // Level of the Octree
00108   int            myLevel;
00109 
00110   Bnd_B3d*       myBox;
00111 };
00112 
00113 //================================================================================
00117 //================================================================================
00118 
00119 inline int SMESH_Octree::getChildIndex(double x, double y, double z, const gp_XYZ& mid) const
00120 {
00121   return (x > mid.X()) + ( y > mid.Y())*2 + (z > mid.Z())*4;
00122 }
00123 
00124 #endif