37 const bool leavesOnly,
38 const bool writeLinesOnly,
47 if (!leavesOnly || nodeI < 0)
71 nodes[nodeI].second(),
84 const bool equalBinSize,
86 const UList<Type>& objects,
88 const labelUList& objectIDs,
89 const treeBoundBox& bb,
92 DynamicList<Pair<treeBoundBox>>& bbs,
93 DynamicList<labelPair>& nodes,
94 DynamicList<labelList>& addressing
99 const direction maxDir = bb.maxDir();
100 const scalar maxSpan = bb.span()[maxDir];
108 bitSet isUsedPoint(
points.size());
109 DynamicList<scalar> component(
points.size());
111 for (
const label objI : objectIDs)
113 const Type& obj = objects[objI];
115 for (
const label pointI : obj)
117 if (isUsedPoint.set(pointI))
119 component.push_back(
points[pointI][maxDir]);
133 pivotValue = bb.min()[maxDir] + 0.5*maxSpan;
137 const scalar divMin = pivotValue + tolerance_*maxSpan;
138 const scalar divMax = pivotValue - tolerance_*maxSpan;
143 DynamicList<label> minBinObjectIDs(objectIDs.size());
144 DynamicList<label> maxBinObjectIDs(objectIDs.size());
149 for (
const label objI : objectIDs)
151 const Type& obj = objects[objI];
156 for (
const label pointi : obj)
158 const scalar& cmptValue =
points[pointi][maxDir];
160 addMin = addMin || (cmptValue < divMin);
161 addMax = addMax || (cmptValue > divMax);
163 if (addMin && addMax)
break;
170 minBinObjectIDs.push_back(objI);
175 maxBinObjectIDs.push_back(objI);
181 if (minBinObjectIDs.size())
185 if (maxBinObjectIDs.size())
190 minBinObjectIDs.shrink();
191 maxBinObjectIDs.shrink();
193 bool addMin = (minBinObjectIDs.size() > minLeafSize_ && level < maxLevel_);
194 bool addMax = (maxBinObjectIDs.size() > minLeafSize_ && level < maxLevel_);
200 objectIDs.size() <= (minBinObjectIDs.size() + minLeafSize_/2)
201 || objectIDs.size() <= (maxBinObjectIDs.size() + minLeafSize_/2)
204 addMin = addMax =
false;
212 nodes.emplace_back(-1, -1);
217 minI = -addressing.size() - 1;
218 addressing.push_back(minBinObjectIDs);
226 nodes.emplace_back(-1, -1);
231 maxI = -addressing.size() - 1;
232 addressing.push_back(maxBinObjectIDs);
236 bbs(nodeI) = Pair<treeBoundBox>(minBb, maxBb);
291 const bool equalBinSize,
297 minLeafSize_(minLeafSize),
311 nodes.emplace_back(-1, -1);
357 if (nodes[nodeI].first() < 0)
362 if (nodes[nodeI].second() < 0)
375 bitSet checked(objects.
size());
378 for (
const auto&
id : box)
384 const label unsetSize = checked.count(
false);
388 Info<<
"*** Problem: IDs not set: " << unsetSize <<
endl;
401 for (
const treeBoundBox& bb : boundBoxes_)
412 for (
const treeBoundBox& bb : boundBoxes_)
427 for (
const treeBoundBox& bb : boundBoxes_)
429 if (bb.overlaps(bbIn))
454 is >>
tree.boundBoxes_ >>
tree.addressing_;
static scalar tolerance_
Relative tolerance.
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).
const List< labelList > & addressing() const noexcept
Return the contents addressing.
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.
bool overlaps(const boundBox &bbIn) const
Determine whether a bounding box overlaps the tree bounding boxes.
label minLeafSize_
Minimum points per leaf.
AABBTree()
Default construct.
const List< treeBoundBox > & boundBoxes() const noexcept
Return the bounding boxes making up the tree.
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.
label maxLevel_
Maximum tree level.
bool pointInside(const point &pt) const
Determine whether a point is inside the bounding boxes.
List< labelList > addressing_
Leaf addressing.
List< treeBoundBox > boundBoxes_
Bounding boxes making up the tree.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
T & emplace_back(Args &&... args)
Construct an element at the end of the list, return reference to the new list element.
void push_back(const T &val)
Copy append an element to the end of this list.
DynamicList< T, SizeMin > & shrink()
Calls shrink_to_fit() and returns a reference to the DynamicList.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void push_back(const T &val)
Append an element at the end of the list.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
An ordered pair of two objects of type <T> with first() and second() elements.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
bool empty() const noexcept
True if List is empty (ie, size() is zero).
void size(const label n)
Older name for setAddressableSize.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
unsigned int count(const bool on=true) const
Count number of bits set.
void set(const bitSet &bitset)
Set specified bits from another bitset.
A bounding box defined in terms of min/max extrema points.
const point & min() const noexcept
Minimum describing the bounding box.
void add(const boundBox &bb)
Extend to include the second box.
direction maxDir() const
Direction (X/Y/Z) of the largest span (for empty box: 0).
void inflate(const scalar factor)
Expand box by factor*mag(span) in all dimensions.
vector span() const
The bounding box span (from minimum to maximum).
Standard boundBox with extra functionality for use in octree.
OBJstream os(runTime.globalPath()/outputName)
Pair< label > labelPair
A pair of labels.
List< label > labelList
A List of labels.
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Istream & operator>>(Istream &, directionInfo &)
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
void sort(UList< T > &list)
Sort the list.
vector point
Point is a vector.
vectorField pointField
pointField is a vectorField.
UList< label > labelUList
A UList of labels.
Tree tree(triangles.begin(), triangles.end())
#define forAll(list, i)
Loop across all elements in list.