BUG: avoid infinite recursion in AABBTree (fixes #2616)
- since bounding boxes overlap, need to verify the splitting actually did something. Problem only really evident with higher tree depths.
This commit is contained in:
parent
ffbad65538
commit
fc0b980333
3
applications/test/surfaceTree/Make/files
Normal file
3
applications/test/surfaceTree/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-surfaceTree.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-surfaceTree
|
9
applications/test/surfaceTree/Make/options
Normal file
9
applications/test/surfaceTree/Make/options
Normal file
@ -0,0 +1,9 @@
|
||||
EXE_INC = \
|
||||
-I$(LIB_SRC)/fileFormats/lnInclude \
|
||||
-I$(LIB_SRC)/surfMesh/lnInclude \
|
||||
-I$(LIB_SRC)/meshTools/lnInclude
|
||||
|
||||
EXE_LIBS = \
|
||||
-lfileFormats \
|
||||
-lsurfMesh \
|
||||
-lmeshTools
|
157
applications/test/surfaceTree/Test-surfaceTree.C
Normal file
157
applications/test/surfaceTree/Test-surfaceTree.C
Normal file
@ -0,0 +1,157 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
Test-surfaceTree
|
||||
|
||||
Description
|
||||
Simple tests for building indexedOctree etc.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
#include "clockTime.H"
|
||||
#include "MeshedSurfaces.H"
|
||||
#include "indexedOctree.H"
|
||||
#include "AABBTree.H"
|
||||
#include "treeDataPrimitivePatch.H"
|
||||
#include "Random.H"
|
||||
#include "ListListOps.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::addNote
|
||||
(
|
||||
"Test octree building etc"
|
||||
);
|
||||
|
||||
argList::noBanner();
|
||||
argList::noParallel();
|
||||
argList::addArgument("input", "The input surface file");
|
||||
|
||||
argList::addOption("maxLevel", "int", "The max level");
|
||||
argList::addOption("leafSize", "int", "The min leaf size");
|
||||
argList::addBoolOption("AABB", "AABBTree instead of indexedOctree");
|
||||
|
||||
argList args(argc, argv);
|
||||
|
||||
const auto importName = args.get<fileName>(1);
|
||||
|
||||
const bool useAABB = args.found("AABB");
|
||||
|
||||
label maxLevel = 10;
|
||||
label leafSize = 10;
|
||||
|
||||
if (useAABB)
|
||||
{
|
||||
// May want different settings..
|
||||
}
|
||||
|
||||
args.readIfPresent("maxLevel", maxLevel);
|
||||
args.readIfPresent("leafSize", leafSize);
|
||||
|
||||
meshedSurface surf(importName);
|
||||
|
||||
Random rndGen(123456);
|
||||
|
||||
treeBoundBox overallBb
|
||||
(
|
||||
treeBoundBox(surf.box()).extend(rndGen, 1e-4, ROOTVSMALL)
|
||||
);
|
||||
|
||||
Info<< "Surface with " << surf.size() << " faces, "
|
||||
<< surf.nPoints() << " points" << endl;
|
||||
|
||||
|
||||
clockTime timing;
|
||||
|
||||
if (useAABB)
|
||||
{
|
||||
AABBTree<face> tree
|
||||
(
|
||||
surf,
|
||||
surf.points(),
|
||||
true, // Equal bins
|
||||
maxLevel, // maxLevel
|
||||
leafSize // minLeafSize
|
||||
);
|
||||
|
||||
Info<< "Built AABBTree, maxLevel:" << maxLevel
|
||||
<< " minLeaf:" << leafSize
|
||||
<< " with " << tree.boundBoxes().size()
|
||||
<< " leaves - " << timing.elapsedTime() << 's' << endl;
|
||||
|
||||
{
|
||||
OFstream os("AABBTree.obj");
|
||||
tree.writeOBJ(os);
|
||||
|
||||
Info<< "Wrote " << os.name() << endl;
|
||||
}
|
||||
|
||||
// Info<< "sizes: ";
|
||||
// ListListOps::subSizes
|
||||
// (
|
||||
// tree.addressing(),
|
||||
// identityOp{}
|
||||
// ).writeList(Info) << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
indexedOctree<treeDataPrimitivePatch<meshedSurface>> tree
|
||||
(
|
||||
treeDataPrimitivePatch<meshedSurface>(surf, 1e-6),
|
||||
overallBb,
|
||||
maxLevel, // maxLevel
|
||||
leafSize, // leafSize
|
||||
3.0 // duplicity
|
||||
);
|
||||
|
||||
Info<< "Built octree, maxLevel:" << maxLevel
|
||||
<< " minLeaf:" << leafSize
|
||||
<< " with " << tree.nodes().size()
|
||||
<< " nodes, " << tree.nLeafs()
|
||||
<< " leaves - " << timing.elapsedTime() << 's' << endl;
|
||||
|
||||
{
|
||||
OFstream os("indexedOctree.obj");
|
||||
tree.writeOBJ(os);
|
||||
|
||||
Info<< "Wrote " << os.name() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Info<< "\nEnd\n" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
@ -141,39 +141,36 @@ void Foam::AABBTree<Type>::createBoxes
|
||||
// Assign the objects to min or max bin
|
||||
|
||||
DynamicList<label> minBinObjectIDs(objectIDs.size());
|
||||
treeBoundBox minBb;
|
||||
|
||||
DynamicList<label> maxBinObjectIDs(objectIDs.size());
|
||||
|
||||
treeBoundBox minBb;
|
||||
treeBoundBox maxBb;
|
||||
|
||||
for (const label objI : objectIDs)
|
||||
{
|
||||
const Type& obj = objects[objI];
|
||||
|
||||
bool intoMin = false;
|
||||
bool intoMax = false;
|
||||
bool addMin = false;
|
||||
bool addMax = false;
|
||||
|
||||
for (const label pointI : obj)
|
||||
for (const label pointi : obj)
|
||||
{
|
||||
const point& pt = points[pointI];
|
||||
if (pt[maxDir] < divMin)
|
||||
{
|
||||
intoMin = true;
|
||||
}
|
||||
if (pt[maxDir] > divMax)
|
||||
{
|
||||
intoMax = true;
|
||||
}
|
||||
const scalar& cmptValue = points[pointi][maxDir];
|
||||
|
||||
addMin = addMin || (cmptValue < divMin);
|
||||
addMax = addMax || (cmptValue > divMax);
|
||||
|
||||
if (addMin && addMax) break;
|
||||
}
|
||||
|
||||
// Note: object is inserted into both min/max child boxes (duplicated)
|
||||
// if it crosses the bin boundaries
|
||||
if (intoMin)
|
||||
if (addMin)
|
||||
{
|
||||
minBinObjectIDs.append(objI);
|
||||
minBb.add(points, obj);
|
||||
}
|
||||
if (intoMax)
|
||||
if (addMax)
|
||||
{
|
||||
maxBinObjectIDs.append(objI);
|
||||
maxBb.add(points, obj);
|
||||
@ -193,9 +190,22 @@ void Foam::AABBTree<Type>::createBoxes
|
||||
minBinObjectIDs.shrink();
|
||||
maxBinObjectIDs.shrink();
|
||||
|
||||
bool addMin = (minBinObjectIDs.size() > minLeafSize_ && level < maxLevel_);
|
||||
bool addMax = (maxBinObjectIDs.size() > minLeafSize_ && level < maxLevel_);
|
||||
|
||||
// Since bounding boxes overlap, verify that splitting was effective
|
||||
|
||||
if
|
||||
(
|
||||
objectIDs.size() <= (minBinObjectIDs.size() + minLeafSize_/2)
|
||||
|| objectIDs.size() <= (maxBinObjectIDs.size() + minLeafSize_/2)
|
||||
)
|
||||
{
|
||||
addMin = addMax = false;
|
||||
}
|
||||
|
||||
label minI;
|
||||
if (minBinObjectIDs.size() > minLeafSize_ && level < maxLevel_)
|
||||
if (addMin)
|
||||
{
|
||||
// New leaf
|
||||
minI = nodes.size();
|
||||
@ -209,7 +219,7 @@ void Foam::AABBTree<Type>::createBoxes
|
||||
}
|
||||
|
||||
label maxI;
|
||||
if (maxBinObjectIDs.size() > minLeafSize_ && level < maxLevel_)
|
||||
if (addMax)
|
||||
{
|
||||
// New leaf
|
||||
maxI = nodes.size();
|
||||
|
Loading…
Reference in New Issue
Block a user