Skip to content

Commit

Permalink
Hook up LAZ 1.4 output to use the non-legacy PDRFs.
Browse files Browse the repository at this point in the history
  • Loading branch information
connormanning committed Apr 3, 2024
1 parent 17d4ccc commit 3765896
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
9 changes: 6 additions & 3 deletions app/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,12 @@ void Build::addArgs()

m_ap.add(
"--laz_14",
"Write LAZ 1.4 content encoding (default: false)"
"logging (default: 10).",
[this](json j) { m_json["laz_14"] = extract(j); });
"Write LAZ 1.4 content encoding (default: false)",
[this](json j)
{
checkEmpty(j);
m_json["laz_14"] = true;
});

addArbiter();
}
Expand Down
15 changes: 12 additions & 3 deletions entwine/io/laszip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,31 @@ void Laszip::write(
reader.addView(view);

// See https://www.pdal.io/stages/writers.las.html
const uint64_t timeMask(contains(metadata.schema, "GpsTime") ? 1 : 0);
const uint64_t colorMask(contains(metadata.schema, "Red") ? 2 : 0);
const bool hasColor = contains(metadata.schema, "Red");

pdal::Options options;
options.add("filename", localDir + localFile);

if (metadata.internal.laz_14)
{
const bool hasNir = contains(metadata.schema, "Infrared");
int pdrf = hasColor ? 7 : 6;
if (hasNir) pdrf = 8;
options.add("minor_version", 4);
options.add("dataformat_id", pdrf);
}
else
{
const uint64_t timeMask(contains(metadata.schema, "GpsTime") ? 1 : 0);
const uint64_t colorMask(hasColor ? 2 : 0);
options.add("minor_version", 2);
options.add("dataformat_id", timeMask | colorMask);
}


options.add("extra_dims", "all");
options.add("software_id", "Entwine " + currentEntwineVersion().toString());

options.add("dataformat_id", timeMask | colorMask);

const auto so = getScaleOffset(metadata.schema);
if (!so) throw std::runtime_error("Scale/offset is required for laszip");
Expand Down
3 changes: 2 additions & 1 deletion entwine/util/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ BuildParameters getBuildParameters(const json& j)
getSleepCount(j),
getProgressInterval(j),
getHierarchyStep(j),
getVerbose(j));
getVerbose(j),
j.value("laz_14", false));
}

} // unnamed namespace
Expand Down
39 changes: 21 additions & 18 deletions test/unit/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ 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();
Expand All @@ -133,10 +132,9 @@ 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" });
const auto stuff = execute();

auto& view = stuff->view;
ASSERT_TRUE(view);
Expand All @@ -147,6 +145,26 @@ TEST(build, withflags)
}
}

TEST(build, laz14Output)
{
run({
{ "input", test::dataPath() + "ellipsoid-class33.laz" },
{ "laz_14", true },
});
const json ept = checkEpt();
EXPECT_EQ(ept.at("dataType").get<std::string>(), "laszip");

const auto stuff = execute();

auto& view = stuff->view;
ASSERT_TRUE(view);
checkData(*view);
for (const auto pr : *view)
{
ASSERT_EQ(pr.getFieldAs<int>(pdal::Dimension::Id::Classification), 33);
}
}

TEST(build, failedWrite)
{
struct FailIo : public io::Laszip
Expand Down Expand Up @@ -175,21 +193,6 @@ TEST(build, failedWrite)
ASSERT_ANY_THROW(builder::run(builder, config));
}

TEST(build, laz14)
{
run({
{ "input", test::dataPath() + "ellipsoid.laz" },
{ "laz_14", "true" }
});
const json ept = checkEpt();
EXPECT_EQ(ept.at("dataType").get<std::string>(), "laszip");

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

TEST(build, binary)
{
run({
Expand Down

0 comments on commit 3765896

Please sign in to comment.