PCCTMC3Encoder.h 5.08 KB
Newer Older
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
1
/* The copyright in this software is being made available under the BSD
David Flynn's avatar
David Flynn committed
2
3
4
 * Licence, included below.  This software may be subject to other third
 * party and contributor rights, including patent rights, and no such
 * rights are granted under this licence.
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
5
 *
David Flynn's avatar
David Flynn committed
6
 * Copyright (c) 2017-2018, ISO/IEC
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
7
8
9
10
11
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
David Flynn's avatar
David Flynn committed
12
13
14
15
16
17
18
19
20
21
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of the ISO/IEC nor the names of its contributors
 *   may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
22
23
24
25
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
David Flynn's avatar
David Flynn committed
26
27
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
28
29
30
31
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
David Flynn's avatar
David Flynn committed
32
33
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
34
35
 */

36
#pragma once
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
37

38
#include <functional>
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
39
40
41
42
#include <map>
#include <string>
#include <vector>

43
#include "PayloadBuffer.h"
44
#include "PCCMath.h"
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
45
#include "PCCPointSet.h"
46
#include "pointset_processing.h"
47
#include "hls.h"
48
#include "partitioning.h"
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
49
50

namespace pcc {
51

52
53
//============================================================================

54
55
56
57
struct EncoderAttributeParams {
  // NB: this only makes sense for setting configurable parameters
  AttributeBrickHeader abh;
};
58
59
60

//----------------------------------------------------------------------------

61
62
63
struct EncoderParams {
  SequenceParameterSet sps;
  GeometryParameterSet gps;
64
  GeometryBrickHeader gbh;
65

66
67
68
  // NB: information about attributes is split between the SPS and the APS.
  //  => The SPS enumerates the attributes, the APS controls coding params.
  std::vector<AttributeParameterSet> aps;
69

70
71
72
  // Encoder specific parameters for attributes
  std::vector<EncoderAttributeParams> attr;

73
74
  // todo(df): this should go away
  std::map<std::string, int> attributeIdxMap;
75

76
77
  // Parameters that control partitioning
  PartitionParams partition;
78
79
80

  // attribute recolouring parameters
  RecolourParams recolour;
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
81
82
};

83
84
//============================================================================

Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
85
class PCCTMC3Encoder3 {
86
public:
87
88
  class Callbacks;

89
  PCCTMC3Encoder3();
90
91
92
93
  PCCTMC3Encoder3(const PCCTMC3Encoder3&) = delete;
  PCCTMC3Encoder3(PCCTMC3Encoder3&&) = default;
  PCCTMC3Encoder3& operator=(const PCCTMC3Encoder3& rhs) = delete;
  PCCTMC3Encoder3& operator=(PCCTMC3Encoder3&& rhs) = default;
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
94
  ~PCCTMC3Encoder3() = default;
95

96
97
  int compress(
    const PCCPointSet3& inputPointCloud,
98
    EncoderParams* params,
99
    Callbacks*,
100
    PCCPointSet3* reconstructedCloud = nullptr);
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
101

102
103
  void compressPartition(
    const PCCPointSet3& inputPointCloud,
104
    const PCCPointSet3& originPartCloud,
105
    EncoderParams* params,
106
    Callbacks*,
107
108
109
110
    PCCPointSet3* reconstructedCloud = nullptr);

  static void fixupParameterSets(EncoderParams* params);

111
private:
112
  void appendReconstructedPoints(PCCPointSet3* reconstructedCloud);
113

114
  void encodeGeometryBrick(const EncoderParams*, PayloadBuffer* buf);
115

116
117
118
119
120
121
  PCCPointSet3 quantization(const PCCPointSet3& inputPointCloud);

  void getSrcPartition(
    const PCCPointSet3& inputPointCloud,
    PCCPointSet3& srcPartition,
    std::vector<int32_t> indexes);
122

123
private:
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
124
  PCCPointSet3 pointCloud;
125

126
  // Position of the slice in the translated+scaled co-ordinate system.
127
  Vec3<int> _sliceOrigin;
128

129
  // Size of the current slice
130
  Vec3<int> _sliceBoxWhd;
131

132
133
134
135
  // The active parameter sets
  const SequenceParameterSet* _sps;
  const GeometryParameterSet* _gps;
  std::vector<const AttributeParameterSet*> _aps;
136
137
138

  // Current identifier of payloads with the same geometry
  int _sliceId;
139
140
141

  // Identifies the current tile
  int _tileId;
142

143
144
145
146
  // Current frame number.
  // NB: only the log2_max_frame_idx LSBs are sampled for frame_idx
  int _frameCounter;

147
  // Map quantized points to the original input points
148
  std::multimap<point_t, int32_t> quantizedToOrigin;
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
149
150
};

151
152
153
154
155
156
157
158
//----------------------------------------------------------------------------

class PCCTMC3Encoder3::Callbacks {
public:
  virtual void onOutputBuffer(const PayloadBuffer&) = 0;
  virtual void onPostRecolour(const PCCPointSet3&) = 0;
};

159
160
161
//============================================================================

}  // namespace pcc