[Liblas-commits] hg: ensure that we don't run out of call stack filtering points ...

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Aug 17 15:27:46 EDT 2010


changeset 0dfc6034dda0 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=0dfc6034dda0
summary: ensure that we don't run out of call stack filtering points by no recursing ReadNextPoint if we fail to pass the filter

diffstat:

 include/liblas/lasreader.hpp |   1 +
 src/lasreader.cpp            |  51 +++++++++++++++++++++++--------------------
 2 files changed, 28 insertions(+), 24 deletions(-)

diffs (86 lines):

diff -r 631eeaa724f6 -r 0dfc6034dda0 include/liblas/lasreader.hpp
--- a/include/liblas/lasreader.hpp	Tue Aug 17 13:27:16 2010 -0500
+++ b/include/liblas/lasreader.hpp	Tue Aug 17 14:27:38 2010 -0500
@@ -163,6 +163,7 @@
     Reader& operator=(Reader const& rhs);
 
     void Init(); // throws on error
+    bool KeepPoint(liblas::Point const& p);
 
     const std::auto_ptr<ReaderI> m_pimpl;
 
diff -r 631eeaa724f6 -r 0dfc6034dda0 src/lasreader.cpp
--- a/src/lasreader.cpp	Tue Aug 17 13:27:16 2010 -0500
+++ b/src/lasreader.cpp	Tue Aug 17 14:27:38 2010 -0500
@@ -149,44 +149,47 @@
     return *m_point;
 }
 
+bool Reader::KeepPoint(liblas::Point const& p)
+{
+    std::vector<liblas::FilterI*>::const_iterator fi;
+    
+    // If there's no filters on this reader, we keep 
+    // the point no matter what.
+    if (m_filters == 0 ) {
+        return true;
+    }
+
+    for (fi = m_filters->begin(); fi != m_filters->end(); ++fi) {
+        liblas::FilterI* filter = *fi;
+        if (!filter->filter(p)){
+            return false;
+        }
+    }
+    return true;
+}
+
 bool Reader::ReadNextPoint()
 {
-    std::vector<liblas::FilterI*>::const_iterator fi;
     std::vector<liblas::TransformI*>::const_iterator ti;
     bool bHaveTransforms = false;
-    bool bHaveFilters = false;
     
     if (m_transforms != 0 ) {
         bHaveTransforms = true;
     }
     
-    if (m_filters != 0 ) {
-        bHaveFilters = true;
-    }
+
     
     try {
         // m_point = m_pimpl->ReadNextPoint(m_header).get();
         m_point = const_cast<Point*>(&(m_pimpl->ReadNextPoint(m_header)));
-        if (bHaveFilters) {
-        if (m_filters->size() != 0) {
-            // We have filters, filter this point.  All filters must 
-            // return true for us to keep it.
-            bool keep = false;
-            for (fi = m_filters->begin(); fi != m_filters->end(); ++fi) {
-                liblas::FilterI* filter = *fi;
-                if (filter->filter(*m_point)){
-                    // if ->filter() is true, we keep the point
-                    keep = true;
-                } else {
-                    keep = false;
-                    break;
-                }
-                
+        
+        // Filter the points and continue reading until we either find 
+        // one to keep or throw an exception.
+        if (!KeepPoint(*m_point)) {
+            m_point = const_cast<Point*>(&(m_pimpl->ReadNextPoint(m_header)));
+            while (!KeepPoint(*m_point)) {
+                m_point = const_cast<Point*>(&(m_pimpl->ReadNextPoint(m_header)));
             }
-            if (!keep) {
-                return ReadNextPoint();
-            }
-        }
         }
         
         if (bHaveTransforms) {


More information about the Liblas-commits mailing list