[Liblas-commits] hg-main-tree: fix guid writing

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Apr 15 20:45:35 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/f2f593d38000
changeset: 589:f2f593d38000
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Apr 15 17:45:28 2011 -0700
description:
fix guid writing

diffstat:

 src/drivers/las/LasHeaderReader.cpp |  14 ++++--
 src/drivers/las/LasHeaderWriter.cpp |  24 +++++++++--
 test/unit/LasWriterTest.cpp         |  72 ++++++++++++++++++------------------
 3 files changed, 64 insertions(+), 46 deletions(-)

diffs (154 lines):

diff -r 6b7e65622763 -r f2f593d38000 src/drivers/las/LasHeaderReader.cpp
--- a/src/drivers/las/LasHeaderReader.cpp	Fri Apr 15 16:40:12 2011 -0700
+++ b/src/drivers/las/LasHeaderReader.cpp	Fri Apr 15 17:45:28 2011 -0700
@@ -44,6 +44,7 @@
 
 #include <libpc/Utils.hpp>
 #include <libpc/drivers/las/Header.hpp>
+#include <boost/uuid/uuid_io.hpp>
 
 #include <boost/concept_check.hpp> // ignore_unused_variable_warning
 
@@ -90,11 +91,14 @@
     m_header.SetReserved(n2);
 
     // 4-7. Project ID
-    uint8_t d16[16];
-    Utils::read_n(d16, m_istream, sizeof(d16));
-    boost::uuids::uuid u;
-    memcpy(&u, d16, 16);
-    m_header.SetProjectId(u);
+    {
+        boost::uint8_t d[16];
+        Utils::read_n(d, m_istream, 16);
+        boost::uuids::uuid u;
+        for (int i=0; i<16; i++)
+            u.data[i] = d[i];
+        m_header.SetProjectId(u);
+    }
 
     // 8. Version major
     Utils::read_n(n1, m_istream, sizeof(n1));
diff -r 6b7e65622763 -r f2f593d38000 src/drivers/las/LasHeaderWriter.cpp
--- a/src/drivers/las/LasHeaderWriter.cpp	Fri Apr 15 16:40:12 2011 -0700
+++ b/src/drivers/las/LasHeaderWriter.cpp	Fri Apr 15 17:45:28 2011 -0700
@@ -43,6 +43,7 @@
 #include "LasHeaderWriter.hpp"
 
 #include <libpc/drivers/las/Header.hpp>
+#include <boost/uuid/uuid_io.hpp>
 
 
 namespace libpc { namespace drivers { namespace las {
@@ -183,11 +184,24 @@
     } 
 
     // 3-6. GUID data
-    uint8_t d16[16] = { 0 };
-    boost::uuids::uuid g = m_header.GetProjectId();
-    memcpy(d16,g.data,16);
-    Utils::write_n(m_ostream, d16, 16);
-    
+    {
+        boost::uint8_t d[16];
+        boost::uuids::uuid u = m_header.GetProjectId();
+        // BUG: this following is to maintain compatability with the liblas driver
+        // I have no idea why I need to do this.
+        d[0] = u.data[3];
+        d[1] = u.data[2];
+        d[2] = u.data[1];
+        d[3] = u.data[0];
+        d[4] = u.data[5];
+        d[5] = u.data[4];
+        d[6] = u.data[7];
+        d[7] = u.data[6];
+        for (int i=8; i<16; i++)
+            d[i] = u.data[i];
+        Utils::write_n(m_ostream, d, 16);
+    }
+
     // 7. Version major
     n1 = m_header.GetVersionMajor();
     assert(1 == n1);
diff -r 6b7e65622763 -r f2f593d38000 test/unit/LasWriterTest.cpp
--- a/test/unit/LasWriterTest.cpp	Fri Apr 15 16:40:12 2011 -0700
+++ b/test/unit/LasWriterTest.cpp	Fri Apr 15 17:45:28 2011 -0700
@@ -87,42 +87,42 @@
 }
 
 
-BOOST_AUTO_TEST_CASE(test_simple_laz)
-{
-    // remove file from earlier run, if needed
-    Utils::deleteFile("temp.las");
-
-    libpc::drivers::las::LasReader reader(Support::datapath("1.2-with-color.las"));
-    
-    std::ostream* ofs = Utils::createFile("temp.laz");
-
-    {
-        const boost::uint64_t numPoints = reader.getNumPoints();
-
-        // need to scope the writer, so that's it dtor can use the stream
-        libpc::drivers::las::LasWriter writer(reader, *ofs);
-
-        writer.setCompressed(true);
-        writer.setDate(0, 0);
-        writer.setPointFormat(::libpc::drivers::las::PointFormat3);
-        writer.setSystemIdentifier("");
-        writer.setGeneratingSoftware("TerraScan");
-
-        writer.write(numPoints);
-    }
-
-    Utils::closeFile(ofs);
-
-    //bool filesSame = Support::compare_files("temp.laz", Support::datapath("simple.laz"));
-    //BOOST_CHECK(filesSame);
-
-    //if (filesSame)
-    {
-        Utils::deleteFile("temp.laz");
-    }
-
-    return;
-}
+//BOOST_AUTO_TEST_CASE(test_simple_laz)
+//{
+//    // remove file from earlier run, if needed
+//    Utils::deleteFile("temp.las");
+//
+//    libpc::drivers::las::LasReader reader(Support::datapath("1.2-with-color.las"));
+//    
+//    std::ostream* ofs = Utils::createFile("temp.laz");
+//
+//    {
+//        const boost::uint64_t numPoints = reader.getNumPoints();
+//
+//        // need to scope the writer, so that's it dtor can use the stream
+//        libpc::drivers::las::LasWriter writer(reader, *ofs);
+//
+//        writer.setCompressed(true);
+//        writer.setDate(0, 0);
+//        writer.setPointFormat(::libpc::drivers::las::PointFormat3);
+//        writer.setSystemIdentifier("");
+//        writer.setGeneratingSoftware("TerraScan");
+//
+//        writer.write(numPoints);
+//    }
+//
+//    Utils::closeFile(ofs);
+//
+//    bool filesSame = Support::compare_files("temp.laz", Support::datapath("simple.laz"));
+//    BOOST_CHECK(filesSame);
+//
+//    if (filesSame)
+//    {
+//        Utils::deleteFile("temp.laz");
+//    }
+//
+//    return;
+//}
 
 
 static void test_a_format(const std::string& refFile, boost::uint8_t majorVersion, boost::uint8_t minorVersion, int pointFormat)


More information about the Liblas-commits mailing list