HoviTron Video Pipeline
RVSVulkan.cpp
Go to the documentation of this file.
1/* ----------------------
2* Copyright 2023 Université Libre de Bruxelles(ULB), Universidad Politécnica de Madrid(UPM), CREAL, Deutsches Zentrum für Luft - und Raumfahrt(DLR)
3
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at < http://www.apache.org/licenses/LICENSE-2.0>
7
8* Unless required by applicable law or agreed to in writing, software
9* distributed under the License is distributed on an "AS IS" BASIS,
10* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11* See the License for the specific language governing permissionsand
12* limitations under the License.
13---------------------- */
14
15
16
17/*****************************************************************/
22#include <iostream>
23
24#include "WindowGLFW.h"
25#ifdef USE_OPENXR
26#include "WindowOpenXR.h"
27#endif
29#include <filesystem>
30#include "SourcesVulkan/DynamicInputProvider.h"
31
32#include"SourcesVulkan/DynamicInputProvider.h"
33
34using namespace std;
35
36
37WindowAbstract * window;
38VulkanWrapper * wraps;
39
40enum class WindowMode
41{
42 Headless, GLFW, OpenXR, Undefined
43};
44
45void printUsage() {
46 std::cout
47 << "\n" //TODO chose what to do about that
48 << " - -------------------------------------------------------------------------------------- -\n"
49 << "| Original authors: |\n"
50 << "| |\n"
51 << "| Universite Libre de Bruxelles, Brussels, Belgium: |\n"
52 << "| Sarah Fachada, Sarah.Fernandes.Pinto.Fachada@ulb.ac.be |\n"
53 << "| Daniele Bonatto, Daniele.Bonatto@ulb.ac.be |\n"
54 << "| Arnaud Schenkel, arnaud.schenkel@ulb.ac.be |\n"
55 << "| |\n"
56 << "| Koninklijke Philips N.V., Eindhoven, The Netherlands: |\n"
57 << "| Bart Kroon, bart.kroon@philips.com |\n"
58 << "| Bart Sonneveldt, bart.sonneveldt@philips.com |\n"
59 << " - -------------------------------------------------------------------------------------- -\n\n";
60
61 std::cout << "Hovitron version " << std::endl;
62
63 std::cout << "Usage: RVS PathToDLL [ --glfw "
64 #ifdef USE_OPENXR
65 << "|| --openxr][--mirror]"
66 #else
67 << " ]"
68 #endif
69 << "[--blendingFactor value] [--start value] [--triangleThreshold value] [--scaleFactor value]"
70 << std::endl;
71 std::cout << "--headless is currently not supported" << std::endl;
72#ifndef USE_OPENXR
73 std::cout << "--openxr is not available since the code was not compiled with openxr flag" << std::endl;
74#endif
75
76
77};
78
79int main(int argc, char* argv[])
80{
81#ifdef WIN32
82 SetConsoleOutputCP(CP_UTF8);
83#endif //
84
85 WindowMode mode = WindowMode::Undefined;
86 PipelineMode pipelineMode = PipelineMode::Raster;
87 std::string pathDLL;
88 bool openXRmirror = false;
89 bool skip = false;
90 float blendingFactor = 5.0;
91 float triangleThreshold = -1;
92 float scaleFactor = -1;
93 auto startingPoint = StartingPosition::Average;
94 float nearPlaneHeadset = -1;
95 float farPlaneHeadset = -1;
96 int32_t portNumber = 60392;
97 for (int i = 1; i < argc; ++i) {
98 if (skip) {
99 skip = false;
100 continue;
101 }
102 if (strcmp(argv[i], "--help") == 0) {
103 pathDLL.clear();
104 break;
105 }
106 else if (strcmp(argv[i], "--headless") == 0) {
107 std::cout << "mode without window have been activated" << std::endl;
108 if (mode == WindowMode::Undefined) {
109 //mode = WindowMode::Headless;
110 printUsage();
111 throw std::runtime_error("Currently the headless mode is unsupported");
112 return EXIT_FAILURE;
113 }
114 else {
115 printUsage();
116 throw std::runtime_error("Only one flag is accepted for chosing the window mode");
117 return EXIT_FAILURE;
118 }
119 }
120 else if (strcmp(argv[i], "--glfw") == 0) {
121 std::cout << "mode with a glfw window" << std::endl;
122 if (mode == WindowMode::Undefined) {
123 mode = WindowMode::GLFW;
124 }
125 else {
126 printUsage();
127 throw std::runtime_error("Only one flag is accepted for chosing the window mode");
128 return EXIT_FAILURE;
129 }
130 }else if (strcmp(argv[i], "--openxr") == 0) {
131 std::cout << "mode with OpenXR" << std::endl;
132 if (mode == WindowMode::Undefined) {
133#ifdef USE_OPENXR
134 mode = WindowMode::OpenXR;
135#else
136 throw std::runtime_error("Not compiled with OpenXr, OpenXR mode unsupported");
137 return EXIT_FAILURE;
138#endif // OPENXR
139 }
140 else {
141 printUsage();
142 throw std::runtime_error("Only one flag is accepted for chosing the window mode");
143 return EXIT_FAILURE;
144 }
145 }
146 else if (strcmp(argv[i], "--mirror") == 0) {
147 openXRmirror = true;
148 std::cout << "Mirror for openXR requested" << std::endl;
149 }
150 else if (strcmp(argv[i], "--blendingFactor") == 0 || strcmp(argv[i], "-b") == 0) {
151 if (i + 1 < argc) {
152 skip = true;
153 auto factor = argv[i+1];
154 blendingFactor = std::stof(factor);
155 std::cout << "Blending factor set to: " << blendingFactor << std::endl;
156 }
157 else {
158 printUsage();
159 throw std::runtime_error("blending factor missing");
160 return EXIT_FAILURE;
161 }
162 }
163 else if (strcmp(argv[i], "--triangleTreshold") == 0 || strcmp(argv[i], "-t") == 0) {
164 if (i + 1 < argc) {
165 skip = true;
166 auto factor = argv[i + 1];
167 triangleThreshold = std::stof(factor);
168 std::cout << "triangleThreshold set to: " << triangleThreshold << std::endl;
169 }
170 else {
171 printUsage();
172 throw std::runtime_error("value for thriangleThreshold missing");
173 return EXIT_FAILURE;
174 }
175 }
176 else if (strcmp(argv[i], "--start") == 0 ) {
177 if (i + 1 < argc) {
178 skip = true;
179 auto start = argv[i + 1];
180 if (strcmp(start, "zero") == 0) {
181 startingPoint = StartingPosition::Zero;
182 PRINT("Starting point set to zero");
183 }else if (strcmp(start, "average") == 0) {
184 startingPoint = StartingPosition::Average;
185 PRINT("Starting point set to the average of the pose of the input cameras");
186 }
187 else {
188 printUsage();
189 throw std::runtime_error((" %s is not a supported mode for starting point", start));
190 return EXIT_FAILURE;
191 }
192 }
193 else {
194 printUsage();
195 throw std::runtime_error("Argument for starting position is missing ");
196 return EXIT_FAILURE;
197 }
198 }
199 else if (strcmp(argv[i], "--port") == 0 || strcmp(argv[i], "-p") == 0) {
200#ifdef HVT_UDP_CONTROL
201 if (i + 1 < argc) {
202 skip = true;
203 portNumber = stoi(argv[i + 1]);
204 PRINT("Port set to %d", portNumber);
205 }
206 else {
207 printUsage();
208 throw std::runtime_error("Argument for port is missing ");
209 return EXIT_FAILURE;
210 }
211#else
212 printUsage();
213 throw std::runtime_error("Not compiled with UDP control, --port argument is unavailable");
214 return EXIT_FAILURE;
215#endif // HVT_UDP_CONTROL
216 }
217 else if (pathDLL.empty()) {
218 pathDLL = argv[i];
219 }
220 else {
221 printUsage();
222 throw std::runtime_error("Too many parameters (try --help)");
223 return EXIT_FAILURE;
224 }
225 }
226
227 std::cout
228 << " - -------------------------------------------------------------------------------------- -\n"
229 << "| Reference View Synthesizer (RVS) version Vulkan, based on (branch: v3.1) |\n"
230 << "| |\n"
231 << "| MPEG2018/N18068 Reference View Synthesizer (RVS) manual |\n"
232 << " - -------------------------------------------------------------------------------------- -" << std::endl;
233
234 if (pathDLL.empty()) {
235 printUsage();
236
237 throw std::runtime_error("Please specify at least a valid path to the dynamic library (.dll) that provide the input");
238
239 }
240
241 if (mode == WindowMode::Undefined) {
242 std::cout << "No mode for the window specidied --> fall back to GLFW window";
243 mode = WindowMode::GLFW;
244 }
245
246 if (openXRmirror && mode != WindowMode::OpenXR) {
247 std::cout << "Mirror for OpenXR mode is requested but the mode chosen isn't OpenXR, --mirror flag will be ignored" << std::endl;
248 openXRmirror = false;
249 }
250
251 std::filesystem::path p = pathDLL;
252 auto dir = p.parent_path();
253 auto ex = std::filesystem::exists(p);
254
255
256 try {
257 switch (mode)
258 {
259 case WindowMode::GLFW:
260 window = new WindowGLFW();
261 break;
262#ifdef USE_OPENXR
263 case WindowMode::OpenXR:
264 window = new WindowOpenXR();
265 static_cast<WindowOpenXR *>(window)->setMirror(openXRmirror);
266 break;
267#endif
268 default:
269 window = new WindowGLFW();
270 break;
271 }
272
273
274
275 wraps = new VulkanWrapper(window, pipelineMode);
276#ifdef HVT_UDP_CONTROL
277 wraps->init(portNumber);
278#else
279 wraps->init();
280#endif
281 wraps->setBlendingFactor(blendingFactor);
282 if (triangleThreshold != -1) {
283 wraps->setTriangleThreshold(triangleThreshold);
284 }
285 if (scaleFactor != -1) {
286 wraps->setScaleFactor(scaleFactor);
287 }
288 InputProvider * inputDLL = new DynamicInputProvider(pathDLL.c_str(), *wraps);
289 wraps->endInit(inputDLL, startingPoint);
290 wraps->start();
291 wraps->cleanUp();
292 delete wraps;
293 delete window;
294 }
295 catch (const std::exception& e) {
296 std::cerr << e.what() << std::endl;
297 return EXIT_FAILURE;
298 }
299
300 return EXIT_SUCCESS;
301}
302
file that contains the VulkanWrapper class that manages the classes related to Vulkan code and ease t...
Contains the class that represents a window created with the GLFW library.
Class that take care of the tasks linked to OpenXR (input and display), is used when HMD support is r...
Abstract interface around getting source views parameters and data.
Definition: InputProvider.h:35
Class that manages the classes related to Vulkan code and act as a wrapper around them.
Definition: VulkanWrapper.h:66
void setScaleFactor(float scaleFactor)
void setTriangleThreshold(float triangleThreshold)
void endInit(InputProvider *input, StartingPosition startingPt=StartingPosition::Average)
void setBlendingFactor(float blendingfactor)
Abstraction of the way of the result is displayed (screen or HMD).
The class that represents a window created with the GLFW library.
Definition: WindowGLFW.h:37
Class that take care of the tasks linked to OpenXR (input and display), is used when HMD support is r...
Definition: WindowOpenXR.h:52