Skip to content

Commit

Permalink
Add support for conditional options on stages.
Browse files Browse the repository at this point in the history
Support extra stage options for tindex.
  • Loading branch information
abellgithub committed Jun 17, 2015
1 parent 0b6a52c commit fa4f0bb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
5 changes: 5 additions & 0 deletions include/pdal/Options.hpp
Expand Up @@ -312,6 +312,11 @@ class PDAL_DLL Options
return (m_options.size() == 0);
}

size_t size() const
{
return m_options.size();
}

Options const operator+(const Options& rhs)
{
return Options(*this) += rhs;
Expand Down
3 changes: 2 additions & 1 deletion include/pdal/Stage.hpp
Expand Up @@ -86,7 +86,8 @@ class PDAL_DLL Stage
{ return m_options; }
void setOptions(Options options)
{ m_options = options; }
void addOptions(Options opts)
void addConditionalOptions(const Options& opts);
void addOptions(const Options& opts)
{
for (const auto& o : opts.getOptions())
m_options.add(o);
Expand Down
4 changes: 3 additions & 1 deletion kernels/tindex/TIndexKernel.cpp
Expand Up @@ -441,6 +441,8 @@ void TIndexKernel::mergeFile()
}
writer->setInput(merge);

applyExtraStageOptionsRecursive(writer);

Options writerOptions;
writerOptions.add("filename", m_filespec);
writerOptions.add("scale_x", 1e-9);
Expand All @@ -449,7 +451,7 @@ void TIndexKernel::mergeFile()
writerOptions.add("offset_x", "auto");
writerOptions.add("offset_y", "auto");
writerOptions.add("offset_z", "auto");
writer->setOptions(writerOptions);
writer->addConditionalOptions(writerOptions);

PointTable table;

Expand Down
12 changes: 12 additions & 0 deletions src/Stage.cpp
Expand Up @@ -52,6 +52,18 @@ Stage::Stage()
}


/// Only add options if an option with the same name doesn't already exist.
///
/// \param[in] ops Options to add.
///
void Stage::addConditionalOptions(const Options& opts)
{
for (const auto& o : opts.getOptions())
if (!m_options.hasOption(o.getName()))
m_options.add(o);
}


void Stage::Construct()
{
m_debug = false;
Expand Down
31 changes: 31 additions & 0 deletions test/unit/OptionsTest.cpp
Expand Up @@ -335,3 +335,34 @@ TEST(OptionsTest, metadata)
}
EXPECT_TRUE(Support::compare_files(goodfile, testfile));
}

TEST(OptionsTest, conditional)
{
CropFilter s;

Options ops;
ops.add("foo", "foo");
ops.add("bar", "bar");
ops.add("baz", "baz");

s.setOptions(ops);

Options condOps;
condOps.add("foo", "lose");
condOps.add("bar", "lose");
condOps.add("baz", "lose");
condOps.add("foot", "win");
condOps.add("barf", "win");
condOps.add("bazel", "win");

s.addConditionalOptions(condOps);
ops = s.getOptions();
EXPECT_EQ(ops.size(), 6u);
EXPECT_EQ(ops.getValueOrDefault("foo", std::string()), "foo");
EXPECT_EQ(ops.getValueOrDefault("bar", std::string()), "bar");
EXPECT_EQ(ops.getValueOrDefault("baz", std::string()), "baz");
EXPECT_EQ(ops.getValueOrDefault("foot", std::string()), "win");
EXPECT_EQ(ops.getValueOrDefault("barf", std::string()), "win");
EXPECT_EQ(ops.getValueOrDefault("bazel", std::string()), "win");
}

0 comments on commit fa4f0bb

Please sign in to comment.