[Liblas-commits] hg: get liblas::{Writer|Reader}::{Get|Set}Header squared away an...

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Jan 20 12:15:22 EST 2011


details:   http://hg.liblas.orghg/rev/2b07a62223ea
changeset: 2795:2b07a62223ea
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Jan 20 11:14:59 2011 -0600
description:
get liblas::{Writer|Reader}::{Get|Set}Header squared away and consistent in both the C++ and C APIs

diffstat:

 include/liblas/capi/liblas.h |  15 ++++++++++++++-
 include/liblas/writer.hpp    |   5 ++++-
 src/c_api.cpp                |  41 ++++++++++++++++++++++++++++++++++++++++-
 src/writer.cpp               |   8 ++++++--
 test/unit/writer_test.cpp    |   3 ++-
 5 files changed, 66 insertions(+), 6 deletions(-)

diffs (172 lines):

diff -r 24b479586b7d -r 2b07a62223ea include/liblas/capi/liblas.h
--- a/include/liblas/capi/liblas.h	Wed Jan 19 16:23:02 2011 -0600
+++ b/include/liblas/capi/liblas.h	Thu Jan 20 11:14:59 2011 -0600
@@ -194,6 +194,7 @@
 */
 LAS_DLL LASHeaderH LASReader_GetHeader(const LASReaderH hReader);
 
+LAS_DLL void LASReader_SetHeader(  LASReaderH hReader, const LASHeaderH hHeader);
 
 LAS_DLL LASError LASReader_SetSRS(LASReaderH hReader, const LASSRSH hSRS);
 LAS_DLL LASError LASReader_SetInputSRS(LASReaderH hReader, const LASSRSH hSRS);
@@ -906,7 +907,9 @@
 LAS_DLL LASError LASWriter_WritePoint(const LASWriterH hWriter, const LASPointH hPoint);
 
 /** Overwrites the header for the file represented by the LASWriterH.  It does 
- *  not matter if the file is opened for append or for write.
+ *  not matter if the file is opened for append or for write.  This function is 
+ *  equivalent to calling LASWriter_SetHeader and LASWriter_WriteOwnedHeader
+ *  simultaneously.
  *  @param hWriter opaque pointer to the LASWriterH instance
  *  @param hHeader LASHeaderH instance to write into the file
  *  @return LE_None if no error occurred during the operation.
@@ -914,6 +917,15 @@
 
 LAS_DLL LASError LASWriter_WriteHeader(const LASWriterH hWriter, const LASHeaderH hHeader);
 
+/** Overwrites the header for the file represented by the LASWriterH that was 
+ *  set using LASWriter_SetHeader or flushes the existing header that is on the
+ *  the writer to the file and resets the file for writing.
+ *  @param hWriter opaque pointer to the LASWriterH instance
+ *  @return LE_None if no error occurred during the operation.
+*/
+
+LAS_DLL LASError LASWriter_WriteOwnedHeader(const LASWriterH hWriter);
+
 /** Destroys the LASWriterH instance, effectively closing the file and performing 
  *  housekeeping operations.
  *  @param hWriter LASWriterH instance to close
@@ -927,6 +939,7 @@
  *  in the event of a NULL return.
 */
 LAS_DLL LASHeaderH LASWriter_GetHeader(const LASWriterH hWriter);
+LAS_DLL void LASWriter_SetHeader(  LASWriterH hWriter, const LASHeaderH hHeader) ;
 
 LAS_DLL LASError LASWriter_SetSRS(LASWriterH hWriter, const LASSRSH hSRS);
 LAS_DLL LASError LASWriter_SetInputSRS(LASWriterH hWriter, const LASSRSH hSRS);
diff -r 24b479586b7d -r 2b07a62223ea include/liblas/writer.hpp
--- a/include/liblas/writer.hpp	Wed Jan 19 16:23:02 2011 -0600
+++ b/include/liblas/writer.hpp	Thu Jan 20 11:14:59 2011 -0600
@@ -82,13 +82,16 @@
     
     /// Provides access to header structure.
     Header const& GetHeader() const;
+    
+    void SetHeader(Header const& header);
+    
 
     /// \todo TODO: Move point record composition deep into writer implementation.
     /// \todo TODO: How to handle point_source_id in portable way, for LAS 1.0 and 1.1
     bool WritePoint(Point const& point);
 
     /// Allow in-place writing of header
-    void WriteHeader(Header& header);
+    void WriteHeader();
 
     /// Sets filters that are used to determine wither or not to 
     /// keep a point that before we write it
diff -r 24b479586b7d -r 2b07a62223ea src/c_api.cpp
--- a/src/c_api.cpp	Wed Jan 19 16:23:02 2011 -0600
+++ b/src/c_api.cpp	Thu Jan 20 11:14:59 2011 -0600
@@ -269,6 +269,17 @@
 
 }
 
+LAS_DLL void LASReader_SetHeader(  LASReaderH hReader, const LASHeaderH hHeader) 
+
+{
+    VALIDATE_LAS_POINTER0(hReader, "LASReader_SetHeader");
+    VALIDATE_LAS_POINTER0(hHeader, "LASReader_SetHeader");
+
+    liblas::Reader* reader = (liblas::Reader*)hReader;
+    liblas::Header* header = (liblas::Header*)hHeader;
+    reader->SetHeader(*header);
+}
+
 LAS_DLL void LASReader_Destroy(LASReaderH hReader)
 {
     VALIDATE_LAS_POINTER0(hReader, "LASReader_Destroy");
@@ -1518,7 +1529,8 @@
     VALIDATE_LAS_POINTER1(hWriter, "LASWriter_WriteHeader", LE_Failure);
     
     try {
-            ((liblas::Writer*) hWriter)->WriteHeader(*((liblas::Header*) hHeader));
+        ((liblas::Writer*) hWriter)->SetHeader(*((liblas::Header*) hHeader));
+        ((liblas::Writer*) hWriter)->WriteHeader();
     } catch (std::exception const& e)
     {
         LASError_PushError(LE_Failure, e.what(), "LASWriter_WriteHeader");
@@ -1528,6 +1540,33 @@
     return LE_None;    
 }
 
+LAS_DLL LASErrorEnum LASWriter_WriteOwnedHeader(const LASWriterH hWriter)
+{
+    VALIDATE_LAS_POINTER1(hWriter, "LASWriter_WriteOwnedHeader", LE_Failure);
+
+    try {
+        ((liblas::Writer*) hWriter)->WriteHeader();
+    } catch (std::exception const& e)
+    {
+        LASError_PushError(LE_Failure, e.what(), "LASWriter_WriteOwnedHeader");
+        return LE_Failure;
+    }
+
+    return LE_None;    
+}
+
+
+LAS_DLL void LASWriter_SetHeader(  LASWriterH hWriter, const LASHeaderH hHeader) 
+
+{
+    VALIDATE_LAS_POINTER0(hWriter, "LASWriter_SetHeader");
+    VALIDATE_LAS_POINTER0(hHeader, "LASWriter_SetHeader");
+
+    liblas::Writer* writer = (liblas::Writer*)hWriter;
+    liblas::Header* header = (liblas::Header*)hHeader;
+    writer->SetHeader(*header);
+}
+
 LAS_DLL void LASWriter_Destroy(LASWriterH hWriter)
 {
     VALIDATE_LAS_POINTER0(hWriter, "LASWriter_Destroy");
diff -r 24b479586b7d -r 2b07a62223ea src/writer.cpp
--- a/src/writer.cpp	Wed Jan 19 16:23:02 2011 -0600
+++ b/src/writer.cpp	Thu Jan 20 11:14:59 2011 -0600
@@ -98,17 +98,21 @@
     return m_pimpl->GetHeader();
 }
 
+void Writer::SetHeader(Header const& header)
+{
+    return m_pimpl->SetHeader(header);
+}
+
 bool Writer::WritePoint(Point const& point)
 {
     m_pimpl->WritePoint(point);
     return true;
 }
 
-void Writer::WriteHeader(Header& header)
+void Writer::WriteHeader()
 {
     // The writer may update our header as part of its 
     // writing process (change VLRs for SRS's, for instance).
-    m_pimpl->SetHeader(header);
     m_pimpl->WriteHeader();
 }
 
diff -r 24b479586b7d -r 2b07a62223ea test/unit/writer_test.cpp
--- a/test/unit/writer_test.cpp	Wed Jan 19 16:23:02 2011 -0600
+++ b/test/unit/writer_test.cpp	Thu Jan 20 11:14:59 2011 -0600
@@ -207,7 +207,8 @@
             header.SetScale(1.123, 2.123, 3.123);
             header.SetOffset(4.321, 5.321, 6.321);
 
-            writer.WriteHeader(header);
+            writer.SetHeader(header);
+            writer.WriteHeader();
             liblas::Header const& written_header = writer.GetHeader();
             ensure_equals("written_header fileSource id", written_header.GetFileSourceId(), 65535);
             ensure_equals("written_header SystemId", written_header.GetSystemId(), "Unit Test libLAS System");


More information about the Liblas-commits mailing list