uvgVPCCenc 1.2.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-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 <cstddef>
40#include <cstdint>
41#include <iomanip>
42#include <limits>
43#include <sstream>
44
45#include "log.hpp"
46
47namespace uvgutils {
48
49template <typename T, size_t N>
50class VectorN : public std::array<T, N> {
51 public:
52 VectorN() : std::array<T, N>() {}
53 VectorN(T x, T y, T z) : std::array<T, 3>({x, y, z}) {}
54 VectorN(std::array<T, N>& arr) : std::array<T, N>(arr) {}
55 VectorN(std::array<T, N>&& arr) : std::array<T, N>(std::move(arr)) {}
56 VectorN(const std::array<T, N>& arr) { std::copy(arr.begin(), arr.end(), this->begin()); }
57 template <typename U>
59 VectorN<T, N> result;
60 for (size_t i = 0; i < N; ++i) {
61 result[i] = (*this)[i] + other[i];
62 }
63 return result;
64 }
65
66 template <typename U>
68 VectorN<T, N> result;
69 for (size_t i = 0; i < N; ++i) {
70 result[i] = (*this)[i] - other[i];
71 }
72 return result;
73 }
74
76 VectorN<double, N> result;
77 for (size_t i = 0; i < N; ++i) {
78 result[i] = (*this)[i] - other[i];
79 }
80 return result;
81 }
82
84 VectorN<T, N> result;
85 for (size_t i = 0; i < N; ++i) {
86 result[i] = -(*this)[i];
87 }
88 return result;
89 }
90
91 template <typename U>
93 for (size_t i = 0; i < N; ++i) {
94 (*this)[i] += other[i];
95 }
96 return *this;
97 }
98
99 template <typename U>
100 VectorN<T, N>& operator/=(const U& val) {
101 (*this)[0] /= val;
102 (*this)[1] /= val;
103 (*this)[2] /= val;
104 return *this;
105 }
106};
107
108inline std::string zeroPad(size_t value, size_t width) {
109 std::ostringstream oss;
110 oss << std::setw(width) << std::setfill('0') << value;
111 return oss.str();
112};
113
114// Round the given number to the nearest bigger multiple.
115// equivalent to : return = ceil(numberF/multipleF) * multiple;
116// Examples : roundUp(7,8) = 8; roundUp(17,8) = 24;
117inline size_t roundUp(const size_t& number, const size_t& multiple) { return (number + multiple - 1) & -multiple; }
118
119} // namespace uvgutils
Definition utils.hpp:50
VectorN(const std::array< T, N > &arr)
Definition utils.hpp:56
VectorN(T x, T y, T z)
Definition utils.hpp:53
VectorN< double, N > operator-(const VectorN< double, N > &other) const
Definition utils.hpp:75
VectorN(std::array< T, N > &&arr)
Definition utils.hpp:55
VectorN< T, N > operator+(const VectorN< U, N > &other) const
Definition utils.hpp:58
VectorN(std::array< T, N > &arr)
Definition utils.hpp:54
VectorN< T, N > & operator/=(const U &val)
Definition utils.hpp:100
VectorN< T, N > & operator+=(const VectorN< U, N > &other)
Definition utils.hpp:92
VectorN< T, N > operator-() const
Definition utils.hpp:83
VectorN< T, N > operator-(const VectorN< U, N > &other) const
Definition utils.hpp:67
VectorN()
Definition utils.hpp:52
Definition jobManagement.hpp:72
Definition jobManagement.hpp:50
std::string zeroPad(size_t value, size_t width)
Definition utils.hpp:108
size_t roundUp(const size_t &number, const size_t &multiple)
Definition utils.hpp:117