uvgVPCCenc 1.1.0
uvgVPCCenc is an open-source real-time V-PCC encoder library written in C++ from scratch.
Loading...
Searching...
No Matches
uvgvpcc.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 * This file is part of uvgVPCCenc V-PCC encoder.
3 *
4 * Copyright (c) 2024, Tampere University, ITU/ISO/IEC, project contributors
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright notice, this
14 * list of conditions and the following disclaimer in the documentation and/or
15 * other materials provided with the distribution.
16 *
17 * * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
25 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
28 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
31 ****************************************************************************/
32
33#pragma once
34
35#include <cstddef>
36#include <cstdint>
37#include <iostream>
38#include <memory>
39#include <queue>
40#include <semaphore>
41#include <sstream>
42#include <string>
43#include <vector>
44
45#include "../utils/utils.hpp"
46
48
49// TODO(lf): why in include/uvgvpcc/ ? What about the related .cpp Why not "include/" only ?
50
51namespace uvgvpcc_enc {
52
53// A patch is a 3D object. Though, the word 'patch' can refer to the "2D version" of this patch
54struct Patch {
56 size_t patchPpi_; // viewId
57
58 size_t normalAxis_; // x
59 size_t tangentAxis_; // y
60 size_t bitangentAxis_; // z
61
62 size_t posU_; // u1_ minU_ // tangential shift
63 size_t posV_; // v1_ minV_ // bitangential shift
64 size_t posD_; // d1_ minD_ // depth shift
65
66 bool projectionMode_; // 0: related to the min depth value; 1: related to the max value
67
68 size_t sizeD_; // while posD_ is the minimum 'depth', sizeD_ store the maximum depth. TODO(lf): check if it is usefull
69
70 std::vector<uint8_t> patchOccupancyMap_; // patch occupancy map (boolean vector)
71
72 size_t widthInPixel_ = 0; // size for U // width of the patch occupancy map (in pixels)
73 size_t heightInPixel_ = 0; // size for V // height of the patch occupancy map (in pixels)
74
75 size_t widthInOccBlk_; // sizeU0_ // width of the patch occupancy map within the down-scaled frame occupancy map (in DS occupancy map
76 // blocks).
77 size_t heightInOccBlk_; // sizeV0_ // height of the patch occupancy map within the down-scaled frame occupancy map (in DS occupancy
78 // map blocks).
79
80 size_t omDSPosX_; // u0_ // location in down-scaled occupancy map // lf posBlkU
81 size_t omDSPosY_; // v0_ // location in down-scaled occupancy map
82
83 bool axisSwap_; // patch orientation // in canvas atlas (false default, true axis swap)
84
85 std::vector<typeGeometryInput> depthL1_; // depth value First layer // TODO(lf): Using the geo type here might lead to issue?
86 std::vector<typeGeometryInput> depthL2_; // depth value Second layer
87
88 // Index of the point in the PC for attribute retrieving during attribute map generation TODO(lf): use for Surface separation?
89 std::vector<size_t> depthPCidxL1_;
90 std::vector<size_t> depthPCidxL2_;
91
92 // inter packing //
93 size_t area_ = 0;
94
96 // Store the id of the best reference patch in the previous frame. Notice that even if the current patch is not
97 // matched, a reference patch id is still found. Then, this reference id will be used to check if the iou treshold
98 // is respected or not, then indicating if this patch is matched or not.
99
101 // Store not the id but the position in the list of patch of the best reference patch in the previous frame. Notice that even if
102 // the current patch is not matched, a reference patch id is still found. Then, this reference id will be used to check if the
103 // iou treshold is respected or not, then indicating if this patch is matched or not.
104 bool isMatched_ = false; // This patch match with a patch from the previous frame (the iou treshold is respected).
105 bool isLinkToAMegaPatch = false;
107
108 void setAxis(size_t normalAxis, size_t tangentAxis, size_t bitangentAxis, bool projectionMode) {
109 normalAxis_ = normalAxis;
110 tangentAxis_ = tangentAxis;
111 bitangentAxis_ = bitangentAxis;
112 projectionMode_ = projectionMode; // TODO(lf): projection mode optimization per patch
113 }
114
115 inline void setPatchPpiAndAxis(size_t patchPpi) {
116 patchPpi_ = patchPpi;
117 // now set the other variables according to the viewId
118 switch (patchPpi_) {
119 case 0:
120 setAxis(0, 2, 1, 0);
121 break;
122 case 1:
123 setAxis(1, 2, 0, 0);
124 break;
125 case 2:
126 setAxis(2, 0, 1, 0);
127 break;
128 case 3:
129 setAxis(0, 2, 1, 1);
130 break;
131 case 4:
132 setAxis(1, 2, 0, 1);
133 break;
134 case 5:
135 setAxis(2, 0, 1, 1);
136 break;
137 default:
138 throw std::runtime_error("ViewId (" + std::to_string(patchPpi) + ") not allowed... exiting");
139 break;
140 }
141 }
142
143 std::string toString() const {
144 std::stringstream str;
145 str << "patchIndex=" << patchIndex_;
146 str << ", patchPpi=" << patchPpi_;
147 str << ", normalAxis=" << normalAxis_;
148 str << ", tangentAxis=" << tangentAxis_;
149 str << ", bitangentAxis=" << bitangentAxis_;
150 str << ", projectionMode=" << projectionMode_;
151 str << ", minU=" << posU_;
152 str << ", minV=" << posV_;
153 str << ", minD=" << posD_;
154 str << ", sizeD=" << sizeD_;
155 str << ", sizeU=" << widthInPixel_;
156 str << ", sizeV=" << heightInPixel_;
157 str << ", sizeUom=" << widthInOccBlk_;
158 str << ", sizeVom=" << heightInOccBlk_;
159 str << ", omDSPosX_=" << omDSPosX_;
160 str << ", omDSPosY_=" << omDSPosY_;
161 str << ", axisSwap=" << axisSwap_;
162 return str.str();
163 }
164};
165
166struct GOF;
167
168// TODO(lf): Avid using both constant sized and dynamic sized memory member within the same struct.
169struct Frame {
170 size_t frameId; // aka relative index (0 if first encoded frame)
171 size_t frameNumber; // aka number from the input frame file name (TODO(lf): correct)
172 std::weak_ptr<GOF> gof;
173 std::shared_ptr<std::counting_semaphore<UINT16_MAX>> conccurentFrameSem;
174
175 std::string pointCloudPath;
176
178 std::vector<Vector3<typeGeometryInput>> pointsGeometry;
179 std::vector<Vector3<uint8_t>> pointsAttribute;
180
181 std::vector<Patch> patchList;
182
183 size_t mapHeight = 0; // TODO(lf): Will be a gof parameter ?
184 size_t mapHeightDS = 0;
185
186 std::vector<uint8_t> occupancyMap; // (boolean vector)
187 std::vector<uint8_t> occupancyMapDS; // Down-scaled occupancy map of the frame (boolean vector)
188
189 std::vector<uint8_t> geometryMapL1; // first layer
190 std::vector<uint8_t> geometryMapL2; // second layer
191
192 std::vector<uint8_t> attributeMapL1; // Store the three channels continuously (all R, then all G, than all B)
193 std::vector<uint8_t> attributeMapL2;
194
195 Frame(const size_t& frameId, const size_t& frameNumber, const std::string& pointCloudPath)
198 if (conccurentFrameSem) {
199 conccurentFrameSem->release();
200 }
201 };
202 void printInfo() const;
203};
204
205struct GOF {
206 std::vector<std::shared_ptr<Frame>> frames;
207 size_t nbFrames;
208 size_t gofId;
209
212
213 std::vector<uint8_t> bitstreamOccupancy;
214 std::vector<uint8_t> bitstreamGeometry;
215 std::vector<uint8_t> bitstreamAttribute;
216};
217
219namespace API {
220
222struct v3c_chunk {
223 size_t len = 0; // Length of data in buffer
224 std::unique_ptr<char[]> data; // Actual data (char type can be used to describe a byte. No need for uint8_t or unsigned char types.)
225 std::vector<size_t> v3c_unit_sizes = {};
226
227 v3c_chunk() = default;
228 v3c_chunk(size_t len, std::unique_ptr<char[]> data) : len(len), data(std::move(data)) {}
229};
230
231// ht: A V3C unit stream is composed of only V3C units without parsing information in the bitstream itself. The parsing information is here
232// given separately.
235 std::queue<v3c_chunk> v3c_chunks = {};
236 std::counting_semaphore<> available_chunks{0};
237 std::mutex io_mutex; // Locks production and consumption in the v3c_chunks queue
238};
239
240void initializeEncoder();
241void setParameter(const std::string& parameterName, const std::string& parameterValue);
242void encodeFrame(std::shared_ptr<Frame>& frame, v3c_unit_stream* output);
243void emptyFrameQueue();
244void stopEncoder();
245
246} // namespace API
247
248}; // namespace uvgvpcc_enc
Definition jobManagement.cpp:168
void stopEncoder()
Insure a proper end of the encoder execution.
Definition uvgvpcc.cpp:594
void initializeEncoder()
Create the context of the uvgVPCCenc encoder. Parse the input parameters and verify if the given conf...
Definition uvgvpcc.cpp:469
void setParameter(const std::string &parameterName, const std::string &parameterValue)
The only way to modify the exposed uvgVPCCenc parameters is by calling this function.
Definition uvgvpcc.cpp:489
void emptyFrameQueue()
This function is called when all frames to be processed have been sent to the encoder....
Definition uvgvpcc.cpp:583
void encodeFrame(std::shared_ptr< Frame > &frame, v3c_unit_stream *output)
Entry point of the uvgVPCCenc library. Take as input a frame. Create all the jobs for processing this...
Definition uvgvpcc.cpp:508
Definition log.hpp:48
constexpr size_t INVALID_PATCH_INDEX
Definition utils.hpp:52
const size_t g_infinitenumber
Definition utils.hpp:49
Bitstream writing miscellaneous.
Definition uvgvpcc.hpp:222
std::unique_ptr< char[]> data
Definition uvgvpcc.hpp:224
v3c_chunk(size_t len, std::unique_ptr< char[]> data)
Definition uvgvpcc.hpp:228
size_t len
Definition uvgvpcc.hpp:223
std::vector< size_t > v3c_unit_sizes
Definition uvgvpcc.hpp:225
Definition uvgvpcc.hpp:233
std::queue< v3c_chunk > v3c_chunks
Definition uvgvpcc.hpp:235
std::counting_semaphore available_chunks
Definition uvgvpcc.hpp:236
std::mutex io_mutex
Definition uvgvpcc.hpp:237
size_t v3c_unit_size_precision_bytes
Definition uvgvpcc.hpp:234
Definition uvgvpcc.hpp:169
size_t mapHeight
Definition uvgvpcc.hpp:183
std::string pointCloudPath
Definition uvgvpcc.hpp:175
std::vector< uint8_t > attributeMapL2
Definition uvgvpcc.hpp:193
size_t pointCount
Definition uvgvpcc.hpp:177
std::weak_ptr< GOF > gof
Definition uvgvpcc.hpp:172
std::vector< uint8_t > geometryMapL2
Definition uvgvpcc.hpp:190
std::vector< uint8_t > occupancyMap
Definition uvgvpcc.hpp:186
Frame(const size_t &frameId, const size_t &frameNumber, const std::string &pointCloudPath)
Definition uvgvpcc.hpp:195
std::shared_ptr< std::counting_semaphore< UINT16_MAX > > conccurentFrameSem
Definition uvgvpcc.hpp:173
std::vector< uint8_t > geometryMapL1
Definition uvgvpcc.hpp:189
std::vector< uint8_t > attributeMapL1
Definition uvgvpcc.hpp:192
std::vector< Vector3< uint8_t > > pointsAttribute
Definition uvgvpcc.hpp:179
~Frame()
Definition uvgvpcc.hpp:197
std::vector< Patch > patchList
Definition uvgvpcc.hpp:181
size_t mapHeightDS
Definition uvgvpcc.hpp:184
size_t frameNumber
Definition uvgvpcc.hpp:171
std::vector< Vector3< typeGeometryInput > > pointsGeometry
Definition uvgvpcc.hpp:178
void printInfo() const
Definition uvgvpcc.cpp:454
size_t frameId
Definition uvgvpcc.hpp:170
std::vector< uint8_t > occupancyMapDS
Definition uvgvpcc.hpp:187
Definition uvgvpcc.hpp:205
std::vector< std::shared_ptr< Frame > > frames
Definition uvgvpcc.hpp:206
size_t mapHeightGOF
Definition uvgvpcc.hpp:210
std::vector< uint8_t > bitstreamAttribute
Definition uvgvpcc.hpp:215
std::vector< uint8_t > bitstreamGeometry
Definition uvgvpcc.hpp:214
size_t nbFrames
Definition uvgvpcc.hpp:207
size_t mapHeightDSGOF
Definition uvgvpcc.hpp:211
size_t gofId
Definition uvgvpcc.hpp:208
std::vector< uint8_t > bitstreamOccupancy
Definition uvgvpcc.hpp:213
Definition uvgvpcc.hpp:54
size_t posU_
Definition uvgvpcc.hpp:62
bool isLinkToAMegaPatch
Definition uvgvpcc.hpp:105
bool axisSwap_
Definition uvgvpcc.hpp:83
size_t widthInPixel_
Definition uvgvpcc.hpp:72
size_t patchIndex_
Definition uvgvpcc.hpp:55
size_t area_
Definition uvgvpcc.hpp:93
std::string toString() const
Definition uvgvpcc.hpp:143
size_t sizeD_
Definition uvgvpcc.hpp:68
std::vector< typeGeometryInput > depthL2_
Definition uvgvpcc.hpp:86
size_t heightInOccBlk_
Definition uvgvpcc.hpp:77
void setPatchPpiAndAxis(size_t patchPpi)
Definition uvgvpcc.hpp:115
bool projectionMode_
Definition uvgvpcc.hpp:66
size_t omDSPosY_
Definition uvgvpcc.hpp:81
size_t posD_
Definition uvgvpcc.hpp:64
size_t bestMatchIdx
Definition uvgvpcc.hpp:100
size_t bitangentAxis_
Definition uvgvpcc.hpp:60
size_t normalAxis_
Definition uvgvpcc.hpp:58
std::vector< size_t > depthPCidxL2_
Definition uvgvpcc.hpp:90
size_t referencePatchId_
Definition uvgvpcc.hpp:95
std::vector< typeGeometryInput > depthL1_
Definition uvgvpcc.hpp:85
bool isMatched_
Definition uvgvpcc.hpp:104
size_t heightInPixel_
Definition uvgvpcc.hpp:73
std::vector< size_t > depthPCidxL1_
Definition uvgvpcc.hpp:89
size_t tangentAxis_
Definition uvgvpcc.hpp:59
size_t posV_
Definition uvgvpcc.hpp:63
std::vector< uint8_t > patchOccupancyMap_
Definition uvgvpcc.hpp:70
size_t unionPatchReferenceIdx
Definition uvgvpcc.hpp:106
size_t widthInOccBlk_
Definition uvgvpcc.hpp:75
void setAxis(size_t normalAxis, size_t tangentAxis, size_t bitangentAxis, bool projectionMode)
Definition uvgvpcc.hpp:108
size_t omDSPosX_
Definition uvgvpcc.hpp:80
size_t patchPpi_
Definition uvgvpcc.hpp:56