[Liblas-commits] hg: switch to reader factory,
to support zippified files
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Dec 24 16:05:30 EST 2010
details: http://hg.liblas.orghg/rev/525e591365b6
changeset: 2641:525e591365b6
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Dec 24 12:17:33 2010 -0800
description:
switch to reader factory, to support zippified files
Subject: hg: fix scoping issue, so dtor can write the stream
details: http://hg.liblas.orghg/rev/d1651ff80146
changeset: 2642:d1651ff80146
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Dec 24 12:20:46 2010 -0800
description:
fix scoping issue, so dtor can write the stream
Subject: hg: another missing facvtory usage
details: http://hg.liblas.orghg/rev/7ac404a1357c
changeset: 2643:7ac404a1357c
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Dec 24 12:23:55 2010 -0800
description:
another missing facvtory usage
Subject: hg: guard against not using the factory
details: http://hg.liblas.orghg/rev/d8abc651ff00
changeset: 2644:d8abc651ff00
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Dec 24 12:24:42 2010 -0800
description:
guard against not using the factory
Subject: hg: guard against bad factories
details: http://hg.liblas.orghg/rev/77cf1db88f17
changeset: 2645:77cf1db88f17
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Dec 24 12:26:09 2010 -0800
description:
guard against bad factories
Subject: hg: flush out and close the output stream before we reopen it again to update the header
details: http://hg.liblas.orghg/rev/de0fbaccb564
changeset: 2646:de0fbaccb564
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Dec 24 12:32:35 2010 -0800
description:
flush out and close the output stream before we reopen it again to update the header
Subject: hg: don't do this -- it only causes unnecessary pain and suffering everytime a writer gets built, for any reason at all
details: http://hg.liblas.orghg/rev/803041b4603d
changeset: 2647:803041b4603d
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Dec 24 12:33:53 2010 -0800
description:
don't do this -- it only causes unnecessary pain and suffering everytime a writer gets built, for any reason at all
Subject: hg: renaming Header::IsCompressed
details: http://hg.liblas.orghg/rev/c5f71ed9f6fc
changeset: 2648:c5f71ed9f6fc
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Dec 24 12:51:59 2010 -0800
description:
renaming Header::IsCompressed
diffstat:
apps/las2las.cpp | 15 ++++++++-------
apps/las2txt.cpp | 6 ++++--
apps/laskernel.cpp | 15 ++++++++-------
include/liblas/header.hpp | 4 ++--
src/detail/reader/header.cpp | 4 ++--
src/detail/reader/reader.cpp | 8 +++++---
src/detail/reader/zipreader.cpp | 6 ++++++
src/detail/writer/header.cpp | 2 +-
src/detail/writer/zipwriter.cpp | 19 +++++++++++--------
src/factory.cpp | 4 ++--
src/header.cpp | 4 ++--
11 files changed, 51 insertions(+), 36 deletions(-)
diffs (268 lines):
diff -r 8f170797c7c5 -r c5f71ed9f6fc apps/las2las.cpp
--- a/apps/las2las.cpp Thu Dec 23 21:29:05 2010 -0600
+++ b/apps/las2las.cpp Fri Dec 24 12:51:59 2010 -0800
@@ -199,6 +199,12 @@
if (verbose)
std::cout << std::endl;
+ // cheap hackery. We need the Writer to disappear before the stream.
+ // Fix this up to not suck so bad.
+ writer = WriterPtr();
+ ofs->close();
+ ofs = OStreamPtr();
+
if (!split_mb && !split_pts) {
reader.Reset();
@@ -207,11 +213,6 @@
RewriteHeader(hnew, output);
}
- // cheap hackery. We need the Writer to disappear before the stream.
- // Fix this up to not suck so bad.
- writer = WriterPtr();
- ofs = OStreamPtr();
-
return true;
}
@@ -327,11 +328,11 @@
switch (WriterFactory::InferFileTypeFromExtension(output))
{
case WriterFactory::FileType_LAS:
- header.SetIsCompressed(false);
+ header.SetCompressed(false);
break;
case WriterFactory::FileType_LAZ:
#ifdef HAVE_LASZIP
- header.SetIsCompressed(true);
+ header.SetCompressed(true);
#else
throw std::runtime_error("Compression support not enabled in liblas configuration");
#endif
diff -r 8f170797c7c5 -r c5f71ed9f6fc apps/las2txt.cpp
--- a/apps/las2txt.cpp Thu Dec 23 21:29:05 2010 -0600
+++ b/apps/las2txt.cpp Fri Dec 24 12:51:59 2010 -0800
@@ -460,7 +460,8 @@
std::cerr << "Cannot open " << input << " for read. Exiting..." << std::endl;
return 1;
}
- liblas::Reader reader(ifs);
+ liblas::ReaderFactory f;
+ liblas::Reader reader = f.CreateWithStream(ifs);
header = reader.GetHeader();
} else {
std::cerr << "Input LAS file not specified!\n";
@@ -592,7 +593,8 @@
}
- liblas::Reader reader(ifs);
+ liblas::ReaderFactory f;
+ liblas::Reader reader = f.CreateWithStream(ifs);
write_points( reader,
*os,
diff -r 8f170797c7c5 -r c5f71ed9f6fc apps/laskernel.cpp
--- a/apps/laskernel.cpp Thu Dec 23 21:29:05 2010 -0600
+++ b/apps/laskernel.cpp Fri Dec 24 12:51:59 2010 -0800
@@ -119,22 +119,23 @@
}
void RewriteHeader(liblas::Header const& header, std::string const& filename)
{
-
std::ios::openmode m = std::ios::out | std::ios::in | std::ios::binary | std::ios::ate;
+ // Write a blank PointRecordsByReturnCount first
+ std::ofstream ofs(filename.c_str(), m);
{
- // Write a blank PointRecordsByReturnCount first
- std::ofstream ofs(filename.c_str(), m);
+ // scope this, so the dtor can write to the stream before we close it
liblas::Writer writer(ofs, header);
- ofs.close();
}
+ ofs.close();
+ // Write our updated header with summary info
+ std::ofstream ofs2(filename.c_str(), m);
{
- // Write our updated header with summary info
- std::ofstream ofs2(filename.c_str(), m);
+ // scope this, so the dtor can write to the stream before we close it
liblas::Writer writer2(ofs2, header);
- ofs2.close();
}
+ ofs2.close();
}
void RepairHeader(liblas::CoordinateSummary const& summary, liblas::Header& header)
diff -r 8f170797c7c5 -r c5f71ed9f6fc include/liblas/header.hpp
--- a/include/liblas/header.hpp Thu Dec 23 21:29:05 2010 -0600
+++ b/include/liblas/header.hpp Fri Dec 24 12:51:59 2010 -0800
@@ -351,10 +351,10 @@
/// Returns true iff the file is compressed (laszip),
/// as determined by the high bit in the point type
- bool IsCompressed() const;
+ bool Compressed() const;
/// Sets whether or not the points are compressed.
- void SetIsCompressed(bool b);
+ void SetCompressed(bool b);
void to_rst(std::ostream& os) const;
void to_xml(std::ostream& os) const;
diff -r 8f170797c7c5 -r c5f71ed9f6fc src/detail/reader/header.cpp
--- a/src/detail/reader/header.cpp Thu Dec 23 21:29:05 2010 -0600
+++ b/src/detail/reader/header.cpp Fri Dec 24 12:51:59 2010 -0800
@@ -162,7 +162,7 @@
if (n1 >> 7)
{
- m_header->SetIsCompressed(true);
+ m_header->SetCompressed(true);
n1 &= 0x7f;
}
@@ -311,7 +311,7 @@
std::ios::off_type remainder = point_bytes % length;
- if ( !m_header->IsCompressed() && m_header->GetPointRecordsCount() != static_cast<uint32_t>(count)) {
+ if ( !m_header->Compressed() && m_header->GetPointRecordsCount() != static_cast<uint32_t>(count)) {
if (remainder == 0)
{
// The point bytes are exactly long enough, let's use it
diff -r 8f170797c7c5 -r c5f71ed9f6fc src/detail/reader/reader.cpp
--- a/src/detail/reader/reader.cpp Thu Dec 23 21:29:05 2010 -0600
+++ b/src/detail/reader/reader.cpp Fri Dec 24 12:51:59 2010 -0800
@@ -132,11 +132,13 @@
m_header_reader->read();
m_header = m_header_reader->GetHeader();
+
+ if (m_header->Compressed())
+ throw std::runtime_error("Internal error: uncompressed reader encountered compressed header");
+
m_point->SetHeaderPtr(m_header);
-
+
Reset();
-
-
}
void ReaderImpl::SetHeader(liblas::Header const& header)
diff -r 8f170797c7c5 -r c5f71ed9f6fc src/detail/reader/zipreader.cpp
--- a/src/detail/reader/zipreader.cpp Thu Dec 23 21:29:05 2010 -0600
+++ b/src/detail/reader/zipreader.cpp Fri Dec 24 12:51:59 2010 -0800
@@ -238,6 +238,9 @@
m_header_reader->read();
m_header = m_header_reader->GetHeader();
+ if (!m_header->Compressed())
+ throw std::runtime_error("Internal error: compressed reader encountered uncompressed header");
+
m_point->SetHeaderPtr(m_header);
Reset();
@@ -260,7 +263,10 @@
std::vector<boost::uint8_t> v(m_lz_point_size);
for (unsigned int i=0; i<m_lz_point_size; i++)
+ {
v[i] = m_lz_point_data[i];
+ //printf("%d %d\n", v[i], i);
+ }
m_point->SetData(v);
++m_current;
diff -r 8f170797c7c5 -r c5f71ed9f6fc src/detail/writer/header.cpp
--- a/src/detail/writer/header.cpp Thu Dec 23 21:29:05 2010 -0600
+++ b/src/detail/writer/header.cpp Fri Dec 24 12:51:59 2010 -0800
@@ -223,7 +223,7 @@
// 16. Point Data Format ID
n1 = static_cast<uint8_t>(m_header.GetDataFormatId());
uint8_t n1tmp = n1;
- if (m_header.IsCompressed())
+ if (m_header.Compressed())
n1tmp |= 0x80;
detail::write_n(m_ofs, n1tmp, sizeof(n1tmp));
diff -r 8f170797c7c5 -r c5f71ed9f6fc src/detail/writer/zipwriter.cpp
--- a/src/detail/writer/zipwriter.cpp Thu Dec 23 21:29:05 2010 -0600
+++ b/src/detail/writer/zipwriter.cpp Fri Dec 24 12:51:59 2010 -0800
@@ -178,7 +178,10 @@
const std::vector<boost::uint8_t>& v = point.GetData();
for (unsigned int i=0; i<m_lz_point_size; i++)
+ {
m_lz_point_data[i] = v[i];
+ //printf("%d %d\n", v[i], i);
+ }
bool ok = m_zipper->write(m_lz_point);
if (!ok)
@@ -191,14 +194,14 @@
{
// Try to update the point count on our way out, but we don't really
// care if we weren't able to write it.
- try
- {
- UpdatePointCount(0);
-
- } catch (std::runtime_error const&)
- {
-
- }
+ //try
+ //{
+ // UpdatePointCount(0);
+ //
+ //} catch (std::runtime_error const&)
+ //{
+ //
+ //}
delete m_zipper;
}
diff -r 8f170797c7c5 -r c5f71ed9f6fc src/factory.cpp
--- a/src/factory.cpp Thu Dec 23 21:29:05 2010 -0600
+++ b/src/factory.cpp Fri Dec 24 12:51:59 2010 -0800
@@ -83,7 +83,7 @@
h->read();
HeaderPtr header = h->GetHeader();
- if (header->IsCompressed())
+ if (header->Compressed())
{
#ifdef HAVE_LASZIP
ReaderIPtr r = ReaderIPtr(new detail::ZipReaderImpl(stream) );
@@ -107,7 +107,7 @@
WriterIPtr WriterFactory::CreateWithStream(std::ostream& stream, Header const& header)
{
- if (header.IsCompressed())
+ if (header.Compressed())
{
#ifdef HAVE_LASZIP
WriterIPtr w = WriterIPtr(new detail::ZipWriterImpl(stream));
diff -r 8f170797c7c5 -r c5f71ed9f6fc src/header.cpp
--- a/src/header.cpp Thu Dec 23 21:29:05 2010 -0600
+++ b/src/header.cpp Fri Dec 24 12:51:59 2010 -0800
@@ -691,12 +691,12 @@
}
-void Header::SetIsCompressed(bool b)
+void Header::SetCompressed(bool b)
{
m_isCompressed = b;
}
-bool Header::IsCompressed() const
+bool Header::Compressed() const
{
return m_isCompressed;
}
More information about the Liblas-commits
mailing list