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,
89 const treeBoundBox& bb,
92 DynamicList<Pair<treeBoundBox>>& bbs,
93 DynamicList<labelPair>& nodes,
94 DynamicList<labelList>& addressing
100 const scalar maxSpan = bb.span()[maxDir];
108 bitSet isUsedPoint(
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))
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),
307 DynamicList<Pair<treeBoundBox>> bbs(maxLevel);
308 DynamicList<labelPair> nodes(maxLevel);
309 DynamicList<labelList> addr(maxLevel);
311 nodes.emplace_back(-1, -1);
312 treeBoundBox topBb(
points);
352 DynamicList<treeBoundBox>
boundBoxes(2*bbs.size());
353 DynamicList<labelList>
addressing(2*addr.size());
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_;
List< labelList > addressing_
Leaf addressing.
void size(const label n)
Older name for setAddressableSize.
bool overlaps(const boundBox &bbIn) const
Determine whether a bounding box overlaps the tree bounding boxes.
List< treeBoundBox > boundBoxes_
Bounding boxes making up the tree.
bool pointInside(const point &pt) const
Determine whether a point is inside the bounding boxes.
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
static void writeOBJ(Ostream &os, const treeBoundBox &bb, label &vertIndex, const bool writeLinesOnly=false)
Write treeBoundBox in OBJ format.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Ostream & endl(Ostream &os)
Add newline and flush stream.
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.
void push_back(const T &val)
Append an element at the end of the list.
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.
UList< label > labelUList
A UList of labels.
#define forAll(list, i)
Loop across all elements in list.
vectorField pointField
pointField is a vectorField.
An ordered pair of two objects of type <T> with first() and second() elements.
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.
Istream & operator>>(Istream &, directionInfo &)
Tree tree(triangles.begin(), triangles.end())
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Pair< label > labelPair
A pair of labels.
OBJstream os(runTime.globalPath()/outputName)
AABBTree()
Default construct.
vector point
Point is a vector.
Standard boundBox with extra functionality for use in octree.
messageStream Info
Information stream (stdout output on master, null elsewhere)
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)
const List< labelList > & addressing() const noexcept
Return the contents addressing.
const List< treeBoundBox > & boundBoxes() const noexcept
Return the bounding boxes making up the tree.