ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Decoder.h
Go to the documentation of this file.
1 /*
2  * Original work Copyright 2009 - 2010 Kevin Ackley (kackley@gwi.net)
3  * Modified work Copyright 2018 - 2020 Andy Maloney <asmaloney@gmail.com>
4  *
5  * Permission is hereby granted, free of charge, to any person or organization
6  * obtaining a copy of the software and accompanying documentation covered by
7  * this license (the "Software") to use, reproduce, display, distribute,
8  * execute, and transmit the Software, and to prepare derivative works of the
9  * Software, and to permit third-parties to whom the Software is furnished to
10  * do so, all subject to the following:
11  *
12  * The copyright notices in the Software and this entire statement, including
13  * the above license grant, this restriction and the following disclaimer,
14  * must be included in all copies of the Software, in whole or in part, and
15  * all derivative works of the Software, unless such copies or derivative
16  * works are solely in the form of machine-executable object code generated by
17  * a source language processor.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  * DEALINGS IN THE SOFTWARE.
26  */
27 
28 #pragma once
29 
30 #include "Common.h"
31 
32 namespace e57
33 {
34  class Decoder
35  {
36  public:
37  static std::shared_ptr<Decoder> DecoderFactory( unsigned bytestreamNumber,
38  const CompressedVectorNodeImpl *cVector,
39  std::vector<SourceDestBuffer> &dbufs, const ustring &codecPath );
40  Decoder() = delete;
41  virtual ~Decoder() = default;
42 
43  virtual void destBufferSetNew( std::vector<SourceDestBuffer> &dbufs ) = 0;
44  virtual uint64_t totalRecordsCompleted() = 0;
45  virtual size_t inputProcess( const char *source, const size_t count ) = 0;
46  virtual void stateReset() = 0;
47  unsigned bytestreamNumber() const
48  {
49  return bytestreamNumber_;
50  }
51 #ifdef E57_DEBUG
52  virtual void dump( int indent = 0, std::ostream &os = std::cout ) = 0;
53 #endif
54 
55  protected:
56  Decoder( unsigned bytestreamNumber );
57 
58  unsigned int bytestreamNumber_;
59  };
60 
61  class BitpackDecoder : public Decoder
62  {
63  public:
64  void destBufferSetNew( std::vector<SourceDestBuffer> &dbufs ) override;
65 
66  uint64_t totalRecordsCompleted() override
67  {
68  return ( currentRecordIndex_ );
69  }
70 
71  size_t inputProcess( const char *source, const size_t availableByteCount ) override;
72  virtual size_t inputProcessAligned( const char *inbuf, const size_t firstBit, const size_t endBit ) = 0;
73 
74  void stateReset() override;
75 
76 #ifdef E57_DEBUG
77  void dump( int indent = 0, std::ostream &os = std::cout ) override;
78 #endif
79  protected:
80  BitpackDecoder( unsigned bytestreamNumber, SourceDestBuffer &dbuf, unsigned alignmentSize,
81  uint64_t maxRecordCount );
82 
83  void inBufferShiftDown();
84 
85  uint64_t currentRecordIndex_ = 0;
86  uint64_t maxRecordCount_ = 0;
87 
88  std::shared_ptr<SourceDestBufferImpl> destBuffer_;
89 
90  std::vector<char> inBuffer_;
91  size_t inBufferFirstBit_ = 0;
92  size_t inBufferEndByte_ = 0;
93  unsigned int inBufferAlignmentSize_;
94  unsigned int bitsPerWord_;
95  unsigned int bytesPerWord_;
96  };
97 
99  {
100  public:
102  uint64_t maxRecordCount );
103 
104  size_t inputProcessAligned( const char *inbuf, const size_t firstBit, const size_t endBit ) override;
105 
106 #ifdef E57_DEBUG
107  void dump( int indent = 0, std::ostream &os = std::cout ) override;
108 #endif
109  protected:
111  };
112 
114  {
115  public:
116  BitpackStringDecoder( unsigned bytestreamNumber, SourceDestBuffer &dbuf, uint64_t maxRecordCount );
117 
118  size_t inputProcessAligned( const char *inbuf, const size_t firstBit, const size_t endBit ) override;
119 
120 #ifdef E57_DEBUG
121  void dump( int indent = 0, std::ostream &os = std::cout ) override;
122 #endif
123  protected:
124  bool readingPrefix_ = true;
125  int prefixLength_ = 1;
126  uint8_t prefixBytes_[8] = {};
128  uint64_t stringLength_ = 0;
130  uint64_t nBytesStringRead_ = 0;
131  };
132 
133  template <typename RegisterT> class BitpackIntegerDecoder : public BitpackDecoder
134  {
135  public:
136  BitpackIntegerDecoder( bool isScaledInteger, unsigned bytestreamNumber, SourceDestBuffer &dbuf, int64_t minimum,
137  int64_t maximum, double scale, double offset, uint64_t maxRecordCount );
138 
139  size_t inputProcessAligned( const char *inbuf, const size_t firstBit, const size_t endBit ) override;
140 
141 #ifdef E57_DEBUG
142  void dump( int indent = 0, std::ostream &os = std::cout ) override;
143 #endif
144  protected:
146  int64_t minimum_;
147  int64_t maximum_;
148  double scale_;
149  double offset_;
150  unsigned bitsPerRecord_;
151  RegisterT destBitMask_;
152  };
153 
155  {
156  public:
157  ConstantIntegerDecoder( bool isScaledInteger, unsigned bytestreamNumber, SourceDestBuffer &dbuf, int64_t minimum,
158  double scale, double offset, uint64_t maxRecordCount );
159  void destBufferSetNew( std::vector<SourceDestBuffer> &dbufs ) override;
160  uint64_t totalRecordsCompleted() override
161  {
162  return currentRecordIndex_;
163  }
164  size_t inputProcess( const char *source, const size_t availableByteCount ) override;
165  void stateReset() override;
166 #ifdef E57_DEBUG
167  void dump( int indent = 0, std::ostream &os = std::cout ) override;
168 #endif
169  protected:
170  uint64_t currentRecordIndex_ = 0;
171  uint64_t maxRecordCount_;
172 
173  std::shared_ptr<SourceDestBufferImpl> destBuffer_;
174 
176  int64_t minimum_;
177  double scale_;
178  double offset_;
179  };
180 }
int count
int offset
std::vector< char > inBuffer_
Definition: Decoder.h:90
uint64_t totalRecordsCompleted() override
Definition: Decoder.h:66
virtual size_t inputProcessAligned(const char *inbuf, const size_t firstBit, const size_t endBit)=0
uint64_t maxRecordCount_
Definition: Decoder.h:86
void stateReset() override
Definition: Decoder.cpp:291
std::shared_ptr< SourceDestBufferImpl > destBuffer_
Definition: Decoder.h:88
BitpackDecoder(unsigned bytestreamNumber, SourceDestBuffer &dbuf, unsigned alignmentSize, uint64_t maxRecordCount)
Definition: Decoder.cpp:191
size_t inBufferFirstBit_
Definition: Decoder.h:91
unsigned int inBufferAlignmentSize_
Definition: Decoder.h:93
uint64_t currentRecordIndex_
Definition: Decoder.h:85
void dump(int indent=0, std::ostream &os=std::cout) override
Definition: Decoder.cpp:324
size_t inBufferEndByte_
Definition: Decoder.h:92
size_t inputProcess(const char *source, const size_t availableByteCount) override
Definition: Decoder.cpp:209
void destBufferSetNew(std::vector< SourceDestBuffer > &dbufs) override
Definition: Decoder.cpp:199
unsigned int bytesPerWord_
Definition: Decoder.h:95
void inBufferShiftDown()
Definition: Decoder.cpp:297
unsigned int bitsPerWord_
Definition: Decoder.h:94
void dump(int indent=0, std::ostream &os=std::cout) override
Definition: Decoder.cpp:452
FloatPrecision precision_
Definition: Decoder.h:110
BitpackFloatDecoder(unsigned bytestreamNumber, SourceDestBuffer &dbuf, FloatPrecision precision, uint64_t maxRecordCount)
Definition: Decoder.cpp:352
size_t inputProcessAligned(const char *inbuf, const size_t firstBit, const size_t endBit) override
Definition: Decoder.cpp:360
BitpackIntegerDecoder(bool isScaledInteger, unsigned bytestreamNumber, SourceDestBuffer &dbuf, int64_t minimum, int64_t maximum, double scale, double offset, uint64_t maxRecordCount)
Definition: Decoder.cpp:643
size_t inputProcessAligned(const char *inbuf, const size_t firstBit, const size_t endBit) override
Definition: Decoder.cpp:658
void dump(int indent=0, std::ostream &os=std::cout) override
Definition: Decoder.cpp:802
BitpackStringDecoder(unsigned bytestreamNumber, SourceDestBuffer &dbuf, uint64_t maxRecordCount)
Definition: Decoder.cpp:468
size_t inputProcessAligned(const char *inbuf, const size_t firstBit, const size_t endBit) override
Definition: Decoder.cpp:474
uint8_t prefixBytes_[8]
Definition: Decoder.h:126
void dump(int indent=0, std::ostream &os=std::cout) override
Definition: Decoder.cpp:617
uint64_t nBytesStringRead_
Definition: Decoder.h:130
size_t inputProcess(const char *source, const size_t availableByteCount) override
Definition: Decoder.cpp:836
void destBufferSetNew(std::vector< SourceDestBuffer > &dbufs) override
Definition: Decoder.cpp:826
std::shared_ptr< SourceDestBufferImpl > destBuffer_
Definition: Decoder.h:173
uint64_t totalRecordsCompleted() override
Definition: Decoder.h:160
ConstantIntegerDecoder(bool isScaledInteger, unsigned bytestreamNumber, SourceDestBuffer &dbuf, int64_t minimum, double scale, double offset, uint64_t maxRecordCount)
Definition: Decoder.cpp:818
void stateReset() override
Definition: Decoder.cpp:872
void dump(int indent=0, std::ostream &os=std::cout) override
Definition: Decoder.cpp:877
static std::shared_ptr< Decoder > DecoderFactory(unsigned bytestreamNumber, const CompressedVectorNodeImpl *cVector, std::vector< SourceDestBuffer > &dbufs, const ustring &codecPath)
Definition: Decoder.cpp:41
virtual void stateReset()=0
virtual size_t inputProcess(const char *source, const size_t count)=0
virtual void dump(int indent=0, std::ostream &os=std::cout)=0
unsigned bytestreamNumber() const
Definition: Decoder.h:47
virtual ~Decoder()=default
virtual uint64_t totalRecordsCompleted()=0
virtual void destBufferSetNew(std::vector< SourceDestBuffer > &dbufs)=0
unsigned int bytestreamNumber_
Definition: Decoder.h:58
Decoder()=delete
FloatPrecision
The IEEE floating point number precisions supported.
Definition: E57Format.h:71
@ E57_SINGLE
32 bit IEEE floating point number format
Definition: E57Format.h:72
std::string ustring
UTF-8 encodeded Unicode string.
Definition: E57Format.h:54