[Liblas-commits] hg: 2 new changesets
liblas-commits at liblas.org
liblas-commits at liblas.org
Thu Sep 23 16:49:22 EDT 2010
changeset 94d90bf6842c in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=94d90bf6842c
summary: add a public utility dump bucket for things like liblas::Summary
changeset 27172e34ddff in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=27172e34ddff
summary: add repair feature using liblas::Summary -- now equivalent and 2x faster than las2las
diffstat:
apps/las2las2.cpp | 102 ++++++++++++++++------
include/liblas/liblas.hpp | 1 +
include/liblas/utility.hpp | 92 +++++++++++++++++++++
src/CMakeLists.txt | 2 +
src/lasreader.cpp | 159 +----------------------------------
src/utility.cpp | 197 +++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 372 insertions(+), 181 deletions(-)
diffs (truncated from 708 to 300 lines):
diff -r 28eddbd39147 -r 27172e34ddff apps/las2las2.cpp
--- a/apps/las2las2.cpp Thu Sep 23 12:27:49 2010 -0400
+++ b/apps/las2las2.cpp Thu Sep 23 15:49:11 2010 -0500
@@ -13,17 +13,8 @@
#include "laskernel.hpp"
#include <boost/cstdint.hpp>
+#include <boost/foreach.hpp>
-// #include <fstream>
-// #include <iostream>
-// #include <sstream>
-// #include <string>
-// #include <vector>
-// #include <string>
-// #include <functional>
-//
-// #include <boost/program_options.hpp>
-// #include <boost/tokenizer.hpp>
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
@@ -38,8 +29,6 @@
#define compare_no_case(a,b,n) strncasecmp( (a), (b), (n) )
#endif
-// #define SEPARATORS ",|"
-
bool term_progress(std::ostream& os, double complete)
{
static int lastTick = -1;
@@ -72,23 +61,16 @@
}
-
-
-
-
-
-
-
-
liblas::Writer* start_writer( std::ofstream* strm,
std::string const& output,
liblas::Header const& header)
{
if (!liblas::Create(*strm, output.c_str()))
-{
- std::cerr << "Cannot create " << output << "for write. Exiting...";
-
+ {
+ std::ostringstream oss;
+ oss << "Cannot create " << output << "for write. Exiting...";
+ throw std::runtime_error(oss.str());
}
liblas::Writer* writer = new liblas::Writer(*strm, header);
return writer;
@@ -96,6 +78,69 @@
}
+void RepairHeader(liblas::Summary const& summary, std::string const& filename)
+{
+ std::ifstream ifs;
+ if (!liblas::Open(ifs, filename.c_str()))
+ {
+ std::ostringstream oss;
+ oss << "Cannot open " << filename << "for read. Exiting...";
+ throw std::runtime_error(oss.str());
+ }
+ liblas::Reader reader(ifs);
+ liblas::Header header = reader.GetHeader();
+ ifs.close();
+
+ for (boost::uint32_t i = 0; i < 5; i++)
+ {
+ header.SetPointRecordsByReturnCount(i, 0);
+ }
+
+ std::ios::openmode m = std::ios::out | std::ios::in | std::ios::binary | std::ios::ate;
+
+ // Write a blank header first
+ std::ofstream ofs(filename.c_str(), m);
+ liblas::Writer writer(ofs, header);
+ ofs.close();
+
+ liblas::property_tree::ptree tree = summary.GetPTree();
+
+ try
+ {
+ header.SetMin(tree.get<double>("minimum.x"),
+ tree.get<double>("minimum.y"),
+ tree.get<double>("minimum.x"));
+
+ header.SetMax(tree.get<double>("maximum.x"),
+ tree.get<double>("maximum.y"),
+ tree.get<double>("maximum.x"));
+
+ for (boost::uint32_t i = 0; i < 5; i++)
+ {
+ header.SetPointRecordsByReturnCount(i, 0);
+ }
+
+ BOOST_FOREACH(ptree::value_type &v,
+ tree.get_child("points_by_return"))
+ {
+ boost::uint32_t i = v.second.get<boost::uint32_t>("id");
+ boost::uint32_t count = v.second.get<boost::uint32_t>("count");
+ header.SetPointRecordsByReturnCount(i-1, count);
+ }
+
+ } catch (liblas::property_tree::ptree_bad_path const& e)
+ {
+ std::cerr << "Unable to write summarized header info. Does the outputted file have any points?";
+ return;
+ }
+
+ // Write our updated header with summary info
+ std::ofstream ofs2(filename.c_str(), m);
+ liblas::Writer writer2(ofs2, header);
+ ofs2.close();
+
+}
+
bool process( std::string const& input,
std::string const& output,
liblas::Header const& header,
@@ -114,6 +159,7 @@
return false;
}
liblas::Reader reader(ifs);
+ liblas::Summary summary;
reader.SetFilters(filters);
reader.SetTransforms(transforms);
@@ -146,7 +192,8 @@
while (reader.ReadNextPoint())
{
- liblas::Point const& p = reader.GetPoint();
+ liblas::Point const& p = reader.GetPoint();
+ summary.AddPoint(p);
writer->WritePoint(p);
if (verbose)
term_progress(std::cout, (i + 1) / static_cast<double>(size));
@@ -175,7 +222,7 @@
std::cout << std::endl;
reader.Reset();
- liblas::property_tree::ptree pts = reader.Summarize();
+ liblas::property_tree::ptree pts = summary.GetPTree();
liblas::property_tree::ptree top;
top.add_child("summary.header",reader.GetHeader().GetPTree());
top.add_child("summary.points",pts);
@@ -186,6 +233,7 @@
delete writer;
delete ofs;
+ RepairHeader(summary, output);
return true;
}
@@ -235,9 +283,6 @@
("output,o", po::value< string >(&output)->default_value("output.las"), "output LAS file")
("verbose,v", po::value<bool>(&verbose)->zero_tokens(), "Verbose message output")
;
-
-
-
po::variables_map vm;
po::options_description options;
@@ -253,7 +298,6 @@
return 1;
}
-
if (vm.count("input"))
{
input = vm["input"].as< string >();
diff -r 28eddbd39147 -r 27172e34ddff include/liblas/liblas.hpp
--- a/include/liblas/liblas.hpp Thu Sep 23 12:27:49 2010 -0400
+++ b/include/liblas/liblas.hpp Thu Sep 23 15:49:11 2010 -0500
@@ -63,6 +63,7 @@
#include <liblas/lasvariablerecord.hpp>
#include <liblas/lasversion.hpp>
#include <liblas/laswriter.hpp>
+#include <liblas/utility.hpp>
#include <liblas/detail/endian.hpp>
#include <liblas/detail/utility.hpp>
#include <liblas/capi/las_version.h>
diff -r 28eddbd39147 -r 27172e34ddff include/liblas/utility.hpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/include/liblas/utility.hpp Thu Sep 23 15:49:11 2010 -0500
@@ -0,0 +1,92 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project: libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose: LAS filter class
+ * Author: Howard Butler, hobu.inc at gmail.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2010, Howard Butler
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of the Martin Isenburg or Iowa Department
+ * of Natural Resources nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ ****************************************************************************/
+
+#ifndef LIBLAS_LASSUMMARY_HPP_INCLUDED
+#define LIBLAS_LASSUMMARY_HPP_INCLUDED
+
+#include <liblas/lasheader.hpp>
+#include <liblas/laspoint.hpp>
+#include <liblas/detail/fwd.hpp>
+#include <liblas/external/property_tree/ptree.hpp>
+// boost
+#include <boost/cstdint.hpp>
+
+// std
+#include <vector>
+#include <functional>
+#include <string>
+
+using liblas::property_tree::ptree;
+typedef boost::array<boost::uint32_t, 32> classes_type;
+
+namespace liblas {
+
+/// A summarization utililty for LAS points
+class Summary
+{
+public:
+
+ Summary();
+ void AddPoint(liblas::Point const& p);
+ ptree GetPTree() const;
+
+private:
+
+ Summary(Summary const& other);
+ Summary& operator=(Summary const& rhs);
+
+
+ classes_type classes;
+ boost::uint32_t synthetic;
+ boost::uint32_t withheld;
+ boost::uint32_t keypoint;
+ boost::uint32_t count;
+ boost::array<boost::uint32_t, 8> points_by_return;
+ boost::array<boost::uint32_t, 8> returns_of_given_pulse;
+ bool first;
+ liblas::Point min;
+ liblas::Point max;
+};
+
+
+} // namespace liblas
+
+#endif // ndef LIBLAS_LASSUMMARY_HPP_INCLUDED
diff -r 28eddbd39147 -r 27172e34ddff src/CMakeLists.txt
--- a/src/CMakeLists.txt Thu Sep 23 12:27:49 2010 -0400
+++ b/src/CMakeLists.txt Thu Sep 23 15:49:11 2010 -0500
@@ -39,6 +39,7 @@
${LIBLAS_HEADERS_DIR}/lasversion.hpp
${LIBLAS_HEADERS_DIR}/laswriter.hpp
${LIBLAS_HEADERS_DIR}/liblas.hpp
+ ${LIBLAS_HEADERS_DIR}/utility.hpp
${LIBLAS_HEADERS_DIR}/version.hpp)
set(LIBLAS_EXTERNAL_HPP)
More information about the Liblas-commits
mailing list