Commit 7f6396bc authored by Quentin Khan's avatar Quentin Khan

Change cost zones bounds : store tree iterator instead of first cell index

The cost zones bound are now stored using a tree iterator pointing at the
first cell of a zone (at a given level) and the number of cells inside the
zone. This makes it easier to navigate through the zones.
parent 75a8abba
......@@ -35,15 +35,16 @@ template<typename OctreeClass, typename CellClass>
class FCostZones {
public:
using CostType = typename CellClass::costtype;
using TreeIterator = typename OctreeClass::Iterator;
/**
* \brief Class used to store the bounds of a zone.
* The bounds consist in the Morton index of the first node and the number
* of subsequent nodes.
*/
using BoundClass = std::pair<MortonIndex, int>;
using BoundClass = std::pair<TreeIterator, int>;
/// Initial value for empty bounds.
const BoundClass _boundInit {-1,0};
const BoundClass _boundInit {TreeIterator(),0};
protected:
......@@ -197,10 +198,12 @@ public:
/**
* \brief Runs the costzones algorithm.
*
* Since ScalFMM's implementation of the octree doesn't have a real root, we
* run the algorithm on each of its children.
*/
void run() {
// Compute tree leaves total cost;
computeLeavesCost();
// Compute tree internal nodes total cost;
......@@ -211,19 +214,7 @@ public:
_it.gotoLeft();
do {
this->costzones();
} while( _it.moveRight());
// int nbRootChildren = 0;
// do {
// nbRootChildren++;
// } while(_it.moveRight());
// _it.gotoLeft();
// // Compute costzones, we have to do the first level manualy
// for ( int i = 0; i < nbRootChildren; i++ ) {
// this->costzones();
// _it.moveRight();
// }
} while( _it.moveRight() );
}
......@@ -242,6 +233,7 @@ protected:
const int level = _it.level();
const bool progressDown = _it.canProgressToDown()
&& (level < _bottomMostLevel);
// Is this cell within the level range we consider
const bool useCell = (level < _bottomMostLevel)
&& (level >= _topMostLevel);
......@@ -251,6 +243,7 @@ protected:
callCostZonesOnChildren(LEFT, childrenCount);
}
// if the current cell is within the levels we consider, we add it
if( useCell )
addCurrentCell();
......@@ -300,7 +293,7 @@ protected:
_it.moveRight();
}
// move up to the cell level
// move up to the previous cell level
_it.moveUp();
}
......@@ -344,7 +337,7 @@ protected:
_leafCurrentCost[colour] += leafCost;
if( _leafZoneBounds.at(cellZone)[colour] == _boundInit ) {
_leafZoneBounds.at(cellZone)[colour].first = _it.getCurrentGlobalIndex();
_leafZoneBounds.at(cellZone)[colour].first = _it;
_leafZoneBounds.at(cellZone)[colour].second = 1;
} else {
_leafZoneBounds.at(cellZone)[colour].second++;
......@@ -358,8 +351,7 @@ protected:
_internalCurrentCost += cellCost;
if( _boundInit == _internalZoneBounds.at(cellZone)[level] ) {
_internalZoneBounds.at(cellZone)[level].first =
_it.getCurrentGlobalIndex();
_internalZoneBounds.at(cellZone)[level].first = _it;
_internalZoneBounds.at(cellZone)[level].second = 1;
} else {
_internalZoneBounds.at(cellZone)[level].second++;
......
......@@ -122,14 +122,9 @@ template <typename OctreeClass, typename CellClass>
void printZonesCosts(OctreeClass& tree, FCostZones<OctreeClass, CellClass>& costzones)
{
using CostType = typename CellClass::costtype;
using TreeIterator = typename OctreeClass::Iterator;
//using BoundClass = typename FCostZones<OctreeClass, CellClass>::BoundClass;
typename OctreeClass::Iterator it(&tree);
// auto leafZoneBounds = costzones.getLeafZoneBounds();
// auto internalZoneBounds = costzones.getZoneBounds();
auto zones = costzones.getZones();
......@@ -156,17 +151,11 @@ void printZonesCosts(OctreeClass& tree, FCostZones<OctreeClass, CellClass>& cost
colourIdx = 0;
for(auto c : z) {
it.gotoBottomLeft();
std::cerr << " " << colourIdx;
const MortonIndex start = c.first;
TreeIterator it = c.first;
int count = c.second;
if(count > 0) {
while( start < it.getCurrentGlobalIndex() && it.moveRight());
}
while(count > 0) {
if( FCoordColour::coord2colour(
it.getCurrentCell()->getCoordinate())
......@@ -180,7 +169,7 @@ void printZonesCosts(OctreeClass& tree, FCostZones<OctreeClass, CellClass>& cost
count--;
}
if (! it.moveRight()) {
if (! it.moveRight() && count > 0) {
std::cerr << "Reached the end...";
break;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment