Loading [MathJax]/extensions/tex2jax.js
DM_attributes_statistic.cpp
// =================================================================
// Small example showing how to access the attribute statistics
// of a datamanager
// =================================================================
#include <iostream>
#include <iomanip>
#include <string>
#include "DM/Datamanager.hpp"
using namespace std;
void DM_attributes_statistics(const char *filename)
{
//open the odm
DM::DatamanagerHandle dm = DM::IDatamanager::load(filename,true/*readOnly*/,false/*threadSafety*/);
//if the dm wasn't opened sucessful exit function
if (!dm)
{
cout << "Unable to open ODM '" << filename << "'" << endl;
return;
}
cout << std::fixed << std::setprecision(3); //use fixed floating-point notation and 3 digits after the comma
//get point index object
DM::PointIndexHandle pi = dm->getPointIndex();
cout << "ODM contains " << dm->sizePoint() << " points" << endl;
cout << "Estimated point density " << pi->estimatePointDensity() << " [points/m^2]" << endl;
//get attribute statistic object
DM::AddInfoStatisticsHandle stats = pi->getAddInfoStatistics();
cout << "Attribute statistics:" << endl;
cout << "Name\t type\t count\t min\t max\t mean\t sigma" << endl;
for(unsigned i=0; i<stats->columns();++i)
{
std::string colname = stats->min().name(i);
DM::ColumnType coltype = stats->min().type(i);
//output colname and coltype
cout << colname << "\t" << static_cast<int>(coltype) << "\t";
//output statistics
if (stats->count(i) > 0)
{
cout << setw(5) << stats->count(i) << stats->min().getAsDouble(i) << " " << stats->max().getAsDouble(i) << " " << stats->mean(i) << " " << stats->sigma(i) << endl;
}
else
{
cout << setw(5) << stats->count(i) << "--- --- --- ---" << endl;
}
}
}
ColumnType
Supported attribute type.
Definition: ColumnTypes.hpp:8
static IDatamanager * load(const char *filename, bool readOnly=false, bool threadSafety=true)
Smart pointer class using reference counting with support for DM objects (see ObjectBase)
Definition: Handle.hpp:75