RealSenseDevice.cpp
Go to the documentation of this file.
1 #include "RealSenseDevice.h"
2 #include "PCH.h"
4 
5 URealSenseDevice::URealSenseDevice(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
6 {
7  REALSENSE_TRACE(TEXT("+URealSenseDevice_%p"), this);
8 }
9 
11 {
12  REALSENSE_TRACE(TEXT("~URealSenseDevice_%p"), this);
13 
14  SetHandle(nullptr);
15 }
16 
18 {
20  RsDevice = Handle;
21 }
22 
24 {
25  return RsDevice;
26 }
27 
29 {
30  auto Sensor = NewNamedObject<URealSenseSensor>(this, ObjName);
31  Sensor->SetHandle(Handle);
32  return Sensor;
33 }
34 
36 {
37  Sensors.Empty();
38 
42 
44  if (List)
45  {
46  const int Count = rs2_get_sensors_count(List, &e);
47  for (int i = 0; i < Count; i++)
48  {
49  rs2_sensor* RsSensor = rs2_create_sensor(List, i, &e);
50  if (RsSensor)
51  {
52  Sensors.Add(NewSensor(RsSensor, TEXT("RealSenseSensor")));
53  }
54  }
55 
57  }
58 
59  for (auto* Sensor : Sensors)
60  {
61  Sensor->QueryData();
62  }
63 }
64 
66 {
67  URealSenseSensor* Result = nullptr;
68 
69  for (auto* Sensor : Sensors)
70  {
71  for (const auto& Profile : Sensor->StreamProfiles)
72  {
73  if (Profile.StreamType == StreamType || StreamType == ERealSenseStreamType::STREAM_ANY)
74  {
75  Result = Sensor;
76  break;
77  }
78  }
79  }
80 
81  return Result;
82 }
83 
85 {
86  TArray<FRealSenseStreamProfile> Result;
87 
88  for (auto* Sensor : Sensors)
89  {
90  for (const auto& Profile : Sensor->StreamProfiles)
91  {
92  if (Profile.StreamType == StreamType || StreamType == ERealSenseStreamType::STREAM_ANY)
93  {
94  Result.Add(Profile);
95  }
96  }
97  }
98 
99  return Result;
100 }
101 
103 {
104  for (auto* Sensor : Sensors)
105  {
106  if (Sensor->SupportsProfile(Profile))
107  {
108  return true;
109  }
110  }
111 
112  return false;
113 }
114 
115 bool URealSenseDevice::LoadPreset(const FString& FileName)
116 {
117  return LoadPreset(RsDevice, FileName);
118 }
119 
120 bool URealSenseDevice::SavePreset(const FString& FileName)
121 {
122  return SavePreset(RsDevice, FileName);
123 }
124 
125 bool URealSenseDevice::LoadPreset(rs2_device* Handle, const FString& FileName)
126 {
127  bool Result = false;
128  IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
129  IFileHandle* FileHandle = PlatformFile.OpenRead(*FileName);
130  if (!FileHandle)
131  {
132  REALSENSE_ERR(TEXT("OpenRead failed: %s"), *FileName);
133  }
134  else
135  {
136  auto Size = FileHandle->Size();
137  std::vector<uint8> Data;
138  Data.resize(Size);
139 
140  if (!FileHandle->Read(&Data[0], Size))
141  {
142  REALSENSE_ERR(TEXT("Read failed: %s Size=%u"), *FileName, (unsigned int)Size);
143  }
144  else
145  {
147  rs2_load_json(Handle, &Data[0], Size, &e);
148  if (!e.success())
149  {
150  REALSENSE_ERR(TEXT("rs2_load_json failed: %s"), ANSI_TO_TCHAR(e.get_message()));
151  }
152  else
153  {
154  Result = true;
155  }
156  }
157 
158  delete FileHandle;
159  }
160  return Result;
161 }
162 
163 bool URealSenseDevice::SavePreset(rs2_device* Handle, const FString& FileName)
164 {
165  bool Result = false;
166  IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
167  IFileHandle* FileHandle = PlatformFile.OpenWrite(*FileName);
168  if (!FileHandle)
169  {
170  REALSENSE_ERR(TEXT("OpenWrite failed: %s"), *FileName);
171  }
172  else
173  {
175  auto Buffer = rs2_serialize_json(Handle, &e);
176  if (!e.success())
177  {
178  REALSENSE_ERR(TEXT("rs2_serialize_json failed: %s"), ANSI_TO_TCHAR(e.get_message()));
179  }
180  else
181  {
182  auto Size = rs2_get_raw_data_size(Buffer, &e);
183  auto Data = rs2_get_raw_data(Buffer, &e);
184 
185  if (!FileHandle->Write(Data, Size))
186  {
187  REALSENSE_ERR(TEXT("Write failed: %s"), *FileName);
188  }
189  else
190  {
191  Result = true;
192  }
193 
194  rs2_delete_raw_data(Buffer);
195  }
196 
197  delete FileHandle;
198  }
199  return Result;
200 }
int rs2_get_sensors_count(const rs2_sensor_list *info_list, rs2_error **error)
Definition: rs.cpp:267
const char * get_message() const
rs2_sensor * rs2_create_sensor(const rs2_sensor_list *list, int index, rs2_error **error)
Definition: rs.cpp:308
void SetHandle(struct rs2_sensor *Handle)
bool SavePreset(const FString &FileName)
void rs2_delete_device(rs2_device *device)
Definition: rs.cpp:301
const unsigned char * rs2_get_raw_data(const rs2_raw_data_buffer *buffer, rs2_error **error)
Definition: rs.cpp:567
class URealSenseSensor * GetSensor(ERealSenseStreamType StreamType)
void rs2_load_json(rs2_device *dev, const void *json_content, unsigned content_size, rs2_error **error)
Definition: rs.cpp:3177
void rs2_delete_raw_data(const rs2_raw_data_buffer *buffer)
Definition: rs.cpp:581
#define REALSENSE_ERR(Format,...)
Definition: Shared.h:16
e
Definition: rmse.py:177
virtual ~URealSenseDevice()
int rs2_get_raw_data_size(const rs2_raw_data_buffer *buffer, rs2_error **error)
Definition: rs.cpp:574
rs2_raw_data_buffer * rs2_serialize_json(rs2_device *dev, rs2_error **error)
Definition: rs.cpp:3169
bool success() const
class URealSenseSensor * NewSensor(struct rs2_sensor *Handle, const TCHAR *Name)
bool LoadPreset(const FString &FileName)
UTexture2D * Get(TUniquePtr< T > &Dtex)
Definition: api.h:28
rs2_sensor_list * rs2_query_sensors(const rs2_device *device, rs2_error **error)
Definition: rs.cpp:236
ERealSenseStreamType
void SetHandle(struct rs2_context *Handle)
struct rs2_device * GetHandle()
#define REALSENSE_TRACE(Format,...)
Definition: Shared.h:21
void rs2_delete_sensor_list(rs2_sensor_list *info_list)
Definition: rs.cpp:282
int i
FString uestr(const char *str)
Definition: Shared.h:38
TArray< FRealSenseStreamProfile > GetStreamProfiles(ERealSenseStreamType StreamType)
void SetHandle(struct rs2_device *Handle)
bool SupportsProfile(FRealSenseStreamProfile Profile)
const char * rs2_get_device_info(const rs2_device *device, rs2_camera_info info, rs2_error **error)
Definition: rs.cpp:703


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