Skip to content

Commit

Permalink
Update Ept code.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Apr 18, 2019
1 parent 51bc44b commit e67040f
Show file tree
Hide file tree
Showing 7 changed files with 10,203 additions and 9,601 deletions.
47 changes: 20 additions & 27 deletions io/EptAddonWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

#include <cassert>

#include <json/json.h>

#include <arbiter/arbiter.hpp>

#include "private/EptSupport.hpp"
Expand All @@ -59,18 +57,17 @@ namespace
CREATE_STATIC_STAGE(EptAddonWriter, s_info)

EptAddonWriter::EptAddonWriter()
: m_addonsArg(new Json::Value())
{ }
{}

EptAddonWriter::~EptAddonWriter()
{ }
{}

std::string EptAddonWriter::getName() const { return s_info.name; }

void EptAddonWriter::addArgs(ProgramArgs& args)
{
args.add("addons", "Mapping of output locations to their dimension names",
*m_addonsArg).setPositional();
m_addonsArg).setPositional();
args.add("threads", "Number of worker threads", m_numThreads);
}

Expand All @@ -95,17 +92,17 @@ void EptAddonWriter::prepared(PointTableRef table)
m_pool.reset(new Pool(threads));

const PointLayout& layout(*table.layout());
for (const std::string path : m_addonsArg->getMemberNames())
for (auto it : m_addonsArg.items())
{
const std::string& path = it.key();
const std::string& dimName = it.value().get<std::string>();

const auto endpoint(
m_arbiter->getEndpoint(arbiter::fs::expandTilde(path)));

const std::string dimName((*m_addonsArg)[path].asString());
const Dimension::Id id(layout.findDim(dimName));

if (id == Dimension::Id::Unknown)
throwError("Cannot find dimension: " + dimName);

throwError("Cannot find dimension '" + dimName + "'.");
m_addons.emplace_back(new Addon(layout, endpoint, id));
}
}
Expand All @@ -129,10 +126,8 @@ void EptAddonWriter::ready(PointTableRef table)
m_hierarchyStep = meta.findChild("step").value<uint64_t>();
m_info.reset(new EptInfo(info));

for (const std::string s : keys.getMemberNames())
{
m_hierarchy[Key(s)] = keys[s].asUInt64();
}
for (auto el : keys.items())
m_hierarchy[Key(el.key())] = el.value().get<uint64_t>();
}
catch (std::exception& e)
{
Expand Down Expand Up @@ -213,25 +208,25 @@ void EptAddonWriter::writeOne(const PointViewPtr view, const Addon& addon) const
m_pool->await();

// Write the addon hierarchy data.
Json::Value h;
NL::json h;
Key key;
key.b = m_info->bounds();
writeHierarchy(h, key, hierEp);
hierEp.put(key.toString() + ".json", h.toStyledString());
hierEp.put(key.toString() + ".json", h.dump());

m_pool->await();

// Write the top-level addon metadata.
Json::Value meta;
NL::json meta;
meta["type"] = getTypeString(addon.type());
meta["size"] = static_cast<Json::UInt64>(addon.size());
meta["size"] = addon.size();
meta["version"] = "1.0.0";
meta["dataType"] = "binary";

ep.put("ept-addon.json", meta.toStyledString());
ep.put("ept-addon.json", meta.dump());
}

void EptAddonWriter::writeHierarchy(Json::Value& curr, const Key& key,
void EptAddonWriter::writeHierarchy(NL::json& curr, const Key& key,
const arbiter::Endpoint& hierEp) const
{
const std::string keyName(key.toString());
Expand All @@ -245,21 +240,19 @@ void EptAddonWriter::writeHierarchy(Json::Value& curr, const Key& key,
curr[keyName] = -1;

// Create a new hierarchy subtree.
Json::Value next;
next[keyName] = static_cast<Json::UInt64>(np);
NL::json next {{ keyName, np }};

for (uint64_t dir(0); dir < 8; ++dir)
{
writeHierarchy(next, key.bisect(dir), hierEp);
}

m_pool->add([&hierEp, keyName, next]()
{
hierEp.put(keyName + ".json", stringify(next));
hierEp.put(keyName + ".json", next.dump());
});
}
else
{
curr[keyName] = static_cast<Json::UInt64>(np);
curr[keyName] = np;
for (uint64_t dir(0); dir < 8; ++dir)
{
writeHierarchy(curr, key.bisect(dir), hierEp);
Expand Down
8 changes: 4 additions & 4 deletions io/EptAddonWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
#include <cstddef>
#include <memory>

#include <pdal/Writer.hpp>
#include <nlohmann/json.hpp>

namespace Json { class Value; }
#include <pdal/Writer.hpp>

namespace pdal
{
Expand Down Expand Up @@ -72,11 +72,11 @@ class PDAL_DLL EptAddonWriter : public Writer
std::unique_ptr<arbiter::Arbiter> m_arbiter;
std::unique_ptr<Pool> m_pool;

std::unique_ptr<Json::Value> m_addonsArg;
NL::json m_addonsArg;
std::vector<std::unique_ptr<Addon>> m_addons;

void writeOne(const PointViewPtr view, const Addon& addon) const;
void writeHierarchy(Json::Value& hier, const Key& key,
void writeHierarchy(NL::json& hier, const Key& key,
const arbiter::Endpoint& hierEp) const;
std::string getTypeString(Dimension::Type t) const;

Expand Down

0 comments on commit e67040f

Please sign in to comment.