mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: split off template-invariant part of indexedOctree node indexing
- code reduction, reinherit for dynamicIndexedOctree ENH: additional OBJ writing, statistics
This commit is contained in:
committed by
Andrew Heather
parent
e5006a62d7
commit
3384747f9b
@ -179,7 +179,7 @@ void Foam::dynamicIndexedOctree<Type>::divide
|
||||
|
||||
|
||||
template<class Type>
|
||||
typename Foam::dynamicIndexedOctree<Type>::node
|
||||
Foam::dynamicIndexedOctreeBase::node
|
||||
Foam::dynamicIndexedOctree<Type>::divide
|
||||
(
|
||||
const treeBoundBox& bb,
|
||||
@ -295,9 +295,9 @@ void Foam::dynamicIndexedOctree<Type>::recursiveSubDivision
|
||||
|
||||
// Recursively divide the contents until maxLevels_ is
|
||||
// reached or the content sizes are less than minSize_
|
||||
for (direction subOct = 0; subOct < 8; subOct++)
|
||||
for (direction subOct = 0; subOct < node::nChildren; ++subOct)
|
||||
{
|
||||
const labelBits& subNodeLabel = nod.subNodes_[subOct];
|
||||
const labelBits subNodeLabel = nod.subNodes_[subOct];
|
||||
|
||||
if (isContent(subNodeLabel))
|
||||
{
|
||||
@ -335,7 +335,7 @@ Foam::volumeType Foam::dynamicIndexedOctree<Type>::calcVolumeType
|
||||
|
||||
volumeType myType = volumeType::UNKNOWN;
|
||||
|
||||
for (direction octant = 0; octant < nod.subNodes_.size(); octant++)
|
||||
for (direction octant = 0; octant < node::nChildren; ++octant)
|
||||
{
|
||||
volumeType subType;
|
||||
|
||||
@ -1027,7 +1027,7 @@ bool Foam::dynamicIndexedOctree<Type>::walkToParent
|
||||
// Find octant nodeI is in.
|
||||
parentOctant = 255;
|
||||
|
||||
for (direction i = 0; i < parentNode.subNodes_.size(); i++)
|
||||
for (direction i = 0; i < node::nChildren; ++i)
|
||||
{
|
||||
labelBits index = parentNode.subNodes_[i];
|
||||
|
||||
@ -1794,7 +1794,7 @@ void Foam::dynamicIndexedOctree<Type>::findBox
|
||||
const node& nod = nodes_[nodeI];
|
||||
const treeBoundBox& nodeBb = nod.bb_;
|
||||
|
||||
for (direction octant = 0; octant < nod.subNodes_.size(); octant++)
|
||||
for (direction octant = 0; octant < node::nChildren; ++octant)
|
||||
{
|
||||
labelBits index = nod.subNodes_[octant];
|
||||
|
||||
@ -1842,7 +1842,7 @@ void Foam::dynamicIndexedOctree<Type>::findSphere
|
||||
const node& nod = nodes_[nodeI];
|
||||
const treeBoundBox& nodeBb = nod.bb_;
|
||||
|
||||
for (direction octant = 0; octant < nod.subNodes_.size(); octant++)
|
||||
for (direction octant = 0; octant < node::nChildren; ++octant)
|
||||
{
|
||||
labelBits index = nod.subNodes_[octant];
|
||||
|
||||
@ -1910,7 +1910,7 @@ void Foam::dynamicIndexedOctree<Type>::findNear
|
||||
{
|
||||
const node& nod2 = tree2.nodes()[tree2.getNode(index2)];
|
||||
|
||||
for (direction i2 = 0; i2 < nod2.subNodes_.size(); i2++)
|
||||
for (direction i2 = 0; i2 < node::nChildren; ++i2)
|
||||
{
|
||||
labelBits subIndex2 = nod2.subNodes_[i2];
|
||||
const treeBoundBox subBb2
|
||||
@ -1938,7 +1938,7 @@ void Foam::dynamicIndexedOctree<Type>::findNear
|
||||
else if (tree2.isContent(index2))
|
||||
{
|
||||
// index2 is leaf, index1 not yet.
|
||||
for (direction i1 = 0; i1 < nod1.subNodes_.size(); i1++)
|
||||
for (direction i1 = 0; i1 < node::nChildren; ++i1)
|
||||
{
|
||||
labelBits subIndex1 = nod1.subNodes_[i1];
|
||||
const treeBoundBox subBb1
|
||||
@ -1978,7 +1978,7 @@ void Foam::dynamicIndexedOctree<Type>::findNear
|
||||
|
||||
if (bb2.overlaps(searchBox))
|
||||
{
|
||||
for (direction i2 = 0; i2 < nod2.subNodes_.size(); i2++)
|
||||
for (direction i2 = 0; i2 < node::nChildren; ++i2)
|
||||
{
|
||||
labelBits subIndex2 = nod2.subNodes_[i2];
|
||||
const treeBoundBox subBb2
|
||||
@ -2067,7 +2067,7 @@ Foam::label Foam::dynamicIndexedOctree<Type>::countElements
|
||||
|
||||
const node& nod = nodes_[nodeI];
|
||||
|
||||
for (direction octant = 0; octant < nod.subNodes_.size(); octant++)
|
||||
for (direction octant = 0; octant < node::nChildren; ++octant)
|
||||
{
|
||||
nElems += countElements(nod.subNodes_[octant]);
|
||||
}
|
||||
@ -2085,6 +2085,43 @@ Foam::label Foam::dynamicIndexedOctree<Type>::countElements
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::dynamicIndexedOctree<Type>::writeOBJ
|
||||
(
|
||||
const label nodeI,
|
||||
Ostream& os,
|
||||
label& vertIndex,
|
||||
const bool leavesOnly,
|
||||
const bool writeLinesOnly
|
||||
) const
|
||||
{
|
||||
const node& nod = nodes_[nodeI];
|
||||
const treeBoundBox& bb = nod.bb_;
|
||||
|
||||
for (direction octant = 0; octant < node::nChildren; ++octant)
|
||||
{
|
||||
const treeBoundBox subBb(bb.subBbox(octant));
|
||||
|
||||
labelBits index = nod.subNodes_[octant];
|
||||
|
||||
if (isNode(index))
|
||||
{
|
||||
label subNodeI = getNode(index);
|
||||
|
||||
writeOBJ(subNodeI, os, vertIndex, leavesOnly, writeLinesOnly);
|
||||
}
|
||||
else if (isContent(index))
|
||||
{
|
||||
indexedOctreeBase::writeOBJ(os, subBb, vertIndex, writeLinesOnly);
|
||||
}
|
||||
else if (isEmpty(index) && !leavesOnly)
|
||||
{
|
||||
indexedOctreeBase::writeOBJ(os, subBb, vertIndex, writeLinesOnly);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::dynamicIndexedOctree<Type>::writeOBJ
|
||||
(
|
||||
@ -2092,11 +2129,6 @@ void Foam::dynamicIndexedOctree<Type>::writeOBJ
|
||||
const direction octant
|
||||
) const
|
||||
{
|
||||
OFstream str
|
||||
(
|
||||
"node" + Foam::name(nodeI) + "_octant" + Foam::name(octant) + ".obj"
|
||||
);
|
||||
|
||||
labelBits index = nodes_[nodeI].subNodes_[octant];
|
||||
|
||||
treeBoundBox subBb;
|
||||
@ -2110,24 +2142,28 @@ void Foam::dynamicIndexedOctree<Type>::writeOBJ
|
||||
subBb = nodes_[nodeI].bb_.subBbox(octant);
|
||||
}
|
||||
|
||||
OFstream os
|
||||
(
|
||||
"node" + Foam::name(nodeI) + "_octant" + Foam::name(octant) + ".obj"
|
||||
);
|
||||
|
||||
Pout<< "dumpContentNode : writing node:" << nodeI << " octant:" << octant
|
||||
<< " to " << str.name() << endl;
|
||||
<< " to " << os.name() << endl;
|
||||
|
||||
// Dump bounding box
|
||||
pointField bbPoints(subBb.points());
|
||||
bool writeLinesOnly(false);
|
||||
label vertIndex(0);
|
||||
indexedOctreeBase::writeOBJ(os, subBb, vertIndex, writeLinesOnly);
|
||||
}
|
||||
|
||||
forAll(bbPoints, i)
|
||||
|
||||
template<class Type>
|
||||
void Foam::dynamicIndexedOctree<Type>::writeOBJ(Ostream& os) const
|
||||
{
|
||||
if (!nodes_.empty())
|
||||
{
|
||||
const point& pt = bbPoints[i];
|
||||
|
||||
str<< "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
|
||||
}
|
||||
|
||||
forAll(treeBoundBox::edges, i)
|
||||
{
|
||||
const edge& e = treeBoundBox::edges[i];
|
||||
|
||||
str<< "l " << e[0] + 1 << ' ' << e[1] + 1 << nl;
|
||||
label vertIndex(0);
|
||||
// leavesOnly=true, writeLinesOnly=false
|
||||
writeOBJ(0, os, vertIndex, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2456,7 +2492,7 @@ Foam::volumeType Foam::dynamicIndexedOctree<Type>::getVolumeType
|
||||
}
|
||||
}
|
||||
|
||||
Pout<< "dynamicIndexedOctree<Type>::getVolumeType : "
|
||||
Pout<< "dynamicIndexedOctree::getVolumeType : "
|
||||
<< " bb:" << bb()
|
||||
<< " nodes_:" << nodes_.size()
|
||||
<< " nodeTypes_:" << nodeTypes_.size()
|
||||
@ -2552,9 +2588,9 @@ bool Foam::dynamicIndexedOctree<Type>::insertIndex
|
||||
{
|
||||
bool shapeInserted = false;
|
||||
|
||||
for (direction octant = 0; octant < 8; octant++)
|
||||
for (direction octant = 0; octant < node::nChildren; ++octant)
|
||||
{
|
||||
const labelBits& subNodeLabel = nodes_[nodIndex].subNodes_[octant];
|
||||
const labelBits subNodeLabel = nodes_[nodIndex].subNodes_[octant];
|
||||
|
||||
if (isNode(subNodeLabel))
|
||||
{
|
||||
@ -2642,9 +2678,9 @@ Foam::label Foam::dynamicIndexedOctree<Type>::removeIndex
|
||||
{
|
||||
label totalContents = 0;
|
||||
|
||||
for (direction octant = 0; octant < 8; octant++)
|
||||
for (direction octant = 0; octant < node::nChildren; ++octant)
|
||||
{
|
||||
const labelBits& subNodeLabel = nodes_[nodIndex].subNodes_[octant];
|
||||
const labelBits subNodeLabel = nodes_[nodIndex].subNodes_[octant];
|
||||
|
||||
if (isNode(subNodeLabel))
|
||||
{
|
||||
@ -2731,7 +2767,7 @@ void Foam::dynamicIndexedOctree<Type>::print
|
||||
<< "parent:" << nod.parent_ << nl
|
||||
<< "n:" << countElements(nodePlusOctant(nodeI, 0)) << nl;
|
||||
|
||||
for (direction octant = 0; octant < nod.subNodes_.size(); octant++)
|
||||
for (direction octant = 0; octant < node::nChildren; ++octant)
|
||||
{
|
||||
const treeBoundBox subBb(bb.subBbox(octant));
|
||||
|
||||
@ -2798,7 +2834,7 @@ void Foam::dynamicIndexedOctree<Type>::writeTreeInfo() const
|
||||
nEntries += contents_[i]->size();
|
||||
}
|
||||
|
||||
Pout<< "indexedOctree<Type>::indexedOctree"
|
||||
Pout<< "indexedOctree::indexedOctree"
|
||||
<< " : finished construction of tree of:" << shapes().typeName
|
||||
<< nl
|
||||
<< " bounding box: " << this->bb() << nl
|
||||
|
||||
Reference in New Issue
Block a user