nouveau fichier : include/TreeStats.hpp
nouveau fichier : include/TreeStats.tpp nouveau fichier : src/TreeStats.cpp
This commit is contained in:
parent
77c4b5fd0b
commit
c8714ca77a
67
include/TreeStats.hpp
Normal file
67
include/TreeStats.hpp
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#ifndef _OTB_TRISKELE_TREE_STATS_HPP
|
||||||
|
#define _OTB_TRISKELE_TREE_STATS_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <boost/accumulators/accumulators.hpp>
|
||||||
|
#include <boost/accumulators/statistics/stats.hpp>
|
||||||
|
#include <boost/accumulators/statistics/sum.hpp>
|
||||||
|
#include <boost/accumulators/statistics/count.hpp>
|
||||||
|
#include <boost/accumulators/statistics/min.hpp>
|
||||||
|
#include <boost/accumulators/statistics/max.hpp>
|
||||||
|
#include <boost/accumulators/statistics/mean.hpp>
|
||||||
|
|
||||||
|
#include "ArrayTree/triskeleArrayTreeBase.hpp"
|
||||||
|
|
||||||
|
namespace otb {
|
||||||
|
namespace triskele {
|
||||||
|
|
||||||
|
using namespace otb::triskele::arrayTree;
|
||||||
|
using namespace std;
|
||||||
|
namespace ba = boost::accumulators;
|
||||||
|
typedef ba::accumulator_set<DimImg, ba::stats<ba::tag::count,
|
||||||
|
ba::tag::mean,
|
||||||
|
ba::tag::min,
|
||||||
|
ba::tag::max> > TreeStatsDim;
|
||||||
|
typedef ba::accumulator_set<double, ba::stats<ba::tag::sum,
|
||||||
|
ba::tag::count,
|
||||||
|
ba::tag::mean,
|
||||||
|
ba::tag::min,
|
||||||
|
ba::tag::max> > 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
|
19
include/TreeStats.tpp
Normal file
19
include/TreeStats.tpp
Normal file
@ -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
|
105
src/TreeStats.cpp
Normal file
105
src/TreeStats.cpp
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
#include <boost/chrono.hpp>
|
||||||
|
|
||||||
|
#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<double> ns (delta);
|
||||||
|
oss.fill ('0');
|
||||||
|
// typedef duration<int, ratio<86400> > days;
|
||||||
|
// auto d = duration_cast<days>(ns);
|
||||||
|
// ns -= d;
|
||||||
|
auto h = duration_cast<hours> (ns);
|
||||||
|
ns -= h;
|
||||||
|
auto m = duration_cast<minutes> (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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user