21namespace fs = std::filesystem;
23#define HVT_ENTRY_ATTR __declspec(dllexport)
25#include <experimental/filesystem>
26namespace fs = std::experimental::filesystem;
30#define HVT_FUNCTION_PROTOTYPES
31#include "HvtStreamingAPI.h"
43#include "Rx.Core\RxException.h"
44#include "Rx.FileIO\Rx.FileIO.Image.h"
45#include "Rx.LFR/LightFieldRuntime.h"
46#include "Rx.LFR/CameraServer.h"
47#include "Rx.LFR/CalibrationManager.h"
48#include "Rx.LFR/Cuda.h"
49#include "Rx.LFR/CudaCompute.h"
50#include "Rx.LFR/ImageQueue.h"
51#include "Rx.LFR\RayFileReader.h"
52#include "Rx.Core/EDepthFillAlgo.h"
53#include "Rx.Core/EDepthAlgo.h"
54#include "Rx.Core/EColorMap.h"
55#include "Rx.LFR/RayFileWriter.h"
56#include "Rx.LFR/SeqFileReader.h"
57#include "Rx.LFR/SeqFileWriter.h"
58#include "Rx.Interop.Runtime30/CameraProperties.h"
62#include <cuda_runtime.h>
66#include "KernelCuda.cuh"
67#include "nlohmann/json.hpp"
70#define VK_UUID_SIZE 16U
73enum class HvtHandleType
79template <
typename OurType,
typename HvtHandle, HvtHandleType htype>
83 static constexpr HvtHandleType staticType = htype;
85 static OurType* check(HvtHandle hvtHandle)
88 if (h && staticType == h->type)
90 return static_cast<OurType*
>(h);
94 throw HvtResult::HVT_ERROR_INVALID_HANDLE;
98 static OurType* opt_check(HvtHandle hvtHandle)
104 return check(hvtHandle);
107 HvtHandle to_handle()
109 return reinterpret_cast<HvtHandle
>(
this);
116struct Semaphore :
public Handle<Semaphore, HvtSemaphore, HvtHandleType::SEMAPHORE>
118 cudaExternalSemaphore_t sem;
141 void destroySemaphore(
Semaphore* sem)
const;
142 void startStreaming();
144 void releaseStreamsFrames(
Semaphore* waitSem);
145 void stopStreaming();
180 static constexpr auto numSlots = 3;
181 using Clock = std::chrono::steady_clock;
187 cudaSurfaceObject_t cuda_ptr_surf;
188 HVT_OPAQUE_HANDLE* vk_handle;
194 size_t colorFrameStride;
195 size_t colorFrameSize;
196 size_t depthFrameStride;
197 size_t depthFrameSize;
199 HvtProjectionType projectionType;
203 HvtImageFormat colorFormat;
204 HvtImageFormat depthFormat;
213 std::array<ImageSlot, numSlots> colorSlots;
214 std::array<ImageSlot, numSlots> depthSlots;
215 bool importedColor =
false;
216 bool importedDepth =
false;
218 Clock::duration framePeriod;
220 int streamedFrame = -1;
227 int frameIndex(Clock::duration time)
const;
233 bool nextFrameReady(Clock::duration time)
const;
243 bool forceRGBResolution =
false;
245 bool forceDepthResolution =
false;
247 unsigned int width = 0;
249 unsigned int height = 0;
251 unsigned int widthDepth = 0;
253 unsigned int heightDepth = 0;
255 unsigned int* uIDs =
nullptr;
257 Rx::CRxString filenameComputeParameters = Rx::CRxString();
259 bool loadFromRawFile =
false;
261 Rx::CRxString* filenameRawFiles =
nullptr;
263 bool specificCal =
false;
265 Rx::CRxString* GUIDsCalib =
nullptr;
267 float* exposureCams =
nullptr;
269 std::string extrinsicParamsPath = std::string();
282 void streamingLoop();
288 void uploadFrame(
size_t streamId, ReadStream& stream);
292 void swapStreamingToPending();
296 void swapPendingToReading();
304 void readInfoFromJSON();
313 void findVulkanGPU(
const uint8_t uuid[VK_UUID_SIZE]);
317 void initStreamParameters();
321 void initRxCudaCompute();
329 void initArrayCuda();
333 void initRxRayFile();
355 void getRGBDFormats();
360 void launchAsyncLoader(
bool needToWaitthreadToFinish =
false);
365 void asyncLoaderImage();
370 void asyncLoaderImageOneCam(
size_t idxCam);
374 void asyncLoaderImageFromSeqFiles();
379 void asyncLoaderImageFromOneSeqFile(
size_t idxCam);
381 std::mutex* loaderMtxs;
383 std::condition_variable* loaderCVs;
389 std::condition_variable syncCV;
391 bool imgsLoaded =
false;
407 template<
typename T>
void writeInFileWindow(T* dataCorrect, T* dataDebug,
size_t width,
size_t height,
size_t sizeWindow,
int numCam = 0);
412 void debugFloatDepth();
418 std::vector<ReadStream> readStreams;
419 std::atomic_bool running =
false;
420 std::thread streamingThread;
421 uint32_t slotReadingIndex = 0;
422 uint32_t slotPendingIndex = 1;
423 uint32_t slotStreamingIndex = 2;
424 std::atomic_bool newDataInPending =
false;
425 std::mutex indicesMutex;
426 std::mutex queueMutex;
427 float numFrames = 0.0f;
432 cudaStream_t* cudaStreams;
434 cudaEvent_t* cudaEvents;
438 Rx::LFR::CCalibration** camCalibrations;
440 Rx::LFR::CCameraServer xCamServer;
442 Rx::LFR::CCudaCompute* xCudaComputes;
444 unsigned short** imgRGB, ** imgDepth;
446 uchar** finalRGB, ** imgUByteRGB;
448 float** finalDepth, ** imgFloatDepth, **prevFinalDepth;
450 Rx::LFR::CImageQueue* camBuffers;
452 const Rx::Interop::Runtime30::Camera::ETriggerMode::ID camCaptureMode = Rx::Interop::Runtime30::Camera::ETriggerMode::Camera_FreeRun;
454 const unsigned uBufferSize = 1;
456 const bool bOverwrite =
true;
458 Rx::CRxImage* capturedImages;
460 Rx::CRxImageFormat* imgFormatRGB, * imgFormatDepth;
462 bool isFormatLoaded =
false;
464 Rx::LFR::CRayImage* rayImages;
466 Rx::LFR::CSeqFileReader* seqReaders;
468 size_t* pitchInCudaRGB, * pitchInCudaDepth;
470 float* referencePlaneToCameraPlane;
472 size_t widthDefault = 3840, heightDefault = 2160;
474 const size_t channelDepth = 2;
476 const double MAX_TIME_BETWEEN_CAMS = 1000.0;
478 const int MAX_TIME_WAIT_BUFFER = 1000;
480 const char* ENV_NAME =
"HVT_RXDLL_PARAMS_PATH";
482 const Rx::LFR::EImage::ID idRGB = Rx::LFR::EImage::TotalFocus_View_Virtual, idDepth = Rx::LFR::EImage::Depth3D_ViewVirtualUndistorted_To_Reference;
484 const Rx::LF::ESpace::ID idSpaceRGB = Rx::LF::ESpace::View_VirtualUndistorted;
486 const Rx::LF::ESpace::ID idSpaceDepth3D[2] = { idSpaceRGB, Rx::LF::ESpace::Reference};
492 char* printMsg = NULL;
494 unsigned int whereToAddMsg;
496 const int SIZE_MSG = 1000;
498 std::chrono::steady_clock::time_point beginAvgStreaming;
500 std::chrono::steady_clock::time_point endStreaming;
507 void addMsgToPrint(
const char* title,
long long int averageTime,
float frameNumber);
511 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.
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.