[Liblas-commits] hg: 3 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Sun Nov 7 00:12:56 EDT 2010


changeset 5d4c2ea5c1c6 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=5d4c2ea5c1c6
summary: remove duplicate url

changeset fe6059f62afd in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=fe6059f62afd
summary: use shared_ptr to take care of writer/summary

changeset 9cf76ab01522 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=9cf76ab01522
summary: put the chipper and kernel in their own libraries that are installed with libas and liblas_c, hook these libs up to the utilties that are using them

diffstat:

 CMakeLists.txt                   |   13 ++++
 apps/CMakeLists.txt              |   31 +++++++--
 apps/las2las.cpp                 |  117 ++++++++++----------------------------
 doc/_templates/indexsidebar.html |    1 -
 4 files changed, 68 insertions(+), 94 deletions(-)

diffs (truncated from 314 to 300 lines):

diff -r f97683cf4471 -r 9cf76ab01522 CMakeLists.txt
--- a/CMakeLists.txt	Fri Nov 05 22:01:59 2010 -0500
+++ b/CMakeLists.txt	Sat Nov 06 23:12:41 2010 -0500
@@ -14,12 +14,25 @@
 
   # Name of C library
   set(LIBLAS_C_LIB_NAME liblas_c)
+  
+  # Name of Chipper library
+  set(LASCHIP_LIB_NAME liblas_chipper )  
+  
+  # Name of Kernel libray
+  set(LASKERNEL_LIB_NAME liblas_kernel )
+  
 else()
   # Name of C++ library
   set(LIBLAS_LIB_NAME las)
   
   # Name of C library
   set(LIBLAS_C_LIB_NAME las_c)
+
+  # Name of Chipper library
+  set(LASCHIP_LIB_NAME las_chipper )  
+
+  # Name of Kernel libray
+  set(LASKERNEL_LIB_NAME las_kernel )
 endif()
 
 # Name of test suite runner
diff -r f97683cf4471 -r 9cf76ab01522 apps/CMakeLists.txt
--- a/apps/CMakeLists.txt	Fri Nov 05 22:01:59 2010 -0500
+++ b/apps/CMakeLists.txt	Sat Nov 06 23:12:41 2010 -0500
@@ -82,6 +82,21 @@
 
 link_directories(${Boost_LIBRARY_DIRS})
 
+set (LASCHIP_SOURCES chipper.cpp)
+add_library(${LASCHIP_LIB_NAME} SHARED ${LASCHIP_SOURCES})
+target_link_libraries(${LASCHIP_LIB_NAME}
+                      ${LIBLAS_LIB_NAME})
+
+set (LASKERNEL_SOURCES laskernel.cpp)
+add_library(${LASKERNEL_LIB_NAME} SHARED ${LASKERNEL_SOURCES})
+target_link_libraries(${LASKERNEL_LIB_NAME}
+                      ${LIBLAS_LIB_NAME})
+
+install(TARGETS ${LASKERNEL_LIB_NAME} ${LASCHIP_LIB_NAME}
+  RUNTIME DESTINATION ${LIBLAS_BIN_DIR}
+  LIBRARY DESTINATION ${LIBLAS_LIB_DIR}
+  ARCHIVE DESTINATION ${LIBLAS_LIB_DIR})
+
 # Build lasinfo
 if(LASINFO_OLD)
     set(LASINFO_OLD_SRC lascommon.c ${LASINFO_OLD}.c)
@@ -97,13 +112,13 @@
 endif()
 
 if(LAS2LAS)
-    add_executable(${LAS2LAS} las2las.cpp laskernel.cpp)
-    target_link_libraries(${LAS2LAS} ${APPS_CPP_DEPENDENCIES} )
+    add_executable(${LAS2LAS} las2las.cpp )
+    target_link_libraries(${LAS2LAS} ${APPS_CPP_DEPENDENCIES} ${LASCHIP_LIB_NAME} ${LASKERNEL_LIB_NAME})
 endif()
 
 if(LASINFO)
-    add_executable(${LASINFO} lasinfo.cpp laskernel.cpp)
-    target_link_libraries(${LASINFO} ${APPS_CPP_DEPENDENCIES} )
+    add_executable(${LASINFO} lasinfo.cpp )
+    target_link_libraries(${LASINFO} ${APPS_CPP_DEPENDENCIES} ${LASKERNEL_LIB_NAME} )
 endif()
 
 # Build las2txt
@@ -134,9 +149,9 @@
 
 # Build lasblock
 if(LASBLOCK)
-    set(LASBLOCK_SRC lasblock.cpp chipper.cpp chipper.hpp)
+    set(LASBLOCK_SRC lasblock.cpp )
     add_executable(${LASBLOCK} ${LASBLOCK_SRC})
-    target_link_libraries(${LASBLOCK} ${APPS_CPP_DEPENDENCIES} )
+    target_link_libraries(${LASBLOCK} ${APPS_CPP_DEPENDENCIES} ${LASCHIP_LIB_NAME})
 endif()
 
 # Build las2ogr
@@ -147,8 +162,8 @@
 
 # Build las2oci
 if(LAS2OCI)
-    add_executable(${LAS2OCI} las2oci.cpp oci_wrapper.cpp kdx_util.cpp oci_util.cpp laskernel.cpp chipper.cpp)
-    target_link_libraries(${LAS2OCI} ${APPS_CPP_DEPENDENCIES} ${ORACLE_LIBRARY})
+    add_executable(${LAS2OCI} las2oci.cpp oci_wrapper.cpp kdx_util.cpp oci_util.cpp )
+    target_link_libraries(${LAS2OCI} ${APPS_CPP_DEPENDENCIES} ${ORACLE_LIBRARY} ${LASCHIP_LIB_NAME} ${LASKERNEL_LIB_NAME})
 endif()
 
 if(BIGFILE_TEST)
diff -r f97683cf4471 -r 9cf76ab01522 apps/las2las.cpp
--- a/apps/las2las.cpp	Fri Nov 05 22:01:59 2010 -0500
+++ b/apps/las2las.cpp	Sat Nov 06 23:12:41 2010 -0500
@@ -14,59 +14,20 @@
 
 #include <boost/cstdint.hpp>
 #include <boost/foreach.hpp>
+#include <boost/shared_ptr.hpp>
 
 namespace po = boost::program_options;
 
 using namespace liblas;
 using namespace std;
 
-// 0, 4, 16, 64, 256
-//std::size_t const default_buffer_size = 0;
-//std::size_t const default_buffer_size = 4 * 1024;
-//std::size_t const default_buffer_size = 16 * 1024;
-//std::size_t const default_buffer_size = 64 * 1024;
-//std::size_t const default_buffer_size = 256 * 1024;
-std::size_t const default_buffer_size = 1024 * 1024;
-std::vector<char> ofs_buffer;
-std::vector<char> ifs_buffer;
+typedef boost::shared_ptr<liblas::Writer> WriterPtr;
+typedef boost::shared_ptr<liblas::Summary> SummaryPtr;
+typedef boost::shared_ptr<std::ofstream> OStreamPtr;
 
-std::ofstream& set_ofstream_buffer(std::ofstream& ofs, std::size_t buffer_size)
-{
-    char* buffer = 0; // unbuffered;
-    if (buffer_size > 0)
-    {
-        std::vector<char>(buffer_size).swap(ofs_buffer);
-        buffer = &ofs_buffer[0];
-    }
-
-    std::streambuf* sb = ofs.rdbuf()->pubsetbuf(buffer, buffer_size);
-    if (0 != buffer && 0 == sb)
-    {
-        throw std::runtime_error("failed to attach non-null buffer to input file stream");
-    }
-    return ofs;
-}
-
-std::ifstream& set_ifstream_buffer(std::ifstream& ifs, std::size_t buffer_size)
-{
-    char* buffer = 0; // unbuffered;
-    if (buffer_size > 0)
-    {
-        std::vector<char>(buffer_size).swap(ifs_buffer);
-        buffer = &ifs_buffer[0];
-    }
-
-    std::streambuf* sb = ifs.rdbuf()->pubsetbuf(buffer, buffer_size);
-    if (0 != buffer && 0 == sb)
-    {
-        throw std::runtime_error("failed to attach non-null buffer to input file stream");
-    }
-    return ifs;
-}
-
-liblas::Writer* start_writer(   std::ofstream* strm, 
-                                std::string const& output, 
-                                liblas::Header const& header)
+WriterPtr start_writer(   OStreamPtr strm, 
+                          std::string const& output, 
+                          liblas::Header const& header)
 {
     
     if (!liblas::Create(*strm, output.c_str()))
@@ -76,9 +37,7 @@
         throw std::runtime_error(oss.str());
     }
 
-    // set_ofstream_buffer(*strm, default_buffer_size);
-
-    liblas::Writer* writer = new liblas::Writer(*strm, header);
+    WriterPtr writer( new liblas::Writer(*strm, header));
     return writer;
     
 }
@@ -100,17 +59,15 @@
         std::cerr << "Cannot open " << input << "for read.  Exiting...";
         return false;
     }
-    // set_ifstream_buffer(ifs, default_buffer_size);
 
     liblas::Reader reader(ifs);
-    liblas::Summary* summary = new liblas::Summary;
+    SummaryPtr summary(new::liblas::Summary);
     
     reader.SetFilters(filters);
     reader.SetTransforms(transforms);    
     
     if (min_offset) 
     {
-        
         liblas::property_tree::ptree tree = reader.Summarize();
         try
         {
@@ -128,8 +85,6 @@
         }
         if (verbose) 
         {
-            
-    
             std::cout << "Using minimum offsets ";
             SetStreamPrecision(std::cout, header.GetScaleX());
             std::cout << header.GetOffsetX() << " ";
@@ -142,9 +97,11 @@
         reader.Reset();
     }
 
-    std::ofstream* ofs = new std::ofstream;
+    OStreamPtr ofs(new std::ofstream);
     std::string out = output;
-    liblas::Writer* writer = 0;
+    
+    WriterPtr writer;
+
     if (!split_mb && !split_pts) {
         writer = start_writer(ofs, output, header);
         
@@ -186,10 +143,11 @@
             // down until we've written that many points into the file.  
             // After that point, we make a new file and start writing into 
             // that.  
-            delete writer;
-            delete ofs;
-            
-            ofs = new std::ofstream;
+
+            // dereference the writer so it is deleted before the ofs
+            writer = WriterPtr();
+                        
+            ofs = OStreamPtr(new std::ofstream);
             ostringstream oss;
             oss << out << "-"<< fileno <<".las";
 
@@ -202,8 +160,7 @@
             RepairHeader(*summary, hnew);
             RewriteHeader(hnew, old_filename.str());
 
-            delete summary;
-            summary =  new liblas::Summary; 
+            summary =  SummaryPtr(new liblas::Summary); 
             fileno++;
             split_bytes_count = 1024*1024*split_mb;
         }
@@ -214,10 +171,11 @@
             // After that point, we make a new file and start writing into 
             // that.  
 
-            delete writer;
-            delete ofs;
+            // dereference the writer so it is deleted before the ofs
+            writer = WriterPtr();
             
-            ofs = new std::ofstream;
+            
+            ofs = OStreamPtr(new std::ofstream);
             ostringstream oss;
             oss << out << "-"<< fileno <<".las";
 
@@ -229,8 +187,8 @@
             liblas::Header hnew = FetchHeader(old_filename.str());
             RepairHeader(*summary, hnew);
             RewriteHeader(hnew, old_filename.str());
-            delete summary;
-            summary =  new liblas::Summary; 
+
+            summary =  SummaryPtr(new liblas::Summary); 
             fileno++;
             split_points_count = 0;
         }
@@ -238,25 +196,14 @@
     }
     if (verbose)
         std::cout << std::endl;
-    
-    reader.Reset();
-    // 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);
-    // liblas::property_tree::write_xml("junk.xml", top);
-    // liblas::property_tree::write_xml("schema.xml", reader.GetHeader().GetSchema().GetPTree());
-    // 
-    // std::cout <<  reader.GetHeader().GetSchema() << std::endl;
-    delete writer;
-    delete ofs;
-    
-    liblas::Header hnew = FetchHeader(output);
-    RepairHeader(*summary, hnew);
-    RewriteHeader(hnew, output);
 
-    delete summary;
-    
+    if (!split_mb && !split_pts) {
+        reader.Reset();
+
+        liblas::Header hnew = FetchHeader(output);
+        RepairHeader(*summary, hnew);
+        RewriteHeader(hnew, output);
+    }


More information about the Liblas-commits mailing list