AABBTree.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2015 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::AABBTree
28
29Description
30 Templated tree of axis-aligned bounding boxes (AABB)
31
32 Designed to be templated on either faces or cells, the AABBTree will
33 decompose the input into a tree of AABB's. The maximum number of tree
34 levels and minimum number of objects per leaf are provided on construction,
35 and the contents (addressing) is stored.
36
37SourceFiles
38 AABBTree.C
39
40\*---------------------------------------------------------------------------*/
41
42#ifndef AABBTree_H
43#define AABBTree_H
44
45#include "labelList.H"
46#include "labelPair.H"
47#include "DynamicList.H"
48#include "pointField.H"
49#include "treeBoundBox.H"
50#include "Ostream.H"
51
52// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53
54namespace Foam
55{
56
57// Forward declaration of friend functions and operators
58
59template<class Type>
60class AABBTree;
61
62template<class Type>
64
65template<class Type>
67
68/*---------------------------------------------------------------------------*\
69 Class AABBTree Declaration
70\*---------------------------------------------------------------------------*/
71
72template<class Type>
73class AABBTree
74{
75
76protected:
77
78 // Protected Data
79
80 //- Tolerance
81 static scalar tolerance_;
82
83 //- Maximum tree level
84 label maxLevel_;
85
86 //- Minimum points per leaf
87 label minLeafSize_;
88
89 //- Bounding boxes making up the tree
91
92 //- Leaf addressing
94
95
96 // Protected Member Functions
97
98 //- Write OBJ file of bounding box
99 void writeOBJ
100 (
101 const bool writeLinesOnly,
102 const treeBoundBox& bb,
103 label& vertI,
104 Ostream& os
105 ) const;
106
107 //- Write OBJ for all bounding boxes
108 void writeOBJ
109 (
110 const bool leavesOnly,
111 const bool writeLinesOnly,
112 const treeBoundBox& bb,
113 const label nodeI,
114 const List<Pair<treeBoundBox>>& bbs,
115 const List<Pair<label>>& nodes,
116 label& vertI,
117 Ostream& os
118 ) const;
119
120 //- Create the bounding boxes by interrogating points
121 void createBoxes
122 (
123 const bool equalBinSize,
124 const label level,
125 const List<Type>& objects,
126 const pointField& points,
127 const DynamicList<label>& objectIDs,
128 const treeBoundBox& bb,
129 const label nodeI,
130
134 ) const;
135
136
137public:
138
139 // Constructors
140
141 //- Null constructor
142 AABBTree();
143
144 //- Construct from components
145 // equalBinSize: divide into equal number of elements or equal span
147 (
148 const UList<Type>& objects,
149 const pointField& points,
150 const bool equalBinSize = true,
151 const label maxLevel = 3,
152 const label minBinSize = 100
153 );
154
155
156 // Public Member Functions
157
158 // Access
159
160 //- Return the bounding boxes making up the tree
161 const List<treeBoundBox>& boundBoxes() const;
162
163 //- Return the contents addressing
164 const List<labelList>& addressing() const;
165
166
167 // Evaluation
168
169 //- Determine whether a point is inside the bounding boxes
170 bool pointInside(const point& pt) const;
171
172 //- Determine whether a bounding box overlaps the tree bounding
173 //- boxes
174 bool overlaps(const boundBox& bbIn) const;
175
176
177 // IOstream operators
179 friend Istream& operator>> <Type>(Istream&, AABBTree&);
180 friend Ostream& operator<< <Type>(Ostream&, const AABBTree&);
181};
182
183
184// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185
186} // End namespace Foam
187
188// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189
190#ifdef NoRepository
191 #include "AABBTree.C"
192#endif
193
194// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195
196#endif
197
198// ************************************************************************* //
Templated tree of axis-aligned bounding boxes (AABB)
Definition: AABBTree.H:73
bool overlaps(const boundBox &bbIn) const
Definition: AABBTree.C:471
static scalar tolerance_
Tolerance.
Definition: AABBTree.H:80
label minLeafSize_
Minimum points per leaf.
Definition: AABBTree.H:86
AABBTree()
Null constructor.
Definition: AABBTree.C:322
const List< labelList > & addressing() const
Return the contents addressing.
Definition: AABBTree.C:449
label maxLevel_
Maximum tree level.
Definition: AABBTree.H:83
bool pointInside(const point &pt) const
Determine whether a point is inside the bounding boxes.
Definition: AABBTree.C:456
void writeOBJ(const bool writeLinesOnly, const treeBoundBox &bb, label &vertI, Ostream &os) const
Write OBJ file of bounding box.
Definition: AABBTree.C:41
List< labelList > addressing_
Leaf addressing.
Definition: AABBTree.H:92
const List< treeBoundBox > & boundBoxes() const
Return the bounding boxes making up the tree.
Definition: AABBTree.C:442
void createBoxes(const bool equalBinSize, const label level, const List< Type > &objects, const pointField &points, const DynamicList< label > &objectIDs, const treeBoundBox &bb, const label nodeI, DynamicList< Pair< treeBoundBox > > &bbs, DynamicList< labelPair > &nodes, DynamicList< labelList > &addressing) const
Create the bounding boxes by interrogating points.
Definition: AABBTree.C:127
List< treeBoundBox > boundBoxes_
Bounding boxes making up the tree.
Definition: AABBTree.H:89
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:69
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:64
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:89
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)