[Liblas-commits] r1230 - in trunk: include/liblas src test/unit
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Apr 17 07:01:55 EDT 2009
Author: mloskot
Date: Fri Apr 17 07:01:53 2009
New Revision: 1230
URL: http://liblas.org/changeset/1230
Log:
* Documented LASClassification class.
* Added more test cases to LASClassification unit tests.
Modified:
trunk/include/liblas/lasclassification.hpp
trunk/src/lasclassification.cpp
trunk/test/unit/lasclassification_test.cpp
Modified: trunk/include/liblas/lasclassification.hpp
==============================================================================
--- trunk/include/liblas/lasclassification.hpp (original)
+++ trunk/include/liblas/lasclassification.hpp Fri Apr 17 07:01:53 2009
@@ -2,7 +2,7 @@
* $Id$
*
* Project: libLAS - http://liblas.org - A BSD library for LAS format data.
- * Purpose: Definition LASClassification type.
+ * Purpose: Definition of LASClassification type.
* Author: Mateusz Loskot, mateusz at loskot.net
*
******************************************************************************
@@ -59,15 +59,18 @@
{
public:
- ///
+ /// Alias on std::bitset<8> used as collection of flags.
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.
+ /// @note Currently, libLAS does not support classification based on table
+ /// stored in variable-length record. Only Standard ASPRS classification
+ /// table is supported.
static std::size_t const class_table_size;
- enum
+ enum BitPosition
{
eClassBit = 0, /// First bit position of 0:4 range.
eSyntheticBit = 5, /// Synthetic flag.
@@ -76,21 +79,30 @@
};
/// Default initialization constructor.
- /// Initializes all flags of classification not set.
+ /// Initializes all flags of classification as set to 0.
/// Operation semantic is equivalent to bitset_type::reset().
LASClassification() {}
- /// Initializes classification with given set of 8 flags.
+ /// Initializes classification flags using given set of 8 bits.
+ /// @param flags [in] - contains 8 bits representing classification flags.
explicit LASClassification(bitset_type const& flags)
: m_flags(flags)
{}
- /// Initializes classification from flags given as integral type.
+ /// Initializes classification flags using 8 bits of integral type.
+ /// @param flags [in] - contains 8 bits representing classification flags.
explicit LASClassification(uint8_t const& flags)
: m_flags(flags)
{}
/// Initializes classification with values of given compounds.
+ /// @param cls [in] - index of Standard ASPRS classification as
+ /// defined in the lookup table, from 0 to class_table_size - 1.
+ /// @param s [in] - If set then this point was created by a technique other than
+ /// LIDAR collection such as digitized from a photogrammetric stereo model.
+ /// @param k [in] - If set, this point is considered to be a model keypoint and
+ /// thus generally should not be withheld in a thinning algorithm.
+ /// @param w [in] - If set, this point should not be included in processing.
LASClassification(uint8_t cls, bool s, bool k, bool w)
{
SetClass(cls);
@@ -99,11 +111,13 @@
SetWithheld(w);
}
+ /// Copy constructor.
LASClassification(LASClassification const& other)
{
m_flags = other.m_flags;
}
+ /// Assignment operator.
LASClassification& operator=(LASClassification const& rhs)
{
if (&rhs != this )
@@ -114,7 +128,8 @@
}
/// Conversion operator.
- /// Returns classification object as flags encoded in form of std::bitset<8>.
+ /// Returns classification object as in form of std::bitset<8>.
+ /// bitset< object
operator bitset_type() const
{
return bitset_type(m_flags);
@@ -123,10 +138,9 @@
/// 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.
- ///
- /// \todo TODO: To be implemented
std::string GetClassName() const;
+ /// Returns index of ASPRS classification as defined in the lookup table.
uint8_t GetClass() const
{
bitset_type bits(m_flags);
@@ -139,6 +153,15 @@
return index;
}
+ /// Updates index of ASPRS classification as defined in the lookup table.
+ /// Valid index is in range from 0 to class_table_size - 1.
+ /// For LAS 1.0, this static number may be invalid and
+ /// extend up to 255 classes stored in variable-length records.
+ /// @note Currently, libLAS does not support classification based on table
+ /// stored in variable-length record. Only Standard ASPRS classification
+ /// table is supported.
+ /// @exception Theoretically, may throw std::out_of_range in case index
+ /// value is not in range between 0 and class_table_size - 1.
void SetClass(uint8_t index)
{
check_class_index(index);
@@ -152,36 +175,47 @@
m_flags |= mask & binval;
}
+ /// Sets if this point was created by a technique other than LIDAR
+ /// collection such as digitized from a photogrammetric stereo model.
void SetSynthetic(bool flag)
{
m_flags[eSyntheticBit] = flag;
}
+ /// Tests if this point was created by a technique other than LIDAR collection.
bool IsSynthetic() const
{
return m_flags[eSyntheticBit];
}
+ /// Sets if this point is considered to be a model keypoint and
+ /// thus generally should not be withheld in a thinning algorithm.
void SetKeyPoint(bool flag)
{
m_flags[eKeyPointBit] = flag;
}
+ /// Tests if this point is considered to be a model keypoint.
bool IsKeyPoint() const
{
return m_flags[eKeyPointBit];
}
+ /// SetTests if this point should excluded from processing.
void SetWithheld(bool flag)
{
m_flags[eWithheldBit] = flag;
}
+ /// Tests if this point should excluded from processing.
bool IsWithheld() const
{
return m_flags[eWithheldBit];
}
+ /// Compares this classification object with other one.
+ /// Comparison is preformed against set of bit flags stored
+ /// in both objects.
bool equal(LASClassification const& other) const
{
return (other.m_flags == m_flags);
@@ -203,11 +237,13 @@
}
};
+/// Equal-to operator implemented in terms of LASClassification::equal.
inline bool operator==(LASClassification const& lhs, LASClassification const& rhs)
{
return lhs.equal(rhs);
}
+/// Not-equal-to operator implemented in terms of LASClassification::equal.
inline bool operator!=(LASClassification const& lhs, LASClassification const& rhs)
{
return (!(lhs == rhs));
@@ -215,7 +251,9 @@
/// 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:
+/// Effects promised as by
+/// @link http://www.open-std.org/Jtc1/sc22/wg21/ Standard for Programming Language C++ @endlink,
+/// 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
Modified: trunk/src/lasclassification.cpp
==============================================================================
--- trunk/src/lasclassification.cpp (original)
+++ trunk/src/lasclassification.cpp Fri Apr 17 07:01:53 2009
@@ -2,7 +2,7 @@
* $Id$
*
* Project: libLAS - http://liblas.org - A BSD library for LAS format data.
- * Purpose: Definition LASClassification type.
+ * Purpose: Implementation of LASClassification type.
* Author: Mateusz Loskot, mateusz at loskot.net
*
******************************************************************************
Modified: trunk/test/unit/lasclassification_test.cpp
==============================================================================
--- trunk/test/unit/lasclassification_test.cpp (original)
+++ trunk/test/unit/lasclassification_test.cpp Fri Apr 17 07:01:53 2009
@@ -18,7 +18,7 @@
{
struct lasclassification_data
{
- typedef liblas::LASClassification bitset_type;
+ typedef liblas::LASClassification::bitset_type bitset_type;
liblas::LASClassification m_default;
};
@@ -58,7 +58,7 @@
{
liblas::LASClassification c31(0x1F);
- ensure_not(c31 == bitset_type(0));
+ ensure_not(c31 == m_default);
ensure_equals(c31.GetClass(), 31);
ensure_not(c31.IsSynthetic());
ensure_not(c31.IsKeyPoint());
@@ -81,6 +81,53 @@
template<>
void to::test<5>()
{
+ liblas::LASClassification c(31, false, false, false);
+
+ ensure_equals(c.GetClass(), 31);
+ ensure_not(c.IsSynthetic());
+ ensure_not(c.IsKeyPoint());
+ ensure_not(c.IsWithheld());
+
+ ensure_equals(c, bitset_type(std::string("00011111")));
+ }
+
+ template<>
+ template<>
+ void to::test<6>()
+ {
+ liblas::LASClassification c(7, true, false, true);
+
+ ensure_equals(c.GetClass(), 7);
+ ensure_not(c.IsKeyPoint());
+ ensure(c.IsWithheld());
+ ensure(c.IsSynthetic());
+ ensure_equals(c, bitset_type(std::string("10100111")));
+ }
+
+ template<>
+ template<>
+ void to::test<7>()
+ {
+ try
+ {
+ liblas::LASClassification c(255, true, true, true);
+
+ fail("std::out_of_range not thrown but expected");
+ }
+ catch (std::out_of_range const& e)
+ {
+ ensure(e.what(), true);
+ }
+ catch (...)
+ {
+ fail("unhandled exception expected");
+ }
+ }
+
+ template<>
+ template<>
+ void to::test<8>()
+ {
liblas::LASClassification c;
c.SetClass(0);
@@ -94,7 +141,7 @@
template<>
template<>
- void to::test<6>()
+ void to::test<9>()
{
liblas::LASClassification c;
@@ -119,7 +166,7 @@
template<>
template<>
- void to::test<7>()
+ void to::test<10>()
{
liblas::LASClassification c;
@@ -144,7 +191,7 @@
template<>
template<>
- void to::test<8>()
+ void to::test<11>()
{
liblas::LASClassification c;
@@ -169,7 +216,7 @@
template<>
template<>
- void to::test<9>()
+ void to::test<12>()
{
liblas::LASClassification c;
@@ -193,7 +240,7 @@
template<>
template<>
- void to::test<10>()
+ void to::test<13>()
{
liblas::LASClassification c;
@@ -221,7 +268,7 @@
template<>
template<>
- void to::test<11>()
+ void to::test<14>()
{
liblas::LASClassification c;
@@ -251,7 +298,7 @@
template<>
template<>
- void to::test<12>()
+ void to::test<15>()
{
std::string const sbits("00000000");
@@ -264,7 +311,7 @@
template<>
template<>
- void to::test<13>()
+ void to::test<16>()
{
std::string const sbits("00000011");
@@ -278,7 +325,7 @@
template<>
template<>
- void to::test<14>()
+ void to::test<17>()
{
std::string const sbits("10000001");
@@ -294,7 +341,7 @@
template<>
template<>
- void to::test<15>()
+ void to::test<18>()
{
std::string const sbits("10110000");
@@ -312,7 +359,7 @@
template<>
template<>
- void to::test<16>()
+ void to::test<19>()
{
std::string const sbits("00000000");
liblas::LASClassification::bitset_type bits(sbits);
@@ -327,7 +374,7 @@
template<>
template<>
- void to::test<17>()
+ void to::test<20>()
{
std::string const sbits("00000011");
liblas::LASClassification::bitset_type bits(sbits);
@@ -342,7 +389,7 @@
template<>
template<>
- void to::test<18>()
+ void to::test<21>()
{
std::string const sbits("10000001");
liblas::LASClassification::bitset_type bits(sbits);
@@ -357,7 +404,7 @@
template<>
template<>
- void to::test<19>()
+ void to::test<22>()
{
std::string const sbits("10110000");
liblas::LASClassification::bitset_type bits(sbits);
@@ -372,7 +419,7 @@
template<>
template<>
- void to::test<20>()
+ void to::test<23>()
{
std::string const cn("Created, never classified");
ensure_equals(m_default.GetClassName(), cn);
@@ -380,7 +427,7 @@
template<>
template<>
- void to::test<21>()
+ void to::test<24>()
{
std::string const cn("Low Point (noise)");
m_default.SetClass(7);
@@ -389,7 +436,7 @@
template<>
template<>
- void to::test<22>()
+ void to::test<25>()
{
std::string const cn("Reserved for ASPRS Definition");
m_default.SetClass(31);
@@ -398,7 +445,7 @@
template<>
template<>
- void to::test<23>()
+ void to::test<26>()
{
try
{
More information about the Liblas-commits
mailing list