1 /******************************************************************************
2 * $Id$
3 *
4 * Project: libLAS - http://liblas.org - A BSD library for LAS format data.
5 * Purpose: LAS point class
6 * Author: Mateusz Loskot, mateusz@loskot.net
7 *
8 ******************************************************************************
9 * Copyright (c) 2008, 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_LASPOINT_HPP_INCLUDED
43 #define LIBLAS_LASPOINT_HPP_INCLUDED
44
45 #include <liblas/classification.hpp>
46 #include <liblas/color.hpp>
47 #include <liblas/schema.hpp>
48 #include <liblas/detail/pointrecord.hpp>
49 #include <liblas/detail/fwd.hpp>
50 #include <liblas/detail/private_utility.hpp>
51 #include <liblas/external/property_tree/ptree.hpp>
52 #include <liblas/export.hpp>
53
54 // boost
55 #include <boost/array.hpp>
56 #include <boost/shared_ptr.hpp>
57 #include <boost/any.hpp>
58 // std
59 #include <stdexcept> // std::out_of_range
60 #include <cstdlib> // std::size_t
61 #include <vector> // std::vector
62
63
64 namespace liblas {
65
66
67 /// Point data record composed with X, Y, Z coordinates and attributes.
68 class LAS_DLL Point
69 {
70 public:
71
72 enum DataMemberFlag
73 {
74 eReturnNumber = 1,
75 eNumberOfReturns = 2,
76 eScanDirection = 4,
77 eFlightLineEdge = 8,
78 eClassification = 16,
79 eScanAngleRank = 32,
80 eTime = 64
81 };
82
83 enum ClassificationType
84 {
85 eCreated = 0,
86 eUnclassified,
87 eGround,
88 eLowVegetation,
89 eMediumVegetation,
90 eHighVegetation,
91 eBuilding,
92 eLowPoint,
93 eModelKeyPoint,
94 eWater = 9,
95 // = 10 // reserved for ASPRS Definition
96 // = 11 // reserved for ASPRS Definition
97 eOverlapPoints = 12
98 // = 13-31 // reserved for ASPRS Definition
99 };
100
101 enum ScanAngleRankRange
102 {
103 eScanAngleRankMin = -90,
104 eScanAngleRankMax = 90
105 };
106
107 // Point();
~Point()108 ~Point() {}
109 Point(Header const* header);
110 Point(Point const& other);
111 Point& operator=(Point const& rhs);
112
113 double GetX() const;
114 double GetY() const;
115 double GetZ() const;
116
117 int32_t GetRawX() const;
118 int32_t GetRawY() const;
119 int32_t GetRawZ() const;
120
121 void SetCoordinates(double const& x, double const& y, double const& z);
122
123 void SetX(double const& value);
124 void SetY(double const& value);
125 void SetZ(double const& value);
126
127 void SetRawX(int32_t const& value);
128 void SetRawY(int32_t const& value);
129 void SetRawZ(int32_t const& value);
130
131 uint16_t GetIntensity() const;
132 void SetIntensity(uint16_t const& intensity);
133
134 /// Gets all scanning flags encoded as single byte.
135 /// The flags are (mandatory):
136 /// - Return Number (bits 0, 1, 2);
137 /// - Number of Returns - given pulse (bits 3, 4, 5);
138 /// - Scan Direction Flag (bit 6);
139 /// - Edge of Flight Line (bit 7).
140 uint8_t GetScanFlags() const;
141
142 /// Sets all scanning flags passed as a single byte.
143 /// \sa Documentation of GetScanFlags method for flags details.
144 void SetScanFlags(uint8_t const& flags);
145
146 uint16_t GetReturnNumber() const;
147 void SetReturnNumber(uint16_t const& num);
148
149 uint16_t GetNumberOfReturns() const;
150 void SetNumberOfReturns(uint16_t const& num);
151
152 uint16_t GetScanDirection() const;
153 void SetScanDirection(uint16_t const& dir);
154
155 uint16_t GetFlightLineEdge() const;
156 void SetFlightLineEdge(uint16_t const& edge);
157
158 //Classification& GetClassification();
159 Classification GetClassification() const;
160 void SetClassification(Classification const& cls);
161 void SetClassification(Classification::bitset_type const& flags);
162 void SetClassification(uint8_t const& flags);
163
164 int8_t GetScanAngleRank() const;
165 void SetScanAngleRank(int8_t const& rank);
166
167 /// Fetch value of File Marker (LAS 1.0) or User Data (LAS 1.1).
168 uint8_t GetUserData() const;
169
170 /// Set value of File Marker (LAS 1.0) or User Data (LAS 1.1).
171 void SetUserData(uint8_t const& data);
172
173 /// Fetch value of User Bit Field (LAS 1.0) or Point Source ID (LAS 1.1).
174 uint16_t GetPointSourceID() const;
175
176 /// Set value of User Bit Field (LAS 1.0) or Point Source ID (LAS 1.1).
177 void SetPointSourceID(uint16_t const& id);
178
179 /// Fetch color value associated with this point (LAS 1.2)
180 Color GetColor() const;
181
182 /// Set color value associated with this point (LAS 1.2)
183 void SetColor(Color const& value);
184
185 double GetTime() const;
186 void SetTime(double const& time);
187
188 /// Const version of index operator providing access to XYZ coordinates of point record.
189 /// Valid index values are 0, 1 or 2.
190 /// \exception std::out_of_range if requested index is out of range (> 2).
191 double operator[](std::size_t const& index) const;
192
193 /// \todo TODO: Should we compare other data members, but not only coordinates?
194 bool equal(Point const& other) const;
195
196 bool Validate() const;
197 bool IsValid() const;
198
199
GetData() const200 std::vector<uint8_t> const& GetData() const {return m_data; }
GetData()201 std::vector<uint8_t> & GetData() {return m_data; }
SetData(std::vector<uint8_t> const & v)202 void SetData(std::vector<uint8_t> const& v) { m_data = v;}
203
204 void SetHeader(Header const* header);
205 Header const* GetHeader() const;
206 property_tree::ptree GetPTree() const;
207 boost::any GetValue(Dimension const& d) const;
208
209 private:
210
211 std::vector<uint8_t> m_data;
212
213 std::vector<uint8_t>::size_type GetDimensionBytePosition(std::size_t dim_pos) const;
214 Header const* m_header;
215 Header const& m_default_header;
216
217 };
218
219 /// Equal-to operator implemented in terms of Point::equal method.
operator ==(Point const & lhs,Point const & rhs)220 inline bool operator==(Point const& lhs, Point const& rhs)
221 {
222 return lhs.equal(rhs);
223 }
224
225 /// Not-equal-to operator implemented in terms of Point::equal method.
operator !=(Point const & lhs,Point const & rhs)226 inline bool operator!=(Point const& lhs, Point const& rhs)
227 {
228 return (!(lhs == rhs));
229 }
230
operator [](std::size_t const & index) const231 inline double Point::operator[](std::size_t const& index) const
232 {
233
234 if (index == 0)
235 return GetX();
236 if (index == 1)
237 return GetY();
238 if (index == 2)
239 return GetZ();
240
241 throw std::out_of_range("coordinate subscript out of range");
242
243 }
244
245
246 LAS_DLL std::ostream& operator<<(std::ostream& os, liblas::Point const&);
247
248
249 } // namespace liblas
250
251 #endif // LIBLAS_LASPOINT_HPP_INCLUDED
252