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

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Feb 10 15:15:04 EST 2009


Author: hobu
Date: Tue Feb 10 15:15:04 2009
New Revision: 1007
URL: http://liblas.org/changeset/1007

Log:
rework to use public LASColor class, 1.2 reading now works

Added:
   trunk/include/liblas/lascolor.hpp   (contents, props changed)
   trunk/src/lascolor.cpp   (contents, props changed)
Modified:
   trunk/include/liblas/detail/fwd.hpp
   trunk/include/liblas/detail/utility.hpp
   trunk/include/liblas/laspoint.hpp
   trunk/include/liblas/lasreader.hpp
   trunk/src/Makefile.am
   trunk/src/detail/reader10.cpp
   trunk/src/detail/reader11.cpp
   trunk/src/detail/reader12.cpp
   trunk/src/laspoint.cpp

Modified: trunk/include/liblas/detail/fwd.hpp
==============================================================================
--- trunk/include/liblas/detail/fwd.hpp	(original)
+++ trunk/include/liblas/detail/fwd.hpp	Tue Feb 10 15:15:04 2009
@@ -49,6 +49,7 @@
 class LASPoint;
 class LASReader;
 class LASWriter;
+class LASColor;
 
 namespace detail {
 

Modified: trunk/include/liblas/detail/utility.hpp
==============================================================================
--- trunk/include/liblas/detail/utility.hpp	(original)
+++ trunk/include/liblas/detail/utility.hpp	Tue Feb 10 15:15:04 2009
@@ -193,17 +193,6 @@
     uint16_t point_source_id; // 1.0: User Bit field / 1.1: Point Source ID
 };
 
-struct Color
-{
-    Color() :
-        red(0), blue(0), green(0) 
-    {}
-    
-    uint16_t red;
-    uint16_t blue;
-    uint16_t green;
-};
-
 template <typename T> 
 bool compare_distance(const T& actual, const T& expected);
 

Added: trunk/include/liblas/lascolor.hpp
==============================================================================
--- (empty file)
+++ trunk/include/liblas/lascolor.hpp	Tue Feb 10 15:15:04 2009
@@ -0,0 +1,157 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose:  LAS color class 
+ * Author:   Mateusz Loskot, mateusz at loskot.net
+ *
+ ******************************************************************************
+ * Copyright (c) 2008, Mateusz Loskot
+ *
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without 
+ * modification, are permitted provided that the following 
+ * conditions are met:
+ * 
+ *     * Redistributions of source code must retain the above copyright 
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright 
+ *       notice, this list of conditions and the following disclaimer in 
+ *       the documentation and/or other materials provided 
+ *       with the distribution.
+ *     * Neither the name of the Martin Isenburg or Iowa Department 
+ *       of Natural Resources nor the names of its contributors may be 
+ *       used to endorse or promote products derived from this software 
+ *       without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
+ * OF SUCH DAMAGE.
+ ****************************************************************************/
+
+#ifndef LIBLAS_LASCOLOR_HPP_INCLUDED
+#define LIBLAS_LASCOLOR_HPP_INCLUDED
+
+#include <liblas/cstdint.hpp>
+#include <liblas/detail/fwd.hpp>
+#include <liblas/detail/utility.hpp>
+// std
+#include <stdexcept> // std::out_of_range
+#include <cstdlib> // std::size_t
+
+namespace liblas {
+
+/// RGB color container
+class LASColor
+{
+public:
+
+    LASColor();
+    LASColor(LASColor const& other);
+    LASColor& operator=(LASColor const& rhs);
+    
+    /// Fetch value of the red image channel 
+    uint16_t GetRed() const;
+
+    /// Set value of the red image channel 
+    void SetRed(uint16_t const& value);
+
+    /// Fetch value of the blue image channel 
+    uint16_t GetBlue() const;
+
+    /// Set value of the blue image channel 
+    void SetBlue(uint16_t const& value);
+
+    /// Fetch value of the green image channel 
+    uint16_t GetGreen() const;
+
+    /// Set value of the red image channel 
+    void SetGreen(uint16_t const& value);
+
+    /// Index operator providing access to RGB values.
+    /// Valid index values are 0, 1 or 2.
+    /// \exception std::out_of_range if requested index is out of range (> 2).
+    uint16_t& operator[](std::size_t const& n);
+
+    /// Const version of index operator providing access to RGB values.
+    /// Valid index values are 0, 1 or 2.
+    /// \exception std::out_of_range if requested index is out of range (> 2).
+    uint16_t const& operator[](std::size_t const& n) const;    
+
+private:
+
+    
+    uint16_t m_red;
+    uint16_t m_green;
+    uint16_t m_blue;
+    
+    void throw_out_of_range() const
+    {
+        throw std::out_of_range("subscript out of range");
+    }
+};
+
+
+
+inline uint16_t LASColor::GetRed() const
+{
+    return m_red;
+}
+
+inline void LASColor::SetRed(uint16_t const& value)
+{
+    m_red = value;
+}
+
+inline uint16_t LASColor::GetBlue() const
+{
+    return m_blue;
+}
+
+inline void LASColor::SetBlue(uint16_t const& value)
+{
+    m_blue = value;
+}
+
+inline uint16_t LASColor::GetGreen() const
+{
+    return m_green;
+}
+
+inline void LASColor::SetGreen(uint16_t const& value)
+{
+    m_green = value;
+}
+
+inline uint16_t& LASColor::operator[](std::size_t const& n)
+{
+    if (n == 0) { return m_red; }
+    if (n == 1) { return m_green; }
+    if (n == 2) { return m_blue; }
+
+    throw_out_of_range();
+
+}
+
+inline uint16_t const& LASColor::operator[](std::size_t const& n) const
+{
+    if (n == 0) { return m_red; }
+    if (n == 1) { return m_green; }
+    if (n == 2) { return m_blue; }
+
+    throw_out_of_range();
+}
+
+} // namespace liblas
+
+#endif // LIBLAS_LASCOLOR_HPP_INCLUDED

Modified: trunk/include/liblas/laspoint.hpp
==============================================================================
--- trunk/include/liblas/laspoint.hpp	(original)
+++ trunk/include/liblas/laspoint.hpp	Tue Feb 10 15:15:04 2009
@@ -45,6 +45,7 @@
 #include <liblas/cstdint.hpp>
 #include <liblas/detail/fwd.hpp>
 #include <liblas/detail/utility.hpp>
+#include <liblas/lascolor.hpp>
 // std
 #include <stdexcept> // std::out_of_range
 #include <cstdlib> // std::size_t
@@ -151,23 +152,12 @@
     /// Set value of User Bit Field (LAS 1.0) or Point Source ID (LAS 1.1).
     void SetPointSourceID(uint16_t const& id);
 
-    /// Fetch value of the red image channel value associated with this point (LAS 1.2)
-    uint16_t GetRed() const;
+    /// Fetch color value associated with this point (LAS 1.2)
+    LASColor const& GetColor() const;
 
-    /// Set value of the red image channel value associated with this point (LAS 1.2)
-    void SetRed(uint16_t const& value);
+    /// Set color value associated with this point (LAS 1.2)
+    void SetColor(LASColor const& value);
 
-    /// Fetch value of the blue image channel value associated with this point (LAS 1.2)
-    uint16_t GetBlue() const;
-
-    /// Set value of the blue image channel value associated with this point (LAS 1.2)
-    void SetBlue(uint16_t const& value);
-
-    /// Fetch value of the green image channel value associated with this point (LAS 1.2)
-    uint16_t GetGreen() const;
-
-    /// Set value of the red image channel value associated with this point (LAS 1.2)
-    void SetGreen(uint16_t const& value);
                 
     double GetTime() const;
     void SetTime(double const& time);
@@ -188,9 +178,7 @@
     bool Validate() const;
     bool IsValid() const;
     
-    /// Scale the coordinates by the Offset and Scale in the given header
-    void ScaleCoordinates(const LASHeader& header);
-    
+
 private:
 
     static std::size_t const coords_size = 3;
@@ -203,7 +191,7 @@
     uint16_t m_pointSourceId;
     double m_gpsTime;
     
-    detail::Color m_color;
+    LASColor m_color;
     detail::PointRecord m_rec;
     
     void throw_out_of_range() const
@@ -345,35 +333,16 @@
     m_gpsTime = time;
 }
 
-inline uint16_t LASPoint::GetRed() const
-{
-    return m_color.red;
-}
-
-inline void LASPoint::SetRed(uint16_t const& value)
+inline LASColor const& LASPoint::GetColor() const
 {
-    m_color.red = value;
+    return m_color;
 }
 
-inline uint16_t LASPoint::GetBlue() const
+inline void LASPoint::SetColor(LASColor const& value)
 {
-    return m_color.blue;
+    m_color = value;
 }
 
-inline void LASPoint::SetBlue(uint16_t const& value)
-{
-    m_color.blue = value;
-}
-
-inline uint16_t LASPoint::GetGreen() const
-{
-    return m_color.green;
-}
-
-inline void LASPoint::SetGreen(uint16_t const& value)
-{
-    m_color.green = value;
-}
 
 inline double& LASPoint::operator[](std::size_t const& n)
 {

Modified: trunk/include/liblas/lasreader.hpp
==============================================================================
--- trunk/include/liblas/lasreader.hpp	(original)
+++ trunk/include/liblas/lasreader.hpp	Tue Feb 10 15:15:04 2009
@@ -90,13 +90,10 @@
     void Init(); // throws on error
     void MakePIMPL(std::istream& ifs);
 
-    void MakePoint(double const& time);
-
     // TODO: Consider restoring const keyword and improving idea of re-assignment (see MakePIMPL).
     std::auto_ptr<detail::Reader> m_pimpl;
     LASHeader m_header;
     LASPoint m_point;
-//    detail::PointRecord m_record;
     std::vector<LASVLR> m_vlrs;
 
 };

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Tue Feb 10 15:15:04 2009
@@ -18,6 +18,7 @@
 	laswriter.cpp \
 	lasfile.cpp \
 	las_c_api.cpp \
+	lascolor.cpp \
     detail/reader.cpp \
     detail/reader10.cpp \
     detail/reader11.cpp \

Modified: trunk/src/detail/reader10.cpp
==============================================================================
--- trunk/src/detail/reader10.cpp	(original)
+++ trunk/src/detail/reader10.cpp	Tue Feb 10 15:15:04 2009
@@ -342,7 +342,7 @@
         }
 
         Reader::FillPoint(record, point);
-        point.ScaleCoordinates(header);
+        point.SetCoordinates(header, point.GetX(), point.GetY(), point.GetZ());
         
         if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
             detail::read_n(t, m_ifs, sizeof(double));
@@ -373,7 +373,8 @@
     detail::read_n(record, m_ifs, sizeof(record));
 
     Reader::FillPoint(record, point);
-    point.ScaleCoordinates(header);
+    point.SetCoordinates(header, point.GetX(), point.GetY(), point.GetZ());
+
     
     if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
         detail::read_n(t, m_ifs, sizeof(double));

Modified: trunk/src/detail/reader11.cpp
==============================================================================
--- trunk/src/detail/reader11.cpp	(original)
+++ trunk/src/detail/reader11.cpp	Tue Feb 10 15:15:04 2009
@@ -255,7 +255,7 @@
         }
 
         Reader::FillPoint(record, point);
-        point.ScaleCoordinates(header);
+        point.SetCoordinates(header, point.GetX(), point.GetY(), point.GetZ());
     
         if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
             detail::read_n(t, m_ifs, sizeof(double));
@@ -288,7 +288,7 @@
     detail::read_n(record, m_ifs, sizeof(record));
 
     Reader::FillPoint(record, point);
-    point.ScaleCoordinates(header);
+    point.SetCoordinates(header, point.GetX(), point.GetY(), point.GetZ());
     
     if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
         detail::read_n(t, m_ifs, sizeof(double));

Modified: trunk/src/detail/reader12.cpp
==============================================================================
--- trunk/src/detail/reader12.cpp	(original)
+++ trunk/src/detail/reader12.cpp	Tue Feb 10 15:15:04 2009
@@ -45,6 +45,7 @@
 #include <liblas/lasheader.hpp>
 #include <liblas/laspoint.hpp>
 #include <liblas/lasrecordheader.hpp>
+#include <liblas/lascolor.hpp>
 // GeoTIFF
 #ifdef HAVE_LIBGEOTIFF
 #include <geotiff.h>
@@ -232,6 +233,11 @@
     // TODO: Replace with compile-time assert
 
     double t = 0;
+    uint16_t red = 0;
+    uint16_t blue = 0;
+    uint16_t green = 0;
+    LASColor color;
+
     detail::PointRecord record;
     assert(LASHeader::ePointSize0 == sizeof(record));
 
@@ -255,14 +261,32 @@
         }
         
         Reader::FillPoint(record, point);
-        point.ScaleCoordinates(header);
-    
-        // TODO: not working yet for the various point formats
-        // if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
-        //     detail::read_n(t, m_ifs, sizeof(double));
-        //     point.SetTime(t);
-        // }
-        
+        point.SetCoordinates(header, point.GetX(), point.GetY(), point.GetZ());
+
+        if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
+            detail::read_n(t, m_ifs, sizeof(double));
+            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));
+            color.SetRed(red);
+            color.SetBlue(blue);
+            color.SetGreen(green);
+            point.SetColor(color);
+        } else if (header.GetDataFormatId() == LASHeader::ePointFormat3) {
+            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));
+            color.SetRed(red);
+            color.SetBlue(blue);
+            color.SetGreen(green);
+            point.SetColor(color);
+        }
+             
+                
         return true;
     }
 
@@ -276,6 +300,11 @@
     // TODO: Replace with compile-time assert
     
     double t = 0;
+    uint16_t red = 0;
+    uint16_t blue = 0;
+    uint16_t green = 0;
+    LASColor color;
+
     detail::PointRecord record;
     assert(LASHeader::ePointSize0 == sizeof(record));
 
@@ -289,12 +318,31 @@
     detail::read_n(record, m_ifs, sizeof(record));
 
     Reader::FillPoint(record, point);
-    point.ScaleCoordinates(header);
+    point.SetCoordinates(header, point.GetX(), point.GetY(), point.GetZ());
 
     if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
         detail::read_n(t, m_ifs, sizeof(double));
         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));
+        color.SetRed(red);
+        color.SetBlue(blue);
+        color.SetGreen(green);
+        point.SetColor(color);
+    } else if (header.GetDataFormatId() == LASHeader::ePointFormat3) {
+        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));
+        color.SetRed(red);
+        color.SetBlue(blue);
+        color.SetGreen(green);
+        point.SetColor(color);
     }
+             
         
     return true;
 }

Added: trunk/src/lascolor.cpp
==============================================================================
--- (empty file)
+++ trunk/src/lascolor.cpp	Tue Feb 10 15:15:04 2009
@@ -0,0 +1,77 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose:  LAS color class 
+ * Author:   Mateusz Loskot, mateusz at loskot.net
+ *
+ ******************************************************************************
+ * Copyright (c) 2008, Mateusz Loskot
+ *
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without 
+ * modification, are permitted provided that the following 
+ * conditions are met:
+ * 
+ *     * Redistributions of source code must retain the above copyright 
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright 
+ *       notice, this list of conditions and the following disclaimer in 
+ *       the documentation and/or other materials provided 
+ *       with the distribution.
+ *     * Neither the name of the Martin Isenburg or Iowa Department 
+ *       of Natural Resources nor the names of its contributors may be 
+ *       used to endorse or promote products derived from this software 
+ *       without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
+ * OF SUCH DAMAGE.
+ ****************************************************************************/
+
+#include <liblas/lascolor.hpp>
+#include <liblas/cstdint.hpp>
+
+// std
+#include <cstring>
+
+namespace liblas {
+
+LASColor::LASColor() :
+    m_red(0),
+    m_green(0),
+    m_blue(0)
+{
+}
+
+LASColor::LASColor(LASColor const& other) :
+    m_red(other.m_red),
+    m_green(other.m_green),
+    m_blue(other.m_blue)
+{
+}
+
+LASColor& LASColor::operator=(LASColor const& rhs)
+{
+    if (&rhs != this)
+    {
+        m_red = rhs.m_red;
+        m_green = rhs.m_green;
+        m_blue = rhs.m_blue;
+    }
+    return *this;
+}
+
+
+
+} // namespace liblas

Modified: trunk/src/laspoint.cpp
==============================================================================
--- trunk/src/laspoint.cpp	(original)
+++ trunk/src/laspoint.cpp	Tue Feb 10 15:15:04 2009
@@ -59,9 +59,6 @@
     m_gpsTime(0)
 {
     std::memset(m_coords, 0, sizeof(m_coords));
-    m_color.red = 0;
-    m_color.blue = 0;
-    m_color.green = 0;    
 }
 
 LASPoint::LASPoint(LASPoint const& other) :
@@ -74,9 +71,6 @@
     m_gpsTime(other.m_gpsTime)
 {
     std::memcpy(m_coords, other.m_coords, sizeof(m_coords));
-    m_color.red = other.m_color.red;
-    m_color.blue = other.m_color.blue;
-    m_color.green = other.m_color.green;
 }
 
 LASPoint& LASPoint::operator=(LASPoint const& rhs)
@@ -93,9 +87,6 @@
         m_userData = rhs.m_userData;
         m_pointSourceId = rhs.m_pointSourceId;
         m_gpsTime = rhs.m_gpsTime;
-        m_color.red = rhs.m_color.red;
-        m_color.blue = rhs.m_color.blue;
-        m_color.green = rhs.m_color.green;
     }
     return *this;
 }
@@ -237,15 +228,5 @@
     return true;
 }
 
-void LASPoint::ScaleCoordinates(const LASHeader& header) 
-{
-
-    double const x = GetX() * header.GetScaleX() + header.GetOffsetX();
-    double const y = GetY() * header.GetScaleY() + header.GetOffsetY();
-    double const z = GetZ() * header.GetScaleZ() + header.GetOffsetZ();
-     
-    SetCoordinates(x, y, z);
-        
-}
 
 } // namespace liblas


More information about the Liblas-commits mailing list