MYNT-EYE-S-SDK/include/mynteye/api/object.h

130 lines
3.2 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_API_OBJECT_H_
#define MYNTEYE_API_OBJECT_H_
2018-04-26 09:44:47 +03:00
#pragma once
#include <memory>
2018-10-27 16:24:04 +03:00
#include <opencv2/core/core.hpp>
2018-04-26 09:44:47 +03:00
#include "mynteye/mynteye.h"
MYNTEYE_BEGIN_NAMESPACE
2018-11-05 11:50:15 +02:00
struct ImgData;
2018-04-26 09:44:47 +03:00
/**
* Input & output object.
*/
2018-05-08 06:12:45 +03:00
struct MYNTEYE_API Object {
2018-04-26 09:44:47 +03:00
Object() = default;
virtual ~Object() = default;
virtual Object *Clone() const = 0;
virtual bool DecValidity() const = 0;
2018-04-26 09:44:47 +03:00
2018-05-16 05:31:31 +03:00
/** Cast the obj to T pointer */
2018-04-26 09:44:47 +03:00
template <typename T>
static T *Cast(Object *obj) {
return dynamic_cast<T *>(obj);
}
2018-05-16 05:31:31 +03:00
/** Cast the obj to const T pointer */
2018-04-26 09:44:47 +03:00
template <typename T>
static const T *Cast(const Object *obj) {
return dynamic_cast<const T *>(obj);
}
template <typename T>
static std::shared_ptr<T> Cast(const std::shared_ptr<Object> &obj) {
return std::dynamic_pointer_cast<T>(obj);
}
2018-04-26 09:44:47 +03:00
};
2018-05-16 05:31:31 +03:00
/**
* Input & output object of one cv::Mat.
*/
2018-05-08 06:12:45 +03:00
struct MYNTEYE_API ObjMat : public Object {
2018-04-26 09:44:47 +03:00
ObjMat() = default;
2018-11-05 11:50:15 +02:00
ObjMat(const cv::Mat &value, std::uint16_t id,
const std::shared_ptr<ImgData> &data)
: value(value), id(id), data(data) {}
2018-04-26 09:44:47 +03:00
2018-05-16 05:31:31 +03:00
/** The value */
2018-04-26 09:44:47 +03:00
cv::Mat value;
2018-10-26 10:39:34 +03:00
/** The id **/
std::uint16_t id;
2018-11-05 11:50:15 +02:00
/** The data **/
std::shared_ptr<ImgData> data;
2018-04-26 09:44:47 +03:00
Object *Clone() const {
ObjMat *mat = new ObjMat;
mat->value = value.clone();
2018-10-26 10:39:34 +03:00
mat->id = id;
2018-11-05 11:50:15 +02:00
mat->data = data;
2018-04-26 09:44:47 +03:00
return mat;
}
bool DecValidity() const {
return !value.empty();
}
2018-04-26 09:44:47 +03:00
};
2018-05-16 05:31:31 +03:00
/**
* Input & output object of two cv::Mat.
*/
2018-05-08 06:12:45 +03:00
struct MYNTEYE_API ObjMat2 : public Object {
2018-04-26 09:44:47 +03:00
ObjMat2() = default;
2018-10-26 10:39:34 +03:00
ObjMat2(const cv::Mat &first, std::uint16_t first_id,
2018-11-05 11:50:15 +02:00
const std::shared_ptr<ImgData> &first_data,
const cv::Mat &second, std::uint16_t second_id,
const std::shared_ptr<ImgData> &second_data)
: first(first), first_id(first_id), first_data(first_data),
second(second), second_id(second_id), second_data(second_data) {}
2018-04-26 09:44:47 +03:00
2018-05-16 05:31:31 +03:00
/** The first value */
2018-04-26 09:44:47 +03:00
cv::Mat first;
2018-10-26 10:39:34 +03:00
/** The first id **/
std::uint16_t first_id;
2018-11-05 11:50:15 +02:00
/** The first data **/
std::shared_ptr<ImgData> first_data;
2018-05-16 05:31:31 +03:00
/** The second value */
2018-04-26 09:44:47 +03:00
cv::Mat second;
2018-10-26 10:39:34 +03:00
/** The second id **/
std::uint16_t second_id;
2018-11-05 11:50:15 +02:00
/** The second data **/
std::shared_ptr<ImgData> second_data;
2018-04-26 09:44:47 +03:00
Object *Clone() const {
ObjMat2 *mat2 = new ObjMat2;
mat2->first = first.clone();
2018-10-26 10:39:34 +03:00
mat2->first_id = first_id;
2018-11-05 11:50:15 +02:00
mat2->first_data = first_data;
2018-04-26 09:44:47 +03:00
mat2->second = second.clone();
2018-10-26 10:39:34 +03:00
mat2->second_id = second_id;
2018-11-05 11:50:15 +02:00
mat2->second_data = second_data;
2018-04-26 09:44:47 +03:00
return mat2;
}
bool DecValidity() const {
return !first.empty() && !second.empty();
}
2018-04-26 09:44:47 +03:00
};
MYNTEYE_END_NAMESPACE
2018-10-27 16:24:04 +03:00
#endif // MYNTEYE_API_OBJECT_H_