[Liblas-commits] hg: 2 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Dec 20 12:58:56 EST 2010


changeset c0cb2660a84b in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=c0cb2660a84b
summary: don't reset the header if it doesn't need to be reset.  I'm so stupid

changeset 48542695b493 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=48542695b493
summary: add a CoordinateSummary utility that only touches GetX, GetY, and GetZ for doing things like summarizing the info needed for header writing in las2las, etc

diffstat:

 apps/las2las.cpp            |    8 +-
 apps/lasblock.cpp           |    4 +-
 apps/laskernel.cpp          |    2 +-
 apps/laskernel.hpp          |    2 +-
 include/liblas/utility.hpp  |   24 +++++++
 src/detail/reader/point.cpp |    3 +-
 src/utility.cpp             |  145 ++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 179 insertions(+), 9 deletions(-)

diffs (286 lines):

diff -r c430311ecc55 -r 48542695b493 apps/las2las.cpp
--- a/apps/las2las.cpp	Mon Dec 20 09:48:35 2010 -0600
+++ b/apps/las2las.cpp	Mon Dec 20 11:58:46 2010 -0600
@@ -22,7 +22,7 @@
 using namespace std;
 
 typedef boost::shared_ptr<liblas::Writer> WriterPtr;
-typedef boost::shared_ptr<liblas::Summary> SummaryPtr;
+typedef boost::shared_ptr<liblas::CoordinateSummary> SummaryPtr;
 typedef boost::shared_ptr<std::ofstream> OStreamPtr;
 
 WriterPtr start_writer(   OStreamPtr strm, 
@@ -62,7 +62,7 @@
 
     liblas::ReaderFactory f;
     liblas::Reader reader = f.CreateWithStream(ifs);
-    SummaryPtr summary(new::liblas::Summary);
+    SummaryPtr summary(new::liblas::CoordinateSummary);
     
     reader.SetFilters(filters);
     reader.SetTransforms(transforms);    
@@ -162,7 +162,7 @@
             RepairHeader(*summary, hnew);
             RewriteHeader(hnew, old_filename.str());
 
-            summary =  SummaryPtr(new liblas::Summary); 
+            summary =  SummaryPtr(new liblas::CoordinateSummary); 
             fileno++;
             split_bytes_count = 1024*1024*split_mb;
         }
@@ -190,7 +190,7 @@
             RepairHeader(*summary, hnew);
             RewriteHeader(hnew, old_filename.str());
 
-            summary =  SummaryPtr(new liblas::Summary); 
+            summary =  SummaryPtr(new liblas::CoordinateSummary); 
             fileno++;
             split_points_count = 0;
         }
diff -r c430311ecc55 -r 48542695b493 apps/lasblock.cpp
--- a/apps/lasblock.cpp	Mon Dec 20 09:48:35 2010 -0600
+++ b/apps/lasblock.cpp	Mon Dec 20 11:58:46 2010 -0600
@@ -38,7 +38,7 @@
 #endif
 
 typedef boost::shared_ptr<liblas::Writer> WriterPtr;
-typedef boost::shared_ptr<liblas::Summary> SummaryPtr;
+typedef boost::shared_ptr<liblas::CoordinateSummary> SummaryPtr;
 typedef boost::shared_ptr<std::ofstream> OStreamPtr;
 
 WriterPtr start_writer(   OStreamPtr strm, 
@@ -103,7 +103,7 @@
     for ( boost::uint32_t i = 0; i < c.GetBlockCount(); ++i )
     {
         OStreamPtr ofs(new std::ofstream);
-        SummaryPtr summary(new::liblas::Summary);
+        SummaryPtr summary(new::liblas::CoordinateSummary);
 
         std::ostringstream name;
         name << out << "-" << i <<".las";
diff -r c430311ecc55 -r 48542695b493 apps/laskernel.cpp
--- a/apps/laskernel.cpp	Mon Dec 20 09:48:35 2010 -0600
+++ b/apps/laskernel.cpp	Mon Dec 20 11:58:46 2010 -0600
@@ -136,7 +136,7 @@
     }
 }  
   
-void RepairHeader(liblas::Summary const& summary, liblas::Header& header)
+void RepairHeader(liblas::CoordinateSummary const& summary, liblas::Header& header)
 {
 
     for (boost::uint32_t i = 0; i < 5; i++)
diff -r c430311ecc55 -r 48542695b493 apps/laskernel.hpp
--- a/apps/laskernel.hpp	Mon Dec 20 09:48:35 2010 -0600
+++ b/apps/laskernel.hpp	Mon Dec 20 11:58:46 2010 -0600
@@ -101,7 +101,7 @@
 
 LAS_DLL liblas::Header FetchHeader(std::string const& filename);
 LAS_DLL void RewriteHeader(liblas::Header const& header, std::string const& filename);
-LAS_DLL void RepairHeader(liblas::Summary const& summary, liblas::Header& header);
+LAS_DLL void RepairHeader(liblas::CoordinateSummary const& summary, liblas::Header& header);
 LAS_DLL liblas::property_tree::ptree SummarizeReader(liblas::Reader& reader) ;
 
 #endif // LIBLAS_ITERATOR_HPP_INCLUDED
diff -r c430311ecc55 -r 48542695b493 include/liblas/utility.hpp
--- a/include/liblas/utility.hpp	Mon Dec 20 09:48:35 2010 -0600
+++ b/include/liblas/utility.hpp	Mon Dec 20 11:58:46 2010 -0600
@@ -89,6 +89,30 @@
     bool bHaveHeader; 
 };
 
+class LAS_DLL CoordinateSummary
+{
+public:
+    
+    CoordinateSummary();
+    CoordinateSummary(CoordinateSummary const& other);
+    CoordinateSummary& operator=(CoordinateSummary const& rhs);
+
+    void AddPoint(liblas::Point const& p);
+    ptree GetPTree() const;
+    void SetHeader(liblas::Header const& h);
+    
+private:
+
+    boost::uint32_t count;
+    boost::array<boost::uint32_t, 8> points_by_return; 
+    boost::array<boost::uint32_t, 8> returns_of_given_pulse;
+    bool first;
+    liblas::Point min;
+    liblas::Point max;
+    liblas::Header m_header;
+    bool bHaveHeader; 
+};
+
 LAS_DLL std::ostream& operator<<(std::ostream& os, liblas::Summary const& s);
 
 LAS_DLL boost::uint32_t GetStreamPrecision(double scale);
diff -r c430311ecc55 -r 48542695b493 src/detail/reader/point.cpp
--- a/src/detail/reader/point.cpp	Mon Dec 20 09:48:35 2010 -0600
+++ b/src/detail/reader/point.cpp	Mon Dec 20 11:58:46 2010 -0600
@@ -73,7 +73,8 @@
     assert(m_point.GetHeaderPtr());
     assert(m_record_size > 0);
     
-    m_point.SetHeaderPtr(m_header);
+    if (m_point.GetHeaderPtr().get() != m_header.get())
+        m_point.SetHeaderPtr(m_header);
     
     detail::read_n(m_point.GetData().front(), m_ifs, m_record_size);
 
diff -r c430311ecc55 -r 48542695b493 src/utility.cpp
--- a/src/utility.cpp	Mon Dec 20 09:48:35 2010 -0600
+++ b/src/utility.cpp	Mon Dec 20 11:58:46 2010 -0600
@@ -456,6 +456,151 @@
     
 }
 
+CoordinateSummary::CoordinateSummary() :
+    count(0)
+    , first(true)
+    , bHaveHeader(false)
+    
+{
+    points_by_return.assign(0);
+    returns_of_given_pulse.assign(0);    
+}
+
+CoordinateSummary::CoordinateSummary(CoordinateSummary const& other)
+    : 
+    count(other.count)
+    , points_by_return(other.points_by_return)
+    , returns_of_given_pulse(other.returns_of_given_pulse)
+    , first(other.first)
+    , min(other.min)
+    , max(other.max)
+    , m_header(other.m_header)
+    , bHaveHeader(other.bHaveHeader)
+{
+}
+
+CoordinateSummary& CoordinateSummary::operator=(CoordinateSummary const& rhs)
+{
+    if (&rhs != this)
+    {
+        count = rhs.count;
+        first = rhs.first;
+        points_by_return = rhs.points_by_return;
+        returns_of_given_pulse = rhs.returns_of_given_pulse;
+        min = rhs.min;
+        max = rhs.max;
+        m_header = rhs.m_header;
+        bHaveHeader = rhs.bHaveHeader;
+    }
+    return *this;
+}
+
+void CoordinateSummary::AddPoint(liblas::Point const& p)
+{
+        count++;
+
+        if (first) {
+            min = p;
+            max = p;
+            
+            // We only summarize the base dimensions 
+            // but we want to be able to read/set them all.  The 
+            // point copy here would set the header ptr of min/max
+            // to be whatever might have come off of the file, 
+            // and this may/may not have space for time/color
+            
+            // If we do have scale/offset values, we do want to keep those, 
+            // however.  
+            liblas::HeaderPtr hdr = p.GetHeaderPtr();
+            if (hdr.get()) 
+            {
+                // Keep scale/offset values around because we need these 
+                liblas::Header header;
+                header.SetScale(hdr->GetScaleX(), hdr->GetScaleY(), hdr->GetScaleZ());
+                header.SetOffset(hdr->GetOffsetX(), hdr->GetOffsetY(), hdr->GetOffsetZ());
+                liblas::HeaderPtr h(new liblas::Header(header));
+                min.SetHeaderPtr(h);
+                max.SetHeaderPtr(h);
+            } else 
+            {
+                min.SetHeaderPtr(HeaderPtr());
+                max.SetHeaderPtr(HeaderPtr()); 
+            }
+
+            first = false;
+        }
+        
+        min.SetX(std::min(p.GetX(), min.GetX()));
+        max.SetX(std::max(p.GetX(), max.GetX()));
+
+        min.SetY(std::min(p.GetY(), min.GetY()));
+        max.SetY(std::max(p.GetY(), max.GetY()));        
+
+        min.SetZ(std::min(p.GetZ(), min.GetZ()));
+        max.SetZ(std::max(p.GetZ(), max.GetZ()));
+
+
+
+        points_by_return[p.GetReturnNumber()]++;
+        returns_of_given_pulse[p.GetNumberOfReturns()]++;    
+}
+
+void CoordinateSummary::SetHeader(liblas::Header const& h) 
+{
+    m_header = h;
+    bHaveHeader = true;
+}
+
+ptree CoordinateSummary::GetPTree() const
+{
+    ptree pt;
+    
+    ptree pmin = min.GetPTree();
+    ptree pmax = max.GetPTree();
+    
+     
+    pt.add_child("minimum", pmin);
+    pt.add_child("maximum", pmax);
+
+    ptree returns;
+    bool have_returns = false;
+    for (boost::array<boost::uint32_t,8>::size_type i=0; i < points_by_return.size(); i++) {
+        if (i == 0) continue;
+
+        if (points_by_return[i] != 0)
+        {
+            have_returns = true;
+            returns.put("id", i);
+            returns.put("count", points_by_return[i]);
+            pt.add_child("points_by_return.return", returns);
+            
+        }
+    }
+    
+    if (! have_returns) {
+        // Assume all points are first return
+        returns.put("id", 1);
+        returns.put("count", count);
+        pt.add_child("points_by_return.return", returns);        
+    }
+    
+    ptree pulses;
+    for (boost::array<boost::uint32_t,8>::size_type i=0; i < returns_of_given_pulse.size(); i++) {
+        if (returns_of_given_pulse[i] != 0) {
+            pulses.put("id",i);
+            pulses.put("count", returns_of_given_pulse[i]);
+            pt.add_child("returns_of_given_pulse.pulse", pulses);
+        }
+    }
+    
+    pt.put("count", count);
+
+    liblas::property_tree::ptree top;
+    if (bHaveHeader)
+        top.add_child("summary.header",m_header.GetPTree());
+    top.add_child("summary.points",pt);
+    return top;
+}
 
 boost::uint32_t GetStreamPrecision(double scale)
 {


More information about the Liblas-commits mailing list