[Liblas-commits] hg: Start storing a single reference for liblas::Point instead o...

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Jun 16 11:59:50 EDT 2011


details:   http://hg.liblas.orghg/rev/c25c7327e6e5
changeset: 2950:c25c7327e6e5
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu May 19 14:53:09 2011 -0500
description:
Start storing a single reference for liblas::Point instead of a boost::shared_ptr
Subject: hg: move test of scales and offsets up to the top because these are often what we are really doing operator== comparisons for

details:   http://hg.liblas.orghg/rev/6ecc66009fff
changeset: 2951:6ecc66009fff
user:      Howard Butler <hobu.inc at gmail.com>
date:      Fri May 20 07:41:05 2011 -0500
description:
move test of scales and offsets up to the top because these are often what we are really doing operator== comparisons for
Subject: hg: typedef for boost::optional< Header const& >

details:   http://hg.liblas.orghg/rev/e902c87b002c
changeset: 2952:e902c87b002c
user:      Howard Butler <hobu.inc at gmail.com>
date:      Fri May 20 07:47:17 2011 -0500
description:
typedef for boost::optional< Header const& >
Subject: hg: remove SetHeaderPtr from liblas::Point entirely.  This was bad

details:   http://hg.liblas.orghg/rev/86df4e0cf773
changeset: 2953:86df4e0cf773
user:      Howard Butler <hobu.inc at gmail.com>
date:      Fri May 20 17:04:29 2011 -0500
description:
remove SetHeaderPtr from liblas::Point entirely.  This was bad
Subject: hg: Z was not being properly offseted

details:   http://hg.liblas.orghg/rev/ed2db75966b2
changeset: 2954:ed2db75966b2
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Jun 16 10:25:42 2011 -0500
description:
Z was not being properly offseted
Subject: hg: merge

details:   http://hg.liblas.orghg/rev/a5cca55eeb75
changeset: 2955:a5cca55eeb75
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Jun 16 10:59:41 2011 -0500
description:
merge

diffstat:

 apps/las2las.cpp                    |    6 +-
 apps/lasinfo.cpp                    |    7 +-
 apps/laskernel.cpp                  |    4 +-
 include/liblas/detail/fwd.hpp       |    4 +
 include/liblas/point.hpp            |   12 +-
 include/liblas/transform.hpp        |   10 +-
 src/c_api.cpp                       |   42 +---
 src/detail/reader/reader.cpp        |   27 ++-
 src/detail/reader/zipreader.cpp     |   16 +-
 src/detail/writer/zipwriter.cpp     |    4 +-
 src/header.cpp                      |    5 +-
 src/point.cpp                       |  320 +++++++++++++++++++++--------------
 src/transform.cpp                   |   16 +-
 src/utility.cpp                     |  103 ++++++-----
 test/unit/point_test.cpp            |    3 +-
 test/unit/spatialreference_test.cpp |   18 +-
 test/unit/transform_test.cpp        |    3 +-
 17 files changed, 338 insertions(+), 262 deletions(-)

diffs (truncated from 1204 to 300 lines):

diff -r a8296ae20249 -r a5cca55eeb75 apps/las2las.cpp
--- a/apps/las2las.cpp	Wed May 18 14:19:37 2011 -0500
+++ b/apps/las2las.cpp	Thu Jun 16 10:59:41 2011 -0500
@@ -101,7 +101,7 @@
             
             if (dynamic_cast<liblas::ReprojectionTransform*>(transform.get()))
             {
-                dynamic_cast<liblas::ReprojectionTransform*>(transform.get())->SetHeaderPtr(liblas::HeaderPtr(new liblas::Header(header)));
+                dynamic_cast<liblas::ReprojectionTransform*>(transform.get())->SetHeader(liblas::HeaderOptionalConstRef(header));
             }
             new_transforms.push_back(transform);
         }
@@ -137,7 +137,7 @@
     boost::uint32_t split_points_count = 0;
     int fileno = 2;
     
-    liblas::HeaderPtr ptr = liblas::HeaderPtr(new liblas::Header(header));
+    liblas::HeaderOptionalConstRef ptr(header);
     
     while (reader.ReadNextPoint())
     {
@@ -145,7 +145,7 @@
         {
             liblas::Point p = reader.GetPoint();
             summary->AddPoint(p);
-            p.SetHeaderPtr(ptr);
+            p.SetHeader(ptr);
             writer->WritePoint(p);
         }
         else 
diff -r a8296ae20249 -r a5cca55eeb75 apps/lasinfo.cpp
--- a/apps/lasinfo.cpp	Wed May 18 14:19:37 2011 -0500
+++ b/apps/lasinfo.cpp	Thu Jun 16 10:59:41 2011 -0500
@@ -29,6 +29,7 @@
 {
 
     liblas::Summary summary;
+    summary.SetHeader(reader.GetHeader());
     
     reader.SetFilters(filters);
     reader.SetTransforms(transforms);
@@ -227,7 +228,7 @@
             }
 
         }
-
+        
         liblas::Summary summary;
         if (check)
             summary = check_points(  reader, 
@@ -236,11 +237,7 @@
                             verbose
                             );
 
-        header = reader.GetHeader();
 
-        // Add the header to the summary so we can get more detailed 
-        // info
-        summary.SetHeader(header);
         
         if (output_xml && output_json) {
             std::cerr << "both JSON and XML output cannot be chosen";
diff -r a8296ae20249 -r a5cca55eeb75 apps/laskernel.cpp
--- a/apps/laskernel.cpp	Wed May 18 14:19:37 2011 -0500
+++ b/apps/laskernel.cpp	Thu Jun 16 10:59:41 2011 -0500
@@ -1329,7 +1329,7 @@
         liblas::Bounds<double> b = header.GetExtent();
         b.project(in_ref, out_ref);
         header.SetExtent(b);
-        liblas::TransformPtr srs_transform = liblas::TransformPtr(new liblas::ReprojectionTransform(in_ref, out_ref, liblas::HeaderPtr(new liblas::Header(header))));
+        liblas::TransformPtr srs_transform = liblas::TransformPtr(new liblas::ReprojectionTransform(in_ref, out_ref, liblas::HeaderOptionalConstRef(header)));
         transforms.push_back(srs_transform);
     }
 
@@ -1414,7 +1414,7 @@
             throw std::runtime_error("The header for this file does not allow storing green color information.  Alter the header's data format using the --point-format switch");
         }        
         
-        liblas::TransformPtr color_fetch = liblas::TransformPtr(new liblas::ColorFetchingTransform(datasource, bands, liblas::HeaderPtr(new liblas::Header(header))));
+        liblas::TransformPtr color_fetch = liblas::TransformPtr(new liblas::ColorFetchingTransform(datasource, bands, liblas::HeaderOptionalConstRef(header)));
         if (bSetScale) {
             liblas::ColorFetchingTransform* c = dynamic_cast<liblas::ColorFetchingTransform*>(color_fetch.get());
             c->SetScaleFactor(scale);
diff -r a8296ae20249 -r a5cca55eeb75 include/liblas/detail/fwd.hpp
--- a/include/liblas/detail/fwd.hpp	Wed May 18 14:19:37 2011 -0500
+++ b/include/liblas/detail/fwd.hpp	Thu Jun 16 10:59:41 2011 -0500
@@ -43,6 +43,7 @@
 #define LIBLAS_DETAIL_FWD_HPP_INCLUDED
 
 #include <boost/shared_ptr.hpp>
+#include <boost/optional.hpp>
 
 // Forward declarations
 namespace liblas {
@@ -64,12 +65,15 @@
 
 typedef boost::shared_ptr<Header> HeaderPtr;
 typedef boost::shared_ptr<const Header> ConstHeaderPtr;
+
 typedef boost::shared_ptr<Point> PointPtr;
 typedef boost::shared_ptr<TransformI> TransformPtr;
 typedef boost::shared_ptr<FilterI> FilterPtr;
 typedef boost::shared_ptr<ReaderI> ReaderIPtr;
 typedef boost::shared_ptr<WriterI> WriterIPtr;
 
+typedef boost::optional<Header const&> HeaderOptionalConstRef;
+
 namespace detail {
 
 class ReaderImpl;
diff -r a8296ae20249 -r a5cca55eeb75 include/liblas/point.hpp
--- a/include/liblas/point.hpp	Wed May 18 14:19:37 2011 -0500
+++ b/include/liblas/point.hpp	Thu Jun 16 10:59:41 2011 -0500
@@ -106,6 +106,7 @@
     };
 
     Point();
+    ~Point() {};
     Point(HeaderPtr header);
     Point(Point const& other);
     Point& operator=(Point const& rhs);
@@ -201,8 +202,12 @@
     std::vector<boost::uint8_t> & GetData() {return m_data; }
     void SetData(std::vector<boost::uint8_t> const& v) { m_data = v;}
     
-    void SetHeaderPtr(HeaderPtr header);
-    HeaderPtr GetHeaderPtr() const;
+    // void SetHeaderPtr(HeaderPtr header);
+    // HeaderPtr GetHeaderPtr() const;
+        // 
+    void SetHeader(HeaderOptionalConstRef header); 
+    HeaderOptionalConstRef GetHeader() const;
+    
     
     property_tree::ptree GetPTree() const;
     
@@ -213,7 +218,8 @@
     std::vector<boost::uint8_t> m_data;
     
     std::vector<boost::uint8_t>::size_type GetDimensionBytePosition(std::size_t dim_pos) const;
-    HeaderPtr m_header;
+    // HeaderPtr m_header;
+    HeaderOptionalConstRef m_header_new;
     Header const& m_default_header;
 
 };
diff -r a8296ae20249 -r a5cca55eeb75 include/liblas/transform.hpp
--- a/include/liblas/transform.hpp	Wed May 18 14:19:37 2011 -0500
+++ b/include/liblas/transform.hpp	Thu Jun 16 10:59:41 2011 -0500
@@ -72,16 +72,16 @@
 public:
     
     ReprojectionTransform(const SpatialReference& inSRS, const SpatialReference& outSRS);    
-    ReprojectionTransform(const SpatialReference& inSRS, const SpatialReference& outSRS, liblas::HeaderPtr new_header);    
+    ReprojectionTransform(const SpatialReference& inSRS, const SpatialReference& outSRS, liblas::HeaderOptionalConstRef new_header);    
     ~ReprojectionTransform();
 
     bool transform(Point& point);
-    void SetHeaderPtr(liblas::HeaderPtr header) {m_new_header = header;}
+    void SetHeader(liblas::HeaderOptionalConstRef header) {m_new_header = header;}
     bool ModifiesHeader() { return true; }
 
 private:
 
-    liblas::HeaderPtr m_new_header;
+    liblas::HeaderOptionalConstRef m_new_header;
     
     typedef boost::shared_ptr<void> ReferencePtr;
     typedef boost::shared_ptr<void> TransformPtr;
@@ -150,7 +150,7 @@
                             );
     ColorFetchingTransform( std::string const& datasource, 
                             std::vector<boost::uint32_t> bands,
-                            HeaderPtr header);
+                            HeaderOptionalConstRef header);
     
     void SetScaleFactor(boost::uint32_t v) {m_scale = v; }
     ~ColorFetchingTransform();
@@ -161,7 +161,7 @@
 
 private:
 
-    liblas::HeaderPtr m_new_header;
+    liblas::HeaderOptionalConstRef m_new_header;
     
     typedef boost::shared_ptr<void> DataSourcePtr;
     
diff -r a8296ae20249 -r a5cca55eeb75 src/c_api.cpp
--- a/src/c_api.cpp	Wed May 18 14:19:37 2011 -0500
+++ b/src/c_api.cpp	Thu Jun 16 10:59:41 2011 -0500
@@ -443,7 +443,7 @@
                                   boost::bind( &IsReprojectionTransform, _1 ) ),
                   transforms.end());
         
-        liblas::TransformPtr srs_transform = liblas::TransformPtr(new liblas::ReprojectionTransform(in_ref, *out_ref, liblas::HeaderPtr(new liblas::Header(h))));
+        liblas::TransformPtr srs_transform = liblas::TransformPtr(new liblas::ReprojectionTransform(in_ref, *out_ref, liblas::HeaderOptionalConstRef(h)));
         if (transforms.size())
             transforms.insert(transforms.begin(), srs_transform);
         else
@@ -485,14 +485,8 @@
     VALIDATE_LAS_POINTER1(hPoint    , "LASPoint_GetHeader", new liblas::HeaderPtr());
 
     liblas::Point const& p= *((liblas::Point*) hPoint);
-    liblas::HeaderPtr h = p.GetHeaderPtr();
-    if (h.get())
-    {
-        return (LASHeaderH) new liblas::HeaderPtr(h);
-    } else
-    {
-        return (LASHeaderH) new liblas::HeaderPtr( new liblas::Header(*h.get()) );
-    }
+    liblas::HeaderOptionalConstRef h = p.GetHeader();
+    return (LASHeaderH) new liblas::HeaderPtr(new liblas::Header(h.get()));
         
 }
 
@@ -503,8 +497,9 @@
     VALIDATE_LAS_POINTER0(hHeader, "LASPoint_SetHeader");
 
     liblas::Point* point = (liblas::Point*)hPoint;
-    liblas::HeaderPtr* header = (liblas::HeaderPtr*)hHeader;
-    point->SetHeaderPtr(*header);
+    liblas::HeaderPtr h = (liblas::HeaderPtr)*hHeader;
+    liblas::Header const& header = *h;
+    point->SetHeader(HeaderOptionalConstRef(header));
 }
 
 LAS_DLL LASErrorEnum LASPoint_SetData(LASPointH hPoint, unsigned char* data) {
@@ -516,14 +511,8 @@
         liblas::Point* p = ((liblas::Point*) hPoint);
         boost::uint16_t size = 0;
 
-        liblas::HeaderPtr h = p->GetHeaderPtr();
-        if (h.get())
-        {
-            size = h->GetDataRecordLength();
-        } else
-        {
-            size = liblas::DefaultHeader::get().GetDataRecordLength();
-        }
+        liblas::HeaderOptionalConstRef h = p->GetHeader();
+        size = h->GetDataRecordLength();
         
         std::vector<boost::uint8_t> & d = p->GetData();
         if (d.size() != size)
@@ -555,14 +544,9 @@
         boost::uint16_t size = 0;
         std::vector<boost::uint8_t> const& d = p->GetData();
 
-        liblas::HeaderPtr h = p->GetHeaderPtr();
-        if (h.get())
-        {
-            size = h->GetDataRecordLength();
-        } else
-        {
-            size = liblas::DefaultHeader::get().GetDataRecordLength();
-        }        
+        liblas::HeaderOptionalConstRef h = p->GetHeader();
+        size = h->GetDataRecordLength();
+
         for (boost::uint16_t i=0; i < size; i++) {
             data[i] = d[i];
         }
@@ -1726,7 +1710,7 @@
 
     try {
         liblas::Writer* writer = ((liblas::Writer*) hWriter);
-        liblas::Header h = writer->GetHeader();
+        liblas::Header const& h = writer->GetHeader();
         liblas::SpatialReference in_ref = h.GetSRS();
         liblas::SpatialReference* out_ref = ((liblas::SpatialReference*) hSRS);
         std::vector<liblas::TransformPtr> transforms = writer->GetTransforms();
@@ -1736,7 +1720,7 @@
                                   boost::bind( &IsReprojectionTransform, _1 ) ),
                   transforms.end());
         
-        liblas::TransformPtr srs_transform = liblas::TransformPtr(new liblas::ReprojectionTransform(in_ref, *out_ref, liblas::HeaderPtr(new liblas::Header(h))));
+        liblas::TransformPtr srs_transform = liblas::TransformPtr(new liblas::ReprojectionTransform(in_ref, *out_ref, liblas::HeaderOptionalConstRef(h)));
         if (transforms.size())
             transforms.insert(transforms.begin(), srs_transform);
         else
diff -r a8296ae20249 -r a5cca55eeb75 src/detail/reader/reader.cpp
--- a/src/detail/reader/reader.cpp	Wed May 18 14:19:37 2011 -0500
+++ b/src/detail/reader/reader.cpp	Thu Jun 16 10:59:41 2011 -0500
@@ -132,18 +132,26 @@
     
     m_header_reader->ReadHeader();
     m_header = m_header_reader->GetHeader();
-
+    
     if (m_header->Compressed())
         throw std::runtime_error("Internal error: uncompressed reader encountered compressed header"); 
         
-    m_point->SetHeaderPtr(m_header);
+    // m_point->SetHeaderPtr(m_header);
+    m_point->SetHeader(HeaderOptionalConstRef(*m_header));
+
 
     Reset();
 }


More information about the Liblas-commits mailing list