~ubuntu-branches/ubuntu/trusty/liblas/trusty-proposed

« back to all changes in this revision

Viewing changes to src/laspoint.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2014-01-05 17:00:29 UTC
  • mfrom: (7.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140105170029-ddtp0j63x5jvck2u
Tags: 1.7.0+dfsg-2
Fixed missing linking of system boost component.
(closes: #733282)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
#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>
47
 
// std
48
 
#include <cstring>
49
 
 
50
 
namespace liblas {
51
 
 
52
 
LASPoint::LASPoint() :
53
 
    m_intensity(0),
54
 
    m_flags(0),
55
 
    m_class(0),
56
 
    m_angleRank(0),
57
 
    m_userData(0),
58
 
    m_pointSourceId(0),
59
 
    m_gpsTime(0)
60
 
{
61
 
    std::memset(m_coords, 0, sizeof(m_coords));
62
 
}
63
 
 
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)
73
 
{
74
 
    std::memcpy(m_coords, other.m_coords, sizeof(m_coords));
75
 
}
76
 
 
77
 
LASPoint& LASPoint::operator=(LASPoint const& rhs)
78
 
{
79
 
    if (&rhs != this)
80
 
    {
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;
92
 
    }
93
 
    return *this;
94
 
}
95
 
 
96
 
void LASPoint::SetCoordinates(LASHeader const& header, double x, double y, double z)
97
 
{
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();
101
 
 
102
 
    SetCoordinates(cx, cy, cz);
103
 
}
104
 
 
105
 
void LASPoint::SetReturnNumber(uint16_t const& num)
106
 
{
107
 
    // Store value in bits 0,1,2
108
 
    uint8_t mask = 0x7 << 0; // 0b00000111
109
 
    m_flags &= ~mask;
110
 
    m_flags |= mask & (static_cast<uint8_t>(num) << 0);
111
 
 
112
 
}
113
 
 
114
 
void LASPoint::SetNumberOfReturns(uint16_t const& num)
115
 
{
116
 
    // Store value in bits 3,4,5
117
 
    uint8_t mask = 0x7 << 3; // 0b00111000
118
 
    m_flags &= ~mask;
119
 
    m_flags |= mask & (static_cast<uint8_t>(num) << 3);
120
 
}
121
 
 
122
 
void LASPoint::SetScanDirection(uint16_t const& dir)
123
 
{
124
 
    // Store value in bit 6
125
 
    uint8_t mask = 0x1 << 6; // 0b01000000
126
 
    m_flags &= ~mask;
127
 
    m_flags |= mask & (static_cast<uint8_t>(dir) << 6);
128
 
}
129
 
 
130
 
void LASPoint::SetFlightLineEdge(uint16_t const& edge)
131
 
{
132
 
    // Store value in bit 7
133
 
    uint8_t mask = 0x1 << 7; // 0b10000000
134
 
    m_flags &= ~mask;
135
 
    m_flags |= mask & (static_cast<uint8_t>(edge) << 7);}
136
 
 
137
 
void LASPoint::SetScanAngleRank(int8_t const& rank)
138
 
{
139
 
    m_angleRank = rank;
140
 
}
141
 
 
142
 
void LASPoint::SetUserData(uint8_t const& data)
143
 
{
144
 
    m_userData = data;
145
 
}
146
 
 
147
 
bool LASPoint::equal(LASPoint const& other) const
148
 
{
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;
153
 
 
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];
157
 
 
158
 
    // TODO: Should we compare other data members, besides the coordinates?
159
 
 
160
 
    if (((dx <= epsilon) && (dx >= -epsilon))
161
 
        && ((dy <= epsilon) && (dy >= -epsilon))
162
 
        && ((dz <= epsilon) && (dz >= -epsilon)))
163
 
    {
164
 
        return true;
165
 
    }
166
 
 
167
 
    return false;
168
 
}
169
 
 
170
 
bool LASPoint::Validate() const
171
 
{
172
 
    unsigned int flags = 0;
173
 
 
174
 
    if (this->GetReturnNumber() > 0x07)
175
 
        flags |= eReturnNumber;
176
 
 
177
 
    if (this->GetNumberOfReturns() > 0x07)
178
 
        flags |= eNumberOfReturns;
179
 
 
180
 
    if (this->GetScanDirection() > 0x01)
181
 
        flags |= eScanDirection;
182
 
 
183
 
    if (this->GetFlightLineEdge() > 0x01)
184
 
        flags |= eFlightLineEdge;
185
 
 
186
 
    if (eScanAngleRankMin > this->GetScanAngleRank()
187
 
        || this->GetScanAngleRank() > eScanAngleRankMax)
188
 
    {
189
 
        flags |= eScanAngleRank;
190
 
    }
191
 
 
192
 
    if (flags > 0)
193
 
    {
194
 
        throw invalid_point_data("point data members out of range", flags);
195
 
    }
196
 
 
197
 
    return true;
198
 
}
199
 
 
200
 
 
201
 
bool LASPoint::IsValid() const
202
 
{
203
 
    
204
 
    if( eScanAngleRankMin > this->GetScanAngleRank() 
205
 
        || this->GetScanAngleRank() > eScanAngleRankMax
206
 
      )
207
 
        return false;
208
 
 
209
 
    if (this->GetFlightLineEdge() > 0x01)
210
 
        return false;
211
 
 
212
 
    if (this->GetScanDirection() > 0x01)
213
 
        return false;
214
 
 
215
 
    if (this->GetNumberOfReturns() > 0x07)
216
 
        return false;
217
 
 
218
 
    if (this->GetReturnNumber() > 0x07)
219
 
        return false;
220
 
 
221
 
 
222
 
    return true;
223
 
}
224
 
 
225
 
 
226
 
} // namespace liblas