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 | Copyright (C) 2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Class
25  Foam::AABBTree
26 
27 Description
28  Templated tree of axis-aligned bounding boxes (AABB)
29 
30  Designed to be templated on either faces or cells, the AABBTree will
31  decompose the input into a tree of AABB's. The maximum number of tree
32  levels and minimum number of objects per leaf are provided on construction,
33  and the contents (addressing) is stored.
34 
35 SourceFiles
36  AABBTree.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef AABBTree_H
41 #define AABBTree_H
42 
43 #include "labelList.H"
44 #include "labelPair.H"
45 #include "DynamicList.H"
46 #include "pointField.H"
47 #include "treeBoundBox.H"
48 #include "Ostream.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward declaration of friend functions and operators
56 
57 template<class Type>
58 class AABBTree;
59 
60 template<class Type>
62 
63 template<class Type>
65 
66 /*---------------------------------------------------------------------------*\
67  Class AABBTree Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 template<class Type>
71 class AABBTree
72 {
73 
74 protected:
75 
76  // Protected Data
77 
78  //- Tolerance
79  static scalar tolerance_;
80 
81  //- Maximum tree level
83 
84  //- Minimum points per leaf
86 
87  //- Bounding boxes making up the tree
89 
90  //- Leaf adressing
92 
93 
94  // Protected Member Functions
95 
96  //- Write OBJ file of bounding box
97  void writeOBJ
98  (
99  const bool writeLinesOnly,
100  const treeBoundBox& bb,
101  label& vertI,
102  Ostream& os
103  ) const;
104 
105  //- Write OBJ for all bounding boxes
106  void writeOBJ
107  (
108  const bool leavesOnly,
109  const bool writeLinesOnly,
110  const treeBoundBox& bb,
111  const label nodeI,
112  const List<Pair<treeBoundBox> >& bbs,
113  const List<Pair<label> >& nodes,
114  label& vertI,
115  Ostream& os
116  ) const;
117 
118  //- Create the bounding boxes by interrogating points
119  void createBoxes
120  (
121  const bool equalBinSize,
122  const label level,
123  const List<Type>& objects,
124  const pointField& points,
125  const DynamicList<label>& objectIDs,
126  const treeBoundBox& bb,
127  const label nodeI,
128 
130  DynamicList<labelPair>& nodes,
132  ) const;
133 
134 
135 public:
136 
137  // Constructors
138 
139  //- Null constructor
140  AABBTree();
141 
142  //- Construct from components
143  // equalBinSize: divide into equal number of elements or
144  // equal span
145  AABBTree
146  (
147  const UList<Type>& objects,
148  const pointField& points,
149  const bool equalBinSize = true,
150  const label maxLevel = 3,
151  const label minBinSize = 100
152  );
153 
154 
155  // Public Member Functions
156 
157  // Access
158 
159  //- Return the bounding boxes making up the tree
160  const List<treeBoundBox>& boundBoxes() const;
161 
162  //- Return the contents addressing
163  const List<labelList>& addressing() const;
164 
165 
166  // Evaluation
167 
168  //- Determine whether a point is inside the bounding boxes
169  bool pointInside(const point& pt) const;
170 
171  //- Determine whether a bounding box overlaps the tree bounding
172  // boxes
173  bool overlaps(const boundBox& bbIn) const;
174 
175 
176  // IOstream operators
177 
178  friend Istream& operator>> <Type>(Istream&, AABBTree&);
179  friend Ostream& operator<< <Type>(Ostream&, const AABBTree&);
180 };
181 
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 } // End namespace Foam
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #ifdef NoRepository
190  #include "AABBTree.C"
191 #endif
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #endif
196 
197 // ************************************************************************* //
Foam::DynamicList< label >
Foam::AABBTree::pointInside
bool pointInside(const point &pt) const
Determine whether a point is inside the bounding boxes.
Definition: AABBTree.C:442
Foam::treeBoundBox
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:75
Foam::AABBTree::overlaps
bool overlaps(const boundBox &bbIn) const
Determine whether a bounding box overlaps the tree bounding.
Definition: AABBTree.C:459
Foam::AABBTree::boundBoxes
const List< treeBoundBox > & boundBoxes() const
Return the bounding boxes making up the tree.
Definition: AABBTree.C:428
Foam::AABBTree::boundBoxes_
List< treeBoundBox > boundBoxes_
Bounding boxes making up the tree.
Definition: AABBTree.H:87
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:38
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
AABBTree.C
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
labelList.H
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
treeBoundBox.H
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::AABBTree::AABBTree
AABBTree()
Null constructor.
Definition: AABBTree.C:329
Foam::AABBTree::maxLevel_
label maxLevel_
Maximum tree level.
Definition: AABBTree.H:81
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::AABBTree::tolerance_
static scalar tolerance_
Tolerance.
Definition: AABBTree.H:78
pointField.H
Ostream.H
Foam::Pair
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
Foam::AABBTree::addressing
const List< labelList > & addressing() const
Return the contents addressing.
Definition: AABBTree.C:435
Foam::Vector< scalar >
Foam::AABBTree
Templated tree of axis-aligned bounding boxes (AABB)
Definition: AABBTree.H:57
Foam::List< treeBoundBox >
Foam::UList< Type >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::operator>>
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:141
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
Foam::AABBTree::minLeafSize_
label minLeafSize_
Minimum points per leaf.
Definition: AABBTree.H:84
DynamicList.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::AABBTree::addressing_
List< labelList > addressing_
Leaf adressing.
Definition: AABBTree.H:90
labelPair.H