OrbbecSDK  1.5.7
OrbbecSDK: Software-Development-Kit for Orbbec 3D-Sensor devices
Frame.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include "Types.hpp"
14 
15 #include <memory>
16 #include <iostream>
17 #include <typeinfo>
18 
36 struct FrameImpl;
37 
38 namespace ob {
39 class StreamProfile;
40 class Filter;
42 
43 typedef std::function<void(void *buffer, void *context)> BufferDestroyCallback;
44 
45 class OB_EXTENSION_API Frame : public std::enable_shared_from_this<Frame> {
46 protected:
47  std::unique_ptr<FrameImpl> impl_;
48 
49 public:
50  Frame(std::unique_ptr<FrameImpl> impl);
51  Frame(Frame &frame);
52 
53  virtual ~Frame() noexcept;
65  virtual OBFrameType type();
66 
78  virtual OBFormat format();
79 
91  virtual uint64_t index();
92 
104  virtual void *data();
105 
119  virtual uint32_t dataSize();
120 
132  uint64_t timeStamp();
133 
145  uint64_t timeStampUs();
146 
158  uint64_t systemTimeStamp();
159 
173  template <typename T> bool is();
174 
188  template <typename T> std::shared_ptr<T> as() {
189  if(!is<T>())
190  throw "unsupported operation, object's type is not require type";
191 
192  return std::static_pointer_cast<T>(std::const_pointer_cast<Frame>(shared_from_this()));
193  }
194 
195 private:
196  friend class Filter;
197  friend class Recorder;
198  friend class FrameHelper;
199 };
200 
202 public:
203  VideoFrame(Frame &frame);
204  virtual ~VideoFrame() noexcept {};
205 
217  uint32_t width();
218 
230  uint32_t height();
231 
243  void *metadata();
244 
256  uint32_t metadataSize();
257 
271  uint8_t pixelAvailableBitSize();
272 };
273 
275 public:
276  ColorFrame(Frame &frame);
277  ~ColorFrame() noexcept {};
278 };
279 
281 public:
282  DepthFrame(Frame &frame);
283  ~DepthFrame() noexcept {};
284 
298  float getValueScale();
299 };
300 
302 public:
303  IRFrame(Frame &frame);
304  virtual ~IRFrame() noexcept {};
305 
306 public:
307  OBSensorType getDataSource();
308 };
309 
311 public:
312  PointsFrame(Frame &frame);
313  ~PointsFrame() noexcept {};
314 
331  float getPositionValueScale();
332 };
333 
335 
336 public:
337  // FrameSet();
338  FrameSet(Frame &frame);
339  ~FrameSet() noexcept;
340 
352  uint32_t frameCount();
353 
365  std::shared_ptr<DepthFrame> depthFrame();
366 
378  std::shared_ptr<ColorFrame> colorFrame();
379 
391  std::shared_ptr<IRFrame> irFrame();
392 
404  std::shared_ptr<PointsFrame> pointsFrame();
405 
419  std::shared_ptr<Frame> getFrame(OBFrameType frameType);
420 
421  friend class Pipeline;
422  friend class Filter;
423 };
424 
426 public:
427  AccelFrame(Frame &frame);
428  ~AccelFrame() noexcept = default;
429 
441  OBAccelValue value();
442 
454  float temperature();
455 };
456 
458 public:
459  GyroFrame(Frame &frame);
460  ~GyroFrame() noexcept = default;
461 
473  OBGyroValue value();
474 
486  float temperature();
487 };
488 
490 public:
491  FrameHelper();
492  ~FrameHelper();
503  static std::shared_ptr<Frame> createFrameFromBuffer(OBFormat format, uint32_t frameWidth, uint32_t frameHeight, uint8_t *buffer, uint32_t bufferSize,
504  BufferDestroyCallback destroyCallback, void *destroyCallbackContext);
505 
511  static std::shared_ptr<Frame> createFrameSet();
512 
520  static void pushFrame(std::shared_ptr<Frame> frameSet, OBFrameType frameType, std::shared_ptr<Frame> frame);
521 
528  static void setFrameSystemTimestamp(std::shared_ptr<Frame> frame, uint64_t systemTimestamp);
529 
536  static void setFrameDeviceTimestamp(std::shared_ptr<Frame> frame, uint64_t deviceTimestamp);
537 
544  static void setFrameDeviceTimestampUs(std::shared_ptr<Frame> frame, uint64_t deviceTimestampUs);
545 };
546 
547 template <typename T> bool Frame::is() {
548  switch(this->type()) {
549  case OB_FRAME_IR_LEFT: // follow
550  case OB_FRAME_IR_RIGHT: // follow
551  case OB_FRAME_IR:
552  return (typeid(T) == typeid(IRFrame) || typeid(T) == typeid(VideoFrame));
553  case OB_FRAME_DEPTH:
554  return (typeid(T) == typeid(DepthFrame) || typeid(T) == typeid(VideoFrame));
555  case OB_FRAME_COLOR:
556  return (typeid(T) == typeid(ColorFrame) || typeid(T) == typeid(VideoFrame));
557  case OB_FRAME_GYRO:
558  return (typeid(T) == typeid(GyroFrame));
559  case OB_FRAME_ACCEL:
560  return (typeid(T) == typeid(AccelFrame));
561  case OB_FRAME_SET:
562  return (typeid(T) == typeid(FrameSet));
563  case OB_FRAME_POINTS:
564  return (typeid(T) == typeid(PointsFrame));
565  default:
566  std::cout << "ob::Frame::is() not catch frame type: " << (int)this->type() << std::endl;
567  break;
568  }
569  return false;
570 }
571 } // namespace ob
OBFormat
Enumeration value describing the pixel format.
Definition: ObTypes.h:221
~DepthFrame() noexcept
Definition: Frame.hpp:283
Data structures for accelerometers and gyroscopes.
Definition: ObTypes.h:611
Definition: Context.hpp:20
OBSensorType
Enumeration value describing the sensor type.
Definition: ObTypes.h:159
~ColorFrame() noexcept
Definition: Frame.hpp:277
Provide SDK structure and enumeration constant definition (depending on libobsensor/h/ObTypes.h)
std::function< void(void *buffer, void *context)> BufferDestroyCallback
Definition: Frame.hpp:41
~PointsFrame() noexcept
Definition: Frame.hpp:313
OBFrameType
Describe the Frame type enumeration value.
Definition: ObTypes.h:199
bool is()
Check if the runtime type of the frame object is compatible with a given type.
Definition: Frame.hpp:547
virtual ~VideoFrame() noexcept
Definition: Frame.hpp:204
virtual ~IRFrame() noexcept
Definition: Frame.hpp:304
std::unique_ptr< FrameImpl > impl_
Definition: Frame.hpp:47
#define OB_EXTENSION_API
Definition: ObTypes.h:25