[Liblas-commits] r1220 - in trunk: build/msvc90/liblas_lib
include/liblas src test/unit
liblas-commits at liblas.org
liblas-commits at liblas.org
Thu Apr 16 11:21:53 EDT 2009
Author: mloskot
Date: Thu Apr 16 11:21:53 2009
New Revision: 1220
URL: http://liblas.org/changeset/1220
Log:
* Compute LASClassification::class_table_size in compile_time according to current definition of lookup table (no need to keep hardcoded size of array).
* Implemented LASClassification::GetClassName() function to return classification description.
* Added tests corresponding to this update.
* src/Makefile.am and src/makefile.vc updated as well.
Added:
trunk/src/lasclassification.cpp
Modified:
trunk/build/msvc90/liblas_lib/liblas_lib.vcproj
trunk/include/liblas/lasclassification.hpp
trunk/src/Makefile.am
trunk/src/makefile.vc
trunk/test/unit/lasclassification_test.cpp
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 11:21:53 2009
@@ -293,6 +293,10 @@
>
</File>
<File
+ RelativePath="..\..\..\src\lasclassification.cpp"
+ >
+ </File>
+ <File
RelativePath="..\..\..\src\lascolor.cpp"
>
</File>
Modified: trunk/include/liblas/lasclassification.hpp
==============================================================================
--- trunk/include/liblas/lasclassification.hpp (original)
+++ trunk/include/liblas/lasclassification.hpp Thu Apr 16 11:21:53 2009
@@ -65,7 +65,7 @@
/// 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;
+ static std::size_t const class_table_size;
enum
{
@@ -125,17 +125,18 @@
/// as defined in classification object.
///
/// \todo TODO: To be implemented
- std::string GetClassName() const
- {
- return std::string("");
- }
+ std::string GetClassName() const;
uint8_t GetClass() const
{
bitset_type bits(m_flags);
- bitset_type mask(class_table_size - 1);
+ bitset_type const mask(class_table_size - 1);
bits &= mask;
- return (static_cast<uint8_t>(bits.to_ulong()));
+
+ uint8_t const index = static_cast<uint8_t>(bits.to_ulong());
+ assert(index < class_table_size);
+
+ return index;
}
void SetClass(uint8_t index)
@@ -190,7 +191,7 @@
bitset_type m_flags;
- void check_class_index(std::size_t index)
+ void check_class_index(std::size_t index) const
{
if (index > (class_table_size - 1))
{
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Thu Apr 16 11:21:53 2009
@@ -14,6 +14,8 @@
lib_LTLIBRARIES = liblas.la
liblas_la_SOURCES = \
+ lasclassification.cpp \
+ lascolor.cpp \
laserror.cpp \
laspoint.cpp \
lasheader.cpp \
@@ -22,7 +24,6 @@
laswriter.cpp \
lasfile.cpp \
las_c_api.cpp \
- lascolor.cpp \
lasspatialreference.cpp \
detail/reader.cpp \
detail/reader10.cpp \
Added: trunk/src/lasclassification.cpp
==============================================================================
--- (empty file)
+++ trunk/src/lasclassification.cpp Thu Apr 16 11:21:53 2009
@@ -0,0 +1,101 @@
+/******************************************************************************
+ * $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.
+ ****************************************************************************/
+
+#include <liblas/lasclassification.hpp>
+#include <liblas/cstdint.hpp>
+#include <liblas/detail/utility.hpp>
+// std
+#include <cstddef>
+#include <string>
+
+namespace {
+
+static std::string g_class_names[] =
+{
+ "Created, never classified",
+ "Unclassified",
+ "Ground",
+ "Low Vegetation",
+ "Medium Vegetation",
+ "High Vegetation",
+ "Building",
+ "Low Point (noise)",
+ "Model Key-point (mass point)",
+ "Water",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Overlap Points",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition",
+ "Reserved for ASPRS Definition"
+};
+
+} // namespace anonymous
+
+namespace liblas {
+
+std::size_t const LASClassification::class_table_size = detail::static_array_size(g_class_names);
+
+std::string LASClassification::GetClassName() const
+{
+ std::size_t const index = GetClass();
+ check_class_index(index);
+
+ return g_class_names[index];
+}
+
+} // namespace liblas
Modified: trunk/src/makefile.vc
==============================================================================
--- trunk/src/makefile.vc (original)
+++ trunk/src/makefile.vc Thu Apr 16 11:21:53 2009
@@ -5,6 +5,7 @@
!INCLUDE $(LAS_ROOT)\nmake.opt
LAS_OBJS = \
+ lasclassification.obj \
lascolor.obj \
laswriter.obj \
lasreader.obj \
Modified: trunk/test/unit/lasclassification_test.cpp
==============================================================================
--- trunk/test/unit/lasclassification_test.cpp (original)
+++ trunk/test/unit/lasclassification_test.cpp Thu Apr 16 11:21:53 2009
@@ -369,4 +369,12 @@
oss << c;
ensure_equals(oss.str(), sbits);
}
+
+ template<>
+ template<>
+ void to::test<20>()
+ {
+ std::string const cn("Created, never classified");
+ ensure_equals(m_default.GetClassName(), cn);
+ }
}
More information about the Liblas-commits
mailing list