[Liblas-commits] hg: 2 new changesets
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Dec 17 12:14:44 EST 2010
changeset e14aba667e5a in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=e14aba667e5a
summary: typos
changeset bc1a553d5a88 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=bc1a553d5a88
summary: add the ability for lasblock to write out blocked LAS files with the --write-points switch
diffstat:
apps/CMakeLists.txt | 2 +-
apps/las2las.cpp | 8 +-
apps/lasblock.cpp | 288 ++++++++++++++++++++++++++++++++++-----------------
3 files changed, 197 insertions(+), 101 deletions(-)
diffs (truncated from 376 to 300 lines):
diff -r 701bdd07631d -r bc1a553d5a88 apps/CMakeLists.txt
--- a/apps/CMakeLists.txt Fri Dec 17 10:10:47 2010 -0600
+++ b/apps/CMakeLists.txt Fri Dec 17 11:14:33 2010 -0600
@@ -144,7 +144,7 @@
# Build lasblock
if(LASBLOCK)
- set(LASBLOCK_SRC lasblock.cpp )
+ set(LASBLOCK_SRC lasblock.cpp laskernel.cpp)
add_executable(${LASBLOCK} ${LASBLOCK_SRC})
target_link_libraries(${LASBLOCK} ${APPS_CPP_DEPENDENCIES} )
endif()
diff -r 701bdd07631d -r bc1a553d5a88 apps/las2las.cpp
--- a/apps/las2las.cpp Fri Dec 17 10:10:47 2010 -0600
+++ b/apps/las2las.cpp Fri Dec 17 11:14:33 2010 -0600
@@ -222,9 +222,9 @@
oss << options;
- oss <<"\nFor more information, see the full documentation for las2las2 at:\n";
+ oss <<"\nFor more information, see the full documentation for las2las at:\n";
- oss << " http://liblas.org/utilities/las2las2.html\n";
+ oss << " http://liblas.org/utilities/las2las.html\n";
oss << "----------------------------------------------------------\n";
}
@@ -247,7 +247,7 @@
try {
- po::options_description file_options("las2las2 options");
+ po::options_description file_options("las2las options");
po::options_description filtering_options = GetFilteringOptions();
po::options_description header_options = GetHeaderOptions();
po::options_description transform_options = GetTransformationOptions() ;
@@ -352,4 +352,4 @@
}
-//las2las2 -i lt_srs_rt.las -o foo.las -c 1,2 -b 2483590,366208,2484000,366612
+//las2las -i lt_srs_rt.las -o foo.las -c 1,2 -b 2483590,366208,2484000,366612
diff -r 701bdd07631d -r bc1a553d5a88 apps/lasblock.cpp
--- a/apps/lasblock.cpp Fri Dec 17 10:10:47 2010 -0600
+++ b/apps/lasblock.cpp Fri Dec 17 11:14:33 2010 -0600
@@ -11,6 +11,7 @@
//
#include <liblas/liblas.hpp>
#include <liblas/chipper.hpp>
+#include "laskernel.hpp"
// std
#include <fstream>
@@ -36,127 +37,127 @@
#define compare_no_case(a,b,n) strncasecmp( (a), (b), (n) )
#endif
-bool term_progress(std::ostream& os, double complete)
+typedef boost::shared_ptr<liblas::Writer> WriterPtr;
+typedef boost::shared_ptr<liblas::Summary> SummaryPtr;
+typedef boost::shared_ptr<std::ofstream> OStreamPtr;
+
+WriterPtr start_writer( OStreamPtr strm,
+ std::string const& output,
+ liblas::Header const& header)
{
- static int lastTick = -1;
- int tick = static_cast<int>(complete * 40.0);
-
- tick = std::min(40, std::max(0, tick));
-
- // Have we started a new progress run?
- if (tick < lastTick && lastTick >= 39)
- lastTick = -1;
-
- if (tick <= lastTick)
- return true;
-
- while (tick > lastTick)
+
+ if (!liblas::Create(*strm, output.c_str()))
{
- lastTick++;
- if (lastTick % 4 == 0)
- os << (lastTick / 4) * 10;
- else
- os << ".";
+ std::ostringstream oss;
+ oss << "Cannot create " << output << "for write. Exiting...";
+ throw std::runtime_error(oss.str());
}
- if( tick == 40 )
- os << " - done.\n";
- else
- os.flush();
-
- return true;
+ WriterPtr writer( new liblas::Writer(*strm, header));
+ return writer;
+
}
using namespace liblas;
+void OutputHelp( std::ostream & oss, po::options_description const& options)
+{
+ oss << "--------------------------------------------------------------------\n";
+ oss << " lasblock (" << GetFullVersion() << ")\n";
+ oss << "--------------------------------------------------------------------\n";
-int main(int argc, char* argv[])
+ oss << options;
+
+ oss <<"\nFor more information, see the full documentation for lasblock at:\n";
+
+ oss << " http://liblas.org/utilities/block.html\n";
+ oss << "----------------------------------------------------------\n";
+
+}
+
+
+void write_tiles(std::string& output,
+ liblas::chipper::Chipper& c,
+ liblas::Reader& reader,
+ bool verbose)
{
- std::string input;
- std::string output;
-
- long capacity = 3000;
- long precision = 8;
- bool verbose = false;
- po::options_description desc("Allowed lasblock options");
- po::positional_options_description p;
- p.add("input", 1);
- p.add("output", 1);
-
- desc.add_options()
- ("help,h", "Produce this help message")
- ("capacity,c", po::value<long>(&capacity)->default_value(3000), "Number of points to nominally put into each block (note that this number will not be exact)")
- ("precision,p", po::value<long>(&precision)->default_value(8), "Number of decimal points to write for each bbox")
- ("input,i", po::value< std::string >(), "input LAS file")
- ("output,o", po::value< std::string >(&output)->default_value(""), "The output .kdx file (defaults to input filename + .kdx)")
- ("verbose,v", po::value<bool>(&verbose)->zero_tokens(), "Verbose message output")
-
- ;
-
- po::variables_map vm;
- po::store(po::command_line_parser(argc, argv).
- options(desc).positional(p).run(), vm);
-
- po::notify(vm);
-
- if (vm.count("help"))
- {
- std::cout << desc << "\n";
- std::cout <<"\nFor more information, see the full documentation for lasblock at:\n";
-
- std::cout << " http://liblas.org/utilities/block.html\n";
- std::cout << "----------------------------------------------------------\n";
- return 1;
- }
-
- if (vm.count("input"))
- {
- input = vm["input"].as< std::string >();
- std::ifstream ifs;
-
- if (!liblas::Open(ifs, input.c_str()))
- {
- std::cerr << "Cannot open file '" << input << "'for read. Exiting...";
- return 1;
- }
- }
+ std::string out = output;
- if (output.empty())
+
+
+ liblas::Header header = reader.GetHeader();
+
+ std::string::size_type dot_pos = output.find_first_of(".");
+ out = output.substr(0, dot_pos);
+
+
+ if (verbose)
+ std::cout << "Writing " << c.GetBlockCount() << " blocks to " << output << std::endl;
+
+ boost::uint32_t prog = 0;
+
+ for ( boost::uint32_t i = 0; i < c.GetBlockCount(); ++i )
{
- output = std::string(input) + ".kdx";
+ OStreamPtr ofs(new std::ofstream);
+ SummaryPtr summary(new::liblas::Summary);
+
+ std::ostringstream name;
+ name << out << "-" << i <<".las";
+
+ const liblas::chipper::Block& b = c.GetBlock(i);
+ header.SetExtent(b.GetBounds());
+
+ WriterPtr writer = start_writer(ofs, name.str(), header);
+
+
+
+ std::vector<boost::uint32_t> ids = b.GetIDs();
+
+
+ for ( boost::uint32_t pi = 0; pi < ids.size(); ++pi )
+ {
+ bool read = reader.ReadPointAt(pi);
+ if (read) {
+ liblas::Point const& p = reader.GetPoint();
+ summary->AddPoint(p);
+ writer->WritePoint(p);
+ }
+ }
+
+
+ writer = WriterPtr();
+ ofs = OStreamPtr();
+
+ liblas::Header hnew = FetchHeader(name.str());
+ RepairHeader(*summary, hnew);
+ RewriteHeader(hnew, name.str());
+
+ if (verbose)
+ term_progress(std::cout, (prog + 1) / static_cast<double>(c.GetBlockCount()));
+ prog++;
}
- std::ifstream in;
- if (!liblas::Open(in, input.c_str()))
- {
- std::cerr << "Cannot open " << input << "for read. Exiting...";
- return 1;
- }
-
+}
+void write_index(std::string& output,
+ liblas::chipper::Chipper& c,
+ liblas::Reader& reader,
+ long precision,
+ bool verbose)
+{
std::ofstream out(output.c_str());
-
- liblas::Reader reader( in );
-
- liblas::chipper::Chipper c(&reader, capacity);
-
- if (verbose)
- std::cout << "Blocking " << input<< " to " << output <<std::endl;
-
- c.Chip();
-
-
+
boost::uint32_t num_blocks = c.GetBlockCount();
if (verbose)
- std::cout << "Writing " << num_blocks << " blocks to " << output << std::endl;
+ std::cout << "Writing " << c.GetBlockCount() << " blocks to " << output << std::endl;
boost::uint32_t prog = 0;
- for ( boost::uint32_t i = 0; i < num_blocks; ++i )
+ for ( boost::uint32_t i = 0; i < c.GetBlockCount(); ++i )
{
const liblas::chipper::Block& b = c.GetBlock(i);
@@ -183,3 +184,98 @@
prog++;
}
}
+int main(int argc, char* argv[])
+{
+ std::string input;
+ std::string output;
+
+ long capacity = 3000;
+ long precision = 8;
+ bool verbose = false;
+ bool tiling = false;
+
+
+ po::options_description desc("Allowed lasblock options");
+ po::positional_options_description p;
+ p.add("input", 1);
+ p.add("output", 1);
+
+ desc.add_options()
+ ("help,h", "Produce this help message")
+ ("capacity,c", po::value<long>(&capacity)->default_value(3000), "Number of points to nominally put into each block (note that this number will not be exact)")
More information about the Liblas-commits
mailing list