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_SYNTHETIC_H_
|
|
|
|
#define MYNTEYE_API_SYNTHETIC_H_
|
2018-04-26 05:33:37 +03:00
|
|
|
#pragma once
|
|
|
|
|
2018-04-27 04:58:53 +03:00
|
|
|
#include <map>
|
2018-04-26 09:44:47 +03:00
|
|
|
#include <memory>
|
2018-04-27 10:47:54 +03:00
|
|
|
#include <string>
|
2018-04-26 09:44:47 +03:00
|
|
|
#include <vector>
|
2019-02-20 10:31:32 +02:00
|
|
|
#include <mutex>
|
2018-04-26 09:44:47 +03:00
|
|
|
|
2018-10-27 16:24:04 +03:00
|
|
|
#include "mynteye/api/api.h"
|
2019-01-09 10:12:43 +02:00
|
|
|
#include "mynteye/api/config.h"
|
2018-04-26 05:33:37 +03:00
|
|
|
|
|
|
|
MYNTEYE_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
class API;
|
2018-05-08 06:12:45 +03:00
|
|
|
class Plugin;
|
2018-04-26 09:44:47 +03:00
|
|
|
class Processor;
|
2019-03-02 04:08:45 +02:00
|
|
|
class RootProcessor;
|
2018-04-26 05:33:37 +03:00
|
|
|
|
2018-05-31 19:17:12 +03:00
|
|
|
struct Object;
|
|
|
|
|
2018-04-26 05:33:37 +03:00
|
|
|
class Synthetic {
|
|
|
|
public:
|
2018-04-26 09:44:47 +03:00
|
|
|
using stream_callback_t = API::stream_callback_t;
|
2019-02-21 16:21:17 +02:00
|
|
|
using stream_data_listener_t =
|
|
|
|
std::function<void(const Stream &stream, const api::StreamData &data)>;
|
2019-02-22 12:20:47 +02:00
|
|
|
using stream_switch_callback_t = API::stream_switch_callback_t;
|
2018-04-26 09:44:47 +03:00
|
|
|
|
2018-04-27 04:58:53 +03:00
|
|
|
typedef enum Mode {
|
2019-03-02 03:58:48 +02:00
|
|
|
MODE_ON, // On
|
|
|
|
MODE_OFF // Off
|
2018-04-27 04:58:53 +03:00
|
|
|
} mode_t;
|
|
|
|
|
2019-01-22 05:30:34 +02:00
|
|
|
struct stream_control_t {
|
|
|
|
Stream stream;
|
|
|
|
mode_t enabled_mode_;
|
|
|
|
stream_callback_t stream_callback;
|
|
|
|
};
|
|
|
|
|
2019-01-08 10:18:34 +02:00
|
|
|
explicit Synthetic(API *api, CalibrationModel calib_model);
|
2018-04-26 05:33:37 +03:00
|
|
|
~Synthetic();
|
|
|
|
|
2019-02-21 16:21:17 +02:00
|
|
|
void SetStreamDataListener(stream_data_listener_t listener);
|
|
|
|
|
2019-01-14 10:40:05 +02:00
|
|
|
void NotifyImageParamsChanged();
|
2018-12-20 16:08:29 +02:00
|
|
|
|
2018-04-26 09:44:47 +03:00
|
|
|
bool Supports(const Stream &stream) const;
|
|
|
|
|
2018-04-27 04:58:53 +03:00
|
|
|
void EnableStreamData(const Stream &stream);
|
|
|
|
void DisableStreamData(const Stream &stream);
|
2019-02-22 12:20:47 +02:00
|
|
|
|
|
|
|
void EnableStreamData(
|
|
|
|
const Stream &stream, stream_switch_callback_t callback, bool try_tag);
|
|
|
|
void DisableStreamData(
|
|
|
|
const Stream &stream, stream_switch_callback_t callback, bool try_tag);
|
2018-04-27 10:47:54 +03:00
|
|
|
bool IsStreamDataEnabled(const Stream &stream) const;
|
2018-04-27 04:58:53 +03:00
|
|
|
|
2018-04-26 09:44:47 +03:00
|
|
|
void SetStreamCallback(const Stream &stream, stream_callback_t callback);
|
|
|
|
bool HasStreamCallback(const Stream &stream) const;
|
|
|
|
|
|
|
|
void StartVideoStreaming();
|
|
|
|
void StopVideoStreaming();
|
|
|
|
|
|
|
|
void WaitForStreams();
|
|
|
|
|
|
|
|
api::StreamData GetStreamData(const Stream &stream);
|
|
|
|
std::vector<api::StreamData> GetStreamDatas(const Stream &stream);
|
|
|
|
|
2018-05-08 06:12:45 +03:00
|
|
|
void SetPlugin(std::shared_ptr<Plugin> plugin);
|
2018-06-04 17:09:20 +03:00
|
|
|
bool HasPlugin() const;
|
2018-05-08 06:12:45 +03:00
|
|
|
|
2019-01-22 10:21:04 +02:00
|
|
|
const struct stream_control_t getControlDateWithStream(
|
|
|
|
const Stream& stream) const;
|
|
|
|
void setControlDateCallbackWithStream(
|
|
|
|
const struct stream_control_t& ctr_data);
|
2019-01-22 05:30:34 +02:00
|
|
|
bool checkControlDateWithStream(const Stream& stream) const;
|
2019-01-22 09:46:11 +02:00
|
|
|
std::shared_ptr<Processor> getProcessorWithStream(const Stream& stream);
|
2019-01-23 11:17:08 +02:00
|
|
|
void SetDisparityComputingMethodType(
|
|
|
|
const DisparityComputingMethod &MethoType);
|
2019-01-22 05:30:34 +02:00
|
|
|
|
2018-04-26 05:33:37 +03:00
|
|
|
private:
|
2019-01-09 10:12:43 +02:00
|
|
|
void InitCalibInfo();
|
2018-04-27 04:58:53 +03:00
|
|
|
|
2018-04-27 17:35:43 +03:00
|
|
|
mode_t GetStreamEnabledMode(const Stream &stream) const;
|
|
|
|
|
2018-04-27 10:47:54 +03:00
|
|
|
void EnableStreamData(const Stream &stream, std::uint32_t depth);
|
|
|
|
void DisableStreamData(const Stream &stream, std::uint32_t depth);
|
|
|
|
|
|
|
|
void InitProcessors();
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
bool ActivateProcessor(bool tree = false);
|
|
|
|
template <class T>
|
|
|
|
bool DeactivateProcessor(bool tree = false);
|
|
|
|
|
2019-03-01 10:08:15 +02:00
|
|
|
bool OnDeviceProcess(
|
|
|
|
Object *const in, Object *const out,
|
|
|
|
std::shared_ptr<Processor> const parent);
|
2018-04-27 10:47:54 +03:00
|
|
|
bool OnRectifyProcess(
|
2019-01-22 05:23:54 +02:00
|
|
|
Object *const in, Object *const out,
|
|
|
|
std::shared_ptr<Processor> const parent);
|
2018-04-27 10:47:54 +03:00
|
|
|
bool OnDisparityProcess(
|
2019-01-22 05:23:54 +02:00
|
|
|
Object *const in, Object *const out,
|
|
|
|
std::shared_ptr<Processor> const parent);
|
2018-04-27 10:47:54 +03:00
|
|
|
bool OnDisparityNormalizedProcess(
|
2019-01-22 05:23:54 +02:00
|
|
|
Object *const in, Object *const out,
|
|
|
|
std::shared_ptr<Processor> const parent);
|
2018-04-27 10:47:54 +03:00
|
|
|
bool OnPointsProcess(
|
2019-01-22 05:23:54 +02:00
|
|
|
Object *const in, Object *const out,
|
|
|
|
std::shared_ptr<Processor> const parent);
|
2018-04-27 10:47:54 +03:00
|
|
|
bool OnDepthProcess(
|
2019-01-22 05:23:54 +02:00
|
|
|
Object *const in, Object *const out,
|
|
|
|
std::shared_ptr<Processor> const parent);
|
2018-04-27 10:47:54 +03:00
|
|
|
|
2019-03-01 10:08:15 +02:00
|
|
|
void OnDevicePostProcess(Object *const out);
|
2018-04-28 07:40:29 +03:00
|
|
|
void OnRectifyPostProcess(Object *const out);
|
|
|
|
void OnDisparityPostProcess(Object *const out);
|
|
|
|
void OnDisparityNormalizedPostProcess(Object *const out);
|
|
|
|
void OnPointsPostProcess(Object *const out);
|
|
|
|
void OnDepthPostProcess(Object *const out);
|
|
|
|
|
2019-02-21 16:21:17 +02:00
|
|
|
void NotifyStreamData(const Stream &stream, const api::StreamData &data);
|
|
|
|
|
2018-04-26 05:33:37 +03:00
|
|
|
API *api_;
|
2018-04-26 09:44:47 +03:00
|
|
|
|
2019-03-02 04:08:45 +02:00
|
|
|
std::shared_ptr<RootProcessor> processor_;
|
2019-03-02 06:46:17 +02:00
|
|
|
std::vector<std::shared_ptr<Processor>> processors_;
|
2018-05-08 06:12:45 +03:00
|
|
|
std::shared_ptr<Plugin> plugin_;
|
2019-01-08 10:18:34 +02:00
|
|
|
|
|
|
|
CalibrationModel calib_model_;
|
2019-01-09 10:12:43 +02:00
|
|
|
|
|
|
|
std::shared_ptr<IntrinsicsBase> intr_left_;
|
|
|
|
std::shared_ptr<IntrinsicsBase> intr_right_;
|
|
|
|
std::shared_ptr<Extrinsics> extr_;
|
2019-01-14 10:40:05 +02:00
|
|
|
bool calib_default_tag_;
|
2019-01-22 05:30:34 +02:00
|
|
|
|
2019-02-21 16:21:17 +02:00
|
|
|
stream_data_listener_t stream_data_listener_;
|
2019-01-22 05:30:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class SyntheticProcessorPart {
|
2019-03-01 10:08:15 +02:00
|
|
|
protected:
|
2019-01-22 05:30:34 +02:00
|
|
|
inline std::vector<Synthetic::stream_control_t> getTargetStreams() {
|
|
|
|
return target_streams_;
|
|
|
|
}
|
2019-02-11 07:38:28 +02:00
|
|
|
inline void addTargetStreams(const Synthetic::stream_control_t& strm) {
|
2019-01-22 05:30:34 +02:00
|
|
|
target_streams_.push_back(strm);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Synthetic::stream_control_t> target_streams_;
|
|
|
|
|
|
|
|
inline unsigned int getStreamsSum() {return target_streams_.size();}
|
|
|
|
friend Synthetic;
|
2018-04-26 05:33:37 +03:00
|
|
|
};
|
|
|
|
|
2018-04-27 10:47:54 +03:00
|
|
|
template <class T, class P>
|
|
|
|
std::shared_ptr<T> find_processor(const P &processor) {
|
2018-04-28 07:40:29 +03:00
|
|
|
return find_processor<T>(processor, T::NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class P>
|
|
|
|
std::shared_ptr<T> find_processor(const P &processor, const std::string &name) {
|
|
|
|
if (processor->Name() == name) {
|
2018-04-27 10:47:54 +03:00
|
|
|
return std::dynamic_pointer_cast<T>(processor);
|
|
|
|
}
|
|
|
|
auto &&childs = processor->GetChilds();
|
2018-04-28 07:40:29 +03:00
|
|
|
return find_processor<T>(std::begin(childs), std::end(childs), name);
|
2018-04-27 10:47:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class InputIt>
|
|
|
|
std::shared_ptr<T> find_processor(
|
|
|
|
InputIt first, InputIt last, const std::string &name) {
|
|
|
|
if (first == last)
|
|
|
|
return nullptr;
|
|
|
|
for (auto it = first; it != last; ++it) {
|
|
|
|
if ((*it)->Name() == name) {
|
|
|
|
return std::dynamic_pointer_cast<T>(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto it = first; it != last; ++it) {
|
|
|
|
auto &&childs = (*it)->GetChilds();
|
|
|
|
if (childs.empty())
|
|
|
|
continue;
|
|
|
|
auto &&result =
|
|
|
|
find_processor<T>(std::begin(childs), std::end(childs), name);
|
|
|
|
if (result == nullptr)
|
|
|
|
continue;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
bool Synthetic::ActivateProcessor(bool parents) {
|
|
|
|
auto &&processor = find_processor<T>(processor_);
|
|
|
|
if (processor == nullptr)
|
|
|
|
return false;
|
|
|
|
processor->Activate(parents);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
bool Synthetic::DeactivateProcessor(bool childs) {
|
|
|
|
auto &&processor = find_processor<T>(processor_);
|
|
|
|
if (processor == nullptr)
|
|
|
|
return false;
|
|
|
|
processor->Deactivate(childs);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-26 05:33:37 +03:00
|
|
|
MYNTEYE_END_NAMESPACE
|
|
|
|
|
2018-10-27 16:24:04 +03:00
|
|
|
#endif // MYNTEYE_API_SYNTHETIC_H_
|
2019-01-22 05:30:34 +02:00
|
|
|
|