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

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Feb 11 10:49:17 EST 2009


Author: hobu
Date: Wed Feb 11 10:49:17 2009
New Revision: 1013
URL: http://liblas.org/changeset/1013

Log:
remove redundant GetStream and move ostream into abstract Writer:: class

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/writer.cpp
   trunk/src/detail/writer10.cpp
   trunk/src/detail/writer11.cpp
   trunk/src/detail/writer12.cpp

Modified: trunk/include/liblas/detail/writer.hpp
==============================================================================
--- trunk/include/liblas/detail/writer.hpp	(original)
+++ trunk/include/liblas/detail/writer.hpp	Wed Feb 11 10:49:17 2009
@@ -54,24 +54,30 @@
 {
 public:
 
-    Writer();
+    Writer(std::ostream& ofs);
     virtual ~Writer();
     virtual std::size_t GetVersion() const = 0;
     virtual void WriteHeader(LASHeader& header) = 0;
     virtual void UpdateHeader(LASHeader const& header) = 0;
     virtual void WritePointRecord(LASPoint const& point, const LASHeader& header) = 0;
     virtual void WriteVLR(LASHeader const& header) = 0;
-    virtual std::ostream& GetStream() const = 0;
+    std::ostream& GetStream() const;
+    void SetStream(std::ostream& stream);
 
 protected:
     PointRecord m_record;
+    std::ostream& m_ofs;
+
     void FillPointRecord(PointRecord& record, const LASPoint& point, const LASHeader& header);
 
+
 private:
 
     // Blocked copying operations, declared but not defined.
     Writer(Writer const& other);
     Writer& operator=(Writer const& rhs);
+
+    
 };
 
 class WriterFactory

Modified: trunk/include/liblas/detail/writer10.hpp
==============================================================================
--- trunk/include/liblas/detail/writer10.hpp	(original)
+++ trunk/include/liblas/detail/writer10.hpp	Wed Feb 11 10:49:17 2009
@@ -61,13 +61,10 @@
     void WriteHeader(LASHeader& header);
     void UpdateHeader(LASHeader const& header);
     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;
 
 private:
 
-    std::ostream& m_ofs;
     liblas::uint32_t m_pointCount;
 };
 

Modified: trunk/include/liblas/detail/writer11.hpp
==============================================================================
--- trunk/include/liblas/detail/writer11.hpp	(original)
+++ trunk/include/liblas/detail/writer11.hpp	Wed Feb 11 10:49:17 2009
@@ -62,11 +62,9 @@
     void UpdateHeader(LASHeader const& header);
     void WritePointRecord(LASPoint const& record, const LASHeader& header);
     void WriteVLR(LASHeader const& header);
-    std::ostream& GetStream() const;
     
 private:
-
-    std::ostream& m_ofs;
+    
     liblas::uint32_t m_pointCount;
 };
 

Modified: trunk/include/liblas/detail/writer12.hpp
==============================================================================
--- trunk/include/liblas/detail/writer12.hpp	(original)
+++ trunk/include/liblas/detail/writer12.hpp	Wed Feb 11 10:49:17 2009
@@ -62,11 +62,9 @@
     void UpdateHeader(LASHeader const& header);
     void WritePointRecord(LASPoint const& record, const LASHeader& header);
     void WriteVLR(LASHeader const& header);
-    std::ostream& GetStream() const;
     
 private:
 
-    std::ostream& m_ofs;
     liblas::uint32_t m_pointCount;
 };
 

Modified: trunk/src/detail/writer.cpp
==============================================================================
--- trunk/src/detail/writer.cpp	(original)
+++ trunk/src/detail/writer.cpp	Wed Feb 11 10:49:17 2009
@@ -53,7 +53,7 @@
 
 namespace liblas { namespace detail {
 
-Writer::Writer()
+Writer::Writer(std::ostream& ofs) : m_ofs(ofs)
 {
 }
 
@@ -61,11 +61,16 @@
 {
 }
 
+std::ostream& Writer::GetStream() const
+{
+    return m_ofs;
+}
+
 void Writer::FillPointRecord(PointRecord& record, const LASPoint& point, const LASHeader& header) 
 {
-    record.x = static_cast<uint32_t>((point.GetX() - header.GetOffsetX()) / header.GetScaleX());
-    record.y = static_cast<uint32_t>((point.GetY() - header.GetOffsetY()) / header.GetScaleY());
-    record.z = static_cast<uint32_t>((point.GetZ() - header.GetOffsetZ()) / header.GetScaleZ());
+    record.x = static_cast<int32_t>((point.GetX() - header.GetOffsetX()) / header.GetScaleX());
+    record.y = static_cast<int32_t>((point.GetY() - header.GetOffsetY()) / header.GetScaleY());
+    record.z = static_cast<int32_t>((point.GetZ() - header.GetOffsetZ()) / header.GetScaleZ());
     record.intensity = point.GetIntensity();
     record.flags = point.GetScanFlags();
     record.classification = point.GetClassification();
@@ -73,6 +78,26 @@
     record.user_data = point.GetUserData();
     record.point_source_id = point.GetPointSourceID();
 }
+
+void Writer::WriteVLR(LASHeader const& header) 
+{
+    m_ofs.seekp(header.GetHeaderSize(), std::ios::beg);
+
+    for (uint32_t i = 0; i < header.GetRecordsCount(); ++i)
+    {
+        LASVLR vlr = header.GetVLR(i);
+
+        detail::write_n(m_ofs, vlr.GetReserved(), sizeof(uint16_t));
+        detail::write_n(m_ofs, vlr.GetUserId(true).c_str(), 16);
+        detail::write_n(m_ofs, vlr.GetRecordId(), sizeof(uint16_t));
+        detail::write_n(m_ofs, vlr.GetRecordLength(), sizeof(uint16_t));
+        detail::write_n(m_ofs, vlr.GetDescription(true).c_str(), 32);
+        std::vector<uint8_t> const& data = vlr.GetData();
+        std::streamsize const size = static_cast<std::streamsize>(data.size());
+        detail::write_n(m_ofs, data.front(), size);
+    }
+}
+
 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	Wed Feb 11 10:49:17 2009
@@ -54,7 +54,7 @@
 namespace liblas { namespace detail { namespace v10 {
 
 WriterImpl::WriterImpl(std::ostream& ofs) :
-    Base(), m_ofs(ofs), m_pointCount(0)
+    Base(ofs), m_pointCount(0)
 {
 }
 
@@ -243,17 +243,6 @@
     ++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::WriteVLR(LASHeader const& header) 
 {
     m_ofs.seekp(header.GetHeaderSize(), std::ios::beg);
@@ -273,9 +262,5 @@
     }
 }
 
-std::ostream& WriterImpl::GetStream() const
-{
-    return m_ofs;
-}
 
 }}} // namespace liblas::detail::v10

Modified: trunk/src/detail/writer11.cpp
==============================================================================
--- trunk/src/detail/writer11.cpp	(original)
+++ trunk/src/detail/writer11.cpp	Wed Feb 11 10:49:17 2009
@@ -54,7 +54,7 @@
 namespace liblas { namespace detail { namespace v11 {
 
 WriterImpl::WriterImpl(std::ostream& ofs) :
-    Base(), m_ofs(ofs), m_pointCount(0)
+    Base(ofs), m_pointCount(0)
 {
 }
 
@@ -244,16 +244,6 @@
     ++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::WriteVLR(LASHeader const& header) 
 {
@@ -274,10 +264,5 @@
     }
 }
 
-std::ostream& WriterImpl::GetStream() const
-{
-    return m_ofs;
-}
-
 }}} // namespace liblas::detail::v11
 

Modified: trunk/src/detail/writer12.cpp
==============================================================================
--- trunk/src/detail/writer12.cpp	(original)
+++ trunk/src/detail/writer12.cpp	Wed Feb 11 10:49:17 2009
@@ -54,7 +54,7 @@
 namespace liblas { namespace detail { namespace v12 {
 
 WriterImpl::WriterImpl(std::ostream& ofs) :
-    Base(), m_ofs(ofs), m_pointCount(0)
+    Base(ofs), m_pointCount(0)
 {
 }
 
@@ -269,18 +269,6 @@
     ++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::WriteVLR(LASHeader const& header) 
 {
     m_ofs.seekp(header.GetHeaderSize(), std::ios::beg);
@@ -300,10 +288,6 @@
     }
 }
 
-std::ostream& WriterImpl::GetStream() const
-{
-    return m_ofs;
-}
 
 }}} // namespace liblas::detail::v12
 


More information about the Liblas-commits mailing list