RealSenseInspector.cpp
Go to the documentation of this file.
1 #include "RealSenseInspector.h"
2 
3 #define MAX_BUFFER_U16 0xFFFF
4 
5 template<typename T>
6 inline UTexture2D* Get(TUniquePtr<T>& Dtex) { return Dtex.Get() ? Dtex.Get()->GetTextureObject() : nullptr; }
7 
9 {
10  for (auto& sensor : dev.query_sensors())
11  {
12  if (auto depth = sensor.as<rs2::depth_sensor>())
13  {
14  return depth.get_depth_scale();
15  }
16  }
17  throw rs2::error("Depth not supported");
18 }
19 
20 ARealSenseInspector::ARealSenseInspector(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
21 {
22  REALSENSE_TRACE(TEXT("+ARealSenseInspector %p"), this);
23 
24  PrimaryActorTick.bCanEverTick = true;
25 
26  RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
27 
28  PclMesh = CreateDefaultSubobject<URuntimeMeshComponent>(TEXT("RuntimeMeshComponent"));
29  PclMesh->SetVisibility(false);
30  PclMesh->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
31  PclMesh->Mobility = EComponentMobility::Movable;
32 #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION >= 20
33  PclMesh->SetGenerateOverlapEvents(false);
34 #else
35  PclMesh->bGenerateOverlapEvents = false;
36 #endif
37  PclMesh->SetupAttachment(RootComponent);
38  GetDeviceDefaultProfileConfig(); // Get device profile and init Configs with proper values
39 }
40 
42 {
43  REALSENSE_TRACE(TEXT("~ARealSenseInspector %p"), this);
44 
45  Stop();
46 }
47 
49 {
50  REALSENSE_TRACE(TEXT("ARealSenseInspector::InitializeDeviceProfile %p"), this);
51  try
52  {
54  if (!Context)
55  {
56  throw std::runtime_error("GetContext failed");
57  }
58 
59  if (Context->Devices.Num() == 0)
60  {
62  if (Context->Devices.Num() == 0)
63  {
64  throw std::runtime_error("No devices available");
65  }
66  }
67 
69  if (!ActiveDevice)
70  {
71  throw std::runtime_error("Device not found");
72  }
73 
74  TArray<FRealSenseStreamProfile> depthProfiles = ActiveDevice->GetStreamProfiles(ERealSenseStreamType::STREAM_DEPTH);
75  if (depthProfiles.Num() > 0)
76  {
77  auto profile = depthProfiles[depthProfiles.Num()-1];
78  REALSENSE_TRACE(TEXT("Will initialize DEPTH profile: %dx%d @%d"), profile.Width, profile.Height, profile.Rate);
79  DepthConfig.Width = profile.Width;
80  DepthConfig.Height = profile.Height;
81  DepthConfig.Rate = profile.Rate;
82  }
83 
84  TArray<FRealSenseStreamProfile> colorProfiles = ActiveDevice->GetStreamProfiles(ERealSenseStreamType::STREAM_COLOR);
85  if (colorProfiles.Num() > 0)
86  {
87  auto profile = colorProfiles[colorProfiles.Num()-1];
88  REALSENSE_TRACE(TEXT("Will initialize COLOR profile: %dx%d @%d"), profile.Width, profile.Height, profile.Rate);
89  ColorConfig.Width = profile.Width;
90  ColorConfig.Height = profile.Height;
91  ColorConfig.Rate = profile.Rate;
92  }
93 
95  {
96  bAlignDepthToColor = false;
97  }
98 
99  TArray<FRealSenseStreamProfile> infraredProfiles = ActiveDevice->GetStreamProfiles(ERealSenseStreamType::STREAM_INFRARED);
100  if (infraredProfiles.Num() > 0)
101  {
102  auto profile = infraredProfiles[infraredProfiles.Num()-1];
103  REALSENSE_TRACE(TEXT("Will initialize INFRARED profile: %dx%d @%d"), profile.Width, profile.Height, profile.Rate);
104  InfraredConfig.Width = profile.Width;
105  InfraredConfig.Height = profile.Height;
106  InfraredConfig.Rate = profile.Rate;
107  }
108  }
109  catch (const rs2::error& ex)
110  {
111  auto what(uestr(ex.what()));
112  auto func(uestr(ex.get_failed_function()));
113  auto args(uestr(ex.get_failed_args()));
114 
115  REALSENSE_ERR(TEXT("ARealSenseInspector::GetDeviceDefaultProfileConfig exception: %s (FUNC %s ; ARGS %s ; TYPE %d"), *what, *func, *args, (int)ex.get_type());
116  }
117  catch (const std::exception& ex)
118  {
119  REALSENSE_ERR(TEXT("ARealSenseInspector::GetDeviceDefaultProfileConfig exception: %s"), ANSI_TO_TCHAR(ex.what()));
120  }
121 
122  REALSENSE_TRACE(TEXT("ARealSenseInspector::GetDeviceDefaultProfileConfig finished."));
123 }
124 
126 {
128 
129  try
130  {
131  FScopeLock Lock(&StateMx);
132 
133  REALSENSE_TRACE(TEXT("ARealSenseInspector::Start %p"), this);
134 
135  if (RsPipeline.Get() || StartedFlag)
136  {
137  throw std::runtime_error("Already started");
138  }
139 
140  PclMesh->SetVisibility(false);
141 
143  if (!Context)
144  {
145  throw std::runtime_error("GetContext failed");
146  }
147 
148  rs2::context_ref RsContext(Context->GetHandle());
149  rs2::config RsConfig;
150 
151  const bool IsPlaybackMode = (PipelineMode == ERealSensePipelineMode::PlaybackFile);
152  if (IsPlaybackMode)
153  {
154  REALSENSE_TRACE(TEXT("enable_device_from_file: %s"), *CaptureFile);
155  RsConfig.enable_device_from_file(TCHAR_TO_ANSI(*CaptureFile));
156  }
157  else
158  {
159  if (Context->Devices.Num() == 0)
160  {
162  if (Context->Devices.Num() == 0)
163  {
164  throw std::runtime_error("No devices available");
165  }
166  }
167 
169  if (!ActiveDevice)
170  {
171  throw std::runtime_error("Device not found");
172  }
173 
174  REALSENSE_TRACE(TEXT("enable_device: SN=%s"), *ActiveDevice->Serial);
175  RsConfig.enable_device(std::string(TCHAR_TO_ANSI(*ActiveDevice->Serial)));
176  }
177 
179  {
180  if (!IsPlaybackMode)
181  {
182  REALSENSE_TRACE(TEXT("enable_stream DEPTH %dx%d @%d"), DepthConfig.Width, DepthConfig.Height, DepthConfig.Rate);
183 
186 
187  if (bAlignDepthToColor)
188  {
189  RsAlign.Reset(new rs2::align(RS2_STREAM_COLOR));
190  }
191  }
192 
193  if (bEnableRawDepth)
194  {
195  // PF_G16 = DXGI_FORMAT_R16_UNORM ; A single-component, 16-bit unsigned-normalized-integer format that supports 16 bits for the red channel.
196  // PF_R16F = DXGI_FORMAT_R16_FLOAT ; A single-component, 16-bit floating-point format that supports 16 bits for the red channel.
197  // PF_R16_UINT = DXGI_FORMAT_R16_UINT ; A single-component, 16-bit unsigned-integer format that supports 16 bits for the red channel.
198  DepthRawDtex.Reset(new FDynamicTexture(TEXT("DepthRaw"), DepthConfig.Width, DepthConfig.Height, PF_G16, TextureCompressionSettings::TC_Displacementmap));
199  }
200 
202  {
203  DepthColorizedDtex.Reset(new FDynamicTexture(TEXT("DepthColorized"), DepthConfig.Width, DepthConfig.Height, PF_R8G8B8A8, TextureCompressionSettings::TC_VectorDisplacementmap));
204  }
205  }
206 
208  {
209  if (!IsPlaybackMode)
210  {
211  REALSENSE_TRACE(TEXT("enable_stream COLOR %dx%d @%d"), ColorConfig.Width, ColorConfig.Height, ColorConfig.Rate);
212 
215  }
216 
217  if (bEnableColor)
218  {
219  ColorDtex.Reset(new FDynamicTexture(TEXT("Color"), ColorConfig.Width, ColorConfig.Height, PF_R8G8B8A8, TextureCompressionSettings::TC_VectorDisplacementmap));
220  }
221  }
222 
223  if (bEnableInfrared)
224  {
225  if (!IsPlaybackMode)
226  {
227  REALSENSE_TRACE(TEXT("enable_stream INFRARED %dx%d @%d"), InfraredConfig.Width, InfraredConfig.Height, InfraredConfig.Rate);
228 
231  }
232 
233  // PF_G8 = DXGI_FORMAT_R8_UNORM ; A single-component, 8-bit unsigned-normalized-integer format that supports 8 bits for the red channel.
234  InfraredDtex.Reset(new FDynamicTexture(TEXT("Infrared"), InfraredConfig.Width, InfraredConfig.Height, PF_G8, TextureCompressionSettings::TC_Displacementmap));
235  }
236 
237  if (bEnablePcl)
238  {
239  RsPointCloud.Reset(new rs2::pointcloud());
240  RsPoints.Reset(new rs2::points());
241  }
243 
245  {
246  REALSENSE_TRACE(TEXT("enable_record_to_file: %s"), *CaptureFile);
247  RsConfig.enable_record_to_file(TCHAR_TO_ANSI(*CaptureFile));
248  }
249 
250  FlushRenderingCommands(); // wait for textures
255 
256  REALSENSE_TRACE(TEXT("Start pipeline"));
257  RsPipeline.Reset(new rs2::pipeline());
258  rs2::pipeline_profile RsProfile = RsPipeline->start(RsConfig);
259  DepthScale = GetDepthScale(RsProfile.get_device());
260  REALSENSE_TRACE(TEXT("DepthScale=%f"), DepthScale);
261  StartedFlag = true;
262 
263  REALSENSE_TRACE(TEXT("Start worker"));
264  Worker.Reset(new FRealSenseInspectorWorker(this));
265  FString ThreadName(FString::Printf(TEXT("FRealSenseInspectorWorker_%s"), *FGuid::NewGuid().ToString()));
266  Thread.Reset(FRunnableThread::Create(Worker.Get(), *ThreadName, 0, TPri_Normal));
267  if (!Thread.Get())
268  {
269  throw std::runtime_error("CreateThread failed");
270  }
271  }
272  catch (const rs2::error& ex)
273  {
274  auto what(uestr(ex.what()));
275  auto func(uestr(ex.get_failed_function()));
276  auto args(uestr(ex.get_failed_args()));
277 
278  REALSENSE_ERR(TEXT("ARealSenseInspector::Start exception: %s (FUNC %s ; ARGS %s ; TYPE %d"), *what, *func, *args, (int)ex.get_type());
279  StartedFlag = false;
280  }
281  catch (const std::exception& ex)
282  {
283  REALSENSE_ERR(TEXT("ARealSenseInspector::Start exception: %s"), ANSI_TO_TCHAR(ex.what()));
284  StartedFlag = false;
285  }
286 
287  if (!StartedFlag)
288  {
289  Stop();
290  }
291 
292  return StartedFlag ? true : false;
293 }
294 
296 {
298 
299  try
300  {
301  FScopeLock Lock(&StateMx);
302 
303  StartedFlag = false;
304 
305  if (RsPipeline.Get())
306  {
307  REALSENSE_TRACE(TEXT("Stop pipeline"));
308  try {
309  NAMED_PROFILER("rs2::pipeline::stop");
310  RsPipeline->stop();
311  }
312  catch (...) {}
313  }
314 
315  if (Thread.Get())
316  {
317  REALSENSE_TRACE(TEXT("Join thread"));
318  {
319  NAMED_PROFILER("JoinRealSenseThread");
320  Thread->WaitForCompletion();
321  }
322 
323  REALSENSE_TRACE(TEXT("Reset thread"));
324  Thread.Reset();
325  }
326 
327  Worker.Reset();
328  RsPipeline.Reset();
329  RsAlign.Reset();
330  RsPoints.Reset();
331  RsPointCloud.Reset();
332 
333  REALSENSE_TRACE(TEXT("Flush rendering commands"));
334  {
335  NAMED_PROFILER("FlushRenderingCommands");
336 
337  ENQUEUE_RENDER_COMMAND(FlushCommand)(
338  [](FRHICommandListImmediate& RHICmdList)
339  {
340  GRHICommandList.GetImmediateCommandList().ImmediateFlush(EImmediateFlushType::FlushRHIThreadFlushResources);
341  RHIFlushResources();
342  GRHICommandList.GetImmediateCommandList().ImmediateFlush(EImmediateFlushType::FlushRHIThreadFlushResources);
343  });
344  FlushRenderingCommands();
345  }
346 
347  REALSENSE_TRACE(TEXT("Destroy dynamic textures"));
348  {
349  NAMED_PROFILER("DestroyDynamicTextures");
350  DepthRawDtex.Reset();
351  DepthColorizedDtex.Reset();
352  ColorDtex.Reset();
353  InfraredDtex.Reset();
354  }
355 
356  ActiveDevice = nullptr;
357  DepthRawTexture = nullptr;
358  DepthColorizedTexture = nullptr;
359  ColorTexture = nullptr;
360  InfraredTexture = nullptr;
361  }
362  catch (const std::exception& ex)
363  {
364  REALSENSE_ERR(TEXT("ARealSenseInspector::Stop exception: %s"), ANSI_TO_TCHAR(ex.what()));
365  }
366 
367  #if defined(PROF_ENABLED)
368  Profiler::GetInstance()->LogSummary();
369  #endif
370 }
371 
373 {
374  REALSENSE_TRACE(TEXT("Enter ARealSenseInspector::ThreadProc %p"), this);
375 
376  try
377  {
378  while (StartedFlag)
379  {
380  if (bEnablePolling)
381  {
382  PollFrames();
383  }
384  else
385  {
386  WaitFrames();
387  }
388  }
389  }
390  catch (const std::exception& ex)
391  {
392  REALSENSE_ERR(TEXT("ARealSenseInspector::ThreadProc exception: %s"), ANSI_TO_TCHAR(ex.what()));
393  StartedFlag = false;
394  }
395 
396  REALSENSE_TRACE(TEXT("Leave ARealSenseInspector::ThreadProc %p"), this);
397 }
398 
400 {
401  const double t0 = FPlatformTime::Seconds();
402 
403  rs2::frameset Frameset;
404  bool GotFrames;
405 
406  try
407  {
408  NAMED_PROFILER("rs2::pipeline::poll_for_frames");
409  GotFrames = RsPipeline->poll_for_frames(&Frameset);
410  }
411  catch (const rs2::error& ex)
412  {
413  REALSENSE_TRACE(TEXT("poll_for_frames failed: %s"), ANSI_TO_TCHAR(ex.what()));
414  GotFrames = false;
415  }
416 
417  if (GotFrames)
418  {
419  ProcessFrameset(&Frameset);
420  }
421 
422  const double t1 = FPlatformTime::Seconds();
423  const double dt = t1 - t0;
424  if (dt < PollFrameRate)
425  {
426  FPlatformProcess::Sleep(PollFrameRate - dt);
427  }
428 }
429 
431 {
432  rs2::frameset Frameset;
433  bool GotFrames;
434 
435  try
436  {
437  NAMED_PROFILER("rs2::pipeline::wait_for_frames");
438  Frameset = RsPipeline->wait_for_frames((unsigned int)(WaitFrameTimeout * 1000.0f));
439  GotFrames = true;
440  }
441  catch (const rs2::error& ex)
442  {
443  REALSENSE_TRACE(TEXT("wait_for_frames failed: %s"), ANSI_TO_TCHAR(ex.what()));
444  GotFrames = false;
445  }
446 
447  if (GotFrames)
448  {
449  ProcessFrameset(&Frameset);
450  }
451 }
452 
454 {
456 
457  FScopedTryLock PclScopedMx;
458 
460  {
461  rs2::depth_frame DepthFrame = (bAlignDepthToColor && RsAlign.Get()) ? RsAlign->process(*Frameset).get_depth_frame() : Frameset->get_depth_frame();
462 
463  if (bEnableRawDepth && DepthRawDtex.Get())
464  {
465  NAMED_PROFILER("UpdateDepthRaw");
466  DepthRawDtex->Update(DepthFrame);
467  }
468 
470  {
471  NAMED_PROFILER("UpdateDepthColorized");
472  auto* Tud = DepthColorizedDtex->AllocBuffer();
474  DepthColorizedDtex->EnqueUpdateCommand(Tud);
475  }
476 
477  if (bEnablePcl && RsPointCloud.Get() && PclCalculateFlag)
478  {
479  if (PclScopedMx.TryLock(&PointCloudMx))
480  {
481  NAMED_PROFILER("rs2::pointcloud::calculate");
482  *RsPoints = RsPointCloud->calculate(DepthFrame);
483  }
484  }
485  }
486 
487  if (bEnableColor)
488  {
489  auto ColorFrame = Frameset->get_color_frame();
490 
491  if (ColorDtex.Get())
492  {
493  NAMED_PROFILER("UpdateColor");
494  ColorDtex->Update(ColorFrame);
495  }
496 
497  if (PclScopedMx.IsLocked())
498  {
499  NAMED_PROFILER("rs2::pointcloud::map_to");
500  RsPointCloud->map_to(ColorFrame);
501  }
502  }
503 
504  if (PclScopedMx.IsLocked())
505  {
506  PclScopedMx.Unlock();
508  PclCalculateFlag = false;
509  PclReadyFlag = true;
510  }
511 
512  if (bEnableInfrared && InfraredDtex.Get())
513  {
514  NAMED_PROFILER("UpdateInfrared");
515  InfraredDtex->Update(Frameset->get_infrared_frame());
516  }
517 
518  //REALSENSE_TRACE(TEXT("Frameset %d"), FramesetId);
519  FramesetId++;
520 }
521 
522 void ARealSenseInspector::Tick(float DeltaSeconds)
523 {
525 
526  Super::Tick(DeltaSeconds);
527 
528  if (bEnablePcl && PclMesh && StartedFlag)
529  {
530  PclRenderAccum += DeltaSeconds;
532  {
533  PclRenderAccum = 0;
534  PclCalculateFlag = true;
535  }
536 
537  if (PclReadyFlag)
538  {
540  if (Mx.TryLock(&PointCloudMx))
541  {
543  PclReadyFlag = false;
544  }
545  }
546  }
547  else if (PclMesh)
548  {
549  PclMesh->SetVisibility(false);
550  }
551 }
552 
554 {
556 
557  const size_t NumPoints = RsPoints->size();
558  const size_t DensityPoints = (size_t)FMath::RoundToInt(NumPoints * FMath::Clamp(PclDensity, 0.0f, 1.0f));
559  if (!DensityPoints) { PclMesh->SetVisibility(false); return; }
560 
561  const size_t Step = (size_t)FMath::RoundToInt(NumPoints / (float)DensityPoints);
562  if (!Step) { PclMesh->SetVisibility(false); return; }
563 
564  const size_t RenderPoints = (NumPoints / Step);
565  const size_t RenderVertices = RenderPoints * 4;
566  const size_t RenderIndices = RenderPoints * 6;
567  const size_t MaxBufferIndices = (MAX_BUFFER_U16 / 6) * 6;
568  const size_t NumSections = (RenderIndices / MaxBufferIndices) + (RenderIndices % MaxBufferIndices ? 1 : 0);
569 
570  #if 1
571  REALSENSE_TRACE(TEXT(
572  "PCL Id=%zu NumPoints=%zu "
573  "RenderPoints=%zu RenderVertices=%zu RenderIndices=%zu NumSections=%zu "
574  "Density=%.3f Step=%zu"),
575  PclFramesetId, NumPoints,
576  RenderPoints, RenderVertices, RenderIndices, NumSections,
577  PclDensity, Step
578  );
579  #endif
580 
581  const rs2::vertex* SrcVertices = RsPoints->get_vertices();
582  const rs2::texture_coordinate* SrcTexcoords = RsPoints->get_texture_coordinates();
583 
584  FPointCloudVertex PV[4];
585  const float Size = (PclVoxelSize * 0.5f);
586  size_t SectionId = 0;
587  size_t PointId = 0;
588  size_t VertexId = 0;
589  size_t IndexId = 0;
590  size_t NumInvalid = 0;
591 
592  while (PointId < NumPoints && SectionId < NumSections)
593  {
594  if (!PclMeshData.Contains(SectionId))
595  {
596  NAMED_PROFILER("AllocMeshSection");
597  PclMeshData.Add(SectionId, MakeUnique<FMeshSection>());
598  PclMeshData[SectionId]->PclVertices.SetNumUninitialized(MAX_BUFFER_U16, false);
599  PclMeshData[SectionId]->PclIndices.SetNumUninitialized(MAX_BUFFER_U16, false);
600  }
601 
602  if (!PclMesh->DoesSectionExist(SectionId))
603  {
604  NAMED_PROFILER("CreateMeshSection");
605  PclMesh->CreateMeshSection(SectionId, PclMeshData[SectionId]->PclVertices, PclMeshData[SectionId]->PclIndices, false, EUpdateFrequency::Frequent);
606  PclMesh->SetMaterial(SectionId, PclMaterial);
607  }
608 
609  FPointCloudVertex* DstVertices = &(PclMeshData[SectionId]->PclVertices[0]);
610  int32* DstIndices = &(PclMeshData[SectionId]->PclIndices[0]);
611  VertexId = 0;
612  IndexId = 0;
613 
614  {NAMED_PROFILER("FillMeshBuffers");
615  while (PointId < NumPoints && IndexId + 6 <= MaxBufferIndices)
616  {
617  const auto V = SrcVertices[PointId];
618  if (!V.z)
619  {
620  PointId += Step;
621  NumInvalid++;
622  continue;
623  }
624 
625  // the positive x-axis points to the right
626  // the positive y-axis points down
627  // the positive z-axis points forward
628  const FVector Pos = FVector(V.z, V.x, -V.y) * 100.0f * PclScale; // meters to mm
629 
630  PV[0].Position = FVector(Pos.X, Pos.Y - Size, Pos.Z - Size);
631  PV[1].Position = FVector(Pos.X, Pos.Y - Size, Pos.Z + Size);
632  PV[2].Position = FVector(Pos.X, Pos.Y + Size, Pos.Z + Size);
633  PV[3].Position = FVector(Pos.X, Pos.Y + Size, Pos.Z - Size);
634 
635  PV[0].Normal = FVector(-1, 0, 0);
636  PV[1].Normal = FVector(-1, 0, 0);
637  PV[2].Normal = FVector(-1, 0, 0);
638  PV[3].Normal = FVector(-1, 0, 0);
639 
640  PV[0].Tangent = FVector(0, 0, 1);
641  PV[1].Tangent = FVector(0, 0, 1);
642  PV[2].Tangent = FVector(0, 0, 1);
643  PV[3].Tangent = FVector(0, 0, 1);
644 
645  const auto T = SrcTexcoords[PointId];
646  PV[0].UV0 = FVector2D(T.u, T.v);
647  PV[1].UV0 = FVector2D(T.u, T.v);
648  PV[2].UV0 = FVector2D(T.u, T.v);
649  PV[3].UV0 = FVector2D(T.u, T.v);
650 
651  DstVertices[0] = PV[0];
652  DstVertices[1] = PV[1];
653  DstVertices[2] = PV[2];
654  DstVertices[3] = PV[3];
655 
656  DstIndices[0] = VertexId + 0;
657  DstIndices[1] = VertexId + 2;
658  DstIndices[2] = VertexId + 1;
659  DstIndices[3] = VertexId + 0;
660  DstIndices[4] = VertexId + 3;
661  DstIndices[5] = VertexId + 2;
662 
663  DstVertices += 4;
664  DstIndices += 6;
665  VertexId += 4;
666  IndexId += 6;
667  PointId += Step;
668  }}
669 
670  if (IndexId > 0)
671  {
672  #if 0
673  REALSENSE_TRACE(TEXT("section id=%zu points=%zu vert=%zu ind=%zu total=%zu invalid=%zu"),
674  SectionId, VertexId / 4, VertexId, IndexId, PointId, NumInvalid);
675  #endif
676 
677  NAMED_PROFILER("UpdateMeshSection");
678  PclMeshData[SectionId]->PclVertices.SetNumUninitialized(VertexId, false);
679  PclMeshData[SectionId]->PclIndices.SetNumUninitialized(IndexId, false);
680  PclMesh->UpdateMeshSection(SectionId, PclMeshData[SectionId]->PclVertices, PclMeshData[SectionId]->PclIndices); // TODO: SLOW AS HELL
681  PclMesh->SetMeshSectionVisible(SectionId, true);
682 
683  SectionId++;
684  }
685  }
686 
687  const auto NumMeshSections = PclMesh->GetNumSections();
688  if (NumMeshSections > SectionId)
689  {
690  for (size_t i = SectionId; i < NumMeshSections; ++i)
691  {
692  //REALSENSE_TRACE(TEXT("hide id=%zu"), i);
693  PclMesh->SetMeshSectionVisible(i, false);
694  }
695  }
696 
697  //REALSENSE_TRACE(TEXT("total=%zu invalid=%zu"), PointId, NumInvalid);
698  PclMesh->SetVisibility(SectionId != 0);
699 }
700 
701 void ARealSenseInspector::SetPointCloudMaterial(int SectionId, UMaterialInterface* Material)
702 {
703  PclMaterial = Material;
704  if (PclMesh)
705  {
706  for (auto i = 0; i < PclMesh->GetNumSections(); ++i)
707  {
708  PclMesh->SetMaterial(i, Material);
709  }
710  }
711 }
712 
714 {
715  FRealSenseStreamProfile Profile;
716  Profile.StreamType = StreamType;
717  Profile.Format = Format;
718  Profile.Width = Mode.Width;
719  Profile.Height = Mode.Height;
720  Profile.Rate = Mode.Rate;
721 
722  if (!Device->SupportsProfile(Profile))
723  {
724  throw std::runtime_error("Profile not supported");
725  }
726 }
void EnsureProfileSupported(class URealSenseDevice *Device, ERealSenseStreamType StreamType, ERealSenseFormatType Format, FRealSenseStreamMode Mode)
class URealSenseDevice * GetDeviceById(int Id)
std::vector< sensor > query_sensors() const
Definition: rs_device.hpp:25
ERealSenseStreamType StreamType
static IRealSensePlugin & Get()
UTexture2D * DepthRawTexture
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Definition: glext.h:9721
TUniquePtr< class FDynamicTexture > DepthColorizedDtex
double dt
Definition: boing.c:106
virtual class URealSenseContext * GetContext()=0
FCriticalSection PointCloudMx
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Definition: glext.h:9721
ERealSensePipelineMode PipelineMode
virtual void Tick(float DeltaSeconds) override
GLint GLint GLsizei GLsizei GLsizei depth
Mode
Definition: monitors.c:40
GLsizei const GLchar *const * string
#define REALSENSE_ERR(Format,...)
Definition: Shared.h:16
TUniquePtr< class rs2::pipeline > RsPipeline
float GetDepthScale(rs2::device dev)
UTexture2D * DepthColorizedTexture
TMap< int32, TUniquePtr< FMeshSection > > PclMeshData
depth_frame get_depth_frame() const
Definition: rs_frame.hpp:1006
void Unlock()
Definition: Shared.h:57
int Mx
Definition: rmse.py:55
video_frame get_color_frame() const
Definition: rs_frame.hpp:1015
const std::string & get_failed_args() const
Definition: rs_types.hpp:117
FRealSenseStreamMode ColorConfig
GLdouble f
#define MAX_BUFFER_U16
TUniquePtr< class rs2::align > RsAlign
TUniquePtr< class FDynamicTexture > ColorDtex
#define SCOPED_PROFILER
Definition: Rs2Base.h:32
TUniquePtr< class rs2::pointcloud > RsPointCloud
FCriticalSection StateMx
class URealSenseContext * Context
FRealSenseStreamMode InfraredConfig
void SetPointCloudMaterial(int SectionId, UMaterialInterface *Material)
UTexture2D * Get(TUniquePtr< T > &Dtex)
FRealSenseStreamMode DepthConfig
bool TryLock(FCriticalSection *Mutex)
Definition: Shared.h:56
#define NAMED_PROFILER(name)
Definition: Rs2Base.h:31
void ProcessFrameset(class rs2::frameset *Frameset)
rs2_exception_type get_type() const
Definition: rs_types.hpp:122
ERealSenseDepthColormap DepthColormap
ERealSenseFormatType
GLenum func
class URuntimeMeshComponent * PclMesh
device get_device() const
Definition: rs_pipeline.hpp:83
UTexture2D * InfraredTexture
TUniquePtr< class FRealSenseInspectorWorker > Worker
TUniquePtr< class FDynamicTexture > InfraredDtex
ERealSenseStreamType
volatile int PclCalculateFlag
friend class FRealSenseInspectorWorker
TArray< class URealSenseDevice * > Devices
#define REALSENSE_TRACE(Format,...)
Definition: Shared.h:21
class URealSenseDevice * FindDeviceBySerial(FString Serial)
video_frame get_infrared_frame(const size_t index=0) const
Definition: rs_frame.hpp:1032
int i
bool IsLocked() const
Definition: Shared.h:58
FString uestr(const char *str)
Definition: Shared.h:38
TArray< FRealSenseStreamProfile > GetStreamProfiles(ERealSenseStreamType StreamType)
ERealSenseFormatType Format
void colorize_depth(depth_pixel *dst, const rs2::video_frame &depth, int colormap_id, float depth_min, float depth_max, float depth_units, bool equalize)
class UMaterialInterface * PclMaterial
class URealSenseDevice * ActiveDevice
TUniquePtr< class rs2::points > RsPoints
Definition: threads.c:40
const std::string & get_failed_function() const
Definition: rs_types.hpp:112
TUniquePtr< class FDynamicTexture > DepthRawDtex
bool SupportsProfile(FRealSenseStreamProfile Profile)
struct rs2_context * GetHandle()


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:39