Changeset 1202:a60e8617562a
- Timestamp:
- 05/16/09 20:37:32 (15 months ago)
- Branch:
- default
- Convert:
- svn:1766ff46-f334-0410-ab20-d63176f87757/trunk@1267
- Files:
-
- 2 edited
-
include/liblas/lasindex.hpp (modified) (3 diffs)
-
src/lasindex.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
include/liblas/lasindex.hpp
r1200 r1202 46 46 #include <liblas/laspoint.hpp> 47 47 48 49 #ifdef HAVE_SPATIALINDEX50 48 #include <spatialindex/SpatialIndex.h> 51 52 #endif53 49 54 50 … … 139 135 }; 140 136 141 } // namespace liblas142 143 namespace SpatialIndex144 {145 146 147 namespace StorageManager148 {149 extern IStorageManager* returnLASStorageManager(Tools::PropertySet& in);150 extern IStorageManager* createNewLASStorageManager();151 152 class LASStorageManager : public SpatialIndex::IStorageManager153 {154 public:155 LASStorageManager(Tools::PropertySet&);156 157 virtual ~LASStorageManager();158 159 virtual void loadByteArray(const id_type id, size_t& len, uint8_t** data);160 virtual void storeByteArray(id_type& id, const size_t len, const uint8_t* const data);161 virtual void deleteByteArray(const id_type id);162 163 private:164 class Entry165 {166 public:167 byte* m_pData;168 size_t m_length;169 170 Entry(size_t l, const uint8_t* const d) : m_pData(0), m_length(l)171 {172 m_pData = new uint8_t[m_length];173 memcpy(m_pData, d, m_length);174 }175 176 ~Entry() { delete[] m_pData; }177 }; // Entry178 179 std::vector<Entry*> m_buffer;180 std::stack<id_type> m_emptyPages;181 }; // MemoryStorageManager182 }183 }184 185 namespace liblas186 {187 137 class LASDataStream : public SpatialIndex::IDataStream 188 138 { … … 202 152 203 153 bool readPoint(); 154 155 protected: 204 156 liblas::LASReader* m_reader; 205 157 SpatialIndex::RTree::Data* m_pNext; 206 158 SpatialIndex::id_type m_id; 207 159 }; 160 161 162 163 164 extern SpatialIndex::IStorageManager* returnLASStorageManager(Tools::PropertySet& in); 165 extern SpatialIndex::IStorageManager* createNewLASStorageManager(); 166 167 class LASStorageManager : public SpatialIndex::IStorageManager 168 { 169 public: 170 LASStorageManager(Tools::PropertySet&); 171 172 virtual ~LASStorageManager(); 173 174 virtual void loadByteArray(const SpatialIndex::id_type id, size_t& len, uint8_t** data); 175 virtual void storeByteArray(SpatialIndex::id_type& id, const size_t len, const uint8_t* const data); 176 virtual void deleteByteArray(const SpatialIndex::id_type id); 177 178 private: 179 class Entry 180 { 181 public: 182 byte* m_pData; 183 size_t m_length; 184 185 Entry(size_t l, const uint8_t* const d) : m_pData(0), m_length(l) 186 { 187 m_pData = new uint8_t[m_length]; 188 memcpy(m_pData, d, m_length); 189 } 190 191 ~Entry() { delete[] m_pData; } 192 }; // Entry 193 194 std::vector<Entry*> m_buffer; 195 std::stack<SpatialIndex::id_type> m_emptyPages; 196 }; // MemoryStorageManager 197 198 208 199 } 209 200 -
src/lasindex.cpp
r1200 r1202 58 58 LASIndex::LASIndex() 59 59 { 60 m_storage = SpatialIndex::StorageManager::createNewLASStorageManager();60 m_storage = createNewLASStorageManager(); 61 61 Init(); 62 62 } … … 112 112 std::cout << "error creating index" << s <<std::endl; exit(1); 113 113 } 114 }114 } 115 115 116 116 Init(); … … 188 188 189 189 190 } // namespace liblas 191 192 193 194 195 SpatialIndex::IStorageManager* SpatialIndex::StorageManager::returnLASStorageManager(Tools::PropertySet& ps) 196 { 197 IStorageManager* sm = new LASStorageManager(ps); 198 return sm; 199 } 200 201 SpatialIndex::IStorageManager* SpatialIndex::StorageManager::createNewLASStorageManager() 202 { 203 Tools::PropertySet ps; 204 return returnLASStorageManager(ps); 205 } 206 207 SpatialIndex::StorageManager::LASStorageManager::LASStorageManager(Tools::PropertySet& ps) 208 { 209 } 210 211 SpatialIndex::StorageManager::LASStorageManager::~LASStorageManager() 212 { 213 for (std::vector<Entry*>::iterator it = m_buffer.begin(); it != m_buffer.end(); it++) delete *it; 214 } 215 216 void SpatialIndex::StorageManager::LASStorageManager::loadByteArray(const id_type id, size_t& len, uint8_t** data) 217 { 218 Entry* e; 219 try 220 { 221 e = m_buffer.at(id); 222 if (e == 0) throw Tools::InvalidPageException(id); 223 } 224 catch (std::out_of_range) 225 { 226 throw Tools::InvalidPageException(id); 227 } 228 229 len = e->m_length; 230 *data = new uint8_t[len]; 231 232 memcpy(*data, e->m_pData, len); 233 } 234 235 void SpatialIndex::StorageManager::LASStorageManager::storeByteArray(id_type& id, const size_t len, const uint8_t* const data) 236 { 237 if (id == NewPage) 238 { 239 Entry* e = new Entry(len, data); 240 241 if (m_emptyPages.empty()) 242 { 243 m_buffer.push_back(e); 244 id = m_buffer.size() - 1; 245 } 246 else 247 { 248 id = m_emptyPages.top(); m_emptyPages.pop(); 249 m_buffer[id] = e; 250 } 251 } 252 else 253 { 254 Entry* e_old; 255 try 256 { 257 e_old = m_buffer.at(id); 258 if (e_old == 0) throw Tools::InvalidPageException(id); 259 } 260 catch (std::out_of_range) 261 { 262 throw Tools::InvalidPageException(id); 263 } 264 265 Entry* e = new Entry(len, data); 266 267 delete e_old; 268 m_buffer[id] = e; 269 } 270 } 271 272 void SpatialIndex::StorageManager::LASStorageManager::deleteByteArray(const id_type id) 273 { 274 Entry* e; 275 try 276 { 277 e = m_buffer.at(id); 278 if (e == 0) throw Tools::InvalidPageException(id); 279 } 280 catch (std::out_of_range) 281 { 282 throw Tools::InvalidPageException(id); 283 } 284 285 m_buffer[id] = 0; 286 m_emptyPages.push(id); 287 288 delete e; 289 } 290 291 292 namespace liblas 293 { 190 191 192 193 SpatialIndex::IStorageManager* returnLASStorageManager(Tools::PropertySet& ps) 194 { 195 SpatialIndex::IStorageManager* sm = new LASStorageManager(ps); 196 return sm; 197 } 198 199 SpatialIndex::IStorageManager* createNewLASStorageManager() 200 { 201 Tools::PropertySet ps; 202 return returnLASStorageManager(ps); 203 } 204 205 LASStorageManager::LASStorageManager(Tools::PropertySet& ps) 206 { 207 } 208 209 LASStorageManager::~LASStorageManager() 210 { 211 for (std::vector<Entry*>::iterator it = m_buffer.begin(); it != m_buffer.end(); it++) delete *it; 212 } 213 214 void LASStorageManager::loadByteArray(const SpatialIndex::id_type id, size_t& len, uint8_t** data) 215 { 216 Entry* e; 217 try 218 { 219 e = m_buffer.at(id); 220 if (e == 0) throw Tools::InvalidPageException(id); 221 } 222 catch (std::out_of_range) 223 { 224 throw Tools::InvalidPageException(id); 225 } 226 227 len = e->m_length; 228 *data = new uint8_t[len]; 229 230 memcpy(*data, e->m_pData, len); 231 } 232 233 void LASStorageManager::storeByteArray(SpatialIndex::id_type& id, const size_t len, const uint8_t* const data) 234 { 235 if (id == SpatialIndex::StorageManager::NewPage) 236 { 237 Entry* e = new Entry(len, data); 238 239 if (m_emptyPages.empty()) 240 { 241 m_buffer.push_back(e); 242 id = m_buffer.size() - 1; 243 } 244 else 245 { 246 id = m_emptyPages.top(); m_emptyPages.pop(); 247 m_buffer[id] = e; 248 } 249 } 250 else 251 { 252 Entry* e_old; 253 try 254 { 255 e_old = m_buffer.at(id); 256 if (e_old == 0) throw Tools::InvalidPageException(id); 257 } 258 catch (std::out_of_range) 259 { 260 throw Tools::InvalidPageException(id); 261 } 262 263 Entry* e = new Entry(len, data); 264 265 delete e_old; 266 m_buffer[id] = e; 267 } 268 } 269 270 void LASStorageManager::deleteByteArray(const SpatialIndex::id_type id) 271 { 272 Entry* e; 273 try 274 { 275 e = m_buffer.at(id); 276 if (e == 0) throw Tools::InvalidPageException(id); 277 } 278 catch (std::out_of_range) 279 { 280 throw Tools::InvalidPageException(id); 281 } 282 283 m_buffer[id] = 0; 284 m_emptyPages.push(id); 285 286 delete e; 287 } 288 294 289 295 290
Note: See TracChangeset
for help on using the changeset viewer.
