[Liblas-commits] r1272 - in trunk: apps include/liblas src

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Jun 8 21:52:13 EDT 2009


Author: hobu
Date: Wed May 20 11:26:05 2009
New Revision: 1272
URL: http://liblas.org/changeset/1272

Log:
more refactoring, still not done

Modified:
   trunk/apps/lasindex.cpp
   trunk/include/liblas/lasindex.hpp
   trunk/src/lasindex.cpp

Modified: trunk/apps/lasindex.cpp
==============================================================================
--- trunk/apps/lasindex.cpp	(original)
+++ trunk/apps/lasindex.cpp	Wed May 20 11:26:05 2009
@@ -143,7 +143,32 @@
     
     std::cout << "Vec length" << ids->size() << std::endl;  
     delete idx;
-  
+
+    LASDataStream* idxstrm = new LASDataStream(reader);
+
+    LASIndex* index = new LASIndex(*idxstrm, "MEMORY");
+    
+    //doing it in memory
+
+    std::vector<liblas::uint32_t>* ids = 0;
+
+    try{
+//        ids = idx->intersects(289815.12,4320979.06, 289818.01,4320982.59,46.83,170.65);
+
+// _zoom
+//        ids = idx->intersects(630355.0,4834609.0,630395.0,4834641.0,0.0,200.0);
+
+// _clip
+// 630346.830000,4834500.000000,55.260000
+        ids = index->intersects(630262.300000,4834500.000000,630346.830000,4834500.000000,50.900000,55.260000);
+//       ids = idx->intersects(630297.0,4834497.0,630302.0,4834501.0,0.0,200.0);
+
+    } catch (Tools::Exception& e) {
+        std::string s = e.what();
+        std::cout << "error querying index value" << s <<std::endl; exit(1);
+    }
+    
+
     // LASPoint* p
     // liblas::uint32_t num_points = reader->GetHeader().GetPointRecordsCount();
     // for (int i =0; i < num_points ; i++) {

Modified: trunk/include/liblas/lasindex.hpp
==============================================================================
--- trunk/include/liblas/lasindex.hpp	(original)
+++ trunk/include/liblas/lasindex.hpp	Wed May 20 11:26:05 2009
@@ -115,7 +115,7 @@
     uint32_t m_idxLeafCap;
     uint32_t m_idxDimension;   
     double m_idxFillFactor; 
-    bool m_idxExternalExists;
+    bool m_idxExists;
 
 
     uint16_t m_bufferCapacity;
@@ -124,7 +124,8 @@
     void Init();
     SpatialIndex::IStorageManager* CreateStorage(std::string& filename);
     SpatialIndex::StorageManager::IBuffer* CreateIndexBuffer(SpatialIndex::IStorageManager& storage);
-    
+    SpatialIndex::ISpatialIndex* CreateIndex(LASDataStream& strm);
+    SpatialIndex::ISpatialIndex* LoadIndex();
     bool ExternalIndexExists(std::string& filename);
 };
 

Modified: trunk/src/lasindex.cpp
==============================================================================
--- trunk/src/lasindex.cpp	(original)
+++ trunk/src/lasindex.cpp	Wed May 20 11:26:05 2009
@@ -70,7 +70,7 @@
     m_bufferCapacity = 10;
     m_bufferWriteThrough = false;
 
-    m_idxExternalExists = false;
+    m_idxExists = false;
 }
 
 LASIndex::LASIndex()
@@ -79,7 +79,55 @@
     Init();
 }
 
+SpatialIndex::ISpatialIndex* LASIndex::CreateIndex(LASDataStream& strm) 
+{
+    using namespace SpatialIndex;
+    
+    ISpatialIndex* index = 0;
+    
+    try{
+        index = RTree::createAndBulkLoadNewRTree(   SpatialIndex::RTree::BLM_STR,
+                                                      strm,
+                                                      *m_buffer,
+                                                      m_idxFillFactor,
+                                                      m_idxCapacity,
+                                                      m_idxLeafCap,
+                                                      m_idxDimension,
+                                                      SpatialIndex::RTree::RV_RSTAR,
+                                                      m_idxId);
+        bool ret = index->isIndexValid();
+        if (ret == false) 
+            throw std::runtime_error(   "Spatial index error: index is not"
+                                        " valid after createAndBulkLoadNewRTree");
 
+        return index;
+    } catch (Tools::Exception& e) {
+        std::ostringstream os;
+        os << "Spatial Index Error: " << e.what();
+        throw std::runtime_error(os.str());
+    }    
+}
+
+SpatialIndex::ISpatialIndex* LASIndex::LoadIndex() 
+{
+    using namespace SpatialIndex;
+    
+    ISpatialIndex* index = 0;
+    
+    try{
+        index = RTree::loadRTree(*m_buffer,m_idxId);
+        bool ret = index->isIndexValid();
+        if (ret == false) 
+            throw std::runtime_error(   "Spatial index error: index is not"
+                                        " valid after loadRTree");
+
+        return index;
+    } catch (Tools::Exception& e) {
+        std::ostringstream os;
+        os << "Spatial Index Error: " << e.what();
+        throw std::runtime_error(os.str());
+    }    
+}
 LASIndex::LASIndex(LASDataStream& strm, std::string& filename)
 {
     using namespace SpatialIndex;
@@ -89,42 +137,15 @@
     m_storage = CreateStorage(filename);
     m_buffer = CreateIndexBuffer(*m_storage);
 
-    if (m_idxType == eExternalIndex) {
-            
-    if (m_idxExternalExists == true) {
+    if (m_idxExists == true) {
         std::cout << "loading existing index from LASDataStream " << std::endl;
-        try{
-            m_rtree = SpatialIndex::RTree::loadRTree(*m_buffer,m_idxId);
-        } catch (Tools::Exception& e) {
-            std::ostringstream os;
-            os << "Spatial Index Error: " << e.what();
-            throw std::runtime_error(os.str());
-        }
+        m_rtree = LoadIndex();
     }
     else
     {
         std::cout << "Creating new index from LASDataStream  ... " << std::endl;
-        try{
-            m_rtree = RTree::createAndBulkLoadNewRTree(   SpatialIndex::RTree::BLM_STR,
-                                                          strm,
-                                                          *m_buffer,
-                                                          m_idxFillFactor,
-                                                          m_idxCapacity,
-                                                          m_idxLeafCap,
-                                                          m_idxDimension,
-                                                          SpatialIndex::RTree::RV_RSTAR,
-                                                          m_idxId);
-        bool ret = m_rtree->isIndexValid();
-        if (ret == false) 
-            throw std::runtime_error(   "Spatial index error: index is not"
-                                        " valid after createAndBulkLoadNewRTree");
-        } catch (Tools::Exception& e) {
-            std::ostringstream os;
-            os << "Spatial Index Error: " << e.what();
-            throw std::runtime_error(os.str());
-        }
+        m_rtree = CreateIndex(strm);
     }        
-    } // eExternalIndex
 }
 
 
@@ -139,7 +160,7 @@
             std::cout << "loading existing DiskStorage " << filename << std::endl;
             try{
                 storage = loadDiskStorageManager(filename);
-                m_idxExternalExists = true;
+                m_idxExists = true;
                 return storage;
             } catch (Tools::Exception& e) {
                 std::ostringstream os;
@@ -150,7 +171,7 @@
             try{
                 std::cout << "creating new DiskStorage " << filename << std::endl;            
                 storage = createNewDiskStorageManager(filename, m_Pagesize);
-                m_idxExternalExists = false;
+                m_idxExists = false;
                 return storage;
             } catch (Tools::Exception& e) {
                 std::ostringstream os;
@@ -158,6 +179,19 @@
                 throw std::runtime_error(os.str());
             }         
         }
+    } else if (m_idxType == eMemoryIndex) {
+
+        try{
+            std::cout << "creating new DiskStorage " << filename << std::endl;            
+            storage = createNewMemoryStorageManager();
+            m_idxExists = false;
+            return storage;
+        } catch (Tools::Exception& e) {
+            std::ostringstream os;
+            os << "Spatial Index Error: " << e.what();
+            throw std::runtime_error(os.str());
+        } 
+                    
     }
     return storage;               
 }
@@ -186,15 +220,19 @@
     std::ostringstream os;
     os << filename << ".dat";
     
-    if (m_idxExternalExists == true) return true;
+    // if we have already checked, we're done.
+    if (m_idxExists == true) return true;
 
     std::string indexname = os.str();
+    
+    // ret is -1 for no file existing and 0 for existing
     int ret = stat(indexname.c_str(),&stats);
-    std::cout << "indexname: " << indexname << " ret: " << ret << std::endl;
+
     bool output = false;
     if (ret == 0) output= true; else output =false;
     return output;
 }
+
 LASIndex::LASIndex(std::string& filename) 
 {
 
@@ -204,31 +242,15 @@
     
     m_buffer = CreateIndexBuffer(*m_storage);
 
-    if (ExternalIndexExists(filename)) {
-        std::cout << "loading existing index " << filename << std::endl;
-        try{
-            // m_storage = SpatialIndex::StorageManager::loadDiskStorageManager(filename);
-            // m_buffer = SpatialIndex::StorageManager::createNewRandomEvictionsBuffer(*m_storage, 
-            //                                                                         m_bufferCapacity, 
-            //                                                                         m_bufferWriteThrough);
-            m_rtree = SpatialIndex::RTree::loadRTree(*m_buffer,m_idxId);
-        } catch (Tools::Exception& e) {
-                std::ostringstream os;
-                os << "Spatial Index Error: " << e.what();
-                throw std::runtime_error(os.str());
-        }
+    if (m_idxExists == true) {
+        std::cout << "loading existing index from file " << std::endl;
+        m_rtree = LoadIndex();
     }
-    else{std::cout << "index name does not exist, failing" << std::endl;exit(1);}
-    // else
-    // {
-    //     std::cout << "Creating new index ... " << std::endl;
-    //     try{
-    //         m_storage = SpatialIndex::StorageManager::createNewDiskStorageManager(filename, 4096);
-    //     } catch (Tools::IllegalStateException& e) {
-    //         std::string s = e.what();
-    //         std::cout << "error creating index" << s <<std::endl; exit(1);
-    //     }
-    // }
+    else
+    {
+        throw std::runtime_error("can't create index with only a filename, must have LASDatastream");
+    }   
+    
 }
 
 LASIndex::LASIndex(LASIndex const& other) 


More information about the Liblas-commits mailing list