std::vector<char> getBytes(PointViewPtr view) { std::vector<char> bytes(view->pointSize() * view->size()); DimTypeList dimTypes = view->dimTypes(); char *p = bytes.data(); for (PointId idx = 0; idx < view->size(); ++idx) { view->getPackedPoint(dimTypes, idx, p); p += view->pointSize(); } return bytes; }
TEST(Compression, simple) { const std::string file(Support::datapath("las/1.2-with-color.las")); const pdal::Option opt_filename("filename", file); pdal::Options opts; opts.add(opt_filename); LasReader reader; reader.setOptions(opts); PointTable table; PointLayoutPtr layout(table.layout()); reader.prepare(table); PointViewSet viewSet = reader.execute(table); PointViewPtr view = *viewSet.begin(); EXPECT_EQ(layout->pointSize(), 52U); std::vector<unsigned char> rawBuf; DimTypeList dimTypes = layout->dimTypes(); auto cb = [&rawBuf](char *buf, size_t bufsize) { unsigned char *ubuf = reinterpret_cast<unsigned char *>(buf); rawBuf.insert(rawBuf.end(), ubuf, ubuf + bufsize); }; LazPerfCompressor compressor(cb, dimTypes); std::vector<char> tmpbuf(layout->pointSize()); for (PointId idx = 0; idx < view->size(); ++idx) { view->getPackedPoint(dimTypes, idx, tmpbuf.data()); compressor.compress(tmpbuf.data(), layout->pointSize()); } compressor.done(); EXPECT_EQ(view->size() * layout->pointSize(), (size_t)55380); EXPECT_EQ(rawBuf.size(), (size_t)30945); PointViewPtr otherView(new PointView(table)); PointId nextId(0); auto cb2 = [&otherView, &dimTypes, &nextId](char *buf, size_t bufsize) { otherView->setPackedPoint(dimTypes, nextId, buf); nextId++; }; LazPerfDecompressor(cb2, dimTypes, view->size()). decompress(reinterpret_cast<const char *>(rawBuf.data()), rawBuf.size()); EXPECT_EQ(otherView->size(), 1065U); EXPECT_EQ(getBytes(otherView).size(), (size_t)(52 * 1065)); uint16_t r = otherView->getFieldAs<uint16_t>(Dimension::Id::Red, 10); EXPECT_EQ(r, 64U); int32_t x = otherView->getFieldAs<int32_t>(Dimension::Id::X, 10); EXPECT_EQ(x, 636038); double xd = otherView->getFieldAs<double>(Dimension::Id::X, 10); EXPECT_FLOAT_EQ(xd, 636037.53); int32_t y = otherView->getFieldAs<int32_t>(Dimension::Id::Y, 10); EXPECT_EQ(y, 849338); }
TEST(Compression, Simple) { const std::string file(Support::datapath("las/1.2-with-color.las")); const pdal::Option opt_filename("filename", file); pdal::Options opts; opts.add(opt_filename); LasReader reader; reader.setOptions(opts); PointTable table; PointLayoutPtr layout(table.layout()); reader.prepare(table); PointViewSet viewSet = reader.execute(table); PointViewPtr view = *viewSet.begin(); EXPECT_EQ(layout->pointSize(), 52U); std::vector<unsigned char> rawBuf; LazPerfBuf b(rawBuf); DimTypeList dimTypes = layout->dimTypes(); LazPerfCompressor<LazPerfBuf> compressor(b, dimTypes); std::vector<char> tmpbuf(compressor.pointSize()); for (PointId idx = 0; idx < view->size(); ++idx) { view->getPackedPoint(dimTypes, idx, tmpbuf.data()); compressor.compress(tmpbuf.data(), compressor.pointSize()); } compressor.done(); EXPECT_EQ(view->size() * compressor.pointSize(), (size_t)55380); EXPECT_EQ(rawBuf.size(), (size_t)30945); LazPerfBuf b2(rawBuf); LazPerfDecompressor<LazPerfBuf> decompressor(b2, dimTypes); size_t outbufSize = decompressor.pointSize() * view->size(); std::vector<char> outbuf(outbufSize); decompressor.decompress(outbuf.data(), outbufSize); PointViewPtr otherView(new PointView(table)); char *pos = outbuf.data(); for (PointId nextId = 0; nextId < 11; nextId++) { otherView->setPackedPoint(dimTypes, nextId, pos); pos += decompressor.pointSize(); } EXPECT_EQ(otherView->size(), 11U); EXPECT_EQ(getBytes(otherView).size(), (size_t)(52 * 11)); uint16_t r = otherView->getFieldAs<uint16_t>(Dimension::Id::Red, 10); EXPECT_EQ(r, 64U); int32_t x = otherView->getFieldAs<int32_t>(Dimension::Id::X, 10); EXPECT_EQ(x, 636038); double xd = otherView->getFieldAs<double>(Dimension::Id::X, 10); EXPECT_FLOAT_EQ(xd, 636037.53); int32_t y = otherView->getFieldAs<int32_t>(Dimension::Id::Y, 10); EXPECT_EQ(y, 849338); }