1
/******************************************************************************
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
8
******************************************************************************
9
* Copyright (c) 2008, Mateusz Loskot
11
* All rights reserved.
13
* Redistribution and use in source and binary forms, with or without
14
* modification, are permitted provided that the following
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.
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
40
****************************************************************************/
42
#include <liblas/laspoint.hpp>
43
#include <liblas/lasheader.hpp>
44
#include <liblas/cstdint.hpp>
45
#include <liblas/exception.hpp>
46
#include <liblas/detail/utility.hpp>
52
LASPoint::LASPoint() :
61
std::memset(m_coords, 0, sizeof(m_coords));
64
LASPoint::LASPoint(LASPoint const& other) :
65
m_intensity(other.m_intensity),
66
m_flags(other.m_flags),
67
m_class(other.m_class),
68
m_angleRank(other.m_angleRank),
69
m_userData(other.m_userData),
70
m_pointSourceId(other.m_pointSourceId),
71
m_gpsTime(other.m_gpsTime),
72
m_color(other.m_color)
74
std::memcpy(m_coords, other.m_coords, sizeof(m_coords));
77
LASPoint& LASPoint::operator=(LASPoint const& rhs)
81
m_coords[0] = rhs.m_coords[0];
82
m_coords[1] = rhs.m_coords[1];
83
m_coords[2] = rhs.m_coords[2];
84
m_intensity = rhs.m_intensity;
85
m_flags = rhs.m_flags;
86
m_class = rhs.m_class;
87
m_angleRank = rhs.m_angleRank;
88
m_userData = rhs.m_userData;
89
m_pointSourceId = rhs.m_pointSourceId;
90
m_gpsTime = rhs.m_gpsTime;
91
m_color = rhs.m_color;
96
void LASPoint::SetCoordinates(LASHeader const& header, double x, double y, double z)
98
double const cx = x * header.GetScaleX() + header.GetOffsetX();
99
double const cy = y * header.GetScaleY() + header.GetOffsetY();
100
double const cz = z * header.GetScaleZ() + header.GetOffsetZ();
102
SetCoordinates(cx, cy, cz);
105
void LASPoint::SetReturnNumber(uint16_t const& num)
107
// Store value in bits 0,1,2
108
uint8_t mask = 0x7 << 0; // 0b00000111
110
m_flags |= mask & (static_cast<uint8_t>(num) << 0);
114
void LASPoint::SetNumberOfReturns(uint16_t const& num)
116
// Store value in bits 3,4,5
117
uint8_t mask = 0x7 << 3; // 0b00111000
119
m_flags |= mask & (static_cast<uint8_t>(num) << 3);
122
void LASPoint::SetScanDirection(uint16_t const& dir)
124
// Store value in bit 6
125
uint8_t mask = 0x1 << 6; // 0b01000000
127
m_flags |= mask & (static_cast<uint8_t>(dir) << 6);
130
void LASPoint::SetFlightLineEdge(uint16_t const& edge)
132
// Store value in bit 7
133
uint8_t mask = 0x1 << 7; // 0b10000000
135
m_flags |= mask & (static_cast<uint8_t>(edge) << 7);}
137
void LASPoint::SetScanAngleRank(int8_t const& rank)
142
void LASPoint::SetUserData(uint8_t const& data)
147
bool LASPoint::equal(LASPoint const& other) const
149
// TODO - mloskot: Default epsilon is too small.
150
// Is 0.00001 good as tolerance or too wide?
151
//double const epsilon = std::numeric_limits<double>::epsilon();
152
double const epsilon = 0.00001;
154
double const dx = m_coords[0] - other.m_coords[0];
155
double const dy = m_coords[1] - other.m_coords[1];
156
double const dz = m_coords[2] - other.m_coords[2];
158
// TODO: Should we compare other data members, besides the coordinates?
160
if (((dx <= epsilon) && (dx >= -epsilon))
161
&& ((dy <= epsilon) && (dy >= -epsilon))
162
&& ((dz <= epsilon) && (dz >= -epsilon)))
170
bool LASPoint::Validate() const
172
unsigned int flags = 0;
174
if (this->GetReturnNumber() > 0x07)
175
flags |= eReturnNumber;
177
if (this->GetNumberOfReturns() > 0x07)
178
flags |= eNumberOfReturns;
180
if (this->GetScanDirection() > 0x01)
181
flags |= eScanDirection;
183
if (this->GetFlightLineEdge() > 0x01)
184
flags |= eFlightLineEdge;
186
if (eScanAngleRankMin > this->GetScanAngleRank()
187
|| this->GetScanAngleRank() > eScanAngleRankMax)
189
flags |= eScanAngleRank;
194
throw invalid_point_data("point data members out of range", flags);
201
bool LASPoint::IsValid() const
204
if( eScanAngleRankMin > this->GetScanAngleRank()
205
|| this->GetScanAngleRank() > eScanAngleRankMax
209
if (this->GetFlightLineEdge() > 0x01)
212
if (this->GetScanDirection() > 0x01)
215
if (this->GetNumberOfReturns() > 0x07)
218
if (this->GetReturnNumber() > 0x07)
226
} // namespace liblas