Skip to content

Commit

Permalink
Use spatial bounds box in EPT reader.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Apr 30, 2019
1 parent 005c458 commit 5e69dbc
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 217 deletions.
4 changes: 4 additions & 0 deletions filters/CropFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ void CropFilter::transform(const SpatialReference& srs)
// If we don't have any SRS, do nothing.
if (srs.empty() && m_args->m_assignedSrs.empty())
return;

// Note that we should never have assigned SRS empty here since
// if it is missing we assign it from the point data.
assert(!m_args->m_assignedSrs.empty());
if (srs.empty() || m_args->m_assignedSrs.empty())
throwError("Unable to transform crop geometry to point "
"coordinate system.");
Expand Down
115 changes: 80 additions & 35 deletions io/EptReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
#include <limits>

#include "private/EptSupport.hpp"

#include "LasReader.hpp"

#include <arbiter/arbiter.hpp>

#include <pdal/GDALUtils.hpp>
#include <pdal/util/Algorithm.hpp>

namespace pdal
Expand All @@ -57,11 +59,63 @@ namespace
};

const std::string addonFilename { "ept-addon.json" };

Dimension::Type getType(const NL::json& dim)
{
if (dim.contains("scale"))
return Dimension::Type::Double;

const std::string typestring(dim["type"].get<std::string>());
const uint64_t size(dim["size"].get<uint64_t>());

return Dimension::type(typestring, size);
}
}

CREATE_STATIC_STAGE(EptReader, s_info);

EptReader::EptReader()
class EptBounds : public Bounds
{
public:
static constexpr double LOWEST = (std::numeric_limits<double>::lowest)();
static constexpr double HIGHEST = (std::numeric_limits<double>::max)();

EptBounds() : Bounds(BOX3D(LOWEST, LOWEST, LOWEST,
HIGHEST, HIGHEST, HIGHEST))
{}
};

namespace Utils
{
template<>
bool fromString<EptBounds>(const std::string& s, EptBounds& bounds)
{

if (!fromString(s, (Bounds&)bounds))
return false;

if (!bounds.is3d())
{
BOX2D box = bounds.to2d();
bounds.grow(box.minx, box.miny, EptBounds::LOWEST);
bounds.grow(box.maxx, box.maxy, EptBounds::HIGHEST);
}
return true;
}
}

struct EptReader::Args
{
public:
EptBounds m_bounds;
std::string m_origin;
std::size_t m_threads = 0;
double m_resolution = 0;
NL::json m_addons;
};


EptReader::EptReader() : m_argsPtr(new EptReader::Args), m_args(*m_argsPtr)
{}

EptReader::~EptReader()
Expand All @@ -71,35 +125,14 @@ std::string EptReader::getName() const { return s_info.name; }

void EptReader::addArgs(ProgramArgs& args)
{
args.add("bounds", "Bounds to fetch", m_args.boundsArg());
args.add("origin", "Origin of source file to fetch", m_args.originArg());
args.add("threads", "Number of worker threads", m_args.threadsArg());
args.add("resolution", "Resolution limit", m_args.resolutionArg());
args.add("bounds", "Bounds to fetch", m_args.m_bounds);
args.add("origin", "Origin of source file to fetch", m_args.m_origin);
args.add("threads", "Number of worker threads", m_args.m_threads);
args.add("resolution", "Resolution limit", m_args.m_resolution);
args.add("addons", "Mapping of addon dimensions to their output directory",
m_args.addonsArg());
m_args.m_addons);
}

BOX3D EptReader::Args::bounds() const
{
// If already 3D (which is non-empty), return it as-is.
if (m_bounds.is3d())
return m_bounds.to3d();

// If empty, return maximal extents to select everything.
const BOX2D b(m_bounds.to2d());
if (b.empty())
{
const double mn((std::numeric_limits<double>::lowest)());
const double mx((std::numeric_limits<double>::max)());
return BOX3D(mn, mn, mn, mx, mx, mx);
}

// Finally if 2D and non-empty, convert to 3D with all-encapsulating
// Z-values.
return BOX3D(
b.minx, b.miny, (std::numeric_limits<double>::lowest)(),
b.maxx, b.maxy, (std::numeric_limits<double>::max)());
}

void EptReader::initialize()
{
Expand All @@ -123,7 +156,8 @@ void EptReader::initialize()

m_arbiter.reset(new arbiter::Arbiter());
m_ep.reset(new arbiter::Endpoint(m_arbiter->getEndpoint(m_root)));
const std::size_t threads(m_args.threads());

const std::size_t threads(std::max(m_args.m_threads, size_t(4)));
if (threads > 100)
{
log()->get(LogLevel::Warning) << "Using a large thread count: " <<
Expand All @@ -140,13 +174,21 @@ void EptReader::initialize()
{
throwError(e.what());
}

debug << "Got EPT info" << std::endl;
debug << "SRS: " << m_info->srs() << std::endl;

const SpatialReference& boundsSrs = m_args.m_bounds.spatialReference();
if (!m_info->srs().valid() && boundsSrs.valid())
throwError("Can't use bounds with SRS with data source that has "
"no SRS.");

setSpatialReference(m_info->srs());

// Figure out our query parameters.
m_queryBounds = m_args.bounds();
m_queryBounds = m_args.m_bounds.to3d();
if (boundsSrs.valid())
gdal::reprojectBounds(m_queryBounds,
boundsSrs.getWKT(), m_info->srs().getWKT());

try
{
handleOriginQuery();
Expand All @@ -157,7 +199,7 @@ void EptReader::initialize()
}

// Figure out our max depth.
const double queryResolution(m_args.resolution());
const double queryResolution(m_args.m_resolution);
if (queryResolution)
{
double currentResolution =
Expand All @@ -184,11 +226,14 @@ void EptReader::initialize()
debug << "Threads: " << m_pool->size() << std::endl;
}


void EptReader::handleOriginQuery()
{
if (m_args.origin().empty()) return;
const std::string search(m_args.m_origin);

if (search.empty())
return;

const std::string search(m_args.origin());
log()->get(LogLevel::Debug) << "Searching sources for " << search <<
std::endl;

Expand Down Expand Up @@ -327,7 +372,7 @@ void EptReader::addDimensions(PointLayoutPtr layout)

try
{
for (auto it : m_args.addons().items())
for (auto it : m_args.m_addons.items())
{
std::string dimName = it.key();
const NL::json& val = it.value();
Expand Down
45 changes: 9 additions & 36 deletions io/EptReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@
#pragma once

#include <array>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <mutex>
#include <set>

#include <nlohmann/json.hpp>

#include <pdal/Bounds.hpp>
#include <pdal/Reader.hpp>
#include <pdal/Streamable.hpp>

#include <nlohmann/json.hpp>

namespace pdal
{
Expand All @@ -69,14 +65,14 @@ class PDAL_DLL EptReader : public Reader
virtual ~EptReader();
std::string getName() const override;

private:
virtual void addArgs(ProgramArgs& args) override;
virtual void initialize() override;
virtual QuickInfo inspect() override;
virtual void addDimensions(PointLayoutPtr layout) override;
virtual void ready(PointTableRef table) override;
virtual PointViewSet run(PointViewPtr view) override;

private:
// If argument "origin" is specified, this function will clip the query
// bounds to the bounds of the specified origin and set m_queryOriginId to
// the selected OriginId value. If the selected origin is not found, throw.
Expand All @@ -86,8 +82,7 @@ class PDAL_DLL EptReader : public Reader
// points from a walk through the hierarchy. Each of these keys will be
// downloaded during the 'read' section.
void overlaps();
void overlaps(
const arbiter::Endpoint& ep, std::map<Key, uint64_t>& target,
void overlaps(const arbiter::Endpoint& ep, std::map<Key, uint64_t>& target,
const NL::json& current, const Key& key);

uint64_t readLaszip(PointView& view, const Key& key, uint64_t nodeId) const;
Expand All @@ -104,33 +99,11 @@ class PDAL_DLL EptReader : public Reader
std::unique_ptr<arbiter::Endpoint> m_ep;
std::unique_ptr<EptInfo> m_info;

class Args
{
public:
Bounds& boundsArg() { return m_bounds; }
std::string& originArg() { return m_origin; }
std::size_t& threadsArg() { return m_threads; }
double& resolutionArg() { return m_resolution; }
NL::json& addonsArg() { return m_addons; }

BOX3D bounds() const;
std::string origin() const { return m_origin; }
std::size_t threads() const
{
return std::max<std::size_t>(4, m_threads);
}
double resolution() const { return m_resolution; }
const NL::json& addons() const { return m_addons; }

private:
Bounds m_bounds;
std::string m_origin;
std::size_t m_threads = 0;
double m_resolution = 0;
NL::json m_addons;
};

Args m_args;
struct Args;

std::unique_ptr<Args> m_argsPtr;
Args& m_args;

BOX3D m_queryBounds;
int64_t m_queryOriginId = -1;
std::unique_ptr<Pool> m_pool;
Expand Down

0 comments on commit 5e69dbc

Please sign in to comment.