[Liblas-commits] r1283 - in trunk: include/liblas/index src/index
liblas-commits at liblas.org
liblas-commits at liblas.org
Mon Jun 8 21:52:13 EDT 2009
Author: hobu
Date: Thu May 21 15:08:07 2009
New Revision: 1283
URL: http://liblas.org/changeset/1283
Log:
basic VLR index storage mechanism
Modified:
trunk/include/liblas/index/index.hpp
trunk/include/liblas/index/storage.hpp
trunk/src/index/datastream.cpp
trunk/src/index/index.cpp
trunk/src/index/storage.cpp
Modified: trunk/include/liblas/index/index.hpp
==============================================================================
--- trunk/include/liblas/index/index.hpp (original)
+++ trunk/include/liblas/index/index.hpp Thu May 21 15:08:07 2009
@@ -42,7 +42,6 @@
#ifndef LIBLAS_INDEX_INDEX_HPP_INCLUDED
#define LIBLAS_INDEX_INDEX_HPP_INCLUDED
-#include <liblas/lasvariablerecord.hpp>
#include <liblas/laspoint.hpp>
#include <spatialindex/SpatialIndex.h>
@@ -113,11 +112,11 @@
/// Sets the index type
/// \param v - index type. Defaults to eExternalIndex.
- void SetIndexType(IndexType v) { m_idxType = v; }
+ void SetType(IndexType v) { m_idxType = v; }
/// Gets the index type
/// \return index type.
- IndexType GetIndexType() { return m_idxType; }
+ IndexType GetType() { return m_idxType; }
private:
Modified: trunk/include/liblas/index/storage.hpp
==============================================================================
--- trunk/include/liblas/index/storage.hpp (original)
+++ trunk/include/liblas/index/storage.hpp Thu May 21 15:08:07 2009
@@ -42,6 +42,7 @@
#ifndef LIBLAS_INDEX_STORAGE_HPP_INCLUDED
#define LIBLAS_INDEX_STORAGE_HPP_INCLUDED
+#include <liblas/lasvariablerecord.hpp>
#include <spatialindex/SpatialIndex.h>
@@ -54,37 +55,43 @@
namespace liblas {
-extern SpatialIndex::IStorageManager* returnLASStorageManager(Tools::PropertySet& in);
-extern SpatialIndex::IStorageManager* createNewLASStorageManager();
+extern SpatialIndex::IStorageManager* returnVLRStorageManager(Tools::PropertySet& in);
+extern SpatialIndex::IStorageManager* createNewVLRStorageManager();
-class LASStorageManager : public SpatialIndex::IStorageManager
+class VLRStorageManager : public SpatialIndex::IStorageManager
{
public:
- LASStorageManager(Tools::PropertySet&);
+ VLRStorageManager(Tools::PropertySet&);
- virtual ~LASStorageManager();
+ virtual ~VLRStorageManager();
virtual void loadByteArray(const SpatialIndex::id_type id, size_t& len, uint8_t** data);
virtual void storeByteArray(SpatialIndex::id_type& id, const size_t len, const uint8_t* const data);
virtual void deleteByteArray(const SpatialIndex::id_type id);
private:
- class Entry
- {
- public:
- byte* m_pData;
- size_t m_length;
-
- Entry(size_t l, const uint8_t* const d) : m_pData(0), m_length(l)
- {
- m_pData = new uint8_t[m_length];
- memcpy(m_pData, d, m_length);
- }
-
- ~Entry() { delete[] m_pData; }
- }; // Entry
-
- std::vector<Entry*> m_buffer;
+
+ LASVariableRecord m_data;
+ LASVariableRecord m_ids;
+ //
+ // class Entry
+ // {
+ // public:
+ // byte* m_pData;
+ // size_t m_length;
+ //
+ // Entry(size_t l, const uint8_t* const d) : m_pData(0), m_length(l)
+ // {
+ // m_pData = new uint8_t[m_length];
+ // memcpy(m_pData, d, m_length);
+ // }
+ //
+ // ~Entry() { delete[] m_pData; }
+ // }; // Entry
+
+ LASVariableRecord* makeVLR(const size_t len, const uint8_t* data);
+ // std::vector<Entry*> m_buffer;
+ std::vector<LASVariableRecord*> m_vlrbuffer;
std::stack<SpatialIndex::id_type> m_emptyPages;
}; // MemoryStorageManager
Modified: trunk/src/index/datastream.cpp
==============================================================================
--- trunk/src/index/datastream.cpp (original)
+++ trunk/src/index/datastream.cpp Thu May 21 15:08:07 2009
@@ -59,7 +59,8 @@
LASIndexDataStream::LASIndexDataStream(LASReader *reader) : m_reader(reader), m_pNext(0), m_id(0)
{
- readPoint();
+ bool read = readPoint();
+ if (read) m_id = 0;
}
LASIndexDataStream::~LASIndexDataStream()
Modified: trunk/src/index/index.cpp
==============================================================================
--- trunk/src/index/index.cpp (original)
+++ trunk/src/index/index.cpp Thu May 21 15:08:07 2009
@@ -206,6 +206,7 @@
{
using namespace SpatialIndex::StorageManager;
+ std::cout << "index type:" << m_idxType << std::endl;
SpatialIndex::IStorageManager* storage = 0;
if (m_idxType == eExternalIndex) {
@@ -235,8 +236,8 @@
} else if (m_idxType == eMemoryIndex) {
try{
- std::cout << "creating new DiskStorage " << filename << std::endl;
- storage = createNewMemoryStorageManager();
+ std::cout << "creating new createNewVLRStorageManager " << filename << std::endl;
+ storage = createNewVLRStorageManager();
m_idxExists = false;
return storage;
} catch (Tools::Exception& e) {
Modified: trunk/src/index/storage.cpp
==============================================================================
--- trunk/src/index/storage.cpp (original)
+++ trunk/src/index/storage.cpp Thu May 21 15:08:07 2009
@@ -55,104 +55,121 @@
{
-SpatialIndex::IStorageManager* returnLASStorageManager(Tools::PropertySet& ps)
+SpatialIndex::IStorageManager* returnVLRStorageManager(Tools::PropertySet& ps)
{
- SpatialIndex::IStorageManager* sm = new LASStorageManager(ps);
+ SpatialIndex::IStorageManager* sm = new VLRStorageManager(ps);
return sm;
}
-SpatialIndex::IStorageManager* createNewLASStorageManager()
+SpatialIndex::IStorageManager* createNewVLRStorageManager()
{
Tools::PropertySet ps;
- return returnLASStorageManager(ps);
+ return returnVLRStorageManager(ps);
}
-LASStorageManager::LASStorageManager(Tools::PropertySet& ps)
+VLRStorageManager::VLRStorageManager(Tools::PropertySet& ps)
{
}
-LASStorageManager::~LASStorageManager()
+VLRStorageManager::~VLRStorageManager()
{
- for (std::vector<Entry*>::iterator it = m_buffer.begin(); it != m_buffer.end(); it++) delete *it;
+
+ // uint32_t vlrsize=0;
+ for (std::vector<LASVariableRecord*>::iterator vit = m_vlrbuffer.begin(); vit != m_vlrbuffer.end(); vit++) {
+ // vlrsize = vlrsize+(*vit)->GetRecordLength();
+ delete *vit;
+ }
+
}
-void LASStorageManager::loadByteArray(const SpatialIndex::id_type id, size_t& len, uint8_t** data)
+void VLRStorageManager::loadByteArray(const SpatialIndex::id_type id, size_t& len, uint8_t** data)
{
- Entry* e;
+ LASVariableRecord* v;
try
{
- e = m_buffer.at(id);
- if (e == 0) throw Tools::InvalidPageException(id);
+ v = m_vlrbuffer.at(id);
+ if (v == 0) throw Tools::InvalidPageException(id);
}
catch (std::out_of_range)
{
throw Tools::InvalidPageException(id);
}
- len = e->m_length;
+ len = v->GetRecordLength();
*data = new uint8_t[len];
- memcpy(*data, e->m_pData, len);
+ memcpy(*data, (uint8_t*)&(v->GetData()[0]), len);
}
-void LASStorageManager::storeByteArray(SpatialIndex::id_type& id, const size_t len, const uint8_t* const data)
+void VLRStorageManager::storeByteArray(SpatialIndex::id_type& id, const size_t len, const uint8_t* const data)
{
+
if (id == SpatialIndex::StorageManager::NewPage)
{
- Entry* e = new Entry(len, data);
+ LASVariableRecord* v = makeVLR(len,data);
if (m_emptyPages.empty())
{
- m_buffer.push_back(e);
- id = m_buffer.size() - 1;
+ m_vlrbuffer.push_back(v);
+ id = m_vlrbuffer.size() - 1;
}
else
{
id = m_emptyPages.top(); m_emptyPages.pop();
- m_buffer[id] = e;
+ m_vlrbuffer[id] = v;
}
}
else
{
- Entry* e_old;
+ LASVariableRecord* v_old;
try
{
- e_old = m_buffer.at(id);
- if (e_old == 0) throw Tools::InvalidPageException(id);
+ v_old = m_vlrbuffer.at(id);
+ if (v_old == 0) throw Tools::InvalidPageException(id);
}
catch (std::out_of_range)
{
throw Tools::InvalidPageException(id);
}
- Entry* e = new Entry(len, data);
-
- delete e_old;
- m_buffer[id] = e;
+ LASVariableRecord* v = makeVLR(len,data);
+
+ delete v_old;
+ m_vlrbuffer[id] = v;
}
}
-void LASStorageManager::deleteByteArray(const SpatialIndex::id_type id)
+void VLRStorageManager::deleteByteArray(const SpatialIndex::id_type id)
{
- Entry* e;
+ LASVariableRecord* v;
try
{
- e = m_buffer.at(id);
- if (e == 0) throw Tools::InvalidPageException(id);
+ v = m_vlrbuffer.at(id);
+ if (v == 0) throw Tools::InvalidPageException(id);
}
catch (std::out_of_range)
{
throw Tools::InvalidPageException(id);
}
- m_buffer[id] = 0;
+ m_vlrbuffer[id] = 0;
m_emptyPages.push(id);
- delete e;
+ delete v;
}
-
+LASVariableRecord* VLRStorageManager::makeVLR(const size_t len, const uint8_t* data)
+{
+ LASVariableRecord* v = new LASVariableRecord();
+ v->SetRecordLength(len);
+ v->SetUserId("liblas.org");
+ v->SetRecordId(2112);
+ std::vector<uint8_t> d;
+ for (size_t i=0;i<len;i++){d.push_back(data[i]);}
+ v->SetData(d);
+ return v;
+}
} // namespace liblas
\ No newline at end of file
More information about the Liblas-commits
mailing list