[Liblas-commits] hg: 5 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Nov 3 12:34:03 EDT 2010


changeset 2d675aadfefd in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=2d675aadfefd
summary: pretty up formating of operator<<

changeset f6cd5ed31646 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=f6cd5ed31646
summary: fix up bogus cast

changeset 8583dcdeb7a9 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=8583dcdeb7a9
summary: update with new version of 1.3 spec

changeset 2e185ee82cee in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=2e185ee82cee
summary: reactivate error message for headers that provide bogus point counts for LAS 1.0-1.2 #147

changeset b75eee10bb92 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=b75eee10bb92
summary: the awful beginnings of the should-be-boost-spirit-but-isn't TranslationTransform

diffstat:

 apps/laskernel.cpp                                        |   15 +-
 doc/_static/files/specifications/asprs_las_format_v13.pdf |    0 
 include/liblas/lasbounds.hpp                              |    2 +-
 include/liblas/lastransform.hpp                           |   68 ++++-
 src/detail/reader/header.cpp                              |   82 ++--
 src/lasdimension.cpp                                      |   13 +-
 src/lastransform.cpp                                      |  209 +++++++++++--
 7 files changed, 297 insertions(+), 92 deletions(-)

diffs (truncated from 539 to 300 lines):

diff -r 365fd6de26d8 -r b75eee10bb92 apps/laskernel.cpp
--- a/apps/laskernel.cpp	Tue Nov 02 09:53:06 2010 -0500
+++ b/apps/laskernel.cpp	Wed Nov 03 11:33:45 2010 -0500
@@ -305,6 +305,7 @@
         ("add-vlr", po::value<std::vector<std::string> >()->multitoken(), "Add VLRs with the given name and id combination. --add-vlr hobu 1234 \"Description of the VLR\" \"filename.ext\"")
         ("system-identifier", po::value<std::string>(), "Set the SystemID for the file. --system_identifier \"MODIFICATION\"")
         ("generating-software", po::value<std::string>(), "Set the SoftwareID for the file. --generating_software \"liblas.org\"")
+        ("point-translate", po::value<std::string>(), "An expression to translate the X, Y, Z values of the point. For example, converting Z units that are in meters to feet: --point-translate \"x*1.0 y*1.0 z*3.2808399\"")
 
     ;
     
@@ -1114,7 +1115,19 @@
         header.SetExtent(b);
         liblas::TransformPtr srs_transform = liblas::TransformPtr(new liblas::ReprojectionTransform(in_ref, out_ref, liblas::HeaderPtr(new liblas::Header(header))));
         transforms.push_back(srs_transform);
-    }    
+    }
+
+    if (vm.count("point-translate")) 
+    {
+        std::string translate = vm["point-translate"].as< std::string >();
+        if (verbose)
+        {
+
+                std::cout << "Translating points with expression: " << translate << std::endl;
+        }
+        liblas::TransformPtr trans_trans = liblas::TransformPtr(new liblas::TranslationTransform(translate));
+        transforms.push_back(trans_trans);
+    }
     return transforms;
 }
 
diff -r 365fd6de26d8 -r b75eee10bb92 doc/_static/files/specifications/asprs_las_format_v13.pdf
Binary file doc/_static/files/specifications/asprs_las_format_v13.pdf has changed
diff -r 365fd6de26d8 -r b75eee10bb92 include/liblas/lasbounds.hpp
--- a/include/liblas/lasbounds.hpp	Tue Nov 02 09:53:06 2010 -0500
+++ b/include/liblas/lasbounds.hpp	Wed Nov 03 11:33:45 2010 -0500
@@ -533,7 +533,7 @@
 
 T volume() const
 {
-    T output = static_cast<T>(0);
+    T output = T();
     for (size_type i = 0; i < dimension(); i++) {
         output = output * ranges[i].length();
     }
diff -r 365fd6de26d8 -r b75eee10bb92 include/liblas/lastransform.hpp
--- a/include/liblas/lastransform.hpp	Tue Nov 02 09:53:06 2010 -0500
+++ b/include/liblas/lastransform.hpp	Wed Nov 03 11:33:45 2010 -0500
@@ -50,6 +50,7 @@
 #include <boost/shared_ptr.hpp>
 // std
 #include <vector>
+#include <string>
 
 namespace liblas {
 
@@ -82,18 +83,75 @@
 
 private:
 
-    // FIXME: use shared_ptr with custom deleter and get rid of bloat of OGR manual calls --mloskot
-    OGRCoordinateTransformationH m_transform;
-    OGRSpatialReferenceH m_in_ref;
-    OGRSpatialReferenceH m_out_ref;
+    struct OGRSpatialReferenceDeleter
+    {
+       template <typename T>
+       void operator()(T* ptr)
+       {
+           ::OSRDestroySpatialReference(ptr);
+       }
+    };
+
+    struct OSRTransformDeleter
+    {
+       template <typename T>
+       void operator()(T* ptr)
+       {
+           ::OCTDestroyCoordinateTransformation(ptr);
+       }
+    };
+
+
     liblas::HeaderPtr m_new_header;
-
+    
+    typedef boost::shared_ptr<void> ReferencePtr;
+    typedef boost::shared_ptr<void> TransformPtr;
+    ReferencePtr m_in_ref_ptr;
+    ReferencePtr m_out_ref_ptr;
+    TransformPtr m_transform_ptr;
+    
+    
     ReprojectionTransform(ReprojectionTransform const& other);
     ReprojectionTransform& operator=(ReprojectionTransform const& rhs);
     
     void Initialize(SpatialReference const& inSRS, SpatialReference const& outSRS);
 };
 
+class LAS_DLL TranslationTransform: public TransformI
+{
+public:
+    
+    TranslationTransform(std::string const& expression);
+    ~TranslationTransform();
+
+    bool transform(Point& point);
+
+    // Yes, Mateusz, I'm embarassed by this :)
+    struct operation{
+        bool multiply;
+        bool divide;
+        bool subtract;
+        bool add;
+        std::string dimension;
+        double value;
+        std::string expression;
+        
+        operation(std::string name) : multiply(false), divide(false), subtract(false), add(false), dimension(name), value(0.0)
+        {
+        }
+    };
+
+private:
+
+    TranslationTransform(TranslationTransform const& other);
+    TranslationTransform& operator=(TranslationTransform const& rhs);
+    
+    operation GetOperation(std::string const& expression);
+    
+    std::vector<operation> operations;
+    
+    std::string m_expression;
+};
 } // namespace liblas
 
 #endif // ndef LIBLAS_LASTRANSFORM_HPP_INCLUDED
diff -r 365fd6de26d8 -r b75eee10bb92 src/detail/reader/header.cpp
--- a/src/detail/reader/header.cpp	Tue Nov 02 09:53:06 2010 -0500
+++ b/src/detail/reader/header.cpp	Wed Nov 03 11:33:45 2010 -0500
@@ -203,14 +203,11 @@
     m_header->SetPointRecordsCount(n4);
 
     // 20. Number of points by return
-    // The committee in its infinite stupidity decided to increase the 
-    // size of this array at 1.3.  Yay for complex code.
+    // A few versions of the spec had this as 7, but 
+    // https://lidarbb.cr.usgs.gov/index.php?showtopic=11388 says 
+    // it is supposed to always be 5
     std::vector<uint32_t>::size_type  return_count_length;
-    if (m_header->GetVersionMinor() > 2) {
-        return_count_length = 7;
-    } else {
-        return_count_length = 5;
-    }
+    return_count_length = 5;
 
     uint32_t* point_counts = new uint32_t[return_count_length];
     for (uint32_t i = 0; i < return_count_length; ++i) {
@@ -280,41 +277,44 @@
     if (m_ifs.eof())
         m_ifs.clear();
     
-    // NOTE: This section is commented out because we now have to believe 
-    // the header's GetPointRecordsCount due to the fact that the LAS 1.3 
-    // specification no longer mandates that the end of the file is the end
-    // of the points.  See http://trac.liblas.org/ticket/147 for more 
-    // details on this issue and why the seek is a problem in the windows 
-    // case.
-    // // Seek to the beginning
-    // m_ifs.seekg(0, std::ios::beg);
-    // std::ios::pos_type beginning = m_ifs.tellg();
-    // 
-    // // Seek to the end
-    // m_ifs.seekg(0, std::ios::end);
-    // std::ios::pos_type end = m_ifs.tellg();
-    // std::ios::off_type size = end - beginning;
-    //  
-    // // Figure out how many points we have 
-    // std::ios::off_type count = (end - static_cast<std::ios::off_type>(m_header->GetDataOffset())) / 
-    //                              static_cast<std::ios::off_type>(m_header->GetDataRecordLength());
-    // 
-    // if ( m_header->GetPointRecordsCount() != static_cast<uint32_t>(count)) {
-    //     std::ostringstream msg; 
-    //     msg <<  "The number of points in the header that was set "
-    //             "by the software '" << m_header->GetSoftwareId() <<
-    //             "' does not match the actual number of points in the file "
-    //             "as determined by subtracting the data offset (" 
-    //             <<m_header->GetDataOffset() << ") from the file length (" 
-    //             << size <<  ") and dividing by the point record length(" 
-    //             << m_header->GetDataRecordLength() << "). "
-    //             " Actual number of points: " << count << 
-    //             " Header-specified number of points: " 
-    //             << m_header->GetPointRecordsCount() ;
-    //     throw std::runtime_error(msg.str());
-    //     
-    // }
+    // LAS 1.3 specification no longer mandates that the end of the file is the
+    // end of the points. See http://trac.liblas.org/ticket/147 for more details
+    // on this issue and why the seek can be trouble in the windows case.  
+    // If you are having trouble properly seeking to the end of the stream on 
+    // windows, use boost's iostreams or similar, which do not have an overflow 
+    // problem.
     
+    if (m_header->GetVersionMinor() < 3) 
+    {
+        // Seek to the beginning 
+        m_ifs.seekg(0, std::ios::beg);
+        std::ios::pos_type beginning = m_ifs.tellg();
+    
+        // Seek to the end
+        m_ifs.seekg(0, std::ios::end);
+        std::ios::pos_type end = m_ifs.tellg();
+        std::ios::off_type size = end - beginning;
+     
+        // Figure out how many points we have 
+        std::ios::off_type count = (end - static_cast<std::ios::off_type>(m_header->GetDataOffset())) / 
+                                     static_cast<std::ios::off_type>(m_header->GetDataRecordLength());
+    
+        if ( m_header->GetPointRecordsCount() != static_cast<uint32_t>(count)) {
+            std::ostringstream msg; 
+            msg <<  "The number of points in the header that was set "
+                    "by the software '" << m_header->GetSoftwareId() <<
+                    "' does not match the actual number of points in the file "
+                    "as determined by subtracting the data offset (" 
+                    <<m_header->GetDataOffset() << ") from the file length (" 
+                    << size <<  ") and dividing by the point record length(" 
+                    << m_header->GetDataRecordLength() << "). "
+                    " Actual number of points: " << count << 
+                    " Header-specified number of points: " 
+                    << m_header->GetPointRecordsCount() ;
+            throw std::runtime_error(msg.str());
+        
+        }
+    }
     // Seek to the data offset so we can start reading points
     m_ifs.seekg(m_header->GetDataOffset());
 
diff -r 365fd6de26d8 -r b75eee10bb92 src/lasdimension.cpp
--- a/src/lasdimension.cpp	Tue Nov 02 09:53:06 2010 -0500
+++ b/src/lasdimension.cpp	Wed Nov 03 11:33:45 2010 -0500
@@ -179,8 +179,17 @@
     
     std::string const name = tree.get<std::string>("name");
 
-    os << "'" << name << "'" << " -- ";
-    os << " size: " << tree.get<boost::uint32_t>("size");
+    std::ostringstream quoted_name;
+    quoted_name << "'" << name << "'";
+    std::ostringstream pad;
+    std::string const& cur = quoted_name.str();
+    std::string::size_type size = cur.size();
+    std::string::size_type pad_size = 30 - size;
+    
+    for (std::string::size_type i=0; i != pad_size; i++ ) {
+        pad << " ";
+    }
+    os << quoted_name.str() << pad.str() <<" -- "<< " size: " << tree.get<boost::uint32_t>("size");
     os << " offset: " << tree.get<boost::uint32_t>("byteoffset");
     os << std::endl;
     
diff -r 365fd6de26d8 -r b75eee10bb92 src/lastransform.cpp
--- a/src/lastransform.cpp	Tue Nov 02 09:53:06 2010 -0500
+++ b/src/lastransform.cpp	Wed Nov 03 11:33:45 2010 -0500
@@ -42,18 +42,22 @@
 #include <liblas/lastransform.hpp>
 // boost
 #include <boost/concept_check.hpp>
+#include <boost/tokenizer.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/algorithm/string/erase.hpp>
+
 // std
 #include <sstream>
 #include <stdexcept>
 #include <string>
+#include <algorithm>
+
+typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
 
 namespace liblas { 
 
 ReprojectionTransform::ReprojectionTransform(const SpatialReference& inSRS, const SpatialReference& outSRS)
-    : m_transform(0)
-    , m_in_ref(0)
-    , m_out_ref(0)
-    , m_new_header(HeaderPtr())
+    : m_new_header(HeaderPtr())
 {
     Initialize(inSRS, outSRS);
 }
@@ -62,10 +66,7 @@
     const SpatialReference& inSRS, 
     const SpatialReference& outSRS,
     liblas::HeaderPtr new_header)
-    : m_transform(0)
-    , m_in_ref(0)
-    , m_out_ref(0)
-    , m_new_header(new_header)


More information about the Liblas-commits mailing list