-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointCloud.hpp
249 lines (211 loc) · 6.19 KB
/
PointCloud.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#ifndef _POINTCLOUD_H
#define _POINTCLOUD_H
#include <fstream>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
// this is a placeholder for the PointCloud class
// it should hold the following elements (at least):
// - x,y,z,intensity
// - return number
// - classification
// - extra fields, extra field names
// - projection (UTM, ECEF, lat/lon) (choose one to always work in... I'm thinking ECEF)
//
// and it should have the following functions (at least):
// - read LAS file
// - write LAS file
// - read ascii delimited x,y,z,i,c
// - write ascii delimited x,y,z,i,c
// - print a summary of data
// - recalculate the x,y,z extents
// - conversion to/from ECEF/latlon/UTM
// forward declaration
struct rgb48;
class PointCloud{
public:
PointCloud(); // ctor
PointCloud(unsigned int numpts); // ctor
PointCloud(const PointCloud & cloud) // copy ctor
: _x(cloud._x),
_y(cloud._y),
_z(cloud._z),
_gpstime(cloud._gpstime),
_intensity(cloud._intensity),
_classification(cloud._classification),
_RGB(cloud._RGB),
_extradata_names(cloud._extradata_names),
_extradata(cloud._extradata)
{_xmin = cloud._xmin; _xmax = cloud._xmax;
_ymin = cloud._ymin; _ymax = cloud._ymax;
_zmin = cloud._zmin; _zmax = cloud._zmax;
_gpst_min = cloud._gpst_min; _gpst_max = cloud._gpst_max;}
~PointCloud(); // dtor
// operators
PointCloud & operator=(const PointCloud & cloud);
PointCloud & operator+=(const PointCloud & cloud);
// terminal output
void print_summary() const;
void print_detailed() const;
// metadata inspectors
unsigned int pointcount() const {return _x.size();};
double xmax() const {return _xmax;};
double xmin() const {return _xmin;};
double ymax() const {return _ymax;};
double ymin() const {return _ymin;};
double zmax() const {return _zmax;};
double zmin() const {return _zmin;};
bool gpstime_present() const {if (_gpstime.size()>0) return true; else return false;};
bool intensity_present() const {if (_intensity.size()>0) return true; else return false;};
bool classification_present() const {if (_classification.size()>0) return true; else return false;};
bool RGB_present() const {if (_RGB.size()>0) return true; else return false;};
bool extradata_present(std::string fieldname) const {for (auto i=0; i<_extradata.size(); i++) {if (_extradata_names.at(i).compare(fieldname)==0) return true;} return false;};
// main data accessors
const double & x() const {return _x.front();};
const double & y() const {return _y.front();};
const double & z() const {return _z.front();};
// optional member data accessors
const double & gpstime() const {return _gpstime.front();};
const unsigned short & intensity() const {return _intensity.front();};
const unsigned char & classification() const {return _classification.front();};
const rgb48 & RGB() const {return _RGB.front();};
// user-defined member data accessors
const double & data(std::string field) const {return _extradata.at(field).front();};
// mutators
PointCloud subset(const bool & keep);
PointCloud subset(const unsigned int & keep_inds, const unsigned int keep_count);
static PointCloud read_LAS(std::string filename, unsigned int byte_offset=0);
void write_LAS(std::string filename);
protected:
private:
// metadata
double _xmin, _xmax, _ymin, _ymax, _zmin, _zmax, _gpst_min, _gpst_max;
unsigned int _pointcount;
// required data
std::vector<double> _x, _y, _z;
// optional data
std::vector<double> _gpstime;
std::vector<unsigned short> _intensity;
std::vector<unsigned char> _classification;
std::vector<rgb48> _RGB;
// user-defined data
std::vector<std::string> _extradata_names;
std::map<std::string, std::vector<double>> _extradata;
// initializing optional data fields
void add_intensity();
void add_classification();
void add_gpstime();
void add_RGB();
void add_extradata(std::string fieldname);
void calc_extents();
void read_LAS_internal(std::string filename, unsigned int byte_offset=0);
};
#pragma pack(push,1)
struct rgb48{
unsigned short R;
unsigned short G;
unsigned short B;
};
struct las_pt_0{
int X;
int Y;
int Z;
unsigned short Intensity;
unsigned char Return_Info;
unsigned char Classification;
char Scan_Angle_Rank;
unsigned char User_Data;
unsigned short Point_Source_ID;
};
struct las_pt_1{
int X;
int Y;
int Z;
unsigned short Intensity;
unsigned char Return_Info;
unsigned char Classification;
char Scan_Angle_Rank;
unsigned char User_Data;
unsigned short Point_Source_ID;
double GPSTime;
};
struct las_pt_2{
int X;
int Y;
int Z;
unsigned short Intensity;
unsigned char Return_Info;
unsigned char Classification;
char Scan_Angle_Rank;
unsigned char User_Data;
unsigned short Point_Source_ID;
unsigned short Red;
unsigned short Green;
unsigned short Blue;
};
struct las_pt_3{
int X;
int Y;
int Z;
unsigned short Intensity;
unsigned char Return_Info;
unsigned char Classification;
char Scan_Angle_Rank;
unsigned char User_Data;
unsigned short Point_Source_ID;
double GPSTime;
unsigned short Red;
unsigned short Green;
unsigned short Blue;
};
struct las_pt_4{
int X;
int Y;
int Z;
unsigned short Intensity;
unsigned char Return_Info;
unsigned char Classification;
char Scan_Angle_Rank;
unsigned char User_Data;
unsigned short Point_Source_ID;
double GPSTime;
unsigned char WaveP_Desc_Idx;
unsigned long WaveP_Byte_Offset;
unsigned int WaveP_Size;
float WaveF_Location;
float X_t;
float Y_t;
float Z_t;
};
struct las_pt_5{
int X;
int Y;
int Z;
unsigned short Intensity;
unsigned char Return_Info;
unsigned char Classification;
char Scan_Angle_Rank;
unsigned char User_Data;
unsigned short Point_Source_ID;
double GPSTime;
unsigned short Red;
unsigned short Green;
unsigned short Blue;
unsigned char WaveP_Desc_Idx;
unsigned long WaveP_Byte_Offset;
unsigned int WaveP_Size;
float WaveF_Location;
float X_t;
float Y_t;
float Z_t;
};
#pragma pack(pop)
#endif