uvgVPCCenc 1.0.0
uvgVPCCenc is an open-source real-time V-PCC encoder library written in C++ from scratch.
Loading...
Searching...
No Matches
utils.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
34
35
36#pragma once
37
38#include <array>
39#include <cstdint>
40#include <limits>
41#include <sstream>
42#include <iomanip>
43
44namespace uvgvpcc_enc {
45
46
47
48
49using typeGeometryInput = uint16_t;
50
51const typeGeometryInput g_infiniteDepth = (std::numeric_limits<typeGeometryInput>::max)(); // TODO(lf)be sure it is well sync with type geo
52const size_t g_infinitenumber = (std::numeric_limits<size_t>::max)();
53const size_t g_valueNotSet = (std::numeric_limits<size_t>::max)();
54
55constexpr size_t INVALID_PATCH_INDEX = std::numeric_limits<size_t>::max();
56
57
58template <typename T>
59class Vector3 : public std::array<T, 3> {
60 public:
61 Vector3() : std::array<T, 3>() {}
62 Vector3(T x, T y, T z) : std::array<T, 3>({x, y, z}) {}
63 Vector3(std::array<T, 3>& arr) : std::array<T, 3>(arr) {}
64 Vector3(std::array<T, 3>&& arr) : std::array<T, 3>(std::move(arr)) {}
65 Vector3(const std::array<T, 3>& arr) {
66 std::copy(arr.begin(), arr.end(), this->begin());
67 }
68
69 template <typename U>
70 Vector3<T> operator+(const Vector3<U>& other) const {
71 return {(*this)[0] + other[0], (*this)[1] + other[1], (*this)[2] + other[2]};
72 }
73
74 template <typename U>
75 Vector3<T> operator-(const Vector3<U>& other) const {
76 return {(*this)[0] - other[0], (*this)[1] - other[1], (*this)[2] - other[2]};
77 }
78
80 return {(*this)[0] - other[0], (*this)[1] - other[1], (*this)[2] - other[2]};
81 }
82
83 Vector3<T> operator-() const { return {-(*this)[0], -(*this)[1], -(*this)[2]}; }
84
85 template <typename U>
87 (*this)[0] += other[0];
88 (*this)[1] += other[1];
89 (*this)[2] += other[2];
90 return *this;
91 }
92
93 template <typename U>
94 Vector3<T>& operator/=(const U& val) {
95 (*this)[0] /= val;
96 (*this)[1] /= val;
97 (*this)[2] /= val;
98 return *this;
99 }
100};
101
102inline std::string zeroPad(size_t value, size_t width) {
103 std::ostringstream oss;
104 oss << std::setw(width) << std::setfill('0') << value;
105 return oss.str();
106};
107
108// Round the given number to the nearest bigger multiple.
109// equivalent to : return = ceil(numberF/multipleF) * multiple;
110// Examples : roundUp(7,8) = 8; roundUp(17,8) = 24;
111inline size_t roundUp(const size_t& number, const size_t& multiple) { return (number + multiple - 1) & -multiple;}
112
113} // uvgvpcc_enc namespace
Definition utils.hpp:59
Vector3(std::array< T, 3 > &arr)
Definition utils.hpp:63
Vector3< double > operator-(const Vector3< double > &other) const
Definition utils.hpp:79
Vector3(T x, T y, T z)
Definition utils.hpp:62
Vector3(const std::array< T, 3 > &arr)
Definition utils.hpp:65
Vector3< T > operator-(const Vector3< U > &other) const
Definition utils.hpp:75
Vector3< T > & operator+=(const Vector3< U > &other)
Definition utils.hpp:86
Vector3()
Definition utils.hpp:61
Vector3(std::array< T, 3 > &&arr)
Definition utils.hpp:64
Vector3< T > & operator/=(const U &val)
Definition utils.hpp:94
Vector3< T > operator-() const
Definition utils.hpp:83
Vector3< T > operator+(const Vector3< U > &other) const
Definition utils.hpp:70
Definition log.hpp:43
std::string zeroPad(size_t value, size_t width)
Definition utils.hpp:102
size_t roundUp(const size_t &number, const size_t &multiple)
Definition utils.hpp:111
constexpr size_t INVALID_PATCH_INDEX
Definition utils.hpp:55
uint16_t typeGeometryInput
Definition utils.hpp:49
const size_t g_infinitenumber
Definition utils.hpp:52
const typeGeometryInput g_infiniteDepth
Definition utils.hpp:51
const size_t g_valueNotSet
Definition utils.hpp:53