STYLE: emplace_back/push_back instead of append in tree algorithms

This commit is contained in:
Mark Olesen
2023-02-24 18:48:12 +01:00
parent 117173aaba
commit 0fc2c817e1
3 changed files with 26 additions and 29 deletions

View File

@ -116,7 +116,7 @@ void Foam::AABBTree<Type>::createBoxes
{
if (isUsedPoint.set(pointI))
{
component.append(points[pointI][maxDir]);
component.push_back(points[pointI][maxDir]);
}
}
}
@ -167,12 +167,12 @@ void Foam::AABBTree<Type>::createBoxes
// if it crosses the bin boundaries
if (addMin)
{
minBinObjectIDs.append(objI);
minBinObjectIDs.push_back(objI);
minBb.add(points, obj);
}
if (addMax)
{
maxBinObjectIDs.append(objI);
maxBinObjectIDs.push_back(objI);
maxBb.add(points, obj);
}
}
@ -209,13 +209,13 @@ void Foam::AABBTree<Type>::createBoxes
{
// New leaf
minI = nodes.size();
nodes.append(labelPair(-1, -1));
nodes.emplace_back(-1, -1);
}
else
{
// Update existing leaf
minI = -addressing.size() - 1;
addressing.append(minBinObjectIDs);
addressing.push_back(minBinObjectIDs);
}
label maxI;
@ -223,13 +223,13 @@ void Foam::AABBTree<Type>::createBoxes
{
// New leaf
maxI = nodes.size();
nodes.append(labelPair(-1, -1));
nodes.emplace_back(-1, -1);
}
else
{
// Update existing leaf
maxI = -addressing.size() - 1;
addressing.append(maxBinObjectIDs);
addressing.push_back(maxBinObjectIDs);
}
nodes(nodeI) = labelPair(minI, maxI);
@ -308,7 +308,7 @@ Foam::AABBTree<Type>::AABBTree
DynamicList<labelPair> nodes(maxLevel);
DynamicList<labelList> addr(maxLevel);
nodes.append(labelPair(-1, -1));
nodes.emplace_back(-1, -1);
treeBoundBox topBb(points);
topBb.inflate(0.01);
@ -356,13 +356,13 @@ Foam::AABBTree<Type>::AABBTree
{
if (nodes[nodeI].first() < 0)
{
boundBoxes.append(bbs[nodeI].first());
addressing.append(addr[-(nodes[nodeI].first() + 1)]);
boundBoxes.push_back(bbs[nodeI].first());
addressing.push_back(addr[-(nodes[nodeI].first() + 1)]);
}
if (nodes[nodeI].second() < 0)
{
boundBoxes.append(bbs[nodeI].second());
addressing.append(addr[-(nodes[nodeI].second() + 1)]);
boundBoxes.push_back(bbs[nodeI].second());
addressing.push_back(addr[-(nodes[nodeI].second() + 1)]);
}
}

View File

@ -56,7 +56,7 @@ void Foam::dynamicIndexedOctree<Type>::divide
{
if (shapes_.overlaps(index, subBbs))
{
contains.append(index);
contains.push_back(index);
}
}
}
@ -117,7 +117,7 @@ Foam::dynamicIndexedOctree<Type>::divide
{
// Append to contents
contentIndex = contents_.size();
contents_.append(std::move(subIndices));
contents_.push_back(std::move(subIndices));
}
nod.subNodes_[octant] = contentPlusOctant(contentIndex, octant);
@ -136,7 +136,7 @@ Foam::dynamicIndexedOctree<Type>::divide
const label newNodeId = nodes_.size();
nodes_.append(nod);
nodes_.push_back(nod);
nodes_[parentNodeIndex].subNodes_[octantToBeDivided]
= nodePlusOctant(newNodeId, octantToBeDivided);
@ -2463,13 +2463,12 @@ bool Foam::dynamicIndexedOctree<Type>::insert(label startIndex, label endIndex)
if (nodes_.empty())
{
contents_.append(DynamicList<label>(1));
contents_[0].append(0);
contents_.emplace_back(1).push_back(0);
// Create topnode.
node topNode = divide(bb_, 0, -1, 0);
nodes_.append(topNode);
nodes_.push_back(topNode);
startIndex++;
}
@ -2528,7 +2527,7 @@ bool Foam::dynamicIndexedOctree<Type>::insertIndex
{
const label contentI = getContent(subNodeLabel);
contents_[contentI].append(index);
contents_[contentI].push_back(index);
recursiveSubDivision
(
@ -2548,11 +2547,9 @@ bool Foam::dynamicIndexedOctree<Type>::insertIndex
if (shapes().overlaps(index, subBb))
{
label sz = contents_.size();
const label sz = contents_.size();
contents_.append(DynamicList<label>(1));
contents_[sz].append(index);
contents_.emplace_back(1).push_back(index);
nodes_[nodIndex].subNodes_[octant]
= contentPlusOctant(sz, octant);
@ -2635,7 +2632,7 @@ Foam::label Foam::dynamicIndexedOctree<Type>::removeIndex
if (oldIndex != index)
{
newContent.append(oldIndex);
newContent.push_back(oldIndex);
}
}

View File

@ -55,7 +55,7 @@ void Foam::indexedOctree<Type>::divide
{
if (shapes_.overlaps(index, subBbs))
{
contains.append(index);
contains.push_back(index);
}
}
@ -117,7 +117,7 @@ Foam::indexedOctree<Type>::divide
{
// Append to contents
contentIndex = contents.size();
contents.append(std::move(subIndices));
contents.push_back(std::move(subIndices));
}
nod.subNodes_[octant] = contentPlusOctant(contentIndex, octant);
@ -171,7 +171,7 @@ void Foam::indexedOctree<Type>::splitNodes
node subNode(divide(bb, contents, contentI));
subNode.parent_ = nodeI;
label sz = nodes.size();
nodes.append(subNode);
nodes.push_back(subNode);
nodes[nodeI].subNodes_[octant] = nodePlusOctant(sz, octant);
}
}
@ -2172,11 +2172,11 @@ Foam::indexedOctree<Type>::indexedOctree
// Start off with one node with all shapes in it.
DynamicList<node> nodes(label(shapes.size() / maxLeafRatio));
DynamicList<labelList> contents(label(shapes.size() / maxLeafRatio));
contents.append(identity(shapes.size()));
contents.push_back(identity(shapes.size()));
// Create topnode.
node topNode(divide(bb, contents, 0));
nodes.append(topNode);
nodes.push_back(topNode);
// Now have all contents at level 1. Create levels by splitting levels