Skip to content

Commit

Permalink
write orientation into XML for #216
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Dec 5, 2013
1 parent ae836be commit f628ab7
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/XMLSchema.cpp
Expand Up @@ -485,6 +485,23 @@ void Reader::Load()

while (dimension != NULL)
{
// Read off orientation setting
if (boost::equals((const char*)dimension->name, "orientation"))
{
xmlChar* n = xmlNodeListGetString(doc, dimension->children, 1);
if (!n) throw schema_loading_error("Unable to fetch orientation!");
std::string orientation = std::string((const char*)n);
xmlFree(n);

if (boost::iequals(orientation, "dimension"))
m_schema.setOrientation(schema::DIMENSION_INTERLEAVED);
else
m_schema.setOrientation(schema::POINT_INTERLEAVED);

dimension = dimension->next;
continue;
}

// printf("node name: %s\n", (const char*)dimension->name);
// if (boost::equals((const char*)dimension->name, "metadata"))
// {
Expand Down
52 changes: 52 additions & 0 deletions test/unit/XMLSchemaTest.cpp
Expand Up @@ -163,4 +163,56 @@ BOOST_AUTO_TEST_CASE(test_schema_read)
}


BOOST_AUTO_TEST_CASE(test_schema_orientation)
{


Dimension cls("Classification", dimension::UnsignedInteger, 1);
Dimension x("X", dimension::SignedInteger, 4);
Dimension y("Y", dimension::Float, 8);

Schema schema;
schema.appendDimension(x);
schema.appendDimension(y);
schema.appendDimension(cls);
schema.setOrientation(schema::DIMENSION_INTERLEAVED);


pdal::schema::Writer writer(schema);

std::string xml_output = writer.getXML();
std::ostream* out = FileUtils::createFile("orientation-schema.xml");
out->write(xml_output.c_str(), strlen(xml_output.c_str()));
FileUtils::closeFile(out);

pdal::schema::Reader reader2(xml_output, std::string(""));
pdal::Schema schema2 = reader2.getSchema();

BOOST_CHECK_EQUAL(schema2.getOrientation(), schema.getOrientation());

schema::index_by_index const& dims1 = schema.getDimensions().get<schema::index>();
schema::index_by_index const& dims2 = schema2.getDimensions().get<schema::index>();

// const std::vector<pdal::Dimension>& dims1 = schema.getDimensions();
// const std::vector<pdal::Dimension>& dims2 = schema2.getDimensions();

BOOST_CHECK_EQUAL(dims1.size(), dims2.size());

for (boost::uint32_t i = 0; i < dims2.size(); ++i)
{
pdal::Dimension const& dim1 = dims1[i];
pdal::Dimension const& dim2 = dims2[i];

BOOST_CHECK_EQUAL(dim1.getName(), dim2.getName());
BOOST_CHECK_EQUAL(dim1.getInterpretation(), dim2.getInterpretation());
BOOST_CHECK_EQUAL(dim1.getByteSize(), dim2.getByteSize());

BOOST_CHECK_EQUAL(dim1.getDescription(), dim2.getDescription());

}

}



BOOST_AUTO_TEST_SUITE_END()

0 comments on commit f628ab7

Please sign in to comment.