Improve process childs

This commit is contained in:
John Zhao 2018-06-12 22:05:47 +08:00
parent 92b38291ee
commit 24ca757c92

View File

@ -49,6 +49,15 @@ api::StreamData data2api(const device::StreamData &data) {
return {data.img, frame2mat(data.frame), data.frame}; return {data.img, frame2mat(data.frame), data.frame};
} }
void process_childs(
const std::shared_ptr<Processor> &proc, const std::string &name,
const Object &obj) {
auto &&processor = find_processor<Processor>(proc, name);
for (auto child : processor->GetChilds()) {
child->Process(obj);
}
}
} // namespace } // namespace
Synthetic::Synthetic(API *api) : api_(api), plugin_(nullptr) { Synthetic::Synthetic(API *api) : api_(api), plugin_(nullptr) {
@ -437,60 +446,50 @@ void Synthetic::InitProcessors() {
void Synthetic::ProcessNativeStream( void Synthetic::ProcessNativeStream(
const Stream &stream, const api::StreamData &data) { const Stream &stream, const api::StreamData &data) {
bool done = false; if (stream == Stream::LEFT || stream == Stream::RIGHT) {
static api::StreamData left_data, right_data; static api::StreamData left_data, right_data;
if (stream == Stream::LEFT) { if (stream == Stream::LEFT) {
left_data = data; left_data = data;
done = true;
} else if (stream == Stream::RIGHT) { } else if (stream == Stream::RIGHT) {
right_data = data; right_data = data;
done = true;
} }
if (done && left_data.img && right_data.img && if (left_data.img && right_data.img &&
left_data.img->frame_id == right_data.img->frame_id) { left_data.img->frame_id == right_data.img->frame_id) {
auto &&processor = find_processor<RectifyProcessor>(processor_); auto &&processor = find_processor<RectifyProcessor>(processor_);
processor->Process(ObjMat2{left_data.frame, right_data.frame}); processor->Process(ObjMat2{left_data.frame, right_data.frame});
} }
if (done)
return; return;
auto &&process_childs = [this, &stream](
const std::string &name, const Object &obj) {
auto &&processor = find_processor<Processor>(processor_, name);
for (auto child : processor->GetChilds()) {
child->Process(obj);
} }
};
if (stream == Stream::LEFT_RECTIFIED || stream == Stream::RIGHT_RECTIFIED) {
static api::StreamData left_rect_data, right_rect_data; static api::StreamData left_rect_data, right_rect_data;
if (stream == Stream::LEFT_RECTIFIED) { if (stream == Stream::LEFT_RECTIFIED) {
left_rect_data = data; left_rect_data = data;
done = true;
} else if (stream == Stream::RIGHT_RECTIFIED) { } else if (stream == Stream::RIGHT_RECTIFIED) {
right_rect_data = data; right_rect_data = data;
done = true;
} }
if (done && left_rect_data.img && right_rect_data.img && if (left_rect_data.img && right_rect_data.img &&
left_rect_data.img->frame_id == right_rect_data.img->frame_id) { left_rect_data.img->frame_id == right_rect_data.img->frame_id) {
process_childs( process_childs(
RectifyProcessor::NAME, processor_, RectifyProcessor::NAME,
ObjMat2{left_rect_data.frame, right_rect_data.frame}); ObjMat2{left_rect_data.frame, right_rect_data.frame});
} }
if (done)
return; return;
}
switch (stream) { switch (stream) {
case Stream::DISPARITY: { case Stream::DISPARITY: {
process_childs(DisparityProcessor::NAME, ObjMat{data.frame}); process_childs(processor_, DisparityProcessor::NAME, ObjMat{data.frame});
} break; } break;
case Stream::DISPARITY_NORMALIZED: { case Stream::DISPARITY_NORMALIZED: {
process_childs(DisparityNormalizedProcessor::NAME, ObjMat{data.frame}); process_childs(
processor_, DisparityNormalizedProcessor::NAME, ObjMat{data.frame});
} break; } break;
case Stream::POINTS: { case Stream::POINTS: {
process_childs(PointsProcessor::NAME, ObjMat{data.frame}); process_childs(processor_, PointsProcessor::NAME, ObjMat{data.frame});
} break; } break;
case Stream::DEPTH: { case Stream::DEPTH: {
process_childs(DepthProcessor::NAME, ObjMat{data.frame}); process_childs(processor_, DepthProcessor::NAME, ObjMat{data.frame});
} break; } break;
default: default:
break; break;