Skip to content

Commit

Permalink
Update to PDAL 2.6, which changed classification flags behavior: PDAL…
Browse files Browse the repository at this point in the history
  • Loading branch information
connormanning committed Apr 3, 2024
1 parent d6b787d commit 17d4ccc
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmake/pdal.cmake
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
find_package(PDAL 2.4.0 REQUIRED CONFIG NO_POLICY_SCOPE)
find_package(PDAL 2.6.0 REQUIRED CONFIG NO_POLICY_SCOPE)

8 changes: 6 additions & 2 deletions entwine/builder/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ void Builder::insert(
// won't count them.
info.points = 0;

auto layout = toLayout(metadata.absoluteSchema);
auto layout = toLayout(
metadata.absoluteSchema,
metadata.dataType == io::Type::Laszip);
VectorPointTable table(layout);
table.setProcess([&]()
{
Expand Down Expand Up @@ -736,7 +738,9 @@ void mergeOne(Builder& dst, const Builder& src, ChunkCache& cache)
}
else
{
auto layout = toLayout(metadata.absoluteSchema);
auto layout = toLayout(
metadata.absoluteSchema,
metadata.dataType == io::Type::Laszip);
VectorPointTable table(layout, count);
table.setProcess([&]()
{
Expand Down
8 changes: 6 additions & 2 deletions entwine/builder/chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ uint64_t Chunk::save(const Endpoints& endpoints) const
uint64_t np(m_gridBlock.size());
for (const auto& o : m_overflows) if (o) np += o->block.size();

auto layout = toLayout(m_metadata.absoluteSchema);
auto layout = toLayout(
m_metadata.absoluteSchema,
m_metadata.dataType == io::Type::Laszip);
BlockPointTable table(layout);
table.reserve(np);
table.insert(m_gridBlock);
Expand All @@ -189,7 +191,9 @@ void Chunk::load(
const Endpoints& endpoints,
const uint64_t np)
{
auto layout = toLayout(m_metadata.absoluteSchema);
auto layout = toLayout(
m_metadata.absoluteSchema,
m_metadata.dataType == io::Type::Laszip);
VectorPointTable table(layout, np);
table.setProcess([&]()
{
Expand Down
6 changes: 3 additions & 3 deletions entwine/io/binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::vector<char> pack(const Metadata& m, BlockPointTable& src)
{
const uint64_t np(src.size());

auto layout = toLayout(m.schema);
auto layout = toLayout(m.schema, false);
VectorPointTable dst(layout, np);

// Handle XYZ separately since we might need to scale/offset them.
Expand Down Expand Up @@ -102,7 +102,7 @@ void unpack(
VectorPointTable& dst,
std::vector<char>&& packed)
{
auto scaledLayout = toLayout(m.schema);
auto scaledLayout = toLayout(m.schema, false);
VectorPointTable src(scaledLayout, std::move(packed));

const uint64_t np(src.capacity());
Expand All @@ -111,7 +111,7 @@ void unpack(
// For reading, our destination schema will always be normalized (i.e. XYZ
// as doubles). So we can just copy the full dimension list and then
// transform XYZ in place, if necessary.
auto absoluteLayout = toLayout(m.absoluteSchema);
auto absoluteLayout = toLayout(m.absoluteSchema, false);
pdal::DimTypeList dimTypes(absoluteLayout.dimTypes());

pdal::PointRef srcPr(src, 0);
Expand Down
25 changes: 22 additions & 3 deletions entwine/types/dimension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,41 @@ Schema combine(Schema agg, const Schema& cur, const bool fixed)
return agg;
}

Schema fromLayout(const pdal::PointLayout& layout)
Schema fromLayout(const pdal::PointLayout& layout, const bool islas)
{
Schema list;
for (const DimId id : layout.dims())
{
list.push_back(Dimension(layout.dimName(id), layout.dimType(id)));
if (islas)
{
// If we're writing to LAS, then we don't write these values in the
// schema since they all get packed into Classification.
if (id != DimId::Synthetic && id != DimId::KeyPoint &&
id != DimId::Withheld && id != DimId::Overlap)
{
list.push_back(Dimension(layout.dimName(id), layout.dimType(id)));
}
}
else list.push_back(Dimension(layout.dimName(id), layout.dimType(id)));
}
return list;
}

FixedPointLayout toLayout(const Schema& list)
FixedPointLayout toLayout(const Schema& list, const bool islas)
{
FixedPointLayout layout;
for (const auto& dim : list)
{
layout.registerOrAssignFixedDim(dim.name, dim.type);
// If this is from LAS, then we have these values packed into
// Classification.
if (islas && dim.name == "Classification")
{
layout.registerOrAssignFixedDim("Synthetic", pdal::Dimension::Type::Unsigned8);
layout.registerOrAssignFixedDim("KeyPoint", pdal::Dimension::Type::Unsigned8);
layout.registerOrAssignFixedDim("Withheld", pdal::Dimension::Type::Unsigned8);
layout.registerOrAssignFixedDim("Overlap", pdal::Dimension::Type::Unsigned8);
}
}
layout.finalize();
return layout;
Expand Down
4 changes: 2 additions & 2 deletions entwine/types/dimension.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ Dimension combine(Dimension agg, const Dimension& dim);
Schema combine(Schema agg, const Schema& list, bool fixed = false);

Schema makeAbsolute(Schema list);
Schema fromLayout(const pdal::PointLayout& layout);
FixedPointLayout toLayout(const Schema& list);
Schema fromLayout(const pdal::PointLayout& layout, bool islas);
FixedPointLayout toLayout(const Schema& list, bool islas);

Schema setScaleOffset(Schema dims, ScaleOffset so);
optional<ScaleOffset> getScaleOffset(const Schema& dims);
Expand Down
2 changes: 1 addition & 1 deletion entwine/util/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ SourceInfo getShallowInfo(const json pipeline)

lock.unlock();

info.schema = fromLayout(*table.layout());
info.schema = fromLayout(*table.layout(), false);
if (const auto so = getScaleOffset(reader))
{
info.schema = setScaleOffset(info.schema, *so);
Expand Down
33 changes: 32 additions & 1 deletion test/unit/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace
EXPECT_EQ(ept.at("hierarchyType").get<std::string>(), "json");
EXPECT_EQ(ept.at("points").get<int>(), 100000);
EXPECT_EQ(ept.at("span").get<int>(), 32);
EXPECT_EQ(Srs(ept.at("srs")), srs);
EXPECT_EQ(ept.at("srs").get<Srs>(), srs);
EXPECT_EQ(ept.at("version").get<std::string>(), "1.1.0");
const Schema schema = ept.at("schema").get<Schema>();
EXPECT_TRUE(hasStats(schema));
Expand Down Expand Up @@ -116,6 +116,37 @@ TEST(build, laszip)
checkData(*view);
}

TEST(build, laszip14)
{
run({ { "input", test::dataPath() + "ellipsoid14.laz" } });
const json ept = checkEpt();
// By default, since this is laszip input, our output will be laszip.
EXPECT_EQ(ept.at("dataType").get<std::string>(), "laszip");

const auto stuff = execute();
auto& view = stuff->view;
ASSERT_TRUE(view);
checkData(*view);
}

TEST(build, withflags)
{
run({ { "input", test::dataPath() + "ellipsoid14.laz" } });
const json ept = checkEpt();
// By default, since this is laszip input, our output will be laszip.
EXPECT_EQ(ept.at("dataType").get<std::string>(), "laszip");

const auto stuff = execute({ outDir + "ept-data/0-0-0-0.laz" });

auto& view = stuff->view;
ASSERT_TRUE(view);
checkData(*view);
for (const auto pr : *view)
{
ASSERT_TRUE(pr.getFieldAs<bool>(pdal::Dimension::Id::KeyPoint));
}
}

TEST(build, failedWrite)
{
struct FailIo : public io::Laszip
Expand Down
5 changes: 2 additions & 3 deletions test/unit/srs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,21 @@ TEST(srs, fromHorizontalWkt)

TEST(srs, fromCompoundWkt)
{
// Unfortunately GDAL's auto-identify-vertical-EPSG doesn't actually return
// the vertical in this case.
const std::string s("EPSG:26915+5703");
pdal::SpatialReference ref(s);
Srs srs(ref.getWKT());

EXPECT_FALSE(srs.empty());
EXPECT_EQ(srs.authority(), "EPSG");
EXPECT_EQ(srs.horizontal(), "26915");
EXPECT_EQ(srs.vertical(), "");
EXPECT_EQ(srs.vertical(), "5703");
EXPECT_EQ(srs.wkt(), ref.getWKT());

const json j(srs);
const json v {
{ "authority", "EPSG" },
{ "horizontal", "26915" },
{ "vertical", "5703" },
{ "wkt", ref.getWKT() }
};
EXPECT_EQ(j, v) << j.dump(2) << " != " << v.dump(2) << std::endl;
Expand Down
4 changes: 4 additions & 0 deletions test/unit/verify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ struct Verify
{"ScanDirectionFlag"},
{"EdgeOfFlightLine"},
{"Classification"},
{"Synthetic"},
{"KeyPoint"},
{"Withheld"},
{"Overlap"},
{"ScanAngleRank"},
{"UserData"},
{"PointSourceId"},
Expand Down

0 comments on commit 17d4ccc

Please sign in to comment.