MYNT-EYE-S-SDK/include/mynteye/device/callbacks.h

152 lines
3.4 KiB
C
Raw Normal View History

2018-05-10 09:46:34 +03:00
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2018-10-27 16:24:04 +03:00
#ifndef MYNTEYE_DEVICE_CALLBACKS_H_
#define MYNTEYE_DEVICE_CALLBACKS_H_
2018-04-06 04:12:09 +03:00
#pragma once
2018-04-08 07:23:33 +03:00
#include <cstdint>
2018-04-08 17:35:49 +03:00
#include <algorithm>
2018-04-06 04:12:09 +03:00
#include <functional>
#include <map>
2018-04-08 07:23:33 +03:00
#include <memory>
#include <vector>
2018-04-06 04:12:09 +03:00
#include "mynteye/mynteye.h"
#include "mynteye/types.h"
MYNTEYE_BEGIN_NAMESPACE
namespace device {
typedef struct ImgParams {
bool ok;
std::shared_ptr<IntrinsicsBase> in_left;
std::shared_ptr<IntrinsicsBase> in_right;
Extrinsics ex_right_to_left;
} img_params_t;
typedef struct ImuParams {
bool ok;
ImuIntrinsics in_accel;
ImuIntrinsics in_gyro;
Extrinsics ex_left_to_imu;
} imu_params_t;
2018-05-16 05:31:31 +03:00
/**
* @ingroup datatypes
* Frame with raw data.
*/
2018-04-23 18:11:11 +03:00
class MYNTEYE_API Frame {
2018-04-08 07:23:33 +03:00
public:
using data_t = std::vector<std::uint8_t>;
2018-05-16 05:31:31 +03:00
/**
* Construct the frame with StreamRequest and raw data.
*/
2018-04-08 07:23:33 +03:00
Frame(const StreamRequest &request, const void *data)
: Frame(request.width, request.height, request.format, data) {}
2018-05-16 05:31:31 +03:00
/**
* Construct the frame with stream info and raw data.
*/
2018-04-08 07:23:33 +03:00
Frame(
std::uint16_t width, std::uint16_t height, Format format,
const void *data)
: width_(width), height_(height), format_(format) {
2018-04-08 17:35:49 +03:00
std::size_t bytes_n = (width * height) * bytes_per_pixel(format);
if (data) {
const std::uint8_t *bytes = static_cast<const std::uint8_t *>(data);
data_ = data_t(bytes, bytes + bytes_n);
} else {
data_.assign(bytes_n, 0);
}
2018-04-08 07:23:33 +03:00
}
2018-05-16 05:31:31 +03:00
/** Get the width. */
2018-04-08 07:23:33 +03:00
std::uint16_t width() const {
return width_;
}
2018-05-16 05:31:31 +03:00
/** Get the height. */
2018-04-08 07:23:33 +03:00
std::uint16_t height() const {
return height_;
}
2018-05-16 05:31:31 +03:00
/** Get the format. */
2018-04-08 07:23:33 +03:00
Format format() const {
return format_;
}
2018-05-16 05:31:31 +03:00
/** Get the data. */
2018-04-08 17:35:49 +03:00
std::uint8_t *data() {
return data_.data();
}
2018-05-16 05:31:31 +03:00
/** Get the const data. */
2018-04-08 17:35:49 +03:00
const std::uint8_t *data() const {
return data_.data();
}
2018-05-16 05:31:31 +03:00
/** Get the size of data. */
2018-04-08 17:35:49 +03:00
std::size_t size() const {
return data_.size();
}
2018-05-16 05:31:31 +03:00
/** Clone a new frame. */
2018-04-08 17:35:49 +03:00
Frame clone() const {
Frame frame(width_, height_, format_, nullptr);
std::copy(data_.begin(), data_.end(), frame.data_.begin());
return frame;
2018-04-08 07:23:33 +03:00
}
private:
std::uint16_t width_;
std::uint16_t height_;
Format format_;
data_t data_;
};
2018-05-16 05:31:31 +03:00
/**
* @ingroup datatypes
* Device stream data.
*/
2018-04-06 04:12:09 +03:00
struct MYNTEYE_API StreamData {
2018-05-16 05:31:31 +03:00
/** ImgData. */
2018-04-08 17:35:49 +03:00
std::shared_ptr<ImgData> img;
2018-05-16 05:31:31 +03:00
/** Frame. */
2018-04-08 07:23:33 +03:00
std::shared_ptr<Frame> frame;
2018-10-26 10:39:34 +03:00
/** Frame ID. */
std::uint16_t frame_id;
2018-04-06 04:12:09 +03:00
};
2018-05-16 05:31:31 +03:00
/**
* @ingroup datatypes
* Device motion data.
*/
2018-04-06 04:12:09 +03:00
struct MYNTEYE_API MotionData {
2018-05-16 05:31:31 +03:00
/** ImuData. */
2018-04-08 17:35:49 +03:00
std::shared_ptr<ImuData> imu;
2018-04-06 04:12:09 +03:00
};
using StreamCallback = std::function<void(const StreamData &data)>;
using MotionCallback = std::function<void(const MotionData &data)>;
} // namespace device
MYNTEYE_END_NAMESPACE
2018-10-27 16:24:04 +03:00
#endif // MYNTEYE_DEVICE_CALLBACKS_H_