Skip to content

Instantly share code, notes, and snippets.

@connormanning
Last active August 29, 2015 14:20
Show Gist options
  • Save connormanning/1d412c858d4e52552bf4 to your computer and use it in GitHub Desktop.
Save connormanning/1d412c858d4e52552bf4 to your computer and use it in GitHub Desktop.
Get stats from pdal::BufferReader pipeline
#include <memory>
#include <iostream>
#include <pdal/BufferReader.hpp>
#include <pdal/PointView.hpp>
#include <pdal/StageFactory.hpp>
#include <pdal/StageWrapper.hpp>
#include <pdal/StatsFilter.hpp>
int main()
{
pdal::PointTable inputTable;
pdal::PointViewPtr inputView(new pdal::PointView(inputTable));
inputTable.layout()->registerDim(pdal::Dimension::Id::X);
inputTable.layout()->registerDim(pdal::Dimension::Id::Y);
inputTable.layout()->registerDim(pdal::Dimension::Id::Z);
for (int i=0; i<8; i++)
{
inputView->setField(pdal::Dimension::Id::X, i, i);
inputView->setField(pdal::Dimension::Id::Y, i, 2*i);
inputView->setField(pdal::Dimension::Id::Z, i, 3*i);
}
pdal::BufferReader reader;
reader.addView(inputView);
pdal::StatsFilter stats;
stats.setInput(reader);
stats.prepare(inputTable);
stats.execute(inputTable);
const pdal::stats::Summary& xs(stats.getStats(pdal::Dimension::Id::X));
const pdal::stats::Summary& ys(stats.getStats(pdal::Dimension::Id::Y));
const pdal::stats::Summary& zs(stats.getStats(pdal::Dimension::Id::Z));
std::cout <<
"X range: [" << xs.minimum() << ", " << xs.maximum() << "]\n" <<
"Y range: [" << ys.minimum() << ", " << ys.maximum() << "]\n" <<
"Z range: [" << zs.minimum() << ", " << zs.maximum() << "]\n" <<
std::endl;
return 0;
}
$ g++ -std=c++11 -lpdalcpp -lpdal_util bufferReaderStats.cpp && ./a.out
X range: [0, 7]
Y range: [0, 14]
Z range: [0, 21]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment