1 // SMESH SMESH_Octree : global Octree implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Octree.cxx
25 // Created : Tue Jan 16 16:00:00 2007
26 // Author : Nicolas Geimer & Aurélien Motteux(OCC)
29 #include "SMESH_Octree.hxx"
31 //===========================================================================
33 * \brief SMESH_Octree Constructor
34 * \param maxLevel - The level max the octree can reach (If <0 unlimited)
36 //===========================================================================
37 SMESH_Octree::SMESH_Octree (const int maxLevel, const double minBoxSize):
41 myMinBoxSize(minBoxSize),
44 myBox = new Bnd_B3d();
47 //======================================
49 * \brief SMESH_Octree Destructor
51 //======================================
52 SMESH_Octree::~SMESH_Octree ()
54 if(myChildren != NULL)
58 for(int i = 0; i<8; i++)
66 //===========================================================================
68 * \brief Set the bounding box of the Octree
69 * \param box - 3d Bounding Box of the Octree
71 //===========================================================================
72 void SMESH_Octree::setBox(const Bnd_B3d* box)
75 myBox=new Bnd_B3d(*box);
78 //===========================================================================
80 * \brief Set box to the 3d Bounding Box of the Octree
81 * \param box - Set box to the 3d Bounding Box of the Octree
83 //===========================================================================
84 void SMESH_Octree::getBox(Bnd_B3d* box)
88 box = new Bnd_B3d (*myBox);
91 //===========================================================================
93 * \brief Set the max level of the Octree
94 * \param maxLevel - The level max the octree can reach (If <0 unlimited)
96 //===========================================================================
97 void SMESH_Octree::setMaxLevel(const int maxLevel)
98 {myMaxLevel = maxLevel;}
101 //===========================================================================
103 * \brief Compute the bigger dimension of the box
104 * \param box - 3d Box
105 * \retval double - bigger dimension of the box
107 //===========================================================================
108 double SMESH_Octree::maxSize(const Bnd_B3d* box)
112 gp_XYZ min = box->CornerMin();
113 gp_XYZ max = box->CornerMax();
114 gp_XYZ Size = (max - min);
115 double returnVal = (Size.X()>Size.Y())?Size.X():Size.Y();
116 return (returnVal>Size.Z())?returnVal:Size.Z();
119 //=============================
121 * \brief Compute the Octree
123 //=============================
124 void SMESH_Octree::Compute()
126 // As soon as the Octree is a Leaf, I stop building his children
131 //=================================================================
133 * \brief Build the 8 children boxes and call buildChildrenData()
135 //=================================================================
136 void SMESH_Octree::buildChildren()
138 myChildren = new SMESH_Octree*[8];
140 gp_XYZ min = myBox->CornerMin();
141 gp_XYZ max = myBox->CornerMax();
142 gp_XYZ HSize = (max - min)/2.;
143 gp_XYZ mid = min + HSize;
144 gp_XYZ childHsize = HSize/2.;
146 Standard_Real XminChild, YminChild, ZminChild;
149 for (int i =0; i<8; i++)
151 // We build the eight boxes, we need 2 points to do that.
153 // In binary, we can write i from 0 to 7
155 // 5 is 101, it corresponds here in coordinates to ZYX
156 // If coordinate is 0 in Y-> box from Ymin to Ymid
157 // If coordinate is 1 in Y-> box from Ymid to Ymax
158 // Same scheme for X and Z
159 // I need the minChild to build the Bnd_B3d box.
161 XminChild= (i%2==0)?min.X():mid.X();
162 YminChild= ((i%4)/2==0)?min.Y():mid.Y();
163 ZminChild= (i<4)?min.Z():mid.Z();
164 minChild.SetCoord(XminChild, YminChild, ZminChild);
166 box = new Bnd_B3d(minChild+childHsize,childHsize);
167 // The child is of the same type than its father (For instance, a SMESH_OctreeNode)
168 // We allocate the memory we need fot the child
169 myChildren[i] = allocateOctreeChild();
170 // and we assign to him its box.
171 myChildren[i]->setBox(box);
175 // After building the 8 boxes, we put the data into the children..
178 //After we pass to the next level of the Octree
179 for (int i =0; i<8; i++)
180 myChildren[i]->Compute();