Skip to content

Commit

Permalink
make pdal info --stats myfile.xml --pipeline-serialization work #203
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Nov 13, 2013
1 parent 334af1f commit 1cffdd4
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 22 deletions.
3 changes: 2 additions & 1 deletion include/pdal/kernel/Info.hpp
Expand Up @@ -66,7 +66,7 @@ class PDAL_DLL Info : public Application
void validateSwitches(); // overrride

void dumpOnePoint(const Stage&) const;
void dumpStats(pdal::filters::Stats& filter) const;
void dumpStats(pdal::filters::Stats& filter, PipelineManager* manager) const;
void dumpSchema(const Stage&) const;
void dumpStage(const Stage&) const;
void dumpQuery(Stage const&, IndexedPointBuffer&) const;
Expand All @@ -89,6 +89,7 @@ class PDAL_DLL Info : public Application
std::string m_QueryPoint;
double m_QueryDistance;
boost::uint64_t m_numPointsToWrite;
std::string m_pipelineFile;
};

}} // pdal::kernel
Expand Down
4 changes: 2 additions & 2 deletions include/pdal/kernel/Pipeline.hpp
@@ -1,5 +1,4 @@

#ifndef INCLUDED_PDAL_KERNEL_PIPELINE_HPP/******************************************************************************
/******************************************************************************
* Copyright (c) 2013, Howard Butler (hobu.inc@gmail.com)
*
* All rights reserved.
Expand Down Expand Up @@ -33,6 +32,7 @@
* OF SUCH DAMAGE.
****************************************************************************/

#ifndef INCLUDED_PDAL_KERNEL_PIPELINE_HPP
#define INCLUDED_PDAL_KERNEL_PIPELINE_HPP


Expand Down
4 changes: 3 additions & 1 deletion include/pdal/kernel/Support.hpp
Expand Up @@ -41,7 +41,7 @@
#include <pdal/Stage.hpp>
#include <pdal/Writer.hpp>
#include <pdal/UserCallback.hpp>

#include <pdal/PipelineManager.hpp>

namespace pdal { namespace kernel {

Expand Down Expand Up @@ -72,6 +72,8 @@ class AppSupport

// makes a writer, from just the filename and some other options (and the input stage)
static pdal::Writer* makeWriter(pdal::Options& options, pdal::Stage& stage);

static pdal::PipelineManager* makePipeline(pdal::Options& options);

private:

Expand Down
54 changes: 38 additions & 16 deletions src/kernel/Info.cpp
Expand Up @@ -33,6 +33,7 @@
****************************************************************************/

#include <pdal/kernel/Info.hpp>
#include <pdal/PipelineWriter.hpp>


namespace pdal { namespace kernel {
Expand Down Expand Up @@ -103,6 +104,8 @@ void Info::addSwitches()
("xml", po::value<bool>(&m_useXML)->zero_tokens()->implicit_value(true), "dump XML instead of JSON")
("seed", po::value<boost::uint32_t>(&m_seed)->default_value(0), "Seed value for random sample")
("sample_size", po::value<boost::uint32_t>(&m_sample_size)->default_value(1000), "Sample size for random sample")
("pipeline-serialization", po::value<std::string>(&m_pipelineFile)->default_value(""), "")

;

addSwitchSet(processing_options);
Expand Down Expand Up @@ -145,7 +148,7 @@ void Info::dumpOnePoint(const Stage& stage) const
}


void Info::dumpStats(pdal::filters::Stats& filter) const
void Info::dumpStats(pdal::filters::Stats& filter, pdal::PipelineManager* manager) const
{

const Schema& schema = filter.getSchema();
Expand All @@ -155,10 +158,18 @@ void Info::dumpStats(pdal::filters::Stats& filter) const
{
chunkSize = filter.getNumPoints();
}


pdal::PipelineWriter* writer(0);

PointBuffer data(schema, chunkSize);

boost::scoped_ptr<StageSequentialIterator> iter(filter.createSequentialIterator(data));
if (m_pipelineFile.size() > 0)
{
writer = new pdal::PipelineWriter(*manager);
writer->setPointBuffer(&data);
}

StageSequentialIterator* iter = filter.createSequentialIterator(data);

boost::uint64_t totRead = 0;
while (!iter->atEnd())
Expand All @@ -167,9 +178,9 @@ void Info::dumpStats(pdal::filters::Stats& filter) const
const boost::uint32_t numRead = iter->read(data);
totRead += numRead;
}

pdal::Metadata output = static_cast<pdal::filters::iterators::sequential::Stats*>(iter.get())->toMetadata();

pdal::Metadata output = static_cast<pdal::filters::iterators::sequential::Stats*>(iter)->toMetadata();
delete iter;
boost::property_tree::ptree tree;
tree.add_child("stats", output.toPTree());
std::ostream& ostr = m_outputStream ? *m_outputStream : std::cout;
Expand All @@ -178,6 +189,13 @@ void Info::dumpStats(pdal::filters::Stats& filter) const
write_xml(ostr, tree);
else
write_json(ostr, tree);

if (m_pipelineFile.size() > 0)
{
writer->writePipeline(m_pipelineFile);
delete writer;
}


return;
}
Expand Down Expand Up @@ -326,7 +344,9 @@ int Info::execute()
readerOptions.add<boost::uint32_t>("verbose", getVerboseLevel());
}

Stage* reader = AppSupport::makeReader(readerOptions);
PipelineManager* manager = AppSupport::makePipeline(readerOptions);

// Stage* reader = AppSupport::makeReader(readerOptions);

if (m_seed != 0)
{
Expand All @@ -353,8 +373,11 @@ int Info::execute()

pdal::Options options = m_options + readerOptions;

pdal::filters::Stats* filter = new pdal::filters::Stats(*reader, options);
Stage* reader = manager->getStage();
manager->addFilter("filters.stats", *reader, options);
// pdal::filters::Stats* filter = new pdal::filters::Stats(*reader, options);

Stage* filter = manager->getStage();

filter->initialize();

Expand All @@ -365,39 +388,38 @@ int Info::execute()

if (m_showStats)
{
dumpStats(*filter);
dumpStats(*dynamic_cast<pdal::filters::Stats*>(filter), manager);
}

if (m_showSchema)
{
dumpSchema(*reader);
dumpSchema(*filter);
}

if (m_showMetadata)
{
dumpMetadata(*reader);
dumpMetadata(*filter);
}
if (m_showStage)
{
dumpStage(*reader);
dumpStage(*filter);
}

if (m_showSDOPCMetadata)
{
dumpSDO_PCMetadata(*reader);
dumpSDO_PCMetadata(*filter);
}

if (m_QueryPoint.size())
{
IndexedPointBuffer buffer(reader->getSchema(), reader->getNumPoints());
dumpQuery(*reader, buffer);
IndexedPointBuffer buffer(filter->getSchema(), filter->getNumPoints());
dumpQuery(*filter, buffer);
}

std::ostream& ostr = m_outputStream ? *m_outputStream : std::cout;
ostr << std::endl;

delete filter;
delete reader;
delete manager;

if (m_outputStream)
{
Expand Down
30 changes: 28 additions & 2 deletions src/kernel/Support.cpp
Expand Up @@ -39,11 +39,37 @@

#include <pdal/FileUtils.hpp>
#include <pdal/Utils.hpp>
#include <pdal/PipelineManager.hpp>
#include <pdal/PipelineReader.hpp>


namespace pdal { namespace kernel {


pdal::PipelineManager* AppSupport::makePipeline(pdal::Options& options)
{
const std::string inputFile = options.getValueOrThrow<std::string>("filename");

if (!pdal::FileUtils::fileExists(inputFile))
{
throw app_runtime_error("file not found: " + inputFile);
}

pdal::PipelineManager* output = new PipelineManager;
pdal::StageFactory factory;
std::string driver = factory.inferReaderDriver(inputFile, options);
if (driver == "")
{
throw app_runtime_error("Cannot determine input file type of " + inputFile);
}

pdal::Stage* stage = output->addReader(driver, options);
if (!stage)
{
throw app_runtime_error("reader creation failed");
}

return output;
}

pdal::Stage* AppSupport::makeReader(pdal::Options& options)
{
const std::string inputFile = options.getValueOrThrow<std::string>("filename");
Expand Down
28 changes: 28 additions & 0 deletions test/data/filters/hexbin-info.xml
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<Pipeline version="1.0">
<Filter type="filters.hexbin">
<Option name="edge_size">
0.0
</Option>
<Option name="threshold">
10
</Option>
<Option name="sample_size">
5000
</Option>
<Option name="x_dim">
drivers.las.reader.X
</Option>
<Option name="y_dim">
Y
</Option>
<Option name="precision">
4
</Option>
<Reader type="drivers.las.reader">
<Option name="filename">
../1.2-with-color.las
</Option>
</Reader>
</Filter>
</Pipeline>

0 comments on commit 1cffdd4

Please sign in to comment.