Skip to content

Commit

Permalink
move most toPTree() methods of PDAL objects out to static functions i…
Browse files Browse the repository at this point in the history
…n PDALUtils.hpp #422
  • Loading branch information
hobu committed Sep 3, 2014
1 parent e8ce7c8 commit 8f69750
Show file tree
Hide file tree
Showing 22 changed files with 445 additions and 378 deletions.
62 changes: 24 additions & 38 deletions include/pdal/Bounds.hpp
Expand Up @@ -47,7 +47,6 @@
#include <cassert>
#include <vector>
#include <sstream>
#include <boost/property_tree/ptree.hpp>

#include <pdal/Vector.hpp>
#include <pdal/Range.hpp>
Expand All @@ -56,13 +55,13 @@ namespace pdal
{


/*!
/*!
\verbatim embed:rst
Bounds is for manipulating n-dimensional ranges of data. Typically
Bounds is for manipulating n-dimensional ranges of data. Typically
used for defining the spatial extents of XYZ data, this class can also be
used for defining bounds of other dimensions.
\endverbatim
*/

Expand Down Expand Up @@ -166,7 +165,7 @@ class PDAL_DLL Bounds
\verbatim embed:rst
.. note::
If `index` is greater than :cpp:func:`size()`,
If `index` is greater than :cpp:func:`size()`,
a default value of ``0.0`` will be returned.
\endverbatim
*/
Expand All @@ -179,7 +178,7 @@ class PDAL_DLL Bounds
return m_ranges[index].getMinimum();
}


/// Sets the minimum value of the Range at the given index
/// @param index the Range index to set the minimum value at
/// @param v the value to set for the minimum
Expand All @@ -197,7 +196,7 @@ class PDAL_DLL Bounds
\verbatim embed:rst
.. note::
If `index` is greater than :cpp:func:`size()`,
If `index` is greater than :cpp:func:`size()`,
a default value of ``0.0`` will be returned.
\endverbatim
*/
Expand All @@ -221,7 +220,7 @@ class PDAL_DLL Bounds
}
m_ranges[index].setMaximum(v);
}

/// A Vector of minimum values for each Range of the Bounds
Vector<T> getMinimum()
{
Expand All @@ -234,7 +233,7 @@ class PDAL_DLL Bounds

return Vector<T>(vec);
}

/// A Vector of maximum values for each Range of the Bounds
Vector<T> getMaximum()
{
Expand All @@ -259,7 +258,7 @@ class PDAL_DLL Bounds
{
return m_ranges.size();
}

/// Calculate a n-dimensional volume for the Bounds instance
T volume() const
{
Expand Down Expand Up @@ -390,7 +389,7 @@ class PDAL_DLL Bounds
}

/// @name Transformation

/// Shift each dimension by a vector of deltas
void shift(std::vector<T> deltas)
{
Expand Down Expand Up @@ -446,7 +445,7 @@ class PDAL_DLL Bounds
}
void grow(double const& x, double const& y, double const& z)
{

m_ranges[0].grow(x);
m_ranges[1].grow(y);
if (size() == 3)
Expand Down Expand Up @@ -494,7 +493,7 @@ class PDAL_DLL Bounds
}
return true;
}

/** @name Default extent
*/
/// Returns a staticly-allocated Bounds extent that represents infinity
Expand All @@ -508,39 +507,26 @@ class PDAL_DLL Bounds

/** @name Summary and serialization
*/
/// Outputs a string-based boost::property_tree::ptree representation
/// of the Bounds instance
boost::property_tree::ptree toPTree() const
{
boost::property_tree::ptree tree;
for (std::size_t i = 0; i < size(); ++i)
{
const Range<T>& r = dimensions()[i];
tree.add_child(boost::lexical_cast<std::string>(i), r.toPTree());
}
return tree;
}

/// Returns the Bounds<T> instance as OGC WKT
/// @param precision the numerical precision to use for the output stream
/// @param precision the numerical precision to use for the output stream
/// describing the number of decimal places each point in the WKT will have
/// @param dimensions override the dimensionality of the WKT. Defaults to
/// @param dimensions override the dimensionality of the WKT. Defaults to
/// 0, and if not set, dimensionality of the WKT is determined by Bounds<T>::size()
std::string toWKT(boost::uint32_t precision = 8) const
{
std::stringstream oss;

oss.precision(precision);
oss.setf(std::ios_base::fixed, std::ios_base::floatfield);

oss << "POLYGON ((";

oss << getMinimum(0) << " " << getMinimum(1) << ", ";
oss << getMinimum(0) << " " << getMaximum(1) << ", ";
oss << getMaximum(0) << " " << getMaximum(1) << ", ";
oss << getMaximum(0) << " " << getMinimum(1) << ", ";
oss << getMinimum(0) << " " << getMinimum(1);

// Nothing happens for 3D bounds.
// else if (m_ranges.size() == 3 || (dimensions != 0 && dimensions == 3))
// {
Expand All @@ -557,18 +543,18 @@ class PDAL_DLL Bounds
std::string toBox(boost::uint32_t precision = 8, boost::uint32_t dimensions=2) const
{
std::stringstream oss;

oss.precision(precision);
oss.setf(std::ios_base::fixed, std::ios_base::floatfield);


if (dimensions == 2)
{
oss << "BOX(";
oss << getMinimum(0) << " " << getMinimum(1) << ", ";
oss << getMaximum(0) << " " << getMaximum(1) << ")";
}

else if (dimensions == 3)
{
oss << "BOX3D(";
Expand All @@ -577,7 +563,7 @@ class PDAL_DLL Bounds
}
return oss.str();
}

};


Expand Down
2 changes: 1 addition & 1 deletion include/pdal/Dimension.hpp
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (c) 2014, Hobu Inc.
* Copyright (c) 2016, Hobu Inc.
*
* All rights reserved.
*
Expand Down
28 changes: 17 additions & 11 deletions include/pdal/Metadata.hpp
Expand Up @@ -68,7 +68,7 @@ class PDAL_DLL ByteArray
/// Constructs a ByteArray instance with the given array of data.
ByteArray(std::vector<boost::uint8_t> const& data) : m_bytes(data)
{}

ByteArray()
{}

Expand Down Expand Up @@ -114,18 +114,18 @@ class MetadataNodeImpl

private:
MetadataNodeImpl(const std::string& name) :
m_name(name), m_nodeType(MetadataType::Instance)
m_name(name), m_kind(MetadataType::Instance)
{}

MetadataNodeImpl() : m_nodeType(MetadataType::Instance)
MetadataNodeImpl() : m_kind(MetadataType::Instance)
{}

void makeArray(MetadataImplList& l)
{
for (auto li = l.begin(); li != l.end(); ++li)
{
MetadataNodeImplPtr node = *li;
node->m_nodeType = MetadataType::Array;
node->m_kind = MetadataType::Array;
}
}

Expand Down Expand Up @@ -222,21 +222,21 @@ class MetadataNodeImpl
if (l.size())
{
MetadataNodeImplPtr node = *l.begin();
return node->m_nodeType;
return node->m_kind;
}
return MetadataType::Instance;
}



std::string toJSON() const;
void toJSON(std::ostream& o, int level) const;
void subnodesToJSON(std::ostream& o, int level) const;
boost::property_tree::ptree toPTree() const;


std::string m_name;
std::string m_descrip;
std::string m_type;
std::string m_value;
MetadataType::Enum m_nodeType;
MetadataType::Enum m_kind;
MetadataSubnodes m_subnodes;
};

Expand Down Expand Up @@ -450,6 +450,13 @@ class PDAL_DLL MetadataNode

std::string type() const
{ return m_impl->m_type; }
std::string kind() const
{
if (m_impl->m_kind == MetadataType::Array)
return "array";
else
return "instance";
}
std::string name() const
{ return m_impl->m_name; }
std::string value() const
Expand Down Expand Up @@ -554,7 +561,6 @@ class PDAL_DLL MetadataNode
}

std::string toJSON() const;
boost::property_tree::ptree toPTree() const;

private:
MetadataNodeImplPtr m_impl;
Expand All @@ -581,7 +587,7 @@ class Metadata
public:
Metadata() : m_root("root"), m_private("private")
{}

Metadata(const std::string& name) : m_name(name)
{}

Expand Down
12 changes: 1 addition & 11 deletions include/pdal/Options.hpp
Expand Up @@ -230,12 +230,6 @@ class PDAL_DLL Option
}
#endif

/// @name Summary and serialization

/// @return a boost::property_tree::ptree representation
/// of the Option instance
boost::property_tree::ptree toPTree() const;

/// @name Private attributes
private:
std::string m_name;
Expand Down Expand Up @@ -298,8 +292,7 @@ class PDAL_DLL Options
{
if (&rhs != this)
{
options::map_t::const_iterator i;
for (i = rhs.m_options.begin(); i != rhs.m_options.end(); ++i)
for (auto i = rhs.m_options.begin(); i != rhs.m_options.end(); ++i)
{
m_options.insert(std::pair<std::string, Option>(
i->first, i->second));
Expand Down Expand Up @@ -381,9 +374,6 @@ class PDAL_DLL Options
// returns true iff the option name is valid
bool hasOption(std::string const& name) const;

// returns a ptree for the whole option block
boost::property_tree::ptree toPTree() const;

// the empty options list
// BUG: this should be a member variable, not a function, but doing so
// causes vs2010 to fail to link
Expand Down

0 comments on commit 8f69750

Please sign in to comment.