forked from elemoine/pointcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlazperf_adapter.hpp
118 lines (92 loc) · 2.84 KB
/
lazperf_adapter.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
/***********************************************************************
* lazperf_adapter.hpp
*
* LazPerf compression/decompression
*
* Copyright (c) 2016 Paul Blottiere, Oslandia
*
***********************************************************************/
#pragma once
#include "pc_api_internal.h"
#ifdef HAVE_LAZPERF
#include <laz-perf/common/common.hpp>
#include <laz-perf/compressor.hpp>
#include <laz-perf/decompressor.hpp>
#include <laz-perf/encoder.hpp>
#include <laz-perf/decoder.hpp>
#include <laz-perf/formats.hpp>
#include <laz-perf/las.hpp>
/**********************************************************************
* C API
*/
extern "C" {
size_t lazperf_compress_from_uncompressed(const PCPATCH_UNCOMPRESSED *pa, uint8_t **compressed);
size_t lazperf_uncompress_from_compressed(const PCPATCH_LAZPERF *pa, uint8_t **decompressed);
}
/**********************************************************************
* INTERNAL CPP
*/
// utility functions
void lazperf_dump( uint8_t* data, const size_t size );
void lazperf_dump( const PCPATCH_UNCOMPRESSED *p );
void lazperf_dump( const PCPATCH_LAZPERF *p );
// struct which capture data coming from the compressor
struct LazPerfBuf {
LazPerfBuf() : buf(), idx(0) {}
const uint8_t* data() {
return reinterpret_cast<const uint8_t*>(buf.data());
}
void putBytes(const unsigned char* b, size_t len) {
while(len --) {
buf.push_back(*b++);
}
}
void putByte(const unsigned char b) {
buf.push_back(b);
}
unsigned char getByte() {
return buf[idx++];
}
void getBytes(unsigned char *b, int len) {
for (int i = 0 ; i < len ; i ++) {
b[i] = getByte();
}
}
std::vector<unsigned char> buf;
size_t idx;
};
// some typedef
typedef laszip::encoders::arithmetic<LazPerfBuf> Encoder;
typedef laszip::decoders::arithmetic<LazPerfBuf> Decoder;
typedef laszip::formats::dynamic_field_compressor<Encoder>::ptr Compressor;
typedef laszip::formats::dynamic_field_decompressor<Decoder>::ptr Decompressor;
// LazPerf class
template<typename LazPerfEngine, typename LazPerfCoder>
class LazPerf {
public:
LazPerf( const PCSCHEMA *pcschema, LazPerfBuf &buf );
~LazPerf();
size_t pointsize() const { return _pointsize; }
protected:
void initSchema();
bool addField(const PCDIMENSION *dim);
const PCSCHEMA *_pcschema;
LazPerfCoder _coder;
LazPerfEngine _engine;
size_t _pointsize;
};
// compressor
class LazPerfCompressor : public LazPerf<Compressor, Encoder> {
public:
LazPerfCompressor( const PCSCHEMA *pcschema, LazPerfBuf &output);
~LazPerfCompressor();
size_t compress( const uint8_t *input, const size_t inputsize );
};
// decompressor
class LazPerfDecompressor : public LazPerf<Decompressor, Decoder> {
public:
LazPerfDecompressor( const PCSCHEMA *pcschema, LazPerfBuf &input );
~LazPerfDecompressor();
size_t decompress( uint8_t *data, const size_t datasize );
};
#endif // HAVE_LAZPERF