[Liblas-commits] r1211 - in trunk: build/msvc90/las2las build/msvc90/las2txt build/msvc90/lasinfo build/msvc90/lasmerge build/msvc90/liblas_c_dll build/msvc90/liblas_lib build/msvc90/liblas_test build/msvc90/txt2las include include/liblas src src/detail test/unit

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Apr 16 09:17:43 EDT 2009


Author: mloskot
Date: Thu Apr 16 09:17:43 2009
New Revision: 1211
URL: http://liblas.org/changeset/1211

Log:
* Added new class LASClassification based on the idea explained in Ticket #131.
* Added corresponding unit test as test/unit/lasclassification_test,cpp.
* Updated all other parts that read/write classification properties.
* Updated build/msvc90 project.
* Updated test/unit/Makefile.am and include/Makefile.am.

Added:
   trunk/include/liblas/lasclassification.hpp
   trunk/test/unit/lasclassification_test.cpp
Modified:
   trunk/build/msvc90/las2las/las2las.vcproj
   trunk/build/msvc90/las2txt/las2txt.vcproj
   trunk/build/msvc90/lasinfo/lasinfo.vcproj
   trunk/build/msvc90/lasmerge/lasmerge.vcproj
   trunk/build/msvc90/liblas_c_dll/liblas_c_dll.vcproj
   trunk/build/msvc90/liblas_lib/liblas_lib.vcproj
   trunk/build/msvc90/liblas_test/liblas_test.vcproj
   trunk/build/msvc90/txt2las/txt2las.vcproj
   trunk/include/Makefile.am
   trunk/include/liblas/laspoint.hpp
   trunk/src/detail/reader.cpp
   trunk/src/detail/writer.cpp
   trunk/src/las_c_api.cpp
   trunk/src/laspoint.cpp
   trunk/test/unit/Makefile.am
   trunk/test/unit/common.cpp
   trunk/test/unit/laspoint_test.cpp
   trunk/test/unit/lasreader_iterator_test.cpp
   trunk/test/unit/laswriter_test.cpp

Modified: trunk/build/msvc90/las2las/las2las.vcproj
==============================================================================
--- trunk/build/msvc90/las2las/las2las.vcproj	(original)
+++ trunk/build/msvc90/las2las/las2las.vcproj	Thu Apr 16 09:17:43 2009
@@ -49,7 +49,7 @@
 				RuntimeLibrary="3"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
-				Detect64BitPortabilityProblems="true"
+				Detect64BitPortabilityProblems="false"
 				DebugInformationFormat="4"
 			/>
 			<Tool

Modified: trunk/build/msvc90/las2txt/las2txt.vcproj
==============================================================================
--- trunk/build/msvc90/las2txt/las2txt.vcproj	(original)
+++ trunk/build/msvc90/las2txt/las2txt.vcproj	Thu Apr 16 09:17:43 2009
@@ -49,7 +49,6 @@
 				RuntimeLibrary="3"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
-				Detect64BitPortabilityProblems="true"
 				DebugInformationFormat="4"
 			/>
 			<Tool

Modified: trunk/build/msvc90/lasinfo/lasinfo.vcproj
==============================================================================
--- trunk/build/msvc90/lasinfo/lasinfo.vcproj	(original)
+++ trunk/build/msvc90/lasinfo/lasinfo.vcproj	Thu Apr 16 09:17:43 2009
@@ -49,7 +49,6 @@
 				RuntimeLibrary="3"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
-				Detect64BitPortabilityProblems="true"
 				DebugInformationFormat="4"
 			/>
 			<Tool

Modified: trunk/build/msvc90/lasmerge/lasmerge.vcproj
==============================================================================
--- trunk/build/msvc90/lasmerge/lasmerge.vcproj	(original)
+++ trunk/build/msvc90/lasmerge/lasmerge.vcproj	Thu Apr 16 09:17:43 2009
@@ -49,7 +49,6 @@
 				RuntimeLibrary="3"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
-				Detect64BitPortabilityProblems="true"
 				DebugInformationFormat="4"
 			/>
 			<Tool

Modified: trunk/build/msvc90/liblas_c_dll/liblas_c_dll.vcproj
==============================================================================
--- trunk/build/msvc90/liblas_c_dll/liblas_c_dll.vcproj	(original)
+++ trunk/build/msvc90/liblas_c_dll/liblas_c_dll.vcproj	Thu Apr 16 09:17:43 2009
@@ -48,7 +48,6 @@
 				RuntimeLibrary="3"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
-				Detect64BitPortabilityProblems="true"
 				DebugInformationFormat="4"
 			/>
 			<Tool

Modified: trunk/build/msvc90/liblas_lib/liblas_lib.vcproj
==============================================================================
--- trunk/build/msvc90/liblas_lib/liblas_lib.vcproj	(original)
+++ trunk/build/msvc90/liblas_lib/liblas_lib.vcproj	Thu Apr 16 09:17:43 2009
@@ -50,7 +50,6 @@
 				DisableLanguageExtensions="true"
 				UsePrecompiledHeader="0"
 				WarningLevel="4"
-				Detect64BitPortabilityProblems="true"
 				DebugInformationFormat="4"
 			/>
 			<Tool
@@ -173,6 +172,10 @@
 					>
 				</File>
 				<File
+					RelativePath="..\..\..\include\liblas\lasclassification.hpp"
+					>
+				</File>
+				<File
 					RelativePath="..\..\..\include\liblas\lascolor.hpp"
 					>
 				</File>

Modified: trunk/build/msvc90/liblas_test/liblas_test.vcproj
==============================================================================
--- trunk/build/msvc90/liblas_test/liblas_test.vcproj	(original)
+++ trunk/build/msvc90/liblas_test/liblas_test.vcproj	Thu Apr 16 09:17:43 2009
@@ -50,7 +50,6 @@
 				DisableLanguageExtensions="false"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
-				Detect64BitPortabilityProblems="true"
 				DebugInformationFormat="4"
 			/>
 			<Tool
@@ -194,6 +193,10 @@
 			</File>
 		</Filter>
 		<File
+			RelativePath="..\..\..\test\unit\CMakeLists.txt"
+			>
+		</File>
+		<File
 			RelativePath="..\..\..\test\unit\common.cpp"
 			>
 		</File>
@@ -206,6 +209,10 @@
 			>
 		</File>
 		<File
+			RelativePath="..\..\..\test\unit\lasclassification_test.cpp"
+			>
+		</File>
+		<File
 			RelativePath="..\..\..\test\unit\laserror_test.cpp"
 			>
 		</File>
@@ -230,6 +237,10 @@
 			>
 		</File>
 		<File
+			RelativePath="..\..\..\test\unit\lasspatialreference_test.cpp"
+			>
+		</File>
+		<File
 			RelativePath="..\..\..\test\unit\lasvariablerecord_test.cpp"
 			>
 		</File>
@@ -245,6 +256,10 @@
 			RelativePath="..\..\..\test\unit\liblas_test_suite.cpp"
 			>
 		</File>
+		<File
+			RelativePath="..\..\..\test\unit\Makefile.am"
+			>
+		</File>
 	</Files>
 	<Globals>
 	</Globals>

Modified: trunk/build/msvc90/txt2las/txt2las.vcproj
==============================================================================
--- trunk/build/msvc90/txt2las/txt2las.vcproj	(original)
+++ trunk/build/msvc90/txt2las/txt2las.vcproj	Thu Apr 16 09:17:43 2009
@@ -49,7 +49,6 @@
 				RuntimeLibrary="3"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
-				Detect64BitPortabilityProblems="true"
 				DebugInformationFormat="4"
 			/>
 			<Tool

Modified: trunk/include/Makefile.am
==============================================================================
--- trunk/include/Makefile.am	(original)
+++ trunk/include/Makefile.am	Thu Apr 16 09:17:43 2009
@@ -1,34 +1,36 @@
 lasdir = $(includedir)
 
-nobase_las_HEADERS =		liblas/cstdint.hpp \
-                    liblas/exception.hpp \
-					    liblas/guid.hpp \
-					    liblas/iterator.hpp \
-					    liblas/lascolor.hpp \
-					    liblas/laserror.hpp \
-					    liblas/lasfile.hpp \
-					    liblas/lasheader.hpp \
-					    liblas/laspoint.hpp \
-					    liblas/lasreader.hpp \
-					    liblas/lasvariablerecord.hpp \
-					    liblas/lasspatialreference.hpp \
-					    liblas/laswriter.hpp \
-					    liblas/liblas.hpp \
-					    liblas/capi/liblas.h \
-					    liblas/capi/las_version.h \
-					    liblas/capi/las_config.h \
-					    liblas/detail/endian.hpp \
-					    liblas/detail/file.hpp \
-					    liblas/detail/fwd.hpp \
-					    liblas/detail/reader.hpp \
-					    liblas/detail/reader10.hpp \
-					    liblas/detail/reader11.hpp \
-						liblas/detail/reader12.hpp \
-					    liblas/detail/sha1.hpp \
-					    liblas/detail/sharedptr.hpp \
-					    liblas/detail/timer.hpp \
-					    liblas/detail/utility.hpp \
-					    liblas/detail/writer.hpp \
-					    liblas/detail/writer10.hpp \
-					    liblas/detail/writer11.hpp \
-						liblas/detail/writer12.hpp
\ No newline at end of file
+nobase_las_HEADERS = \
+    liblas/cstdint.hpp \
+    liblas/exception.hpp \
+    liblas/guid.hpp \
+    liblas/iterator.hpp \
+    liblas/lasclassification.hpp \					    
+    liblas/lascolor.hpp \
+    liblas/laserror.hpp \
+    liblas/lasfile.hpp \
+    liblas/lasheader.hpp \
+    liblas/laspoint.hpp \
+    liblas/lasreader.hpp \
+    liblas/lasvariablerecord.hpp \
+    liblas/lasspatialreference.hpp \
+    liblas/laswriter.hpp \
+    liblas/liblas.hpp \
+    liblas/capi/liblas.h \
+    liblas/capi/las_version.h \
+    liblas/capi/las_config.h \
+    liblas/detail/endian.hpp \
+    liblas/detail/file.hpp \
+    liblas/detail/fwd.hpp \
+    liblas/detail/reader.hpp \
+    liblas/detail/reader10.hpp \
+    liblas/detail/reader11.hpp \
+    liblas/detail/reader12.hpp \
+    liblas/detail/sha1.hpp \
+    liblas/detail/sharedptr.hpp \
+    liblas/detail/timer.hpp \
+    liblas/detail/utility.hpp \
+    liblas/detail/writer.hpp \
+    liblas/detail/writer10.hpp \
+    liblas/detail/writer11.hpp \
+    liblas/detail/writer12.hpp
\ No newline at end of file

Added: trunk/include/liblas/lasclassification.hpp
==============================================================================
--- (empty file)
+++ trunk/include/liblas/lasclassification.hpp	Thu Apr 16 09:17:43 2009
@@ -0,0 +1,227 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose:  Definition LASClassification type.
+ * Author:   Mateusz Loskot, mateusz at loskot.net
+ *
+ ******************************************************************************
+ * Copyright (c) 2009, 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_LASCLASSIFICATION_HPP_INCLUDED
+#define LIBLAS_LASCLASSIFICATION_HPP_INCLUDED
+
+#include <liblas/cstdint.hpp>
+// std
+#include <cassert>
+#include <cstddef>
+#include <bitset>
+#include <ostream>
+#include <sstream>
+#include <stdexcept>
+
+namespace liblas {
+
+/// Class definition to manipulate properties of point record classification.
+///
+class LASClassification
+{
+public:
+
+    ///
+    typedef std::bitset<8> bitset_type;
+
+    /// Number of classes in lookup table as defined in ASPRS LAS 1.1+.
+    /// For LAS 1.0, this static number may be invalid and
+    /// extend up to 255 classes stored in variable-length records.
+    static std::size_t const class_table_size = 32;
+
+    enum
+    {
+        eClassBit     = 0, /// First bit position of 0:4 range.
+        eSyntheticBit = 5, /// Synthetic flag.
+        eKeyPointBit  = 6, /// Key-point flag.
+        eWithheldBit  = 7  /// Withheld flag.
+    };
+
+    /// Default initialization constructor.
+    /// Initializes all flags of classification not set.
+    /// Operation semantic is equivalent to bitset_type::reset().
+    LASClassification() {}
+
+    /// Initializes classification with given set of 8 flags.
+    explicit LASClassification(bitset_type flags)
+        : m_flags(flags)
+    {}
+
+    /// Initializes classification from flags given as integral type.
+    explicit LASClassification(uint8_t flags)
+        : m_flags(flags)
+    {}
+
+    /// Initializes classification with values of given compounds.
+    LASClassification(uint8_t cls, bool s, bool k, bool w)
+    {
+        SetClass(cls);
+        SetSynthetic(s);
+        SetKeyPoint(k);
+        SetWithheld(w);
+    }
+
+    LASClassification(LASClassification const& other)
+    {
+        m_flags = other.m_flags;
+    }
+
+    LASClassification& operator=(LASClassification const& rhs)
+    {
+        if (&rhs != this )
+        {    
+            m_flags = rhs.m_flags;
+        }
+        return *this;
+    }
+
+    /// Conversion operator.
+    /// Returns classification object as flags encoded in form of std::bitset<8>.
+    operator bitset_type() const
+    {
+        return bitset_type(m_flags);
+    }
+
+    /// Raturns name of class as defined in LAS 1.1+
+    /// Finds class name in lookup table based on class index
+    /// as defined in classification object.
+    std::string GetClassName() const
+    {
+        return std::string("");
+    }
+
+    uint8_t GetClass() const
+    {
+        bitset_type bits(m_flags);
+        bitset_type mask(class_table_size - 1);
+        bits &= mask;
+        return (static_cast<uint8_t>(bits.to_ulong()));
+    }
+
+    void SetClass(uint8_t index)
+    {
+        check_class_index(index);
+
+        uint8_t flags = static_cast<uint8_t>(m_flags.to_ulong());
+        uint8_t const mask = 0x1F << 0; // 0b00011111
+        flags &= ~mask;
+        flags |= mask & (static_cast<uint8_t>(index) << 0);
+        m_flags = bitset_type(flags);
+    }
+
+    void SetSynthetic(bool flag)
+    {
+        m_flags[eSyntheticBit] = flag;
+    }
+
+    bool IsSynthetic() const
+    {
+        return m_flags[eSyntheticBit];
+    }
+
+    void SetKeyPoint(bool flag)
+    {
+        m_flags[eKeyPointBit] = flag;
+    }
+
+    bool IsKeyPoint() const
+    {
+        return m_flags[eKeyPointBit];
+    }
+
+    void SetWithheld(bool flag)
+    {
+        m_flags[eWithheldBit] = flag;
+    }
+
+    bool IsWithheld() const
+    {
+        return m_flags[eWithheldBit];
+    }
+
+    bool equal(LASClassification const& other) const
+    {
+        return (other.m_flags == m_flags);
+    }
+
+private:
+
+    bitset_type m_flags;
+
+    void check_class_index(std::size_t index)
+    {
+        if (index > (class_table_size - 1))
+        {
+            std::ostringstream oss;
+            oss << "given index is " << index
+                << ", but must fit between 0 and " << (class_table_size - 1);
+            throw std::out_of_range(oss.str());
+        }
+    }
+};
+
+inline bool operator==(LASClassification const& lhs, LASClassification const& rhs)
+{
+    return lhs.equal(rhs);
+}
+
+inline bool operator!=(LASClassification const& lhs, LASClassification const& rhs)
+{
+    return (!(lhs == rhs));
+}
+
+/// The output stream operator is based on std::bitset<N>::operator<<.
+/// It outputs classification flags in form of string.
+/// Effects promised as by Standard for Programming Language C++, 23.3.5.2:
+/// Each character is determined by the value of its corresponding bit
+/// position in *this. Character position N - 1 corresponds to bit position
+/// zero. Subsequent decreasing character positions correspond to increasing
+/// bit positions. Bit value zero becomes the character 0, bit value one
+/// becomes the character 1.
+inline std::ostream& operator<<(std::ostream& os, LASClassification const& cls)
+{
+    LASClassification::bitset_type flags(cls);
+    return (os << flags);
+}
+
+} // namespace liblas
+
+#endif // LIBLAS_LASCLASSIFICATION_HPP_INCLUDED

Modified: trunk/include/liblas/laspoint.hpp
==============================================================================
--- trunk/include/liblas/laspoint.hpp	(original)
+++ trunk/include/liblas/laspoint.hpp	Thu Apr 16 09:17:43 2009
@@ -45,6 +45,7 @@
 #include <liblas/cstdint.hpp>
 #include <liblas/detail/fwd.hpp>
 #include <liblas/detail/utility.hpp>
+#include <liblas/lasclassification.hpp>
 #include <liblas/lascolor.hpp>
 // std
 #include <stdexcept> // std::out_of_range
@@ -134,8 +135,11 @@
     uint16_t GetFlightLineEdge() const;
     void SetFlightLineEdge(uint16_t const& edge);
 
-    uint8_t GetClassification() const;
-    void SetClassification(uint8_t const& classify);
+    //LASClassification& GetClassification();
+    LASClassification const& GetClassification() const;
+    void SetClassification(LASClassification const& cls);
+    void SetClassification(LASClassification::bitset_type const& flags);
+    void SetClassification(liblas::uint8_t const& flags);
 
     int8_t GetScanAngleRank() const;
     void SetScanAngleRank(int8_t const& rank);
@@ -182,18 +186,18 @@
 private:
 
     static std::size_t const coords_size = 3;
+
+    detail::PointRecord m_rec;
     double m_coords[coords_size];
+    double m_gpsTime;
+    LASColor m_color;
+    LASClassification m_cls;
     uint16_t m_intensity;
+    uint16_t m_pointSourceId;
     uint8_t m_flags;
-    uint8_t m_class;
-    int8_t m_angleRank;
     uint8_t m_userData;
-    uint16_t m_pointSourceId;
-    double m_gpsTime;
-    
-    LASColor m_color;
-    detail::PointRecord m_rec;
-    
+    int8_t m_angleRank;
+
     void throw_out_of_range() const
     {
         throw std::out_of_range("coordinate subscript out of range");
@@ -293,16 +297,6 @@
     m_flags = flags;
 }
 
-inline uint8_t LASPoint::GetClassification() const
-{
-    return m_class;
-}
-
-inline void LASPoint::SetClassification(uint8_t const& classify)
-{
-    m_class = classify;
-}
-
 inline int8_t LASPoint::GetScanAngleRank() const
 {
     return m_angleRank;

Modified: trunk/src/detail/reader.cpp
==============================================================================
--- trunk/src/detail/reader.cpp	(original)
+++ trunk/src/detail/reader.cpp	Thu Apr 16 09:17:43 2009
@@ -45,6 +45,7 @@
 #include <liblas/detail/reader12.hpp>
 #include <liblas/lasheader.hpp>
 #include <liblas/laspoint.hpp>
+#include <liblas/lasclassification.hpp>
 // 
 // // GeoTIFF
 // #ifdef HAVE_LIBGEOTIFF
@@ -112,7 +113,7 @@
 
     point.SetIntensity(record.intensity);
     point.SetScanFlags(record.flags);
-    point.SetClassification(record.classification);
+    point.SetClassification((record.classification));
     point.SetScanAngleRank(record.scan_angle_rank);
     point.SetUserData(record.user_data);
     point.SetPointSourceID(record.point_source_id);

Modified: trunk/src/detail/writer.cpp
==============================================================================
--- trunk/src/detail/writer.cpp	(original)
+++ trunk/src/detail/writer.cpp	Thu Apr 16 09:17:43 2009
@@ -91,11 +91,16 @@
     record.y = static_cast<int32_t>((point.GetY() - header.GetOffsetY()) / header.GetScaleY());
     record.z = static_cast<int32_t>((point.GetZ() - header.GetOffsetZ()) / header.GetScaleZ());
 
-    if (m_transform) Project(record);
+    if (0 != m_transform)
+    {
+        Project(record);
+    }
+
+    LASClassification::bitset_type clsflags(point.GetClassification());
+    record.classification = static_cast<uint8_t>(clsflags.to_ulong());
 
     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();

Modified: trunk/src/las_c_api.cpp
==============================================================================
--- trunk/src/las_c_api.cpp	(original)
+++ trunk/src/las_c_api.cpp	Thu Apr 16 09:17:43 2009
@@ -62,7 +62,8 @@
 typedef struct LASColorHS *LASColorH;
 typedef struct LASSRSHS *LASSRSH;
 
-
+#include <cstdio>
+#include <bitset>
 #include <exception>
 #include <fstream>
 #include <iostream>
@@ -72,7 +73,6 @@
 #include <stack>
 #include <typeinfo>
 #include <vector>
-#include <cstdio>
 
 using namespace liblas;
 
@@ -546,8 +546,9 @@
 LAS_DLL liblas::uint8_t LASPoint_GetClassification(const LASPointH hPoint) {
     
     VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetClassification", 0);
-    
-    liblas::uint8_t value = ((LASPoint*) hPoint)->GetClassification();
+
+    LASClassification::bitset_type clsflags(((LASPoint*) hPoint)->GetClassification());
+    liblas::uint8_t value = static_cast<uint8_t>(clsflags.to_ulong());
     return value;
 }
 
@@ -1773,7 +1774,6 @@
         return LE_Failure;
     }
 
-
     return LE_None;
 }
 
@@ -1787,7 +1787,8 @@
 LAS_DLL liblas::uint32_t LASSRS_GetVLRCount(const LASSRSH hSRS) {
     VALIDATE_LAS_POINTER1(hSRS, "LASSRS_GetVLR", 0);
     
-    liblas::uint32_t size = ((LASSpatialReference*) hSRS)->GetVLRs().size();
+    using liblas::uint32_t;
+    uint32_t size = static_cast<uint32_t>(((LASSpatialReference*) hSRS)->GetVLRs().size());
     return size;
 }
 

Modified: trunk/src/laspoint.cpp
==============================================================================
--- trunk/src/laspoint.cpp	(original)
+++ trunk/src/laspoint.cpp	Thu Apr 16 09:17:43 2009
@@ -52,7 +52,6 @@
 LASPoint::LASPoint() :
     m_intensity(0),
     m_flags(0),
-    m_class(0),
     m_angleRank(0),
     m_userData(0),
     m_pointSourceId(0),
@@ -64,7 +63,7 @@
 LASPoint::LASPoint(LASPoint const& other) :
     m_intensity(other.m_intensity),
     m_flags(other.m_flags),
-    m_class(other.m_class),
+    m_cls(other.m_cls),
     m_angleRank(other.m_angleRank),
     m_userData(other.m_userData),
     m_pointSourceId(other.m_pointSourceId),
@@ -83,7 +82,7 @@
         m_coords[2] = rhs.m_coords[2];
         m_intensity = rhs.m_intensity;
         m_flags = rhs.m_flags;
-        m_class = rhs.m_class;
+        m_cls = rhs.m_cls;
         m_angleRank = rhs.m_angleRank;
         m_userData = rhs.m_userData;
         m_pointSourceId = rhs.m_pointSourceId;
@@ -144,6 +143,26 @@
     m_userData = data;
 }
 
+LASClassification const& LASPoint::GetClassification() const
+{
+    return m_cls;
+}
+
+void LASPoint::SetClassification(LASClassification const& cls)
+{
+    m_cls = cls;
+}
+
+void LASPoint::SetClassification(LASClassification::bitset_type const& flags)
+{
+    m_cls = LASClassification(flags);
+}
+
+void LASPoint::SetClassification(liblas::uint8_t const& flags)
+{
+    m_cls = LASClassification(flags);
+}
+
 bool LASPoint::equal(LASPoint const& other) const
 {
     // TODO - mloskot: Default epsilon is too small.

Modified: trunk/test/unit/Makefile.am
==============================================================================
--- trunk/test/unit/Makefile.am	(original)
+++ trunk/test/unit/Makefile.am	Thu Apr 16 09:17:43 2009
@@ -22,6 +22,7 @@
 liblas_test_SOURCES = \
     common.cpp \
     guid_test.cpp \
+    lasclassification_test.cpp \
     laserror_test.cpp \
     lasfile_test.cpp \
     lasheader_test.cpp \

Modified: trunk/test/unit/common.cpp
==============================================================================
--- trunk/test/unit/common.cpp	(original)
+++ trunk/test/unit/common.cpp	Thu Apr 16 09:17:43 2009
@@ -100,7 +100,7 @@
     ensure_equals("wrong defualt edge of flight line",
         p.GetFlightLineEdge(), 0);
     ensure_equals("wrong defualt classification",
-        p.GetClassification(), 0);
+        p.GetClassification(), liblas::LASClassification::bitset_type(0));
     ensure_equals("wrong defualt scan angle rank",
         p.GetScanAngleRank(), 0);
     ensure_equals("wrong defualt file marker/user data value",
@@ -162,7 +162,7 @@
     ensure_distance(p.GetY(), double(4834500), 0.0001);
     ensure_distance(p.GetZ(), double(51.53), 0.0001);
     ensure_equals(p.GetIntensity(), 670);
-    ensure_equals(p.GetClassification(), liblas::uint8_t(1));
+    ensure_equals(p.GetClassification(), liblas::LASClassification::bitset_type(1));
     ensure_equals(p.GetScanAngleRank(), 0);
     ensure_equals(p.GetUserData(), 3);
     ensure_equals(p.GetPointSourceID(), 0);
@@ -176,7 +176,7 @@
     ensure_distance(p.GetY(), double(4834500), 0.0001);
     ensure_distance(p.GetZ(), double(51.63), 0.0001);
     ensure_equals(p.GetIntensity(), 350);
-    ensure_equals(p.GetClassification(), 1);
+    ensure_equals(p.GetClassification(), liblas::LASClassification::bitset_type(1));
     ensure_equals(p.GetScanAngleRank(), 0);
     ensure_equals(p.GetUserData(), 3);
     ensure_equals(p.GetPointSourceID(), 0);
@@ -190,7 +190,7 @@
     ensure_distance(p.GetY(), double(4834500), 0.0001);
     ensure_distance(p.GetZ(), double(50.90), 0.0001);
     ensure_equals(p.GetIntensity(), 150);
-    ensure_equals(p.GetClassification(), 1);
+    ensure_equals(p.GetClassification(), liblas::LASClassification::bitset_type(1));
     ensure_equals(p.GetScanAngleRank(), 0);
     ensure_equals(p.GetUserData(), 4);
     ensure_equals(p.GetPointSourceID(), 0);
@@ -199,4 +199,3 @@
 }
 
 }
-

Added: trunk/test/unit/lasclassification_test.cpp
==============================================================================
--- (empty file)
+++ trunk/test/unit/lasclassification_test.cpp	Thu Apr 16 09:17:43 2009
@@ -0,0 +1,312 @@
+// $Id$
+//
+// (C) Copyright Mateusz Loskot 2008, mateusz at loskot.net
+// Distributed under the BSD License
+// (See accompanying file LICENSE.txt or copy at
+// http://www.opensource.org/licenses/bsd-license.php)
+//
+#include <liblas/lasclassification.hpp>
+#include <liblas/cstdint.hpp>
+#include <tut/tut.hpp>
+#include <bitset>
+#include <sstream>
+#include <stdexcept>
+#include <string>
+#include "common.hpp"
+
+namespace tut
+{ 
+    struct lasclassification_data
+    {
+        typedef liblas::LASClassification bitset_type;
+        liblas::LASClassification m_default;
+    };
+
+    typedef test_group<lasclassification_data> tg;
+    typedef tg::object to;
+
+    tg test_group_lasclassification("liblas::LASClassification");
+
+    template<>
+    template<>
+    void to::test<1>()
+    {
+        ensure_equals(m_default, bitset_type(0));
+        ensure_equals(m_default.GetClass(), 0);
+        ensure_not(m_default.IsSynthetic());
+        ensure_not(m_default.IsKeyPoint());
+        ensure_not(m_default.IsWithheld());
+    }
+
+    template<>
+    template<>
+    void to::test<2>()
+    {
+        liblas::LASClassification c0(0);
+
+        ensure_equals(c0, m_default);
+        ensure_equals(c0, bitset_type(0));
+        ensure_equals(c0.GetClass(), 0);
+        ensure_not(c0.IsSynthetic());
+        ensure_not(c0.IsKeyPoint());
+        ensure_not(c0.IsWithheld());
+    }
+
+    template<>
+    template<>
+    void to::test<3>()
+    {
+        liblas::LASClassification c31(0x1F);
+
+        ensure_not(c31 == bitset_type(0));
+        ensure_equals(c31.GetClass(), 31);
+        ensure_not(c31.IsSynthetic());
+        ensure_not(c31.IsKeyPoint());
+        ensure_not(c31.IsWithheld());
+    }
+
+    template<>
+    template<>
+    void to::test<4>()
+    {
+        liblas::LASClassification c255(255);
+        ensure_equals(c255, bitset_type(255));
+        ensure_equals(c255.GetClass(), 31);
+        ensure(c255.IsSynthetic());
+        ensure(c255.IsKeyPoint());
+        ensure(c255.IsWithheld());
+    }
+
+    template<>
+    template<>
+    void to::test<5>()
+    {
+        liblas::LASClassification c;
+
+        c.SetClass(0);
+        ensure_equals(c.GetClass(), 0);
+
+        c.SetClass(31);
+        ensure_equals(c.GetClass(), 31);
+
+        ensure(c != m_default);
+    }
+
+    template<>
+    template<>
+    void to::test<6>()
+    {
+        liblas::LASClassification c;
+
+        c.SetSynthetic(true);
+        ensure(c.IsSynthetic());
+        ensure(c != m_default);
+
+        c.SetSynthetic(false);
+        ensure_not(c.IsSynthetic());
+        ensure_equals(c, m_default);
+
+        c.SetSynthetic(true);
+        ensure(c.IsSynthetic());
+        ensure(c != m_default);
+
+        c.SetSynthetic(false);
+        ensure_not(c.IsSynthetic());
+        ensure_equals(c, m_default);
+
+        ensure_equals(c.GetClass(), 0);
+    }
+
+    template<>
+    template<>
+    void to::test<7>()
+    {
+        liblas::LASClassification c;
+
+        c.SetKeyPoint(true);
+        ensure(c.IsKeyPoint());
+        ensure(c != m_default);
+
+        c.SetKeyPoint(false);
+        ensure_not(c.IsKeyPoint());
+        ensure_equals(c, m_default);
+
+        c.SetKeyPoint(true);
+        ensure(c.IsKeyPoint());
+        ensure(c != m_default);
+
+        c.SetKeyPoint(false);
+        ensure_not(c.IsKeyPoint());
+        ensure_equals(c, m_default);
+
+        ensure_equals(c.GetClass(), 0);
+    }
+
+    template<>
+    template<>
+    void to::test<8>()
+    {
+        liblas::LASClassification c;
+
+        c.SetWithheld(true);
+        ensure(c.IsWithheld());
+        ensure(c != m_default);
+
+        c.SetWithheld(false);
+        ensure_not(c.IsWithheld());
+        ensure_equals(c, m_default);
+
+        c.SetWithheld(true);
+        ensure(c.IsWithheld());
+        ensure(c != m_default);
+
+        c.SetWithheld(false);
+        ensure_not(c.IsWithheld());
+        ensure_equals(c, m_default);
+
+        ensure_equals(c.GetClass(), 0);
+    }
+
+    template<>
+    template<>
+    void to::test<9>()
+    {
+        liblas::LASClassification c;
+
+        c.SetKeyPoint(true);
+        ensure(c.IsKeyPoint());
+        ensure(c != m_default);
+
+        c.SetWithheld(true);
+        ensure(c.IsWithheld());
+        ensure(c.IsKeyPoint());
+        ensure(c != m_default);
+        
+        c.SetSynthetic(true);
+        ensure(c.IsWithheld());
+        ensure(c.IsKeyPoint());
+        ensure(c.IsSynthetic());
+        ensure(c != m_default);
+
+        ensure_equals(c.GetClass(), 0);
+    }
+
+    template<>
+    template<>
+    void to::test<10>()
+    {
+        liblas::LASClassification c;
+
+        c.SetKeyPoint(true);
+        c.SetSynthetic(true);
+        c.SetWithheld(true);
+        ensure(c.IsWithheld());
+        ensure(c.IsKeyPoint());
+        ensure(c.IsSynthetic());
+        ensure_not(c == m_default);
+        ensure_equals(c.GetClass(), 0);
+
+        c.SetKeyPoint(false);
+        c.SetSynthetic(false);
+        c.SetWithheld(false);
+        ensure_not(c.IsWithheld());
+        ensure_not(c.IsKeyPoint());
+        ensure_not(c.IsSynthetic());
+        ensure_equals(c.GetClass(), 0);
+
+        liblas::LASClassification::bitset_type bits1(c);
+        liblas::LASClassification::bitset_type bits2(m_default);
+        ensure_equals(c, m_default);
+    }
+
+    template<>
+    template<>
+    void to::test<11>()
+    {
+        liblas::LASClassification c;
+
+        c.SetKeyPoint(true);
+        c.SetClass(1);
+        c.SetSynthetic(true);
+        c.SetWithheld(true);
+        ensure(c.IsWithheld());
+        ensure(c.IsKeyPoint());
+        ensure(c.IsSynthetic());
+        ensure_equals(c.GetClass(), 1);
+        ensure_not(c == m_default);
+        
+        c.SetKeyPoint(false);
+        c.SetSynthetic(false);
+        c.SetClass(0);
+        c.SetWithheld(false);
+        ensure_not(c.IsWithheld());
+        ensure_not(c.IsKeyPoint());
+        ensure_not(c.IsSynthetic());
+        ensure_equals(c.GetClass(), 0);
+
+        liblas::LASClassification::bitset_type bits1(c);
+        liblas::LASClassification::bitset_type bits2(m_default);
+        ensure_equals(c, m_default);
+    }
+
+    template<>
+    template<>
+    void to::test<12>()
+    {
+        std::string sbits("00000000");
+
+        liblas::LASClassification c;
+
+        std::ostringstream oss;
+        oss << c;
+        ensure_equals(oss.str(), sbits);
+    }
+
+    template<>
+    template<>
+    void to::test<13>()
+    {
+        std::string sbits("00000011");
+
+        liblas::LASClassification c;
+        c.SetClass(3);
+
+        std::ostringstream oss;
+        oss << c;
+        ensure_equals(oss.str(), sbits);
+    }
+
+    template<>
+    template<>
+    void to::test<14>()
+    {
+        std::string sbits("10000001");
+
+        liblas::LASClassification c;
+        
+        c.SetWithheld(true);
+        c.SetClass(1);
+
+        std::ostringstream oss;
+        oss << c;
+        ensure_equals(oss.str(), sbits);
+    }
+
+    template<>
+    template<>
+    void to::test<15>()
+    {
+        std::string sbits("10110000");
+
+        liblas::LASClassification c;
+        
+        c.SetClass(16);
+        c.SetSynthetic(true);
+        c.SetKeyPoint(false);
+        c.SetWithheld(true);
+
+        std::ostringstream oss;
+        oss << c;
+        ensure_equals(oss.str(), sbits);
+    }
+}

Modified: trunk/test/unit/laspoint_test.cpp
==============================================================================
--- trunk/test/unit/laspoint_test.cpp	(original)
+++ trunk/test/unit/laspoint_test.cpp	Thu Apr 16 09:17:43 2009
@@ -247,17 +247,22 @@
     void to::test<11>()
     {
         ensure_equals("invalid default classification",
-            m_default.GetClassification(), 0);
+            m_default.GetClassification(), liblas::LASClassification::bitset_type(0));
 
+        liblas::LASClassification c;
+        
         liblas::uint8_t const begclass = 0;
-        m_default.SetClassification(begclass);
-        ensure_equals("invalid classification",
-            m_default.GetClassification(), begclass);
+        c.SetClass(begclass);
+        m_default.SetClassification(c);
+        
+        ensure_equals("invalid class index",
+            m_default.GetClassification().GetClass(), begclass);
 
         liblas::uint8_t const endclass = 31;
-        m_default.SetClassification(endclass);
-        ensure_equals("invalid classification",
-            m_default.GetClassification(), endclass);
+        c.SetClass(endclass);
+        m_default.SetClassification(c);
+        ensure_equals("invalid class index",
+            m_default.GetClassification().GetClass(), endclass);
     }
 
     // Test Get/SetScanAngleRank

Modified: trunk/test/unit/lasreader_iterator_test.cpp
==============================================================================
--- trunk/test/unit/lasreader_iterator_test.cpp	(original)
+++ trunk/test/unit/lasreader_iterator_test.cpp	Thu Apr 16 09:17:43 2009
@@ -123,11 +123,13 @@
         ensure_distance(it->GetY(), double(4834500), 0.0001);
         ensure_distance(it->GetZ(), double(51.53), 0.0001);
         ensure_equals(it->GetIntensity(), 670);
-        ensure_equals(it->GetClassification(), liblas::uint8_t(1));
         ensure_equals(it->GetScanAngleRank(), 0);
         ensure_equals(it->GetUserData(), 3);
         ensure_equals(it->GetScanFlags(), 9);
         ensure_distance(it->GetTime(), double(413665.23360000004), 0.0001);
+
+        liblas::LASClassification c(1);
+        ensure_equals(it->GetClassification(), c);
     }
 
     // Test pre-increment operator

Modified: trunk/test/unit/laswriter_test.cpp
==============================================================================
--- trunk/test/unit/laswriter_test.cpp	(original)
+++ trunk/test/unit/laswriter_test.cpp	Thu Apr 16 09:17:43 2009
@@ -9,12 +9,14 @@
 #include <liblas/lasreader.hpp>
 #include <liblas/lasheader.hpp>
 #include <liblas/laspoint.hpp>
+#include <liblas/lasclassification.hpp>
 #include <liblas/cstdint.hpp>
 #include <liblas/liblas.hpp>
 #include <tut/tut.hpp>
+#include <cstdio>
+#include <bitset>
 #include <fstream>
 #include <string>
-#include <cstdio>
 #include "liblas_test.hpp"
 #include "common.hpp"
 
@@ -135,11 +137,13 @@
             ensure_equals(point.GetNumberOfReturns(), 1);
             ensure_equals(point.GetScanDirection(), 1);
             ensure_equals(point.GetFlightLineEdge(), 1);
-            ensure_equals(point.GetClassification(), 7);
             ensure_equals(point.GetScanAngleRank(), 90);
             ensure_equals(point.GetUserData(), 0);
             ensure_equals(point.GetPointSourceID(), 1);
 
+            typedef liblas::LASClassification::bitset_type bitset_type;
+            ensure_equals(bitset_type(point.GetClassification()), bitset_type(7));
+
             // read 2nd point
             reader.ReadNextPoint();
             point = reader.GetPoint();
@@ -151,7 +155,6 @@
             ensure_equals(point.GetNumberOfReturns(), 1);
             ensure_equals(point.GetScanDirection(), 1);
             ensure_equals(point.GetFlightLineEdge(), 1);
-            ensure_equals(point.GetClassification(), 7);
             ensure_equals(point.GetScanAngleRank(), 90);
             ensure_equals(point.GetUserData(), 0);
             ensure_equals(point.GetPointSourceID(), 2);
@@ -167,10 +170,12 @@
             ensure_equals(point.GetNumberOfReturns(), 1);
             ensure_equals(point.GetScanDirection(), 1);
             ensure_equals(point.GetFlightLineEdge(), 1);
-            ensure_equals(point.GetClassification(), 7);
             ensure_equals(point.GetScanAngleRank(), 90);
             ensure_equals(point.GetUserData(), 0);
             ensure_equals(point.GetPointSourceID(), 3);
+
+            typedef liblas::LASClassification::bitset_type bitset_type;
+            ensure_equals(bitset_type(point.GetClassification()), bitset_type(7));
         }
     }
 


More information about the Liblas-commits mailing list