1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
28 Class to implement octree.
30 Holds the pointers to sub-octants. These are either other treeNodes or
31 treeLeafs. The treeLeafs hold the actual data as a list of indices into
35 To prevent calculation errors all bounding boxes used in octrees are
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"
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>&);
72 /*---------------------------------------------------------------------------*\
73 Class treeNodeName Declaration
74 \*---------------------------------------------------------------------------*/
76 TemplateName(treeNode);
79 /*---------------------------------------------------------------------------*\
80 Class treeNode Declaration
81 \*---------------------------------------------------------------------------*/
86 public treeElem<Type>,
91 //- Position of the midpoint
94 //- Type stored in subNodes_
95 unsigned char subNodeTypes_;
97 //- Pointers to sub treeNode or treeLeaf
98 treeElem<Type>* subNodes_[8];
100 //- Constant valid for whole subNode/leaf
103 // Static data members
105 //- leaf offset for octant index
106 static const label leafOffset;
109 // Private Member Functions
111 //- mark pointer to subnode as being a treeNode*
112 void setAsNode(const label octant);
114 //- mark pointer to subnode as being a treeLeaf*
115 void setAsLeaf(const label octant);
117 //- Set pointer to sub node
118 void setNodePtr(const label octant, treeElem<Type>* treeNodePtr);
120 //- Set pointer to sub leaf
121 void setLeafPtr(const label octant, treeElem<Type>* treeLeafPtr);
123 //- Set type of octant
124 void setVolType(const label octant, const label type);
126 //- Get type of octant
127 inline label getVolType(const label octant) const;
129 //- Find first leaf on line start-end. Updates start.
130 const treeLeaf<Type>* findLeafLineOctant
135 const vector& direction,
142 static void space(Ostream&, const label);
144 //- Disallow default bitwise copy construct
145 treeNode(const treeNode&);
147 //- Disallow default bitwise assignment
148 void operator=(const treeNode&);
155 //- Construct from components
156 treeNode(const treeBoundBox&);
158 //- Construct from Istream
170 //- The midpoint position
171 inline const point& midpoint() const;
173 //- array of 8 subNodes/leaves
174 inline treeElem<Type>* const* subNodes() const;
176 //- octant contains pointer to treeNode(1) or treeLeaf(0)
177 inline label isNode(const label octant) const;
179 //- Get pointer to sub node
180 inline treeNode<Type>* getNodePtr(const label octant) const;
182 //- Get pointer to sub leaf
183 inline treeLeaf<Type>* getLeafPtr(const label octant) const;
187 //- Take list of shapes and distribute over the 8 octants
196 //- Distribute at certain level only
205 //- Set type of subnodes
215 //- Find type of node sample is in. Used for inside/outside
220 const octree<Type>& top,
225 //- Find index of shape containing sample.
232 //- Find tightest bounding box around sample which is guaranteed
233 // to hold at least one cell.
234 // Current best bb in tightest,
235 // returns true if newTightest has changed, 0 otherwise.
240 treeBoundBox& tightest
243 //- Find nearest shape to sample
244 // Returns true if found nearer shape and updates
245 // tightest, tightestI, tightestDist
250 treeBoundBox& tightest,
255 //- Find nearest shape to line
256 // Returns true if found nearer shape and updates nearest and
261 const linePointRef& ln,
262 treeBoundBox& tightest,
263 label& tightestI, // index of nearest shape
264 point& linePoint, // nearest point on line
265 point& shapePoint // nearest point on shape
268 //- Find shapes not outside box. Return true if anything found.
273 labelHashSet& elements
276 //- Find treeLeaves intersecting line segment [start..end]
278 const treeLeaf<Type>* findLeafLine
287 //- Collect all treeLeafs in leafArray. leafIndex points to first
288 // empty slot in leafArray and gets updated.
291 List<treeLeaf<Type>*>& leafArray,
295 //- Same but for const.
298 List<const treeLeaf<Type>*>& leafArray,
305 //- Print contents of node.
312 //- Write subleafs in OBJ format.
321 // IOstream Operators
323 friend Istream& operator>> <Type> (Istream&, treeNode<Type>&);
324 friend Ostream& operator<< <Type> (Ostream&, const treeNode<Type>&);
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 } // End namespace Foam
333 #include "treeNodeI.H"
335 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338 # include "treeNode.C"
341 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345 // ************************************************************************* //