2018-04-26 05:33:37 +03:00
|
|
|
#ifndef MYNTEYE_SYNTHETIC_H_ // NOLINT
|
|
|
|
#define MYNTEYE_SYNTHETIC_H_
|
|
|
|
#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>
|
|
|
|
|
|
|
|
#include "api/api.h"
|
2018-04-26 05:33:37 +03:00
|
|
|
|
|
|
|
MYNTEYE_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
class API;
|
2018-04-27 10:47:54 +03:00
|
|
|
class Object;
|
2018-04-26 09:44:47 +03:00
|
|
|
class Processor;
|
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;
|
|
|
|
|
2018-04-27 04:58:53 +03:00
|
|
|
typedef enum Mode {
|
|
|
|
MODE_NATIVE, // Native stream
|
|
|
|
MODE_SYNTHETIC, // Synthetic stream
|
|
|
|
MODE_LAST // Unsupported
|
|
|
|
} mode_t;
|
|
|
|
|
2018-04-26 05:33:37 +03:00
|
|
|
explicit Synthetic(API *api);
|
|
|
|
~Synthetic();
|
|
|
|
|
2018-04-26 09:44:47 +03:00
|
|
|
bool Supports(const Stream &stream) const;
|
2018-04-27 17:35:43 +03:00
|
|
|
mode_t SupportsMode(const Stream &stream) const;
|
2018-04-26 09:44:47 +03:00
|
|
|
|
2018-04-27 04:58:53 +03:00
|
|
|
void EnableStreamData(const Stream &stream);
|
|
|
|
void DisableStreamData(const Stream &stream);
|
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-04-26 05:33:37 +03:00
|
|
|
private:
|
2018-04-27 04:58:53 +03:00
|
|
|
void InitStreamSupports();
|
|
|
|
|
2018-04-27 17:35:43 +03:00
|
|
|
mode_t GetStreamEnabledMode(const Stream &stream) const;
|
|
|
|
bool IsStreamEnabledNative(const Stream &stream) const;
|
|
|
|
bool IsStreamEnabledSynthetic(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);
|
|
|
|
|
2018-04-27 17:35:43 +03:00
|
|
|
void Process(const Stream &stream, const api::StreamData &data);
|
|
|
|
|
2018-04-27 10:47:54 +03:00
|
|
|
bool OnRectifyProcess(
|
|
|
|
Object *const in, Object *const out, Processor *const parent);
|
|
|
|
bool OnDisparityProcess(
|
|
|
|
Object *const in, Object *const out, Processor *const parent);
|
|
|
|
bool OnDisparityNormalizedProcess(
|
|
|
|
Object *const in, Object *const out, Processor *const parent);
|
|
|
|
bool OnPointsProcess(
|
|
|
|
Object *const in, Object *const out, Processor *const parent);
|
|
|
|
bool OnDepthProcess(
|
|
|
|
Object *const in, Object *const out, Processor *const parent);
|
|
|
|
|
2018-04-26 05:33:37 +03:00
|
|
|
API *api_;
|
2018-04-26 09:44:47 +03:00
|
|
|
|
2018-04-27 04:58:53 +03:00
|
|
|
std::map<Stream, mode_t> stream_supports_mode_;
|
2018-04-27 17:35:43 +03:00
|
|
|
std::map<Stream, mode_t> stream_enabled_mode_;
|
2018-04-27 04:58:53 +03:00
|
|
|
|
2018-04-27 10:47:54 +03:00
|
|
|
std::map<Stream, stream_callback_t> stream_callbacks_;
|
|
|
|
|
|
|
|
std::shared_ptr<Processor> processor_;
|
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) {
|
|
|
|
if (processor->Name() == T::NAME) {
|
|
|
|
return std::dynamic_pointer_cast<T>(processor);
|
|
|
|
}
|
|
|
|
auto &&childs = processor->GetChilds();
|
|
|
|
return find_processor<T>(std::begin(childs), std::end(childs), T::NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
#endif // MYNTEYE_SYNTHETIC_H_ NOLINT
|