Skip to content

Commit

Permalink
filter done, now starting to connect to writer
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgerlek committed May 1, 2015
1 parent 68c71f8 commit 1f6d962
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 93 deletions.
48 changes: 26 additions & 22 deletions filters/tiler/TilerCommon.cpp
Expand Up @@ -48,16 +48,25 @@ namespace tilercommon


TileSet::TileSet(
const PointView& sourceView,
PointViewSet& outputSet,
uint32_t maxLevel,
LogPtr log) :
m_sourceView(NULL),
m_outputSet(NULL),
m_sourceView(sourceView),
m_outputSet(outputSet),
m_maxLevel(maxLevel),
m_log(log),
m_roots(NULL)

{
assert(m_maxLevel <= 32);

// TODO: for now, we only support two tiles at the root
m_roots = new tilercommon::Tile*[2];
const tilercommon::Rectangle r00(-180.0, -90.0, 0.0, 90.0); // wsen
const tilercommon::Rectangle r10(0.0, -90.0, 180.0, 90.0);
m_roots[0] = new tilercommon::Tile(*this, 0, 0, 0, r00);
m_roots[1] = new tilercommon::Tile(*this, 0, 1, 0, r10);
}


Expand All @@ -71,20 +80,16 @@ TileSet::~TileSet()
}


void TileSet::prep(const PointView* sourceView, PointViewSet* outputSet)
PointViewPtr TileSet::createPointView()
{
m_sourceView = sourceView;
m_outputSet = outputSet;

m_roots = new tilercommon::Tile*[2];
PointViewPtr p = m_sourceView.makeNew();
m_outputSet.insert(p);

const tilercommon::Rectangle r00(-180.0, -90.0, 0.0, 90.0); // wsen
const tilercommon::Rectangle r10(0.0, -90.0, 180.0, 90.0);
m_roots[0] = new tilercommon::Tile(*this, 0, 0, 0, r00);
m_roots[1] = new tilercommon::Tile(*this, 0, 1, 0, r10);
return p;
}


// enter the point into the tree
void TileSet::addPoint(PointId idx, double lon, double lat)
{
if (lon < 0)
Expand All @@ -94,6 +99,7 @@ void TileSet::addPoint(PointId idx, double lon, double lat)
}


// set the metadata for each tree node
void TileSet::setMetadata(MetadataNode& root)
{
assert(root.valid());
Expand All @@ -105,15 +111,6 @@ void TileSet::setMetadata(MetadataNode& root)
}


PointViewPtr TileSet::createPointView()
{
PointViewPtr p = m_sourceView->makeNew();
m_outputSet->insert(p);

return p;
}


Tile::Tile(
TileSet& tileSet,
uint32_t level,
Expand Down Expand Up @@ -178,6 +175,7 @@ Tile::~Tile()
}


// set the metaadata for this node, and then recurse down
void Tile::setMetadata(MetadataNode& tileSetNode)
{
// child mask
Expand Down Expand Up @@ -212,7 +210,13 @@ void Tile::setMetadata(MetadataNode& tileSetNode)
}


void Tile::add(const PointView* sourcePointView, PointId pointNumber, double lon, double lat)
// Add the point to this tile.
//
// If we're not a leaf tile, add the point only if we're a module-N numbered
// point, where N is based on the level.
//
// If we're not a leaf tile, add the node to one of our child tiles.
void Tile::add(const PointView& sourcePointView, PointId pointNumber, double lon, double lat)
{
assert(m_rect.contains(lon, lat));

Expand All @@ -228,7 +232,7 @@ void Tile::add(const PointView* sourcePointView, PointId pointNumber, double lon
}
assert(m_pointView);

m_pointView->appendPoint(*sourcePointView, pointNumber);
m_pointView->appendPoint(sourcePointView, pointNumber);
}

if (m_level == m_tileSet.getMaxLevel()) return;
Expand Down
26 changes: 18 additions & 8 deletions filters/tiler/TilerCommon.hpp
Expand Up @@ -133,36 +133,46 @@ class Rectangle
class Tile;


// the tile set holds all the tiles that make up the tile tree
//
// (note the tree is not technically a tree as it has two roots,
// one on each side of Greenwich)
class TileSet
{
public:
TileSet(uint32_t maxLevel, LogPtr log);
TileSet(const PointView& sourceView, PointViewSet& outputSet, uint32_t maxLevel, LogPtr log);
~TileSet();

void prep(const PointView* sourceView, PointViewSet* outputSet);
void addPoint(PointId, double lon, double lat);
uint32_t getMaxLevel() const { return m_maxLevel; }
LogPtr log() { return m_log; }
void setMetadata(MetadataNode&);

void addPoint(PointId, double lon, double lat);
PointViewPtr createPointView();
void setMetadata(MetadataNode&);

LogPtr log() { return m_log; }

private:
const PointView* m_sourceView;
PointViewSet* m_outputSet;
const PointView& m_sourceView;
PointViewSet& m_outputSet;
uint32_t m_maxLevel;
LogPtr m_log;
Tile** m_roots;
MetadataNode m_metadata;
};


// A node of the tile tree
//
// Tiles are identified by level, column (x), and row (y)
// A tile may contain points; if so, m_pointView will be set.
// A tile may have 0..3 children.
class Tile
{
public:
Tile(TileSet& tileSet, uint32_t level, uint32_t tx, uint32_t ty, Rectangle r);
~Tile();

void add(const PointView* pointView, PointId pointNumber, double lon, double lat);
void add(const PointView& pointView, PointId pointNumber, double lon, double lat);

void collectStats(std::vector<uint32_t> numTilesPerLevel,
std::vector<uint64_t> numPointsPerLevel) const;
Expand Down
49 changes: 19 additions & 30 deletions filters/tiler/TilerFilter.cpp
Expand Up @@ -53,8 +53,6 @@ std::string TilerFilter::getName() const { return s_info.name; }

void TilerFilter::processOptions(const Options& options)
{
m_tileSet = NULL;

m_maxLevel = options.getValueOrDefault<uint32_t>("maxLevel");

// TODO: make these be options
Expand All @@ -70,60 +68,51 @@ Options TilerFilter::getDefaultOptions()
{
Options options;

options.add("maxLevel", 23, "Number of levels"); // yields 0..23
options.add("maxLevel", 23, "Number of highest level"); // yields 0..23

return options;
}


void TilerFilter::ready(PointTableRef table)
{
assert(!m_tileSet);
m_tileSet = new tilercommon::TileSet(m_maxLevel, log());
}


void TilerFilter::done(PointTableRef table)
{
if (m_tileSet) {
delete m_tileSet;
m_tileSet = NULL;
}
}


PointViewSet TilerFilter::run(PointViewPtr sourceView)
{
// TODO: assert the input is ESPG:4326

assert(m_tileSet);

PointViewSet outputSet;
const PointView& sourceViewRef(*sourceView.get());
m_tileSet->prep(sourceView.get(), &outputSet);

// build the tiles
tilercommon::TileSet tileSet(sourceViewRef, outputSet, m_maxLevel, log());

// enter each point into the tile set
for (PointId idx = 0; idx < sourceViewRef.size(); ++idx)
{
const double lon = sourceViewRef.getFieldAs<double>(Dimension::Id::X, idx);
const double lat = sourceViewRef.getFieldAs<double>(Dimension::Id::Y, idx);
m_tileSet->addPoint(idx, lon, lat);
tileSet.addPoint(idx, lon, lat);
}

// set the metadata
// Set the metadata for the tile set
// tileset:
// <tile id>:
// level = <l>
// tileX = <x>
// tileY = <y>
// mask = <m>
// pointView = <point view id> # optional
// <tile id>:
// ...
//
// Note the point view node will only be present if the tile contains
// any points.
{
assert(outputSet.size() != 0);
PointViewPtr tmp = *(outputSet.begin());
MetadataNode root = tmp->metadata();
assert(root.valid());

m_tileSet->setMetadata(root);
tileSet.setMetadata(root);
}

// cleanup
delete m_tileSet;
m_tileSet = NULL;

return outputSet;
}

Expand Down
13 changes: 4 additions & 9 deletions filters/tiler/TilerFilter.hpp
Expand Up @@ -53,18 +53,13 @@ class PDAL_DLL TilerFilter : public pdal::Filter
static int32_t destroy(void *);
std::string getName() const;

void ready(PointTableRef table);
void done(PointTableRef table);

Options getDefaultOptions();

private:
int32_t m_maxLevel;
int32_t m_numTilesX;
int32_t m_numTilesY;
tilercommon::Rectangle m_rectangle;

tilercommon::TileSet *m_tileSet;
int32_t m_maxLevel; // number of highest level
int32_t m_numTilesX; // number of tile rows at level 0
int32_t m_numTilesY; // number of tile columns at level 0
tilercommon::Rectangle m_rectangle; // bbox of tile tree

virtual void processOptions(const Options& options);
virtual PointViewSet run(PointViewPtr view);
Expand Down

0 comments on commit 1f6d962

Please sign in to comment.