libLAS API Reference (svn-trunk)
classification.hpp
Go to the documentation of this file.
1/******************************************************************************
2 * $Id$
3 *
4 * Project: libLAS - http://liblas.org - A BSD library for LAS format data.
5 * Purpose: Definition of LASClassification type.
6 * Author: Mateusz Loskot, mateusz@loskot.net
7 *
8 ******************************************************************************
9 * Copyright (c) 2009, Mateusz Loskot
10 *
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following
15 * conditions are met:
16 *
17 * * Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * * Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided
22 * with the distribution.
23 * * Neither the name of the Martin Isenburg or Iowa Department
24 * of Natural Resources nor the names of its contributors may be
25 * used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
35 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
36 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
38 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
39 * OF SUCH DAMAGE.
40 ****************************************************************************/
41
42#ifndef LIBLAS_LASCLASSIFICATION_HPP_INCLUDED
43#define LIBLAS_LASCLASSIFICATION_HPP_INCLUDED
44
45#include <liblas/export.hpp>
46// std
47#include <cassert>
48#include <cstddef>
49#include <bitset>
50#include <ostream>
51#include <sstream>
52#include <stdexcept>
53#include <stdint.h>
54
55// I hate you windows
56#ifdef _MSC_VER
57#ifdef GetClassName
58#undef GetClassName
59#endif
60#endif
61
62namespace liblas {
63
67{
68public:
69
71 typedef std::bitset<8> bitset_type;
72
73
80 static uint32_t const class_table_size;
81
90
95
98 explicit Classification(bitset_type const& flags)
99 : m_flags(flags)
100 {}
101
104 explicit Classification(uint8_t const& flags)
105 : m_flags(flags)
106 {}
107
116 Classification(uint32_t cls, bool s, bool k, bool w)
117 {
118 SetClass(cls);
119 SetSynthetic(s);
120 SetKeyPoint(k);
121 SetWithheld(w);
122 }
123
126 {
127 m_flags = other.m_flags;
128 }
129
132 {
133 if (&rhs != this)
134 {
135 m_flags = rhs.m_flags;
136 }
137 return *this;
138 }
139
142 operator bitset_type() const
143 {
144 return bitset_type(m_flags);
145 }
146
149 {
150 return bitset_type(m_flags);
151 }
152
156 std::string GetClassName() const;
157
159 uint8_t GetClass() const;
160
170 void SetClass(uint32_t index);
171
174 void SetSynthetic(bool flag)
175 {
176 m_flags[eSyntheticBit] = flag;
177 }
178
180 bool IsSynthetic() const
181 {
182 return m_flags[eSyntheticBit];
183 }
184
187 void SetKeyPoint(bool flag)
188 {
189 m_flags[eKeyPointBit] = flag;
190 }
191
193 bool IsKeyPoint() const
194 {
195 return m_flags[eKeyPointBit];
196 }
197
199 void SetWithheld(bool flag)
200 {
201 m_flags[eWithheldBit] = flag;
202 }
203
205 bool IsWithheld() const
206 {
207 return m_flags[eWithheldBit];
208 }
209
213 bool equal(Classification const& other) const
214 {
215 return (other.m_flags == m_flags);
216 }
217
218private:
219
220 bitset_type m_flags;
221
222 void check_class_index(uint32_t index) const;
223};
224
226inline bool operator==(Classification const& lhs, Classification const& rhs)
227{
228 return lhs.equal(rhs);
229}
230
232inline bool operator!=(Classification const& lhs, Classification const& rhs)
233{
234 return (!(lhs == rhs));
235}
236
247inline std::ostream& operator<<(std::ostream& os, Classification const& cls)
248{
250 return (os << flags);
251}
252
253} // namespace liblas
254
255#endif // LIBLAS_LASCLASSIFICATION_HPP_INCLUDED
Class definition to manipulate properties of point record classification.
Definition classification.hpp:67
std::bitset< 8 > bitset_type
Alias on std::bitset<8> used as collection of flags.
Definition classification.hpp:71
uint8_t GetClass() const
Returns index of ASPRS classification as defined in the lookup table.
void SetSynthetic(bool flag)
Sets if this point was created by a technique other than LIDAR collection such as digitized from a ph...
Definition classification.hpp:174
void SetWithheld(bool flag)
SetTests if this point should excluded from processing.
Definition classification.hpp:199
bitset_type GetFlags() const
Named accessor converting Classification to std::bitset<8>.
Definition classification.hpp:148
bool IsWithheld() const
Tests if this point should excluded from processing.
Definition classification.hpp:205
Classification(bitset_type const &flags)
Initializes classification flags using given set of 8 bits.
Definition classification.hpp:98
Classification()
Default initialization constructor.
Definition classification.hpp:94
bool IsSynthetic() const
Tests if this point was created by a technique other than LIDAR collection.
Definition classification.hpp:180
void SetKeyPoint(bool flag)
Sets if this point is considered to be a model keypoint and thus generally should not be withheld in ...
Definition classification.hpp:187
bool IsKeyPoint() const
Tests if this point is considered to be a model keypoint.
Definition classification.hpp:193
Classification & operator=(Classification const &rhs)
Assignment operator.
Definition classification.hpp:131
bool equal(Classification const &other) const
Compares this classification object with other one.
Definition classification.hpp:213
void SetClass(uint32_t index)
Updates index of ASPRS classification as defined in the lookup table.
BitPosition
Values of indexes in the set of bit flags.
Definition classification.hpp:84
@ eSyntheticBit
Synthetic flag.
Definition classification.hpp:86
@ eKeyPointBit
Key-point flag.
Definition classification.hpp:87
@ eClassBit
First bit position of 0:4 range.
Definition classification.hpp:85
@ eWithheldBit
Withheld flag.
Definition classification.hpp:88
Classification(uint32_t cls, bool s, bool k, bool w)
Initializes classification with values of given compounds.
Definition classification.hpp:116
Classification(uint8_t const &flags)
Initializes classification flags using 8 bits of integral type.
Definition classification.hpp:104
static uint32_t const class_table_size
Number of classes in lookup table as defined in ASPRS LAS 1.1+.
Definition classification.hpp:80
std::string GetClassName() const
Raturns name of class as defined in LAS 1.1+ Finds class name in lookup table based on class index as...
Classification(Classification const &other)
Copy constructor.
Definition classification.hpp:125
#define LAS_DLL
Definition export.hpp:58
Namespace grouping all elements of libLAS public interface.
Definition bounds.hpp:60
bool operator!=(Classification const &lhs, Classification const &rhs)
Not-equal-to operator implemented in terms of Classification::equal.
Definition classification.hpp:232
std::ostream & operator<<(std::ostream &os, Classification const &cls)
The output stream operator is based on std::bitset<N>::operator<<.
Definition classification.hpp:247
bool operator==(Classification const &lhs, Classification const &rhs)
Equal-to operator implemented in terms of Classification::equal.
Definition classification.hpp:226
Definition schema.hpp:80