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