1#include "RaytrixStreamer.h"
23void OnImageCaptured(
const Rx::CRxImage& xImage,
unsigned uCamIdx, Rx::LFR::CImageQueue& camBuffer)
28 Rx::CRxImage xCapturedImage;
29 xCapturedImage.Create(xImage);
34 if (!camBuffer.MoveIn(std::move(xCapturedImage)))
41 catch (Rx::CRxException& ex)
43 printf(
"Exception occured:\n%s\n\n", ex.ToString(
true).ToCString());
44 printf(
"Press any key to end program...\n");
57static void ImageCaptured(
const Rx::CRxImage& xImage,
unsigned uCamIdx,
void* pvContext)
60 OnImageCaptured(xImage, uCamIdx, context->
getCamBuffer(uCamIdx));
96void RaytrixStreamer::findVulkanGPU(
const uint8_t uuid[VK_UUID_SIZE]) {
99 cudaGetDeviceCount(&cudaDeviceCount);
102 for (
int cudaDevice = 0; cudaDevice < cudaDeviceCount; cudaDevice++)
104 cudaDeviceProp deviceProp;
105 cudaGetDeviceProperties(&deviceProp, cudaDevice);
107 std::cout <<
"GPU n: " << cudaDevice << std::endl;
108 const unsigned char* p =
reinterpret_cast<uchar*
>(&deviceProp.uuid);
109 for (
size_t i = 0; i < 16; i++) {
110 printf(
"%02hhx", p[i]);
114 if (!memcmp(&deviceProp.uuid, uuid, VK_UUID_SIZE))
116 vulkanGPU = cudaDevice;
119 std::cout << std::endl;
120 std::cout <<
"Vulkan GPU: " << std::endl;
121 for (
size_t i = 0; i < 16; ++i) {
122 printf(
"%02hhx", uuid[i]);
126 std::cout << std::endl;
129 gpuErrchk(cudaSetDevice(vulkanGPU));
130 std::cout <<
"Available GPUs: " << cudaDeviceCount <<
" Vulkan GPU:" << vulkanGPU << std::endl;
133void RaytrixStreamer::initRxCams() {
135 std::cout <<
"Initializing Rx cams" << std::endl;
138 xCamServer.FindCameras();
141 if (xCamServer.GetCameraCount() == 0)
143 printf(
"No camera found\n");
144 throw HVT_ERROR_NOT_FOUND;
147 printf(
"Number of cameras available: %d\n", xCamServer.GetCameraCount());
149 for (
int i = 0; i < infoJSON.numCams; ++i) {
151 auto& xCam = xCamServer.GetCamera(infoJSON.uIDs[i]);
154 printf(
"Opening camera %i...", infoJSON.uIDs[i]);
159 xCam.AddImageCapturedCallback(ImageCaptured, (
void*)
this);
161 printf(
"______________________________________________\n");
162 printf(
"Camera %d:\n", infoJSON.uIDs[i]);
168 printf(
">> Type: %s\n", xCam.GetDriverName().ToCString());
171 printf(
">> ID : %s\n", xCam.GetInternalSerial().ToCString());
173 printf(
">> Buffersize: %u\n", uBufferSize);
175 printf(
">> Overwrite : %s\n", bOverwrite ?
"Yes" :
"No");
180 camBuffers[i].Initialize(uBufferSize, bOverwrite);
182 if(xCam.IsPropertyAvailable(Rx::Interop::Runtime30::Camera::EProperty::Exposure)) xCam.SetProperty(Rx::Interop::Runtime30::Camera::EProperty::Exposure, infoJSON.exposureCams[i]);
184 Rx::CRxArrayString GUIDs;
185 Rx::LFR::CCalibrationManager::GetCalibrationGUIDs(GUIDs);
187 for (
size_t j = 0; infoJSON.specificCal && j < GUIDs.Length(); ++j) {
188 if (GUIDs.GetDataPtr()[j] == infoJSON.GUIDsCalib[i]) {
189 std::cout <<
"Find metric calibration wanted: " << infoJSON.GUIDsCalib[i].ToCString() << std::endl;
194 if (idxInGUIDs >= 0) {
195 Rx::LFR::CCalibrationManager::LoadCalibration(*(camCalibrations[i]), GUIDs.GetDataPtr()[idxInGUIDs],
true);
199 if (!Rx::LFR::CCalibrationManager::HasDatabase(xCam))
201 std::cerr <<
"The first camera in your system does not have a database." << std::endl;
202 std::cerr <<
"Either use the installer for your camera settings to install the calibration on your system or create a calibration manualy via RxLive for example." << std::endl;
203 throw HVT_ERROR_NOT_FOUND;
205 Rx::LFR::CCalibrationManager::LoadDefaultCalibration(*(camCalibrations[i]), xCam,
true);
210void RaytrixStreamer::initStreamParameters() {
213 if (synthesisSem == NULL) {
214 std::cerr <<
"Impossible to allocate data for semaphore ..." << std::endl;
215 throw HVT_ERROR_UNKNOWN;
220 using namespace std::chrono_literals;
221 auto framePeriod = std::chrono::nanoseconds(1s) / frameRate;
224 for (
size_t i = 0; i < infoJSON.numCams; ++i)
227 HvtProjectionType ptype;
230 ptype = HvtProjectionType::HVT_PROJECTION_PERSPECTIVE;
236 RS.projectionType = ptype;
237 RS.width_color = infoJSON.width;
238 RS.height_color = infoJSON.height;
239 RS.width_depth = infoJSON.widthDepth;
240 RS.height_depth = infoJSON.heightDepth;
243 RS.colorFrameSize = infoJSON.width * infoJSON.height * 4;
244 RS.colorFrameStride = infoJSON.width * 4;
245 RS.depthFrameSize = infoJSON.widthDepth * infoJSON.heightDepth *
sizeof(float);
246 RS.depthFrameStride = infoJSON.widthDepth *
sizeof(float);
247 RS.colorFormat = HvtImageFormat::HVT_FORMAT_R8G8B8A8_UNORM;
248 RS.depthFormat = HvtImageFormat::HVT_FORMAT_R32_SFLOAT;
249 RS.intrinsics = intrinsics;
250 RS.extrinsics = extrinsics;
251 RS.framePeriod = framePeriod;
252 RS.frameCount = (int) numFrames;
253 readStreams.push_back(RS);
257void RaytrixStreamer::initRxCudaCompute() {
258 std::cout <<
"Initialize RxCUDACompute instances" << std::endl;
259 xCudaComputes =
new Rx::LFR::CCudaCompute[infoJSON.numCams];
261 Rx::LFR::CCuda::EnumerateCudaDevices();
262 Rx::CRxMetaData metaData;
264 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
266 xCudaComputes[i].SetCudaDevice(Rx::LFR::CCuda::GetDevice(vulkanGPU));
268 xCudaComputes[i].ApplyCalibration(*(camCalibrations[i]),
true);
270 if (infoJSON.loadFromRawFile) {
271 seqReaders[i].GetMetaData((Rx::CRxMetaData&)metaData);
272 xCudaComputes[i].GetComputeParams().ImportFromMetaData(metaData);
274 rayImages[i].GetSize((
int&)widthDefault, (
int&)heightDefault);
277 xCudaComputes[i].GetComputeParams().ImportParameterFromFile(infoJSON.filenameComputeParameters);
279 xCamServer.GetCamera(i).GetProperty(Rx::Interop::Runtime30::Camera::EProperty::Width, (
int&)widthDefault);
280 xCamServer.GetCamera(i).GetProperty(Rx::Interop::Runtime30::Camera::EProperty::Height, (
int&)heightDefault);
283 xCudaComputes[i].GetComputeParams().SetValue(Rx::LFR::Params::ECudaCompute::PreProc_DataType, (
unsigned)Rx::Interop::Runtime28::EDataType::UByte);
285 if (infoJSON.forceRGBResolution) {
286 if (widthDefault / infoJSON.width != heightDefault / infoJSON.height) {
287 std::cout <<
"The focus image divisor should be the same for the rows and the the columns..." << std::endl;
289 imgDivisor = (double)widthDefault / (
double)infoJSON.width;
290 xCudaComputes[i].GetComputeParams().SetValue(Rx::LFR::Params::ECudaCompute::Focus_ImageDivisor, imgDivisor);
293 xCudaComputes[i].GetComputeParams().GetValue(Rx::LFR::Params::ECudaCompute::Focus_ImageDivisor,(
double&) imgDivisor);
294 infoJSON.width = widthDefault/imgDivisor;
295 infoJSON.height = heightDefault/imgDivisor;
298 if (infoJSON.forceDepthResolution) {
299 if (widthDefault / infoJSON.widthDepth != heightDefault / infoJSON.heightDepth) {
300 std::cout <<
"The depth image divisor should be the same for the rows and the the columns..." << std::endl;
302 imgDivisor = (double)widthDefault / (
double)infoJSON.widthDepth;
303 xCudaComputes[i].GetComputeParams().SetValue(Rx::LFR::Params::ECudaCompute::Depth_ImageDivisor, imgDivisor);
306 xCudaComputes[i].GetComputeParams().GetValue(Rx::LFR::Params::ECudaCompute::Depth_ImageDivisor, (
double&)imgDivisor);
307 infoJSON.widthDepth = widthDefault / imgDivisor;
308 infoJSON.heightDepth = heightDefault / imgDivisor;
311 catch (Rx::CRxException e) {
312 std::cerr <<
"Failed to initialized cuda compute... Check Raytrix error code: " << e.ToString().ToCString() << std::endl;
313 throw HVT_ERROR_UNKNOWN;
319void RaytrixStreamer::initRxSDK() {
321 printf(
"Authenticate LFR...\n");
323 Rx::LFR::CLightFieldRuntime::Authenticate();
325 catch (Rx::CRxException e) {
326 std::cerr <<
"Impossible to authenticate. Check RaytrixSDK error code: " << e.ToString().ToCString() << std::endl;
327 throw HVT_ERROR_UNKNOWN;
329 if (!Rx::LFR::CLightFieldRuntime::IsFeatureSupported(Rx::Dongle::ERuntimeFeature::SDK)) {
330 std::cerr <<
"Your license does not allow you to use the SDK properly. Upgrade it or buy another license..." << std::endl;
331 throw HVT_ERROR_INVALID_HANDLE;
334 camCalibrations = (Rx::LFR::CCalibration**)malloc(
sizeof(Rx::LFR::CCalibration*) * infoJSON.numCams);
335 if (camCalibrations == NULL) {
336 std::cerr <<
"Impossible to allocate memory for default calibrations" << std::endl;
337 throw HVT_ERROR_UNKNOWN;
340 if (infoJSON.loadFromRawFile) {
341 rayImages =
new Rx::LFR::CRayImage[infoJSON.numCams];
342 seqReaders =
new Rx::LFR::CSeqFileReader[infoJSON.numCams];
345 camBuffers =
new Rx::LFR::CImageQueue[infoJSON.numCams];
346 capturedImages =
new Rx::CRxImage[infoJSON.numCams];
347 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
348 camCalibrations[i] =
new Rx::LFR::CCalibration();
351 imgFormatRGB =
new Rx::CRxImageFormat[infoJSON.numCams];
352 imgFormatDepth =
new Rx::CRxImageFormat[infoJSON.numCams];
354 pitchInCudaRGB =
new size_t[infoJSON.numCams];
355 pitchInCudaDepth =
new size_t[infoJSON.numCams];
357 referencePlaneToCameraPlane =
new float[infoJSON.numCams];
360void RaytrixStreamer::initArrayCuda() {
361 std::cout <<
"Init CUDA array" << std::endl;
362 imgRGB = (
unsigned short**)malloc(
sizeof(
unsigned short*) * infoJSON.numCams);
363 imgDepth = (
unsigned short**)malloc(
sizeof(
unsigned short*) * infoJSON.numCams);
364 finalRGB = (
unsigned char**)malloc(
sizeof(
unsigned char*) * infoJSON.numCams);
365 finalDepth = (
float**)malloc(
sizeof(
float*) * infoJSON.numCams);
366 imgFloatDepth = (
float**)malloc(
sizeof(
float*) * infoJSON.numCams);
367 prevFinalDepth = (
float**)malloc(
sizeof(
float*) * infoJSON.numCams);
368 imgUByteRGB = (uchar**)malloc(
sizeof(uchar*) * infoJSON.numCams);
370 if (imgRGB == NULL || imgDepth == NULL || finalRGB == NULL || finalDepth == NULL) {
371 std::cerr <<
"Impossible to allocate data for img vectors..." << std::endl;
372 throw HVT_ERROR_UNKNOWN;
375 gpuErrchk(cudaSetDevice(vulkanGPU));
376 cudaStreams = (cudaStream_t*)malloc(
sizeof(cudaStream_t) * infoJSON.numCams);
377 cudaEvents = (cudaEvent_t*)malloc(
sizeof(cudaEvent_t) * infoJSON.numCams);
379 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
380 gpuErrchk(cudaMalloc(finalRGB + i,
sizeof(uchar) * infoJSON.width * infoJSON.height * 4));
381 gpuErrchk(cudaMalloc(finalDepth + i,
sizeof(
float) * infoJSON.widthDepth * infoJSON.heightDepth));
382 gpuErrchk(cudaMalloc(prevFinalDepth + i,
sizeof(
float) * infoJSON.widthDepth * infoJSON.heightDepth));
384 gpuErrchk(cudaStreamCreate(&(cudaStreams[i])));
385 gpuErrchk(cudaEventCreateWithFlags(&(cudaEvents[i]), cudaEventDisableTiming));
389void RaytrixStreamer::readInfoFromJSON() {
392 errno_t err = _dupenv_s(&jsonPath, &len, ENV_NAME);
394 std::cerr <<
"No " << ENV_NAME <<
"env variable set, cannot load settings" << std::endl;
395 throw HvtResult::HVT_ERROR_NOT_FOUND;
399 std::cout <<
"Start reading JSON file..." << std::endl;
400 std::ifstream jsonRead{ jsonPath, std::ifstream::binary };
401 if (!jsonRead.good()) {
402 std::cout <<
"Impossible to read JSON file, check path... Path given: " << jsonPath << std::endl;
403 throw HVT_ERROR_NOT_FOUND;
405 nlohmann::json jsonContent;
406 jsonRead >> jsonContent;
408 infoJSON.numCams = jsonContent[
"numCams"];
410 infoJSON.forceRGBResolution = jsonContent[
"forceUseOfSpecificRBGResolution"];
411 if (infoJSON.forceRGBResolution) {
413 infoJSON.width = jsonContent[
"width"];
414 infoJSON.height = jsonContent[
"height"];
417 infoJSON.forceDepthResolution = jsonContent[
"forceUseOfSpecificDepthResolution"];
418 if (infoJSON.forceRGBResolution) {
420 infoJSON.widthDepth = jsonContent[
"width_depth"];
421 infoJSON.heightDepth = jsonContent[
"height_depth"];
424 infoJSON.uIDs =
new unsigned int[infoJSON.numCams];
425 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
426 infoJSON.uIDs[i] = jsonContent[
"idCams"][std::to_string(i).c_str()];
429 std::string tmpStdString = jsonContent[
"RxComputeParametersFile"];
430 infoJSON.filenameComputeParameters = Rx::CRxString(tmpStdString.c_str());
432 infoJSON.loadFromRawFile = jsonContent[
"fromRawFile"];
433 if (infoJSON.loadFromRawFile) {
435 infoJSON.filenameRawFiles =
new Rx::CRxString[infoJSON.numCams];
436 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
437 tmpStdString = jsonContent[
"pathRawFile"][std::to_string(i).c_str()];
438 infoJSON.filenameRawFiles[i] = Rx::CRxString(tmpStdString.c_str());
442 infoJSON.specificCal = jsonContent[
"specificCalibration"];
443 if (infoJSON.specificCal) {
445 infoJSON.GUIDsCalib =
new Rx::CRxString[infoJSON.numCams];
446 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
447 tmpStdString = jsonContent[
"GUIDsForCalibration"][std::to_string(i).c_str()];
448 infoJSON.GUIDsCalib[i] = Rx::CRxString(tmpStdString.c_str());
451 if (!infoJSON.loadFromRawFile) {
453 infoJSON.exposureCams =
new float[infoJSON.numCams];
454 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
455 infoJSON.exposureCams[i] = jsonContent[
"exposureCams"][std::to_string(i).c_str()];
459 infoJSON.extrinsicParamsPath = jsonContent[
"ExtrinsicParamsFile"];
460 std::cout <<
"Json path read" << std::endl;
463void RaytrixStreamer::initMutex() {
464 loaderMtxs =
new std::mutex[infoJSON.numCams];
465 loaderCVs =
new std::condition_variable[infoJSON.numCams];
466 canLoadImgs =
new bool[infoJSON.numCams];
467 memset(canLoadImgs,
true, infoJSON.numCams *
sizeof(
bool));
470void RaytrixStreamer::initRxRayFile() {
471 std::cout <<
"Read RayFile: " << std::endl;
473 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
474 std::cout <<
"Seq " << i <<
": " << infoJSON.filenameRawFiles[i].ToCString() << std::endl;
475 seqReaders[i].Open(infoJSON.filenameRawFiles[i]);
476 seqReaders[i].ReadFrame(rayImages[i],
true,
false);
478 Rx::CRxArrayString GUIDs;
479 Rx::LFR::CCalibrationManager::GetCalibrationGUIDs(GUIDs);
481 for (
size_t j = 0; infoJSON.specificCal && j < GUIDs.Length(); ++j) {
482 if (GUIDs.GetDataPtr()[j] == infoJSON.GUIDsCalib[i]) {
483 std::cout <<
"Find metric calibration wanted: " << infoJSON.GUIDsCalib[i].ToCString() << std::endl;
488 if (idxInGUIDs >= 0) {
489 camCalibrations[i] =
new Rx::LFR::CCalibration();
490 Rx::LFR::CCalibrationManager::LoadCalibration(*(camCalibrations[i]), GUIDs.GetDataPtr()[idxInGUIDs],
true);
493 camCalibrations[i] = (Rx::LFR::CCalibration*)&(rayImages[i].GetCalibration());
497 catch (Rx::CRxException e) {
498 std::cout <<
"Impossible to read Rays file... Check error code: " << e.ToString().ToCString() << std::endl;
499 throw HVT_ERROR_UNKNOWN;
507void RaytrixStreamer::addMsgToPrint(
const char* title,
long long int averageTime,
float frameNumber)
509 if (printMsg == NULL) {
511 printMsg = (
char*)malloc(
sizeof(
char) * SIZE_MSG);
512 if (printMsg == NULL)
516 size_t size = std::strlen(title) + 6 + 6;
517 sprintf(printMsg + whereToAddMsg,
"%s: %f ...", title, (frameNumber) * 1000.f / averageTime);
518 whereToAddMsg += size;
521void RaytrixStreamer::printFPS() {
522 std::cout <<
'\r' << printMsg << std::flush;
525void RaytrixStreamer::resetPrintMsg() {
526 memset(printMsg,
'\0',
sizeof(
char) * SIZE_MSG);
534 const float ZFar = 1.3f;
539 const float ZNear = 0.4f;
544 Rx::LFR::CParameters<Rx::LFR::Params::ECalib::ID>& paramsCal = camCalibrations[idxCam]->GetParams();
546 paramsCal.GetValue(Rx::LFR::Params::ECalib::MainLensThick_NominalFocalLengthMM, f);
547 paramsCal.GetValue(Rx::LFR::Params::ECalib::Sensor_PhysicalPixelSizeMM, sizePixel);
550 intrinsicParams.
focalX = (float) f / (((
float)widthDefault / (
float)infoJSON.widthDepth) * sizePixel);
551 intrinsicParams.
focalY = (float) f / (((
float)heightDefault / (float)infoJSON.heightDepth) * sizePixel);
555 return intrinsicParams;
562 Rx::LFR::CParameters<Rx::LFR::Params::ECalib::ID>& paramsCal = camCalibrations[idxCam]->GetParams();
563 paramsCal.GetValue(Rx::LFR::Params::ECalib::IsExtrinsicCalibrated, isExCalib);
564 if (isExCalib != 1) {
565 std::cerr <<
"Camera " << idxCam <<
" is not extrinsincly calibrated... Reconstruction must be wrong." << std::endl;
567 Rx::CRxArrayDouble trans;
568 paramsCal.GetValue(Rx::LFR::Params::ECalib::Translation_Global_Sensor, trans);
569 double* dataPtr = (
double*)trans.GetPointer();
570 size_t sizeData = trans.Length();
571 bool checkExParams =
true;
573 checkExParams =
false;
575 std::ifstream jsonRead{ infoJSON.extrinsicParamsPath, std::ifstream::binary };
576 if (!jsonRead.good()) {
577 std::cout <<
"Impossible to read JSON extrinsic file, check path... Path given: " << infoJSON.extrinsicParamsPath << std::endl;
578 throw HVT_ERROR_NOT_FOUND;
580 nlohmann::json jsonContent;
581 jsonRead >> jsonContent;
584 pos.x = (float)dataPtr[2] + (
double) jsonContent[
"cameras"][idxCam][
"Position"][0];
585 pos.y = (float)dataPtr[0] + (
double) jsonContent[
"cameras"][idxCam][
"Position"][1];
586 pos.z = (float)dataPtr[1] + (
double) jsonContent[
"cameras"][idxCam][
"Position"][2];
587 referencePlaneToCameraPlane[idxCam] = pos.x;
589 paramsCal.GetValue(Rx::LFR::Params::ECalib::Rotation_Global_Sensor_Pitch, data);
590 rot.pitch = (float)data + (
double) jsonContent[
"cameras"][idxCam][
"Rotation"][0];
591 paramsCal.GetValue(Rx::LFR::Params::ECalib::Rotation_Global_Sensor_Roll, data);
592 rot.roll = (float)data + (
double) jsonContent[
"cameras"][idxCam][
"Rotation"][1];
593 paramsCal.GetValue(Rx::LFR::Params::ECalib::Rotation_Global_Sensor_Yaw, data);
594 rot.yaw = (float)data + (
double) jsonContent[
"cameras"][idxCam][
"Rotation"][2];
600 referencePlaneToCameraPlane[idxCam] = 1.0f;
609 extrinsics.position = pos;
610 extrinsics.rotation = rot;
616 return camBuffers[idxCam];
622void RaytrixStreamer::getRGBDFormats() {
623 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
625 imgFormatRGB[i] = xCudaComputes[i].GetImageFormat(idRGB);
627 catch (Rx::CRxException e) {
628 std::cerr <<
"Impossible to get image format... Check error code: "<< e.ToString().ToCString() << std::endl;
629 throw HVT_ERROR_UNKNOWN;
631 if (imgFormatRGB[i].m_iWidth != infoJSON.width || imgFormatRGB[i].m_iHeight != infoJSON.height) {
632 std::cerr <<
"RGB image formats do not correspond..." << std::endl;
633 throw HVT_ERROR_UNKNOWN;
636 imgFormatDepth[i] = xCudaComputes[i].GetImageFormat(idDepth);
638 catch (Rx::CRxException e) {
639 std::cerr <<
"Impossible to get image format... Check error code: " << e.ToString().ToCString() << std::endl;
640 throw HVT_ERROR_UNKNOWN;
642 if (imgFormatDepth[i].m_iWidth != infoJSON.widthDepth || imgFormatDepth[i].m_iHeight != infoJSON.heightDepth) {
643 std::cerr <<
"Depth image formats do not correspond..." << std::endl;
644 throw HVT_ERROR_UNKNOWN;
647 pitchInCudaRGB[i] = xCudaComputes[i].GetDevicePointerPitch(idRGB);
648 pitchInCudaDepth[i] = xCudaComputes[i].GetDevicePointerPitch(idDepth);
650 std::cout <<
"RGB cam/file " << i <<
" :" << imgFormatRGB[i].ToString().ToCString() << std::endl;
651 std::cout <<
"Depth cam/file "<< i <<
" :" << imgFormatDepth[i].ToString().ToCString() << std::endl;
653 isFormatLoaded =
true;
656void RaytrixStreamer::launchAsyncLoader(
bool needToWaitThreadToFinish) {
658 if (infoJSON.loadFromRawFile) {
659 t = std::thread(&RaytrixStreamer::asyncLoaderImageFromSeqFiles,
this);
662 t = std::thread(&RaytrixStreamer::asyncLoaderImage,
this);
664 if (needToWaitThreadToFinish) t.join();
668void RaytrixStreamer::asyncLoaderImageFromOneSeqFile(
size_t idxCam) {
671 if (seqReaders[idxCam].GetFrameCount() == seqReaders[idxCam].GetLastFrameIndex() + 1) {
672 seqReaders[idxCam].SetNextFrameIndex(0);
674 seqReaders[idxCam].ReadFrame(rayImages[idxCam],
false);
676 xCudaComputes[idxCam].UploadRawImage(rayImages[idxCam]);
678 catch (Rx::CRxException e) {
679 std::cerr <<
"Impossible to read or upload ray image to the cuda compute ... Check error code: " << e.ToString().ToCString() << std::endl;
680 throw HVT_ERROR_UNKNOWN;
684void RaytrixStreamer::asyncLoaderImageFromSeqFiles() {
685 bool* tmpSync = &imgsLoaded;
686 std::unique_lock<std::mutex> lckSync(syncMtx);
687 syncCV.wait(lckSync, [tmpSync] {
return !(*tmpSync); });
688 std::thread* threads =
new std::thread[infoJSON.numCams];
689 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
690 threads[i] = std::thread(&RaytrixStreamer::asyncLoaderImageFromOneSeqFile,
this, i);
692 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
701void RaytrixStreamer::asyncLoaderImage() {
702 size_t idxRefCam = 0;
703 bool loadImgSuccess =
false;
705 bool* tmpSync = &imgsLoaded;
706 std::unique_lock<std::mutex> lckSync(syncMtx);
707 syncCV.wait(lckSync, [tmpSync] {
return !(*tmpSync); });
708 while(!loadImgSuccess){
709 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
710 std::thread(&RaytrixStreamer::asyncLoaderImageOneCam,
this, i).detach();
712 if (infoJSON.numCams == 1) {
713 bool* tmp = canLoadImgs;
714 std::unique_lock<std::mutex> lck(loaderMtxs[0]);
715 loaderCVs[0].wait(lck, [tmp] {
return !(*tmp); });
716 canLoadImgs[0] =
true;
718 loaderCVs[0].notify_all();
722 bool* tmpLoaderRefCam = canLoadImgs + idxRefCam;
723 std::unique_lock<std::mutex> lckLoaderRefCam(loaderMtxs[idxRefCam]);
724 loaderCVs[idxRefCam].wait(lckLoaderRefCam, [tmpLoaderRefCam] {
return !(*tmpLoaderRefCam); });
725 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
726 if (i == idxRefCam)
continue;
728 bool* tmp = canLoadImgs+i;
729 std::unique_lock<std::mutex> lckLoader(loaderMtxs[i]);
730 loaderCVs[i].wait(lckLoader, [tmp] {
return !(*tmp) ; });
732 loadImgSuccess = (abs(capturedImages[i].GetTimestamp() - capturedImages[idxRefCam].GetTimestamp()) < MAX_TIME_BETWEEN_CAMS);
734 canLoadImgs[i] =
true;
736 loaderCVs[i].notify_all();
738 canLoadImgs[idxRefCam] =
true;
739 lckLoaderRefCam.unlock();
740 loaderCVs[idxRefCam].notify_all();
743 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
744 xCudaComputes[i].UploadRawImage(capturedImages[i]);
747 catch (Rx::CRxException e) {
748 std::cerr <<
"Impossible to upload raw image to the cuda compute ... Check error code: " << e.ToString().ToCString() << std::endl;
749 throw HVT_ERROR_UNKNOWN;
756void RaytrixStreamer::asyncLoaderImageOneCam(
size_t idxCam) {
757 bool* tmp = canLoadImgs + idxCam;
758 std::unique_lock<std::mutex> lck(loaderMtxs[idxCam]);
759 loaderCVs[idxCam].wait(lck, [tmp] {
return *tmp; });
761 bool imgLoadSucess =
false;
762 while (!imgLoadSucess) {
763 if (camCaptureMode == Rx::Interop::Runtime30::Camera::ETriggerMode::Software_SnapShot) {
765 auto& cam = xCamServer.GetCamera(idxCam);
770 if(!camBuffers[idxCam].WaitForNotEmpty(MAX_TIME_WAIT_BUFFER))
continue;
773 imgLoadSucess = camBuffers[idxCam].MoveOut(capturedImages[idxCam]);
775 canLoadImgs[idxCam] =
false;
777 loaderCVs[idxCam].notify_all();
780void RaytrixStreamer::acquireRGBD(){
782 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
783 if (!xCudaComputes[i].Compute_TotalFocus(idSpaceRGB)) {
784 std::cerr <<
"Impossible to compute total focus image and depth ... Camera: " << i << std::endl;
785 throw HVT_ERROR_UNKNOWN;
787 if (!xCudaComputes[i].Compute_Depth3D(idSpaceDepth3D[0], idSpaceDepth3D[1])) {
788 std::cerr <<
"Impossible to compute depth ... Camera: " << i << std::endl;
789 throw HVT_ERROR_UNKNOWN;
793 catch (Rx::CRxException e) {
794 std::cerr <<
"Impossible to read or compute... Check error code: " << e.ToString().ToCString() << std::endl;
795 throw HVT_ERROR_UNKNOWN;
797 if (!isFormatLoaded) {
800 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
801 switch (imgFormatRGB[i].m_eDataType) {
802 case Rx::Interop::Runtime28::EDataType::UByte:
803 imgUByteRGB[i] = (uchar*)xCudaComputes[i].GetImageDevicePointer(idRGB);
805 case Rx::Interop::Runtime28::EDataType::UShort:
806 imgRGB[i] = (
unsigned short*)xCudaComputes[i].GetImageDevicePointer(idRGB);
809 std::cerr <<
"Not known RGBA format... Check format: " << imgFormatRGB[i].ToString().ToCString() << std::endl;
810 throw HVT_ERROR_UNKNOWN;
813 switch (imgFormatDepth[i].m_eDataType) {
814 case Rx::Interop::Runtime28::EDataType::UShort:
815 imgDepth[i] = (
unsigned short*)xCudaComputes[i].GetImageDevicePointer(idDepth);
817 case Rx::Interop::Runtime28::EDataType::Float:
818 imgFloatDepth[i] = (
float*)xCudaComputes[i].GetImageDevicePointer(idDepth);
821 std::cerr <<
"Not known depth format... Check format: " << imgFormatDepth[i].ToString().ToCString() << std::endl;
822 throw HVT_ERROR_UNKNOWN;
828void RaytrixStreamer::refineRGBD() {
829 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
830 switch (imgFormatRGB[i].m_eDataType) {
831 case Rx::Interop::Runtime28::EDataType::UByte:
832 if (pitchInCudaRGB[i] !=
sizeof(uchar) * 4 * infoJSON.width) {
833 removePitch<uchar>(imgUByteRGB[i], finalRGB[i], infoJSON.width, infoJSON.height, pitchInCudaRGB[i] / (
sizeof(uchar) * 4), 4, cudaStreams[i]);
836 gpuErrchk(cudaMemcpyAsync(finalRGB[i], imgUByteRGB[i],
sizeof(uchar) * 4 * infoJSON.width * infoJSON.height, cudaMemcpyDeviceToDevice, cudaStreams[i]));
839 case Rx::Interop::Runtime28::EDataType::UShort:
840 uShort2uChar(imgRGB[i], finalRGB[i], infoJSON.width, infoJSON.height, pitchInCudaRGB[i] / (
sizeof(USHORT) * 4), 4, cudaStreams[i]);
843 std::cerr <<
"Not known RGBA format... Check format: " << imgFormatRGB[i].ToString().ToCString() << std::endl;
844 throw HVT_ERROR_UNKNOWN;
847 switch (imgFormatDepth[i].m_eDataType) {
848 case Rx::Interop::Runtime28::EDataType::UShort:
850 case Rx::Interop::Runtime28::EDataType::Float:
851 scaleAddDataArrayUChannel<float>(imgFloatDepth[i], finalDepth[i], infoJSON.widthDepth, infoJSON.heightDepth, pitchInCudaDepth[i] / (
sizeof(
float) * 4), 4, channelDepth, -1 / 1000.0f, -referencePlaneToCameraPlane[i], cudaStreams[i]);
854 std::cerr <<
"Not known depth format... Check format: " << imgFormatDepth[i].ToString().ToCString() << std::endl;
855 throw HVT_ERROR_UNKNOWN;
857 temporalConsistencyAdjustement<float>(prevFinalDepth[i], finalDepth[i], infoJSON.widthDepth, infoJSON.heightDepth, 5, 0.05, 0.5, cudaStreams[i]);
865void RaytrixStreamer::uploadFrame(
size_t streamId, ReadStream& stream)
867 auto imageIndex = slotStreamingIndex;
869 auto& dstColorSlot = stream.colorSlots.at(imageIndex);
870 auto& dstDepthSlot = stream.depthSlots.at(imageIndex);
873 copyColor(dstColorSlot.cuda_ptr_surf,finalRGB[streamId],stream.width_color,stream.height_color, cudaStreams[streamId]);
874 copyDepth(dstDepthSlot.cuda_ptr_surf, finalDepth[streamId], stream.width_depth, stream.height_depth, cudaStreams[streamId]);
875 gpuErrchk(cudaEventRecord(cudaEvents[streamId],cudaStreams[streamId]));
878void RaytrixStreamer::streamingLoop() {
879 gpuErrchk(cudaSetDevice(vulkanGPU));
880 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
881 if (!infoJSON.loadFromRawFile) {
883 std::cout <<
"Start camera " << i << std::endl;
884 xCamServer.GetCamera(i).Start(camCaptureMode);
888 beginAvgStreaming = std::chrono::steady_clock::now();
889 std::chrono::steady_clock::time_point begin;
891 launchAsyncLoader(
true);
893 std::unique_lock<std::mutex> lck(syncMtx, std::defer_lock);
894 bool* cond = &imgsLoaded;
896 begin = std::chrono::steady_clock::now();
899 syncCV.wait(lck, [cond] {
return *cond; });
911 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
912 uploadFrame(i, readStreams[i]);
914 readStreams[i].streamedFrame = readStreams[i].frameIndex(begin - beginAvgStreaming);
917 swapStreamingToPending();
920 endStreaming = std::chrono::steady_clock::now();
922 if ((
int)numFrames % 100 == 0) {
923 addMsgToPrint(
"Streaming Loop fps", std::chrono::duration_cast<std::chrono::milliseconds>(endStreaming - beginAvgStreaming).count(), numFrames);
928 std::this_thread::yield();
931void RaytrixStreamer::swapStreamingToPending() {
932 std::lock_guard<std::mutex> l(indicesMutex);
933 std::swap(slotPendingIndex, slotStreamingIndex);
934 newDataInPending =
true;
937void RaytrixStreamer::swapPendingToReading() {
938 std::lock_guard<std::mutex> l(indicesMutex);
939 if (newDataInPending)
941 std::swap(slotPendingIndex, slotReadingIndex);
942 newDataInPending =
false;
950template<
typename T>
void RaytrixStreamer::writeInFileWindow(T* dataCorrect, T* dataDebug,
size_t width,
size_t height,
size_t sizeWindow,
int numCam) {
951 if (width / 2 + sizeWindow > width || height / 2 + sizeWindow > height) {
952 std::cerr <<
"Specify a smaller window size..." << std::endl;
953 throw HVT_ERROR_UNKNOWN;
955 if (dataCorrect == NULL || dataDebug == NULL) {
956 std::cerr <<
"Specify allocated array ... " << std::endl;
957 throw HVT_ERROR_UNKNOWN;
960 const char outCorrect[] =
"../RaytrixStreamer/dataCorrect.txt";
961 const char outDebug[] =
"../RaytrixStreamer/dataDebug.txt";
963 fs::path pathCorrect = outCorrect;
964 std::ofstream correctDataStream{ pathCorrect, std::ofstream::out | std::ofstream::trunc };
965 if (!correctDataStream.good()) {
966 std::cerr <<
"Impossible to open data correct file, check path... Path given: " << pathCorrect << std::endl;
967 throw HVT_ERROR_NOT_FOUND;
969 fs::path pathDebug = outDebug;
970 std::ofstream debugDataStream{ pathDebug, std::ofstream::out | std::ofstream::trunc };
971 if (!debugDataStream.good()) {
972 std::cerr <<
"Impossible to open data debug file, check path... Path given: " << pathDebug << std::endl;
973 throw HVT_ERROR_NOT_FOUND;
976 for (
size_t i = 0; i < sizeWindow; ++i) {
977 for (
size_t j = 0; j < sizeWindow; ++j) {
978 correctDataStream << dataCorrect[(width / 2) * ((height / 2) + i) + j] <<
",";
979 debugDataStream << dataDebug[(width / 2) * ((height / 2) + i) + j] <<
",";
981 correctDataStream << std::endl;
982 debugDataStream << std::endl;
985 correctDataStream.close();
986 debugDataStream.close();
989void RaytrixStreamer::debugFloatDepth() {
991 float* imgTmp2 =
new float[infoJSON.widthDepth * infoJSON.heightDepth];
993 gpuErrchk(cudaDeviceSynchronize());
994 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
996 xCudaComputes[i].Download(Rx::LFR::EImage::DepthMap_View_Virtual, imgTmp);
997 imgTmp.GetSize(width, height);
999 catch (Rx::CRxException e) {
1000 std::cerr <<
"Error while debugging depth... Check error code: " << e.ToString().ToCString() << std::endl;
1001 throw HVT_ERROR_UNKNOWN;
1003 std::cout <<
"Downloaded img " << i <<
": Width: " << width <<
" Height: " << height <<
" Nb of bytes: " << imgTmp.GetByteCount() <<
" Format: " << imgTmp.GetFormat().ToString().ToCString() << std::endl;
1004 gpuErrchk(cudaMemcpy(imgTmp2, finalDepth[i], infoJSON.widthDepth * infoJSON.heightDepth *
sizeof(
float), cudaMemcpyDeviceToHost));
1005 std::cout <<
"CUDA img " << i <<
": Width: " << infoJSON.widthDepth <<
" Height : " << infoJSON.heightDepth <<
" Nb of bytes : " << infoJSON.widthDepth * infoJSON.heightDepth *
sizeof(float) <<
" Format: " << imgFormatDepth[i].ToString().ToCString() << std::endl;
1006 gpuErrchk(cudaDeviceSynchronize());
1007 writeInFileWindow<float>((
float*)imgTmp.GetDataPtr(), imgTmp2, infoJSON.widthDepth, infoJSON.heightDepth, 100, i);
1015int RaytrixStreamer::ReadStream::frameIndex(Clock::duration time)
const
1017 return (time / framePeriod);
1020bool RaytrixStreamer::ReadStream::nextFrameReady(Clock::duration time)
const
1022 return streamedFrame != frameIndex(time);
1044 findVulkanGPU(uuid);
1047 if (infoJSON.loadFromRawFile) {
1053 initRxCudaCompute();
1054 initStreamParameters();
1061 std::cout <<
"---- Destroy RaytrixStreamer dll ----" << std::endl;
1062 if (synthesisSem != NULL)
1063 delete synthesisSem;
1064 for (
size_t i = 0; i < infoJSON.numCams; ++i) {
1065 xCamServer.GetCamera(i).Close();
1067 if (infoJSON.loadFromRawFile) {
1068 delete[] seqReaders;
1071 Rx::LFR::CLightFieldRuntime::End();
1075void RaytrixStreamer::enumerateStreamsParameters(uint32_t* streamsCount,
HvtRGBDStreamParameters* parameters)
const
1077 cudaSetDevice(vulkanGPU);
1080 *streamsCount = readStreams.size();
1084 if (*streamsCount != readStreams.size())
1086 throw HvtResult::HVT_ERROR_WRONG_BUFFER_SIZE;
1090 for (
const auto& readStream : readStreams)
1093 SP->
colorResolution = { (uint32_t)readStream.width_color, (uint32_t)readStream.height_color };
1094 SP->
depthResolution = { (uint32_t)readStream.width_depth, (uint32_t)readStream.height_depth };
1097 SP->
colorFormat = (HvtImageFormat)readStream.colorFormat;
1098 SP->
depthFormat = (HvtImageFormat)readStream.depthFormat;
1102 parameters[i] = *SP;
1110 cudaSetDevice(vulkanGPU);
1111 auto isDepth = (bool)exportInfos.
depth;
1112 auto& stream = readStreams.at(exportInfos.
streamIndex);
1115 auto& slots = isDepth ? stream.depthSlots : stream.colorSlots;
1122 throw HvtResult::HVT_ERROR_WRONG_BUFFER_SIZE;
1125 for (
int i = 0; i < numSlots; ++i)
1127 auto mem = exportInfos.
pImages[i];
1130 cudaExternalMemory_t cudaExtMemImageBuffer;
1131 cudaMipmappedArray_t cudaMipmappedImageArray;
1133 cudaExternalMemoryHandleDesc cudaExtMemHandleDesc;
1134 memset(&cudaExtMemHandleDesc, 0,
sizeof(cudaExtMemHandleDesc));
1136 cudaExtMemHandleDesc.type = cudaExternalMemoryHandleTypeOpaqueWin32;
1137 cudaExtMemHandleDesc.handle.win32.handle = (HANDLE)mem.handle;
1138 cudaExtMemHandleDesc.size = mem.size;
1140 gpuErrchk(cudaImportExternalMemory(&cudaExtMemImageBuffer, &cudaExtMemHandleDesc));
1142 cudaExternalMemoryMipmappedArrayDesc externalMemoryMipmappedArrayDesc;
1143 memset(&externalMemoryMipmappedArrayDesc, 0,
sizeof(externalMemoryMipmappedArrayDesc));
1145 cudaExtent extent = isDepth ? make_cudaExtent(stream.width_depth, stream.height_depth, 0) : make_cudaExtent(stream.width_color, stream.height_color, 0);
1146 cudaChannelFormatDesc formatDesc;
1147 formatDesc.x = isDepth ? 32 : 8;
1148 formatDesc.y = isDepth ? 0 : 8;
1149 formatDesc.z = isDepth ? 0 : 8;
1150 formatDesc.w = isDepth ? 0 : 8;
1151 formatDesc.f = isDepth ? cudaChannelFormatKindFloat : cudaChannelFormatKindUnsigned;
1153 externalMemoryMipmappedArrayDesc.offset = 0;
1154 externalMemoryMipmappedArrayDesc.formatDesc = formatDesc;
1155 externalMemoryMipmappedArrayDesc.extent = extent;
1156 externalMemoryMipmappedArrayDesc.flags = 0;
1157 externalMemoryMipmappedArrayDesc.numLevels = mipLevels;
1159 gpuErrchk(cudaExternalMemoryGetMappedMipmappedArray(&cudaMipmappedImageArray, cudaExtMemImageBuffer, &externalMemoryMipmappedArrayDesc));
1161 cudaArray_t cudaMipLevelArray;
1162 cudaResourceDesc resourceDesc;
1164 gpuErrchk(cudaGetMipmappedArrayLevel(&cudaMipLevelArray, cudaMipmappedImageArray, 0));
1167 memset(&resourceDesc, 0,
sizeof(resourceDesc));
1168 resourceDesc.resType = cudaResourceTypeArray;
1169 resourceDesc.res.array.array = cudaMipLevelArray;
1171 cudaSurfaceObject_t surfaceObject;
1172 gpuErrchk(cudaCreateSurfaceObject(&surfaceObject, &resourceDesc));
1176 IS.vk_handle = &mem.handle;
1177 IS.cuda_ptr_surf = surfaceObject;
1181 (isDepth ? stream.importedDepth : stream.importedColor) =
true;
1186 cudaSetDevice(vulkanGPU);
1187 if (exportInfos.semaphore == NULL)
1189 synthesisSem->isValid =
false;
1190 synthesisSem->sem = NULL;
1194 cudaExternalSemaphoreHandleDesc externalSemaphoreHandleDesc = {};
1196 if (exportInfos.type & HvtSemaphoreType::HVT_SEMAPHORE_TYPE_OPAQUE_WIN32_BIT)
1198 externalSemaphoreHandleDesc.type = cudaExternalSemaphoreHandleTypeOpaqueWin32;
1200 else if (exportInfos.type & HvtSemaphoreType::HVT_SEMAPHORE_TYPE_OPAQUE_WIN32_KMT_BIT)
1202 externalSemaphoreHandleDesc.type = cudaExternalSemaphoreHandleTypeOpaqueWin32Kmt;
1204 else if (exportInfos.type & HvtSemaphoreType::HVT_SEMAPHORE_TYPE_SYNC_FD_BIT)
1206 externalSemaphoreHandleDesc.type = cudaExternalSemaphoreHandleTypeOpaqueFd;
1209 externalSemaphoreHandleDesc.handle.win32.handle = (HANDLE)exportInfos.semaphore;
1210 externalSemaphoreHandleDesc.flags = 0;
1212 cudaImportExternalSemaphore(&synthesisSem->sem, &externalSemaphoreHandleDesc);
1213 synthesisSem->isValid =
true;
1217void RaytrixStreamer::destroySemaphore(
Semaphore* sem)
const
1219 cudaSetDevice(vulkanGPU);
1223void RaytrixStreamer::startStreaming()
1227 for (
auto& stream : readStreams)
1229 if (!stream.importedColor || !stream.importedDepth)
1231 throw HvtResult::HVT_ERROR_CALL_ORDER;
1237 std::cout <<
"Starting streaming" << std::endl;
1238 streamingThread = std::thread([&]
1239 { streamingLoop(); });
1244 gpuErrchk(cudaSetDevice(vulkanGPU));
1247 throw HvtResult::HVT_ERROR_WRONG_BUFFER_SIZE;
1250 swapPendingToReading();
1252 auto imageIndex = slotReadingIndex;
1256 gpuErrchk(cudaEventSynchronize(cudaEvents[i]));
1258 auto& stream = readStreams.at(i);
1261 desc.intrinsics = stream.intrinsics;
1262 desc.imageIndex = imageIndex;
1266void RaytrixStreamer::releaseStreamsFrames(
Semaphore* waitSem)
1268 std::cout <<
"release frames" << std::endl;
1271void RaytrixStreamer::stopStreaming()
1273 cudaSetDevice(vulkanGPU);
1275 if (streamingThread.joinable())
1277 streamingThread.join();
1285template <
typename Closure>
1286HvtResult exceptionFirewall(Closure&& clos)
1292 catch (HvtResult res)
1296 catch (
const std::exception& e)
1298 std::cerr <<
"Catched exception at C boundary : \"" << e.what() <<
"\"" << std::endl;
1299 return HvtResult::HVT_ERROR_UNKNOWN;
1303 return HvtResult::HVT_ERROR_UNKNOWN;
1305 return HvtResult::HVT_SUCESS;
1308template <
typename T>
1309void checkNonNull(T ptr)
1313 throw HvtResult::HVT_ERROR_INVALID_HANDLE;
1328 HVTAPI_ATTR HvtResult HVTAPI_CALL hvtCreateStreamingContext(
const HvtStreamingContextCreateInfo* createInfo, HvtStreamingContext* outStreamingContext)
1331 return exceptionFirewall([&]
1333 checkNonNull(createInfo);
1336 throw HvtResult::HVT_ERROR_HEADER_VERSION;
1340 *outStreamingContext = context->to_handle(); });
1350 HVTAPI_ATTR HvtResult HVTAPI_CALL hvtEnumerateStreamsParameters(HvtStreamingContext streamingContext, uint32_t* pStreamParameterCount,
HvtRGBDStreamParameters* pStreamParameters)
1353 return exceptionFirewall([&]
1355 auto context = RaytrixStreamer::check(streamingContext);
1356 checkNonNull(pStreamParameterCount);
1357 context->enumerateStreamsParameters(pStreamParameterCount, pStreamParameters); });
1366 HVTAPI_ATTR HvtResult HVTAPI_CALL hvtExportStreamImages(HvtStreamingContext streamingContext,
const HvtStreamImagesExportInfo* exportInfos)
1369 return exceptionFirewall([&]
1371 auto context = RaytrixStreamer::check(streamingContext);
1372 checkNonNull(exportInfos);
1373 context->importStreamImages(*exportInfos); });
1383 HVTAPI_ATTR HvtResult HVTAPI_CALL hvtExportSemaphore(HvtStreamingContext streamingContext,
const HvtSemaphoreExportInfo* exportInfo, HvtSemaphore* outSemaphore)
1386 return exceptionFirewall([&]
1388 auto context = RaytrixStreamer::check(streamingContext);
1389 checkNonNull(exportInfo);
1390 context->importSemaphore(*exportInfo); });
1399 HVTAPI_ATTR HvtResult HVTAPI_CALL hvtDestroySemaphore(HvtStreamingContext streamingContext, HvtSemaphore semaphore)
1402 return exceptionFirewall([&]
1404 auto context = RaytrixStreamer::check(streamingContext);
1405 context->destroySemaphore(Semaphore::check(semaphore)); });
1413 HVTAPI_ATTR HvtResult HVTAPI_CALL hvtStartStreaming(HvtStreamingContext streamingContext)
1416 return exceptionFirewall([&]
1418 auto context = RaytrixStreamer::check(streamingContext);
1419 context->startStreaming(); });
1428 HVTAPI_ATTR HvtResult HVTAPI_CALL hvtAcquireStreamsFrames(HvtStreamingContext streamingContext,
const HvtAcquireStreamFramesInfo* infos)
1431 return exceptionFirewall([&]
1433 auto context = RaytrixStreamer::check(streamingContext);
1434 context->acquireStreamsFrames(*infos); });
1446 HVTAPI_ATTR HvtResult HVTAPI_CALL hvtReleaseStreamsFrames(HvtStreamingContext streamingContext, HvtSemaphore waitSemaphore)
1449 return exceptionFirewall([&]
1461 HVTAPI_ATTR HvtResult HVTAPI_CALL hvtStopStreaming(HvtStreamingContext streamingContext)
1464 return exceptionFirewall([&]
1466 auto context = RaytrixStreamer::check(streamingContext);
1467 context->stopStreaming();
1476 HVTAPI_ATTR HvtResult HVTAPI_CALL hvtDestroyStreamingContext(HvtStreamingContext streamingContext)
1479 return exceptionFirewall([&]
1481 auto context = RaytrixStreamer::check(streamingContext);
HvtIntrinsicsPerspective getRxIntrinsicParams(size_t idxCam)
Get the intrinsic parameters of the camera of ID "idxCam". The intrinsic parameters are found through...
~RaytrixStreamer()
Free all the memories that were allocated during the streaming process.
HvtExtrinsics getRxExtrinsicParams(size_t idxCam)
Get the extrinsic parameters of the camera of ID "idxCam". The extrinsic parameters are found through...
float getMinDepth()
Get the minimum depth.
float getMaxDepth()
Get the maximum depth.
Rx::LFR::CImageQueue & getCamBuffer(size_t idxCam)
Get the camera buffer in the list of camera buffers.
RaytrixStreamer(const uint8_t uuid[VK_UUID_SIZE])
Launch all init functions defined in RaytrixStreamer class.
Parameters for query of the current frames infos.
HvtStreamFrameInfo * pStreamFrameInfos
Intrinsics parameters of a perspective projection.
Description of an RGBD stream.
HvtExtent2D depthResolution
HvtImageFormat colorFormat
HvtProjectionType projectionType
HvtImageFormat depthFormat
HvtExtent2D colorResolution
Export info for images of a stream.
HvtStreamImageMemoryInfo * pImages
Parameters for the creation of the Streaming context.
uint8_t graphicsDeviceUUID[VK_UUID_SIZE]
Union of possible intrinsics types data.