From f98fe1b4eca9131a22a2c7445dfd31b6da20d099 Mon Sep 17 00:00:00 2001 From: TinyOh Date: Tue, 22 Jan 2019 18:26:21 +0800 Subject: [PATCH] 2c92a2b0703ef9a37c653797b133de2a5371a5b7 --- src/mynteye/api/processor.h | 28 +++- src/mynteye/api/synthetic.cc | 290 +++++------------------------------ 2 files changed, 59 insertions(+), 259 deletions(-) diff --git a/src/mynteye/api/processor.h b/src/mynteye/api/processor.h index 09a9cf3..bf36792 100644 --- a/src/mynteye/api/processor.h +++ b/src/mynteye/api/processor.h @@ -133,18 +133,36 @@ void iterate_processors_PtoC_before( } template -void iterate_processors_CtoP_before( +void iterate_processor_PtoC_after( T processor, std::function)> fn) { - if (processor->GetParent() != nullptr) - iterate_processors_CtoP_before(processor->GetParent(), fn); + fn(processor); + auto chids = processor->GetChilds(); + for (auto it : chids) { + iterate_processor_PtoC_after(it, fn); + } +} +template +void iterate_processor_PtoC_before( + T processor, std::function)> fn) { + auto chids = processor->GetChilds(); + for (auto it : chids) { + iterate_processor_PtoC_before(it, fn); + } fn(processor); } template -void iterate_processors_CtoP_after( +void iterate_processor_CtoP_before( + T processor, std::function)> fn) { + if (processor->GetParent() != nullptr) + iterate_processor_CtoP_before(processor->GetParent(), fn); + fn(processor); +} +template +void iterate_processor_CtoP_after( T processor, std::function)> fn) { fn(processor); if (processor->GetParent() != nullptr) - iterate_processors_CtoP_after(processor->GetParent(), fn); + iterate_processor_CtoP_after(processor->GetParent(), fn); } MYNTEYE_END_NAMESPACE diff --git a/src/mynteye/api/synthetic.cc b/src/mynteye/api/synthetic.cc index 3f97ca6..54935f6 100644 --- a/src/mynteye/api/synthetic.cc +++ b/src/mynteye/api/synthetic.cc @@ -42,6 +42,7 @@ #define DISPARITY_NORM_PROC_PERIOD 0 #define POINTS_PROC_PERIOD 0 #define DEPTH_PROC_PERIOD 0 +#define ROOT_PROC_PERIOD 0 MYNTEYE_BEGIN_NAMESPACE @@ -183,21 +184,6 @@ void Synthetic::setControlDateCallbackWithStream( LOG(ERROR) << "ERROR: no suited processor for stream "<< ctr_data.stream; } -// void Synthetic::setControlDateModeWithStream( -// const struct stream_control_t& ctr_data) { -// for (auto &&it : processors_) { -// int i = 0; -// for (auto it_s : it->getTargetStreams()) { -// if (it_s.stream == ctr_data.stream) { -// it->target_streams_[i].mode = ctr_data.mode; -// return; -// } -// i++; -// } -// } -// LOG(ERROR) << "ERROR: no suited processor for stream "<< ctr_data.stream; -// } - bool Synthetic::checkControlDateWithStream(const Stream& stream) const { for (auto &&it : processors_) { for (auto it_s : it->getTargetStreams()) { @@ -209,40 +195,25 @@ bool Synthetic::checkControlDateWithStream(const Stream& stream) const { return false; } -// bool Synthetic::Supports(const Stream &stream) const { -// return checkControlDateWithStream(stream); -// } - -// Synthetic::status_mode_t Synthetic::GetStreamStatusMode( -// const Stream &stream) const { -// if (checkControlDateWithStream(stream)) { -// auto ctrData = getControlDateWithStream(stream); -// return ctrData.mode; -// } else { -// return MODE_STATUS_LAST; -// } -// } - -// void Synthetic::EnableStreamData(const Stream &stream) { -// // Activate processors of synthetic stream -// auto processor = getProcessorWithStream(stream); -// iterate_processors_CtoP_before(processor, -// [](std::shared_ptr proce){ -// auto streams = proce->getTargetStreams(); -// int act_tag = 0; -// for (unsigned int i = 0; i < proce->getStreamsSum() ; i++) { -// if (proce->target_streams_[i].mode == MODE_STATUS_DISABLE) { -// act_tag++; -// proce->target_streams_[i].mode = MODE_STATUS_ENABLE; -// } -// } -// if (act_tag > 0) { -// std::cout << proce->Name() << "active" << std::endl; -// proce->Activate(); -// } -// // std::cout < proce){ + auto streams = proce->getTargetStreams(); + int act_tag = 0; + for (unsigned int i = 0; i < proce->getStreamsSum() ; i++) { + if (proce->target_streams_[i].enabled_mode_ == MODE_LAST) { + act_tag++; + proce->target_streams_[i].enabled_mode_ = MODE_SYNTHETIC; + } + } + if (act_tag > 0 && !proce->IsActivated()) { + // std::cout << proce->Name() << " Active now" << std::endl; + proce->Activate(); + } + }); +} bool Synthetic::Supports(const Stream &stream) const { @@ -257,12 +228,23 @@ Synthetic::mode_t Synthetic::SupportsMode(const Stream &stream) const { return MODE_LAST; } -void Synthetic::EnableStreamData(const Stream &stream) { - EnableStreamData(stream, 0); -} - void Synthetic::DisableStreamData(const Stream &stream) { - DisableStreamData(stream, 0); + auto processor = getProcessorWithStream(stream); + iterate_processor_PtoC_before(processor, + [](std::shared_ptr proce){ + auto streams = proce->getTargetStreams(); + int act_tag = 0; + for (unsigned int i = 0; i < proce->getStreamsSum() ; i++) { + if (proce->target_streams_[i].enabled_mode_ == MODE_SYNTHETIC) { + act_tag++; + proce->target_streams_[i].enabled_mode_ = MODE_LAST; + } + } + if (act_tag > 0 && proce->IsActivated()) { + // std::cout << proce->Name() << "Deactive now" << std::endl; + proce->Deactivate(); + } + }); } bool Synthetic::IsStreamDataEnabled(const Stream &stream) const { @@ -349,7 +331,6 @@ api::StreamData Synthetic::GetStreamData(const Stream &stream) { auto sum = processor->getStreamsSum(); auto &&out = processor->GetOutput(); static std::shared_ptr output = nullptr; - std::cout << processor->Name() << stream <(out); @@ -469,205 +450,6 @@ bool Synthetic::IsStreamEnabledSynthetic(const Stream &stream) const { return GetStreamEnabledMode(stream) == MODE_SYNTHETIC; } -void Synthetic::EnableStreamData(const Stream &stream, std::uint32_t depth) { - if (IsStreamDataEnabled(stream)) - return; - // Activate processors of synthetic stream - - auto processor = getProcessorWithStream(stream); - for (unsigned int i = 0; i< processor->target_streams_.size(); i++) { - if (processor->target_streams_[i].stream == stream) { - processor->target_streams_[i].enabled_mode_ = MODE_SYNTHETIC; - } - } - switch (stream) { - case Stream::LEFT_RECTIFIED: { - if (!IsStreamDataEnabled(Stream::LEFT)) - break; - if (calib_model_ == CalibrationModel::PINHOLE) { - CHECK(ActivateProcessor()); -#ifdef WITH_CAM_MODELS - } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { - CHECK(ActivateProcessor()); -#endif - } else { - LOG(ERROR) << "Unknow calib model type in device: " - << calib_model_ << ", use default pinhole model"; - CHECK(ActivateProcessor()); - } - } return; - case Stream::RIGHT_RECTIFIED: { - if (!IsStreamDataEnabled(Stream::RIGHT)) - break; - if (calib_model_ == CalibrationModel::PINHOLE) { - CHECK(ActivateProcessor()); -#ifdef WITH_CAM_MODELS - } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { - CHECK(ActivateProcessor()); -#endif - } else { - LOG(ERROR) << "Unknow calib model type in device: " - << calib_model_ << ", use default pinhole model"; - CHECK(ActivateProcessor()); - } - } return; - case Stream::DISPARITY: { - EnableStreamData(Stream::LEFT_RECTIFIED, depth + 1); - EnableStreamData(Stream::RIGHT_RECTIFIED, depth + 1); - CHECK(ActivateProcessor()); - } return; - case Stream::DISPARITY_NORMALIZED: { - EnableStreamData(Stream::DISPARITY, depth + 1); - CHECK(ActivateProcessor()); - } return; - case Stream::POINTS: { - if (calib_model_ == CalibrationModel::PINHOLE) { - EnableStreamData(Stream::DISPARITY, depth + 1); - CHECK(ActivateProcessor()); -#ifdef WITH_CAM_MODELS - } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { - EnableStreamData(Stream::DEPTH, depth + 1); - CHECK(ActivateProcessor()); -#endif - } else { - LOG(ERROR) << "Unknow calib model type in device: " - << calib_model_; - } - } return; - case Stream::DEPTH: { - if (calib_model_ == CalibrationModel::PINHOLE) { - EnableStreamData(Stream::POINTS, depth + 1); - CHECK(ActivateProcessor()); -#ifdef WITH_CAM_MODELS - } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { - EnableStreamData(Stream::DISPARITY, depth + 1); - CHECK(ActivateProcessor()); -#endif - } else { - LOG(ERROR) << "Unknow calib model type in device: " - << calib_model_; - } - } return; - default: break; - } - if (depth == 0) { - LOG(WARNING) << "Enable stream data of " << stream << " failed"; - } -} - -void Synthetic::DisableStreamData(const Stream &stream, std::uint32_t depth) { - if (!IsStreamDataEnabled(stream)) - return; - // Deactivate processors of synthetic stream - auto data = getControlDateWithStream(stream); - if (data.enabled_mode_ != MODE_NATIVE) { - data.enabled_mode_ = MODE_LAST; - switch (stream) { - case Stream::LEFT_RECTIFIED: { - if (IsStreamEnabledSynthetic(Stream::DISPARITY)) { - DisableStreamData(Stream::DISPARITY, depth + 1); - } - if (IsStreamEnabledSynthetic(Stream::RIGHT_RECTIFIED)) { - DisableStreamData(Stream::RIGHT_RECTIFIED, depth + 1); - } - if (calib_model_ == CalibrationModel::PINHOLE) { - DeactivateProcessor(); -#ifdef WITH_CAM_MODELS - } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { - DeactivateProcessor(); -#endif - } else { - LOG(ERROR) << "Unknow calib model type in device: " - << calib_model_ << ", use default pinhole model"; - DeactivateProcessor(); - } - } break; - case Stream::RIGHT_RECTIFIED: { - if (IsStreamEnabledSynthetic(Stream::DISPARITY)) { - DisableStreamData(Stream::DISPARITY, depth + 1); - } - if (IsStreamEnabledSynthetic(Stream::LEFT_RECTIFIED)) { - DisableStreamData(Stream::LEFT_RECTIFIED, depth + 1); - } - if (calib_model_ == CalibrationModel::PINHOLE) { - DeactivateProcessor(); -#ifdef WITH_CAM_MODELS - } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { - DeactivateProcessor(); -#endif - } else { - LOG(ERROR) << "Unknow calib model type in device: " - << calib_model_ << ", use default pinhole model"; - DeactivateProcessor(); - } - } break; - case Stream::DISPARITY: { - if (calib_model_ == CalibrationModel::PINHOLE) { - if (IsStreamEnabledSynthetic(Stream::DISPARITY_NORMALIZED)) { - DisableStreamData(Stream::DISPARITY_NORMALIZED, depth + 1); - } - if (IsStreamEnabledSynthetic(Stream::POINTS)) { - DisableStreamData(Stream::POINTS, depth + 1); - } - DeactivateProcessor(); -#ifdef WITH_CAM_MODELS - } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { - if (IsStreamEnabledSynthetic(Stream::DISPARITY_NORMALIZED)) { - DisableStreamData(Stream::DISPARITY_NORMALIZED, depth + 1); - } - if (IsStreamEnabledSynthetic(Stream::DEPTH)) { - DisableStreamData(Stream::DEPTH, depth + 1); - } - DeactivateProcessor(); -#endif - } else { - LOG(ERROR) << "Unknow calib model type in device: " - << calib_model_; - } - } break; - case Stream::DISPARITY_NORMALIZED: { - DeactivateProcessor(); - } break; - case Stream::POINTS: { - if (calib_model_ == CalibrationModel::PINHOLE) { - if (IsStreamEnabledSynthetic(Stream::DEPTH)) { - DisableStreamData(Stream::DEPTH, depth + 1); - } - DeactivateProcessor(); -#ifdef WITH_CAM_MODELS - } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { - DeactivateProcessor(); -#endif - } else { - LOG(ERROR) << "Unknow calib model type in device: " - << calib_model_; - } - } break; - case Stream::DEPTH: { - if (calib_model_ == CalibrationModel::PINHOLE) { - DeactivateProcessor(); -#ifdef WITH_CAM_MODELS - } else if (calib_model_ == CalibrationModel::KANNALA_BRANDT) { - if (IsStreamEnabledSynthetic(Stream::POINTS)) { - DisableStreamData(Stream::POINTS, depth + 1); - } - DeactivateProcessor(); -#endif - } else { - LOG(ERROR) << "Unknow calib model type in device: " - << calib_model_; - } - } break; - default: return; - } - if (depth > 0) { - LOG(WARNING) << "Disable synthetic stream data of " << stream << " too"; - } - } else if (depth == 0) { - LOG(WARNING) << "Disable native stream data of " << stream << " failed"; - } -} - void Synthetic::InitProcessors() { std::shared_ptr rectify_processor = nullptr; #ifdef WITH_CAM_MODELS