/
point.go
544 lines (447 loc) · 9.82 KB
/
point.go
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
// Copyright (c) 2015 Boise Center Aerospace Laboratory.
// All rights reserved. Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package las
import (
"encoding/binary"
)
// Represents a fully capable LASF point. The interface handles any field
// available in *any* point format from the LASF 1.4 spec. If a field is not
// supported, 0 or nil is returned. This may possible change to return an
// error as well.
type Pointer interface {
RecordFormat() uint8
X() float64
Y() float64
Z() float64
Intensity() uint16
RetNum() uint8
RetCount() uint8
ScanFlag() uint8
Edge() uint8
Classification() uint8
//ClassificationString string
ScanAngle() int16
UserData() uint8
PointSourceID() uint16
GpsTime() float64
Red() uint16
Green() uint16
Blue() uint16
NIR() uint16
WavePacketDesc() uint8
WaveOffset() uint64
WaveSize() uint32
//ReturnPointWaveLoc uint32
X_t() float32
Y_t() float32
Z_t() float32
}
/*
All lidar point formats are based on a combination of the following structures
- Point format 0 or 6
- GPS time // mandatory in 6-10
- Red, green and blue packet
- NIR packet // 6-10 only
- Wave packet
Each point format has an internal, binary representation of the point for
reading/writing to disk (pointPacketN, where N is 0-10), and the implementation
of the format which satisfies the Pointer interface (pointFormatN). Omitted
fields are zeroed out (not initialized), and return 0. You must override
RecordFormat() for each concrete type.
The members are public so we can use binary.Read for reading, but the structs
are private.
*/
// Base types
type GpsTimePacket float64
func (gps GpsTimePacket) GpsTime() float64 {
return float64(gps)
}
func (gps *GpsTimePacket) SetGpsTime(t float64) {
*gps = GpsTimePacket(t)
}
type rgbPacket struct {
Red_, Green_, Blue_ uint16
}
func (rgb *rgbPacket) Red() uint16 {
return rgb.Red_
}
func (rgb *rgbPacket) Green() uint16 {
return rgb.Green_
}
func (rgb *rgbPacket) Blue() uint16 {
return rgb.Blue_
}
func (rgb *rgbPacket) SetRGB(r, g, b uint16) {
rgb.Red_, rgb.Green_, rgb.Blue_ = r, g, b
}
type nirPacket uint16
func (n nirPacket) NIR() uint16 {
return uint16(n)
}
func (nir *nirPacket) SetNIR(n uint16) {
*nir = nirPacket(n)
}
// Encapsulate the waveform packet description
type wavePacket struct {
WavePacketDesc_ uint8
WaveformOffset_ uint64
WaveformSize_ uint32
WaveformReturnPoint_ float32
X_t_, Y_t_, Z_t_ float32
}
func (w *wavePacket) WavePacketDesc() uint8 {
return w.WavePacketDesc_
}
func (w *wavePacket) WaveOffset() uint64 {
return w.WaveformOffset_
}
func (w *wavePacket) WaveSize() uint32 {
return w.WaveformSize_
}
func (w *wavePacket) WaveformReturnPoint() float32 {
return w.WaveformReturnPoint_
}
func (w *wavePacket) X_t() float32 {
return w.X_t_
}
func (w *wavePacket) Y_t() float32 {
return w.Y_t_
}
func (w *wavePacket) Z_t() float32 {
return w.Z_t_
}
type pointPacket0 struct {
X_, Y_, Z_ int32
Intensity_ uint16
// Return Number 0-2
// Number of returns 3-5
// Scan Direction flag 6
// Edge of flight line 7
RetScanData_ uint8
Classification_ uint8
ScanAngle_ int8
UserData_ uint8
PointSourceId_ uint16
}
func (p *pointPacket0) RecordFormat() uint8 {
return 0
}
func (p *pointPacket0) X() float64 {
return float64(p.X_)
}
func (p *pointPacket0) Y() float64 {
return float64(p.Y_)
}
func (p *pointPacket0) Z() float64 {
return float64(p.Z_)
}
func (p *pointPacket0) Intensity() uint16 {
return p.Intensity_
}
func (p *pointPacket0) RetNum() uint8 {
return convertToUInt8(p.RetScanData_, 0, 3)
}
func (p *pointPacket0) RetCount() uint8 {
return convertToUInt8(p.RetScanData_, 3, 3)
}
func (p *pointPacket0) ScanFlag() uint8 {
return convertToUInt8(p.RetScanData_, 6, 1)
}
func (p *pointPacket0) Edge() uint8 {
return convertToUInt8(p.RetScanData_, 7, 1)
}
func (p *pointPacket0) Classification() uint8 {
return p.Classification_
}
func (p *pointPacket0) ScanAngle() int16 {
return int16(p.ScanAngle_)
}
func (p *pointPacket0) UserData() uint8 {
return p.UserData_
}
func (p *pointPacket0) PointSourceID() uint16 {
return p.PointSourceId_
}
type pointFormat0 struct {
// Concrete
pointPacket0
// Zero fields
GpsTimePacket
rgbPacket
nirPacket
wavePacket
}
func (p *pointFormat0) RecordFormat() uint8 {
return 0
}
type pointPacket1 struct {
pointPacket0
GpsTimePacket
}
type pointFormat1 struct {
pointPacket1
rgbPacket
nirPacket
wavePacket
}
func (p *pointFormat1) RecordFormat() uint8 {
return 1
}
type pointPacket2 struct {
pointPacket0
rgbPacket
}
type pointFormat2 struct {
pointPacket2
GpsTimePacket
nirPacket
wavePacket
}
func (p *pointFormat2) RecordFormat() uint8 {
return 2
}
type pointPacket3 struct {
pointPacket0
GpsTimePacket
rgbPacket
}
type pointFormat3 struct {
pointPacket3
nirPacket
wavePacket
}
func (p *pointFormat3) RecordFormat() uint8 {
return 3
}
type pointPacket4 struct {
pointPacket1
wavePacket
}
type pointFormat4 struct {
pointPacket4
rgbPacket
nirPacket
}
func (p *pointFormat4) RecordFormat() uint8 {
return 4
}
type pointPacket5 struct {
pointPacket3
wavePacket
}
type pointFormat5 struct {
pointPacket5
nirPacket
}
func (p *pointFormat5) RecordFormat() uint8 {
return 5
}
func (las *Lasf) readPointFormat0() (Pointer, error) {
var p pointPacket0
err := binary.Read(las.fin, binary.LittleEndian, &p)
if err != nil {
return nil, err
}
return &pointFormat0{pointPacket0: p}, nil
}
func (las *Lasf) readPointFormat1() (Pointer, error) {
var p pointPacket1
err := binary.Read(las.fin, binary.LittleEndian, &p)
if err != nil {
return nil, err
}
return &pointFormat1{pointPacket1: p}, nil
}
func (las *Lasf) readPointFormat2() (Pointer, error) {
var p pointPacket2
err := binary.Read(las.fin, binary.LittleEndian, &p)
if err != nil {
return nil, err
}
return &pointFormat2{pointPacket2: p}, nil
}
func (las *Lasf) readPointFormat3() (Pointer, error) {
var p pointPacket3
err := binary.Read(las.fin, binary.LittleEndian, &p)
if err != nil {
return nil, err
}
return &pointFormat3{pointPacket3: p}, nil
}
func (las *Lasf) readPointFormat4() (Pointer, error) {
var p pointPacket4
err := binary.Read(las.fin, binary.LittleEndian, &p)
if err != nil {
return nil, err
}
return &pointFormat4{pointPacket4: p}, nil
}
func (las *Lasf) readPointFormat5() (Pointer, error) {
var p pointPacket5
err := binary.Read(las.fin, binary.LittleEndian, &p)
if err != nil {
return nil, err
}
return &pointFormat5{pointPacket5: p}, nil
}
type pointPacket6 struct {
X_, Y_, Z_ int32
Intensity_ uint16
// Return Number 0-4
// Number of returns 4-7
ReturnData_ uint8
// Classification Flags 0-3
// Scanner Channel 4-5
// Scan Direction flag 6
// Edge of flight line 7
ScanData_ uint8
Classification_ uint8
UserData_ uint8
ScanAngle_ int16
PointSourceId_ uint16
GpsTimePacket
}
func (p *pointPacket6) RecordFormat() uint8 {
return 6
}
func (p *pointPacket6) X() float64 {
return float64(p.X_)
}
func (p *pointPacket6) Y() float64 {
return float64(p.Y_)
}
func (p *pointPacket6) Z() float64 {
return float64(p.Z_)
}
func (p *pointPacket6) Intensity() uint16 {
return p.Intensity_
}
func (p *pointPacket6) RetNum() uint8 {
return convertToUInt8(p.ReturnData_, 0, 4)
}
func (p *pointPacket6) RetCount() uint8 {
return convertToUInt8(p.ReturnData_, 4, 4)
}
/*
func (p *pointPacket6) ClassificationFlags() uint8 {
return convertToUInt8(p.ScanData_, 0, 4)
}
func (p *pointPacket6) ScanChannel() uint8 {
return convertToUInt8(p.ScanData_, 4, 2)
}
*/
func (p *pointPacket6) ScanFlag() uint8 {
return convertToUInt8(p.ScanData_, 6, 1)
}
func (p *pointPacket6) Edge() uint8 {
return convertToUInt8(p.ReturnData_, 7, 1)
}
func (p *pointPacket6) Classification() uint8 {
return p.Classification_
}
func (p *pointPacket6) UserData() uint8 {
return p.UserData_
}
func (p *pointPacket6) ScanAngle() int16 {
return p.ScanAngle_
}
func (p *pointPacket6) PointSourceID() uint16 {
return p.PointSourceId_
}
type pointFormat6 struct {
pointPacket6
rgbPacket
nirPacket
wavePacket
}
func (p *pointFormat6) RecordFormat() uint8 {
return 6
}
type pointPacket7 struct {
pointPacket6
rgbPacket
}
type pointFormat7 struct {
pointPacket7
nirPacket
wavePacket
}
func (p *pointFormat7) RecordFormat() uint8 {
return 7
}
type pointPacket8 struct {
pointPacket7
nirPacket
}
type pointFormat8 struct {
pointPacket8
wavePacket
}
func (p *pointFormat8) RecordFormat() uint8 {
return 8
}
type pointPacket9 struct {
pointPacket6
wavePacket
}
type pointFormat9 struct {
pointPacket9
rgbPacket
nirPacket
}
func (p *pointFormat9) RecordFormat() uint8 {
return 9
}
type pointPacket10 struct {
pointPacket6
rgbPacket
nirPacket
wavePacket
}
type pointFormat10 struct {
pointPacket10
}
func (p *pointFormat10) RecordFormat() uint8 {
return 10
}
func (las *Lasf) readPointFormat6() (Pointer, error) {
var p pointPacket6
err := binary.Read(las.fin, binary.LittleEndian, &p)
if err != nil {
return nil, err
}
return &pointFormat6{pointPacket6: p}, nil
}
func (las *Lasf) readPointFormat7() (Pointer, error) {
var p pointPacket7
err := binary.Read(las.fin, binary.LittleEndian, &p)
if err != nil {
return nil, err
}
return &pointFormat7{pointPacket7: p}, nil
}
func (las *Lasf) readPointFormat8() (Pointer, error) {
var p pointPacket8
err := binary.Read(las.fin, binary.LittleEndian, &p)
if err != nil {
return nil, err
}
return &pointFormat8{pointPacket8: p}, nil
}
func (las *Lasf) readPointFormat9() (Pointer, error) {
var p pointPacket9
err := binary.Read(las.fin, binary.LittleEndian, &p)
if err != nil {
return nil, err
}
return &pointFormat9{pointPacket9: p}, nil
}
func (las *Lasf) readPointFormat10() (Pointer, error) {
var p pointPacket10
err := binary.Read(las.fin, binary.LittleEndian, &p)
if err != nil {
return nil, err
}
return &pointFormat10{pointPacket10: p}, nil
}