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 -------------------------------------------------------------------------------
10 License
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 
26 Class
27  Foam::AABBTree
28 
29 Description
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 
37 SourceFiles
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 
54 namespace Foam
55 {
56 
57 // Forward declaration of friend functions and operators
58 
59 template<class Type>
60 class AABBTree;
61 
62 template<class Type>
64 
65 template<class Type>
67 
68 /*---------------------------------------------------------------------------*\
69  Class AABBTree Declaration
70 \*---------------------------------------------------------------------------*/
71 
72 template<class Type>
73 class AABBTree
74 {
75 
76 protected:
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 
132  DynamicList<labelPair>& nodes,
134  ) const;
135 
136 
137 public:
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
146  AABBTree
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
178 
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 // ************************************************************************* //
Foam::DynamicList< label >
Foam::AABBTree::pointInside
bool pointInside(const point &pt) const
Determine whether a point is inside the bounding boxes.
Definition: AABBTree.C:456
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:86
Foam::AABBTree::overlaps
bool overlaps(const boundBox &bbIn) const
Definition: AABBTree.C:471
Foam::AABBTree::boundBoxes
const List< treeBoundBox > & boundBoxes() const
Return the bounding boxes making up the tree.
Definition: AABBTree.C:442
Foam::AABBTree::boundBoxes_
List< treeBoundBox > boundBoxes_
Bounding boxes making up the tree.
Definition: AABBTree.H:89
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::AABBTree::writeOBJ
void writeOBJ(const bool writeLinesOnly, const treeBoundBox &bb, label &vertI, Ostream &os) const
Write OBJ file of bounding box.
Definition: AABBTree.C:41
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
AABBTree.C
labelList.H
Foam::Field< vector >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
treeBoundBox.H
Foam::AABBTree::AABBTree
AABBTree()
Null constructor.
Definition: AABBTree.C:322
Foam::AABBTree::maxLevel_
label maxLevel_
Maximum tree level.
Definition: AABBTree.H:83
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::AABBTree::tolerance_
static scalar tolerance_
Tolerance.
Definition: AABBTree.H:80
pointField.H
Ostream.H
Foam::Pair
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:54
Foam::AABBTree::addressing
const List< labelList > & addressing() const
Return the contents addressing.
Definition: AABBTree.C:449
Foam::Vector< scalar >
Foam::AABBTree
Templated tree of axis-aligned bounding boxes (AABB)
Definition: AABBTree.H:59
Foam::List< treeBoundBox >
Foam::AABBTree::createBoxes
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
Foam::UList< Type >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::AABBTree::minLeafSize_
label minLeafSize_
Minimum points per leaf.
Definition: AABBTree.H:86
DynamicList.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::AABBTree::addressing_
List< labelList > addressing_
Leaf addressing.
Definition: AABBTree.H:92
labelPair.H