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
146  // equal span
147  AABBTree
148  (
149  const UList<Type>& objects,
150  const pointField& points,
151  const bool equalBinSize = true,
152  const label maxLevel = 3,
153  const label minBinSize = 100
154  );
155 
156 
157  // Public Member Functions
158 
159  // Access
160 
161  //- Return the bounding boxes making up the tree
162  const List<treeBoundBox>& boundBoxes() const;
163 
164  //- Return the contents addressing
165  const List<labelList>& addressing() const;
166 
167 
168  // Evaluation
169 
170  //- Determine whether a point is inside the bounding boxes
171  bool pointInside(const point& pt) const;
172 
173  //- Determine whether a bounding box overlaps the tree bounding
174  // boxes
175  bool overlaps(const boundBox& bbIn) const;
176 
177 
178  // IOstream operators
179 
180  friend Istream& operator>> <Type>(Istream&, AABBTree&);
181  friend Ostream& operator<< <Type>(Ostream&, const AABBTree&);
182 };
183 
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 } // End namespace Foam
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 #ifdef NoRepository
192  #include "AABBTree.C"
193 #endif
194 
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 
197 #endif
198 
199 // ************************************************************************* //
Foam::DynamicList< label >
Foam::AABBTree::pointInside
bool pointInside(const point &pt) const
Determine whether a point is inside the bounding boxes.
Definition: AABBTree.C:435
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:86
Foam::AABBTree::overlaps
bool overlaps(const boundBox &bbIn) const
Determine whether a bounding box overlaps the tree bounding.
Definition: AABBTree.C:450
Foam::AABBTree::boundBoxes
const List< treeBoundBox > & boundBoxes() const
Return the bounding boxes making up the tree.
Definition: AABBTree.C:421
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
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:428
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