SALOME - SMESH
|
00001 // Copyright (C) 2007-2008 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 // SMESH SMESH_Octree : global Octree implementation 00023 // 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 <Bnd_B3d.hxx> 00033 00034 class SMESH_Octree { 00035 00036 public: 00037 00038 // Data limiting the tree height 00039 struct Limit { 00040 // MaxLevel of the Octree 00041 int myMaxLevel; 00042 // Minimal size of the Box 00043 double myMinBoxSize; 00044 00045 // Default: 00046 // maxLevel-> 8^8 = 16777216 terminal trees 00047 // minSize -> box size not checked 00048 Limit(int maxLevel=8, double minSize=0.):myMaxLevel(maxLevel),myMinBoxSize(minSize) {} 00049 virtual ~Limit() {} // it can be inherited 00050 }; 00051 00052 // Constructor. limit must be provided at tree root construction. 00053 // limit will be deleted by SMESH_Octree 00054 SMESH_Octree (Limit* limit=0); 00055 00056 // Destructor 00057 virtual ~SMESH_Octree (); 00058 00059 // Compute the Octree. Must be called by constructor of inheriting class 00060 void compute(); 00061 00062 // Tell if Octree is a leaf or not. 00063 // An inheriting class can influence it via myIsLeaf protected field 00064 bool isLeaf() const; 00065 00066 // Return its level 00067 int level() const { return myLevel; } 00068 00069 // Get box to the 3d Bounding Box of the Octree 00070 const Bnd_B3d& getBox() const { return *myBox; } 00071 00072 // Compute the bigger dimension of my box 00073 double maxSize() const; 00074 00075 // Return index of a child the given point is in 00076 inline int getChildIndex(double x, double y, double z, const gp_XYZ& boxMiddle)const; 00077 00078 protected: 00079 // Return box of the whole tree 00080 virtual Bnd_B3d* buildRootBox() = 0; 00081 00082 // Constructor for children 00083 virtual SMESH_Octree* allocateOctreeChild() const = 0; 00084 00085 // Build the data in the 8 children 00086 virtual void buildChildrenData() = 0; 00087 00088 // members 00089 00090 // Array of 8 Octree children 00091 SMESH_Octree** myChildren; 00092 00093 // Point the father, set to NULL for the level 0 00094 SMESH_Octree* myFather; 00095 00096 // Tell us if the Octree is a leaf or not 00097 bool myIsLeaf; 00098 00099 // Tree limit 00100 const Limit* myLimit; 00101 00102 private: 00103 // Build the 8 children boxes recursively 00104 void buildChildren(); 00105 00106 // Level of the Octree 00107 int myLevel; 00108 00109 Bnd_B3d* myBox; 00110 }; 00111 00112 //================================================================================ 00116 //================================================================================ 00117 00118 inline int SMESH_Octree::getChildIndex(double x, double y, double z, const gp_XYZ& mid) const 00119 { 00120 return (x > mid.X()) + ( y > mid.Y())*2 + (z > mid.Z())*4; 00121 } 00122 00123 #endif