[Liblas-commits] r1298 - in trunk: . apps include/liblas
include/liblas/index src src/index
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Jun 17 12:18:58 EDT 2009
Author: hobu
Date: Wed Jun 17 12:18:57 2009
New Revision: 1298
URL: http://liblas.org/changeset/1298
Log:
boost streams, start on index compression
Modified:
trunk/apps/lasindex.cpp
trunk/configure.ac
trunk/include/liblas/index/index.hpp
trunk/include/liblas/index/storage.hpp
trunk/include/liblas/lasvariablerecord.hpp
trunk/src/index/index.cpp
trunk/src/index/storage.cpp
trunk/src/lasvariablerecord.cpp
Modified: trunk/apps/lasindex.cpp
==============================================================================
--- trunk/apps/lasindex.cpp (original)
+++ trunk/apps/lasindex.cpp Wed Jun 17 12:18:57 2009
@@ -6,12 +6,29 @@
#include <liblas/lascolor.hpp>
#include <liblas/lasreader.hpp>
#include <liblas/lasheader.hpp>
+#include <liblas/lasvariablerecord.hpp>
#include <liblas/index/index.hpp>
+#ifdef HAVE_BOOST_API
+#include <boost/iostreams/filter/zlib.hpp>
+#include <boost/iostreams/filtering_streambuf.hpp>
+#include <boost/iostreams/filtering_stream.hpp>
+#include <boost/iostreams/device/array.hpp>
+#include <boost/iostreams/device/back_inserter.hpp>
+#include <boost/iostreams/copy.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/format.hpp>
+#endif
+
+#ifdef HAVE_SPATIALINDEX
+#include <spatialindex/SpatialIndex.h>
+#endif
#include <iostream>
+#include <iterator>
#include <fstream>
#include <vector>
+#include <sstream>
#ifdef _WIN32
#define compare_no_case(a,b,n) _strnicmp( (a), (b), (n) )
@@ -108,19 +125,49 @@
LASReader* reader = new LASReader(*istrm);
+// LASIndexDataStream* idxstrm = new LASIndexDataStream(reader);
+//
+// LASIndex* index = new LASIndex( input);
+// index->Initialize(*idxstrm);
+//
+// delete idxstrm;
+// delete index;
+// delete reader;
+// delete istrm;
+//
+// LASIndex* idx = new LASIndex(input);
+//
+// idx->Initialize();
+// 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 = idx->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);
+// }
+//
+//
+// if (ids != 0) delete ids;
+// if (idx != 0) delete idx;
+
+
LASIndexDataStream* idxstrm = new LASIndexDataStream(reader);
- LASIndex* index = new LASIndex( input);
- index->Initialize(*idxstrm);
-
- delete idxstrm;
- delete index;
- delete reader;
- delete istrm;
- LASIndex* idx = new LASIndex(input);
-
- idx->Initialize();
+ std::string nothing = std::string("");
+ LASIndex* idx = new LASIndex(nothing);
+ idx->SetType(LASIndex::eMemoryIndex);
+ idx->Initialize(*idxstrm);
std::vector<liblas::uint32_t>* ids = 0;
try{
@@ -139,8 +186,51 @@
std::cout << "error querying index value" << s <<std::endl; exit(1);
}
+ //
+ // if (ids != 0) delete ids;
+ // if (idx != 0) delete idx;
+ // idx = 0;
+ //
+ namespace io = boost::iostreams;
+
+ // io::filtering_ostream ofilter;
+ // std::stringstream junk;
+
+ // std::vector<liblas::uint8_t> compressed;
+
+ std::string compressed;
+ io::filtering_streambuf<io::output> ofilter;
+ ofilter.push(io::zlib_compressor());
+ ofilter.push(back_inserter(compressed));
- if (ids != 0) delete ids;
- if (idx != 0) delete idx;
+ LASVariableRecord *vlr = idx->GetVLR();
+
+ std::string data("some junkdsfasdfasdfqwerasdfasdfasdfasdfasdfweradsfasdfasdfasdfasdfasdqwerasdfasdfasdfasdfqwerasdfasdfv");
+ std::cout << "uncompressed size " << data.size() << std::endl;
+
+ io::copy(boost::make_iterator_range(data),ofilter);
+
+ // std::vector<liblas::uint8_t>& d= *(vlr->GetData());
+ // io::copy(boost::make_iterator_range(d.begin(), d.end()),ofilter);
+
+ std::cout << "compressed size " << compressed.size() << std::endl;
+ //
+ // ofilter.push(io::zlib_compressor());
+ // ofilter.push(back_inserter(compressed));
+ //
+ // LASVariableRecord *vlr = idx->GetVLR();
+ // std::cout << "VLR length: " << vlr->GetRecordLength() << std::endl;
+ //
+ // ofilter << "some junkdsfasdfasdfqwerasdfv";
+ //
+ // // ofilter << *vlr;
+ // std::cout << "stream size: " << ofilter.size() << std::endl;
+ //
+ // ofilter.flush();
+ //
+ // std::cout << "compressed size: " << compressed.size() << std::endl;
+ //
+ //
+ //
}
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Wed Jun 17 12:18:57 2009
@@ -280,7 +280,7 @@
if test "${HAVE_BOOST}" == "" ; then
HAVE_BOOST="yes"
- LIBS="$BOOST_LDFLAGS $LIBS"
+ LIBS="$BOOST_LDFLAGS -lboost_iostreams $LIBS"
fi
Modified: trunk/include/liblas/index/index.hpp
==============================================================================
--- trunk/include/liblas/index/index.hpp (original)
+++ trunk/include/liblas/index/index.hpp Wed Jun 17 12:18:57 2009
@@ -123,6 +123,8 @@
/// \return index type.
IndexType GetType() { return m_idxType; }
+ LASVariableRecord* GetVLR();
+
private:
SpatialIndex::IStorageManager* m_storage;
Modified: trunk/include/liblas/index/storage.hpp
==============================================================================
--- trunk/include/liblas/index/storage.hpp (original)
+++ trunk/include/liblas/index/storage.hpp Wed Jun 17 12:18:57 2009
@@ -73,6 +73,8 @@
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);
+
+ LASVariableRecord* getVLR() const;
private:
Modified: trunk/include/liblas/lasvariablerecord.hpp
==============================================================================
--- trunk/include/liblas/lasvariablerecord.hpp (original)
+++ trunk/include/liblas/lasvariablerecord.hpp Wed Jun 17 12:18:57 2009
@@ -121,41 +121,44 @@
/// Get the total size of the VLR in bytes
uint32_t GetTotalSize() const;
-
- friend std::ostream& operator << ( std::ostream& out, LASVariableRecord const& d)
- {
- // std::vector<uint8_t> data = d.GetData();
- for (size_t i=0;i<d.GetData().size();i++) {
- out << d.GetData()[i];
- }
- return out;
- }
- friend std::istream& operator >> ( std::istream& in, LASVariableRecord& d)
- {
- std::streampos input_pos = in.tellg();
- std::vector<uint8_t> data;
- in.seekg(0, std::ios::end);
- std::streampos length = in.tellg();
- in.seekg(input_pos, std::ios::beg);
-
- uint8_t* buffer = new uint8_t[length];
-
- liblas::detail::read_n(buffer, in, length);
-
- // FIXME: This has probably already been properly swapped?
- // but I'm worried about the case where we have a
- // stream that is really some sort of zlib or bzip stream
- // and we don't know the orientation of the bytes - hobu
- LIBLAS_SWAP_BYTES_N(buffer, length);
-
- for (size_t i=0; i < length; i++){
- data.push_back(buffer[i]);
- }
- delete buffer;
-
- d.SetData(data);
- return in;
- }
+
+ friend std::ostream& operator << ( std::ostream& out, LASVariableRecord const& d);
+ friend std::istream& operator >> ( std::istream& in, LASVariableRecord& d);
+ // friend std::ostream& operator << ( std::ostream& out, LASVariableRecord const& d)
+ // {
+ // // std::vector<uint8_t> data = d.GetData();
+ // for (size_t i=0;i<d.GetData().size();i++) {
+ // out << d.GetData()[i];
+ // }
+ // return out;
+ // }
+ // friend std::istream& operator >> ( std::istream& in, LASVariableRecord& d)
+ // {
+ // std::streampos input_pos = in.tellg();
+ // std::vector<uint8_t> data;
+ // in.seekg(0, std::ios::end);
+ // std::streampos length = in.tellg();
+ // in.seekg(input_pos, std::ios::beg);
+ // std::cout << "Stream length: " << length << std::endl;
+ //
+ // uint8_t* buffer = new uint8_t[length];
+ //
+ // liblas::detail::read_n(buffer, in, length);
+ //
+ // // FIXME: This has probably already been properly swapped?
+ // // but I'm worried about the case where we have a
+ // // stream that is really some sort of zlib or bzip stream
+ // // and we don't know the orientation of the bytes - hobu
+ // LIBLAS_SWAP_BYTES_N(buffer, length);
+ //
+ // for (size_t i=0; i < length; i++){
+ // data.push_back(buffer[i]);
+ // }
+ // delete buffer;
+ //
+ // d.SetData(data);
+ // return in;
+ // }
private:
Modified: trunk/src/index/index.cpp
==============================================================================
--- trunk/src/index/index.cpp (original)
+++ trunk/src/index/index.cpp Wed Jun 17 12:18:57 2009
@@ -152,6 +152,13 @@
m_Initialized = true;
}
+
+LASVariableRecord* LASIndex::GetVLR()
+{
+ if (m_idxType == eMemoryIndex) { return static_cast<VLRStorageManager*>(m_storage)->getVLR();}
+ else
+ return new LASVariableRecord();
+}
SpatialIndex::ISpatialIndex* LASIndex::CreateIndex(LASIndexDataStream& strm)
{
using namespace SpatialIndex;
Modified: trunk/src/index/storage.cpp
==============================================================================
--- trunk/src/index/storage.cpp (original)
+++ trunk/src/index/storage.cpp Wed Jun 17 12:18:57 2009
@@ -171,5 +171,9 @@
return v;
}
+LASVariableRecord* VLRStorageManager::getVLR() const
+{
+ return m_vlrbuffer[0];
+}
} // namespace liblas
\ No newline at end of file
Modified: trunk/src/lasvariablerecord.cpp
==============================================================================
--- trunk/src/lasvariablerecord.cpp (original)
+++ trunk/src/lasvariablerecord.cpp Wed Jun 17 12:18:57 2009
@@ -217,5 +217,48 @@
return static_cast<uint32_t>(sum);
}
+std::ostream& operator << ( std::ostream& out, LASVariableRecord const& d)
+{
+ // std::vector<uint8_t> data = d.GetData();
+ std::streampos begin = out.tellp();
+ std::cout << "begin: " << begin << std::endl;
+ std::cout << "Dumping " << d.GetRecordLength() <<" bytes out for VLR" << "Size is : " << d.GetData().size() <<std::endl;
+ for (size_t i=0;i<d.GetData().size();i++) {
+ // out << d.GetData()[i];
+ }
+ out << &(d.GetData()[0]);
+ std::streampos end = out.tellp();
+ std::cout << "end: " << end << std::endl;
+
+ return out;
+}
+
+std::istream& operator >> ( std::istream& in, LASVariableRecord& d)
+{
+ std::streampos input_pos = in.tellg();
+ std::vector<uint8_t> data;
+ in.seekg(0, std::ios::end);
+ std::streampos length = in.tellg();
+ in.seekg(input_pos, std::ios::beg);
+ std::cout << "Stream length: " << length << std::endl;
+
+ uint8_t* buffer = new uint8_t[length];
+
+ liblas::detail::read_n(buffer, in, length);
+
+ // FIXME: This has probably already been properly swapped?
+ // but I'm worried about the case where we have a
+ // stream that is really some sort of zlib or bzip stream
+ // and we don't know the orientation of the bytes - hobu
+ LIBLAS_SWAP_BYTES_N(buffer, length);
+
+ for (size_t i=0; i < length; i++){
+ data.push_back(buffer[i]);
+ }
+ delete buffer;
+
+ d.SetData(data);
+ return in;
+}
} // namespace liblas
More information about the Liblas-commits
mailing list