HoviTron Video Pipeline
helpersSynthesis.cpp
1#include"../include/helpersSynthesis.h"
2
3
4
5
6std::vector<uint32_t> generate_picture_EBO(const cv::Size& s)
7{
8 const size_t W = s.width;
9 const size_t H = s.height;
10
11 size_t elements_number = 3 * 2 * (H - 1) * (W - 1);
12 std::vector<uint32_t> indices;
13 indices.resize(elements_number);
14
15 size_t offset = 0;
16 for (size_t y = 0; y < H - 1; ++y)
17 {
18 for (size_t x = 0; x < W - 1; ++x)
19 {
20 indices[3 * INDEX_E(x, y, (W - 1)) + 0] = uint32_t(INDEX_E(x, y, W));
21 indices[3 * INDEX_E(x, y, (W - 1)) + 1] = uint32_t(INDEX_E(x + 1, y, W));
22 indices[3 * INDEX_E(x, y, (W - 1)) + 2] = uint32_t(INDEX_E(x, y + 1, W));
23 offset += 3;
24 }
25 }
26
27 for (size_t y = 1; y < H; ++y)
28 {
29 for (size_t x = 0; x < W - 1; ++x)
30 {
31 indices[offset + 3 * INDEX_E(x, y - 1, (W - 1)) + 0] = uint32_t(INDEX_E(x, y, W));
32 indices[offset + 3 * INDEX_E(x, y - 1, (W - 1)) + 1] = uint32_t(INDEX_E(x + 1, y - 1, W));
33 indices[offset + 3 * INDEX_E(x, y - 1, (W - 1)) + 2] = uint32_t(INDEX_E(x + 1, y, W));
34 }
35 }
36
37 printf("Real number of elements %i\n", int(elements_number));
38 return indices;
39}
40
41cv::Matx33f rotationMatrixFromRotationAroundX(float rx)
42{
43 return cv::Matx33f(
44 1.f, 0.f, 0.f,
45 0.f, cos(rx), -sin(rx),
46 0.f, sin(rx), cos(rx));
47}
48
49cv::Matx33f rotationMatrixFromRotationAroundY(float ry)
50{
51 return cv::Matx33f(
52 cos(ry), 0.f, sin(ry),
53 0.f, 1.f, 0.f,
54 -sin(ry), 0.f, cos(ry));
55}
56
57cv::Matx33f rotationMatrixFromRotationAroundZ(float rz)
58{
59 return cv::Matx33f(
60 cos(rz), -sin(rz), 0.f,
61 sin(rz), cos(rz), 0.f,
62 0.f, 0.f, 1.f);
63}
64
65cv::Matx33f EulerAnglesToRotationMatrix(cv::Vec3f rotation)
66{
67 // /!\ should be in rad !!!!!!!!!!!!!!!
68 //for rotation in OMAF
69 return
70 rotationMatrixFromRotationAroundZ(rotation[0]) *
71 rotationMatrixFromRotationAroundY(rotation[1]) *
72 rotationMatrixFromRotationAroundX(rotation[2]);
73}
74
75cv::Matx33f EulerAnglesDegreeToRotationMatrixNotOMAF(cv::Vec3f rotationDegrees)
76{
77 // /!\ should be in degree !!!!!!!!!!!!!!!
78 // not for OMAF !!!!
79 cv::Vec3f tmp = rotationDegrees;
80 auto const radperdeg = 0.01745329252f;
81 auto rotation = radperdeg * tmp;
82 return rotationMatrixFromRotationAroundZ(rotation[2]) *
83 rotationMatrixFromRotationAroundY(rotation[1]) *
84 rotationMatrixFromRotationAroundX(rotation[0]);
85}
86
87
88glm::mat3x3 glmRotationMatrixFromRotationAroundX(float rx)
89{
90 /*The following is not correct because glm use column major representation
91 return glm::mat3x3(
92 1.f, 0.f, 0.f,
93 0.f, cos(rx), -sin(rx),
94 0.f, sin(rx), cos(rx));*/
95 //the correct way:
96 return glm::mat3x3(
97 1.f, 0.f, 0.f,
98 0.f, cos(rx), sin(rx),
99 0.f, -sin(rx), cos(rx));
100}
101
102glm::mat3x3 glmRotationMatrixFromRotationAroundY(float ry)
103{
104 /*
105 The following is not correct because glm use column major representation
106 return glm::mat3x3(
107 cos(ry), 0.f, sin(ry),
108 0.f, 1.f, 0.f,
109 -sin(ry), 0.f, cos(ry));*/
110 //the correct way:
111 return glm::mat3x3(
112 cos(ry), 0.f, -sin(ry),
113 0.f, 1.f, 0.f,
114 sin(ry), 0.f, cos(ry));
115}
116
117glm::mat3x3 glmRotationMatrixFromRotationAroundZ(float rz)
118{
119 /*The following is not correct because glm use column major representation
120 return glm::mat3x3(
121 cos(rz), -sin(rz), 0.f,
122 sin(rz), cos(rz), 0.f,
123 0.f, 0.f, 1.f);*/
124 //the correct way:
125 return glm::mat3x3(
126 cos(rz), sin(rz), 0.f,
127 -sin(rz), cos(rz), 0.f,
128 0.f, 0.f, 1.f);
129}
130
131glm::mat3x3 glmEulerAnglesDegreeToRotationMatrix(glm::vec3 rotationDegrees)
132{
133 // /!\ should be in rad !!!!!!!!!!!!!!!
134 //for rotation in OMAF
135 auto const radperdeg = 0.01745329252f;
136 auto rotation = radperdeg * rotationDegrees;
137 return
138 glmRotationMatrixFromRotationAroundZ(rotation[0]) *
139 glmRotationMatrixFromRotationAroundY(rotation[1]) *
140 glmRotationMatrixFromRotationAroundX(rotation[2]);
141}
142
143glm::mat3x3 glmEulerAnglesDegreeToRotationMatrixNotOMAF(glm::vec3 rotationDegrees)
144{
145 // /!\ should be in degree !!!!!!!!!!!!!!!
146 // not for OMAF !!!!
147 auto const radperdeg = 0.01745329252f;
148 auto rotation = radperdeg * rotationDegrees;
149 return glmRotationMatrixFromRotationAroundZ(rotation[2]) *
150 glmRotationMatrixFromRotationAroundY(rotation[1]) *
151 glmRotationMatrixFromRotationAroundX(rotation[0]);
152}