[Liblas-commits] hg: 2 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Sat Oct 30 15:35:29 EDT 2010


changeset 03014c28e3e2 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=03014c28e3e2
summary: Boost is mandatory now - bring original implementation of random byte generator based on Boost.Random.

changeset e1c899bc4a6f in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=e1c899bc4a6f
summary: Renamed bigtest.cpp to bigtest.c

diffstat:

 apps/CMakeLists.txt                       |   4 +-
 apps/bigtest.c                            |  55 +++++++++++++++++++++++++++++++
 apps/bigtest.cpp                          |  55 -------------------------------
 include/liblas/detail/private_utility.hpp |  13 -------
 include/liblas/guid.hpp                   |  25 +++++++++++++-
 5 files changed, 81 insertions(+), 71 deletions(-)

diffs (211 lines):

diff -r b7e2421634c4 -r e1c899bc4a6f apps/CMakeLists.txt
--- a/apps/CMakeLists.txt	Sat Oct 30 17:54:55 2010 +0100
+++ b/apps/CMakeLists.txt	Sat Oct 30 20:33:49 2010 +0100
@@ -44,7 +44,7 @@
 
 set(LIBLAS_UTILITIES
     ${LASINFO_OLD} ${LASINFO} ${LASMERGE} ${LAS2LAS} ${LAS2TXT} ${TXT2LAS} 
-    ${LAS2OGR}  ${LAS2OCI} ${LAS2LAS} ${LAS2LAS_OLD} ${LASBLOCK} ${TS2LAS} )
+    ${LAS2OGR}  ${LAS2OCI} ${LAS2LAS} ${LAS2LAS_OLD} ${LASBLOCK} ${TS2LAS})
 
 # TODO: Experimental and requires testing --mloskot
 # Generate user-specific settings for Visual Studio project
@@ -142,7 +142,7 @@
 endif()
 
 if(BIGFILE_TEST)
-    add_executable(${BIGFILE_TEST} bigtest.cpp)
+    add_executable(${BIGFILE_TEST} bigtest.c)
     target_link_libraries(${BIGFILE_TEST} ${LIBLAS_C_LIB_NAME})
 endif()
 
diff -r b7e2421634c4 -r e1c899bc4a6f apps/bigtest.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/bigtest.c	Sat Oct 30 20:33:49 2010 +0100
@@ -0,0 +1,55 @@
+#include <liblas.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void dumperror (const char * appmsg)
+{
+   printf("\n%s.\n\tMessage:  %s\n\tMethod: %s",appmsg, LASError_GetLastErrorMsg(), LASError_GetLastErrorMethod());
+}
+int main()
+{
+
+    LASHeaderH header = NULL;
+    LASWriterH writer = NULL;
+    LASReaderH reader = NULL;
+    LASError err;
+    // Limitation about seeking past 4GB output size.  At 20 bytes / record, we
+    // can successfully write 204 million records, but not 205.
+    const unsigned long nMillionPoints = 205;
+    const unsigned long NPOINTS = 1024*1024*nMillionPoints ;
+    const char * OutputName = "Issue147.las";
+
+    // Write a LAS file and after the points are in, update the header.
+    header = LASHeader_Create();
+    writer = LASWriter_Create(OutputName, header, LAS_MODE_WRITE);
+    for (unsigned long i = 0; i < NPOINTS; i++)
+    {
+      double percentDone = ((double)i)/NPOINTS * 100.0;
+      if (i % 1000 == 0)
+         printf("\b\b\b\b\b\b\b%6.2f%%", percentDone);
+      
+      LASPointH pt = LASPoint_Create();
+      err = LASPoint_SetX(pt, 0);
+      if (err) printf ("For point %lu, failed to set point value X\n", i);
+      err = LASPoint_SetY(pt, 0);
+      if (err) printf ("For point %lu, failed to set point value Y\n", i);
+      err = LASPoint_SetZ(pt, 0);
+      if (err) printf ("For point %lu, failed to set point value Z\n", i);
+      err = LASWriter_WritePoint(writer, pt);  
+      if (err) printf ("For point %lu, failed to WritePoint\n", i);
+      LASPoint_Destroy(pt);
+    }
+   err = LASHeader_SetPointRecordsCount(header, NPOINTS);
+   if (err) dumperror ("Failed to LASHeader_SetPointRecordsCount\n");
+   err = LASWriter_WriteHeader(writer, header);
+   if (err) dumperror ("Failed to LASWriter_WriteHeader");
+   LASWriter_Destroy(writer);
+   LASHeader_Destroy(header);
+   
+   // Read the file we just wrote and check the header data.
+    reader = LASReader_Create(OutputName);
+    header = LASReader_GetHeader(reader);
+    unsigned long npoints = LASHeader_GetPointRecordsCount(header);
+    printf ("\n\nWrote %lu, Read %lu (testing %lu Million (1024 x 1024) Points)\n", NPOINTS, npoints, nMillionPoints);
+}
diff -r b7e2421634c4 -r e1c899bc4a6f apps/bigtest.cpp
--- a/apps/bigtest.cpp	Sat Oct 30 17:54:55 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-#include <liblas.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-void dumperror (const char * appmsg)
-{
-   printf("\n%s.\n\tMessage:  %s\n\tMethod: %s",appmsg, LASError_GetLastErrorMsg(), LASError_GetLastErrorMethod());
-}
-int main()
-{
-
-    LASHeaderH header = NULL;
-    LASWriterH writer = NULL;
-    LASReaderH reader = NULL;
-    LASError err;
-    // Limitation about seeking past 4GB output size.  At 20 bytes / record, we
-    // can successfully write 204 million records, but not 205.
-    const unsigned long nMillionPoints = 205;
-    const unsigned long NPOINTS = 1024*1024*nMillionPoints ;
-    const char * OutputName = "Issue147.las";
-
-    // Write a LAS file and after the points are in, update the header.
-    header = LASHeader_Create();
-    writer = LASWriter_Create(OutputName, header, LAS_MODE_WRITE);
-    for (unsigned long i = 0; i < NPOINTS; i++)
-    {
-      double percentDone = ((double)i)/NPOINTS * 100.0;
-      if (i % 1000 == 0)
-         printf("\b\b\b\b\b\b\b%6.2f%%", percentDone);
-      
-      LASPointH pt = LASPoint_Create();
-      err = LASPoint_SetX(pt, 0);
-      if (err) printf ("For point %lu, failed to set point value X\n", i);
-      err = LASPoint_SetY(pt, 0);
-      if (err) printf ("For point %lu, failed to set point value Y\n", i);
-      err = LASPoint_SetZ(pt, 0);
-      if (err) printf ("For point %lu, failed to set point value Z\n", i);
-      err = LASWriter_WritePoint(writer, pt);  
-      if (err) printf ("For point %lu, failed to WritePoint\n", i);
-      LASPoint_Destroy(pt);
-    }
-   err = LASHeader_SetPointRecordsCount(header, NPOINTS);
-   if (err) dumperror ("Failed to LASHeader_SetPointRecordsCount\n");
-   err = LASWriter_WriteHeader(writer, header);
-   if (err) dumperror ("Failed to LASWriter_WriteHeader");
-   LASWriter_Destroy(writer);
-   LASHeader_Destroy(header);
-   
-   // Read the file we just wrote and check the header data.
-    reader = LASReader_Create(OutputName);
-    header = LASReader_GetHeader(reader);
-    unsigned long npoints = LASHeader_GetPointRecordsCount(header);
-    printf ("\n\nWrote %lu, Read %lu (testing %lu Million (1024 x 1024) Points)\n", NPOINTS, npoints, nMillionPoints);
-}
diff -r b7e2421634c4 -r e1c899bc4a6f include/liblas/detail/private_utility.hpp
--- a/include/liblas/detail/private_utility.hpp	Sat Oct 30 17:54:55 2010 +0100
+++ b/include/liblas/detail/private_utility.hpp	Sat Oct 30 20:33:49 2010 +0100
@@ -223,19 +223,6 @@
 //     return (!lhs.equal(rhs));
 // }
 
-template <typename T>
-inline T generate_random_byte()
-{
-    // Requires pseudo-random numbers generator to be initialized
-    // in create_random_based() function - a poor man solution.
-    T const rmin = (std::numeric_limits<T>::min)();
-    T const rmax = (std::numeric_limits<T>::max)();
-    unsigned int const rnd = std::rand() % rmax + rmin;
-
-    assert(rnd <= 255);
-    return static_cast<T>(rnd);
-}
-
 template <typename T> 
 bool compare_distance(const T& actual, const T& expected) 
 { 
diff -r b7e2421634c4 -r e1c899bc4a6f include/liblas/guid.hpp
--- a/include/liblas/guid.hpp	Sat Oct 30 17:54:55 2010 +0100
+++ b/include/liblas/guid.hpp	Sat Oct 30 20:33:49 2010 +0100
@@ -64,6 +64,7 @@
 // boost
 #include <boost/array.hpp>
 #include <boost/cstdint.hpp>
+#include <boost/random.hpp>
 // std
 #include <iosfwd>
 #include <iomanip>
@@ -79,6 +80,28 @@
 
 namespace liblas {
 
+namespace detail {
+
+    inline uint8_t random_byte()
+    {
+        // Change seed to something better?
+
+        typedef boost::mt19937 engine_t;
+        typedef boost::uniform_int<unsigned long> distribution_t;
+        typedef boost::variate_generator<engine_t, distribution_t> generator_t;
+
+        static generator_t generator(
+            engine_t(static_cast<engine_t::result_type>( std::time(0) )),
+            // this line should work and does, but it produces lots of warnings
+            // thus we will use unsigned long and cast it to a uint8_t
+            //distribution_t((std::numeric_limits<uint8_t>::min)(), (std::numeric_limits<uint8_t>::max)()));
+            distribution_t((std::numeric_limits<unsigned long>::min)(), (std::numeric_limits<unsigned long>::max)()));
+
+        return static_cast<uint8_t>(generator() & 0xFF);
+    }
+
+} // namespace detail
+
 /// Definition of Globally Unique Identifier type.
 /// The GUID is a 16-byte (128-bit) number.
 /// This class is used to represent value stored as Project Identifier
@@ -418,7 +441,7 @@
         
         for (size_t i = 0; i < result.data_.size(); i++)
         {
-            result.data_[i] = detail::generate_random_byte<boost::uint8_t>();
+            result.data_[i] = detail::random_byte();
         }
     
         // set variant


More information about the Liblas-commits mailing list