Skip to content

Commit

Permalink
Changes to support preview of stages and general stats filter changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Dec 29, 2014
1 parent 043c7d9 commit 9a89861
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 271 deletions.
1 change: 0 additions & 1 deletion filters/stats/StatsFilter.cpp
Expand Up @@ -125,7 +125,6 @@ void StatsFilter::ready(PointContext ctx)

void StatsFilter::extractMetadata(PointContext ctx)
{

uint32_t position(0);

for (auto di = m_stats.begin(); di != m_stats.end(); ++di)
Expand Down
64 changes: 44 additions & 20 deletions include/pdal/Metadata.hpp
Expand Up @@ -46,7 +46,7 @@
#include <map>
#include <memory>
#include <vector>

#include <stdint.h>

namespace
{
Expand Down Expand Up @@ -96,7 +96,7 @@ class MetadataNodeImpl
private:
MetadataNodeImpl(const std::string& name) : m_kind(MetadataType::Instance)
{
m_name = sanitize(name);
m_name = sanitize(name);
}

MetadataNodeImpl() : m_kind(MetadataType::Instance)
Expand Down Expand Up @@ -264,8 +264,7 @@ inline void MetadataNodeImpl::setValue<double>(const double& d)
}

template <>
inline void MetadataNodeImpl::setValue<SpatialReference>(
const SpatialReference& ref)
inline void MetadataNodeImpl::setValue(const SpatialReference& ref)
{
std::ostringstream oss;
oss << ref;
Expand All @@ -274,7 +273,7 @@ inline void MetadataNodeImpl::setValue<SpatialReference>(
}

template <>
inline void MetadataNodeImpl::setValue<BOX3D>(const BOX3D& b)
inline void MetadataNodeImpl::setValue(const BOX3D& b)
{
std::ostringstream oss;
oss << b;
Expand All @@ -283,64 +282,84 @@ inline void MetadataNodeImpl::setValue<BOX3D>(const BOX3D& b)
}

template <>
inline void MetadataNodeImpl::setValue<uint8_t>(const uint8_t& u)
inline void MetadataNodeImpl::setValue(const unsigned char& u)
{
m_type = "nonNegativeInteger";
m_value = boost::lexical_cast<std::string>((unsigned)u);
}

template <>
inline void MetadataNodeImpl::setValue<uint16_t>(const uint16_t& u)
inline void MetadataNodeImpl::setValue(const unsigned short& u)
{
m_type = "nonNegativeInteger";
m_value = boost::lexical_cast<std::string>(u);
}

template <>
inline void MetadataNodeImpl::setValue(const unsigned int& u)
{
m_type = "nonNegativeInteger";
m_value = boost::lexical_cast<std::string>(u);
}

template <>
inline void MetadataNodeImpl::setValue<uint32_t>(const uint32_t& u)
inline void MetadataNodeImpl::setValue<unsigned long>(const unsigned long& u)
{
m_type = "nonNegativeInteger";
m_value = boost::lexical_cast<std::string>(u);
}

template <>
inline void MetadataNodeImpl::setValue<uint64_t>(const uint64_t& u)
inline void MetadataNodeImpl::setValue(const unsigned long long& u)
{
m_type = "nonNegativeInteger";
m_value = boost::lexical_cast<std::string>(u);
}

template <>
inline void MetadataNodeImpl::setValue<int8_t>(const int8_t& i)
inline void MetadataNodeImpl::setValue<char>(const char& i)
{
m_type = "integer";
m_value = boost::lexical_cast<std::string>((int)i);
}

template <>
inline void MetadataNodeImpl::setValue<int16_t>(const int16_t& i)
inline void MetadataNodeImpl::setValue(const signed char& i)
{
m_type = "integer";
m_value = boost::lexical_cast<std::string>(i);
m_value = boost::lexical_cast<std::string>((int)i);
}

template <>
inline void MetadataNodeImpl::setValue<int32_t>(const int32_t& i)
inline void MetadataNodeImpl::setValue(const short& s)
{
m_type = "integer";
m_value = boost::lexical_cast<std::string>(i);
m_value = boost::lexical_cast<std::string>(s);
}

template <>
inline void MetadataNodeImpl::setValue<int64_t>(const int64_t& i)
inline void MetadataNodeImpl::setValue(const int& i)
{
m_type = "integer";
m_value = boost::lexical_cast<std::string>(i);
}

template <>
inline void MetadataNodeImpl::setValue<boost::uuids::uuid>(
const boost::uuids::uuid& u)
inline void MetadataNodeImpl::setValue(const long& l)
{
m_type = "integer";
m_value = boost::lexical_cast<std::string>(l);
}

template <>
inline void MetadataNodeImpl::setValue<int64_t>(const long long& l)
{
m_type = "integer";
m_value = boost::lexical_cast<std::string>(l);
}

template <>
inline void MetadataNodeImpl::setValue(const boost::uuids::uuid& u)
{
std::ostringstream oss;
oss << u;
Expand Down Expand Up @@ -370,6 +389,14 @@ class PDAL_DLL MetadataNode
MetadataNode addList(const std::string& name)
{ return MetadataNode(m_impl->addList(name)); }

MetadataNode clone(const std::string& name)
{
MetadataNode node;
node.m_impl.reset(new MetadataNodeImpl(*m_impl));
node.m_impl->m_name = name;
return node;
}

MetadataNode add(MetadataNode node)
{ return MetadataNode(m_impl->add(node.m_impl)); }

Expand Down Expand Up @@ -624,9 +651,6 @@ class Metadata
MetadataNode m_root;
MetadataNode m_private;
std::string m_name;

MetadataNode privateNode() const
{ return m_private; }
};
typedef std::shared_ptr<Metadata> MetadataPtr;

Expand Down
35 changes: 14 additions & 21 deletions include/pdal/PDALUtils.hpp
Expand Up @@ -34,14 +34,14 @@

#pragma once

#include <pdal/Metadata.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/algorithm/string.hpp>
#include <pdal/Dimension.hpp>
#include <pdal/pdal_defines.h>
#include <pdal/Bounds.hpp>
#include <pdal/PointContext.hpp>
#include <pdal/PointBuffer.hpp>
#include <pdal/Metadata.hpp>
#include <pdal/Options.hpp>

namespace pdal
Expand Down Expand Up @@ -87,24 +87,21 @@ inline ptree toPTree(MetadataNode const& node)
}


inline ptree toPTree(PointContextRef ctx)
inline MetadataNode toMetadata(PointContextRef ctx)
{
ptree tree;
ptree dimsTree;
MetadataNode root;

for (const auto& id : ctx.dims())
{
ptree dim;
dim.put("name", ctx.dimName(id));
MetadataNode dim("dimensions");
dim.add("name", ctx.dimName(id));
Dimension::Type::Enum t = ctx.dimType(id);
dim.put("type", Dimension::toName(Dimension::base(t)));
dim.put("size", ctx.dimSize(id));
dimsTree.push_back(std::make_pair("", dim));
dim.add("type", Dimension::toName(Dimension::base(t)));
dim.add("size", ctx.dimSize(id));
root.addList(dim);
}

tree.add_child("dimensions", dimsTree);

return tree;
return root;
}


Expand All @@ -124,27 +121,23 @@ inline ptree toPTree(PointContextRef ctx)
\endverbatim
*/
inline ptree toPTree(const PointBuffer& buffer)
inline MetadataNode toMetadata(const PointBuffer& buffer)
{

ptree tree;
MetadataNode node;

const Dimension::IdList& dims = buffer.dims();

for (PointId idx = 0; idx < buffer.size(); idx++)
{
std::string pointstring = boost::lexical_cast<std::string>(idx) + ".";

MetadataNode pointnode = node.add(std::to_string(idx));
for (auto di = dims.begin(); di != dims.end(); ++di)
{
std::string key = pointstring + Dimension::name(*di);
double v = buffer.getFieldAs<double>(*di, idx);
std::string value = boost::lexical_cast<std::string>(v);
tree.add(key, value);
pointnode.add(Dimension::name(*di), v);
}
}

return tree;
return node;
}

/// Outputs a string-based boost::property_tree::ptree representation
Expand Down
5 changes: 2 additions & 3 deletions kernels/KernelSupport.cpp
Expand Up @@ -44,10 +44,8 @@
namespace pdal
{

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

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

Expand All @@ -67,6 +65,7 @@ PipelineManager* KernelSupport::makePipeline(pdal::Options& options)
{
StageFactory factory;
std::string driver = factory.inferReaderDriver(inputFile);

if (driver.empty())
throw app_runtime_error("Cannot determine input file type of " +
inputFile);
Expand Down
2 changes: 1 addition & 1 deletion kernels/KernelSupport.hpp
Expand Up @@ -73,7 +73,7 @@ class PDAL_DLL KernelSupport
// makes a writer, from just the filename and some other
// options (and the input stage)
static Writer* makeWriter(const std::string& filename, Stage *stage);
static PipelineManager* makePipeline(Options& options);
static PipelineManager* makePipeline(const std::string& filename);

private:
KernelSupport& operator=(const KernelSupport&); // not implemented
Expand Down

0 comments on commit 9a89861

Please sign in to comment.