Skip to content

Commit

Permalink
reader validating (needs Ptr work)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgerlek committed May 7, 2015
1 parent 325c80a commit f7c426e
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 9 deletions.
49 changes: 41 additions & 8 deletions plugins/rialto/io/RialtoDb.cpp
Expand Up @@ -43,6 +43,7 @@
#include <pdal/PointView.hpp>
#include <pdal/util/Bounds.hpp>
#include <pdal/util/FileUtils.hpp>
#include <pdal/BufferReader.hpp>

#include <cstdint>

Expand Down Expand Up @@ -631,7 +632,31 @@ std::vector<uint32_t> RialtoDb::queryForTileIds(uint32_t tileSetId,
}


Stage* RialtoDb::query(uint32_t tileSetId,
// appends points to end of view (does not start with point index 0)
static void serializeToPointView(const rialtosupport::RialtoDb::TileInfo& info, PointViewPtr view, LogPtr log)
{
const size_t numPoints = info.numPoints;
PointId idx = view->size();
const uint32_t pointSize = view->pointSize();

const Patch& patch = info.patch;

const char* buf = (const char*)(&patch.buf[0]);
const DimTypeList& dtl = view->dimTypes();
for (size_t i=0; i<numPoints; ++i)
{
view->setPackedPoint(dtl, idx, buf);
buf += pointSize;
++idx;

log->get(LogLevel::Debug) << "here" << std::endl;
}
}


Stage* RialtoDb::query(PointTable& table,
PointViewPtr view,
uint32_t tileSetId,
double minx, double miny,
double maxx, double maxy,
uint32_t level)
Expand All @@ -645,21 +670,29 @@ Stage* RialtoDb::query(uint32_t tileSetId,
maxx, maxy, level);
if (!ids.size()) return NULL;

PointTable table;
PointViewPtr inputView(new PointView(table));

table.layout()->registerDim(Dimension::Id::X); // TODO
table.layout()->registerDim(Dimension::Id::Y);
table.layout()->registerDim(Dimension::Id::Z);

TileInfo info;
uint32_t pointIndex = 0;
for (auto id: ids)
{
getTileInfo(id, true);
TileInfo info = getTileInfo(id, true);

log()->get(LogLevel::Debug) << " got some points: " << info.numPoints << std::endl;

serializeToPointView(info, view, log());

log()->get(LogLevel::Debug) << " view now has this many: " << view->size() << std::endl;
}

assert(0);
return NULL;
Options readerOptions;
BufferReader* reader = new BufferReader(); // TODO: need ptr
reader->setOptions(readerOptions);
reader->addView(view);
reader->setSpatialReference(SpatialReference("EPSG:4326"));

return reader;
}


Expand Down
4 changes: 3 additions & 1 deletion plugins/rialto/io/RialtoDb.hpp
Expand Up @@ -135,7 +135,9 @@ class PDAL_DLL RialtoDb
// query for all the points of a tile set, bounded by bbox region
// returns a pipeline made up of a BufferReader and a CropFilter
// returns NULL if no points found
Stage* query(uint32_t tileSetId,
Stage* query(PointTable& table,
PointViewPtr view,
uint32_t tileSetId,
double minx, double miny,
double max, double maxy,
uint32_t level);
Expand Down
40 changes: 40 additions & 0 deletions plugins/rialto/test/RialtoDbWriterTest.cpp
Expand Up @@ -115,6 +115,20 @@ static void verifyBytes(std::vector<unsigned char>& buf,
}


// verify point view has the correct data
static void testPoint(PointViewPtr view, PointId idx, const Data& data)
{
const double x = view->getFieldAs<double>(Dimension::Id::X, idx);
const double y = view->getFieldAs<double>(Dimension::Id::Y, idx);
const double z = view->getFieldAs<double>(Dimension::Id::Z, idx);

EXPECT_FLOAT_EQ(x, data.x);
EXPECT_FLOAT_EQ(y, data.y);
EXPECT_FLOAT_EQ(z, data.z);
}



TEST(RialtoDbWriterTest, testWriter)
{
FileUtils::deleteFile(Support::temppath("rialto2.sqlite"));
Expand Down Expand Up @@ -290,5 +304,31 @@ TEST(RialtoDbWriterTest, testWriter)
EXPECT_EQ(ids.size(), 8u); // should be 2
}

{
PointTable table;
PointViewPtr view(new PointView(table));

Stage* stage = db.query(table, view, 0, 0.0, 0.0, 180.0, 90.0, 2);

// execution
stage->prepare(table);
PointViewSet outputViews = stage->execute(table);
EXPECT_EQ(outputViews.size(), 1u);
for (auto outView: outputViews)
{
EXPECT_EQ(outView->size(), 8u);
}

PointViewPtr outView = *(outputViews.begin());
testPoint(outView, 0, data[0]);
testPoint(outView, 1, data[1]);
testPoint(outView, 2, data[2]);
testPoint(outView, 3, data[3]);
testPoint(outView, 4, data[4]);
testPoint(outView, 5, data[5]);
testPoint(outView, 6, data[6]);
testPoint(outView, 7, data[7]);
}

//FileUtils::deleteDirectory(Support::temppath("rialto2.sqlite"));
}

0 comments on commit f7c426e

Please sign in to comment.