Skip to content

Commit

Permalink
Warn about auto offset/scaling in stream mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Apr 23, 2018
1 parent b0b12fb commit dab5221
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
47 changes: 46 additions & 1 deletion io/LasWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ void LasWriter::fillForwardList()

void LasWriter::readyTable(PointTableRef table)
{
m_firstPoint = true;
m_forwardMetadata = table.privateMetadata("lasforward");
if(m_writePDALMetadata)
{
Expand Down Expand Up @@ -742,7 +743,51 @@ void LasWriter::openCompression()
}


// This is only called in stream mode.
bool LasWriter::processOne(PointRef& point)
{
if (m_firstPoint)
{
auto doScale = [this](const XForm::XFormComponent& scale,
const std::string& name)
{
if (scale.m_auto)
log()->get(LogLevel::Warning) << "Auto scale for " << name <<
"requested in stream mode. Using value of 1.0." << std::endl;
};

doScale(m_scaling.m_xXform.m_scale, "X");
doScale(m_scaling.m_yXform.m_scale, "Y");
doScale(m_scaling.m_zXform.m_scale, "Z");

auto doOffset = [this](XForm::XFormComponent& offset, double val,
const std::string name)
{
if (offset.m_auto)
{
offset.m_val = val;
log()->get(LogLevel::Warning) << "Auto offset for " << name <<
"requested in stream mode. Using value of " <<
offset.m_val << "." << std::endl;
}
};

doOffset(m_scaling.m_xXform.m_offset,
point.getFieldAs<double>(Dimension::Id::X), "X");
doOffset(m_scaling.m_yXform.m_offset,
point.getFieldAs<double>(Dimension::Id::Y), "Y");
doOffset(m_scaling.m_zXform.m_offset,
point.getFieldAs<double>(Dimension::Id::Z), "Z");

m_firstPoint = false;
}
return processPoint(point);
}


// This is separated from processOne so that we're sure when processOne is
// called we know we're in stream mode.
bool LasWriter::processPoint(PointRef& point)
{
//ABELL - Need to do something about auto offset.

Expand Down Expand Up @@ -785,7 +830,7 @@ void LasWriter::writeView(const PointViewPtr view)
for (PointId idx = 0; idx < view->size(); ++idx)
{
point.setPointId(idx);
processOne(point);
processPoint(point);
}
}
else
Expand Down
2 changes: 2 additions & 0 deletions io/LasWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class PDAL_DLL LasWriter : public FlexWriter, public Streamable
MetadataNode m_forwardMetadata;
bool m_writePDALMetadata;
Json::Value m_userVLRs;
bool m_firstPoint;

virtual void addArgs(ProgramArgs& args);
virtual void initialize();
Expand Down Expand Up @@ -174,6 +175,7 @@ class PDAL_DLL LasWriter : public FlexWriter, public Streamable
bool addWktVlr();
void finishLasZipOutput();
void finishLazPerfOutput();
bool processPoint(PointRef& point);

LasWriter& operator=(const LasWriter&); // not implemented
LasWriter(const LasWriter&); // not implemented
Expand Down
35 changes: 35 additions & 0 deletions test/unit/io/LasWriterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,41 @@ TEST(LasWriterTest, oversize_vlr)
}


TEST(LasWriterTest, issue1940)
{
StageFactory f;

Stage& r = *(f.createStage("readers.faux"));
Options ro;
ro.add("mode", "constant");
ro.add("bounds", "([55,55],[55,55],[55,55])");
ro.add("count", 20);
r.addOptions(ro);

LasWriter w;
Options wo;
//LogPtr log(new Log("TEST", &std::clog));
//log->setLevel((LogLevel)5);
//w.setLog(log);
wo.add("filename", Support::temppath("out.las"));
wo.add("scale_x", "auto");
wo.add("offset_y", "auto");
w.addOptions(wo);
w.setInput(r);

FixedPointTable t(100);
w.prepare(t);
w.execute(t);

LasTester tester;
LasHeader *h = tester.header(w);
EXPECT_DOUBLE_EQ(h->offsetX(), 0);
EXPECT_DOUBLE_EQ(h->offsetY(), 55);
EXPECT_DOUBLE_EQ(h->scaleX(), 1.0);
EXPECT_DOUBLE_EQ(h->scaleY(), .01);
}


/**
namespace
Expand Down

0 comments on commit dab5221

Please sign in to comment.