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#include <algorithm>
45#include <unordered_map>
46
47#include "../utils/utils.hpp"
48
50
51// TODO(lf): why in include/uvgvpcc/ ? What about the related .cpp Why not "include/" only ?
52
53namespace uvgvpcc_enc {
54
55// A patch is a 3D object. Though, the word 'patch' can refer to the "2D version" of this patch
56struct Patch {
58 size_t patchPpi_; // viewId
59
60 size_t normalAxis_; // x
61 size_t tangentAxis_; // y
62 size_t bitangentAxis_; // z
63
64 size_t posU_; // u1_ minU_ // tangential shift
65 size_t posV_; // v1_ minV_ // bitangential shift
66 size_t posD_; // d1_ minD_ // depth shift
67
68 bool projectionMode_; // 0: related to the min depth value; 1: related to the max value
69
70 size_t sizeD_; // while posD_ is the minimum 'depth', sizeD_ store the maximum depth. TODO(lf): check if it is usefull
71
72 std::vector<uint8_t> patchOccupancyMap_; // patch occupancy map (boolean vector)
73
74 size_t widthInPixel_ = 0; // size for U // width of the patch occupancy map (in pixels)
75 size_t heightInPixel_ = 0; // size for V // height of the patch occupancy map (in pixels)
76
77 size_t widthInOccBlk_; // sizeU0_ // width of the patch occupancy map within the down-scaled frame occupancy map (in DS occupancy map
78 // blocks).
79 size_t heightInOccBlk_; // sizeV0_ // height of the patch occupancy map within the down-scaled frame occupancy map (in DS occupancy
80 // map blocks).
81
82 size_t omDSPosX_; // u0_ // location in down-scaled occupancy map // lf posBlkU
83 size_t omDSPosY_; // v0_ // location in down-scaled occupancy map
84
85 bool axisSwap_; // patch orientation // in canvas atlas (false default, true axis swap)
86
87 std::vector<typeGeometryInput> depthL1_; // depth value First layer // TODO(lf): Using the geo type here might lead to issue?
88 std::vector<typeGeometryInput> depthL2_; // depth value Second layer
89
90 // Index of the point in the PC for attribute retrieving during attribute map generation TODO(lf): use for Surface separation?
91 std::vector<size_t> depthPCidxL1_;
92 std::vector<size_t> depthPCidxL2_;
93
94 // inter packing //
95 size_t area_ = 0;
96
98 // Store the id of the best reference patch in the previous frame. Notice that even if the current patch is not
99 // matched, a reference patch id is still found. Then, this reference id will be used to check if the iou treshold
100 // is respected or not, then indicating if this patch is matched or not.
101
103 // 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
104 // the current patch is not matched, a reference patch id is still found. Then, this reference id will be used to check if the
105 // iou treshold is respected or not, then indicating if this patch is matched or not.
106 bool isMatched_ = false; // This patch match with a patch from the previous frame (the iou treshold is respected).
107 bool isLinkToAMegaPatch = false;
109
110 void setAxis(size_t normalAxis, size_t tangentAxis, size_t bitangentAxis, bool projectionMode) {
111 normalAxis_ = normalAxis;
112 tangentAxis_ = tangentAxis;
113 bitangentAxis_ = bitangentAxis;
114 projectionMode_ = projectionMode; // TODO(lf): projection mode optimization per patch
115 }
116
117 inline void setPatchPpiAndAxis(size_t patchPpi) {
118 patchPpi_ = patchPpi;
119 // now set the other variables according to the viewId
120 switch (patchPpi_) {
121 case 0:
122 setAxis(0, 2, 1, 0);
123 break;
124 case 1:
125 setAxis(1, 2, 0, 0);
126 break;
127 case 2:
128 setAxis(2, 0, 1, 0);
129 break;
130 case 3:
131 setAxis(0, 2, 1, 1);
132 break;
133 case 4:
134 setAxis(1, 2, 0, 1);
135 break;
136 case 5:
137 setAxis(2, 0, 1, 1);
138 break;
139 default:
140 throw std::runtime_error("ViewId (" + std::to_string(patchPpi) + ") not allowed... exiting");
141 break;
142 }
143 }
144
145 std::string toString() const {
146 std::stringstream str;
147 str << "patchIndex=" << patchIndex_;
148 str << ", patchPpi=" << patchPpi_;
149 str << ", normalAxis=" << normalAxis_;
150 str << ", tangentAxis=" << tangentAxis_;
151 str << ", bitangentAxis=" << bitangentAxis_;
152 str << ", projectionMode=" << projectionMode_;
153 str << ", minU=" << posU_;
154 str << ", minV=" << posV_;
155 str << ", minD=" << posD_;
156 str << ", sizeD=" << sizeD_;
157 str << ", sizeU=" << widthInPixel_;
158 str << ", sizeV=" << heightInPixel_;
159 str << ", sizeUom=" << widthInOccBlk_;
160 str << ", sizeVom=" << heightInOccBlk_;
161 str << ", omDSPosX_=" << omDSPosX_;
162 str << ", omDSPosY_=" << omDSPosY_;
163 str << ", axisSwap=" << axisSwap_;
164 return str.str();
165 }
166};
167
168struct GOF;
169
170// TODO(lf): Avid using both constant sized and dynamic sized memory member within the same struct.
171struct Frame {
172 size_t frameId; // aka relative index (0 if first encoded frame)
173 size_t frameNumber; // aka number from the input frame file name (TODO(lf): correct)
174 std::weak_ptr<GOF> gof;
175 std::shared_ptr<std::counting_semaphore<UINT16_MAX>> conccurentFrameSem;
176
177 std::string pointCloudPath;
178
180 std::vector<Vector3<typeGeometryInput>> pointsGeometry;
181 std::vector<Vector3<uint8_t>> pointsAttribute;
182
183 std::vector<Patch> patchList;
184
185 size_t mapHeight = 0; // TODO(lf): Will be a gof parameter ?
186 size_t mapHeightDS = 0;
187
188 std::vector<uint8_t> occupancyMap; // (boolean vector)
189 std::vector<uint8_t> occupancyMapDS; // Down-scaled occupancy map of the frame (boolean vector)
190
191 std::vector<uint8_t> geometryMapL1; // first layer
192 std::vector<uint8_t> geometryMapL2; // second layer
193
194 std::vector<uint8_t> attributeMapL1; // Store the three channels continuously (all R, then all G, than all B)
195 std::vector<uint8_t> attributeMapL2;
196
197 Frame(const size_t& frameId, const size_t& frameNumber, const std::string& pointCloudPath)
200 if (conccurentFrameSem) {
201 conccurentFrameSem->release();
202 }
203 };
204 void printInfo() const;
205};
206
207struct GOF {
208 std::vector<std::shared_ptr<Frame>> frames;
209 size_t nbFrames;
210 size_t gofId;
211
214
215 std::vector<uint8_t> bitstreamOccupancy;
216 std::vector<uint8_t> bitstreamGeometry;
217 std::vector<uint8_t> bitstreamAttribute;
218};
219
221namespace API {
222
224struct v3c_chunk {
225 size_t len = 0; // Length of data in buffer
226 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.)
227 std::vector<size_t> v3c_unit_sizes = {};
228
229 v3c_chunk() = default;
230 v3c_chunk(size_t len, std::unique_ptr<char[]> data) : len(len), data(std::move(data)) {}
231};
232
233// ht: A V3C unit stream is composed of only V3C units without parsing information in the bitstream itself. The parsing information is here
234// given separately.
237 std::queue<v3c_chunk> v3c_chunks = {};
238 std::counting_semaphore<> available_chunks{0};
239 std::mutex io_mutex; // Locks production and consumption in the v3c_chunks queue
240};
241
242void initializeEncoder();
243void setParameter(const std::string& parameterName, const std::string& parameterValue);
244void encodeFrame(std::shared_ptr<Frame>& frame, v3c_unit_stream* output);
245void emptyFrameQueue();
246void stopEncoder();
247
248} // namespace API
249
250}; // namespace uvgvpcc_enc
Definition jobManagement.cpp:168
void stopEncoder()
Insure a proper end of the encoder execution.
Definition uvgvpcc.cpp:622
void initializeEncoder()
Create the context of the uvgVPCCenc encoder. Parse the input parameters and verify if the given conf...
Definition uvgvpcc.cpp:497
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:517
void emptyFrameQueue()
This function is called when all frames to be processed have been sent to the encoder....
Definition uvgvpcc.cpp:611
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:536
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:224
std::unique_ptr< char[]> data
Definition uvgvpcc.hpp:226
v3c_chunk(size_t len, std::unique_ptr< char[]> data)
Definition uvgvpcc.hpp:230
size_t len
Definition uvgvpcc.hpp:225
std::vector< size_t > v3c_unit_sizes
Definition uvgvpcc.hpp:227
Definition uvgvpcc.hpp:235
std::queue< v3c_chunk > v3c_chunks
Definition uvgvpcc.hpp:237
std::counting_semaphore available_chunks
Definition uvgvpcc.hpp:238
std::mutex io_mutex
Definition uvgvpcc.hpp:239
size_t v3c_unit_size_precision_bytes
Definition uvgvpcc.hpp:236
Definition uvgvpcc.hpp:171
size_t mapHeight
Definition uvgvpcc.hpp:185
std::string pointCloudPath
Definition uvgvpcc.hpp:177
std::vector< uint8_t > attributeMapL2
Definition uvgvpcc.hpp:195
size_t pointCount
Definition uvgvpcc.hpp:179
std::weak_ptr< GOF > gof
Definition uvgvpcc.hpp:174
std::vector< uint8_t > geometryMapL2
Definition uvgvpcc.hpp:192
std::vector< uint8_t > occupancyMap
Definition uvgvpcc.hpp:188
Frame(const size_t &frameId, const size_t &frameNumber, const std::string &pointCloudPath)
Definition uvgvpcc.hpp:197
std::shared_ptr< std::counting_semaphore< UINT16_MAX > > conccurentFrameSem
Definition uvgvpcc.hpp:175
std::vector< uint8_t > geometryMapL1
Definition uvgvpcc.hpp:191
std::vector< uint8_t > attributeMapL1
Definition uvgvpcc.hpp:194
std::vector< Vector3< uint8_t > > pointsAttribute
Definition uvgvpcc.hpp:181
~Frame()
Definition uvgvpcc.hpp:199
std::vector< Patch > patchList
Definition uvgvpcc.hpp:183
size_t mapHeightDS
Definition uvgvpcc.hpp:186
size_t frameNumber
Definition uvgvpcc.hpp:173
std::vector< Vector3< typeGeometryInput > > pointsGeometry
Definition uvgvpcc.hpp:180
void printInfo() const
Definition uvgvpcc.cpp:482
size_t frameId
Definition uvgvpcc.hpp:172
std::vector< uint8_t > occupancyMapDS
Definition uvgvpcc.hpp:189
Definition uvgvpcc.hpp:207
std::vector< std::shared_ptr< Frame > > frames
Definition uvgvpcc.hpp:208
size_t mapHeightGOF
Definition uvgvpcc.hpp:212
std::vector< uint8_t > bitstreamAttribute
Definition uvgvpcc.hpp:217
std::vector< uint8_t > bitstreamGeometry
Definition uvgvpcc.hpp:216
size_t nbFrames
Definition uvgvpcc.hpp:209
size_t mapHeightDSGOF
Definition uvgvpcc.hpp:213
size_t gofId
Definition uvgvpcc.hpp:210
std::vector< uint8_t > bitstreamOccupancy
Definition uvgvpcc.hpp:215
Definition uvgvpcc.hpp:56
size_t posU_
Definition uvgvpcc.hpp:64
bool isLinkToAMegaPatch
Definition uvgvpcc.hpp:107
bool axisSwap_
Definition uvgvpcc.hpp:85
size_t widthInPixel_
Definition uvgvpcc.hpp:74
size_t patchIndex_
Definition uvgvpcc.hpp:57
size_t area_
Definition uvgvpcc.hpp:95
std::string toString() const
Definition uvgvpcc.hpp:145
size_t sizeD_
Definition uvgvpcc.hpp:70
std::vector< typeGeometryInput > depthL2_
Definition uvgvpcc.hpp:88
size_t heightInOccBlk_
Definition uvgvpcc.hpp:79
void setPatchPpiAndAxis(size_t patchPpi)
Definition uvgvpcc.hpp:117
bool projectionMode_
Definition uvgvpcc.hpp:68
size_t omDSPosY_
Definition uvgvpcc.hpp:83
size_t posD_
Definition uvgvpcc.hpp:66
size_t bestMatchIdx
Definition uvgvpcc.hpp:102
size_t bitangentAxis_
Definition uvgvpcc.hpp:62
size_t normalAxis_
Definition uvgvpcc.hpp:60
std::vector< size_t > depthPCidxL2_
Definition uvgvpcc.hpp:92
size_t referencePatchId_
Definition uvgvpcc.hpp:97
std::vector< typeGeometryInput > depthL1_
Definition uvgvpcc.hpp:87
bool isMatched_
Definition uvgvpcc.hpp:106
size_t heightInPixel_
Definition uvgvpcc.hpp:75
std::vector< size_t > depthPCidxL1_
Definition uvgvpcc.hpp:91
size_t tangentAxis_
Definition uvgvpcc.hpp:61
size_t posV_
Definition uvgvpcc.hpp:65
std::vector< uint8_t > patchOccupancyMap_
Definition uvgvpcc.hpp:72
size_t unionPatchReferenceIdx
Definition uvgvpcc.hpp:108
size_t widthInOccBlk_
Definition uvgvpcc.hpp:77
void setAxis(size_t normalAxis, size_t tangentAxis, size_t bitangentAxis, bool projectionMode)
Definition uvgvpcc.hpp:110
size_t omDSPosX_
Definition uvgvpcc.hpp:82
size_t patchPpi_
Definition uvgvpcc.hpp:58