Loading...
Searching...
No Matches
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 Copyright (C) 2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::AABBTree
29
30Description
31 Templated tree of axis-aligned bounding boxes (AABB)
32
33 Designed to be templated on either faces or cells, the AABBTree will
34 decompose the input into a tree of AABB's. The maximum number of tree
35 levels and minimum number of objects per leaf are provided on construction,
36 and the contents (addressing) is stored.
37
38SourceFiles
39 AABBTree.C
40 AABBTreeBase.C
41
42\*---------------------------------------------------------------------------*/
43
44#ifndef Foam_AABBTree_H
45#define Foam_AABBTree_H
46
47#include "labelList.H"
48#include "labelPair.H"
49#include "DynamicList.H"
50#include "pointField.H"
51#include "treeBoundBox.H"
52#include "Ostream.H"
53
54// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55
56namespace Foam
57{
59// Forward Declarations
60template<class Type> class AABBTree;
62template<class Type>
64
65template<class Type>
67
68
69/*---------------------------------------------------------------------------*\
70 Class AABBTreeBase Declaration
71\*---------------------------------------------------------------------------*/
72
73//- Template invariant parts for AABBTree
74class AABBTreeBase
75{
76protected:
77
78 // Static Data
79
80 //- Relative tolerance.
81 static scalar tolerance_;
82
83
84public:
85
86 // Constructors
87
88 //- Default construct
89 AABBTreeBase() = default;
91
92 // Output Helpers
93
94 //- Write treeBoundBox in OBJ format
95 static void writeOBJ
96 (
97 Ostream& os,
98 const treeBoundBox& bb,
99 label& vertIndex,
100 const bool writeLinesOnly = false
101 );
102};
103
104
105/*---------------------------------------------------------------------------*\
106 Class AABBTree Declaration
107\*---------------------------------------------------------------------------*/
108
109template<class Type>
110class AABBTree
111:
112 public AABBTreeBase
114protected:
115
116 // Protected Data
117
118 //- Maximum tree level
119 label maxLevel_;
120
121 //- Minimum points per leaf
122 label minLeafSize_;
123
124 //- Bounding boxes making up the tree
126
127 //- Leaf addressing
130
131 // Protected Member Functions
132
133 //- Write OBJ for all bounding boxes
135 (
136 const bool leavesOnly,
137 const bool writeLinesOnly,
138 const treeBoundBox& bb,
139 const label nodeI,
140 const List<Pair<treeBoundBox>>& bbs,
141 const List<Pair<label>>& nodes,
142 label& vertI,
143 Ostream& os
144 ) const;
145
146 //- Create the bounding boxes by interrogating points
147 void createBoxes
148 (
149 const bool equalBinSize,
150 const label level,
151 const UList<Type>& objects,
152 const pointField& points,
153 const labelUList& objectIDs,
154 const treeBoundBox& bb,
155 const label nodeI,
156
160 ) const;
161
162
163public:
164
165 // Constructors
166
167 //- Default construct
168 AABBTree();
169
170 //- Construct from components
171 // equalBinSize: divide into equal number of elements or equal span
173 (
174 const UList<Type>& objects,
175 const pointField& points,
176 const bool equalBinSize = true,
177 label maxLevel = 3,
178 label minBinSize = 100
179 );
180
181
182 // Public Member Functions
183
184 // Access
185
186 //- Return the bounding boxes making up the tree
188 {
189 return boundBoxes_;
190 }
191
192 //- Return the contents addressing
193 const List<labelList>& addressing() const noexcept
194 {
195 return addressing_;
196 }
197
198
199 // Evaluation
200
201 //- Determine whether a point is inside the bounding boxes
202 bool pointInside(const point& pt) const;
203
204 //- Determine whether a bounding box overlaps the tree bounding boxes
205 bool overlaps(const boundBox& bbIn) const;
206
207
208 // Write
210 //- Write all tree boxes (leaves) in OBJ format
211 void writeOBJ(Ostream& os) const;
212
213
214 // IOstream Operators
215
216 friend Istream& operator>> <Type>(Istream&, AABBTree&);
217 friend Ostream& operator<< <Type>(Ostream&, const AABBTree&);
218};
219
220
221// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222
223} // End namespace Foam
224
225// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226
227#ifdef NoRepository
228 #include "AABBTree.C"
229#endif
230
231// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232
233#endif
234
235// ************************************************************************* //
Template invariant parts for AABBTree.
Definition AABBTree.H:72
static scalar tolerance_
Relative tolerance.
Definition AABBTree.H:80
AABBTreeBase()=default
Default construct.
static void writeOBJ(Ostream &os, const treeBoundBox &bb, label &vertIndex, const bool writeLinesOnly=false)
Write treeBoundBox in OBJ format.
Templated tree of axis-aligned bounding boxes (AABB).
Definition AABBTree.H:116
const List< labelList > & addressing() const noexcept
Return the contents addressing.
Definition AABBTree.H:217
void createBoxes(const bool equalBinSize, const label level, const UList< Type > &objects, const pointField &points, const labelUList &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:76
bool overlaps(const boundBox &bbIn) const
Determine whether a bounding box overlaps the tree bounding boxes.
Definition AABBTree.C:418
label minLeafSize_
Minimum points per leaf.
Definition AABBTree.H:129
AABBTree()
Default construct.
Definition AABBTree.C:270
const List< treeBoundBox > & boundBoxes() const noexcept
Return the bounding boxes making up the tree.
Definition AABBTree.H:209
void writeOBJ(const bool leavesOnly, const bool writeLinesOnly, const treeBoundBox &bb, const label nodeI, const List< Pair< treeBoundBox > > &bbs, const List< Pair< label > > &nodes, label &vertI, Ostream &os) const
Write OBJ for all bounding boxes.
Definition AABBTree.C:29
label maxLevel_
Maximum tree level.
Definition AABBTree.H:124
bool pointInside(const point &pt) const
Determine whether a point is inside the bounding boxes.
Definition AABBTree.C:403
List< labelList > addressing_
Leaf addressing.
Definition AABBTree.H:139
List< treeBoundBox > boundBoxes_
Bounding boxes making up the tree.
Definition AABBTree.H:134
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
An ordered pair of two objects of type <T> with first() and second() elements.
Definition Pair.H:66
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:89
A bounding box defined in terms of min/max extrema points.
Definition boundBox.H:71
Standard boundBox with extra functionality for use in octree.
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).
Istream & operator>>(Istream &, directionInfo &)
vector point
Point is a vector.
Definition point.H:37
const direction noexcept
Definition scalarImpl.H:265
vectorField pointField
pointField is a vectorField.
UList< label > labelUList
A UList of labels.
Definition UList.H:75