Skip to content

Commit

Permalink
Add nativeBounds parameter to /read requests for more natural non-ren…
Browse files Browse the repository at this point in the history
…derer query behavior.
  • Loading branch information
connormanning committed Nov 30, 2017
1 parent d073de6 commit fa07fdd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
16 changes: 16 additions & 0 deletions entwine/reader/query-params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#pragma once

#include <cstddef>
#include <memory>

#include <json/json.h>

#include <entwine/types/bounds.hpp>
#include <entwine/types/delta.hpp>
#include <entwine/util/unique.hpp>

namespace entwine
{
Expand Down Expand Up @@ -89,6 +91,16 @@ class QueryParams
throw std::runtime_error("Invalid depth specification");
}
}

if (q.isMember("nativeBounds"))
{
if (q.isMember("bounds"))
{
throw std::runtime_error("Cannot specify multiple bounds");
}

m_nativeBounds = std::make_shared<Bounds>(q["nativeBounds"]);
}
}

const Bounds& bounds() const { return m_bounds; }
Expand All @@ -97,12 +109,16 @@ class QueryParams
std::size_t de() const { return m_depthEnd; }
const Json::Value& filter() const { return m_filter; }

const Bounds* nativeBounds() const { return m_nativeBounds.get(); }

private:
const Bounds m_bounds;
const Delta m_delta;
const std::size_t m_depthBegin;
const std::size_t m_depthEnd;
const Json::Value m_filter;

std::shared_ptr<Bounds> m_nativeBounds;
};

} // namespace entwine
Expand Down
18 changes: 14 additions & 4 deletions entwine/reader/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,17 @@ Bounds Query::localize(const Bounds& q, const Delta& localDelta) const

Query::Query(const Reader& reader, const QueryParams& p)
: m_reader(reader)
, m_params(p)
, m_metadata(m_reader.metadata())
, m_structure(m_metadata.structure())
, m_delta(localize(p.delta()))
, m_bounds(localize(p.bounds(), m_delta))
, m_delta(
p.nativeBounds() ?
p.delta() :
localize(p.delta()))
, m_bounds(
p.nativeBounds() ?
localize(*p.nativeBounds(), m_metadata.delta()->inverse()) :
localize(p.bounds(), m_delta))
, m_depthBegin(p.db())
, m_depthEnd(p.de() ? p.de() : std::numeric_limits<uint32_t>::max())
, m_filter(m_reader.metadata(), m_bounds, p.filter(), &m_delta)
Expand Down Expand Up @@ -265,7 +272,10 @@ ReadQuery::ReadQuery(
: Query(reader, params)
, m_schema(schema.empty() ? m_metadata.schema() : schema)
, m_reg(reader, m_schema)
, m_mid(m_metadata.boundsScaledCubic().mid())
, m_mid(
params.nativeBounds() ?
m_delta.offset() :
m_metadata.boundsScaledCubic().mid())
{ }

void ReadQuery::chunk(const ChunkReader& cr)
Expand Down Expand Up @@ -293,7 +303,7 @@ void ReadQuery::process(const PointInfo& info)
{
const DimInfo& dimInfo(dim.info());
dimNum = pdal::Utils::toNative(dimInfo.id()) - 1;
if (m_delta.exists() && dimNum < 3)
if ((m_delta.exists() || m_params.nativeBounds()) && dimNum < 3)
{
setScaled(dimInfo, dimNum, pos);
}
Expand Down
27 changes: 22 additions & 5 deletions entwine/reader/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Query
void processPoint(const PointInfo& info);

const Reader& m_reader;
const QueryParams m_params;
const Metadata& m_metadata;
const Structure& m_structure;
const Delta m_delta;
Expand Down Expand Up @@ -167,11 +168,27 @@ class ReadQuery : public Query
private:
void setScaled(const DimInfo& dim, std::size_t dimNum, char* pos)
{
const double d = Point::scale(
m_pointRef.getFieldAs<double>(dim.id()),
m_mid[dimNum],
m_delta.scale()[dimNum],
m_delta.offset()[dimNum]);
double d(0);
if (m_params.nativeBounds())
{
d = Point::unscale(
m_pointRef.getFieldAs<double>(dim.id()),
m_metadata.delta()->scale()[dimNum],
m_metadata.delta()->offset()[dimNum]);

d = Point::scale(
d,
m_delta.scale()[dimNum],
m_delta.offset()[dimNum]);
}
else
{
d = Point::scale(
m_pointRef.getFieldAs<double>(dim.id()),
m_mid[dimNum],
m_delta.scale()[dimNum],
m_delta.offset()[dimNum]);
}

switch (dim.type())
{
Expand Down

0 comments on commit fa07fdd

Please sign in to comment.