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

liblas-commits at liblas.org liblas-commits at liblas.org
Sun May 17 00:59:32 EDT 2009


Author: hobu
Date: Sun May 17 00:59:31 2009
New Revision: 1269
URL: http://liblas.org/changeset/1269

Log:
more indexing junk.. bulk loading not working yet for 3d indexes

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	Sun May 17 00:59:31 2009
@@ -105,10 +105,49 @@
         usage();
         exit(-1);
     }
-    // std::cout << "input: " << input<<  " output: " <<output<<std::endl;
+    std::cout << "input: " << input<<  " output: " <<output<<std::endl;
     // 
-    // std::istream* istrm = OpenInput(input);
-    // LASReader* reader = new LASReader(*istrm);
+    std::istream* istrm = OpenInput(input);
+    LASReader* reader = new LASReader(*istrm);
+    
+    
+    LASDataStream* idxstrm = new LASDataStream(reader);
+
+    LASIndex* index = new LASIndex(*idxstrm, input);
+    
+    delete idxstrm;
+    delete index;
+    delete reader;
+    
+    LASIndex* idx = new LASIndex(input);
+    
+    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
+       ids = idx->intersects(630297.0,4834497.0,630302.0,4834501.0,0.0,200.0);
+
+    } catch (Tools::IllegalArgumentException& e) {
+        std::string s = e.what();
+        std::cout << "error querying index value" << s <<std::endl; exit(1);
+    }
+        
+    
+    
+    delete idx;
+    std::cout << "Vec length" << ids->size() << std::endl;    
+    // LASPoint* p
+    // liblas::uint32_t num_points = reader->GetHeader().GetPointRecordsCount();
+    // for (int i =0; i < num_points ; i++) {
+    //     
+    //     bool bInserted = index->insert(*p, i);
+    // }
+
     // reader->Index(input);
     // 
     // LASHeader header = reader->GetHeader();

Modified: trunk/include/liblas/lasindex.hpp
==============================================================================
--- trunk/include/liblas/lasindex.hpp	(original)
+++ trunk/include/liblas/lasindex.hpp	Sun May 17 00:59:31 2009
@@ -56,6 +56,7 @@
 
 namespace liblas {
 
+class LASDataStream;
 
 class LASIndex
 {
@@ -63,6 +64,7 @@
 
     
     LASIndex();
+    LASIndex(LASDataStream& strm, std::string& filename);
     LASIndex(std::string& filename);
     /// Copy constructor.
     LASIndex(LASIndex const& other);

Modified: trunk/src/lasindex.cpp
==============================================================================
--- trunk/src/lasindex.cpp	(original)
+++ trunk/src/lasindex.cpp	Sun May 17 00:59:31 2009
@@ -57,10 +57,63 @@
 
 LASIndex::LASIndex()
 {
+    std::cout << "Blank Index Constructor called!" << std::endl;
     m_storage = createNewLASStorageManager();
     Init();
 }
 
+LASIndex::LASIndex(LASDataStream& strm, std::string& filename)
+{
+
+    struct stat stats;
+    std::ostringstream os;
+    os << filename << ".dat";
+    std::cout << "LASDataStream index name: " << os.str() << std::endl;
+
+    std::string indexname = os.str();
+    int ret = stat(indexname.c_str(),&stats);
+    if (!ret) {
+        std::cout << "loading existing index " << indexname << std::endl;
+        try{
+            m_storage = SpatialIndex::StorageManager::loadDiskStorageManager(filename);
+            Init();
+        } catch (Tools::Exception& e) {
+            std::string s = e.what();
+            std::cout << "error loading index " << s <<std::endl; exit(1);
+        }
+    }
+    else
+    {
+        std::cout << "Creating new index from LASReader stream ... " << std::endl;
+        try{
+            m_storage = SpatialIndex::StorageManager::createNewDiskStorageManager(filename, 4096);
+            uint16_t capacity = 10;
+            bool writeThrough = false;
+            // R-Tree parameters
+            double fillFactor = 0.7;
+            uint32_t indexCapacity = 100;
+            uint32_t leafCapacity = 100;
+            uint32_t dimension = 3;
+            SpatialIndex::id_type indexId=1;
+            m_buffer = SpatialIndex::StorageManager::createNewRandomEvictionsBuffer(*m_storage, capacity, writeThrough);
+            m_rtree = SpatialIndex::RTree::createAndBulkLoadNewRTree(   SpatialIndex::RTree::BLM_STR,
+                                                                        strm,
+                                                                        *m_buffer,
+                                                                        fillFactor,
+                                                                        indexCapacity,
+                                                                        leafCapacity,
+                                                                        dimension,
+                                                                        SpatialIndex::RTree::RV_RSTAR,
+                                                                        indexId);
+        bool ret = m_rtree->isIndexValid();
+        if (ret == false) std::cerr << "ERROR: Structure is invalid!" << std::endl;
+            
+        } catch (Tools::Exception& e) {
+            std::string s = e.what();
+            std::cout << "error creating index" << s <<std::endl; exit(1);
+        }
+    }        
+}
 void LASIndex::Init()
 {    
     uint16_t capacity = 10;
@@ -125,6 +178,7 @@
 LASIndex::~LASIndex() 
 {
     std::cout << "~LASIndex called" << std::endl;
+    
     delete m_rtree;
     delete m_buffer;
     delete m_storage;
@@ -181,7 +235,7 @@
     const SpatialIndex::Region *region = new SpatialIndex::Region(min, max, 3);
     std::cout << *region << std::endl;
     index().intersectsWithQuery(*region, *visitor);
-    
+    std::cout << index() <<std::endl;
     return vect;
     
 }
@@ -296,6 +350,7 @@
     if (read)
         m_id = 0;
 
+    std::cout<<"Initiating LASDataStream... read=" << read <<std::endl;
     
 }
 
@@ -309,7 +364,6 @@
         p = (LASPoint*) &(m_reader->GetPoint());
     else
         return false;
-//        throw Tools::IllegalStateException("Unable to read first point for LASReader!");
     
     double x = p->GetX();
     double y = p->GetY();
@@ -318,9 +372,11 @@
     min[0] = x; min[1] = y; min[2] = z;
     max[0] = x; max[1] = y; max[2] = z;
     
-    m_id = 0;
+
     SpatialIndex::Region r = SpatialIndex::Region(min, max, 3);
     m_pNext = new SpatialIndex::RTree::Data(0, 0, r, m_id);
+    
+     std::cout << "Read point " << r <<  "Id: " << m_id << std::endl;
     return true;
 }
 
@@ -338,6 +394,7 @@
 
 bool LASDataStream::hasNext() throw (Tools::NotSupportedException)
 {
+    // std::cout << "LASDataStream::hasNext called ..." << std::endl;
     return (m_pNext != 0);
 }
 
@@ -348,6 +405,7 @@
 
 void LASDataStream::rewind() throw (Tools::NotSupportedException)
 {
+    // std::cout << "LASDataStream::rewind called..." << std::endl;
 
     if (m_pNext != 0)
     {


More information about the Liblas-commits mailing list