uvgVPCCenc 1.2.0
uvgVPCCenc is an open-source real-time V-PCC encoder library written in C++ from scratch.
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 * This file is part of uvgVPCCenc V-PCC encoder.
3 *
4 * Copyright (c) 2024-present, 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 (subject to the limitations in the disclaimer below) 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 Tampere University, 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 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
29 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
32 ****************************************************************************/
33
35
36#pragma once
37
38#include <array>
39#include <cassert>
40#include <cstddef>
41#include <cstdint>
42#include <memory>
43#include <semaphore>
44#include <sstream>
45#include <string>
46#include <vector>
47
50#include "uvgutils/utils.hpp"
51#include "constants.hpp"
52#include "parameters.hpp"
53
54namespace uvgvpcc_enc {
55
56// Forward declaration to break the FrameContext <-> GOF circular dependency.
57struct GOF;
58
59// A patch is a 3D object. Though, the word 'patch' can refer to the "2D version" of this patch
60struct Patch {
62 size_t patchPpi_; // viewId
63
64 size_t normalAxis_; // x
65 size_t tangentAxis_; // y
66 size_t bitangentAxis_; // z
67
68 size_t posU_; // u1_ minU_ // tangential shift
69 size_t posV_; // v1_ minV_ // bitangential shift
70 size_t posD_; // d1_ minD_ // depth shift
71
72 bool projectionMode_; // 0: related to the min depth value; 1: related to the max value
73
74 size_t sizeD_; // while posD_ is the minimum 'depth', sizeD_ store the maximum depth. TODO(lf): check if it is usefull
75
76 std::vector<uint8_t> patchOccupancyMap_; // patch occupancy map (boolean vector)
77 std::vector<uint8_t> patchOccupancyMapColor_; // Patch occupancy map colored per patch
78
79 size_t widthInPixel_ = 0; // size for U // width of the patch occupancy map (in pixels)
80 size_t heightInPixel_ = 0; // size for V // height of the patch occupancy map (in pixels)
81
82 size_t widthInPPBlk_; // sizeU0_ Width in term of patch packing block (not related to the occupancy map downscaling factor)
83 size_t heightInPPBlk_; // sizeV0_ Height in term of patch packing block (not related to the occupancy map downscaling factor)
84
85 size_t omPPPosX_; // u0_ 2dPosX Position in the occupancy map in term of patch packing block (not related to the occupancy map downscaling factor)
86 size_t omPPPosY_; // v0_ 2dPosY
87
88 bool axisSwap_; // patch orientation // in canvas atlas (false default, true axis swap)
89
90 std::vector<typeGeometryInput> depthL1_; // depth value First layer // TODO(lf): Using the geo type here might lead to issue?
91 std::vector<typeGeometryInput> depthL2_; // depth value Second layer
92
93 // Index of the point in the PC for attribute retrieving during attribute map generation TODO(lf): use for Surface separation?
94 std::vector<size_t> depthPCidxL1_;
95 std::vector<size_t> depthPCidxL2_;
96
97 // inter packing //
98 size_t area_ = 0;
99
101 // Store the id of the best reference patch in the previous frame. Notice that even if the current patch is not
102 // matched, a reference patch id is still found. Then, this reference id will be used to check if the iou treshold
103 // is respected or not, then indicating if this patch is matched or not.
104
106 // 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
107 // the current patch is not matched, a reference patch id is still found. Then, this reference id will be used to check if the
108 // iou treshold is respected or not, then indicating if this patch is matched or not.
109 bool isLinkToAMegaPatch = false;
111
112 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).
113
114 void setAxis(size_t normalAxis, size_t tangentAxis, size_t bitangentAxis, bool projectionMode) {
115 normalAxis_ = normalAxis;
116 tangentAxis_ = tangentAxis;
117 bitangentAxis_ = bitangentAxis;
118 projectionMode_ = projectionMode; // TODO(lf): projection mode optimization per patch
119 }
120
121 inline void setPatchPpiAndAxis(size_t patchPpi) {
122 patchPpi_ = patchPpi;
123 // now set the other variables according to the viewId
124 switch (patchPpi_) {
125 case 0:
126 setAxis(0, 2, 1, 0);
127 break;
128 case 1:
129 setAxis(1, 2, 0, 0);
130 break;
131 case 2:
132 setAxis(2, 0, 1, 0);
133 break;
134 case 3:
135 setAxis(0, 2, 1, 1);
136 break;
137 case 4:
138 setAxis(1, 2, 0, 1);
139 break;
140 case 5:
141 setAxis(2, 0, 1, 1);
142 break;
143 default:
144 throw std::runtime_error("ViewId (" + std::to_string(patchPpi) + ") not allowed... exiting");
145 break;
146 }
147 }
148
149 std::string toString() const {
150 std::stringstream str;
151 str << "patchIndex=" << patchIndex_;
152 str << ", patchPpi=" << patchPpi_;
153 str << ", normalAxis=" << normalAxis_;
154 str << ", tangentAxis=" << tangentAxis_;
155 str << ", bitangentAxis=" << bitangentAxis_;
156 str << ", projectionMode=" << projectionMode_;
157 str << ", minU=" << posU_;
158 str << ", minV=" << posV_;
159 str << ", minD=" << posD_;
160 str << ", sizeD=" << sizeD_;
161 str << ", sizeU=" << widthInPixel_;
162 str << ", sizeV=" << heightInPixel_;
163 str << ", sizeUom=" << widthInPPBlk_;
164 str << ", sizeVom=" << heightInPPBlk_;
165 str << ", omPPPosX_=" << omPPPosX_;
166 str << ", omPPPosY_=" << omPPPosY_;
167 str << ", axisSwap=" << axisSwap_;
168 return str.str();
169 }
170};
171
181 // ---- User payload (shared ownership, zero-copy) ----
182 // Declared first so references below are bound to valid memory.
183 std::shared_ptr<uvgformat::uvgFrame> uvgframe;
184
185 // ---- Convenience references into the payload (non-owning, bound at construction) ----
186 std::vector<uvgutils::VectorN<typeGeometryInput, 3>>& pointsGeometry;
187 std::vector<uvgutils::VectorN<uint8_t, 3>>& pointsAttribute;
188
189 // ---- Encoder-assigned identity ----
190 size_t frameId;
191 size_t gofId;
192 size_t frameNumber; // copied from uvgframe->frameNumber
193
194 // ---- Encoder lifecycle ----
195 std::weak_ptr<GOF> gof;
196 std::shared_ptr<std::counting_semaphore<UINT16_MAX>> conccurentFrameSem;
197
198 // ---- Map sizing ----
199 size_t mapHeight;
201
202 // ---- Centralized memory pointers (set by GOF::setFrameMemoryPtrs) ----
203 std::vector<Patch>* patchList;
204 std::vector<uint8_t>* occupancyMap;
205 std::vector<uint8_t>* occupancyMapColored;
206 std::vector<uint8_t>* occupancyMapDS;
207 std::vector<uint8_t>* geometryMapL1;
208 std::vector<uint8_t>* geometryMapL2;
209 std::vector<uint8_t>* attributeMapL1;
210 std::vector<uint8_t>* attributeMapL2;
211
212 FrameContext(const size_t frameId, std::shared_ptr<uvgformat::uvgFrame> frame)
213 : uvgframe(std::move(frame))
214 , pointsGeometry(uvgformat::getGeometryRgb(uvgframe->payload).geometry)
215 , pointsAttribute(uvgformat::getGeometryRgb(uvgframe->payload).attribute)
217 , gofId(0)
219 , mapHeight(p_->minimumMapHeight)
220 , mapHeightDS(p_->minimumMapHeight / p_->occupancyMapDSResolution)
221 , patchList(nullptr)
222 , occupancyMap(nullptr)
223 , occupancyMapColored(nullptr)
224 , occupancyMapDS(nullptr)
225 , geometryMapL1(nullptr)
226 , geometryMapL2(nullptr)
227 , attributeMapL1(nullptr)
228 , attributeMapL2(nullptr) {}
229
231 if (conccurentFrameSem) {
232 conccurentFrameSem->release();
233 }
234 }
235
236 void printInfo() const;
237};
238
239struct GOF {
240 std::vector<std::shared_ptr<FrameContext>> frames;
241 size_t nbFrames;
242 size_t gofId;
243
246
247 std::vector<uint8_t> bitstreamOccupancy;
248 std::vector<uint8_t> bitstreamGeometry;
249 std::vector<uint8_t> bitstreamAttribute;
250
251 // lf: centralized memory handling //
252 std::array<std::vector<Patch>, MAX_GOF_SIZE>* framePatches;
253 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* frameOccupancyMaps;
254 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* frameOccupancyMapsColor;
255 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* frameOccupancyMapsDS;
256 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* frameGeometryMapsL1;
257 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* frameGeometryMapsL2;
258 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* frameAttributeMapsL1;
259 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* frameAttributeMapsL2;
260
261 GOF(const size_t& gofId);
262 void setFrameMemoryPtrs(std::shared_ptr<FrameContext>& frame);
263 ~GOF();
264};
265
266} // namespace uvgvpcc_enc
Definition jobManagement.hpp:72
Definition voxelization.cpp:45
Definition uvgvpccenc.hpp:49
constexpr size_t INVALID_PATCH_INDEX
Definition constants.hpp:55
constexpr size_t MAX_GOF_SIZE
Definition constants.hpp:63
const Parameters * p_
Definition uvgvpccenc.cpp:597
const size_t g_infinitenumber
Definition constants.hpp:52
Encoder-internal per-frame state.
Definition types.hpp:180
std::vector< uint8_t > * occupancyMap
Definition types.hpp:204
std::vector< uint8_t > * occupancyMapDS
Definition types.hpp:206
size_t mapHeightDS
Definition types.hpp:200
std::vector< Patch > * patchList
Definition types.hpp:203
std::vector< uint8_t > * occupancyMapColored
Definition types.hpp:205
std::shared_ptr< uvgformat::uvgFrame > uvgframe
Definition types.hpp:183
std::weak_ptr< GOF > gof
Definition types.hpp:195
std::vector< uint8_t > * geometryMapL2
Definition types.hpp:208
std::shared_ptr< std::counting_semaphore< UINT16_MAX > > conccurentFrameSem
Definition types.hpp:196
size_t gofId
Definition types.hpp:191
size_t frameId
Definition types.hpp:190
std::vector< uint8_t > * attributeMapL1
Definition types.hpp:209
std::vector< uvgutils::VectorN< uint8_t, 3 > > & pointsAttribute
Definition types.hpp:187
std::vector< uvgutils::VectorN< typeGeometryInput, 3 > > & pointsGeometry
Definition types.hpp:186
std::vector< uint8_t > * geometryMapL1
Definition types.hpp:207
std::vector< uint8_t > * attributeMapL2
Definition types.hpp:210
~FrameContext()
Definition types.hpp:230
FrameContext(const size_t frameId, std::shared_ptr< uvgformat::uvgFrame > frame)
Definition types.hpp:212
size_t mapHeight
Definition types.hpp:199
void printInfo() const
Definition types.cpp:42
size_t frameNumber
Definition types.hpp:192
Definition types.hpp:239
size_t mapHeightGOF
Definition types.hpp:244
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * frameAttributeMapsL1
Definition types.hpp:258
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * frameOccupancyMaps
Definition types.hpp:253
void setFrameMemoryPtrs(std::shared_ptr< FrameContext > &frame)
Definition types.cpp:61
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * frameGeometryMapsL1
Definition types.hpp:256
std::vector< uint8_t > bitstreamAttribute
Definition types.hpp:249
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * frameAttributeMapsL2
Definition types.hpp:259
std::vector< uint8_t > bitstreamGeometry
Definition types.hpp:248
size_t nbFrames
Definition types.hpp:241
std::vector< std::shared_ptr< FrameContext > > frames
Definition types.hpp:240
size_t mapHeightDSGOF
Definition types.hpp:245
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * frameOccupancyMapsColor
Definition types.hpp:254
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * frameGeometryMapsL2
Definition types.hpp:257
size_t gofId
Definition types.hpp:242
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * frameOccupancyMapsDS
Definition types.hpp:255
std::vector< uint8_t > bitstreamOccupancy
Definition types.hpp:247
std::array< std::vector< Patch >, MAX_GOF_SIZE > * framePatches
Definition types.hpp:252
~GOF()
Definition types.cpp:76
Definition types.hpp:60
size_t posU_
Definition types.hpp:68
size_t omPPPosX_
Definition types.hpp:85
bool isLinkToAMegaPatch
Definition types.hpp:109
bool axisSwap_
Definition types.hpp:88
size_t widthInPixel_
Definition types.hpp:79
size_t patchIndex_
Definition types.hpp:61
size_t heightInPPBlk_
Definition types.hpp:83
size_t area_
Definition types.hpp:98
std::string toString() const
Definition types.hpp:149
size_t sizeD_
Definition types.hpp:74
std::vector< typeGeometryInput > depthL2_
Definition types.hpp:91
std::vector< uint8_t > patchOccupancyMapColor_
Definition types.hpp:77
void setPatchPpiAndAxis(size_t patchPpi)
Definition types.hpp:121
bool projectionMode_
Definition types.hpp:72
size_t posD_
Definition types.hpp:70
size_t bestMatchIdx
Definition types.hpp:105
size_t bitangentAxis_
Definition types.hpp:66
size_t normalAxis_
Definition types.hpp:64
std::vector< size_t > depthPCidxL2_
Definition types.hpp:95
size_t referencePatchId_
Definition types.hpp:100
std::vector< typeGeometryInput > depthL1_
Definition types.hpp:90
size_t heightInPixel_
Definition types.hpp:80
std::vector< size_t > depthPCidxL1_
Definition types.hpp:94
size_t tangentAxis_
Definition types.hpp:65
size_t posV_
Definition types.hpp:69
std::vector< uint8_t > patchOccupancyMap_
Definition types.hpp:76
size_t widthInPPBlk_
Definition types.hpp:82
size_t unionPatchReferenceIdx
Definition types.hpp:110
bool isDiscarded
Definition types.hpp:112
void setAxis(size_t normalAxis, size_t tangentAxis, size_t bitangentAxis, bool projectionMode)
Definition types.hpp:114
size_t omPPPosY_
Definition types.hpp:86
size_t patchPpi_
Definition types.hpp:62