Merge branch 'feature-updated-core' into 'develop'

Feature updated core

See merge request Development/openfoam!573
This commit is contained in:
Andrew Heather
2022-11-24 12:21:37 +00:00
326 changed files with 8319 additions and 5892 deletions

View File

@ -88,7 +88,7 @@ int main(int argc, char *argv[])
while (buf1.size() > 2)
{
(void) buf1.pop_front();
buf1.pop_front();
}
report(buf1);
@ -123,6 +123,8 @@ int main(int argc, char *argv[])
Info<< endl;
}
Info<< nl << "list: " << flatOutput(buf2.list()) << nl;
Info<< "normal: " << flatOutput(buf2) << nl;
buf2.reverse();
Info<< "reverse: " << flatOutput(buf2) << nl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -152,15 +152,15 @@ int main(int argc, char *argv[])
Info<< " => " << flatOutput(myList) << nl;
{
myList.swapUp(myList.DLListBase::first());
myList.swapUp(myList.DLListBase::last());
myList.swapUp(myList.DLListBase::front());
myList.swapUp(myList.DLListBase::back());
Info<< nl << "swapUp => " << flatOutput(myList) << nl;
}
{
myList.swapDown(myList.DLListBase::first());
myList.swapDown(myList.DLListBase::last());
myList.swapDown(myList.DLListBase::front());
myList.swapDown(myList.DLListBase::back());
Info<< nl << "swapDown => " << flatOutput(myList) << nl;
}

View File

@ -189,6 +189,12 @@ int main(int argc, char *argv[])
<< " hash:" << FixedList<label, 4>::hasher()(list1) << nl
<< " hash:" << Hash<FixedList<label, 4>>()(list1) << nl;
Info<< "get<0>: " << list1.get<0>() << nl;
Info<< "get<1>: " << list1.get<1>() << nl;
Info<< "get<2>: " << list1.get<2>() << nl;
Info<< "get<3>: " << list1.get<3>() << nl;
// Will not compile: Info<< "get<4>: " << list1.get<4>() << nl;
label a[4] = {0, 1, 2, 3};
FixedList<label, 4> list2(a);

View File

@ -101,6 +101,9 @@ int main(int argc, char *argv[])
printInfo(idl1);
Info<< "list() = ";
idl1.list().writeList(Info, 0) << endl;
for (const label val : { 10, 30, 40, 50, 90, 80, 120 } )
{
testFind(val, idl1);

View File

@ -108,7 +108,7 @@ Ostream& printAddr
for (label i=0; i < len; ++i)
{
os << "addr=" << name(list(i)) << nl;
os << "addr=" << Foam::name(list.get(i)) << nl;
}
// End delimiter
@ -140,7 +140,7 @@ Ostream& print
for (label i=0; i < len; ++i)
{
const T* ptr = list(i);
const T* ptr = list.get(i);
if (ptr)
{
@ -174,7 +174,7 @@ Ostream& print
for (label i=0; i < len; ++i)
{
const T* ptr = list(i);
const T* ptr = list.get(i);
if (ptr)
{
@ -192,7 +192,7 @@ Ostream& print
for (label i=len; i < cap; ++i)
{
const T* ptr = list(i);
const T* ptr = list.get(i);
os << "unused " << name(ptr) << nl;
}
@ -274,9 +274,9 @@ int main(int argc, char *argv[])
{
DLPtrList<Scalar> llist1;
llist1.prepend(new Scalar(100));
llist1.prepend(new Scalar(200));
llist1.prepend(new Scalar(300));
llist1.push_front(new Scalar(100));
llist1.push_front(new Scalar(200));
llist1.push_front(new Scalar(300));
auto citer = llist1.begin();
@ -305,9 +305,9 @@ int main(int argc, char *argv[])
// Same but as SLPtrList
{
SLPtrList<Scalar> llist1;
llist1.prepend(new Scalar(100));
llist1.prepend(new Scalar(200));
llist1.prepend(new Scalar(300));
llist1.push_front(new Scalar(100));
llist1.push_front(new Scalar(200));
llist1.push_front(new Scalar(300));
for (const auto& it : llist1)
{
@ -334,7 +334,7 @@ int main(int argc, char *argv[])
{
listApp.append(new Scalar(1.3*i));
}
listApp.emplace_append(100);
listApp.emplace_back(100);
Info<< nl
@ -580,8 +580,8 @@ int main(int argc, char *argv[])
}
PtrList<plane> planes;
planes.emplace_append(vector::one, vector::one);
planes.emplace_append(vector(1,2,3), vector::one);
planes.emplace_back(vector::one, vector::one);
planes.emplace_back(vector(1,2,3), vector::one);
Info<< nl << "appended values" << nl;
for (const plane& p : planes)
@ -594,15 +594,15 @@ int main(int argc, char *argv[])
PtrDynList<plane> dynPlanes;
{
dynPlanes.emplace_append(vector::one, vector::one);
dynPlanes.emplace_append(vector(1,2,3), vector::one);
dynPlanes.emplace_back(vector::one, vector::one);
dynPlanes.emplace_back(vector(1,2,3), vector::one);
dynPlanes.append(nullptr);
dynPlanes.set(6, new plane(vector(2,2,1), vector::one));
dynPlanes.set(10, new plane(vector(4,5,6), vector::one));
dynPlanes.emplace(12, vector(3,2,1), vector::one);
dynPlanes.emplace_append(Zero, vector::one);
dynPlanes.emplace_back(Zero, vector::one);
}
Info<< nl << "PtrDynList: ";
@ -633,7 +633,7 @@ int main(int argc, char *argv[])
forAll(dynPlanes, i)
{
const plane* pln = dynPlanes.set(i);
const plane* pln = dynPlanes.get(i);
if (pln)
{
stdPlanes.set(i, new plane(*pln));

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -43,7 +43,7 @@ void print(const boolVector& v)
<< " any:" << Switch::name(v.any())
<< " all:" << Switch::name(v.all())
<< " none:" << Switch::name(v.none())
<< " count:" << v.count() << nl;
<< " on:" << v.count() << " off:" << v.count(false) << nl;
}
@ -68,7 +68,7 @@ int main(int argc, char *argv[])
Info<< nl;
{
boolVector vec{1, 0, 1};
boolVector vec(1, 0, 1);
print(vec);
vec.flip();

View File

@ -34,7 +34,6 @@ Description
#include "line.H"
#include "Random.H"
#include "treeBoundBox.H"
#include "cellModel.H"
#include "bitSet.H"
#include "HashSet.H"
#include "ListOps.H"
@ -59,8 +58,7 @@ int main(int argc, char *argv[])
{
#include "setRootCase.H"
Info<<"boundBox faces: " << boundBox::faces << nl
<<"hex faces: " << cellModel::ref(cellModel::HEX).modelFaces() << nl
Info<<"boundBox faces: " << boundBox::hexFaces() << nl
<<"tree-bb faces: " << treeBoundBox::faces << nl
<<"tree-bb edges: " << treeBoundBox::edges << endl;
@ -113,10 +111,8 @@ int main(int argc, char *argv[])
Info<<"enclose point " << pt << " -> " << bb << endl;
// restart with same points
bb = boundBox::invertedBox;
bb.add(point(1,1,1));
bb.add(point::zero);
bb.add(point(0,1.5,0.5));
bb.reset(point::zero);
bb.add(point(1,1,1), point(0,1.5,0.5));
bb.add(point(5,2,-2));
Info<<"repeated " << bb << endl;

View File

@ -0,0 +1,3 @@
Test-boundBox2.C
EXE = $(FOAM_USER_APPBIN)/Test-boundBox2

View File

@ -0,0 +1,2 @@
/* EXE_INC = */
/* EXE_LIBS = */

View File

@ -0,0 +1,235 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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/>.
Description
Test bounding box behaviour
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "polyMesh.H"
#include "line.H"
#include "Random.H"
#include "treeBoundBox.H"
#include "bitSet.H"
#include "HashSet.H"
#include "ListOps.H"
using namespace Foam;
//- simple helper to create a cube, given lower corner and width
boundBox cube(scalar start, scalar width)
{
return boundBox
(
point::uniform(start),
point::uniform(start + width)
);
}
//- simple helper to create a cube, given mid-point and width
boundBox cubeAt(const point& mid, scalar width)
{
boundBox bb(mid);
bb.grow(0.5*width);
return bb;
}
word faceName(direction whichFace)
{
switch (whichFace)
{
case treeBoundBox::LEFT : return "-x";
case treeBoundBox::RIGHT : return "+x";
case treeBoundBox::BOTTOM : return "-y";
case treeBoundBox::TOP : return "+y";
case treeBoundBox::BACK : return "-z";
case treeBoundBox::FRONT : return "+z";
}
return "??";
}
word octantName(direction octant)
{
word str("-x-y-z");
if (octant & treeBoundBox::RIGHTHALF)
{
str[0] = '+';
}
if (octant & treeBoundBox::TOPHALF)
{
str[2] = '+';
}
if (octant & treeBoundBox::FRONTHALF)
{
str[4] = '+';
}
return str;
}
void testOverlaps(const treeBoundBox& bb, const treeBoundBox& searchBox)
{
FixedList<bool, 8> overlaps;
for (direction octant = 0; octant < 8; ++octant)
{
overlaps[octant] = bb.subOverlaps(octant, searchBox);
}
Info<< "box " << bb << " and " << searchBox << nl;
Info<< "overlaps any:" << bb.overlaps(searchBox)
<< " octants: " << overlaps << nl;
}
void testOverlaps
(
const treeBoundBox& bb,
const point& sample,
const scalar nearestDistSqr
)
{
FixedList<bool, 8> overlaps;
for (direction octant = 0; octant < 8; ++octant)
{
overlaps[octant] = bb.subOverlaps(octant, sample, nearestDistSqr);
}
Info<< "box " << bb << " and "
<< sample << " distSqr:" << nearestDistSqr << nl;
Info<< "overlaps any:" << bb.overlaps(sample, nearestDistSqr)
<< " octants: " << overlaps << nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
#include "setRootCase.H"
treeBoundBox bb(cube(0, 1));
treeBoundBox sub(cube(0.1, 0.8));
Info<< nl
<< "box: " << bb << nl;
Info<< nl;
for (direction octant = 0; octant < 8; ++octant)
{
Info<< "octant:" << octant
<< " (" << octantName(octant) << ") = "
<< bb.subBbox(octant) << nl;
}
Info<< nl;
for (direction facei = 0; facei < 6; ++facei)
{
Info<< "sub-half:" << facei
<< " (" << faceName(facei) << ") = "
<< bb.subHalf(facei) << nl;
}
Info<< nl;
for (direction octant = 0; octant < 8; ++octant)
{
const point pt = sub.corner(octant);
const direction subOctant = bb.subOctant(pt);
Info<< "point:" << pt
<< " in octant " << subOctant
<< " sub-box: " << bb.subBbox(subOctant) << nl;
}
for (const scalar dist : {0.1})
{
Info<< nl;
for (direction octant = 0; octant < 8; ++octant)
{
treeBoundBox searchBox(cubeAt(bb.corner(octant), dist));
testOverlaps(bb, searchBox);
}
Info<< nl;
for (direction facei = 0; facei < 6; ++facei)
{
treeBoundBox searchBox(cubeAt(bb.faceCentre(facei), dist));
testOverlaps(bb, searchBox);
}
}
{
treeBoundBox largerBox(bb);
largerBox.grow(0.2);
// Checking at corners,
// larger by 0.2 in three directions: radius = 0.3464
for (const scalar dist : {0.1, 0.35})
{
const scalar distSqr = sqr(dist);
Info<< nl;
for (direction octant = 0; octant < 8; ++octant)
{
testOverlaps(bb, largerBox.corner(octant), distSqr);
}
}
// Checking at face centres,
// larger by 0.2 in a single direction
for (const scalar dist : {0.1, 0.25})
{
const scalar distSqr = sqr(dist);
Info<< nl;
for (direction facei = 0; facei < 6; ++facei)
{
testOverlaps(bb, largerBox.faceCentre(facei), distSqr);
}
}
}
Info<< nl << "End" << nl << endl;
return 0;
}
// ************************************************************************* //

View File

@ -67,7 +67,7 @@ int main(int argc, char *argv[])
Info<<"collapse? -> " << e4.collapse() << endl;
printInfo(e4);
Info<< e3 << " connects " << e2 << " => " << e2.connects(e3) << endl;
Info<< e3 << " connects " << e2 << " => " << e2.connected(e3) << endl;
labelPair labels(e3);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -33,6 +33,7 @@ Description
#include "argList.H"
#include "labelledTri.H"
#include "edge.H"
#include "faceList.H"
#include "triFaceList.H"
#include "pointList.H"
@ -131,10 +132,25 @@ int main(int argc, char *argv[])
testSign(f1, points2, testPoints);
Info<< nl;
triFace t1({1, 2, 3});
// Initializer list
// triFace t1({1, 2, 3});
// Component-wise
{
edge e1(3, 2, 1); // Inadvertent sort!!!
Info<< "edge:" << e1 << nl;
}
// Component-wise
triFace t1(1, 2, 3);
Info<< "triFace:"; faceInfo(t1, points1); Info << nl;
testSign(t1, points1, testPoints);
{
scalarField fld({0, 20, 20, 30});
Info<< "avg:" << t1.average(pointField::null(), fld) << nl;
}
Info<< "triFace:"; faceInfo(t1, points2); Info << nl;
testSign(t1, points2, testPoints);
Info<< nl;

View File

@ -53,20 +53,17 @@ int main(int argc, char *argv[])
const polyMesh::cellDecomposition decompMode = polyMesh::CELL_TETS;
treeBoundBox meshBb(mesh.bounds());
treeBoundBox shiftedBb(meshBb);
// Calculate typical cell related size to shift bb by.
scalar typDim = meshBb.avgDim()/(2.0*Foam::cbrt(scalar(mesh.nCells())));
treeBoundBox shiftedBb
(
meshBb.min(),
meshBb.max() + vector(typDim, typDim, typDim)
);
shiftedBb.max() += vector::uniform(typDim);
Info<< "Mesh" << endl;
Info<< " bounding box : " << meshBb << endl;
Info<< " bounding box (shifted) : " << shiftedBb << endl;
Info<< " typical dimension : " << shiftedBb.typDim() << endl;
Info<< " typical dimension : " << shiftedBb.avgDim() << endl;
Info<< "Initialised mesh in "
<< runTime.cpuTimeIncrement() << " s" << endl;

View File

@ -67,17 +67,10 @@ int main(int argc, char *argv[])
treeBoundBox bb(efem.points());
bb.grow(ROOTVSMALL);
labelList allEdges(identity(efem.edges().size()));
indexedOctree<treeDataEdge> edgeTree
(
treeDataEdge
(
false, // cachebb
efem.edges(), // edges
efem.points(), // points
allEdges // selected edges
),
treeDataEdge(efem.edges(), efem.points()), // All edges
bb, // bb
8, // maxLevel
10, // leafsize

View File

@ -0,0 +1,3 @@
Test-surfaceTree.C
EXE = $(FOAM_USER_APPBIN)/Test-surfaceTree

View 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

View 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;
}
// ************************************************************************* //

View File

@ -1,3 +1,4 @@
#include "argList.H"
#include "point.H"
#include "triangle.H"
#include "tetrahedron.H"
@ -5,7 +6,7 @@
using namespace Foam;
int main()
int main(int argc, char *argv[])
{
triangle<point, point> tri
(
@ -14,6 +15,12 @@ int main()
vector(1, 1, 0)
);
Info<< "triangle: " << tri << nl
<< " vecA: " << tri.vecA() << nl
<< " vecB: " << tri.vecB() << nl
<< " vecC: " << tri.vecC() << nl
<< endl;
Info<< "tri circumCentre = " << tri.circumCentre() << endl;
Info<< "tri circumRadius = " << tri.circumRadius() << endl;
@ -28,6 +35,8 @@ int main()
Info<< "tet circumCentre = " << tet.circumCentre() << endl;
Info<< "tet circumRadius = " << tet.circumRadius() << endl;
InfoErr<< "Enter four points: " << endl;
vector a(Sin);
vector b(Sin);
vector c(Sin);
@ -36,5 +45,6 @@ int main()
Info<< "tet circumRadius = "
<< tetrahedron<point, point>(a, b, c, d).circumRadius() << endl;
Info<< "\nEnd\n";
return 0;
}

View File

@ -0,0 +1,3 @@
Test-triangleIntersection.C
EXE = $(FOAM_USER_APPBIN)/Test-triangleIntersection

View File

@ -0,0 +1,5 @@
EXE_INC = \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-lmeshTools

View File

@ -0,0 +1,142 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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/>.
Description
Test bounding box / triangle intersection
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "line.H"
#include "Random.H"
#include "triangle.H"
#include "triangleFuncs.H"
#include "treeBoundBox.H"
#include "ListOps.H"
using namespace Foam;
//- simple helper to create a cube
boundBox cube(scalar start, scalar width)
{
return boundBox
(
point::uniform(start),
point::uniform(start + width)
);
}
void printEdges(const treeBoundBox& bb)
{
pointField pts(bb.points());
for (const edge& e : treeBoundBox::edges)
{
Info<< pts[e.first()] << " -> " << pts[e.second()] << nl;
}
}
void testIntersect(const treeBoundBox& bb, const triPoints& tri)
{
int ninside = 0;
if (bb.contains(tri.a())) ++ninside;
if (bb.contains(tri.b())) ++ninside;
if (bb.contains(tri.c())) ++ninside;
Info<< "box: " << bb << endl;
Info<< "tri: " << tri << endl;
Info<< "num inside: " << ninside << nl;
Info<< "intersects: " << bb.intersects(tri.tri())
<< ' ' << triangleFuncs::intersectBb(tri.tri(), bb) << nl << endl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList args(argc, argv);
// Info<<"tree-bb faces: " << treeBoundBox::faces << nl
// <<"tree-bb edges: " << treeBoundBox::edges << endl;
treeBoundBox bb;
bb = cube(0, 1);
triPoints tri;
tri.a() = point(-0.1, 0.5, 0.5);
tri.b() = point(0.1, 0.6, 0.5);
tri.c() = point(0.2, 0.4, 0.5);
testIntersect(bb, tri);
tri.a().z() = 1.1;
tri.b().z() = 1.1;
tri.c().z() = 1.1;
testIntersect(bb, tri);
tri.a().z() = 1 + 1e-15;
tri.b().z() = 1 + 1e-15;
tri.c().z() = 1 + 1e-15;
testIntersect(bb, tri);
tri.a() = point(-1, -1, -1);
tri.b() = point(2, 2, -2);
tri.c() = point(0, 0, 2);
testIntersect(bb, tri);
tri.a() = point(0.9, 1.1, 0);
tri.b() = point(1.1, 0.9, 0);
tri.c() = point(1, 1, 1.1);
testIntersect(bb, tri);
tri.a() = point(-1e-3, 1e-3, -1);
tri.b() = point( 1e-3, -1e-3, -1);
tri.c() = point(0, 0, 2);
testIntersect(bb, tri);
tri.a() = point(-1e-3, 1e-3, -1);
tri.b() = point( 1e-3, -1e-3, -1);
tri.c() = point(-1e-4, -1e-4, 2);
testIntersect(bb, tri);
return 0;
}
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -88,7 +88,7 @@ label findPoint(const primitivePatch& pp, const point& nearPoint)
for (const label pointi : meshPoints)
{
scalar distSqr = magSqr(nearPoint - points[pointi]);
scalar distSqr = nearPoint.distSqr(points[pointi]);
if (distSqr < minDistSqr)
{
@ -288,7 +288,7 @@ label findCell(const primitiveMesh& mesh, const point& nearPoint)
if (celli != -1)
{
scalar distToCcSqr = magSqr(nearPoint - mesh.cellCentres()[celli]);
scalar distToCcSqr = nearPoint.distSqr(mesh.cellCentres()[celli]);
const labelList& cPoints = mesh.cellPoints()[celli];
@ -297,7 +297,7 @@ label findCell(const primitiveMesh& mesh, const point& nearPoint)
for (const label pointi : cPoints)
{
scalar distSqr = magSqr(nearPoint - mesh.points()[pointi]);
scalar distSqr = nearPoint.distSqr(mesh.points()[pointi]);
if (distSqr < minDistSqr)
{

View File

@ -293,7 +293,7 @@ bool Foam::fileFormats::ensightMeshReader::readGoldPart
elemIdToCells
);
const auto& model = *cellModel::ptr(cellModel::TET);
const auto& model = cellModel::ref(cellModel::TET);
for (label shapei = 0; shapei < nShapes; shapei++)
{
readVerts(is, 4, nodeIdToPoints, verts);
@ -326,7 +326,7 @@ bool Foam::fileFormats::ensightMeshReader::readGoldPart
elemIdToCells
);
const auto& model = *cellModel::ptr(cellModel::PYR);
const auto& model = cellModel::ref(cellModel::PYR);
for (label shapei = 0; shapei < nShapes; shapei++)
{
readVerts(is, 5, nodeIdToPoints, verts);
@ -359,7 +359,7 @@ bool Foam::fileFormats::ensightMeshReader::readGoldPart
elemIdToCells
);
const auto& model = *cellModel::ptr(cellModel::PRISM);
const auto& model = cellModel::ref(cellModel::PRISM);
for (label shapei = 0; shapei < nShapes; shapei++)
{
readVerts(is, 6, nodeIdToPoints, verts);
@ -392,7 +392,7 @@ bool Foam::fileFormats::ensightMeshReader::readGoldPart
elemIdToCells
);
const auto& model = *cellModel::ptr(cellModel::HEX);
const auto& model = cellModel::ref(cellModel::HEX);
for (label shapei = 0; shapei < nShapes; shapei++)
{
readVerts(is, 8, nodeIdToPoints, verts);

View File

@ -890,11 +890,10 @@ int main(int argc, char *argv[])
const boundBox& bb = mesh.bounds();
const vector span = bb.span();
const scalar mergeDim = mergeTol * bb.minDim();
Info<< "Mesh bounding box : " << bb << nl
<< " with span : " << span << nl
<< " with span : " << bb.span() << nl
<< "Merge distance : " << mergeDim << nl
<< endl;

View File

@ -869,9 +869,7 @@ Foam::DistributedDelaunayMesh<Triangulation>::rangeInsertReferredWithInfo
if (!bb.contains(samplePoint))
{
const Foam::point nearestPoint = bb.nearest(samplePoint);
distFromBbSqr = magSqr(nearestPoint - samplePoint);
distFromBbSqr = bb.nearest(samplePoint).distSqr(samplePoint);
}
pointsBbDistSqr.append

View File

@ -167,7 +167,7 @@ void Foam::backgroundMeshDecomposition::initialRefinement()
{
if (volumeStatus[celli] == volumeType::UNKNOWN)
{
treeBoundBox cellBb(mesh_.cells()[celli].box(mesh_));
treeBoundBox cellBb(mesh_.cellBb(celli));
if (geometry.overlaps(cellBb))
{
@ -279,7 +279,7 @@ void Foam::backgroundMeshDecomposition::initialRefinement()
{
if (volumeStatus[celli] == volumeType::UNKNOWN)
{
treeBoundBox cellBb(mesh_.cells()[celli].box(mesh_));
treeBoundBox cellBb(mesh_.cellBb(celli));
if (geometry.overlaps(cellBb))
{
@ -498,7 +498,7 @@ bool Foam::backgroundMeshDecomposition::refineCell
// const conformationSurfaces& geometry = geometryToConformTo_;
treeBoundBox cellBb(mesh_.cells()[celli].box(mesh_));
treeBoundBox cellBb(mesh_.cellBb(celli));
weightEstimate = 1.0;
@ -577,7 +577,7 @@ bool Foam::backgroundMeshDecomposition::refineCell
// // weightEstimate += sampleVol/pow3(s);
// }
//
// if (sqr(spanScale_)*sqr(minCellSize) < magSqr(cellBb.span()))
// if (sqr(spanScale_)*sqr(minCellSize) < cellBb.magSqr())
// {
// return true;
// }
@ -695,7 +695,7 @@ void Foam::backgroundMeshDecomposition::buildPatchAndTree()
Pstream::allGatherList(allBackgroundMeshBounds_);
// find global bounding box
globalBackgroundBounds_ = treeBoundBox(boundBox::invertedBox);
globalBackgroundBounds_.reset();
forAll(allBackgroundMeshBounds_, proci)
{
globalBackgroundBounds_.add(allBackgroundMeshBounds_[proci]);
@ -1119,10 +1119,7 @@ Foam::labelList Foam::backgroundMeshDecomposition::processorNearestPosition
if (info.hit())
{
distanceSqrToCandidate[tPI] = magSqr
(
testPoints[tPI] - info.hitPoint()
);
distanceSqrToCandidate[tPI] = info.point().distSqr(testPoints[tPI]);
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -132,10 +132,7 @@ Foam::word Foam::cellShapeControlMesh::meshSubDir = "cellShapeControlMesh";
//
// if (spokeHit.hit())
// {
// scalar spokeHitDistance = mag
// (
// spokeHit.hitPoint() - pt
// );
// scalar spokeHitDistance = spokeHit.point().dist(pt);
//
// if (spokeHitDistance < closestSpokeHitDistance)
// {
@ -159,10 +156,7 @@ Foam::word Foam::cellShapeControlMesh::meshSubDir = "cellShapeControlMesh";
//
// if (spokeHit.hit())
// {
// scalar spokeHitDistance = mag
// (
// spokeHit.hitPoint() - mirrorPt
// );
// scalar spokeHitDistance = spokeHit.point().dist(mirrorPt);
//
// if (spokeHitDistance < closestSpokeHitDistance)
// {
@ -202,10 +196,10 @@ Foam::word Foam::cellShapeControlMesh::meshSubDir = "cellShapeControlMesh";
// FatalErrorInFunction
// << "Parallel normals detected in spoke search." << nl
// << "point: " << pt << nl
// << "closest surface point: " << surfHit.hitPoint() << nl
// << "closest spoke hit: " << closestSpokeHit.hitPoint() << nl
// << "np: " << surfHit.hitPoint() + np << nl
// << "ns: " << closestSpokeHit.hitPoint() + na << nl
// << "closest surface point: " << surfHit.point() << nl
// << "closest spoke hit: " << closestSpokeHit.point() << nl
// << "np: " << surfHit.point() + np << nl
// << "ns: " << closestSpokeHit.point() + na << nl
// << exit(FatalError);
// }
//

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -439,7 +439,7 @@ void Foam::searchableSurfaceControl::initialVertices
{
// Limit cell size
const vector vN =
infoList[0].hitPoint()
infoList[0].point()
- 2.0*normals[0]*defaultCellSize_;
List<pointIndexHit> intersectionList;
@ -453,8 +453,7 @@ void Foam::searchableSurfaceControl::initialVertices
// if (intersectionList[0].hit())
// {
// scalar dist =
// mag(intersectionList[0].hitPoint() - pts[pI]);
// scalar dist = intersectionList[0].point().dist(pts[pI]);
//
// limitedCellSize = dist/2.0;
// }

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2015 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -739,7 +740,7 @@ Foam::label Foam::controlMeshRefinement::refineMesh
if (hitPt.hit())
{
const Foam::point& pt = hitPt.hitPoint();
const Foam::point& pt = hitPt.point();
if (!geometryToConformTo_.inside(pt))
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2015 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -155,10 +155,10 @@ bool Foam::linearDistance::cellSize(const point& pt, scalar& size) const
if (hitInfo.hit())
{
const point& hitPt = hitInfo.hitPoint();
const point& hitPt = hitInfo.point();
const label hitIndex = hitInfo.index();
const scalar dist = mag(pt - hitPt);
const scalar dist = hitPt.dist(pt);
if (sideMode_ == rmBothsides)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2015 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -206,10 +206,10 @@ bool Foam::surfaceOffsetLinearDistance::cellSize
if (hitInfo.hit())
{
const point& hitPt = hitInfo.hitPoint();
const point& hitPt = hitInfo.point();
const label hitIndex = hitInfo.index();
const scalar dist = mag(pt - hitPt);
const scalar dist = hitPt.dist(pt);
if (sideMode_ == rmBothsides)
{
@ -220,7 +220,7 @@ bool Foam::surfaceOffsetLinearDistance::cellSize
// If the nearest point is essentially on the surface, do not do a
// getVolumeType calculation, as it will be prone to error.
if (mag(pt - hitInfo.hitPoint()) < snapToSurfaceTol_)
if (hitInfo.point().dist(pt) < snapToSurfaceTol_)
{
size = sizeFunction(hitPt, 0, hitIndex);

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2015 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -97,7 +98,7 @@ bool uniform::cellSize
if (hitInfo.hit())
{
const point& hitPt = hitInfo.hitPoint();
const point& hitPt = hitInfo.point();
const label index = hitInfo.index();
if (sideMode_ == rmBothsides)

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2015 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -134,7 +134,7 @@ bool Foam::uniformDistance::cellSize
if (hitInfo.hit())
{
const point& hitPt = hitInfo.hitPoint();
const point& hitPt = hitInfo.point();
const label index = hitInfo.index();
if (sideMode_ == rmBothsides)
@ -146,7 +146,7 @@ bool Foam::uniformDistance::cellSize
// If the nearest point is essentially on the surface, do not do a
// getVolumeType calculation, as it will be prone to error.
if (mag(pt - hitInfo.hitPoint()) < snapToSurfaceTol_)
if (hitInfo.point().dist(pt) < snapToSurfaceTol_)
{
size = surfaceCellSizeFunction_().interpolate(hitPt, index);

View File

@ -231,7 +231,7 @@ void Foam::conformalVoronoiMesh::insertSurfacePointPairs
const vector& normal = norm[0];
const Foam::point& surfacePt(surfaceHit.hitPoint());
const Foam::point& surfacePt = surfaceHit.hitPoint();
extendedFeatureEdgeMesh::sideVolumeType meshableSide =
geometryToConformTo_.meshableSide(featureIndex, surfaceHit);

View File

@ -488,7 +488,7 @@ Foam::label Foam::conformalVoronoiMesh::mergeIdenticalDualVertices
////
//// if (surfHit.hit())
//// {
//// pt += (surfHit.hitPoint() - pt)
//// pt += (surfHit.point() - pt)
//// *pow
//// (
//// foamyHexMeshControls()
@ -969,7 +969,7 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::findOffsetPatchFaces
if
(
pHit.hit()
&& (mag(pHit.hitPoint() - faceCentre) > allowedOffset*targetSize)
&& (pHit.point().dist(faceCentre) > allowedOffset*targetSize)
)
{
offsetBoundaryCells.insert(fCell[pLFI]);
@ -1362,10 +1362,10 @@ void Foam::conformalVoronoiMesh::indexDualVertices
if (debug)
{
Info<< "Dual = " << dual << nl
<< " Nearest = " << fpHit.hitPoint() << endl;
<< " Nearest = " << fpHit.point() << endl;
}
pts[cit->cellIndex()] = fpHit.hitPoint();
pts[cit->cellIndex()] = fpHit.point();
}
}
}
@ -1401,7 +1401,7 @@ void Foam::conformalVoronoiMesh::indexDualVertices
// );
//
// pointFromPoint nearestPointOnTet =
// tet.nearestPoint(dual).rawPoint();
// tet.nearestPoint(dual).point();
//
// // Get nearest point on surface from tet.
// geometryToConformTo_.findSurfaceNearest
@ -1440,10 +1440,10 @@ void Foam::conformalVoronoiMesh::indexDualVertices
// snapping2.writeLine
// (
// nearestPointOnTet,
// hitInfo.hitPoint()
// hitInfo.point()
// );
//
// pts[cit->cellIndex()] = hitInfo.hitPoint();
// pts[cit->cellIndex()] = hitInfo.point();
// }
// }
// }

View File

@ -311,7 +311,7 @@ void Foam::conformalVoronoiMesh::buildSurfaceConformation()
)
{
// meshTools::writeOBJ(Pout, vert);
// meshTools::writeOBJ(Pout, surfHit.hitPoint());
// meshTools::writeOBJ(Pout, surfHit.point());
// Pout<< "l cr0 cr1" << endl;
addSurfaceAndEdgeHits
@ -804,7 +804,7 @@ Foam::label Foam::conformalVoronoiMesh::synchroniseEdgeTrees
if (nearest.hit())
{
// Pout<< "Not inserting " << peI << " " << pt << " "
// << nearest.rawPoint() << " on proc " << proci
// << nearest.point() << " on proc " << proci
// << ", near edge = " << nearest
// << " near ftPt = "<< info
// << " " << featureEdgeExclusionDistanceSqr(pt)
@ -1477,9 +1477,9 @@ void Foam::conformalVoronoiMesh::reportProcessorOccupancy()
// << vit->type() << nl
// << vit->ppMaster() << nl
// << "nearFeaturePt "
// << nearFeaturePt(surfHit.hitPoint()) << nl
// << nearFeaturePt(surfHit.point()) << nl
// << vert << nl
// << surfHit.hitPoint()
// << surfHit.point()
// << endl;
// }
// }
@ -1614,7 +1614,7 @@ void Foam::conformalVoronoiMesh::limitDisplacement
{
limit = true;
if (magSqr(pt - surfHit.hitPoint()) <= searchDistanceSqr)
if (surfHit.point().distSqr(pt) <= searchDistanceSqr)
{
// Cannot limit displacement, point closer than tolerance
displacement = Zero;
@ -1711,7 +1711,7 @@ bool Foam::conformalVoronoiMesh::nearSurfacePoint
(
closeToSurfacePt
&& (
magSqr(pt - closePoint.hitPoint())
closePoint.hitPoint().distSqr(pt)
> sqr(pointPairDistance(pt))
)
)
@ -1807,23 +1807,25 @@ Foam::conformalVoronoiMesh::nearestFeatureEdgeLocations
const Foam::point& pt
) const
{
const auto& tree = edgeLocationTreePtr_();
const scalar exclusionRangeSqr = featureEdgeExclusionDistanceSqr(pt);
labelList elems
= edgeLocationTreePtr_().findSphere(pt, exclusionRangeSqr);
labelList elems = tree.findSphere(pt, exclusionRangeSqr);
DynamicList<pointIndexHit> dynPointHit;
DynamicList<pointIndexHit> dynPointHit(elems.size());
forAll(elems, elemI)
for (const label index : elems)
{
label index = elems[elemI];
const Foam::point& pointi
= edgeLocationTreePtr_().shapes().shapePoints()[index];
pointIndexHit nearHit(true, pointi, index);
dynPointHit.append(nearHit);
dynPointHit.append
(
pointIndexHit
(
true,
tree.shapes().centre(index),
index
)
);
}
return dynPointHit;
@ -1965,12 +1967,9 @@ void Foam::conformalVoronoiMesh::buildEdgeLocationTree
{
treeBoundBox overallBb
(
geometryToConformTo_.globalBounds().extend(rndGen_, 1e-4)
geometryToConformTo_.globalBounds().extend(rndGen_, 1e-4, ROOTVSMALL)
);
overallBb.min() -= Foam::point::uniform(ROOTVSMALL);
overallBb.max() += Foam::point::uniform(ROOTVSMALL);
edgeLocationTreePtr_.reset
(
new dynamicIndexedOctree<dynamicTreeDataPoint>
@ -1992,12 +1991,9 @@ void Foam::conformalVoronoiMesh::buildSurfacePtLocationTree
{
treeBoundBox overallBb
(
geometryToConformTo_.globalBounds().extend(rndGen_, 1e-4)
geometryToConformTo_.globalBounds().extend(rndGen_, 1e-4, ROOTVSMALL)
);
overallBb.min() -= Foam::point::uniform(ROOTVSMALL);
overallBb.max() += Foam::point::uniform(ROOTVSMALL);
surfacePtLocationTreePtr_.reset
(
new dynamicIndexedOctree<dynamicTreeDataPoint>
@ -2079,7 +2075,7 @@ void Foam::conformalVoronoiMesh::addSurfaceAndEdgeHits
if (edHit.hit())
{
const Foam::point& edPt = edHit.hitPoint();
const Foam::point& edPt = edHit.point();
if
(
@ -2095,7 +2091,7 @@ void Foam::conformalVoronoiMesh::addSurfaceAndEdgeHits
{
if
(
magSqr(edPt - surfPt)
surfPt.distSqr(edPt)
< surfacePtReplaceDistCoeffSqr*cellSizeSqr
)
{
@ -2141,7 +2137,7 @@ void Foam::conformalVoronoiMesh::addSurfaceAndEdgeHits
surfacePtToEdgePtDist.insert
(
existingEdgeLocations_.size() - 1,
magSqr(edPt - surfPt)
surfPt.distSqr(edPt)
);
}
else if (firstPass)
@ -2152,7 +2148,7 @@ void Foam::conformalVoronoiMesh::addSurfaceAndEdgeHits
if
(
magSqr(edPt - surfPt)
surfPt.distSqr(edPt)
< surfacePtToEdgePtDist[hitIndex]
)
{
@ -2162,7 +2158,7 @@ void Foam::conformalVoronoiMesh::addSurfaceAndEdgeHits
existingEdgeLocations_[hitIndex] =
edHit.hitPoint();
surfacePtToEdgePtDist[hitIndex] =
magSqr(edPt - surfPt);
surfPt.distSqr(edPt);
// Change edge location in featureEdgeHits
// remove index from edge tree

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -564,12 +564,9 @@ Foam::conformationSurfaces::conformationSurfaces
// Extend the global bounds to stop the bound box sitting on the surfaces
// to be conformed to
//globalBounds_ = globalBounds_.extend(rndGen, 1e-4);
//globalBounds_.inflate(rndGen, 1e-4);
vector newSpan = 1e-4*globalBounds_.span();
globalBounds_.min() -= newSpan;
globalBounds_.max() += newSpan;
globalBounds_.grow(1e-4*globalBounds_.span());
// Look at all surfaces at determine whether the locationInMesh point is
// inside or outside each, to establish a signature for the domain to be
@ -746,7 +743,7 @@ Foam::Field<bool> Foam::conformationSurfaces::wellInOutSide
const vector hitDir =
normalised
(
info[0].rawPoint() - samplePts[i]
info[0].point() - samplePts[i]
);
pointIndexHit surfHit;
@ -755,7 +752,7 @@ Foam::Field<bool> Foam::conformationSurfaces::wellInOutSide
findSurfaceNearestIntersection
(
samplePts[i],
info[0].rawPoint() - 1e-3*mag(hitDir)*hitDir,
info[0].point() - 1e-3*mag(hitDir)*hitDir,
surfHit,
hitSurface
);
@ -1057,7 +1054,7 @@ void Foam::conformationSurfaces::findFeaturePointNearest
if (hitInfo.hit())
{
minDistSqr = magSqr(hitInfo.hitPoint()- sample);
minDistSqr = hitInfo.point().distSqr(sample);
fpHit = hitInfo;
featureHit = testI;
}
@ -1123,11 +1120,9 @@ void Foam::conformationSurfaces::findEdgeNearest
{
if (hitInfo[pointi].hit())
{
minDistSqr[pointi] = magSqr
(
hitInfo[pointi].hitPoint()
- samples[pointi]
);
minDistSqr[pointi] =
hitInfo[pointi].point().distSqr(samples[pointi]);
edgeHits[pointi] = hitInfo[pointi];
featuresHit[pointi] = testI;
}
@ -1167,7 +1162,7 @@ void Foam::conformationSurfaces::findEdgeNearestByType
{
if (hitInfo[typeI].hit())
{
minDistSqr[typeI] = magSqr(hitInfo[typeI].hitPoint() - sample);
minDistSqr[typeI] = hitInfo[typeI].point().distSqr(sample);
edgeHits[typeI] = hitInfo[typeI];
featuresHit[typeI] = testI;
}
@ -1207,6 +1202,7 @@ void Foam::conformationSurfaces::findAllNearestEdges
if (hitInfo[hitI].hit())
{
anyHit = true;
break;
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2015 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -238,7 +238,7 @@ Foam::List<Vb::Point> Foam::rayShooting::initialPoints() const
if ((normStart[0] & normEnd[0]) < 0)
{
line<point, point> l(fC, surfHitEnd.hitPoint());
line<point, point> l(fC, surfHitEnd.point());
if (Pstream::parRun())
{
@ -256,7 +256,7 @@ Foam::List<Vb::Point> Foam::rayShooting::initialPoints() const
line<point, point>
(
l.start(),
procIntersection.hitPoint()
procIntersection.point()
);
}
}

View File

@ -353,7 +353,7 @@ tmp<scalarField> signedDistance
forAll(volType, i)
{
label pointi = surfIndices[i];
scalar dist = mag(points[pointi] - nearest[pointi].hitPoint());
scalar dist = points[pointi].dist(nearest[pointi].hitPoint());
volumeType vT = volType[i];

View File

@ -122,11 +122,7 @@ int main(int argc, char *argv[])
// Extend
treeBoundBox bb = geometryToConformTo.globalBounds();
{
const vector smallVec = 0.1*bb.span();
bb.min() -= smallVec;
bb.max() += smallVec;
}
bb.grow(0.1*bb.span());
Info<< "Meshing to bounding box " << bb << nl << endl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2015 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -113,7 +113,7 @@ bool Foam::CV2D::insertPointPairAtIntersection
if (pHit.hit())
{
scalar dist2 =
magSqr(toPoint2D(pHit.hitPoint()) - vertices[vi]);
toPoint2D(pHit.point()).distSqr(vertices[vi]);
// Check the point is further away than the furthest so far
if (dist2 > interDist2)
@ -131,7 +131,7 @@ bool Foam::CV2D::insertPointPairAtIntersection
if (dist2 > mps2)
{
found = true;
interPoint = toPoint2D(pHit.hitPoint());
interPoint = toPoint2D(pHit.point());
interTri = pHit.index();
interDist2 = dist2;
interHitSurface = hitSurface;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2015 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -89,7 +90,7 @@ void Foam::CV2D::insertSurfaceNearPointPairs()
insertPointPair
(
meshControls().ppDist(),
toPoint2D(pHit.hitPoint()),
toPoint2D(pHit.point()),
toPoint2D(norm[0])
);

View File

@ -871,17 +871,16 @@ Foam::label Foam::checkTopology
Info<< " "
<< setw(20) << "PointZone"
<< setw(8) << "Points"
<< "BoundingBox" << endl;
<< "BoundingBox" << nl;
for (const auto& zone : pointZones)
{
boundBox bb;
for (const label pointi : zone)
{
bb.add(mesh.points()[pointi]);
}
bb.reduce(); // Global min/max
boundBox bb
(
mesh.points(),
static_cast<const labelUList&>(zone),
true // Reduce (global min/max)
);
Info<< " "
<< setw(20) << zone.name()

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2021 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -389,7 +389,7 @@ Foam::meshedSurface Foam::PDRobstacle::surface() const
boundBox box(obs.pt, obs.pt + obs.span);
pointField pts(box.points());
faceList fcs(boundBox::faces);
faceList fcs(boundBox::hexFaces());
surf.transfer(pts, fcs);
@ -436,7 +436,7 @@ Foam::meshedSurface Foam::PDRobstacle::surface() const
);
pointField pts0(box.points());
faceList fcs(boundBox::faces);
faceList fcs(boundBox::hexFaces());
pointField pts(cs.globalPosition(pts0));

View File

@ -1,5 +1,3 @@
const cellModel& hex = cellModel::ref(cellModel::HEX);
cellShapeList cellShapes;
faceListList boundary;
pointField points;
@ -8,20 +6,8 @@ pointField points;
block b
(
cellShape(hex, identity(8)),
pointField
(
{
point(0, 0, 0),
point(L.x(), 0, 0),
point(L.x(), L.y(), 0),
point(0, L.y(), 0),
point(0, 0, L.z()),
point(L.x(), 0, L.z()),
point(L.x(), L.y(), L.z()),
point(0, L.y(), L.z())
}
),
cellShape(cellModel::HEX, identity(8)),
pointField(boundBox(point::zero, L).hexCorners()),
blockEdgeList(),
blockFaceList(),
N

View File

@ -4,10 +4,7 @@ Random rndGen(653213);
List<treeBoundBox> meshBb
(
1,
treeBoundBox
(
boundBox(coarseMesh.points(), false)
).extend(rndGen, 1e-3)
treeBoundBox(coarseMesh.points()).extend(rndGen, 1e-3)
);
// Dummy bounds dictionary

View File

@ -4,10 +4,7 @@ Random rndGen(653213);
List<treeBoundBox> meshBb
(
1,
treeBoundBox
(
boundBox(coarseMesh.points(), false)
).extend(rndGen, 1e-3)
treeBoundBox(coarseMesh.points()).extend(rndGen, 1e-3)
);
// Dummy bounds dictionary

View File

@ -146,7 +146,7 @@ for (const int proci : Pstream::allProcs())
if (aggHitIndex[hitIndex] == startAgg[rayID])
{
const vector& endP = end[rayID];
const vector& startP = hitInfo[hitIndex].hitPoint();
const vector& startP = hitInfo[hitIndex].point();
const vector& d = endP - startP;
startHitItself.append(startP + 0.01*d);

View File

@ -1002,7 +1002,7 @@ int main(int argc, char *argv[])
if (intStreamPtr)
{
intStreamPtr().write(hitInfo.hitPoint());
intStreamPtr().write(hitInfo.point());
}
// Try and find from other side.
@ -1014,7 +1014,7 @@ int main(int argc, char *argv[])
if (intStreamPtr)
{
intStreamPtr().write(hitInfo2.hitPoint());
intStreamPtr().write(hitInfo2.point());
}
}
}
@ -1044,7 +1044,7 @@ int main(int argc, char *argv[])
//
// if (hitInfo.hit() && intStreamPtr)
// {
// intStreamPtr().write(hitInfo.hitPoint());
// intStreamPtr().write(hitInfo.point());
//
// label nearFaceI = hitInfo.index();
// triPointRef nearTri(surf[nearFaceI].tri(surf.points()));

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -642,7 +643,7 @@ static void projectNonSpanPoints
<< abort(FatalError);
}
scalar w = mag(pHit.hitPoint() - p0) / mag(p1 - p0);
scalar w = pHit.point().dist(p0) / p1.dist(p0);
insertSorted(v, w, sortedVertices, sortedWeights);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2014-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -166,11 +166,7 @@ void createBoundaryEdgeTrees
// Boundary edges
treeBoundaryEdges[surfI] =
identity
(
surf.nEdges() - surf.nInternalEdges(),
surf.nInternalEdges()
);
identity(surf.nBoundaryEdges(), surf.nInternalEdges());
Random rndGen(17301893);
@ -178,12 +174,9 @@ void createBoundaryEdgeTrees
// geometry there are less face/edge aligned items.
treeBoundBox bb
(
treeBoundBox(UList<point>(surf.localPoints())).extend(rndGen, 1e-4)
treeBoundBox(surf.localPoints()).extend(rndGen, 1e-4, ROOTVSMALL)
);
bb.min() -= point::uniform(ROOTVSMALL);
bb.max() += point::uniform(ROOTVSMALL);
bEdgeTrees.set
(
surfI,
@ -191,9 +184,8 @@ void createBoundaryEdgeTrees
(
treeDataEdge
(
false, // cachebb
surf.edges(), // edges
surf.localPoints(), // points
surf.edges(),
surf.localPoints(),
treeBoundaryEdges[surfI] // selected edges
),
bb, // bb
@ -238,16 +230,14 @@ public:
for (const label index : indices)
{
const label edgeIndex = shape.edgeLabels()[index];
const label edgeIndex = shape.objectIndex(index);
if (shapeMask_.found(edgeIndex))
{
continue;
}
const edge& e = shape.edges()[edgeIndex];
pointHit nearHit = e.line(shape.points()).nearestDist(sample);
pointHit nearHit = shape.line(index).nearestDist(sample);
// Only register hit if closest point is not an edge point
if (nearHit.hit())
@ -258,7 +248,7 @@ public:
{
nearestDistSqr = distSqr;
minIndex = index;
nearestPoint = nearHit.rawPoint();
nearestPoint = nearHit.point();
}
}
}
@ -420,8 +410,8 @@ int main(int argc, char *argv[])
!nearestHit.hit()
||
(
magSqr(currentHit.hitPoint() - samplePt)
< magSqr(nearestHit.hitPoint() - samplePt)
currentHit.point().distSqr(samplePt)
< nearestHit.point().distSqr(samplePt)
)
)
)
@ -431,8 +421,6 @@ int main(int argc, char *argv[])
}
}
scalar dist2 = magSqr(nearestHit.rawPoint() - samplePt);
if (nearestHit.hit())
{
// bool rejectEdge =
@ -444,7 +432,9 @@ int main(int argc, char *argv[])
// 30
// );
if (dist2 > Foam::sqr(dist))
scalar distSqr = nearestHit.point().distSqr(samplePt);
if (distSqr > Foam::sqr(dist))
{
nearestHit.setMiss();
}
@ -491,11 +481,11 @@ int main(int argc, char *argv[])
if
(
(
magSqr(pt - hitSurf.localPoints()[e.start()])
pt.distSqr(hitSurf.localPoints()[e.start()])
< matchTolerance
)
|| (
magSqr(pt - hitSurf.localPoints()[e.end()])
pt.distSqr(hitSurf.localPoints()[e.end()])
< matchTolerance
)
)

View File

@ -193,10 +193,7 @@ int main(int argc, char *argv[])
meshBb[Pstream::myProcNo()] = List<treeBoundBox>
(
1,
treeBoundBox
(
boundBox(mesh.points(), false)
).extend(rndGen, 1e-3)
treeBoundBox(mesh.points()).extend(rndGen, 1e-3)
);
Pstream::allGatherList(meshBb);
}
@ -243,7 +240,7 @@ int main(int argc, char *argv[])
}
else
{
bbs = List<treeBoundBox>(1, treeBoundBox(boundBox::invertedBox));
bbs = List<treeBoundBox>(1, treeBoundBox::null());
}
dictionary dict;

View File

@ -533,6 +533,7 @@ $(primitiveShapes)/line/line.C
$(primitiveShapes)/plane/plane.C
$(primitiveShapes)/triangle/intersection.C
$(primitiveShapes)/objectHit/pointIndexHitIOList.C
$(primitiveShapes)/volumeType/volumeType.C
meshShapes = meshes/meshShapes
$(meshShapes)/edge/edge.C
@ -550,11 +551,8 @@ $(cell)/cell.C
$(cell)/oppositeCellFace.C
$(cell)/cellIOList.C
hexCell = $(meshShapes)/hexCell
$(hexCell)/hexCell.C
tetCell = $(meshShapes)/tetCell
$(tetCell)/tetCell.C
$(meshShapes)/hexCell/hexCell.C
$(meshShapes)/tetCell/tetCell.C
cellModel = $(meshShapes)/cellModel
$(cellModel)/cellModel.C
@ -810,7 +808,7 @@ meshes/preservePatchTypes/preservePatchTypes.C
interpolations = interpolations
interpolation = $(interpolations)/interpolation
$(interpolations)/patchToPatchInterpolation/PatchToPatchInterpolationName.C
$(interpolations)/patchToPatchInterpolation/PatchToPatchInterpolationBase.C
$(interpolations)/interpolationTable/tableReaders/tableReaders.C
$(interpolations)/interpolationTable/tableReaders/openFoam/openFoamTableReaders.C
@ -822,13 +820,14 @@ $(interpolationWeights)/linearInterpolationWeights/linearInterpolationWeights.C
$(interpolationWeights)/splineInterpolationWeights/splineInterpolationWeights.C
algorithms/indexedOctree/indexedOctreeName.C
algorithms/AABBTree/AABBTreeBase.C
algorithms/indexedOctree/indexedOctreeBase.C
algorithms/indexedOctree/treeDataCell.C
algorithms/indexedOctree/treeDataEdge.C
algorithms/indexedOctree/treeDataPoint.C
algorithms/indexedOctree/volumeType.C
algorithms/dynamicIndexedOctree/dynamicIndexedOctreeName.C
algorithms/dynamicIndexedOctree/dynamicIndexedOctreeBase.C
algorithms/dynamicIndexedOctree/dynamicTreeDataPoint.C
parallel/commSchedule/commSchedule.C

View File

@ -29,51 +29,8 @@ License
#include "AABBTree.H"
#include "bitSet.H"
template<class Type>
Foam::scalar Foam::AABBTree<Type>::tolerance_ = 1e-4;
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
template<class Type>
void Foam::AABBTree<Type>::writeOBJ
(
const bool writeLinesOnly,
const treeBoundBox& bb,
label& vertI,
Ostream& os
) const
{
const pointField pts(bb.points());
for (const point& p : pts)
{
os << "v " << p.x() << ' ' << p.y() << ' ' << p.z() << nl;
}
if (writeLinesOnly)
{
for (const edge& e : treeBoundBox::edges)
{
os << "l " << e[0] + vertI + 1 << ' ' << e[1] + vertI + 1 << nl;
}
}
else
{
for (const face& f : treeBoundBox::faces)
{
os << 'f';
for (const label fpi : f)
{
os << ' ' << fpi + vertI + 1;
}
os << nl;
}
}
vertI += pts.size();
}
template<class Type>
void Foam::AABBTree<Type>::writeOBJ
(
@ -89,7 +46,7 @@ void Foam::AABBTree<Type>::writeOBJ
{
if (!leavesOnly || nodeI < 0)
{
writeOBJ(writeLinesOnly, bb, vertI, os);
AABBTreeBase::writeOBJ(os, bb, vertI, writeLinesOnly);
}
// recurse to find leaves
@ -126,9 +83,9 @@ void Foam::AABBTree<Type>::createBoxes
(
const bool equalBinSize,
const label level,
const List<Type>& objects,
const UList<Type>& objects,
const pointField& points,
const DynamicList<label>& objectIDs,
const labelUList& objectIDs,
const treeBoundBox& bb,
const label nodeI,
@ -137,23 +94,12 @@ void Foam::AABBTree<Type>::createBoxes
DynamicList<labelList>& addressing
) const
{
const vector span = bb.span();
// Determine which direction to divide the box
direction maxDir = 0;
scalar maxSpan = span[maxDir];
for (label dirI = 1; dirI < 3; ++dirI)
{
if (span[dirI] > maxSpan)
{
maxSpan = span[dirI];
maxDir = dirI;
}
}
const direction maxDir = bb.maxDir();
const scalar maxSpan = bb.span()[maxDir];
scalar divide;
scalar pivotValue;
if (equalBinSize)
{
@ -179,55 +125,52 @@ void Foam::AABBTree<Type>::createBoxes
Foam::sort(component);
divide = component[component.size()/2];
pivotValue = component[component.size()/2];
}
else
{
// Geometric middle
divide = bb.min()[maxDir] + 0.5*maxSpan;
pivotValue = bb.min()[maxDir] + 0.5*maxSpan;
}
scalar divMin = divide + tolerance_*maxSpan;
scalar divMax = divide - tolerance_*maxSpan;
const scalar divMin = pivotValue + tolerance_*maxSpan;
const scalar divMax = pivotValue - tolerance_*maxSpan;
// Assign the objects to min or max bin
DynamicList<label> minBinObjectIDs(objectIDs.size());
treeBoundBox minBb(boundBox::invertedBox);
DynamicList<label> maxBinObjectIDs(objectIDs.size());
treeBoundBox maxBb(boundBox::invertedBox);
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);
@ -247,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();
@ -263,7 +219,7 @@ void Foam::AABBTree<Type>::createBoxes
}
label maxI;
if (maxBinObjectIDs.size() > minLeafSize_ && level < maxLevel_)
if (addMax)
{
// New leaf
maxI = nodes.size();
@ -333,8 +289,8 @@ Foam::AABBTree<Type>::AABBTree
const UList<Type>& objects,
const pointField& points,
const bool equalBinSize,
const label maxLevel,
const label minLeafSize
label maxLevel,
label minLeafSize
)
:
maxLevel_(maxLevel),
@ -356,7 +312,7 @@ Foam::AABBTree<Type>::AABBTree
treeBoundBox topBb(points);
topBb.inflate(0.01);
DynamicList<label> objectIDs(identity(objects.size()));
labelList objectIDs(identity(objects.size()));
createBoxes
(
@ -438,16 +394,15 @@ Foam::AABBTree<Type>::AABBTree
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
const Foam::List<Foam::treeBoundBox>& Foam::AABBTree<Type>::boundBoxes() const
void Foam::AABBTree<Type>::writeOBJ(Ostream& os) const
{
return boundBoxes_;
}
label vertIndex(0);
template<class Type>
const Foam::List<Foam::labelList>& Foam::AABBTree<Type>::addressing() const
{
return addressing_;
for (const treeBoundBox& bb : boundBoxes_)
{
// writeLinesOnly=false
AABBTreeBase::writeOBJ(os, bb, vertIndex, false);
}
}
@ -486,24 +441,7 @@ bool Foam::AABBTree<Type>::overlaps(const boundBox& bbIn) const
template<class Type>
Foam::Ostream& Foam::operator<<(Ostream& os, const AABBTree<Type>& tree)
{
if (os.format() == IOstreamOption::ASCII)
{
os << tree.maxLevel_ << token::SPACE
<< tree.minLeafSize_ << token::SPACE
<< tree.boundBoxes_ << token::SPACE
<< tree.addressing_ << token::SPACE;
}
else
{
os.write
(
reinterpret_cast<const char*>(&tree.maxLevel_),
sizeof(tree.maxLevel_)
+ sizeof(tree.minLeafSize_)
);
os << tree.boundBoxes_
<< tree.addressing_;
}
os << tree.boundBoxes_ << tree.addressing_;
os.check(FUNCTION_NAME);
return os;
@ -513,23 +451,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const AABBTree<Type>& tree)
template<class Type>
Foam::Istream& Foam::operator>>(Istream& is, AABBTree<Type>& tree)
{
if (is.format() == IOstreamOption::ASCII)
{
is >> tree.maxLevel_
>> tree.minLeafSize_;
}
else
{
is.beginRawRead();
readRawLabel(is, &tree.maxLevel_);
readRawLabel(is, &tree.minLeafSize_);
is.endRawRead();
}
is >> tree.boundBoxes_
>> tree.addressing_;
is >> tree.boundBoxes_ >> tree.addressing_;
is.check(FUNCTION_NAME);
return is;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,11 +37,12 @@ Description
SourceFiles
AABBTree.C
AABBTreeBase.C
\*---------------------------------------------------------------------------*/
#ifndef AABBTree_H
#define AABBTree_H
#ifndef Foam_AABBTree_H
#define Foam_AABBTree_H
#include "labelList.H"
#include "labelPair.H"
@ -54,10 +56,8 @@ SourceFiles
namespace Foam
{
// Forward declaration of friend functions and operators
template<class Type>
class AABBTree;
// Forward Declarations
template<class Type> class AABBTree;
template<class Type>
Istream& operator>>(Istream&, AABBTree<Type>&);
@ -65,21 +65,56 @@ Istream& operator>>(Istream&, AABBTree<Type>&);
template<class Type>
Ostream& operator<<(Ostream&, const AABBTree<Type>&);
/*---------------------------------------------------------------------------*\
Class AABBTreeBase Declaration
\*---------------------------------------------------------------------------*/
//- Template invariant parts for AABBTree
class AABBTreeBase
{
protected:
// Static Data
//- Relative tolerance.
static scalar tolerance_;
public:
// Constructors
//- Default construct
AABBTreeBase() = default;
// Output Helpers
//- Write treeBoundBox in OBJ format
static void writeOBJ
(
Ostream& os,
const treeBoundBox& bb,
label& vertIndex,
const bool writeLinesOnly = false
);
};
/*---------------------------------------------------------------------------*\
Class AABBTree Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class AABBTree
:
public AABBTreeBase
{
protected:
// Protected Data
//- Tolerance
static scalar tolerance_;
//- Maximum tree level
label maxLevel_;
@ -95,15 +130,6 @@ protected:
// Protected Member Functions
//- Write OBJ file of bounding box
void writeOBJ
(
const bool writeLinesOnly,
const treeBoundBox& bb,
label& vertI,
Ostream& os
) const;
//- Write OBJ for all bounding boxes
void writeOBJ
(
@ -122,9 +148,9 @@ protected:
(
const bool equalBinSize,
const label level,
const List<Type>& objects,
const UList<Type>& objects,
const pointField& points,
const DynamicList<label>& objectIDs,
const labelUList& objectIDs,
const treeBoundBox& bb,
const label nodeI,
@ -138,7 +164,7 @@ public:
// Constructors
//- Null constructor
//- Default construct
AABBTree();
//- Construct from components
@ -148,33 +174,44 @@ public:
const UList<Type>& objects,
const pointField& points,
const bool equalBinSize = true,
const label maxLevel = 3,
const label minBinSize = 100
label maxLevel = 3,
label minBinSize = 100
);
// Public Member Functions
// Access
// Access
//- Return the bounding boxes making up the tree
const List<treeBoundBox>& boundBoxes() const;
//- Return the bounding boxes making up the tree
const List<treeBoundBox>& boundBoxes() const noexcept
{
return boundBoxes_;
}
//- Return the contents addressing
const List<labelList>& addressing() const;
//- Return the contents addressing
const List<labelList>& addressing() const noexcept
{
return addressing_;
}
// Evaluation
// Evaluation
//- Determine whether a point is inside the bounding boxes
bool pointInside(const point& pt) const;
//- Determine whether a point is inside the bounding boxes
bool pointInside(const point& pt) const;
//- Determine whether a bounding box overlaps the tree bounding
//- boxes
bool overlaps(const boundBox& bbIn) const;
//- Determine whether a bounding box overlaps the tree bounding boxes
bool overlaps(const boundBox& bbIn) const;
// IOstream operators
// Write
//- Write all tree boxes (leaves) in OBJ format
void writeOBJ(Ostream& os) const;
// IOstream Operators
friend Istream& operator>> <Type>(Istream&, AABBTree&);
friend Ostream& operator<< <Type>(Ostream&, const AABBTree&);

View File

@ -0,0 +1,81 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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/>.
\*---------------------------------------------------------------------------*/
#include "AABBTree.H"
#include "treeBoundBox.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
Foam::scalar Foam::AABBTreeBase::tolerance_ = 1e-4;
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
void Foam::AABBTreeBase::writeOBJ
(
Ostream& os,
const treeBoundBox& bb,
label& vertIndex,
const bool writeLinesOnly
)
{
// Annotate with '#box' which can be grep'd for later
os << "#box" << nl;
pointField pts(bb.points());
for (const point& p : pts)
{
os << "v " << p.x() << ' ' << p.y() << ' ' << p.z() << nl;
}
if (writeLinesOnly)
{
for (const edge& e : treeBoundBox::edges)
{
os << "l " << e[0] + vertIndex + 1
<< ' ' << e[1] + vertIndex + 1 << nl;
}
}
else
{
for (const face& f : treeBoundBox::faces)
{
os << 'f';
for (const label fpi : f)
{
os << ' ' << fpi + vertIndex + 1;
}
os << nl;
}
}
vertIndex += pts.size();
}
// ************************************************************************* //

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -38,39 +39,45 @@ SourceFiles
#ifndef Foam_dynamicIndexedOctree_H
#define Foam_dynamicIndexedOctree_H
#include "treeBoundBox.H"
#include "pointIndexHit.H"
#include "FixedList.H"
#include "Ostream.H"
#include "HashSet.H"
#include "labelBits.H"
#include "PackedList.H"
#include "volumeType.H"
#include "indexedOctree.H"
#include "DynamicList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef DynamicList<autoPtr<DynamicList<label>>> contentListList;
// Forward Declarations
template<class Type> class dynamicIndexedOctree;
template<class Type> Ostream& operator<<
(
Ostream&,
const dynamicIndexedOctree<Type>&
);
class Istream;
template<class Type> class dynamicIndexedOctree;
template<class Type>
Ostream& operator<<(Ostream&, const dynamicIndexedOctree<Type>&);
/*---------------------------------------------------------------------------*\
Class dynamicIndexedOctreeName Declaration
Class dynamicIndexedOctreeBase Declaration
\*---------------------------------------------------------------------------*/
TemplateName(dynamicIndexedOctree);
//- Template invariant parts for dynamicIndexedOctree
// Same type of node bookkeeping as indexedOctree
class dynamicIndexedOctreeBase
:
public indexedOctreeBase
{
public:
//- Document that we are using the same types of node
using node = indexedOctreeBase::node;
//- Runtime type information
ClassName("dynamicIndexedOctree");
// Constructors
//- Default construct
dynamicIndexedOctreeBase() = default;
};
/*---------------------------------------------------------------------------*\
@ -80,64 +87,9 @@ TemplateName(dynamicIndexedOctree);
template<class Type>
class dynamicIndexedOctree
:
public dynamicIndexedOctreeName
public dynamicIndexedOctreeBase
{
public:
// Data types
//- Tree node. Has up pointer and down pointers.
class node
{
public:
//- Bounding box of this node
treeBoundBox bb_;
//- Parent node (index into nodes_ of tree)
label parent_;
//- IDs of the 8 nodes on all sides of the mid point
FixedList<labelBits, 8> subNodes_;
friend Ostream& operator<< (Ostream& os, const node& n)
{
return os << n.bb_ << token::SPACE
<< n.parent_ << token::SPACE << n.subNodes_;
}
friend Istream& operator>> (Istream& is, node& n)
{
return is >> n.bb_ >> n.parent_ >> n.subNodes_;
}
friend bool operator==(const node& a, const node& b)
{
return
a.bb_ == b.bb_
&& a.parent_ == b.parent_
&& a.subNodes_ == b.subNodes_;
}
friend bool operator!=(const node& a, const node& b)
{
return !(a == b);
}
};
private:
// Static data
//- Relative perturbation tolerance. Determines when point is
// considered to be close to face/edge of bb of node.
// The tolerance is relative to the bounding box of the smallest
// node.
static scalar perturbTol_;
// Private data
// Private Data
//- Underlying shapes for geometric queries.
const Type shapes_;
@ -159,23 +111,13 @@ private:
DynamicList<node> nodes_;
//- List of all contents (referenced by those nodes that are contents)
contentListList contents_;
DynamicList<DynamicList<label>> contents_;
//- Per node per octant whether is fully inside/outside/mixed.
mutable PackedList<2> nodeTypes_;
// Private Member Functions
//- Helper: does bb intersect a sphere around sample? Or is any
// corner point of bb closer than nearestDistSqr to sample.
// (bb is implicitly provided as parent bb + octant)
static bool overlaps
(
const treeBoundBox& parentBb,
const direction octant,
const scalar nearestDistSqr,
const point& sample
);
// Private Member Functions
// Construction
@ -183,9 +125,9 @@ private:
// according to where they are in relation to mid.
void divide
(
const autoPtr<DynamicList<label>>& indices,
const labelUList& indices,
const treeBoundBox& bb,
contentListList& result
FixedList<DynamicList<label>, 8>& dividedIndices
) const;
//- Subdivide the contents node at position contentI.
@ -193,7 +135,7 @@ private:
node divide
(
const treeBoundBox& bb,
const label contentI,
label contentIndex,
const label parentNodeIndex,
const label octantToBeDivided
);
@ -327,22 +269,23 @@ private:
const point& end
) const;
//- Find all elements intersecting box.
void findBox
//- Find elements intersecting box
// Store all results in elements (if non-null), or early exit
bool findBox
(
const label nodeI,
const treeBoundBox& searchBox,
labelHashSet& elements
labelHashSet* elements
) const;
//- Find all elements intersecting sphere.
void findSphere
//- Find elements intersecting sphere.
// Store all results in elements (if non-null), or early exit
bool findSphere
(
const label nodeI,
const point& centre,
const scalar radiusSqr,
labelHashSet& elements
labelHashSet* elements
) const;
@ -361,49 +304,27 @@ private:
);
// Other
// Other
//- Count number of elements on this and sublevels
label countElements(const labelBits index) const;
//- Count number of elements on this and sublevels
label countElements(const labelBits index) const;
//- Dump node+octant to an obj file
void writeOBJ(const label nodeI, const direction octant) const;
//- Write node treeBoundBoxes in OBJ format
void writeOBJ
(
const label nodeI,
Ostream& os,
label& vertIndex,
const bool leavesOnly,
const bool writeLinesOnly = false
) const;
//- From index into contents_ to subNodes_ entry
static labelBits contentPlusOctant
(
const label i,
const direction octant
)
{
return labelBits(-i - 1, octant);
}
//- Dump node+octant to an obj file
void writeOBJ(const label nodeI, const direction octant) const;
//- From index into nodes_ to subNodes_ entry
static labelBits nodePlusOctant
(
const label i,
const direction octant
)
{
return labelBits(i + 1, octant);
}
//- From empty to subNodes_ entry
static labelBits emptyPlusOctant
(
const direction octant
)
{
return labelBits(0, octant);
}
public:
//- Get the perturbation tolerance
static scalar& perturbTol();
// Constructors
//- Construct from shapes
@ -426,80 +347,36 @@ public:
// Member Functions
// Access
// Access
//- Reference to shape
const Type& shapes() const
//- Reference to shape
const Type& shapes() const noexcept { return shapes_; }
//- List of all nodes
const List<node>& nodes() const noexcept { return nodes_; }
//- List of all contents
//- (referenced by those nodes that are contents)
const DynamicList<DynamicList<label>>& contents() const noexcept
{
return contents_;
}
//- Per node, per octant whether is fully inside/outside/mixed.
PackedList<2>& nodeTypes() const noexcept
{
return nodeTypes_;
}
//- Top bounding box
const treeBoundBox& bb() const
{
if (nodes_.empty())
{
return shapes_;
}
//- List of all nodes
const List<node>& nodes() const
{
return nodes_;
}
//- List of all contents (referenced by those nodes that are
// contents)
const contentListList& contents() const
{
return contents_;
}
//- Top bounding box
const treeBoundBox& bb() const
{
if (nodes_.empty())
{
FatalErrorInFunction
<< "Tree is empty" << abort(FatalError);
}
return nodes_[0].bb_;
}
// Conversions for entries in subNodes_.
static bool isContent(const labelBits i)
{
return i.val() < 0;
}
static bool isEmpty(const labelBits i)
{
return i.val() == 0;
}
static bool isNode(const labelBits i)
{
return i.val() > 0;
}
static label getContent(const labelBits i)
{
if (!isContent(i))
{
FatalErrorInFunction
<< abort(FatalError);
}
return -i.val()-1;
}
static label getNode(const labelBits i)
{
if (!isNode(i))
{
FatalErrorInFunction
<< abort(FatalError);
}
return i.val() - 1;
}
static direction getOctant(const labelBits i)
{
return i.bits();
return treeBoundBox::null();
}
return nodes_[0].bb_;
}
// Queries
@ -554,19 +431,53 @@ public:
const point& end
) const;
//- Find (in no particular order) indices of all shapes inside or
// overlapping bounding box (i.e. all shapes not outside box)
labelList findBox(const treeBoundBox& bb) const;
//- True if any shapes overlap the bounding box
bool overlaps(const treeBoundBox& bb) const;
//- Find (in no particular order) indices of all shapes inside or
// overlapping a bounding sphere (i.e. all shapes not outside
// sphere)
//- Find indices of all shapes inside or overlapping
//- a bounding box (i.e. all shapes not outside box)
// \returns the indices (in no particular order)
labelList findBox
(
const treeBoundBox& bb //!< bound box limits
) const;
//- Find indices of all shapes inside or overlapping
//- a bounding box (i.e. all shapes not outside box)
// \returns the number of elements found
label findBox
(
const treeBoundBox& bb, //!< bound box limits
labelHashSet& elements //!< [out] elements found
) const;
//- True if any shapes overlap the bounding sphere
bool overlaps
(
const point& centre, //!< centre of bound sphere
const scalar radiusSqr //!< radius^2 of sphere
) const;
//- Find indices of all shapes inside or overlapping
//- a bounding sphere (i.e. all shapes not outside a sphere)
// \returns the indices (in no particular order)
labelList findSphere
(
const point& centre,
const scalar radiusSqr
const point& centre, //!< centre of bound sphere
const scalar radiusSqr //!< radius^2 of sphere
) const;
//- Find indices of all shapes inside or overlapping
//- a bounding sphere (i.e. all shapes not outside sphere)
// \returns the number of elements found
label findSphere
(
const point& centre, //!< centre of bound sphere
const scalar radiusSqr, //!< radius^2 of sphere
labelHashSet& elements //!< [out] elements found
) const;
//- Find deepest node (as parent+octant) containing point. Starts
// off from starting index in nodes_ (use 0 to start from top)
// Use getNode and getOctant to extract info, or call findIndices.
@ -591,16 +502,6 @@ public:
const vector& vec
);
//- Helper: does bb intersect a sphere around sample? Or is any
// corner point of bb closer than nearestDistSqr to sample.
static bool overlaps
(
const point& bbMin,
const point& bbMax,
const scalar nearestDistSqr,
const point& sample
);
//- Find near pairs and apply CompareOp to them.
// tree2 can be *this or different tree.
template<class CompareOp>
@ -630,20 +531,23 @@ public:
label removeIndex(const label nodIndex, const label index);
// Write
// Write
//- Print tree. Either print all indices (printContent = true) or
// just size of contents nodes.
void print
(
prefixOSstream&,
const bool printContents,
const label
) const;
//- Write all tree boxes as OBJ format
void writeOBJ(Ostream& os) const;
bool write(Ostream& os) const;
//- Print tree. Either print all indices (printContent = true) or
// just size of contents nodes.
void print
(
prefixOSstream&,
const bool printContents,
const label
) const;
void writeTreeInfo() const;
bool write(Ostream& os) const;
void writeTreeInfo() const;
// IOstream Operators

View File

@ -31,7 +31,7 @@ License
namespace Foam
{
defineTypeNameAndDebug(dynamicIndexedOctreeName, 0);
defineTypeNameAndDebug(dynamicIndexedOctreeBase, 0);
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,14 +27,13 @@ License
\*---------------------------------------------------------------------------*/
#include "dynamicTreeDataPoint.H"
#include "treeBoundBox.H"
#include "dynamicIndexedOctree.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(dynamicTreeDataPoint, 0);
defineTypeName(dynamicTreeDataPoint);
}
@ -50,10 +50,10 @@ Foam::dynamicTreeDataPoint::dynamicTreeDataPoint
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::DynamicList<Foam::point>&
Foam::dynamicTreeDataPoint::shapePoints() const
Foam::treeBoundBox
Foam::dynamicTreeDataPoint::bounds(const labelUList& indices) const
{
return points_;
return treeBoundBox(points_, indices);
}
@ -70,10 +70,10 @@ Foam::volumeType Foam::dynamicTreeDataPoint::getVolumeType
bool Foam::dynamicTreeDataPoint::overlaps
(
const label index,
const treeBoundBox& cubeBb
const treeBoundBox& searchBox
) const
{
return cubeBb.contains(points_[index]);
return searchBox.contains(centre(index));
}
@ -84,16 +84,7 @@ bool Foam::dynamicTreeDataPoint::overlaps
const scalar radiusSqr
) const
{
const point& p = points_[index];
const scalar distSqr = magSqr(p - centre);
if (distSqr <= radiusSqr)
{
return true;
}
return false;
return (centre.distSqr(this->centre(index)) <= radiusSqr);
}
@ -107,13 +98,11 @@ void Foam::dynamicTreeDataPoint::findNearest
point& nearestPoint
) const
{
forAll(indices, i)
for (const label index : indices)
{
const label index = indices[i];
const point& pt = centre(index);
const point& pt = points_[index];
scalar distSqr = magSqr(pt - sample);
const scalar distSqr = sample.distSqr(pt);
if (distSqr < nearestDistSqr)
{
@ -136,42 +125,30 @@ void Foam::dynamicTreeDataPoint::findNearest
point& nearestPoint
) const
{
const treeBoundBox lnBb(ln.box());
// Best so far
scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
scalar nearestDistSqr = linePoint.distSqr(nearestPoint);
forAll(indices, i)
for (const label index : indices)
{
const label index = indices[i];
const point& pt = centre(index);
const point& shapePt = points_[index];
if (tightest.contains(shapePt))
if (tightest.contains(pt))
{
// Nearest point on line
pointHit pHit = ln.nearestDist(shapePt);
scalar distSqr = sqr(pHit.distance());
pointHit pHit = ln.nearestDist(pt);
const scalar distSqr = sqr(pHit.distance());
if (distSqr < nearestDistSqr)
{
nearestDistSqr = distSqr;
minIndex = index;
linePoint = pHit.rawPoint();
nearestPoint = shapePt;
linePoint = pHit.point();
nearestPoint = pt;
{
point& minPt = tightest.min();
minPt = min(ln.start(), ln.end());
minPt.x() -= pHit.distance();
minPt.y() -= pHit.distance();
minPt.z() -= pHit.distance();
}
{
point& maxPt = tightest.max();
maxPt = max(ln.start(), ln.end());
maxPt.x() += pHit.distance();
maxPt.y() += pHit.distance();
maxPt.z() += pHit.distance();
}
tightest = lnBb;
tightest.grow(pHit.distance());
}
}
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2015 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -61,100 +62,126 @@ template<class Type> class dynamicIndexedOctree;
class dynamicTreeDataPoint
{
// Private data
// Private Data
//- The point field
const DynamicList<point>& points_;
public:
// Declare name of the class and its debug switch
ClassName("dynamicTreeDataPoint");
// Declare name of the class
ClassNameNoDebug("dynamicTreeDataPoint");
// Constructors
// Constructors (non-caching)
//- Construct from List. Holds reference!
dynamicTreeDataPoint(const DynamicList<point>& points);
explicit dynamicTreeDataPoint(const DynamicList<point>& points);
// Member Functions
// Access
//- Object dimension == 0 (point element)
int nDim() const noexcept { return 0; }
inline label size() const
{
return points_.size();
}
//- Get representative point cloud for all shapes inside
// (one point per shape)
const DynamicList<point>& shapePoints() const;
//- Return bounding box for the specified point indices
treeBoundBox bounds(const labelUList& indices) const;
// Search
// Access
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
// Only makes sense for closed surfaces.
volumeType getVolumeType
(
const dynamicIndexedOctree<dynamicTreeDataPoint>&,
const point&
) const;
//- The original point field
const DynamicList<point>& points() const noexcept { return points_; }
//- Does (bb of) shape at index overlap bb
bool overlaps
(
const label index,
const treeBoundBox& sampleBb
) const;
//TDB //- The subset of point ids to use
///const labelList& pointLabels() const noexcept { labelList::null(); }
//- Check if any point on shape is inside sphere.
bool overlaps
(
const label index,
const point& centre,
const scalar radiusSqr
) const;
//- Use a subset of points
bool useSubset() const noexcept { return false; }
//- Calculates nearest (to sample) point in shape.
// Returns actual point and distance (squared)
void findNearest
(
const labelUList& indices,
const point& sample,
//- Is the effective point field empty?
bool empty() const noexcept { return points_.empty(); }
scalar& nearestDistSqr,
label& nearestIndex,
point& nearestPoint
) const;
//- The size of the effective point field
label size() const noexcept { return points_.size(); }
//- Calculates nearest (to line) point in shape.
// Returns point and distance (squared)
void findNearest
(
const labelUList& indices,
const linePointRef& ln,
//- Map from shape index to original (non-subset) point label
label objectIndex(label index) const noexcept { return index; }
treeBoundBox& tightest,
label& minIndex,
point& linePoint,
point& nearestPoint
) const;
//- Point at specified shape index
const point& operator[](label index) const { return points_[index]; }
//- Calculate intersection of shape with ray. Sets result
// accordingly
bool intersects
(
const label index,
const point& start,
const point& end,
point& result
) const
{
NotImplemented;
return false;
}
//- Point at specified shape index
const point& centre(label index) const { return points_[index]; }
//- Representative point cloud
const DynamicList<point>& centres() const noexcept { return points_; }
// Search
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
// Only makes sense for closed surfaces.
volumeType getVolumeType
(
const dynamicIndexedOctree<dynamicTreeDataPoint>&,
const point&
) const;
//- Does (bb of) shape at index overlap bb
bool overlaps
(
const label index,
const treeBoundBox& searchBox
) const;
//- Check if any point on shape is inside sphere.
bool overlaps
(
const label index,
const point& centre,
const scalar radiusSqr
) const;
//- Calculates nearest (to sample) point in shape.
// Returns actual point and distance (squared)
void findNearest
(
const labelUList& indices,
const point& sample,
scalar& nearestDistSqr,
label& nearestIndex,
point& nearestPoint
) const;
//- Calculates nearest (to line) point in shape.
// Returns point and distance (squared)
void findNearest
(
const labelUList& indices,
const linePointRef& ln,
treeBoundBox& tightest,
label& minIndex,
point& linePoint,
point& nearestPoint
) const;
//- Calculate intersection of shape with ray.
// Sets result accordingly
bool intersects
(
const label index,
const point& start,
const point& end,
point& result
) const
{
NotImplemented;
return false;
}
};

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -52,45 +53,61 @@ namespace Foam
{
// Forward Declarations
class Istream;
template<class Type> class indexedOctree;
template<class Type> Ostream& operator<<(Ostream&, const indexedOctree<Type>&);
class Istream;
/*---------------------------------------------------------------------------*\
Class indexedOctreeName Declaration
Class indexedOctreeBase Declaration
\*---------------------------------------------------------------------------*/
TemplateName(indexedOctree);
/*---------------------------------------------------------------------------*\
Class indexedOctree Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class indexedOctree
:
public indexedOctreeName
//- Template invariant parts for indexedOctree
// The internal node bookkeeping is encoded follows:
// - 0: empty
// - +ve: parent
// - -ve: leaf
class indexedOctreeBase
{
public:
// Data types
// Public Data Types
//- Tree node. Has up pointer and down pointers.
class node
{
public:
//- Has exactly 8 sub-nodes (octants)
static constexpr direction nChildren = 8;
//- Bounding box of this node
treeBoundBox bb_;
//- Parent node (index into nodes_ of tree)
label parent_;
//- Parent node (index into flat list addressing for tree)
label parent_ = -1;
//- IDs of the 8 nodes on all sides of the mid point
FixedList<labelBits, 8> subNodes_;
// Operators
friend bool operator==(const node& a, const node& b)
{
return
(
a.parent_ == b.parent_
&& a.subNodes_ == b.subNodes_
&& a.bb_ == b.bb_
);
}
friend bool operator!=(const node& a, const node& b)
{
return !(a == b);
}
friend Ostream& operator<< (Ostream& os, const node& n)
{
return os << n.bb_ << token::SPACE
@ -101,34 +118,147 @@ public:
{
return is >> n.bb_ >> n.parent_ >> n.subNodes_;
}
friend bool operator==(const node& a, const node& b)
{
return
a.bb_ == b.bb_
&& a.parent_ == b.parent_
&& a.subNodes_ == b.subNodes_;
}
friend bool operator!=(const node& a, const node& b)
{
return !(a == b);
}
};
private:
// Static Functions
// Static data
// Tests for node handling
// (0: empty, +ve: parent, -ve: leaf)
//- Relative perturbation tolerance. Determines when point is
// considered to be close to face/edge of bb of node.
//- An empty node - no content
static bool isEmpty(labelBits i) noexcept
{
return (i.val() == 0);
}
//- Node with content (leaf)
static bool isContent(labelBits i) noexcept
{
return (i.val() < 0);
}
//- A parent node
static bool isNode(labelBits i) noexcept
{
return (i.val() > 0);
}
// Decode/retrieve node addressing
//- Return real (dereferenced) index for a content node
static label getContent(labelBits i)
{
if (!isContent(i))
{
FatalErrorInFunction
<< abort(FatalError);
}
return (-i.val()-1);
}
//- Return real (dereferenced) index for a parent node
static label getNode(const labelBits i)
{
if (!isNode(i))
{
FatalErrorInFunction
<< abort(FatalError);
}
return (i.val()-1);
}
//- Return sub-node direction/octant
static direction getOctant(labelBits i) noexcept
{
return i.bits();
}
protected:
// Static Data
//- Relative perturbation tolerance.
// Determines when point is considered to be close to face/edge
// of bb of node.
// The tolerance is relative to the bounding box of the smallest
// node.
static scalar perturbTol_;
// Private data
// Protected Member Functions
// Encode node addressing
// (only used when building)
//- From empty to subNodes_ entry
static labelBits emptyPlusOctant(direction octant)
{
return labelBits(0, octant);
}
//- From index into contents_ to subNodes_ entry
static labelBits contentPlusOctant(label i, direction octant)
{
return labelBits(-i-1, octant);
}
//- From index into nodes_ to subNodes_ entry
static labelBits nodePlusOctant(label i, direction octant)
{
return labelBits(i+1, octant);
}
public:
//- Get the perturbation tolerance
static scalar& perturbTol() noexcept { return perturbTol_; }
//- Set the perturbation tolerance, return the old value
static scalar perturbTol(scalar tol) noexcept
{
scalar old(perturbTol_);
perturbTol_ = tol;
return old;
}
//- Runtime type information
ClassName("indexedOctree");
// Constructors
//- Default construct
indexedOctreeBase() = default;
// Output Helpers
//- Write treeBoundBox in OBJ format
static void writeOBJ
(
Ostream& os,
const treeBoundBox& bb,
label& vertIndex,
const bool writeLinesOnly = false
);
};
/*---------------------------------------------------------------------------*\
Class indexedOctree Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class indexedOctree
:
public indexedOctreeBase
{
// Private Data
//- Underlying shapes for geometric queries.
const Type shapes_;
@ -137,23 +267,13 @@ private:
List<node> nodes_;
//- List of all contents (referenced by those nodes that are contents)
labelListList contents_;
List<labelList> contents_;
//- Per node per octant whether is fully inside/outside/mixed.
mutable PackedList<2> nodeTypes_;
// Private Member Functions
//- Helper: does bb intersect a sphere around sample? Or is any
// corner point of bb closer than nearestDistSqr to sample.
// (bb is implicitly provided as parent bb + octant)
static bool overlaps
(
const treeBoundBox& parentBb,
const direction octant,
const scalar nearestDistSqr,
const point& sample
);
// Private Member Functions
// Construction
@ -161,9 +281,9 @@ private:
// according to where they are in relation to mid.
void divide
(
const labelList& indices,
const labelUList& indices,
const treeBoundBox& bb,
labelListList& result
FixedList<labelList, 8>& dividedIndices
) const;
//- Subdivide the contents node at position contentI.
@ -172,7 +292,7 @@ private:
(
const treeBoundBox& bb,
DynamicList<labelList>& contents,
const label contentI
label contentIndex
) const;
//- Split any contents node with more than minSize elements.
@ -327,22 +447,23 @@ private:
const FindIntersectOp& fiOp
) const;
//- Find all elements intersecting box.
void findBox
//- Find elements intersecting box
// Store all results in elements (if non-null), or early exit
bool findBox
(
const label nodeI,
const treeBoundBox& searchBox,
labelHashSet& elements
labelHashSet* elements
) const;
//- Find all elements intersecting sphere.
void findSphere
//- Find elements intersecting sphere.
// Store all results in elements (if non-null), or early exit
bool findSphere
(
const label nodeI,
const point& centre,
const scalar radiusSqr,
labelHashSet& elements
labelHashSet* elements
) const;
@ -361,49 +482,30 @@ private:
);
// Other
// Other
//- Count number of elements on this and sublevels
label countElements(const labelBits index) const;
//- Count number of elements on this and sublevels
label countElements(const labelBits index) const;
//- Dump node+octant to an obj file
void writeOBJ(const label nodeI, const direction octant) const;
//- Number of leafs below given node
label countLeafs(const label nodeI) const;
//- From index into contents_ to subNodes_ entry
static labelBits contentPlusOctant
(
const label i,
const direction octant
)
{
return labelBits(-i - 1, octant);
}
//- Write node treeBoundBoxes in OBJ format
void writeOBJ
(
const label nodeI,
Ostream& os,
label& vertIndex,
const bool leavesOnly,
const bool writeLinesOnly = false
) const;
//- From index into nodes_ to subNodes_ entry
static labelBits nodePlusOctant
(
const label i,
const direction octant
)
{
return labelBits(i + 1, octant);
}
//- Dump node+octant to an obj file
void writeOBJ(const label nodeI, const direction octant) const;
//- From empty to subNodes_ entry
static labelBits emptyPlusOctant
(
const direction octant
)
{
return labelBits(0, octant);
}
public:
//- Get the perturbation tolerance
static scalar& perturbTol();
// Constructors
//- Construct null
@ -414,7 +516,7 @@ public:
(
const Type& shapes,
const List<node>& nodes,
const labelListList& contents
const List<labelList>& contents
);
//- Construct from shapes
@ -437,88 +539,42 @@ public:
return autoPtr<indexedOctree<Type>>::New(*this);
}
// Member Functions
// Access
// Access
//- Reference to shape
const Type& shapes() const
//- Reference to shape
const Type& shapes() const noexcept { return shapes_; }
//- List of all nodes
const List<node>& nodes() const noexcept { return nodes_; }
//- List of all contents
//- (referenced by those nodes that are contents)
const List<labelList>& contents() const noexcept
{
return contents_;
}
//- Per node, per octant whether is fully inside/outside/mixed.
PackedList<2>& nodeTypes() const noexcept
{
return nodeTypes_;
}
//- Top bounding box
const treeBoundBox& bb() const
{
if (nodes_.empty())
{
return shapes_;
return treeBoundBox::null();
}
return nodes_[0].bb_;
}
//- List of all nodes
const List<node>& nodes() const
{
return nodes_;
}
//- List of all contents (referenced by those nodes that are
// contents)
const labelListList& contents() const
{
return contents_;
}
//- Top bounding box
const treeBoundBox& bb() const
{
if (nodes_.empty())
{
FatalErrorInFunction
<< "Tree is empty" << abort(FatalError);
}
return nodes_[0].bb_;
}
//- Per node, per octant whether is fully inside/outside/mixed.
PackedList<2>& nodeTypes() const
{
return nodeTypes_;
}
// Conversions for entries in subNodes_.
static bool isContent(const labelBits i)
{
return i.val() < 0;
}
static bool isEmpty(const labelBits i)
{
return i.val() == 0;
}
static bool isNode(const labelBits i)
{
return i.val() > 0;
}
static label getContent(const labelBits i)
{
if (!isContent(i))
{
FatalErrorInFunction
<< abort(FatalError);
}
return -i.val()-1;
}
static label getNode(const labelBits i)
{
if (!isNode(i))
{
FatalErrorInFunction
<< abort(FatalError);
}
return i.val() - 1;
}
static direction getOctant(const labelBits i)
{
return i.bits();
}
//- Return the number of leaf nodes
label nLeafs() const;
// Queries
@ -613,19 +669,53 @@ public:
const FindIntersectOp& fiOp
) const;
//- Find (in no particular order) indices of all shapes inside or
// overlapping bounding box (i.e. all shapes not outside box)
labelList findBox(const treeBoundBox& bb) const;
//- True if any shapes overlap the bounding box
bool overlaps(const treeBoundBox& bb) const;
//- Find (in no particular order) indices of all shapes inside or
// overlapping a bounding sphere (i.e. all shapes not outside
// sphere)
//- Find indices of all shapes inside or overlapping
//- a bounding box (i.e. all shapes not outside box)
// \returns the indices (in no particular order)
labelList findBox
(
const treeBoundBox& bb //!< bound box limits
) const;
//- Find indices of all shapes inside or overlapping
//- a bounding box (i.e. all shapes not outside box)
// \returns the number of elements found
label findBox
(
const treeBoundBox& bb, //!< bound box limits
labelHashSet& elements //!< [out] elements found
) const;
//- True if any shapes overlap the bounding sphere
bool overlaps
(
const point& centre, //!< centre of bound sphere
const scalar radiusSqr //!< radius^2 of sphere
) const;
//- Find indices of all shapes inside or overlapping
//- a bounding sphere (i.e. all shapes not outside a sphere)
// \returns the indices (in no particular order)
labelList findSphere
(
const point& centre,
const scalar radiusSqr
const point& centre, //!< centre of bound sphere
const scalar radiusSqr //!< radius^2 of sphere
) const;
//- Find indices of all shapes inside or overlapping
//- a bounding sphere (i.e. all shapes not outside sphere)
// \returns the number of elements found
label findSphere
(
const point& centre, //!< centre of bound sphere
const scalar radiusSqr, //!< radius^2 of sphere
labelHashSet& elements //!< [out] elements found
) const;
//- Find deepest node (as parent+octant) containing point. Starts
// off from starting index in nodes_ (use 0 to start from top)
// Use getNode and getOctant to extract info, or call findIndices.
@ -650,16 +740,6 @@ public:
const vector& vec
);
//- Helper: does bb intersect a sphere around sample? Or is any
// corner point of bb closer than nearestDistSqr to sample.
static bool overlaps
(
const point& bbMin,
const point& bbMax,
const scalar nearestDistSqr,
const point& sample
);
//- Find near pairs and apply CompareOp to them.
// tree2 can be *this or different tree.
template<class CompareOp>
@ -671,18 +751,21 @@ public:
) const;
// Write
// Write
//- Print tree. Either print all indices (printContent = true) or
// just size of contents nodes.
void print
(
prefixOSstream&,
const bool printContents,
const label
) const;
//- Write (non-empty) tree boxes in OBJ format
void writeOBJ(Ostream& os) const;
bool write(Ostream& os) const;
//- Print tree. Either print all indices (printContent = true) or
// just size of contents nodes.
void print
(
prefixOSstream&,
const bool printContents,
const label
) const;
bool write(Ostream& os) const;
// IOstream Operators

View File

@ -0,0 +1,87 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2012 OpenFOAM Foundation
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/>.
\*---------------------------------------------------------------------------*/
#include "indexedOctree.H"
#include "treeBoundBox.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(indexedOctreeBase, 0);
scalar indexedOctreeBase::perturbTol_ = 10*SMALL;
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
void Foam::indexedOctreeBase::writeOBJ
(
Ostream& os,
const treeBoundBox& bb,
label& vertIndex,
const bool writeLinesOnly
)
{
// Annotate with '#box' which can be grep'd for later
os << "#box" << nl;
pointField pts(bb.points());
for (const point& p : pts)
{
os << "v " << p.x() << ' ' << p.y() << ' ' << p.z() << nl;
}
if (writeLinesOnly)
{
for (const edge& e : treeBoundBox::edges)
{
os << "l " << e[0] + vertIndex + 1
<< ' ' << e[1] + vertIndex + 1 << nl;
}
}
else
{
for (const face& f : treeBoundBox::faces)
{
os << 'f';
for (const label fpi : f)
{
os << ' ' << fpi + vertIndex + 1;
}
os << nl;
}
}
vertIndex += pts.size();
}
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -29,44 +29,119 @@ License
#include "treeDataCell.H"
#include "indexedOctree.H"
#include "polyMesh.H"
#include <algorithm>
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(treeDataCell, 0);
defineTypeName(treeDataCell);
}
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
// Bound boxes corresponding to specified cells
template<class ElementIds>
static treeBoundBoxList boxesImpl
(
const primitiveMesh& mesh,
const ElementIds& elemIds
)
{
treeBoundBoxList bbs(elemIds.size());
if (mesh.hasCellPoints())
{
std::transform
(
elemIds.cbegin(),
elemIds.cend(),
bbs.begin(),
[&](label celli)
{
return treeBoundBox(mesh.points(), mesh.cellPoints(celli));
}
);
}
else
{
std::transform
(
elemIds.cbegin(),
elemIds.cend(),
bbs.begin(),
[&](label celli)
{
return treeBoundBox(mesh.cells()[celli].box(mesh));
}
);
}
return bbs;
}
} // End namespace Foam
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::treeBoundBoxList
Foam::treeDataCell::boxes(const primitiveMesh& mesh)
{
// All cells
return boxesImpl(mesh, labelRange(mesh.nCells()));
}
Foam::treeBoundBoxList
Foam::treeDataCell::boxes
(
const primitiveMesh& mesh,
const labelUList& cellIds
)
{
return boxesImpl(mesh, cellIds);
}
Foam::treeBoundBox
Foam::treeDataCell::bounds
(
const primitiveMesh& mesh,
const labelUList& cellIds
)
{
treeBoundBox bb;
if (mesh.hasCellPoints())
{
for (const label celli : cellIds)
{
bb.add(mesh.points(), mesh.cellPoints(celli));
}
}
else
{
for (const label celli : cellIds)
{
bb.add(mesh.cells()[celli].box(mesh));
}
}
return bb;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::treeBoundBox Foam::treeDataCell::calcCellBb(const label celli) const
inline Foam::treeBoundBox
Foam::treeDataCell::getBounds(const label index) const
{
const cellList& cells = mesh_.cells();
const faceList& faces = mesh_.faces();
const pointField& points = mesh_.points();
treeBoundBox cellBb
(
vector(GREAT, GREAT, GREAT),
vector(-GREAT, -GREAT, -GREAT)
);
const cell& cFaces = cells[celli];
forAll(cFaces, cFacei)
{
const face& f = faces[cFaces[cFacei]];
forAll(f, fp)
{
const point& p = points[f[fp]];
cellBb.min() = min(cellBb.min(), p);
cellBb.max() = max(cellBb.max(), p);
}
}
return cellBb;
return treeBoundBox(mesh_.cellBb(objectIndex(index)));
}
@ -74,11 +149,13 @@ void Foam::treeDataCell::update()
{
if (cacheBb_)
{
bbs_.setSize(cellLabels_.size());
forAll(cellLabels_, i)
if (useSubset_)
{
bbs_[i] = calcCellBb(cellLabels_[i]);
bbs_ = treeDataCell::boxes(mesh_, cellLabels_);
}
else
{
bbs_ = treeDataCell::boxes(mesh_);
}
}
}
@ -86,6 +163,23 @@ void Foam::treeDataCell::update()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::treeDataCell::treeDataCell
(
const bool cacheBb,
const polyMesh& mesh,
const polyMesh::cellDecomposition decompMode
)
:
mesh_(mesh),
cellLabels_(),
useSubset_(false),
cacheBb_(cacheBb),
decompMode_(decompMode)
{
update();
}
Foam::treeDataCell::treeDataCell
(
const bool cacheBb,
@ -96,6 +190,7 @@ Foam::treeDataCell::treeDataCell
:
mesh_(mesh),
cellLabels_(cellLabels),
useSubset_(true),
cacheBb_(cacheBb),
decompMode_(decompMode)
{
@ -113,6 +208,7 @@ Foam::treeDataCell::treeDataCell
:
mesh_(mesh),
cellLabels_(std::move(cellLabels)),
useSubset_(true),
cacheBb_(cacheBb),
decompMode_(decompMode)
{
@ -120,22 +216,79 @@ Foam::treeDataCell::treeDataCell
}
Foam::treeDataCell::treeDataCell
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::treeBoundBox
Foam::treeDataCell::bounds(const labelUList& indices) const
{
if (useSubset_)
{
treeBoundBox bb;
if (mesh_.hasCellPoints())
{
for (const label index : indices)
{
const label celli = cellLabels_[index];
bb.add(mesh_.points(), mesh_.cellPoints(celli));
}
}
else
{
for (const label index : indices)
{
const label celli = cellLabels_[index];
bb.add(mesh_.cells()[celli].box(mesh_));
}
}
return bb;
}
return treeDataCell::bounds(mesh_, indices);
}
Foam::tmp<Foam::pointField> Foam::treeDataCell::centres() const
{
if (useSubset_)
{
return tmp<pointField>::New(mesh_.cellCentres(), cellLabels_);
}
return mesh_.cellCentres();
}
bool Foam::treeDataCell::overlaps
(
const bool cacheBb,
const polyMesh& mesh,
const polyMesh::cellDecomposition decompMode
)
:
mesh_(mesh),
cellLabels_(identity(mesh_.nCells())),
cacheBb_(cacheBb),
decompMode_(decompMode)
const label index,
const treeBoundBox& searchBox
) const
{
update();
return
(
cacheBb_
? searchBox.overlaps(bbs_[index])
: searchBox.overlaps(getBounds(index))
);
}
bool Foam::treeDataCell::contains
(
const label index,
const point& sample
) const
{
return mesh_.pointInCell(sample, objectIndex(index), decompMode_);
}
// * * * * * * * * * * * * * * * * Searching * * * * * * * * * * * * * * * * //
Foam::treeDataCell::findNearestOp::findNearestOp
(
const indexedOctree<treeDataCell>& tree
@ -154,43 +307,29 @@ Foam::treeDataCell::findIntersectOp::findIntersectOp
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::pointField Foam::treeDataCell::shapePoints() const
{
pointField cc(cellLabels_.size());
forAll(cellLabels_, i)
{
cc[i] = mesh_.cellCentres()[cellLabels_[i]];
}
return cc;
}
bool Foam::treeDataCell::overlaps
void Foam::treeDataCell::findNearest
(
const label index,
const treeBoundBox& cubeBb
const labelUList& indices,
const point& sample,
scalar& nearestDistSqr,
label& minIndex,
point& nearestPoint
) const
{
if (cacheBb_)
for (const label index : indices)
{
return cubeBb.overlaps(bbs_[index]);
const point& pt = centre(index);
const scalar distSqr = sample.distSqr(pt);
if (distSqr < nearestDistSqr)
{
nearestDistSqr = distSqr;
minIndex = index;
nearestPoint = pt;
}
}
return cubeBb.overlaps(calcCellBb(cellLabels_[index]));
}
bool Foam::treeDataCell::contains
(
const label index,
const point& sample
) const
{
return mesh_.pointInCell(sample, cellLabels_[index], decompMode_);
}
@ -204,21 +343,14 @@ void Foam::treeDataCell::findNearestOp::operator()
point& nearestPoint
) const
{
const treeDataCell& shape = tree_.shapes();
forAll(indices, i)
{
label index = indices[i];
label celli = shape.cellLabels()[index];
scalar distSqr = magSqr(sample - shape.mesh().cellCentres()[celli]);
if (distSqr < nearestDistSqr)
{
nearestDistSqr = distSqr;
minIndex = index;
nearestPoint = shape.mesh().cellCentres()[celli];
}
}
tree_.shapes().findNearest
(
indices,
sample,
nearestDistSqr,
minIndex,
nearestPoint
);
}
@ -260,7 +392,7 @@ bool Foam::treeDataCell::findIntersectOp::operator()
}
else
{
const treeBoundBox cellBb = shape.calcCellBb(shape.cellLabels_[index]);
const treeBoundBox cellBb = shape.getBounds(index);
if ((cellBb.posBits(start) & cellBb.posBits(end)) != 0)
{
@ -274,23 +406,23 @@ bool Foam::treeDataCell::findIntersectOp::operator()
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Disable picking up intersections behind us.
scalar oldTol = intersection::setPlanarTol(0.0);
const cell& cFaces = shape.mesh_.cells()[shape.cellLabels_[index]];
const scalar oldTol = intersection::setPlanarTol(0);
const vector dir(end - start);
scalar minDistSqr = magSqr(dir);
bool hasMin = false;
forAll(cFaces, i)
const label celli = shape.objectIndex(index);
for (const label facei : shape.mesh().cells()[celli])
{
const face& f = shape.mesh_.faces()[cFaces[i]];
const face& f = shape.mesh().faces()[facei];
pointHit inter = f.ray
(
start,
dir,
shape.mesh_.points(),
shape.mesh().points(),
intersection::HALF_RAY
);
@ -300,7 +432,7 @@ bool Foam::treeDataCell::findIntersectOp::operator()
// since using half_ray AND zero tolerance. (note that tolerance
// is used to look behind us)
minDistSqr = sqr(inter.distance());
intersectionPoint = inter.hitPoint();
intersectionPoint = inter.point();
hasMin = true;
}
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,8 +36,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef treeDataCell_H
#define treeDataCell_H
#ifndef Foam_treeDataCell_H
#define Foam_treeDataCell_H
#include "polyMesh.H"
#include "treeBoundBoxList.H"
@ -47,7 +48,7 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward Declarations
template<class Type> class indexedOctree;
/*---------------------------------------------------------------------------*\
@ -56,13 +57,17 @@ template<class Type> class indexedOctree;
class treeDataCell
{
// Private data
// Private Data
//- Reference to the mesh
const polyMesh& mesh_;
//- Subset of cells to work on
const labelList cellLabels_;
//- Use subset of cells (cellLabels)
const bool useSubset_;
//- Whether to precalculate and store cell bounding box
const bool cacheBb_;
@ -75,8 +80,8 @@ class treeDataCell
// Private Member Functions
//- Calculate cell bounding box
treeBoundBox calcCellBb(const label celli) const;
//- Get cell bounding box at specified index
inline treeBoundBox getBounds(const label index) const;
//- Initialise all member data
void update();
@ -133,11 +138,19 @@ public:
};
// Declare name of the class and its debug switch
ClassName("treeDataCell");
// Declare name of the class
ClassNameNoDebug("treeDataCell");
// Constructors
// Constructors (cachable versions)
//- Construct from mesh, using all cells in mesh.
treeDataCell
(
const bool cacheBb,
const polyMesh& mesh,
polyMesh::cellDecomposition decompMode
);
//- Construct from mesh, copying subset of cells.
treeDataCell
@ -145,7 +158,7 @@ public:
const bool cacheBb,
const polyMesh& mesh,
const labelUList& cellLabels,
const polyMesh::cellDecomposition decompMode
polyMesh::cellDecomposition decompMode
);
//- Construct from mesh, moving subset of cells
@ -154,74 +167,166 @@ public:
const bool cacheBb,
const polyMesh& mesh,
labelList&& cellLabels,
const polyMesh::cellDecomposition decompMode
polyMesh::cellDecomposition decompMode
);
//- Construct from mesh. Uses all cells in mesh.
// Constructors (non-caching)
//- Construct from mesh, using all cells in mesh.
treeDataCell
(
const bool cacheBb,
const polyMesh& mesh,
const polyMesh::cellDecomposition decompMode
polyMesh::cellDecomposition decompMode
)
:
treeDataCell(false, mesh, decompMode)
{}
//- Construct from mesh, copying subset of cells.
treeDataCell
(
const polyMesh& mesh,
const labelUList& cellLabels,
polyMesh::cellDecomposition decompMode
)
:
treeDataCell(false, mesh, cellLabels, decompMode)
{}
//- Construct from mesh, moving subset of cells
treeDataCell
(
const polyMesh& mesh,
labelList&& cellLabels,
polyMesh::cellDecomposition decompMode
)
:
treeDataCell(false, mesh, std::move(cellLabels), decompMode)
{}
// Static Functions
//- Calculate and return bounding boxes for all mesh cells
static treeBoundBoxList boxes
(
const primitiveMesh& mesh
);
//- Calculate and return bounding boxes for specified mesh cells
static treeBoundBoxList boxes
(
const primitiveMesh& mesh,
const labelUList& cellIds
);
//- Return bounding box of specified mesh cells
static treeBoundBox bounds
(
const primitiveMesh& mesh,
const labelUList& cellIds
);
// Member Functions
// Access
//- Object dimension == 3 (volume element)
int nDim() const noexcept { return 3; }
inline const labelList& cellLabels() const
{
return cellLabels_;
}
inline const polyMesh& mesh() const
{
return mesh_;
}
inline polyMesh::cellDecomposition decompMode() const
{
return decompMode_;
}
inline label size() const
{
return cellLabels_.size();
}
//- Get representative point cloud for all shapes inside
// (one point per shape)
pointField shapePoints() const;
//- Return bounding box for the specified cell indices
treeBoundBox bounds(const labelUList& indices) const;
// Search
// Access
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
// Only makes sense for closed surfaces.
volumeType getVolumeType
(
const indexedOctree<treeDataCell>&,
const point&
) const
{
NotImplemented;
return volumeType::UNKNOWN;
}
//- Reference to the supporting mesh
const polyMesh& mesh() const noexcept { return mesh_; }
//- Does (bb of) shape at index overlap bb
bool overlaps
(
const label index,
const treeBoundBox& sampleBb
) const;
//- The cell decomposition mode used
polyMesh::cellDecomposition decompMode() const noexcept
{
return decompMode_;
}
//- Does shape at index contain sample
bool contains
(
const label index,
const point& sample
) const;
//- The subset of cell ids to use
const labelList& cellLabels() const noexcept { return cellLabels_; }
//- Use a subset of cells
bool useSubset() const noexcept { return useSubset_; }
//- Is the effective cell selection empty?
bool empty() const noexcept
{
return useSubset_ ? cellLabels_.empty() : !mesh_.nCells();
}
//- The size of the cell selection
label size() const noexcept
{
return useSubset_ ? cellLabels_.size() : mesh_.nCells();
}
//- Map from shape index to original (non-subset) cell label
label objectIndex(const label index) const
{
return useSubset_ && index >= 0 ? cellLabels_[index] : index;
}
//TBD //- Cell at specified shape index
///const cell& operator[](const label index) const
///{ return mesh_.cells()[objectIndex(index)]; }
//- Representative point (cell centre) at shape index
const point& centre(const label index) const
{
return mesh_.cellCentres()[objectIndex(index)];
}
//- Representative point cloud for contained shapes.
//- One point per shape, corresponding to the cell centres.
tmp<pointField> centres() const;
// Search
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
// Only makes sense for closed surfaces.
volumeType getVolumeType
(
const indexedOctree<treeDataCell>&,
const point&
) const
{
NotImplemented;
return volumeType::UNKNOWN;
}
//- Does (bb of) shape at index overlap searchBox
bool overlaps
(
const label index,
const treeBoundBox& searchBox
) const;
//- Does shape at index contain sample
bool contains
(
const label index,
const point& sample
) const;
//- Calculates nearest (to sample) point in shape.
// Returns actual point and distance (squared)
void findNearest
(
const labelUList& indices,
const point& sample,
scalar& nearestDistSqr,
label& nearestIndex,
point& nearestPoint
) const;
};

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,36 +28,173 @@ License
#include "treeDataEdge.H"
#include "indexedOctree.H"
#include <algorithm>
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(treeDataEdge, 0);
defineTypeName(treeDataEdge);
}
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
// Bound boxes corresponding to specified edges
template<class ElementIds>
static treeBoundBoxList boxesImpl
(
const edgeList& edges,
const pointField& points,
const ElementIds& elemIds
)
{
treeBoundBoxList bbs(elemIds.size());
std::transform
(
elemIds.cbegin(),
elemIds.cend(),
bbs.begin(),
[&](label edgei)
{
return treeBoundBox(edges[edgei].box(points));
}
);
return bbs;
}
// Overall bound box for specified edges
template<class ElementIds>
static treeBoundBox boundsImpl
(
const edgeList& edges,
const pointField& points,
const ElementIds& elemIds
)
{
treeBoundBox bb;
for (const label edgei : elemIds)
{
const edge& e = edges[edgei];
bb.add(points[e.first()], points[e.second()]);
}
return bb;
}
} // End namespace Foam
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::treeBoundBoxList
Foam::treeDataEdge::boxes
(
const edgeList& edges,
const pointField& points
)
{
treeBoundBoxList bbs(edges.size());
std::transform
(
edges.cbegin(),
edges.cend(),
bbs.begin(),
[&](const edge& e) { return treeBoundBox(e.box(points)); }
);
return bbs;
}
Foam::treeBoundBoxList
Foam::treeDataEdge::boxes
(
const edgeList& edges,
const pointField& points,
const labelRange& range
)
{
return boxesImpl(edges, points, range);
}
Foam::treeBoundBoxList
Foam::treeDataEdge::boxes
(
const edgeList& edges,
const pointField& points,
const labelUList& edgeIds
)
{
return boxesImpl(edges, points, edgeIds);
}
Foam::treeBoundBox
Foam::treeDataEdge::bounds
(
const edgeList& edges,
const pointField& points
)
{
treeBoundBox bb;
for (const edge& e : edges)
{
bb.add(points[e.first()], points[e.second()]);
}
return bb;
}
Foam::treeBoundBox
Foam::treeDataEdge::bounds
(
const edgeList& edges,
const pointField& points,
const labelRange& range
)
{
return boundsImpl(edges, points, range);
}
Foam::treeBoundBox
Foam::treeDataEdge::bounds
(
const edgeList& edges,
const pointField& points,
const labelUList& edgeIds
)
{
return boundsImpl(edges, points, edgeIds);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::treeBoundBox Foam::treeDataEdge::calcBb(const label edgeI) const
{
const edge& e = edges_[edgeI];
const point& p0 = points_[e[0]];
const point& p1 = points_[e[1]];
return treeBoundBox(min(p0, p1), max(p0, p1));
}
void Foam::treeDataEdge::update()
{
if (cacheBb_)
{
bbs_.setSize(edgeLabels_.size());
forAll(edgeLabels_, i)
if (useSubset_)
{
bbs_[i] = calcBb(edgeLabels_[i]);
bbs_ = treeDataEdge::boxes(edges_, points_, edgeLabels_);
}
else
{
bbs_ = treeDataEdge::boxes(edges_, points_);
}
}
}
@ -64,6 +202,41 @@ void Foam::treeDataEdge::update()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::treeDataEdge::treeDataEdge
(
const bool cacheBb,
const edgeList& edges,
const pointField& points
)
:
points_(points),
edges_(edges),
edgeLabels_(),
useSubset_(false),
cacheBb_(cacheBb)
{
update();
}
Foam::treeDataEdge::treeDataEdge
(
const bool cacheBb,
const edgeList& edges,
const pointField& points,
const labelRange& range
)
:
points_(points),
edges_(edges),
edgeLabels_(identity(range)),
useSubset_(true),
cacheBb_(cacheBb)
{
update();
}
Foam::treeDataEdge::treeDataEdge
(
const bool cacheBb,
@ -72,9 +245,10 @@ Foam::treeDataEdge::treeDataEdge
const labelUList& edgeLabels
)
:
edges_(edges),
points_(points),
edges_(edges),
edgeLabels_(edgeLabels),
useSubset_(true),
cacheBb_(cacheBb)
{
update();
@ -89,15 +263,107 @@ Foam::treeDataEdge::treeDataEdge
labelList&& edgeLabels
)
:
edges_(edges),
points_(points),
edges_(edges),
edgeLabels_(std::move(edgeLabels)),
useSubset_(true),
cacheBb_(cacheBb)
{
update();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::treeBoundBox Foam::treeDataEdge::bounds(const labelUList& indices) const
{
if (useSubset_)
{
treeBoundBox bb;
for (const label index : indices)
{
const edge& e = edges_[edgeLabels_[index]];
bb.add(points_[e.first()], points_[e.second()]);
}
return bb;
}
return treeDataEdge::bounds(edges_, points_, indices);
}
Foam::tmp<Foam::pointField> Foam::treeDataEdge::centres() const
{
tmp<pointField> tpts;
if (useSubset_)
{
tpts = tmp<pointField>::New(edgeLabels_.size());
std::transform
(
edgeLabels_.cbegin(),
edgeLabels_.cend(),
tpts.ref().begin(),
[&](label edgei) { return edges_[edgei].centre(points_); }
);
}
else
{
tpts = tmp<pointField>::New(edges_.size());
std::transform
(
edges_.cbegin(),
edges_.cend(),
tpts.ref().begin(),
[&](const edge& e) { return e.centre(points_); }
);
}
return tpts;
}
Foam::volumeType Foam::treeDataEdge::getVolumeType
(
const indexedOctree<treeDataEdge>& oc,
const point& sample
) const
{
return volumeType::UNKNOWN;
}
bool Foam::treeDataEdge::overlaps
(
const label index,
const treeBoundBox& searchBox
) const
{
point intersect;
return searchBox.intersects(this->line(index), intersect);
}
bool Foam::treeDataEdge::overlaps
(
const label index,
const point& centre,
const scalar radiusSqr
) const
{
const pointHit nearHit = this->line(index).nearestDist(centre);
return (sqr(nearHit.distance()) <= radiusSqr);
}
// * * * * * * * * * * * * * * * * Searching * * * * * * * * * * * * * * * * //
Foam::treeDataEdge::findNearestOp::findNearestOp
(
const indexedOctree<treeDataEdge>& tree
@ -114,63 +380,29 @@ Foam::treeDataEdge::findIntersectOp::findIntersectOp
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::treeDataEdge::findNearest
(
const labelUList& indices,
const point& sample,
Foam::pointField Foam::treeDataEdge::shapePoints() const
scalar& nearestDistSqr,
label& minIndex,
point& nearestPoint
) const
{
pointField eMids(edgeLabels_.size());
forAll(edgeLabels_, i)
for (const label index : indices)
{
const edge& e = edges_[edgeLabels_[i]];
pointHit nearHit = this->line(index).nearestDist(sample);
eMids[i] = e.centre(points_);
const scalar distSqr = sqr(nearHit.distance());
if (distSqr < nearestDistSqr)
{
nearestDistSqr = distSqr;
minIndex = index;
nearestPoint = nearHit.point();
}
}
return eMids;
}
Foam::volumeType Foam::treeDataEdge::getVolumeType
(
const indexedOctree<treeDataEdge>& oc,
const point& sample
) const
{
return volumeType::UNKNOWN;
}
bool Foam::treeDataEdge::overlaps
(
const label index,
const treeBoundBox& cubeBb
) const
{
const edge& e = edges_[edgeLabels_[index]];
const point& start = points_[e.start()];
const point& end = points_[e.end()];
point intersect;
return cubeBb.intersects(start, end, intersect);
}
bool Foam::treeDataEdge::overlaps
(
const label index,
const point& centre,
const scalar radiusSqr
) const
{
const edge& e = edges_[edgeLabels_[index]];
const pointHit nearHit = e.line(points_).nearestDist(centre);
const scalar distSqr = sqr(nearHit.distance());
return (distSqr <= radiusSqr);
}
@ -184,23 +416,14 @@ void Foam::treeDataEdge::findNearestOp::operator()
point& nearestPoint
) const
{
const treeDataEdge& shape = tree_.shapes();
for (const label index : indices)
{
const edge& e = shape.edges()[shape.edgeLabels()[index]];
pointHit nearHit = e.line(shape.points()).nearestDist(sample);
const scalar distSqr = sqr(nearHit.distance());
if (distSqr < nearestDistSqr)
{
nearestDistSqr = distSqr;
minIndex = index;
nearestPoint = nearHit.rawPoint();
}
}
tree_.shapes().findNearest
(
indices,
sample,
nearestDistSqr,
minIndex,
nearestPoint
);
}
@ -217,19 +440,20 @@ void Foam::treeDataEdge::findNearestOp::operator()
{
const treeDataEdge& shape = tree_.shapes();
const treeBoundBox lnBb(ln.box());
// Best so far
scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
scalar nearestDistSqr = linePoint.distSqr(nearestPoint);
for (const label index : indices)
{
const edge& e = shape.edges()[shape.edgeLabels()[index]];
// Note: could do bb test ? Worthwhile?
// Nearest point on line
point ePoint, lnPt;
scalar dist = e.line(shape.points()).nearestDist(ln, ePoint, lnPt);
scalar distSqr = sqr(dist);
const scalar dist = shape.line(index).nearestDist(ln, ePoint, lnPt);
const scalar distSqr = sqr(dist);
if (distSqr < nearestDistSqr)
{
@ -238,20 +462,8 @@ void Foam::treeDataEdge::findNearestOp::operator()
linePoint = lnPt;
nearestPoint = ePoint;
{
point& minPt = tightest.min();
minPt = min(ln.start(), ln.end());
minPt.x() -= dist;
minPt.y() -= dist;
minPt.z() -= dist;
}
{
point& maxPt = tightest.max();
maxPt = max(ln.start(), ln.end());
maxPt.x() += dist;
maxPt.y() += dist;
maxPt.z() += dist;
}
tightest = lnBb;
tightest.grow(dist);
}
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -39,6 +39,7 @@ SourceFiles
#define Foam_treeDataEdge_H
#include "treeBoundBoxList.H"
#include "labelRange.H"
#include "line.H"
#include "volumeType.H"
@ -56,41 +57,37 @@ template<class Type> class indexedOctree;
class treeDataEdge
{
// Static Data
//- Tolerance on linear dimensions
static scalar tol;
// Private Data
//- Reference to the underlying support points
const pointField& points_;
//- Reference to edgeList
const edgeList& edges_;
//- Reference to points
const pointField& points_;
//- Labels of edges
//- Subset of edges to work on
const labelList edgeLabels_;
//- Whether to precalculate and store face bounding box
//- Use subset of edges (edgeLabels)
const bool useSubset_;
//- Whether to precalculate and store edge bounding box
const bool cacheBb_;
//- Bbs for all above edges (valid only if cacheBb_)
//- Edge bounding boxes (valid only if cacheBb_)
treeBoundBoxList bbs_;
// Private Member Functions
//- Calculate edge bounding box
treeBoundBox calcBb(const label edgeI) const;
//- Initialise all member data
void update();
public:
//- Forward to treeDataEdge findNearest operations
class findNearestOp
{
const indexedOctree<treeDataEdge>& tree_;
@ -122,6 +119,7 @@ public:
};
//- Forward to treeDataEdge findIntersect operations
class findIntersectOp
{
public:
@ -141,10 +139,29 @@ public:
// Declare name of the class and its debug switch
ClassName("treeDataEdge");
ClassNameNoDebug("treeDataEdge");
// Constructors
// Constructors (cachable versions)
//- Construct from all edges.
// \note Holds references to edges and points!
treeDataEdge
(
const bool cacheBb,
const edgeList& edges,
const pointField& points
);
//- Construct from range of edges.
// \note Holds references to edges and points!
treeDataEdge
(
const bool cacheBb,
const edgeList& edges,
const pointField& points,
const labelRange& range
);
//- Construct from selected edges.
// \note Holds references to edges and points!
@ -167,59 +184,201 @@ public:
);
// Constructors (non-caching)
//- Construct from all edges.
// \note Holds references to edges and points!
treeDataEdge(const edgeList& edges, const pointField& points)
:
treeDataEdge(false, edges, points)
{}
//- Construct from range of edges.
// \note Holds references to edges and points!
treeDataEdge
(
const edgeList& edges,
const pointField& points,
const labelRange& range
)
:
treeDataEdge(false, edges, points, range)
{}
//- Construct from selected edges.
// \note Holds references to edges and points!
treeDataEdge
(
const edgeList& edges,
const pointField& points,
const labelUList& edgeLabels
)
:
treeDataEdge(false, edges, points, edgeLabels)
{}
//- Construct from selected edges, transferring contents.
// \note Holds references to edges and points!
treeDataEdge
(
const edgeList& edges,
const pointField& points,
labelList&& edgeLabels
)
:
treeDataEdge(false, edges, points, std::move(edgeLabels))
{}
// Static Functions
//- Calculate and return bounding boxes for all edges
static treeBoundBoxList boxes
(
const edgeList& edges,
const pointField& points
);
//- Calculate and return bounding boxes for specified range of edges
static treeBoundBoxList boxes
(
const edgeList& edges,
const pointField& points,
const labelRange& range
);
//- Calculate and return bounding boxes for specified edges
static treeBoundBoxList boxes
(
const edgeList& edges,
const pointField& points,
const labelUList& edgeIds
);
//- Return bounding box of all edges
static treeBoundBox bounds
(
const edgeList& edges,
const pointField& points
);
//- Return bounding box of specified range of edges
static treeBoundBox bounds
(
const edgeList& edges,
const pointField& points,
const labelRange& range
);
//- Return bounding box of specified edges
static treeBoundBox bounds
(
const edgeList& edges,
const pointField& points,
const labelUList& edgeIds
);
// Member Functions
// Access
//- Object dimension == 1 (line element)
int nDim() const noexcept { return 1; }
const edgeList& edges() const
{
return edges_;
}
const pointField& points() const
{
return points_;
}
const labelList& edgeLabels() const
{
return edgeLabels_;
}
label size() const
{
return edgeLabels_.size();
}
//- Representative point cloud for all shapes inside
//- (one point per shape)
pointField shapePoints() const;
//- Return bounding box for the specified edge indices
treeBoundBox bounds(const labelUList& indices) const;
// Search
// Access
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
// Only makes sense for closed surfaces.
volumeType getVolumeType
(
const indexedOctree<treeDataEdge>&,
const point&
) const;
//- The reference point field
const pointField& points() const noexcept { return points_; }
//- Does (bb of) shape at index overlap bb
bool overlaps
(
const label index,
const treeBoundBox& sampleBb
) const;
//- The original list of edges
const edgeList& edges() const noexcept { return edges_; }
//- Does (bb of) shape at index overlap bb
bool overlaps
(
const label index,
const point& centre,
const scalar radiusSqr
) const;
//- The subset of edge ids to use
const labelList& edgeLabels() const noexcept { return edgeLabels_; }
//- Use a subset of edges
bool useSubset() const noexcept { return useSubset_; }
//- Is the effective edge selection empty?
bool empty() const noexcept
{
return useSubset_ ? edgeLabels_.empty() : edges_.empty();
}
//- The size of edge selection
label size() const noexcept
{
return useSubset_ ? edgeLabels_.size() : edges_.size();
}
//- Map from shape index to original (non-subset) edge label
label objectIndex(const label index) const
{
return useSubset_ && index >= 0 ? edgeLabels_[index] : index;
}
//- Edge at specified shape index
const edge& operator[](const label index) const
{
return edges_[objectIndex(index)];
}
//- Geometric line for edge at specified shape index. Frequently used
const linePointRef line(const label index) const
{
return edges_[objectIndex(index)].line(points_);
}
//- Representative point (edge centre) at shape index
point centre(const label index) const
{
return edges_[objectIndex(index)].centre(points_);
}
//- Representative point cloud for contained shapes.
//- One point per shape, corresponding to the edge centres.
tmp<pointField> centres() const;
// Search
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
// Only makes sense for closed surfaces.
volumeType getVolumeType
(
const indexedOctree<treeDataEdge>&,
const point&
) const;
//- Does (bb of) shape at index searchBox
bool overlaps
(
const label index,
const treeBoundBox& searchBox
) const;
//- Does (bb of) shape at index overlap bb
bool overlaps
(
const label index,
const point& centre,
const scalar radiusSqr
) const;
//- Calculates nearest (to sample) point in shape.
// Returns actual point and distance (squared)
void findNearest
(
const labelUList& indices,
const point& sample,
scalar& nearestDistSqr,
label& nearestIndex,
point& nearestPoint
) const;
};

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -33,7 +33,7 @@ License
namespace Foam
{
defineTypeNameAndDebug(treeDataPoint, 0);
defineTypeName(treeDataPoint);
}
@ -72,29 +72,29 @@ Foam::treeDataPoint::treeDataPoint
{}
Foam::treeDataPoint::findNearestOp::findNearestOp
(
const indexedOctree<treeDataPoint>& tree
)
:
tree_(tree)
{}
Foam::treeDataPoint::findIntersectOp::findIntersectOp
(
const indexedOctree<treeDataPoint>& tree
)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::pointField Foam::treeDataPoint::shapePoints() const
Foam::treeBoundBox Foam::treeDataPoint::bounds(const labelUList& indices) const
{
if (useSubset_)
{
return pointField(points_, pointLabels_);
treeBoundBox bb;
for (const label index : indices)
{
bb.add(points_[pointLabels_[index]]);
}
return bb;
}
return treeBoundBox(points_, indices);
}
Foam::tmp<Foam::pointField> Foam::treeDataPoint::centres() const
{
if (useSubset_)
{
return tmp<pointField>::New(points_, pointLabels_);
}
return points_;
@ -114,10 +114,10 @@ Foam::volumeType Foam::treeDataPoint::getVolumeType
bool Foam::treeDataPoint::overlaps
(
const label index,
const treeBoundBox& cubeBb
const treeBoundBox& searchBox
) const
{
return cubeBb.contains(shapePoint(index));
return searchBox.contains(centre(index));
}
@ -128,7 +128,51 @@ bool Foam::treeDataPoint::overlaps
const scalar radiusSqr
) const
{
return (magSqr(shapePoint(index) - centre) <= radiusSqr);
return (centre.distSqr(this->centre(index)) <= radiusSqr);
}
// * * * * * * * * * * * * * * * * Searching * * * * * * * * * * * * * * * * //
Foam::treeDataPoint::findNearestOp::findNearestOp
(
const indexedOctree<treeDataPoint>& tree
)
:
tree_(tree)
{}
Foam::treeDataPoint::findIntersectOp::findIntersectOp
(
const indexedOctree<treeDataPoint>& tree
)
{}
void Foam::treeDataPoint::findNearest
(
const labelUList& indices,
const point& sample,
scalar& nearestDistSqr,
label& minIndex,
point& nearestPoint
) const
{
for (const label index : indices)
{
const point& pt = centre(index);
const scalar distSqr = sample.distSqr(pt);
if (distSqr < nearestDistSqr)
{
nearestDistSqr = distSqr;
minIndex = index;
nearestPoint = pt;
}
}
}
@ -142,21 +186,14 @@ void Foam::treeDataPoint::findNearestOp::operator()
point& nearestPoint
) const
{
const treeDataPoint& shape = tree_.shapes();
for (const label index : indices)
{
const point& pt = shape.shapePoint(index);
const scalar distSqr = magSqr(pt - sample);
if (distSqr < nearestDistSqr)
{
nearestDistSqr = distSqr;
minIndex = index;
nearestPoint = pt;
}
}
tree_.shapes().findNearest
(
indices,
sample,
nearestDistSqr,
minIndex,
nearestPoint
);
}
@ -173,44 +210,34 @@ void Foam::treeDataPoint::findNearestOp::operator()
{
const treeDataPoint& shape = tree_.shapes();
const treeBoundBox lnBb(ln.box());
// Best so far
scalar nearestDistSqr = GREAT;
if (minIndex >= 0)
{
nearestDistSqr = magSqr(linePoint - nearestPoint);
nearestDistSqr = linePoint.distSqr(nearestPoint);
}
for (const label index : indices)
{
const point& shapePt = shape.shapePoint(index);
const point& pt = shape.centre(index);
if (tightest.contains(shapePt))
if (tightest.contains(pt))
{
// Nearest point on line
pointHit pHit = ln.nearestDist(shapePt);
pointHit pHit = ln.nearestDist(pt);
const scalar distSqr = sqr(pHit.distance());
if (distSqr < nearestDistSqr)
{
nearestDistSqr = distSqr;
minIndex = index;
linePoint = pHit.rawPoint();
nearestPoint = shapePt;
linePoint = pHit.point();
nearestPoint = pt;
{
point& minPt = tightest.min();
minPt = min(ln.start(), ln.end());
minPt.x() -= pHit.distance();
minPt.y() -= pHit.distance();
minPt.z() -= pHit.distance();
}
{
point& maxPt = tightest.max();
maxPt = max(ln.start(), ln.end());
maxPt.x() += pHit.distance();
maxPt.y() += pHit.distance();
maxPt.z() += pHit.distance();
}
tightest = lnBb;
tightest.grow(pHit.distance());
}
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -64,16 +64,19 @@ class treeDataPoint
{
// Private Data
//- Reference to the underlying point field
const pointField& points_;
//- Subset of points to work on (or empty)
const labelList pointLabels_;
//- Use subset of points (pointLabels)
const bool useSubset_;
public:
//- Forward to treeDataPoint findNearest operations
class findNearestOp
{
const indexedOctree<treeDataPoint>& tree_;
@ -105,6 +108,7 @@ public:
};
//- Forward to treeDataPoint findIntersect operations (not possible)
class findIntersectOp
{
public:
@ -123,11 +127,11 @@ public:
};
// Declare name of the class and its debug switch
ClassName("treeDataPoint");
// Declare name of the class
ClassNameNoDebug("treeDataPoint");
// Constructors
// Constructors (non-caching)
//- Construct from pointField
// \note Holds reference to the points!
@ -154,108 +158,101 @@ public:
// Member Functions
// Access
//- Object dimension == 0 (point element)
int nDim() const noexcept { return 0; }
//- An empty effective point field?
inline bool empty() const
{
return
(
useSubset_
? pointLabels_.empty()
: points_.empty()
);
}
//- The effective point field size
inline label size() const
{
return
(
useSubset_
? pointLabels_.size()
: points_.size()
);
}
//- The original point field
inline const pointField& points() const
{
return points_;
}
//- The original point ids
inline const labelList& pointLabels() const
{
return pointLabels_;
}
//- Use a subset of points
inline bool useSubset() const
{
return useSubset_;
}
//- The original (non-subset) point label
inline label pointLabel(const label index) const
{
return
(
useSubset_ && index >= 0
? pointLabels_[index]
: index
);
}
//- Point at specified index
inline const point& shapePoint(const label index) const
{
return
(
useSubset_
? points_[pointLabels_[index]]
: points_[index]
);
}
//- Representative point cloud for all shapes inside
//- (one point per shape)
pointField shapePoints() const;
//- Return bounding box for the specified point indices
treeBoundBox bounds(const labelUList& indices) const;
// Search
// Access
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
// Only makes sense for closed surfaces.
volumeType getVolumeType
(
const indexedOctree<treeDataPoint>& os,
const point& sample
) const;
//- The original point field
const pointField& points() const noexcept { return points_; }
//- Does (bb of) shape at index overlap bb
bool overlaps
(
const label index,
const treeBoundBox& sampleBb
) const;
//- The subset of point ids to use
const labelList& pointLabels() const noexcept { return pointLabels_; }
//- Does shape at index overlap the sphere
bool overlaps
(
const label index,
const point& centre,
const scalar radiusSqr
) const;
//- Use a subset of points
bool useSubset() const noexcept { return useSubset_; }
// Member Operators
//- The point at the specified index
inline const point& operator[](const label index) const
//- Is the effective point field empty?
bool empty() const noexcept
{
return shapePoint(index);
return useSubset_ ? pointLabels_.empty() : points_.empty();
}
//- The size of the effective point field
label size() const noexcept
{
return useSubset_ ? pointLabels_.size() : points_.size();
}
//- Map to the original (non-subset) point label
label objectIndex(const label index) const
{
return useSubset_ && index >= 0 ? pointLabels_[index] : index;
}
//- Point at specified shape index
const point& operator[](const label index) const
{
return points_[objectIndex(index)];
}
//- Point at specified shape index
const point& centre(const label index) const
{
return points_[objectIndex(index)];
}
//- Point cloud
tmp<pointField> centres() const;
// Search
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
// Only makes sense for closed surfaces.
volumeType getVolumeType
(
const indexedOctree<treeDataPoint>& os,
const point& sample
) const;
//- Does (bb of) shape at index searchBox
bool overlaps
(
const label index,
const treeBoundBox& searchBox
) const;
//- Does shape at index overlap the sphere
bool overlaps
(
const label index,
const point& centre,
const scalar radiusSqr
) const;
//- Calculates nearest (to sample) point in shape.
// Returns actual point and distance (squared)
void findNearest
(
const labelUList& indices,
const point& sample,
scalar& nearestDistSqr,
label& nearestIndex,
point& nearestPoint
) const;
// Housekeeping
//- Map to the original (non-subset) point label
///FOAM_DEPRECATED_FOR(2022-10, "objectIndex()")
label pointLabel(label index) const { return objectIndex(index); }
};

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -437,7 +437,10 @@ public:
// Member Operators
//- Append a value at the end of the list
inline PackedList<Width>& append(const unsigned int val);
inline void push_back(const unsigned int val);
//- Reduce size by 1 or more elements. Can be called on an empty list.
inline void pop_back(label n = 1);
//- Remove and return the last element
inline unsigned int remove();
@ -556,6 +559,14 @@ public:
//- Alias for resize()
void setSize(const label n, unsigned int val = 0u) { resize(n, val); }
//- Append a value at the end of the list
//FOAM_DEPRECATED_FOR(2022-10, "push_back()")
PackedList<Width>& append(const unsigned int val)
{
this->push_back(val);
return *this;
}
};

View File

@ -693,15 +693,27 @@ inline bool Foam::PackedList<Width>::unset(const label i)
template<unsigned Width>
inline Foam::PackedList<Width>&
Foam::PackedList<Width>::append(const unsigned int val)
inline void Foam::PackedList<Width>::push_back(const unsigned int val)
{
const label idx = size();
reserve(idx + 1);
++size_;
reference(this, idx).set(val);
return *this;
}
template<unsigned Width>
inline void Foam::PackedList<Width>::pop_back(label n)
{
if (n >= size())
{
clear();
}
else if (n > 0)
{
resize(size() - n);
}
}

View File

@ -142,7 +142,7 @@ Foam::Istream& Foam::PackedList<Width>::readList(Istream& is)
while (!tok.isPunctuation(token::END_LIST))
{
is.putBack(tok);
list.append(list.readValue(is));
list.push_back(list.readValue(is));
is >> tok;
is.fatalCheck(FUNCTION_NAME);

View File

@ -114,13 +114,30 @@ Foam::label Foam::CircularBuffer<T>::find(const T& val, label pos) const
if (pos < list1.size())
{
// Can start search in first array
i = list1.find(val, pos);
// Position for continued search in second array
pos = 0;
}
else
{
// Position for continued search in second array
pos -= list1.size();
}
if (i < 0)
const auto list2 = this->array_two();
if (i < 0 && list2.size())
{
// Not found - search the second list
return this->array_two().find(val, 0);
// Not yet found, continue search in second array
i = list2.find(val, pos);
if (i >= 0)
{
// As flat index into the entire buffer
i += list1.size();
}
}
return i;
@ -140,4 +157,25 @@ void Foam::CircularBuffer<T>::reverse()
}
template<class T>
Foam::List<T> Foam::CircularBuffer<T>::list() const
{
const auto list1 = array_one();
const auto list2 = array_two();
List<T> result(list1.size() + list2.size());
if (list1.size())
{
result.slice(0, list1.size()) = list1;
}
if (list2.size())
{
result.slice(list1.size(), list1.size() + list2.size()) = list2;
}
return result;
}
// ************************************************************************* //

View File

@ -246,16 +246,16 @@ public:
// Access
//- Access the first element (front). Requires !empty().
T& first();
T& front();
//- Access the last element (back). Requires !empty().
T& last();
T& back();
//- Const access to the first element (front). Requires !empty().
const T& first() const;
const T& front() const;
//- Const access to the last element (back). Requires !empty().
const T& last() const;
const T& back() const;
// Sizing
@ -315,32 +315,33 @@ public:
//- Shrink by moving the end of the buffer 1 or more times
inline void pop_back(label n = 1);
//- Copy append an element to the end of the buffer
void append(const T& val) { this->push_back(val); }
//- Move append an element to the end of the buffer
void append(T&& val) { this->push_back(std::move(val)); }
//- Copy append multiple elements the end of the buffer
inline void append(const UList<T>& list);
inline void push_back(const UList<T>& list);
//- Copy append IndirectList elements the end of the buffer
template<class Addr>
inline void append(const IndirectListBase<T, Addr>& list);
inline void push_back(const IndirectListBase<T, Addr>& list);
//- Append an element if not already in the buffer.
// \return the change in the buffer length
inline label appendUniq(const T& val);
inline label push_uniq(const T& val);
// Other Operations
//- Return a copy of the buffer flattened into a single List.
//- Use sparingly!
List<T> list() const;
//- Reverse the buffer order, swapping elements
void reverse();
// Member Operators
//- Return the buffer flattened as a single List. Use sparingly!
List<T> operator()() const { return this->list(); }
//- Non-const access to an element in the list.
// The index is allowed to wrap in both directions
inline T& operator[](const label i);
@ -475,6 +476,41 @@ public:
//- Return a const_iterator at end of buffer
inline const_iterator end() const { return cend(); }
// Housekeeping
//- Access the first element (front). Requires !empty().
//FOAM_DEPRECATED_FOR(2022-10, "front()")
T& first() { return front(); }
//- Access the first element (front). Requires !empty().
//FOAM_DEPRECATED_FOR(2022-10, "front()")
const T& first() const { return front(); }
//- Access the last element (back). Requires !empty().
//FOAM_DEPRECATED_FOR(2022-10, "back()")
T& last() { return back(); }
//- Access the last element (back). Requires !empty().
//FOAM_DEPRECATED_FOR(2022-10, "back()")
const T& last() const { return back(); }
//- Copy append an element to the end of the buffer
//FOAM_DEPRECATED_FOR(2022-10, "push_back()")
void append(const T& val) { this->push_back(val); }
//- Move append an element to the end of the buffer
//FOAM_DEPRECATED_FOR(2022-10, "push_back()")
void append(T&& val) { this->push_back(std::move(val)); }
//- Copy append multiple elements the end of the buffer
//FOAM_DEPRECATED_FOR(2022-10, "push_back()")
void append(const UList<T>& list) { this->push_back(list); }
//- Append an element if not already in the buffer.
//FOAM_DEPRECATED_FOR(2022-10, "push_uniq()")
label appendUniq(const T& val) { return this->push_uniq(val); }
};

View File

@ -263,7 +263,7 @@ inline bool Foam::CircularBuffer<T>::found(const T& val, label pos) const
template<class T>
inline T& Foam::CircularBuffer<T>::first()
inline T& Foam::CircularBuffer<T>::front()
{
if (empty())
{
@ -275,7 +275,7 @@ inline T& Foam::CircularBuffer<T>::first()
template<class T>
inline const T& Foam::CircularBuffer<T>::first() const
inline const T& Foam::CircularBuffer<T>::front() const
{
if (empty())
{
@ -287,7 +287,7 @@ inline const T& Foam::CircularBuffer<T>::first() const
template<class T>
inline T& Foam::CircularBuffer<T>::last()
inline T& Foam::CircularBuffer<T>::back()
{
if (empty())
{
@ -299,7 +299,7 @@ inline T& Foam::CircularBuffer<T>::last()
template<class T>
inline const T& Foam::CircularBuffer<T>::last() const
inline const T& Foam::CircularBuffer<T>::back() const
{
if (empty())
{
@ -393,7 +393,7 @@ inline void Foam::CircularBuffer<T>::pop_back(label n)
template<class T>
inline Foam::label Foam::CircularBuffer<T>::appendUniq(const T& val)
inline Foam::label Foam::CircularBuffer<T>::push_uniq(const T& val)
{
if (this->found(val))
{
@ -408,7 +408,7 @@ inline Foam::label Foam::CircularBuffer<T>::appendUniq(const T& val)
template<class T>
inline void Foam::CircularBuffer<T>::append(const UList<T>& rhs)
inline void Foam::CircularBuffer<T>::push_back(const UList<T>& rhs)
{
const label len = rhs.size();
@ -429,7 +429,7 @@ inline void Foam::CircularBuffer<T>::append(const UList<T>& rhs)
template<class T>
template<class Addr>
inline void Foam::CircularBuffer<T>::append
inline void Foam::CircularBuffer<T>::push_back
(
const IndirectListBase<T, Addr>& rhs
)

View File

@ -185,20 +185,28 @@ Foam::wordList Foam::DictionaryBase<IDLListType, T>::sortedToc
template<class IDLListType, class T>
void Foam::DictionaryBase<IDLListType, T>::prepend(const word& keyword, T* ptr)
void Foam::DictionaryBase<IDLListType, T>::push_front
(
const word& keyword,
T* ptr
)
{
// NOTE: we should probably check that HashTable::insert actually worked
hashedTs_.insert(keyword, ptr);
IDLListType::prepend(ptr);
IDLListType::push_front(ptr);
}
template<class IDLListType, class T>
void Foam::DictionaryBase<IDLListType, T>::append(const word& keyword, T* ptr)
void Foam::DictionaryBase<IDLListType, T>::push_back
(
const word& keyword,
T* ptr
)
{
// NOTE: we should probably check that HashTable::insert actually worked
hashedTs_.insert(keyword, ptr);
IDLListType::append(ptr);
IDLListType::push_back(ptr);
}

View File

@ -142,10 +142,10 @@ public:
// Editing
//- Add to front of dictionary
void prepend(const word& keyword, T* ptr);
void push_front(const word& keyword, T* ptr);
//- Add to back of dictionary
void append(const word& keyword, T* ptr);
void push_back(const word& keyword, T* ptr);
//- Remove and return entry specified by keyword.
// Return nullptr if the keyword was not found.
@ -205,9 +205,24 @@ public:
}
//- Add to front of dictionary
//FOAM_DEPRECATED_FOR(2022-10, "push_front()")
void insert(const word& keyword, T* ptr)
{
this->prepend(keyword, ptr);
this->push_front(keyword, ptr);
}
//- Add to front of dictionary
//FOAM_DEPRECATED_FOR(2022-10, "push_front()")
void prepend(const word& keyword, T* ptr)
{
this->push_front(keyword, ptr);
}
//- Add to back of dictionary
//FOAM_DEPRECATED_FOR(2022-10, "push_back()")
void append(const word& keyword, T* ptr)
{
this->push_back(keyword, ptr);
}
};

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,8 +35,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef BiIndirectList_H
#define BiIndirectList_H
#ifndef Foam_BiIndirectList_H
#define Foam_BiIndirectList_H
#include "List.H"
@ -57,8 +57,7 @@ class BiIndirectList
UList<T>& posList_;
UList<T>& negList_;
labelList addressing_;
labelList addr_;
public:
@ -83,50 +82,56 @@ public:
// Member Functions
// Access
// Access
//- The number of elements in the list
inline label size() const noexcept;
//- The number of elements in the list
label size() const noexcept { return addr_.size(); }
//- True if the list is empty (ie, size() is zero).
inline bool empty() const noexcept;
//- True if the list is empty (ie, size() is zero).
bool empty() const noexcept { return addr_.empty(); }
inline const UList<T>& posList() const noexcept;
inline const UList<T>& negList() const noexcept;
//- The list of positive values (without addressing)
const UList<T>& posList() const noexcept { return posList_; }
//- Return the list addressing
inline const labelList& addressing() const noexcept;
//- The list of negative values (without addressing)
const UList<T>& negList() const noexcept { return negList_; }
//- Calculate index given whether index is into posList or negList
inline static label posIndex(const label i);
inline static label negIndex(const label i);
//- The addressing used for the list
const labelList& addressing() const noexcept { return addr_; }
//- Calculate index given whether index is into posList or negList
static label posIndex(const label i) noexcept { return i; }
static label negIndex(const label i) noexcept { return (-i-1); }
// Edit
// Edit
//- Copy reset addressing
inline void resetAddressing(const labelUList& addr);
//- Copy reset addressing
inline void resetAddressing(const labelUList& addr);
//- Move reset addressing
inline void resetAddressing(labelList&& addr);
//- Move reset addressing
inline void resetAddressing(labelList&& addr);
//- Return the addressed elements as a List
inline List<T> list() const;
// Member Operators
// Member Operators
//- Return the addressed elements as a List
inline List<T> operator()() const;
//- Return the addressed elements as a List
List<T> operator()() const { return this->list(); }
//- Return non-const access to an element
inline T& operator[](const label i);
//- Return non-const access to an element
inline T& operator[](const label i);
//- Return const access to an element
inline const T& operator[](const label i) const;
//- Return const access to an element
inline const T& operator[](const label i) const;
//- Assignment to UList of addressed elements
inline void operator=(const UList<T>& ae);
//- Assignment to UList of addressed elements
inline void operator=(const UList<T>& ae);
//- Assignment of all entries to the given value
inline void operator=(const T& val);
//- Assignment of all entries to the given value
inline void operator=(const T& val);
};

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,22 +26,6 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class T>
inline Foam::label Foam::BiIndirectList<T>::posIndex(const label i)
{
return i;
}
template<class T>
inline Foam::label Foam::BiIndirectList<T>::negIndex(const label i)
{
return -i-1;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
@ -54,7 +38,7 @@ inline Foam::BiIndirectList<T>::BiIndirectList
:
posList_(const_cast<UList<T>&>(posList)),
negList_(const_cast<UList<T>&>(negList)),
addressing_(addr)
addr_(addr)
{}
@ -68,72 +52,28 @@ inline Foam::BiIndirectList<T>::BiIndirectList
:
posList_(const_cast<UList<T>&>(posList)),
negList_(const_cast<UList<T>&>(negList)),
addressing_(std::move(addr))
addr_(std::move(addr))
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline Foam::label Foam::BiIndirectList<T>::size() const noexcept
inline void Foam::BiIndirectList<T>::resetAddressing(const labelUList& addr)
{
return addressing_.size();
addr_ = addr;
}
template<class T>
inline bool Foam::BiIndirectList<T>::empty() const noexcept
inline void Foam::BiIndirectList<T>::resetAddressing(labelList&& addr)
{
return addressing_.empty();
addr_.transfer(addr);
}
template<class T>
inline const Foam::UList<T>& Foam::BiIndirectList<T>::posList() const noexcept
{
return posList_;
}
template<class T>
inline const Foam::UList<T>& Foam::BiIndirectList<T>::negList() const noexcept
{
return negList_;
}
template<class T>
inline const Foam::labelList&
Foam::BiIndirectList<T>::addressing() const noexcept
{
return addressing_;
}
template<class T>
inline void Foam::BiIndirectList<T>::resetAddressing
(
const labelUList& addr
)
{
addressing_ = addr;
}
template<class T>
inline void Foam::BiIndirectList<T>::resetAddressing
(
labelList&& addr
)
{
addressing_.transfer(addr);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
inline Foam::List<T> Foam::BiIndirectList<T>::operator()() const
inline Foam::List<T> Foam::BiIndirectList<T>::list() const
{
List<T> result(size());
@ -146,51 +86,39 @@ inline Foam::List<T> Foam::BiIndirectList<T>::operator()() const
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
inline T& Foam::BiIndirectList<T>::operator[](const label i)
{
const label index = addressing_[i];
const label index = addr_[i];
if (index >= 0)
{
return posList_[index];
}
else
{
return negList_[-index-1];
}
return (index >= 0 ? posList_[index] : negList_[-index-1]);
}
template<class T>
inline const T& Foam::BiIndirectList<T>::operator[](const label i) const
{
const label index = addressing_[i];
const label index = addr_[i];
if (index >= 0)
{
return posList_[index];
}
else
{
return negList_[-index-1];
}
return (index >= 0 ? posList_[index] : negList_[-index-1]);
}
template<class T>
inline void Foam::BiIndirectList<T>::operator=(const UList<T>& ae)
{
if (addressing_.size() != ae.size())
if (addr_.size() != ae.size())
{
FatalErrorInFunction
<< "Addressing and list of addressed elements "
"have different sizes: "
<< addressing_.size() << " " << ae.size()
<< addr_.size() << " " << ae.size()
<< abort(FatalError);
}
forAll(addressing_, i)
forAll(addr_, i)
{
operator[](i) = ae[i];
}
@ -200,7 +128,7 @@ inline void Foam::BiIndirectList<T>::operator=(const UList<T>& ae)
template<class T>
inline void Foam::BiIndirectList<T>::operator=(const T& val)
{
forAll(addressing_, i)
forAll(addr_, i)
{
operator[](i) = val;
}

View File

@ -123,49 +123,35 @@ public:
// Access
//- The number of elements in the list
inline label size() const noexcept
{
return addr_.size();
}
label size() const noexcept { return addr_.size(); }
//- True if the list is empty (ie, size() is zero).
inline bool empty() const noexcept
{
return addr_.empty();
}
bool empty() const noexcept { return addr_.empty(); }
//- The list of values (without addressing)
inline const UList<T>& values() const noexcept
{
return values_;
}
const UList<T>& values() const noexcept { return values_; }
//- The list of values (without addressing)
inline UList<T>& values() noexcept
{
return values_;
}
UList<T>& values() noexcept { return values_; }
//- The addressing used for the list
inline const Addr& addressing() const noexcept
{
return addr_;
}
const Addr& addressing() const noexcept { return addr_; }
//- True if all entries have identical values, and list is non-empty
inline bool uniform() const;
//- The first element of the list.
inline const T& first() const;
inline const T& front() const;
//- The first element of the list.
inline T& first();
inline T& front();
//- The last element of the list.
inline const T& last() const;
inline const T& back() const;
//- The last element of the list.
inline T& last();
inline T& back();
//- The forward circular index. The next index in the list
//- which returns to the first at the end of the list
@ -187,6 +173,9 @@ public:
//- Return reverse circular value (ie, previous value in the list)
inline T& rcValue(const label i);
//- Return the addressed elements as a List
inline List<T> list() const;
// Search
@ -211,7 +200,7 @@ public:
// Member Operators
//- Return the addressed elements as a List
inline List<T> operator()() const;
List<T> operator()() const { return this->list(); }
//- Non-const access to an element in the list
inline T& operator[](const label i);
@ -374,6 +363,25 @@ public:
//- Write List, with line-breaks in ASCII when length exceeds shortLen.
// Using '0' suppresses line-breaks entirely.
Ostream& writeList(Ostream& os, const label shortLen=0) const;
// Housekeeping
//- Access first element of the list, position [0]
//FOAM_DEPRECATED_FOR(2022-10, "front()")
T& first() { return front(); }
//- Access first element of the list
//FOAM_DEPRECATED_FOR(2022-10, "front()")
const T& first() const { return front(); };
//- Access last element of the list, position [size()-1]
//FOAM_DEPRECATED_FOR(2022-10, "back()")
T& last() { return back(); }
//- Access last element of the list, position [size()-1]
//FOAM_DEPRECATED_FOR(2022-10, "back()")
const T& last() const { return back(); };
};

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -124,28 +124,28 @@ inline Foam::label Foam::IndirectListBase<T, Addr>::rcIndex(const label i) const
template<class T, class Addr>
inline const T& Foam::IndirectListBase<T, Addr>::first() const
inline const T& Foam::IndirectListBase<T, Addr>::front() const
{
return values_[addr_.first()];
return values_[addr_.front()];
}
template<class T, class Addr>
inline T& Foam::IndirectListBase<T, Addr>::first()
inline T& Foam::IndirectListBase<T, Addr>::front()
{
return values_[addr_.first()];
return values_[addr_.front()];
}
template<class T, class Addr>
inline const T& Foam::IndirectListBase<T, Addr>::last() const
inline const T& Foam::IndirectListBase<T, Addr>::back() const
{
return values_[addr_.last()];
return values_[addr_.back()];
}
template<class T, class Addr>
inline T& Foam::IndirectListBase<T, Addr>::last()
inline T& Foam::IndirectListBase<T, Addr>::back()
{
return values_[addr_.last()];
return values_[addr_.back()];
}
@ -176,12 +176,8 @@ inline T& Foam::IndirectListBase<T, Addr>::rcValue(const label i)
return values_[this->rcIndex(i)];
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Addr>
inline Foam::List<T>
Foam::IndirectListBase<T, Addr>::operator()() const
inline Foam::List<T> Foam::IndirectListBase<T, Addr>::list() const
{
const label len = addr_.size();
@ -197,6 +193,8 @@ Foam::IndirectListBase<T, Addr>::operator()() const
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Addr>
inline T& Foam::IndirectListBase<T, Addr>::operator[](const label i)
{

View File

@ -37,7 +37,7 @@ Foam::ILList<LListBase, T>::ILList(const ILList<LListBase, T>& lst)
{
for (const auto& item : lst)
{
this->append(item.clone().ptr());
this->push_back(item.clone().ptr());
}
}
@ -63,7 +63,7 @@ Foam::ILList<LListBase, T>::ILList
{
for (const auto& item : lst)
{
this->append(item.clone(cloneArg).ptr());
this->push_back(item.clone(cloneArg).ptr());
}
}
@ -80,11 +80,27 @@ Foam::ILList<LListBase, T>::~ILList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class LListBase, class T>
bool Foam::ILList<LListBase, T>::eraseHead()
void Foam::ILList<LListBase, T>::pop_front(label n)
{
T* p = this->removeHead();
delete p;
return bool(p);
if (n > this->size())
{
n = this->size();
}
while (n > 0)
{
T* p = this->removeHead();
delete p;
--n;
}
}
template<class LListBase, class T>
void Foam::ILList<LListBase, T>::clear()
{
this->pop_front(this->size());
LListBase::clear();
}
@ -97,20 +113,6 @@ bool Foam::ILList<LListBase, T>::erase(T* item)
}
template<class LListBase, class T>
void Foam::ILList<LListBase, T>::clear()
{
label len = this->size();
while (len--)
{
eraseHead();
}
LListBase::clear();
}
template<class LListBase, class T>
void Foam::ILList<LListBase, T>::transfer(ILList<LListBase, T>& lst)
{
@ -128,7 +130,7 @@ void Foam::ILList<LListBase, T>::operator=(const ILList<LListBase, T>& lst)
for (const auto& item : lst)
{
this->append(item.clone().ptr());
this->push_back(item.clone().ptr());
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -106,21 +106,21 @@ public:
ILList(Istream& is, const INew& inew);
//- Destructor
//- Destructor. Calls clear()
~ILList();
// Member Functions
//- Remove the head element specified from the list and delete it
bool eraseHead();
//- Clear the contents of the list
void clear();
//- Remove first element(s) from the list (deletes pointers)
void pop_front(label n = 1);
//- Remove the specified element from the list and delete it
bool erase(T* item);
//- Clear the contents of the list
void clear();
//- Transfer the contents of the argument into this List
//- and annul the argument list.
void transfer(ILList<LListBase, T>& lst);

View File

@ -60,7 +60,7 @@ void Foam::ILList<LListBase, T>::readIstream(Istream& is, const INew& inew)
for (label i=0; i<len; ++i)
{
T* p = inew(is).ptr();
this->append(p);
this->push_back(p);
is.fatalCheck
(
@ -72,7 +72,7 @@ void Foam::ILList<LListBase, T>::readIstream(Istream& is, const INew& inew)
else // BEGIN_BLOCK
{
T* p = inew(is).ptr();
this->append(p);
this->push_back(p);
is.fatalCheck
(
@ -82,7 +82,7 @@ void Foam::ILList<LListBase, T>::readIstream(Istream& is, const INew& inew)
for (label i=1; i<len; ++i)
{
this->append(new T(*p)); // Copy construct
this->push_back(new T(*p)); // Copy construct
}
}
}
@ -100,7 +100,7 @@ void Foam::ILList<LListBase, T>::readIstream(Istream& is, const INew& inew)
is.putBack(tok);
T* p = inew(is).ptr();
this->append(p);
this->push_back(p);
is >> tok;
is.fatalCheck(FUNCTION_NAME);

View File

@ -37,7 +37,7 @@ Foam::LList<LListBase, T>::LList(const LList<LListBase, T>& lst)
{
for (const T& val : lst)
{
this->append(val);
this->push_back(val);
}
}
@ -58,7 +58,7 @@ Foam::LList<LListBase, T>::LList(std::initializer_list<T> lst)
{
for (const T& val : lst)
{
this->append(val);
this->push_back(val);
}
}
@ -75,15 +75,26 @@ Foam::LList<LListBase, T>::~LList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class LListBase, class T>
void Foam::LList<LListBase, T>::clear()
void Foam::LList<LListBase, T>::pop_front(label n)
{
label len = this->size();
while (len--)
if (n > this->size())
{
this->eraseHead();
n = this->size();
}
while (n > 0)
{
link* p = static_cast<link*>(LListBase::removeHead());
delete p;
--n;
}
}
template<class LListBase, class T>
void Foam::LList<LListBase, T>::clear()
{
this->pop_front(this->size());
LListBase::clear();
}
@ -105,7 +116,7 @@ void Foam::LList<LListBase, T>::operator=(const LList<LListBase, T>& lst)
for (const T& val : lst)
{
this->append(val);
this->push_back(val);
}
}
@ -126,7 +137,7 @@ void Foam::LList<LListBase, T>::operator=(std::initializer_list<T> lst)
for (const T& val : lst)
{
this->append(val);
this->push_back(val);
}
}

View File

@ -177,13 +177,13 @@ public:
//- Construct and copy add initial item
explicit LList(const T& elem)
{
this->prepend(elem);
this->push_front(elem);
}
//- Construct and move add initial item
explicit LList(T&& elem)
{
this->prepend(std::move(elem));
this->push_front(std::move(elem));
}
//- Construct from Istream
@ -199,68 +199,66 @@ public:
LList(std::initializer_list<T> lst);
//- Destructor
//- Destructor. Calls clear()
~LList();
// Member Functions
//- The first entry in the list
reference first()
reference front()
{
return link::ref(LListBase::first());
return link::ref(LListBase::front());
}
//- The first entry in the list (const access)
const_reference first() const
const_reference front() const
{
return link::ref(LListBase::first());
return link::ref(LListBase::front());
}
//- The last entry in the list
reference last()
reference back()
{
return link::ref(LListBase::last());
return link::ref(LListBase::back());
}
//- The last entry in the list (const access)
const_reference last() const
const_reference back() const
{
return link::ref(LListBase::last());
return link::ref(LListBase::back());
}
//- Add copy at front of list
void prepend(const T& elem)
void push_front(const T& elem)
{
LListBase::prepend(new link(elem));
LListBase::push_front(new link(elem));
}
//- Move construct at front of list
void prepend(T&& elem)
void push_front(T&& elem)
{
LListBase::prepend(new link(std::move(elem)));
LListBase::push_front(new link(std::move(elem)));
}
//- Add copy at back of list
void append(const T& elem)
void push_back(const T& elem)
{
LListBase::append(new link(elem));
LListBase::push_back(new link(elem));
}
//- Move construct at back of list
void append(T&& elem)
void push_back(T&& elem)
{
LListBase::append(new link(std::move(elem)));
LListBase::push_back(new link(std::move(elem)));
}
//- Erase the first entry
bool eraseHead()
{
link* p = static_cast<link*>(LListBase::removeHead());
delete p;
return bool(p);
}
//- Delete contents of list
void clear();
//- Remove first element(s) from the list (deletes pointers)
void pop_front(label n = 1);
//- Remove and return first entry
T removeHead()
@ -280,10 +278,6 @@ public:
return link::remove(LListBase::remove(iter));
}
//- Delete contents of list
void clear();
//- Transfer the contents of the argument into this List
//- and annul the argument list.
void transfer(LList<LListBase, T>& lst);
@ -576,11 +570,45 @@ public:
// Housekeeping
//- Add copy at front of list. Same as prepend()
void insert(const T& elem) { this->prepend(elem); }
//- The first entry in the list
//FOAM_DEPRECATED_FOR(2022-10, "front()")
reference first() { return front(); }
//- Move construct at front of list. Same as prepend()
void insert(T&& elem) { this->prepend(std::move(elem)); }
//- The first entry in the list (const access)
//FOAM_DEPRECATED_FOR(2022-10, "front()")
const_reference first() const { return front(); }
//- The last entry in the list
//FOAM_DEPRECATED_FOR(2022-10, "back()")
reference last() { return back(); }
//- The last entry in the list (const access)
//FOAM_DEPRECATED_FOR(2022-10, "back()")
const_reference last() const { return back(); }
//- Add copy at front of list
//FOAM_DEPRECATED_FOR(2022-10, "push_front()")
void prepend(const T& elem) { push_front(elem); }
//- Move construct at front of list
//FOAM_DEPRECATED_FOR(2022-10, "push_front()")
void prepend(T&& elem) { push_front(std::move(elem)); }
//- Add copy at back of list
//FOAM_DEPRECATED_FOR(2022-10, "push_back()")
void append(const T& elem) { push_back(elem); }
//- Move construct at back of list
//FOAM_DEPRECATED_FOR(2022-10, "push_back()")
void append(T&& elem) { push_back(std::move(elem)); }
//- Add copy at front of list. Same as push_front()
//FOAM_DEPRECATED_FOR(2022-01, "push_front()")
void insert(const T& elem) { push_front(elem); }
//- Move construct at front of list. Same as push_front()
//FOAM_DEPRECATED_FOR(2022-01, "push_front()")
void insert(T&& elem) { push_front(std::move(elem)); }
};

View File

@ -70,7 +70,7 @@ Foam::Istream& Foam::LList<LListBase, T>::readList(Istream& is)
{
T elem;
is >> elem;
list.append(std::move(elem));
list.push_back(std::move(elem));
}
}
else
@ -82,7 +82,7 @@ Foam::Istream& Foam::LList<LListBase, T>::readList(Istream& is)
for (label i=0; i<len; ++i)
{
list.append(elem);
list.push_back(elem);
}
}
}
@ -101,7 +101,7 @@ Foam::Istream& Foam::LList<LListBase, T>::readList(Istream& is)
T elem;
is >> elem;
list.append(std::move(elem));
list.push_back(std::move(elem));
is >> tok;
is.fatalCheck(FUNCTION_NAME);

View File

@ -37,7 +37,7 @@ Foam::LPtrList<LListBase, T>::LPtrList(const LPtrList<LListBase, T>& lst)
{
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
{
this->append((*iter).clone().ptr());
this->push_back((*iter).clone().ptr());
}
}
@ -63,24 +63,26 @@ Foam::LPtrList<LListBase, T>::~LPtrList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class LListBase, class T>
bool Foam::LPtrList<LListBase, T>::eraseHead()
void Foam::LPtrList<LListBase, T>::pop_front(label n)
{
T* p = this->removeHead();
delete p;
return bool(p);
if (n > this->size())
{
n = this->size();
}
while (n > 0)
{
T* p = this->removeHead();
delete p;
--n;
}
}
template<class LListBase, class T>
void Foam::LPtrList<LListBase, T>::clear()
{
label len = this->size();
while (len--)
{
eraseHead();
}
this->pop_front(this->size());
LList<LListBase, T*>::clear();
}
@ -102,7 +104,7 @@ void Foam::LPtrList<LListBase, T>::operator=(const LPtrList<LListBase, T>& lst)
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
{
this->append((*iter).clone().ptr());
this->push_back((*iter).clone().ptr());
}
}

View File

@ -98,7 +98,7 @@ public:
typedef const T& const_reference;
// Forward declaration of STL iterators
// Forward Declaration (iterators)
class iterator;
class const_iterator;
@ -118,7 +118,7 @@ public:
//- Construct and add initial item pointer
explicit LPtrList(T* item)
{
this->prepend(item);
this->push_front(item);
}
//- Copy construct by using 'clone()' for each element
@ -135,39 +135,38 @@ public:
explicit LPtrList(Istream& is);
//- Destructor
//- Destructor. Calls clear()
~LPtrList();
// Member Functions
//- The first entry in the list
T& first()
T& front()
{
return *(parent_type::first());
return *(parent_type::front());
}
//- The first entry in the list (const access)
const T& first() const
const T& front() const
{
return *(parent_type::first());
return *(parent_type::front());
}
//- The last entry in the list
T& last()
T& back()
{
return *(parent_type::last());
return *(parent_type::back());
}
//- The last entry in the list (const access)
const T& last() const
const T& back() const
{
return *(parent_type::last());
return *(parent_type::back());
}
//- Remove the head element from the list and delete the pointer
bool eraseHead();
//- Remove first element(s) from the list (deletes pointers)
void pop_front(label n = 1);
//- Clear the contents of the list
void clear();
@ -177,7 +176,7 @@ public:
void transfer(LPtrList<LListBase, T>& lst);
// Member operators
// Member Operators
//- Copy assign by using 'clone()' for each element
void operator=(const LPtrList<LListBase, T>& lst);
@ -428,6 +427,25 @@ public:
Ostream& os,
const LPtrList<LListBase, T>& list
);
// Housekeeping
//- The first entry in the list
//FOAM_DEPRECATED_FOR(2022-10, "front()")
T& first() { return front(); }
//- The first entry in the list (const access)
//FOAM_DEPRECATED_FOR(2022-10, "front()")
const T& first() const { return front(); }
//- The last entry in the list
//FOAM_DEPRECATED_FOR(2022-10, "back()")
T& last() { return back(); }
//- The last entry in the list (const access)
//FOAM_DEPRECATED_FOR(2022-10, "back()")
const T& last() const { return back(); }
};

View File

@ -61,7 +61,7 @@ void Foam::LPtrList<LListBase, T>::readIstream(Istream& is, const INew& inew)
for (label i=0; i<len; ++i)
{
T* p = inew(is).ptr();
this->append(p);
this->push_back(p);
is.fatalCheck
(
@ -73,7 +73,7 @@ void Foam::LPtrList<LListBase, T>::readIstream(Istream& is, const INew& inew)
else // Assumed to be token::BEGIN_BLOCK
{
T* p = inew(is).ptr();
this->append(p);
this->push_back(p);
is.fatalCheck
(
@ -83,7 +83,7 @@ void Foam::LPtrList<LListBase, T>::readIstream(Istream& is, const INew& inew)
for (label i=1; i<len; ++i)
{
this->append(p->clone().ptr());
this->push_back(p->clone().ptr());
}
}
}
@ -99,7 +99,7 @@ void Foam::LPtrList<LListBase, T>::readIstream(Istream& is, const INew& inew)
while (!tok.isPunctuation(token::END_LIST))
{
is.putBack(tok);
this->append(inew(is).ptr());
this->push_back(inew(is).ptr());
is >> tok;
is.fatalCheck(FUNCTION_NAME);

View File

@ -35,7 +35,7 @@ Foam::UILList<LListBase, T>::UILList(const UILList<LListBase, T>& lst)
{
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
{
this->append(&(*iter));
this->push_back(&(*iter));
}
}
@ -49,7 +49,7 @@ void Foam::UILList<LListBase, T>::operator=(const UILList<LListBase, T>& lst)
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
{
this->append(&(*iter));
this->push_back(&(*iter));
}
}

View File

@ -41,6 +41,7 @@ SourceFiles
#include "label.H"
#include "uLabel.H"
#include "stdFoam.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -112,37 +113,37 @@ public:
//- Construct and add initial item pointer
explicit UILList(T* item)
{
this->prepend(item);
this->push_front(item);
}
//- Construct as copy
UILList(const UILList<LListBase, T>& lst);
UILList(const UILList<LListBase, T>& list);
// Member Functions
//- The first entry in the list
T* first()
T* front()
{
return static_cast<T*>(LListBase::first());
return static_cast<T*>(LListBase::front());
}
//- The first entry in the list (const access)
const T* first() const
const T* front() const
{
return static_cast<const T*>(LListBase::first());
return static_cast<const T*>(LListBase::front());
}
//- The last entry in the list
T* last()
T* back()
{
return static_cast<T*>(LListBase::last());
return static_cast<T*>(LListBase::back());
}
//- The last entry in the list (const access)
const T* last() const
const T* back() const
{
return static_cast<const T*>(LListBase::last());
return static_cast<const T*>(LListBase::back());
}
@ -165,7 +166,7 @@ public:
}
// Member operators
// Member Operators
//- Copy assignment
void operator=(const UILList<LListBase, T>& lst);
@ -446,6 +447,25 @@ public:
{
return crend();
}
// Housekeeping
//- The first entry in the list
//FOAM_DEPRECATED_FOR(2022-10, "front()")
T* first() { return front(); }
//- The first entry in the list (const access)
//FOAM_DEPRECATED_FOR(2022-10, "front()")
const T* first() const { return front(); }
//- The last entry in the list
//FOAM_DEPRECATED_FOR(2022-10, "back()")
T* last() { return back(); }
//- The last entry in the list (const access)
//FOAM_DEPRECATED_FOR(2022-10, "back()")
const T* last() const { return back(); }
};

View File

@ -31,7 +31,7 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::DLListBase::prepend(DLListBase::link* item)
void Foam::DLListBase::push_front(DLListBase::link* item)
{
if (!item)
{
@ -56,7 +56,7 @@ void Foam::DLListBase::prepend(DLListBase::link* item)
}
void Foam::DLListBase::append(DLListBase::link* item)
void Foam::DLListBase::push_back(DLListBase::link* item)
{
if (!item)
{
@ -161,15 +161,17 @@ bool Foam::DLListBase::swapDown(DLListBase::link* a)
Foam::DLListBase::link* Foam::DLListBase::removeHead()
{
--size_;
if (!first_)
{
FatalErrorInFunction
<< "remove from empty list"
<< abort(FatalError);
// return nullptr;
}
--size_;
DLListBase::link *ret = first_;
first_ = first_->next_;

View File

@ -73,13 +73,13 @@ public:
link* next_ = nullptr;
//- Default construct
link() = default;
link() noexcept = default;
//- Check if the node is registered with the list
inline bool registered() const noexcept;
//- Node registered (linked) in a list?
bool registered() const noexcept { return prev_ && next_; }
//- Deregister the node after removal
inline void deregister() noexcept;
//- Deregister the node (after removal)
void deregister() noexcept { prev_ = next_ = nullptr; }
};
@ -124,7 +124,7 @@ protected:
public:
// Forward declaration of iterators
// Forward Declarations (iterators)
class iterator;
friend class iterator;
@ -157,23 +157,23 @@ public:
inline bool empty() const noexcept;
//- Return first entry
inline link* first();
inline link* front();
//- Return const access to first entry
inline const link* first() const;
inline const link* front() const;
//- Return last entry
inline link* last();
inline link* back();
//- Return const access to last entry
inline const link* last() const;
inline const link* back() const;
//- Add at front of list
void prepend(link* item);
void push_front(link* item);
//- Add at back of list
void append(link* item);
void push_back(link* item);
//- Swap this element with the one above unless it is at the top
bool swapUp(link* item);
@ -320,6 +320,33 @@ public:
//- End of list for reverse iterators
inline const const_iterator& crend() const;
// Housekeeping
//- Return first entry
//FOAM_DEPRECATED_FOR(2022-10, "front()")
link* first() { return front(); }
//- Return const access to first entry
//FOAM_DEPRECATED_FOR(2022-10, "front()")
const link* first() const { return front(); }
//- Return last entry
//FOAM_DEPRECATED_FOR(2022-10, "back()")
link* last() { return back(); }
//- Return const access to last entry
//FOAM_DEPRECATED_FOR(2022-10, "back()")
const link* last() const { return back(); }
//- Add at front of list
//FOAM_DEPRECATED_FOR(2022-10, "push_front()")
void prepend(link* item) { push_front(item); }
//- Add at back of list
//FOAM_DEPRECATED_FOR(2022-10, "push_back()")
void append(link* item) { push_back(item); }
};

View File

@ -99,18 +99,6 @@ Foam::DLListBase::crend() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline bool Foam::DLListBase::link::registered() const noexcept
{
return prev_ != nullptr && next_ != nullptr;
}
inline void Foam::DLListBase::link::deregister() noexcept
{
prev_ = next_ = nullptr;
}
inline Foam::label Foam::DLListBase::size() const noexcept
{
return size_;
@ -124,7 +112,7 @@ inline bool Foam::DLListBase::empty() const noexcept
inline Foam::DLListBase::link*
Foam::DLListBase::first()
Foam::DLListBase::front()
{
if (!size_)
{
@ -137,7 +125,7 @@ Foam::DLListBase::first()
inline const Foam::DLListBase::link*
Foam::DLListBase::first() const
Foam::DLListBase::front() const
{
if (!size_)
{
@ -150,7 +138,7 @@ Foam::DLListBase::first() const
inline Foam::DLListBase::link*
Foam::DLListBase::last()
Foam::DLListBase::back()
{
if (!size_)
{
@ -163,7 +151,7 @@ Foam::DLListBase::last()
inline const Foam::DLListBase::link*
Foam::DLListBase::last() const
Foam::DLListBase::back() const
{
if (!size_)
{

View File

@ -31,7 +31,7 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::SLListBase::prepend(SLListBase::link* item)
void Foam::SLListBase::push_front(SLListBase::link* item)
{
if (!item)
{
@ -53,7 +53,7 @@ void Foam::SLListBase::prepend(SLListBase::link* item)
}
void Foam::SLListBase::append(SLListBase::link* item)
void Foam::SLListBase::push_back(SLListBase::link* item)
{
if (!item)
{
@ -76,15 +76,17 @@ void Foam::SLListBase::append(SLListBase::link* item)
Foam::SLListBase::link* Foam::SLListBase::removeHead()
{
--size_;
if (last_ == nullptr)
{
FatalErrorInFunction
<< "remove from empty list"
<< abort(FatalError);
// return nullptr;
}
--size_;
SLListBase::link *ret = last_->next_;
if (ret == last_)
@ -96,6 +98,7 @@ Foam::SLListBase::link* Foam::SLListBase::removeHead()
last_->next_ = ret->next_;
}
ret->deregister();
return ret;
}
@ -125,6 +128,7 @@ Foam::SLListBase::link* Foam::SLListBase::remove(SLListBase::link* item)
last_ = prev;
}
item->deregister();
return item;
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -70,7 +70,10 @@ public:
link* next_ = nullptr;
//- Default construct
link() = default;
link() noexcept = default;
//- Deregister the node (after removal)
void deregister() noexcept { next_ = nullptr; }
};
@ -112,7 +115,7 @@ protected:
public:
// Forward declaration of iterators
// Forward Declarations (iterators)
class iterator;
friend class iterator;
@ -145,23 +148,23 @@ public:
inline bool empty() const noexcept;
//- Return first entry
inline link* first();
inline link* front();
//- Return const access to first entry
inline const link* first() const;
inline const link* front() const;
//- Return last entry
inline link* last();
inline link* back();
//- Return const access to last entry
inline const link* last() const;
inline const link* back() const;
//- Add at front of list
void prepend(link* item);
void push_front(link* item);
//- Add at back of list
void append(link* item);
void push_back(link* item);
//- Remove and return first entry
link* removeHead();
@ -293,6 +296,33 @@ public:
//- No reverse iteration
const const_iterator& crend() const = delete;
// Housekeeping
//- Return first entry
//FOAM_DEPRECATED_FOR(2022-10, "front()")
link* first() { return front(); }
//- Return const access to first entry
//FOAM_DEPRECATED_FOR(2022-10, "front()")
const link* first() const { return front(); }
//- Return last entry
//FOAM_DEPRECATED_FOR(2022-10, "back()")
link* last() { return back(); }
//- Return const access to last entry
//FOAM_DEPRECATED_FOR(2022-10, "back()")
const link* last() const { return back(); }
//- Add at front of list
//FOAM_DEPRECATED_FOR(2022-10, "push_front()")
void prepend(link* item) { push_front(item); }
//- Add at back of list
//FOAM_DEPRECATED_FOR(2022-10, "push_back()")
void append(link* item) { push_back(item); }
};

View File

@ -83,7 +83,7 @@ inline bool Foam::SLListBase::empty() const noexcept
inline Foam::SLListBase::link*
Foam::SLListBase::first()
Foam::SLListBase::front()
{
if (!size_)
{
@ -96,7 +96,7 @@ Foam::SLListBase::first()
inline const Foam::SLListBase::link*
Foam::SLListBase::first() const
Foam::SLListBase::front() const
{
if (!size_)
{
@ -109,7 +109,7 @@ Foam::SLListBase::first() const
inline Foam::SLListBase::link*
Foam::SLListBase::last()
Foam::SLListBase::back()
{
if (!size_)
{
@ -122,7 +122,7 @@ Foam::SLListBase::last()
inline const Foam::SLListBase::link*
Foam::SLListBase::last() const
Foam::SLListBase::back() const
{
if (!size_)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -66,25 +66,25 @@ public:
//- Const reference to the top element
const T& top() const
{
return this->last();
return this->back();
}
//- Const reference to the bottom element
const T& bottom() const
{
return this->first();
return this->front();
}
//- Push an element onto the back of the stack
void push(const T& elem)
{
this->append(elem);
this->push_back(elem);
}
//- Move an element onto the back of the stack
void push(T&& elem)
{
this->append(std::move(elem));
this->push_back(std::move(elem));
}
//- Pop the bottom element off the stack

Some files were not shown because too many files have changed in this diff Show More