diff --git a/include/TreeStats.hpp b/include/TreeStats.hpp new file mode 100644 index 0000000..c1078cc --- /dev/null +++ b/include/TreeStats.hpp @@ -0,0 +1,67 @@ +#ifndef _OTB_TRISKELE_TREE_STATS_HPP +#define _OTB_TRISKELE_TREE_STATS_HPP + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "ArrayTree/triskeleArrayTreeBase.hpp" + +namespace otb { + namespace triskele { + + using namespace otb::triskele::arrayTree; + using namespace std; + namespace ba = boost::accumulators; + typedef ba::accumulator_set > TreeStatsDim; + typedef ba::accumulator_set > TreeStatsDouble; + + enum statsIdxType { + buildTreeStats, + areaStats, + averageStats, + xyStats, + moiStats, + sdStats, + filteringStats, + copyImageStats, + readStats, + writeStats, + allStats, + + statsIdxTypeCount + }; + + class TreeStats { + public : + //void reset (); + inline void addDim (const treeType &type, const DimImg& leafCount, const DimImg& compCount); + inline void addTime (const statsIdxType &type, const double &duration); + ostream &printDim (ostream &out); + ostream &printTime (ostream &out); + private : + ostream &printDim (ostream &out, const TreeStatsDim stats[], const string &msg); + + TreeStatsDim leavesStats[treeTypeCount], compStats[treeTypeCount]; + TreeStatsDouble timeStats[statsIdxTypeCount]; + }; + static TreeStats globalTreeStats; + +#include "TreeStats.tpp" + } // triskele +} // otb + +#endif // _OTB_TRISKELE_TREE_HPP diff --git a/include/TreeStats.tpp b/include/TreeStats.tpp new file mode 100644 index 0000000..87efe7e --- /dev/null +++ b/include/TreeStats.tpp @@ -0,0 +1,19 @@ +#ifndef _OTB_TRISKELE_TREE_STATS_TPP +#define _OTB_TRISKELE_TREE_STATS_TPP + +// ======================================== +inline void +TreeStats::addDim (const treeType &type, const DimImg& leafCount, const DimImg& compCount) { + leavesStats[type] (leafCount); + compStats[type] (compCount); +} + +inline void +TreeStats::addTime (const statsIdxType &type, const double &duration) { + timeStats[type] (duration); +} + +// ======================================== + + +#endif // _OTB_TRISKELE_TREE_STATS_TPP diff --git a/src/TreeStats.cpp b/src/TreeStats.cpp new file mode 100644 index 0000000..e592e44 --- /dev/null +++ b/src/TreeStats.cpp @@ -0,0 +1,105 @@ +#include + +#include + +#include "TreeStats.hpp" + +using namespace otb::triskele; +using namespace std; + +// ======================================== +static string timeStatsLabels [statsIdxTypeCount] = { + "build tree", + "area", + "average", + "xy", + "moi", + "sd", + "filtering", + "copy image", + "GDAL read", + "GDAL write", + "sum All", +}; + +using namespace boost::chrono; +inline string +ns2string (double delta) { + ostringstream oss; + duration ns (delta); + oss.fill ('0'); + // typedef duration > days; + // auto d = duration_cast(ns); + // ns -= d; + auto h = duration_cast (ns); + ns -= h; + auto m = duration_cast (ns); + ns -= m; + oss << setw (2) << h.count () << ":" + << setw (2) << m.count () << ":" + << setw (9) << fixed << setprecision (6) << ns.count (); + return oss.str (); +} + +TreeStats globalTreeStats; + +ostream & +TreeStats::printDim (ostream &out, const TreeStatsDim stats[], const string &msg) { + cout << endl + << setw (11) << left << msg << "\t" + << setw (3) << left << "Count" << "\t" + << setw (9) << left << "Mean" << "\t" + << setw (9) << left << "Min" << "\t" + << setw (9) << left << "Max" << endl; + for (unsigned int i = 0; i < treeTypeCount; ++i) { + if (!ba::count (stats[i])) + continue; + cout << setw (11) << right << treeName [i] << "\t" + << setw (3) << ba::count (stats[i]) << "\t" + << setw (9) << DimImg (ba::mean (stats[i])) << "\t" + << setw (9) << ba::min (stats[i]) << "\t" + << setw (9) << ba::max (stats[i]) + << endl << flush; + } + return out; +} + +ostream & +TreeStats::printDim (ostream &out) { + bool empty = true; + for (unsigned int i = 0; i < treeTypeCount; ++i) + if (!(empty = !ba::count (leavesStats[i]))) + break; + if (empty) + return out; + printDim (out, leavesStats, "Leaf"); + return printDim (out, compStats, "Comp"); +} + +ostream & +TreeStats::printTime (ostream &out) { + bool empty = true; + for (unsigned int i = 0; i < statsIdxTypeCount; ++i) + if (!(empty = !ba::count (timeStats[i]))) + break; + if (empty) + return out; + cout << endl + << setw (11) << left << "Time" << "\t" + << setw (15) << left << "Sum" << "\t" + << setw (3) << left << "Count" << "\t" + << setw (15) << left << "Mean" << "\t" + << setw (15) << left << "Min" << "\t" + << setw (15) << left << "Max" << endl; + for (unsigned int i = 0; i < statsIdxTypeCount; ++i) { + if (!ba::count (timeStats[i])) + continue; + cout << setw (11) << right << timeStatsLabels[i] << "\t" + << ns2string (ba::sum (timeStats[i])) << "\t" << setw (3) << ba::count (timeStats[i]) << "\t" + << ns2string (ba::mean (timeStats[i])) << "\t" + << ns2string (ba::min (timeStats[i])) << "\t" + << ns2string (ba::max (timeStats[i])) + << endl << flush; + } + return out; +}