[Liblas-commits] r1009 - in trunk: include/liblas/detail src src/detail

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Feb 10 22:56:34 EST 2009


Author: hobu
Date: Tue Feb 10 22:56:34 2009
New Revision: 1009
URL: http://liblas.org/changeset/1009

Log:
1.2 LASWriter support

Modified:
   trunk/include/liblas/detail/writer.hpp
   trunk/include/liblas/detail/writer10.hpp
   trunk/include/liblas/detail/writer11.hpp
   trunk/include/liblas/detail/writer12.hpp
   trunk/src/detail/reader12.cpp
   trunk/src/detail/writer.cpp
   trunk/src/detail/writer10.cpp
   trunk/src/detail/writer11.cpp
   trunk/src/detail/writer12.cpp
   trunk/src/laswriter.cpp

Modified: trunk/include/liblas/detail/writer.hpp
==============================================================================
--- trunk/include/liblas/detail/writer.hpp	(original)
+++ trunk/include/liblas/detail/writer.hpp	Tue Feb 10 22:56:34 2009
@@ -43,6 +43,8 @@
 #define LIBLAS_DETAIL_WRITER_HPP_INCLUDED
 
 #include <liblas/detail/fwd.hpp>
+#include <liblas/detail/utility.hpp>
+
 // std
 #include <iosfwd>
 
@@ -57,11 +59,14 @@
     virtual std::size_t GetVersion() const = 0;
     virtual void WriteHeader(LASHeader& header) = 0;
     virtual void UpdateHeader(LASHeader const& header) = 0;
-    virtual void WritePointRecord(PointRecord const& record) = 0;
-    virtual void WritePointRecord(PointRecord const& record, double const& time) = 0;    
+    virtual void WritePointRecord(LASPoint const& point, const LASHeader& header) = 0;
     virtual void WriteVLR(LASHeader const& header) = 0;
     virtual std::ostream& GetStream() const = 0;
 
+protected:
+    PointRecord m_record;
+    void FillPointRecord(PointRecord& record, const LASPoint& point);
+
 private:
 
     // Blocked copying operations, declared but not defined.

Modified: trunk/include/liblas/detail/writer10.hpp
==============================================================================
--- trunk/include/liblas/detail/writer10.hpp	(original)
+++ trunk/include/liblas/detail/writer10.hpp	Tue Feb 10 22:56:34 2009
@@ -60,8 +60,8 @@
     std::size_t GetVersion() const;
     void WriteHeader(LASHeader& header);
     void UpdateHeader(LASHeader const& header);
-    void WritePointRecord(PointRecord const& record);
-    void WritePointRecord(PointRecord const& record, double const& time);
+    void WritePointRecord(LASPoint const& record, const LASHeader& header);
+//    void WritePointRecord(PointRecord const& record, double const& time);
     void WriteVLR(LASHeader const& header);
     std::ostream& GetStream() const;
 

Modified: trunk/include/liblas/detail/writer11.hpp
==============================================================================
--- trunk/include/liblas/detail/writer11.hpp	(original)
+++ trunk/include/liblas/detail/writer11.hpp	Tue Feb 10 22:56:34 2009
@@ -60,8 +60,7 @@
     std::size_t GetVersion() const;
     void WriteHeader(LASHeader& header);
     void UpdateHeader(LASHeader const& header);
-    void WritePointRecord(PointRecord const& record);
-    void WritePointRecord(PointRecord const& record, double const& time);
+    void WritePointRecord(LASPoint const& record, const LASHeader& header);
     void WriteVLR(LASHeader const& header);
     std::ostream& GetStream() const;
     

Modified: trunk/include/liblas/detail/writer12.hpp
==============================================================================
--- trunk/include/liblas/detail/writer12.hpp	(original)
+++ trunk/include/liblas/detail/writer12.hpp	Tue Feb 10 22:56:34 2009
@@ -60,8 +60,7 @@
     std::size_t GetVersion() const;
     void WriteHeader(LASHeader& header);
     void UpdateHeader(LASHeader const& header);
-    void WritePointRecord(PointRecord const& record);
-    void WritePointRecord(PointRecord const& record, double const& time);
+    void WritePointRecord(LASPoint const& record, const LASHeader& header);
     void WriteVLR(LASHeader const& header);
     std::ostream& GetStream() const;
     

Modified: trunk/src/detail/reader12.cpp
==============================================================================
--- trunk/src/detail/reader12.cpp	(original)
+++ trunk/src/detail/reader12.cpp	Tue Feb 10 22:56:34 2009
@@ -268,8 +268,8 @@
             point.SetTime(t);
         } else if (header.GetDataFormatId() == LASHeader::ePointFormat2) {
             detail::read_n(red, m_ifs, sizeof(uint16_t));
-            detail::read_n(blue, m_ifs, sizeof(uint16_t));
             detail::read_n(green, m_ifs, sizeof(uint16_t));
+            detail::read_n(blue, m_ifs, sizeof(uint16_t));
             color.SetRed(red);
             color.SetBlue(blue);
             color.SetGreen(green);
@@ -278,8 +278,8 @@
             detail::read_n(t, m_ifs, sizeof(double));
             point.SetTime(t);
             detail::read_n(red, m_ifs, sizeof(uint16_t));
-            detail::read_n(blue, m_ifs, sizeof(uint16_t));
             detail::read_n(green, m_ifs, sizeof(uint16_t));
+            detail::read_n(blue, m_ifs, sizeof(uint16_t));
             color.SetRed(red);
             color.SetBlue(blue);
             color.SetGreen(green);

Modified: trunk/src/detail/writer.cpp
==============================================================================
--- trunk/src/detail/writer.cpp	(original)
+++ trunk/src/detail/writer.cpp	Tue Feb 10 22:56:34 2009
@@ -60,6 +60,18 @@
 {
 }
 
+void Writer::FillPointRecord(PointRecord& record, const LASPoint& point) 
+{
+    record.x = point.GetX();
+    record.y = point.GetY();
+    record.z = point.GetZ();
+    record.intensity = point.GetIntensity();
+    record.flags = point.GetScanFlags();
+    record.classification = point.GetClassification();
+    record.scan_angle_rank = point.GetScanAngleRank();
+    record.user_data = point.GetUserData();
+    record.point_source_id = point.GetPointSourceID();
+}
 Writer* WriterFactory::Create(std::ostream& ofs, LASHeader const& header)
 {
     if (!ofs)

Modified: trunk/src/detail/writer10.cpp
==============================================================================
--- trunk/src/detail/writer10.cpp	(original)
+++ trunk/src/detail/writer10.cpp	Tue Feb 10 22:56:34 2009
@@ -227,25 +227,32 @@
     }
 }
 
-void WriterImpl::WritePointRecord(detail::PointRecord const& record)
+void WriterImpl::WritePointRecord(LASPoint const& point, const LASHeader& header)
 {
     // TODO: Static assert would be better
-    assert(20 == sizeof(record));
-    detail::write_n(m_ofs, record, sizeof(record));
-
+    
+    double t = 0;
+    assert(LASHeader::ePointSize0 == sizeof(m_record));
+    Writer::FillPointRecord(m_record, point);
+    detail::write_n(m_ofs, m_record, sizeof(m_record));
+
+    if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
+        t = point.GetTime();
+        detail::write_n(m_ofs, t, sizeof(double));
+    }
     ++m_pointCount;
 }
 
-void WriterImpl::WritePointRecord(detail::PointRecord const& record, double const& time)
-{
-    // TODO: Static assert would be better
-    assert(28 == sizeof(record) + sizeof(time));
-
-    // Write point data record format 1
-    WritePointRecord(record);
-
-    detail::write_n(m_ofs, time, sizeof(double));
-}
+// void WriterImpl::WritePointRecord(detail::PointRecord const& record, double const& time)
+// {
+//     // TODO: Static assert would be better
+//     assert(28 == sizeof(record) + sizeof(time));
+// 
+//     // Write point data record format 1
+//     WritePointRecord(record);
+// 
+//     detail::write_n(m_ofs, time, sizeof(double));
+// }
 
 void WriterImpl::WriteVLR(LASHeader const& header) 
 {

Modified: trunk/src/detail/writer11.cpp
==============================================================================
--- trunk/src/detail/writer11.cpp	(original)
+++ trunk/src/detail/writer11.cpp	Tue Feb 10 22:56:34 2009
@@ -228,27 +228,32 @@
     }
 }
 
-void WriterImpl::WritePointRecord(detail::PointRecord const& record)
+void WriterImpl::WritePointRecord(LASPoint const& point, const LASHeader& header)
 {
-    // Write point data record format 0
-
     // TODO: Static assert would be better
-    assert(20 == sizeof(record));
-    detail::write_n(m_ofs, record, sizeof(record));
-
+    
+    double t = 0;
+    assert(LASHeader::ePointSize0 == sizeof(m_record));
+    Writer::FillPointRecord(m_record, point);
+    detail::write_n(m_ofs, m_record, sizeof(m_record));
+
+    if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
+        t = point.GetTime();
+        detail::write_n(m_ofs, t, sizeof(double));
+    }
     ++m_pointCount;
 }
 
-void WriterImpl::WritePointRecord(detail::PointRecord const& record, double const& time)
-{
-    // TODO: Static assert would be better
-    assert(28 == sizeof(record) + sizeof(time));
-
-    // Write point data record format 1
-    WritePointRecord(record);
-
-    detail::write_n(m_ofs, time, sizeof(double));
-}
+// void WriterImpl::WritePointRecord(detail::PointRecord const& record, double const& time)
+// {
+//     // TODO: Static assert would be better
+//     assert(28 == sizeof(record) + sizeof(time));
+// 
+//     // Write point data record format 1
+//     WritePointRecord(record);
+// 
+//     detail::write_n(m_ofs, time, sizeof(double));
+// }
 
 void WriterImpl::WriteVLR(LASHeader const& header) 
 {

Modified: trunk/src/detail/writer12.cpp
==============================================================================
--- trunk/src/detail/writer12.cpp	(original)
+++ trunk/src/detail/writer12.cpp	Tue Feb 10 22:56:34 2009
@@ -228,27 +228,58 @@
     }
 }
 
-void WriterImpl::WritePointRecord(detail::PointRecord const& record)
+void WriterImpl::WritePointRecord(LASPoint const& point, const LASHeader& header)
 {
-    // Write point data record format 0
-
     // TODO: Static assert would be better
-    assert(20 == sizeof(record));
-    detail::write_n(m_ofs, record, sizeof(record));
+    
+    double t = 0;
+    uint16_t red = 0;
+    uint16_t blue = 0;
+    uint16_t green = 0;
+    LASColor color;
+    
+    assert(LASHeader::ePointSize0 == sizeof(m_record));
+    Writer::FillPointRecord(m_record, point);
+    detail::write_n(m_ofs, m_record, sizeof(m_record));
+
+    if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
+        t = point.GetTime();
+        detail::write_n(m_ofs, t, sizeof(double));
+    } else if (header.GetDataFormatId() == LASHeader::ePointFormat2) {
+        color = point.GetColor();
+        red = color.GetRed();
+        green = color.GetGreen();
+        blue = color.GetBlue();
+        detail::write_n(m_ofs, red, sizeof(uint16_t));
+        detail::write_n(m_ofs, green, sizeof(uint16_t));
+        detail::write_n(m_ofs, blue, sizeof(uint16_t));
+    } else if (header.GetDataFormatId() == LASHeader::ePointFormat3) {
+        t = point.GetTime();
+        detail::write_n(m_ofs, t, sizeof(double));
+        color = point.GetColor();
+        red = color.GetRed();
+        green = color.GetGreen();
+        blue = color.GetBlue();
+        detail::write_n(m_ofs, red, sizeof(uint16_t));
+        detail::write_n(m_ofs, green, sizeof(uint16_t));
+        detail::write_n(m_ofs, blue, sizeof(uint16_t));
+    }
+
 
     ++m_pointCount;
 }
 
-void WriterImpl::WritePointRecord(detail::PointRecord const& record, double const& time)
-{
-    // TODO: Static assert would be better
-    assert(28 == sizeof(record) + sizeof(time));
-
-    // Write point data record format 1
-    WritePointRecord(record);
-
-    detail::write_n(m_ofs, time, sizeof(double));
-}
+// 
+// void WriterImpl::WritePointRecord(detail::PointRecord const& record, double const& time)
+// {
+//     // TODO: Static assert would be better
+//     assert(28 == sizeof(record) + sizeof(time));
+// 
+//     // Write point data record format 1
+//     WritePointRecord(record);
+// 
+//     detail::write_n(m_ofs, time, sizeof(double));
+// }
 
 void WriterImpl::WriteVLR(LASHeader const& header) 
 {

Modified: trunk/src/laswriter.cpp
==============================================================================
--- trunk/src/laswriter.cpp	(original)
+++ trunk/src/laswriter.cpp	Tue Feb 10 22:56:34 2009
@@ -82,22 +82,22 @@
     }
 
     // TODO: Move composition of point record deep into writer implementation
-    m_record.x = static_cast<uint32_t>((point.GetX() - m_header.GetOffsetX()) / m_header.GetScaleX());
-    m_record.y = static_cast<uint32_t>((point.GetY() - m_header.GetOffsetY()) / m_header.GetScaleY());
-    m_record.z = static_cast<uint32_t>((point.GetZ() - m_header.GetOffsetZ()) / m_header.GetScaleZ());
-    m_record.intensity = point.GetIntensity();
-    m_record.flags = point.GetScanFlags();
-    m_record.classification = point.GetClassification();
-    m_record.scan_angle_rank = point.GetScanAngleRank();
-    // For LAS 1.0 - File Marker; for LAS 1.1 - User Data.
-    m_record.user_data = point.GetUserData();
-    // For LAS 1.0 - User Bit Field; for LAS 1.1 - Point Source ID.
-    m_record.point_source_id = point.GetPointSourceID();
-
-    if (m_header.GetDataFormatId() == LASHeader::ePointFormat0)
-        m_pimpl->WritePointRecord(m_record);
-    else
-        m_pimpl->WritePointRecord(m_record, point.GetTime());
+    // m_record.x = static_cast<uint32_t>((point.GetX() - m_header.GetOffsetX()) / m_header.GetScaleX());
+    // m_record.y = static_cast<uint32_t>((point.GetY() - m_header.GetOffsetY()) / m_header.GetScaleY());
+    // m_record.z = static_cast<uint32_t>((point.GetZ() - m_header.GetOffsetZ()) / m_header.GetScaleZ());
+    // m_record.intensity = point.GetIntensity();
+    // m_record.flags = point.GetScanFlags();
+    // m_record.classification = point.GetClassification();
+    // m_record.scan_angle_rank = point.GetScanAngleRank();
+    // // For LAS 1.0 - File Marker; for LAS 1.1 - User Data.
+    // m_record.user_data = point.GetUserData();
+    // // For LAS 1.0 - User Bit Field; for LAS 1.1 - Point Source ID.
+    // m_record.point_source_id = point.GetPointSourceID();
+    // 
+    // if (m_header.GetDataFormatId() == LASHeader::ePointFormat0)
+        m_pimpl->WritePointRecord(point, m_header);
+    // else
+    //     m_pimpl->WritePointRecord(m_record, point.GetTime());
 
     return true;
 }


More information about the Liblas-commits mailing list