Skip to content

Commit

Permalink
fix up filters.stats to do selection of dimensions upon first buffer …
Browse files Browse the repository at this point in the history
…read rather than at initialize() time
  • Loading branch information
hobu committed Dec 30, 2013
1 parent 2e1f4d6 commit 14ffc86
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
11 changes: 6 additions & 5 deletions include/pdal/filters/Stats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,11 @@ class PDAL_DLL Stats : public Filter

void processBuffer(PointBuffer& data) const;

std::vector<std::string> const& getDimensionNames() const { return m_dimension_names; }
std::vector<std::string> const& getExactDimensionNames() const { return m_exact_dimension_names; }


private:

std::vector<std::string> m_dimension_names;
std::vector<std::string> m_exact_dimension_names;


Stats& operator=(const Stats&); // not implemented
Stats(const Stats&); // not implemented
Expand Down Expand Up @@ -249,14 +247,17 @@ class PDAL_DLL Stats : public pdal::FilterSequentialIterator
protected:
virtual void readBufferBeginImpl(PointBuffer&);
virtual void readBufferEndImpl(PointBuffer&);
std::vector<std::string> const& getDimensionNames() const { return m_dimension_names; }
std::vector<std::string> const& getExactDimensionNames() const { return m_exact_dimension_names; }
private:
boost::uint64_t skipImpl(boost::uint64_t);
boost::uint32_t readBufferImpl(PointBuffer&);
bool atEndImpl() const;

const pdal::filters::Stats& m_statsFilter;

std::vector<DimensionPtr> m_dimensions;
std::vector<std::string> m_dimension_names;
std::vector<std::string> m_exact_dimension_names;

double getValue(PointBuffer& data, Dimension& dim, boost::uint32_t pointIndex);

Expand Down
69 changes: 34 additions & 35 deletions src/filters/Stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,35 +190,7 @@ void Stats::initialize()
{
Filter::initialize();

std::string names = getOptions().getValueOrDefault<std::string>("dimensions", "");
if (names.size())
{
log()->get(logDEBUG) << "Using explicit list of dimension names'" << names << "'"<<std::endl;
boost::char_separator<char> seps(" ,");


tokenizer parameters(names, seps);
for (tokenizer::iterator t = parameters.begin(); t != parameters.end(); ++t)
{
log()->get(logDEBUG) << "adding '" << *t << "' as dimension name to cumulate stats for" << std::endl;
m_dimension_names.push_back(*t);
}
}

std::string exact = getOptions().getValueOrDefault<std::string>("exact_dimensions", "");
if (exact.size())
{
log()->get(logDEBUG) << "Calculating histogram statistics for exact names '" << names << "'"<<std::endl;
boost::char_separator<char> seps(" ,");


tokenizer parameters(exact, seps);
for (tokenizer::iterator t = parameters.begin(); t != parameters.end(); ++t)
{
log()->get(logDEBUG) << "adding '" << *t << "' as exact dimension name to cumulate stats for" << std::endl;
m_exact_dimension_names.push_back(*t);
}
}


return;
Expand Down Expand Up @@ -252,7 +224,6 @@ namespace sequential

Stats::Stats(const pdal::filters::Stats& filter, PointBuffer& buffer)
: pdal::FilterSequentialIterator(filter, buffer)
, m_statsFilter(filter)
{
return;
}
Expand Down Expand Up @@ -418,11 +389,40 @@ void Stats::readBufferBeginImpl(PointBuffer& buffer)
{
Options const& options = getStage().getOptions();

std::vector<std::string> dimension_names = m_statsFilter.getExactDimensionNames();
std::string names = options.getValueOrDefault<std::string>("dimensions", "");
if (names.size())
{
getStage().log()->get(logDEBUG) << "Using explicit list of dimension names'" << names << "'"<<std::endl;
boost::char_separator<char> seps(" ,");


tokenizer parameters(names, seps);
for (tokenizer::iterator t = parameters.begin(); t != parameters.end(); ++t)
{
getStage().log()->get(logDEBUG) << "adding '" << *t << "' as dimension name to cumulate stats for" << std::endl;
m_dimension_names.push_back(*t);
}
}

std::string exact = options.getValueOrDefault<std::string>("exact_dimensions", "");
if (exact.size())
{
getStage().log()->get(logDEBUG) << "Calculating histogram statistics for exact names '" << names << "'"<<std::endl;
boost::char_separator<char> seps(" ,");


tokenizer parameters(exact, seps);
for (tokenizer::iterator t = parameters.begin(); t != parameters.end(); ++t)
{
getStage().log()->get(logDEBUG) << "adding '" << *t << "' as exact dimension name to cumulate stats for" << std::endl;
m_exact_dimension_names.push_back(*t);
}
}


std::map<std::string, bool> exact_dimensions;
for (std::vector<std::string>::const_iterator i = dimension_names.begin();
i != dimension_names.end(); ++i)
for (std::vector<std::string>::const_iterator i = m_dimension_names.begin();
i != m_dimension_names.end(); ++i)
{
getStage().log()->get(logDEBUG2) << "Using exact histogram counts for '" << *i << "'" << std::endl;
std::pair<std::string,bool> p(*i, true);
Expand Down Expand Up @@ -464,12 +464,11 @@ void Stats::readBufferBeginImpl(PointBuffer& buffer)

boost::uint32_t bin_count = options.getValueOrDefault<boost::uint32_t>("num_bins", 20);

std::vector<std::string> const& specified_names = m_statsFilter.getDimensionNames();

if (specified_names.size())
if (m_exact_dimension_names.size())
{

for (std::vector<std::string>::const_iterator i = specified_names.begin(); i != specified_names.end(); i++)
for (std::vector<std::string>::const_iterator i = m_exact_dimension_names.begin(); i != m_exact_dimension_names.end(); i++)
{
std::string const& name = *i;
getStage().log()->get(logDEBUG2) << "Requested to cumulate stats for dimension with name '" << name <<"'"<< std::endl;
Expand Down
6 changes: 3 additions & 3 deletions test/unit/filters/StatsFilterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ BOOST_AUTO_TEST_CASE(test_specified_stats)

pdal::filters::iterators::sequential::Stats* iterator = static_cast<pdal::filters::iterators::sequential::Stats*>(iter.get());

const pdal::filters::stats::Summary& statsX = iterator->getStats(schema.getDimension("filters.inplacereprojection.X"));
const pdal::filters::stats::Summary& statsY = iterator->getStats(schema.getDimension("drivers.las.reader.Y"));
const pdal::filters::stats::Summary& statsZ = iterator->getStats(schema.getDimension("Z"));
const pdal::filters::stats::Summary& statsX = iterator->getStats(data.getSchema().getDimension("filters.inplacereprojection.X"));
const pdal::filters::stats::Summary& statsY = iterator->getStats(data.getSchema().getDimension("drivers.las.reader.Y"));
const pdal::filters::stats::Summary& statsZ = iterator->getStats(data.getSchema().getDimension("Z"));

BOOST_CHECK_EQUAL(statsX.count(), 1000u);
BOOST_CHECK_EQUAL(statsY.count(), 1000u);
Expand Down

0 comments on commit 14ffc86

Please sign in to comment.