diff --git a/CMakeLists.txt b/CMakeLists.txt index 06d7b5a..0bce18b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,6 +142,11 @@ if(WITH_API) src/api/api.cc src/api/synthetic.cc src/api/processor/processor.cc + src/api/processor/rectify_processor.cc + src/api/processor/disparity_processor.cc + src/api/processor/disparity_normalized_processor.cc + src/api/processor/depth_processor.cc + src/api/processor/points_processor.cc ) endif() diff --git a/src/api/api.cc b/src/api/api.cc index 614f94b..fed52bb 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -148,6 +148,10 @@ void API::WaitForStreams() { synthetic_->WaitForStreams(); } +void API::EnableStreamData(const Stream &stream) { + synthetic_->EnableStreamData(stream); +} + api::StreamData API::GetStreamData(const Stream &stream) { return synthetic_->GetStreamData(stream); } diff --git a/src/api/api.h b/src/api/api.h index d226e70..4954831 100644 --- a/src/api/api.h +++ b/src/api/api.h @@ -78,6 +78,7 @@ class MYNTEYE_API API { void WaitForStreams(); + void EnableStreamData(const Stream &stream); api::StreamData GetStreamData(const Stream &stream); std::vector GetStreamDatas(const Stream &stream); diff --git a/src/api/processor/depth_processor.cc b/src/api/processor/depth_processor.cc new file mode 100644 index 0000000..3c6e12a --- /dev/null +++ b/src/api/processor/depth_processor.cc @@ -0,0 +1,30 @@ +#include "api/processor/depth_processor.h" + +#include + +MYNTEYE_BEGIN_NAMESPACE + +DepthProcessor::DepthProcessor() : Processor() { + VLOG(2) << __func__; +} + +DepthProcessor::~DepthProcessor() { + VLOG(2) << __func__; +} + +std::string DepthProcessor::Name() { + return NAME; +} + +Object *DepthProcessor::OnCreateOutput() { + return nullptr; +} + +void DepthProcessor::OnProcess( + Object *const in, Object *const out, Processor *const parent) { + UNUSED(in) + UNUSED(out) + UNUSED(parent) +} + +MYNTEYE_END_NAMESPACE diff --git a/src/api/processor/depth_processor.h b/src/api/processor/depth_processor.h new file mode 100644 index 0000000..616cc76 --- /dev/null +++ b/src/api/processor/depth_processor.h @@ -0,0 +1,28 @@ +#ifndef MYNTEYE_DEPTH_PROCESSOR_H_ // NOLINT +#define MYNTEYE_DEPTH_PROCESSOR_H_ +#pragma once + +#include + +#include "api/processor/processor.h" + +MYNTEYE_BEGIN_NAMESPACE + +class DepthProcessor : public Processor { + public: + static constexpr auto &&NAME = "DepthProcessor"; + + DepthProcessor(); + virtual ~DepthProcessor(); + + std::string Name() override; + + protected: + Object *OnCreateOutput() override; + void OnProcess( + Object *const in, Object *const out, Processor *const parent) override; +}; + +MYNTEYE_END_NAMESPACE + +#endif // MYNTEYE_DEPTH_PROCESSOR_H_ NOLINT diff --git a/src/api/processor/disparity_normalized_processor.cc b/src/api/processor/disparity_normalized_processor.cc new file mode 100644 index 0000000..57bdd63 --- /dev/null +++ b/src/api/processor/disparity_normalized_processor.cc @@ -0,0 +1,30 @@ +#include "api/processor/disparity_normalized_processor.h" + +#include + +MYNTEYE_BEGIN_NAMESPACE + +DisparityNormalizedProcessor::DisparityNormalizedProcessor() : Processor() { + VLOG(2) << __func__; +} + +DisparityNormalizedProcessor::~DisparityNormalizedProcessor() { + VLOG(2) << __func__; +} + +std::string DisparityNormalizedProcessor::Name() { + return NAME; +} + +Object *DisparityNormalizedProcessor::OnCreateOutput() { + return nullptr; +} + +void DisparityNormalizedProcessor::OnProcess( + Object *const in, Object *const out, Processor *const parent) { + UNUSED(in) + UNUSED(out) + UNUSED(parent) +} + +MYNTEYE_END_NAMESPACE diff --git a/src/api/processor/disparity_normalized_processor.h b/src/api/processor/disparity_normalized_processor.h new file mode 100644 index 0000000..f218cb8 --- /dev/null +++ b/src/api/processor/disparity_normalized_processor.h @@ -0,0 +1,28 @@ +#ifndef MYNTEYE_DISPARITY_NORMALIZED_PROCESSOR_H_ // NOLINT +#define MYNTEYE_DISPARITY_NORMALIZED_PROCESSOR_H_ +#pragma once + +#include + +#include "api/processor/processor.h" + +MYNTEYE_BEGIN_NAMESPACE + +class DisparityNormalizedProcessor : public Processor { + public: + static constexpr auto &&NAME = "DisparityNormalizedProcessor"; + + DisparityNormalizedProcessor(); + virtual ~DisparityNormalizedProcessor(); + + std::string Name() override; + + protected: + Object *OnCreateOutput() override; + void OnProcess( + Object *const in, Object *const out, Processor *const parent) override; +}; + +MYNTEYE_END_NAMESPACE + +#endif // MYNTEYE_DISPARITY_NORMALIZED_PROCESSOR_H_ NOLINT diff --git a/src/api/processor/disparity_processor.cc b/src/api/processor/disparity_processor.cc new file mode 100644 index 0000000..642bc32 --- /dev/null +++ b/src/api/processor/disparity_processor.cc @@ -0,0 +1,30 @@ +#include "api/processor/disparity_processor.h" + +#include + +MYNTEYE_BEGIN_NAMESPACE + +DisparityProcessor::DisparityProcessor() : Processor() { + VLOG(2) << __func__; +} + +DisparityProcessor::~DisparityProcessor() { + VLOG(2) << __func__; +} + +std::string DisparityProcessor::Name() { + return NAME; +} + +Object *DisparityProcessor::OnCreateOutput() { + return nullptr; +} + +void DisparityProcessor::OnProcess( + Object *const in, Object *const out, Processor *const parent) { + UNUSED(in) + UNUSED(out) + UNUSED(parent) +} + +MYNTEYE_END_NAMESPACE diff --git a/src/api/processor/disparity_processor.h b/src/api/processor/disparity_processor.h new file mode 100644 index 0000000..b0e96d3 --- /dev/null +++ b/src/api/processor/disparity_processor.h @@ -0,0 +1,28 @@ +#ifndef MYNTEYE_DISPARITY_PROCESSOR_H_ // NOLINT +#define MYNTEYE_DISPARITY_PROCESSOR_H_ +#pragma once + +#include + +#include "api/processor/processor.h" + +MYNTEYE_BEGIN_NAMESPACE + +class DisparityProcessor : public Processor { + public: + static constexpr auto &&NAME = "DisparityProcessor"; + + DisparityProcessor(); + virtual ~DisparityProcessor(); + + std::string Name() override; + + protected: + Object *OnCreateOutput() override; + void OnProcess( + Object *const in, Object *const out, Processor *const parent) override; +}; + +MYNTEYE_END_NAMESPACE + +#endif // MYNTEYE_DISPARITY_PROCESSOR_H_ NOLINT diff --git a/src/api/processor/points_processor.cc b/src/api/processor/points_processor.cc new file mode 100644 index 0000000..9b8c500 --- /dev/null +++ b/src/api/processor/points_processor.cc @@ -0,0 +1,30 @@ +#include "api/processor/points_processor.h" + +#include + +MYNTEYE_BEGIN_NAMESPACE + +PointsProcessor::PointsProcessor() : Processor() { + VLOG(2) << __func__; +} + +PointsProcessor::~PointsProcessor() { + VLOG(2) << __func__; +} + +std::string PointsProcessor::Name() { + return NAME; +} + +Object *PointsProcessor::OnCreateOutput() { + return nullptr; +} + +void PointsProcessor::OnProcess( + Object *const in, Object *const out, Processor *const parent) { + UNUSED(in) + UNUSED(out) + UNUSED(parent) +} + +MYNTEYE_END_NAMESPACE diff --git a/src/api/processor/points_processor.h b/src/api/processor/points_processor.h new file mode 100644 index 0000000..636bf84 --- /dev/null +++ b/src/api/processor/points_processor.h @@ -0,0 +1,28 @@ +#ifndef MYNTEYE_POINTS_PROCESSOR_H_ // NOLINT +#define MYNTEYE_POINTS_PROCESSOR_H_ +#pragma once + +#include + +#include "api/processor/processor.h" + +MYNTEYE_BEGIN_NAMESPACE + +class PointsProcessor : public Processor { + public: + static constexpr auto &&NAME = "PointsProcessor"; + + PointsProcessor(); + virtual ~PointsProcessor(); + + std::string Name() override; + + protected: + Object *OnCreateOutput() override; + void OnProcess( + Object *const in, Object *const out, Processor *const parent) override; +}; + +MYNTEYE_END_NAMESPACE + +#endif // MYNTEYE_POINTS_PROCESSOR_H_ NOLINT diff --git a/src/api/processor/rectify_processor.cc b/src/api/processor/rectify_processor.cc new file mode 100644 index 0000000..ae9fff4 --- /dev/null +++ b/src/api/processor/rectify_processor.cc @@ -0,0 +1,30 @@ +#include "api/processor/rectify_processor.h" + +#include + +MYNTEYE_BEGIN_NAMESPACE + +RectifyProcessor::RectifyProcessor() : Processor() { + VLOG(2) << __func__; +} + +RectifyProcessor::~RectifyProcessor() { + VLOG(2) << __func__; +} + +std::string RectifyProcessor::Name() { + return NAME; +} + +Object *RectifyProcessor::OnCreateOutput() { + return nullptr; +} + +void RectifyProcessor::OnProcess( + Object *const in, Object *const out, Processor *const parent) { + UNUSED(in) + UNUSED(out) + UNUSED(parent) +} + +MYNTEYE_END_NAMESPACE diff --git a/src/api/processor/rectify_processor.h b/src/api/processor/rectify_processor.h new file mode 100644 index 0000000..2896477 --- /dev/null +++ b/src/api/processor/rectify_processor.h @@ -0,0 +1,28 @@ +#ifndef MYNTEYE_RECTIFY_PROCESSOR_H_ // NOLINT +#define MYNTEYE_RECTIFY_PROCESSOR_H_ +#pragma once + +#include + +#include "api/processor/processor.h" + +MYNTEYE_BEGIN_NAMESPACE + +class RectifyProcessor : public Processor { + public: + static constexpr auto &&NAME = "RectifyProcessor"; + + RectifyProcessor(); + virtual ~RectifyProcessor(); + + std::string Name() override; + + protected: + Object *OnCreateOutput() override; + void OnProcess( + Object *const in, Object *const out, Processor *const parent) override; +}; + +MYNTEYE_END_NAMESPACE + +#endif // MYNTEYE_RECTIFY_PROCESSOR_H_ NOLINT diff --git a/src/api/synthetic.cc b/src/api/synthetic.cc index 90f12e0..f12d2da 100644 --- a/src/api/synthetic.cc +++ b/src/api/synthetic.cc @@ -2,21 +2,91 @@ #include +#include + +#include "api/processor/depth_processor.h" +#include "api/processor/disparity_normalized_processor.h" +#include "api/processor/disparity_processor.h" +#include "api/processor/points_processor.h" #include "api/processor/processor.h" +#include "api/processor/rectify_processor.h" #include "device/device.h" MYNTEYE_BEGIN_NAMESPACE Synthetic::Synthetic(API *api) : api_(api) { VLOG(2) << __func__; + CHECK_NOTNULL(api_); + InitStreamSupports(); } Synthetic::~Synthetic() { VLOG(2) << __func__; } +Synthetic::mode_t Synthetic::GetMode(const Stream &stream) const { + try { + return stream_supports_mode_.at(stream); + } catch (const std::out_of_range &e) { + return MODE_LAST; + } +} + bool Synthetic::Supports(const Stream &stream) const { - return api_->device()->Supports(stream); + return GetMode(stream) != MODE_LAST; +} + +void Synthetic::EnableStreamData(const Stream &stream) { + if (Supports(stream)) + return; + switch (stream) { + case Stream::LEFT_RECTIFIED: { + if (Supports(Stream::LEFT)) { + stream_supports_mode_[stream] = MODE_SYNTHETIC; + return; + } + } break; + case Stream::RIGHT_RECTIFIED: { + if (Supports(Stream::RIGHT)) { + stream_supports_mode_[stream] = MODE_SYNTHETIC; + return; + } + } break; + case Stream::DISPARITY: { + if (Supports(Stream::LEFT) && Supports(Stream::RIGHT)) { + stream_supports_mode_[stream] = MODE_SYNTHETIC; + return; + } + } break; + case Stream::DISPARITY_NORMALIZED: { + if ((Supports(Stream::LEFT) && Supports(Stream::RIGHT)) || + Supports(Stream::DISPARITY)) { + stream_supports_mode_[stream] = MODE_SYNTHETIC; + return; + } + } break; + case Stream::DEPTH: { + if ((Supports(Stream::LEFT) && Supports(Stream::RIGHT)) || + Supports(Stream::DISPARITY) || Supports(Stream::POINTS)) { + stream_supports_mode_[stream] = MODE_SYNTHETIC; + return; + } + } break; + case Stream::POINTS: { + if ((Supports(Stream::LEFT) && Supports(Stream::RIGHT)) || + Supports(Stream::DISPARITY)) { + stream_supports_mode_[stream] = MODE_SYNTHETIC; + return; + } + } break; + default: + break; + } + LOG(WARNING) << "Enable stream data of " << stream << " failed"; +} + +void Synthetic::DisableStreamData(const Stream &stream) { + UNUSED(stream) } void Synthetic::SetStreamCallback( @@ -46,4 +116,14 @@ std::vector Synthetic::GetStreamDatas(const Stream &stream) { return {}; } +void Synthetic::InitStreamSupports() { + auto &&device = api_->device(); + for (Stream s = Stream::LEFT; s < Stream::LAST;) { + if (device->Supports(s)) { + stream_supports_mode_[s] = MODE_NATIVE; + } + s = static_cast(static_cast(s) + 1); + } +} + MYNTEYE_END_NAMESPACE diff --git a/src/api/synthetic.h b/src/api/synthetic.h index 645a934..d63a359 100644 --- a/src/api/synthetic.h +++ b/src/api/synthetic.h @@ -2,6 +2,7 @@ #define MYNTEYE_SYNTHETIC_H_ #pragma once +#include #include #include @@ -16,11 +17,21 @@ class Synthetic { public: using stream_callback_t = API::stream_callback_t; + typedef enum Mode { + MODE_NATIVE, // Native stream + MODE_SYNTHETIC, // Synthetic stream + MODE_LAST // Unsupported + } mode_t; + explicit Synthetic(API *api); ~Synthetic(); + mode_t GetMode(const Stream &stream) const; bool Supports(const Stream &stream) const; + void EnableStreamData(const Stream &stream); + void DisableStreamData(const Stream &stream); + void SetStreamCallback(const Stream &stream, stream_callback_t callback); bool HasStreamCallback(const Stream &stream) const; @@ -33,8 +44,12 @@ class Synthetic { std::vector GetStreamDatas(const Stream &stream); private: + void InitStreamSupports(); + API *api_; + std::map stream_supports_mode_; + std::vector> processors_; };