[Liblas-commits] hg: segregate generic option handling into its own files to be r...

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Aug 12 12:11:08 EDT 2010


changeset a17bad855c63 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=a17bad855c63
summary: segregate generic option handling into its own files to be reused in other contexts than las2las

diffstat:

 apps/CMakeLists.txt |    6 +-
 apps/las2las2.cpp   |  569 +++------------------------------------------------
 apps/laskernel.cpp  |  561 +++++++++++++++++++++++++++++++++++++++++++++++++++
 apps/laskernel.hpp  |   82 +++++++
 4 files changed, 680 insertions(+), 538 deletions(-)

diffs (truncated from 1323 to 300 lines):

diff -r d7975db2a1a1 -r a17bad855c63 apps/CMakeLists.txt
--- a/apps/CMakeLists.txt	Wed Aug 11 13:32:14 2010 -0500
+++ b/apps/CMakeLists.txt	Thu Aug 12 11:11:02 2010 -0500
@@ -88,7 +88,7 @@
 endif()
 
 if(LAS2LAS2)
-    add_executable(${LAS2LAS2} las2las2.cpp)
+    add_executable(${LAS2LAS2} las2las2.cpp laskernel.cpp)
     target_link_libraries(${LAS2LAS2} ${APPS_CPP_DEPENDENCIES} ${Boost_LIBRARIES})
 endif()
 
@@ -128,8 +128,8 @@
 
 # Build las2oci
 if(LAS2OCI)
-    add_executable(${LAS2OCI} las2oci.cpp oci_wrapper.cpp kdx_util.cpp oci_util.cpp)
-    target_link_libraries(${LAS2OCI} ${APPS_CPP_DEPENDENCIES})
+    add_executable(${LAS2OCI} las2oci.cpp oci_wrapper.cpp kdx_util.cpp oci_util.cpp laskernel.cpp)
+    target_link_libraries(${LAS2OCI} ${APPS_CPP_DEPENDENCIES} ${Boost_LIBRARIES})
 endif()
 
 if (BIGFILE_TEST)
diff -r d7975db2a1a1 -r a17bad855c63 apps/las2las2.cpp
--- a/apps/las2las2.cpp	Wed Aug 11 13:32:14 2010 -0500
+++ b/apps/las2las2.cpp	Thu Aug 12 11:11:02 2010 -0500
@@ -10,17 +10,18 @@
  **************************************************************************/
 
 #include <liblas/liblas.hpp>
+#include "laskernel.hpp"
 
-#include <fstream>
-#include <iostream>
-#include <sstream>
-#include <string>
-#include <vector>
-#include <string>
-#include <functional>
-
-#include <boost/program_options.hpp>
-#include <boost/tokenizer.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;
 
@@ -35,7 +36,7 @@
 #define compare_no_case(a,b,n)  strncasecmp( (a), (b), (n) )
 #endif
 
-#define SEPARATORS ",|"
+// #define SEPARATORS ",|"
 
 bool term_progress(std::ostream& os, double complete)
 {
@@ -92,112 +93,6 @@
     
 }
 
-bool IsDualRangeFilter(std::string parse_string) 
-{
-
-string::size_type dash = parse_string.find_first_of("-");
-
-if (dash != std::string::npos) {
-    return true;
-}
-return false;
-}
-
-liblas::FilterI*  MakeReturnFilter(std::string return_string, liblas::FilterI::FilterType ftype) 
-{
-    boost::char_separator<char> sep(SEPARATORS);
-
-    std::vector<uint16_t> returns;
-    tokenizer tokens(return_string, sep);
-    for (tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t) {
-        returns.push_back(atoi((*t).c_str()));
-    }
-
-    liblas::ReturnFilter* return_filter = new ReturnFilter(returns, false);
-    return_filter->SetType(ftype);
-    return return_filter;
-}
-
-
-liblas::FilterI*  MakeClassFilter(std::string class_string, liblas::FilterI::FilterType ftype) 
-{
-    boost::char_separator<char> sep(SEPARATORS);
-
-    std::vector<uint8_t> classes;
-    tokenizer tokens(class_string, sep);
-    for (tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t) {
-        classes.push_back(atoi((*t).c_str()));
-    }
-
-    liblas::ClassificationFilter* class_filter = new ClassificationFilter(classes); 
-    class_filter->SetType(ftype);
-    return class_filter;
-}
-
-liblas::FilterI*  MakeBoundsFilter(std::string bounds_string, liblas::FilterI::FilterType ftype) 
-{
-    boost::char_separator<char> sep(SEPARATORS);
-    std::vector<double> vbounds;
-    tokenizer tokens(bounds_string, sep);
-    liblas::Bounds<double> bounds;
-    for (tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t) {
-        vbounds.push_back(atof((*t).c_str()));
-    }
-    if (vbounds.size() == 4) 
-    {
-        bounds = liblas::Bounds<double>(vbounds[0], 
-                                vbounds[1], 
-                                vbounds[2], 
-                                vbounds[3]);
-    } else if (vbounds.size() == 6)
-    {
-        bounds = liblas::Bounds<double>(vbounds[0], 
-                                vbounds[1], 
-                                vbounds[2], 
-                                vbounds[3], 
-                                vbounds[4], 
-                                vbounds[5]);
-    } else {
-        ostringstream oss;
-        oss << "Bounds must be specified as a 4-tuple or "
-               "6-tuple, not a "<< vbounds.size()<<"-tuple" << "\n";
-        throw std::runtime_error(oss.str());
-    }
-    liblas::BoundsFilter* bounds_filter = new BoundsFilter(bounds);
-    bounds_filter->SetType(ftype);
-    return bounds_filter;
-}
-
-liblas::FilterI*  MakeIntensityFilter(std::string intensities, liblas::FilterI::FilterType ftype) 
-{
-    liblas::ContinuousValueFilter<uint16_t>::filter_func f = &liblas::Point::GetIntensity;
-    liblas::ContinuousValueFilter<uint16_t>* intensity_filter = new liblas::ContinuousValueFilter<uint16_t>(f, intensities);
-    intensity_filter->SetType(ftype);
-    return intensity_filter;
-}
-
-liblas::FilterI*  MakeTimeFilter(std::string times, liblas::FilterI::FilterType ftype) 
-{
-    liblas::ContinuousValueFilter<double>::filter_func f = &liblas::Point::GetTime;
-    liblas::ContinuousValueFilter<double>* time_filter = new liblas::ContinuousValueFilter<double>(f, times);
-    time_filter->SetType(ftype);
-    return time_filter;
-}
-
-liblas::FilterI*  MakeScanAngleFilter(std::string intensities, liblas::FilterI::FilterType ftype) 
-{
-    liblas::ContinuousValueFilter<int8_t>::filter_func f = &liblas::Point::GetScanAngleRank;
-    liblas::ContinuousValueFilter<int8_t>* intensity_filter = new liblas::ContinuousValueFilter<int8_t>(f, intensities);
-    intensity_filter->SetType(ftype);
-    return intensity_filter;
-}
-
-liblas::FilterI* MakeColorFilter(liblas::Color const& low, liblas::Color const& high, liblas::FilterI::FilterType ftype)
-{
-    liblas::ColorFilter* filter = new liblas::ColorFilter(low, high);
-    filter->SetType(ftype);
-    return filter;
-}
 
 bool process(   std::string const& input,
                 std::string const& output,
@@ -291,13 +186,13 @@
 {
 
     uint32_t split_size;
-    uint32_t thin;
+    // uint32_t thin;
     std::string input;
     std::string output;
     
-    bool last_return_only;
-    bool first_return_only;
-    bool valid_only;
+    // bool last_return_only;
+    // bool first_return_only;
+    // bool valid_only;
     bool verbose = false;
     std::vector<liblas::FilterI*> filters;
     std::vector<liblas::TransformI*> transforms;
@@ -306,56 +201,39 @@
 
     try {
 
-        po::options_description desc("Allowed options");
+        po::options_description file_options("las2las2 options");
+        po::options_description filtering_options = GetFilteringOptions();
+        po::options_description transform_options = GetTransformationOptions() ;
+
         po::positional_options_description p;
         p.add("input", 1);
         p.add("output", 1);
 
-        desc.add_options()
+        file_options.add_options()
             ("help,h", "produce help message")
             ("split,s", po::value<uint32_t>(&split_size)->default_value(0), "Split file into multiple files with each being this size in MB or less. If this value is 0, no splitting is done")
             ("input,i", po::value< string >(), "input LAS file")
             ("output,o", po::value< string >(&output)->default_value("output.las"), "output LAS file")
-            ("keep-classes,k", po::value< string >(), "A comma-separated list of classifications to keep:\n-k 2,4,12\n--keep-classes 2")
-            ("drop-classes,d", po::value< string >(), "A comma-separated list of classifications to drop:\n-d 1,7,8\n--drop-classes 2")
-            ("extent,e", po::value< string >(), "Extent window that points must fall within to keep.\nUse a comma-separated list, for example, \n  -e minx, miny, maxx, maxy\n  or \n  -e minx, miny, maxx, maxy, minz, maxz")
-            ("thin,t", po::value<uint32_t>(&thin)->default_value(0), "Simple decimation-style thinning.\nThin the file by removing every t'th point from the file.")
-            ("last_return_only", po::value<bool>(&last_return_only)->zero_tokens(), "Keep last returns (cannot be used with --first_return_only)")
-            ("first_return_only", po::value<bool>(&first_return_only)->zero_tokens(), "Keep first returns (cannot be used with --last_return_only")
-            ("keep-returns", po::value< string >(), "A comma-separated list of return numbers to keep in the output file: \n--keep-returns 1,2,3")
-            ("drop-returns", po::value< string >(), "Return numbers to drop.\nUse a comma-separated list, for example, --drop-returns 2,3,4,5")
-            ("valid_only", po::value<bool>(&valid_only)->zero_tokens(), "Keep only valid points")
-            ("keep-intensity", po::value< string >(), "Range in which to keep intensity.\nThe following expression types are supported:  \n--keep-intensity 0-100 \n--keep-intensity <200 \n--keep-intensity >400 \n--keep-intensity >=200")
-            ("drop-intensity", po::value< string >(), "Range in which to drop intensity.\nThe following expression types are supported:  \n--drop-intensity <200 \n--drop-intensity >400 \n--drop-intensity >=200")
-            ("keep-time", po::value< string >(), "Range in which to keep time.\nThe following expression types are supported:  \n--keep-time 413665.2336-414092.8462 \n--keep-time <414094.8462 \n--keep-time >413665.2336 \n--keep-time >=413665.2336")
-            ("drop-time", po::value< string >(), "Range in which to drop time.\nThe following expression types are supported:  \n--drop-time <413666.2336 \n--drop-time >413665.2336 \n--drop-time >=413665.2336")
-            ("keep-scan-angle", po::value< string >(), "Range in which to keep scan angle.\nThe following expression types are supported:  \n--keep-scan-angle 0-100 \n--keep-scan-angle <100\n--keep-scan-angle <=100")
-            ("drop-scan-angle", po::value< string >(), "Range in which to drop scan angle.\nThe following expression types are supported:  \n--drop-scan-angle <30 \n--drop-scan-angle >100 \n--drop-scan-angle >=100")
-            ("keep-color", po::value< string >(), "Range in which to keep colors.\nDefine colors as two 3-tuples (R,G,B-R,G,B):  \n--keep-color '0,0,0-125,125,125'")
-            ("drop-color", po::value< string >(), "Range in which to drop colors.\nDefine colors as two 3-tuples (R,G,B-R,G,B):  \n--drop-color '255,255,255-65536,65536,65536'")
+            ("verbose,v", po::value<bool>(&verbose)->zero_tokens(), "Verbose message output")
+        ;
+        
 
-            ("verbose,v", po::value<bool>(&verbose)->zero_tokens(), "Verbose message output")
-            ("a_srs", po::value< string >(), "Coordinate system to assign to input LAS file")
-            ("t_srs", po::value< string >(), "Coordinate system to reproject output LAS file to.  Use --a_srs or verify that your input LAS file has a coordinate system according to lasinfo")   
-            ("offset", po::value< string >(), "A comma-separated list of offsets to set on the output file: \n--offset 0,0,0 \n--offset  min,min,min\n ")
-            ("scale", po::value< string >(), "A comma-separated list of scales to set on the output file: \n--scale 0.1,0.1,0.00001\n ")
-            ("format,f", po::value< string >(), "Set the LAS format of the new file (only 1.0-1.2 supported at this time): \n--format 1.2\n-f 1.1")
+        
 
-    ;
-    
-        po::variables_map vm;        
+        po::variables_map vm;
+        po::options_description options;
+        options.add(file_options).add(transform_options).add(filtering_options);
         po::store(po::command_line_parser(argc, argv).
-          options(desc).positional(p).run(), vm);
+          options(options).positional(p).run(), vm);
 
         po::notify(vm);
 
         if (vm.count("help")) 
         {
-            std::cout << desc << "\n";
+            std::cout << file_options<<transform_options<<filtering_options<<"\n";
             return 1;
         }
 
-        boost::char_separator<char> sep(SEPARATORS);
 
         if (vm.count("input")) 
         {
@@ -371,381 +249,15 @@
             liblas::Reader reader(ifs);
             header = reader.GetHeader();
         } else {
-            std::cerr << "Input LAS file not specified!\n" << desc << "\n";
+            std::cerr << "Input LAS file not specified!\n";
             return 1;
         }
         
-        if (vm.count("keep-classes")) 
-        {
-            std::string classes = vm["keep-classes"].as< string >();
-            if (verbose)
-                std::cout << "Keeping classes with the values: " << classes << std::endl;
-                
-            liblas::FilterI* class_filter = MakeClassFilter(  classes, 
-                                                              liblas::FilterI::eInclusion);
-            filters.push_back(class_filter); 
-        }
 
-        if (vm.count("drop-classes")) 
-        {
-            std::string classes = vm["drop-classes"].as< string >();
-            if (verbose)
-                std::cout << "Dropping classes with the values: " << classes << std::endl;
-                
-            liblas::FilterI* class_filter = MakeClassFilter(  classes, 
-                                                                liblas::FilterI::eExclusion);
-            filters.push_back(class_filter);
-        }
-
-        if (vm.count("keep-returns")) 
-        {
-            std::string returns = vm["keep-returns"].as< string >();


More information about the Liblas-commits mailing list