19namespace fs = std::filesystem;
21#define HVT_ENTRY_ATTR __declspec(dllexport)
23#include <experimental/filesystem>
24namespace fs = std::experimental::filesystem;
28#define HVT_FUNCTION_PROTOTYPES
29#include "HvtStreamingAPI.h"
41#include "Rx.Core\RxException.h"
42#include "Rx.LFR/LightFieldRuntime.h"
43#include "Rx.LFR/CameraServer.h"
44#include "Rx.LFR/CalibrationManager.h"
45#include "Rx.LFR/Cuda.h"
46#include "Rx.LFR/CudaCompute.h"
47#include "Rx.LFR/ImageQueue.h"
48#include "Rx.LFR\RayFileReader.h"
49#include "Rx.Core/EColorMap.h"
50#include "Rx.LFR/RayFileWriter.h"
51#include "Rx.LFR/SeqFileReader.h"
52#include "Rx.LFR/SeqFileWriter.h"
56#include <cuda_runtime.h>
60#include "KernelCuda.cuh"
61#include "nlohmann/json.hpp"
64#define VK_UUID_SIZE 16U
67enum class HvtHandleType
73template <
typename OurType,
typename HvtHandle, HvtHandleType htype>
77 static constexpr HvtHandleType staticType = htype;
79 static OurType* check(HvtHandle hvtHandle)
82 if (h && staticType == h->type)
84 return static_cast<OurType*
>(h);
88 throw HvtResult::HVT_ERROR_INVALID_HANDLE;
92 static OurType* opt_check(HvtHandle hvtHandle)
98 return check(hvtHandle);
101 HvtHandle to_handle()
103 return reinterpret_cast<HvtHandle
>(
this);
110struct Semaphore :
public Handle<Semaphore, HvtSemaphore, HvtHandleType::SEMAPHORE>
112 cudaExternalSemaphore_t sem;
135 void destroySemaphore(
Semaphore* sem)
const;
136 void startStreaming();
138 void releaseStreamsFrames(
Semaphore* waitSem);
139 void stopStreaming();
174 static constexpr auto numSlots = 3;
175 using Clock = std::chrono::steady_clock;
181 cudaSurfaceObject_t cuda_ptr_surf;
182 HVT_OPAQUE_HANDLE* vk_handle;
188 size_t colorFrameStride;
189 size_t colorFrameSize;
190 size_t depthFrameStride;
191 size_t depthFrameSize;
193 HvtProjectionType projectionType;
197 HvtImageFormat colorFormat;
198 HvtImageFormat depthFormat;
207 std::array<ImageSlot, numSlots> colorSlots;
208 std::array<ImageSlot, numSlots> depthSlots;
209 bool importedColor =
false;
210 bool importedDepth =
false;
212 Clock::duration framePeriod;
214 int streamedFrame = -1;
221 int frameIndex(Clock::duration time)
const;
227 bool nextFrameReady(Clock::duration time)
const;
237 bool forceRGBResolution =
false;
239 bool forceDepthResolution =
false;
241 unsigned int width = 0;
243 unsigned int height = 0;
245 unsigned int widthDepth = 0;
247 unsigned int heightDepth = 0;
249 unsigned int* uIDs =
nullptr;
251 Rx::CRxString filenameComputeParameters = Rx::CRxString();
253 bool loadFromRawFile =
false;
255 Rx::CRxString* filenameRawFiles =
nullptr;
257 bool specificCal =
false;
259 Rx::CRxString* GUIDsCalib =
nullptr;
261 float* exposureCams =
nullptr;
263 std::string extrinsicParamsPath = std::string();
276 void streamingLoop();
282 void uploadFrame(
size_t streamId, ReadStream& stream);
286 void swapStreamingToPending();
290 void swapPendingToReading();
298 void readInfoFromJSON();
307 void findVulkanGPU(
const uint8_t uuid[VK_UUID_SIZE]);
311 void initStreamParameters();
315 void initRxCudaCompute();
323 void initArrayCuda();
327 void initRxRayFile();
349 void getRGBDFormats();
354 void launchAsyncLoader(
bool needToWaitthreadToFinish =
false);
359 void asyncLoaderImage();
364 void asyncLoaderImageOneCam(
size_t idxCam);
368 void asyncLoaderImageFromSeqFiles();
373 void asyncLoaderImageFromOneSeqFile(
size_t idxCam);
375 std::mutex* loaderMtxs;
377 std::condition_variable* loaderCVs;
383 std::condition_variable syncCV;
385 bool imgsLoaded =
false;
401 template<
typename T>
void writeInFileWindow(T* dataCorrect, T* dataDebug,
size_t width,
size_t height,
size_t sizeWindow,
int numCam = 0);
406 void debugFloatDepth();
412 std::vector<ReadStream> readStreams;
413 std::atomic_bool running =
false;
414 std::thread streamingThread;
415 uint32_t slotReadingIndex = 0;
416 uint32_t slotPendingIndex = 1;
417 uint32_t slotStreamingIndex = 2;
418 std::atomic_bool newDataInPending =
false;
419 std::mutex indicesMutex;
420 std::mutex queueMutex;
421 float numFrames = 0.0f;
426 cudaStream_t* cudaStreams;
428 cudaEvent_t* cudaEvents;
432 Rx::LFR::CCalibration** camCalibrations;
434 Rx::LFR::CCameraServer xCamServer;
436 Rx::LFR::CCudaCompute* xCudaComputes;
438 unsigned short** imgRGB, ** imgDepth;
440 uchar** finalRGB, ** imgUByteRGB;
442 float** finalDepth, ** imgFloatDepth, ** prevFinalDepth;;
444 Rx::LFR::CImageQueue* camBuffers;
446 const Rx::ECamTriggerMode camCaptureMode = Rx::ECamTriggerMode::Camera_FreeRun;
448 const unsigned uBufferSize = 1;
450 const bool bOverwrite =
true;
452 Rx::CRxImage* capturedImages;
454 Rx::CRxImageFormat* imgFormatRGB, * imgFormatDepth;
456 Rx::LFR::CudaImage* cuImgs, * cuDepths;
458 bool isFormatLoaded =
false;
460 Rx::LFR::CRayImage* rayImages;
462 Rx::LFR::CSeqFileReader* seqReaders;
464 size_t* pitchInCudaRGB, * pitchInCudaDepth;
466 float* referencePlaneToCameraPlane;
468 size_t widthDefault = 3840, heightDefault = 2160;
470 const size_t channelDepth = 2;
472 const double MAX_TIME_BETWEEN_CAMS = 1000.0;
474 const int MAX_TIME_WAIT_BUFFER = 1000;
476 const char* ENV_NAME =
"HVT_RXDLL_PARAMS_PATH";
478 const Rx::LFR::EImage idRGB = Rx::LFR::EImage::TotalFocus_View_Virtual, idDepth = Rx::LFR::EImage::Depth3D_ViewVirtualUndistorted_To_Reference;
480 const Rx::ELFSpace idSpaceRGB = Rx::ELFSpace::View_VirtualUndistorted;
482 const Rx::ELFSpace idSpaceDepth3D[2] = { idSpaceRGB, Rx::ELFSpace::Reference };
487 char* printMsg = NULL;
489 unsigned int whereToAddMsg;
491 const int SIZE_MSG = 1000;
493 std::chrono::steady_clock::time_point beginAvgStreaming;
495 std::chrono::steady_clock::time_point endStreaming;
502 void addMsgToPrint(
const char* title,
long long int averageTime,
float frameNumber);
506 void resetPrintMsg();
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.
Intrinsics parameters of a perspective projection.
Description of an RGBD stream.
Export info for images of a stream.
Union of possible intrinsics types data.