1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Class to implement octree.
31 Holds the pointers to subcubes. These are either other treeNodes or
32 treeLeafs. treeLeafs hold the actual data as a list of indices into
35 To prevent calculation errors all bb's used in octrees are calculated
38 The pointers to either treeNode/treeLeaf are implemented 'by hand'
39 (explicitly marking type) instead of using a proper virtual mechanism
40 to save some space in the treeLeaves.
45 \*---------------------------------------------------------------------------*/
50 #include "treeBoundBoxList.H"
52 #include "linePointRef.H"
53 #include "labelHashSet.H"
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 // class intersection;
62 template<class Type> class octree;
63 template<class Type> class treeLeaf;
64 template<class Type> class treeNode;
66 // Forward declaration of friend functions and operators
68 template<class Type> Istream& operator>>(Istream&, treeNode<Type>&);
69 template<class Type> Ostream& operator<<(Ostream&, const treeNode<Type>&);
73 /*---------------------------------------------------------------------------*\
74 Class treeNodeName Declaration
75 \*---------------------------------------------------------------------------*/
77 TemplateName(treeNode);
80 /*---------------------------------------------------------------------------*\
81 Class treeNode Declaration
82 \*---------------------------------------------------------------------------*/
87 public treeElem<Type>,
92 //- position of midPoint
95 //- Type stored in subNodes_
96 unsigned char subNodeTypes_;
98 //- Pointers to sub treeNode or treeLeaf
99 treeElem<Type>* subNodes_[8];
101 //- Constant valid for whole subNode/leaf
104 // Static data members
106 //- empty labelList to satisfy compiler
107 static const labelList dummy;
109 //- leaf offset for octant index
110 static const label leafOffset;
113 // Private Member Functions
115 //- mark pointer to subnode as being a treeNode*
116 void setAsNode(const label octant);
118 //- mark pointer to subnode as being a treeLeaf*
119 void setAsLeaf(const label octant);
121 //- Set pointer to sub node
122 void setNodePtr(const label octant, treeElem<Type>* treeNodePtr);
124 //- Set pointer to sub leaf
125 void setLeafPtr(const label octant, treeElem<Type>* treeLeafPtr);
127 //- Set type of octant
128 void setVolType(const label octant, const label type);
130 //- Get type of octant
131 inline label getVolType(const label octant) const;
133 //- Find first leaf on line start-end. Updates start.
134 const treeLeaf<Type>* findLeafLineOctant
139 const vector& direction,
146 static void space(Ostream&, const label);
148 //- Disallow default bitwise copy construct
149 treeNode(const treeNode&);
151 //- Disallow default bitwise assignment
152 void operator=(const treeNode&);
159 //- Construct from components
160 treeNode(const treeBoundBox& bb);
162 //- Construct from Istream
175 //- position of midPoint
176 const point& mid() const;
178 //- array of 8 subNodes/leaves
179 inline treeElem<Type>* const* subNodes() const;
181 //- octant contains pointer to treeNode(1) or treeLeaf(0)
182 inline label isNode(const label octant) const;
184 //- Get pointer to sub node
185 inline treeNode<Type>* getNodePtr(const label octant) const;
187 //- Get pointer to sub leaf
188 inline treeLeaf<Type>* getLeafPtr(const label octant) const;
192 //- Take list of shapes and distribute over the 8 octants
201 //- Distribute at certain level only
210 //- Set type of subnodes
220 //- Find type of node sample is in. Used for inside/outside
225 const octree<Type>& top,
230 //- Find index of shape containing sample.
237 //- Find tightest bounding box around sample which is guaranteed
238 // to hold at least one cell.
239 // Current best bb in tightest,
240 // returns true if newTightest has changed, 0 otherwise.
245 treeBoundBox& tightest
248 //- Find nearest shape to sample
249 // Returns true if found nearer shape and updates
250 // tightest, tightesti, tightestDist
255 treeBoundBox& tightest,
260 //- Find nearest shape to line
261 // Returns true if found nearer shape and updates nearest and
266 const linePointRef& ln,
267 treeBoundBox& tightest,
268 label& tightesti, // index of nearest shape
269 point& linePoint, // nearest point on line
270 point& shapePoint // nearest point on shape
273 //- Find shapes not outside box. Return true if anything found.
278 labelHashSet& elements
281 //- Find treeLeaves intersecting line segment [start..end]
283 const treeLeaf<Type>* findLeafLine
292 //- Collect all treeLeafs in leafArray. leafIndex points to first
293 // empty slot in leafArray and gets updated.
296 List<treeLeaf<Type>*>& leafArray,
300 //- Same but for const.
303 List<const treeLeaf<Type>*>& leafArray,
310 //- Print contents of node.
317 //- Write subleafs in OBJ format.
326 // IOstream Operators
328 friend Istream& operator>> <Type> (Istream&, treeNode<Type>&);
329 friend Ostream& operator<< <Type> (Ostream&, const treeNode<Type>&);
333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 } // End namespace Foam
338 #include "treeNodeI.H"
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
343 # include "treeNode.C"
346 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
350 // ************************************************************************* //