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