refactor(synthetic): use shared_ptr for parent_
This commit is contained in:
parent
aa83d3bf85
commit
69168303d6
|
@ -52,7 +52,7 @@ std::string Processor::Name() {
|
|||
}
|
||||
|
||||
void Processor::AddChild(const std::shared_ptr<Processor> &child) {
|
||||
child->parent_ = this;
|
||||
child->parent_ = shared_from_this();
|
||||
childs_.push_back(child);
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,8 @@ void Processor::Activate(bool parents) {
|
|||
return;
|
||||
if (parents) {
|
||||
// Activate all parents
|
||||
Processor *parent = parent_;
|
||||
auto parent = parent_;
|
||||
// Processor *parent = parent_;
|
||||
while (parent != nullptr) {
|
||||
parent->Activate();
|
||||
parent = parent->parent_;
|
||||
|
@ -97,7 +98,8 @@ void Processor::Deactivate(bool childs) {
|
|||
return;
|
||||
if (childs) {
|
||||
// Deactivate all childs
|
||||
iterate_processors(GetChilds(), [](std::shared_ptr<Processor> proc) {
|
||||
iterate_processors_PtoC_after(GetChilds(),
|
||||
[](std::shared_ptr<Processor> proc) {
|
||||
proc->Deactivate();
|
||||
});
|
||||
}
|
||||
|
@ -152,6 +154,10 @@ std::uint64_t Processor::GetDroppedCount() {
|
|||
return dropped_count_;
|
||||
}
|
||||
|
||||
std::shared_ptr<Processor> Processor::GetParent() {
|
||||
return parent_;
|
||||
}
|
||||
|
||||
void Processor::Run() {
|
||||
VLOG(2) << Name() << " thread start";
|
||||
|
||||
|
|
|
@ -23,18 +23,22 @@
|
|||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
// #include "mynteye/api/synthetic.h"
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
#include "mynteye/api/object.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
class Processor /*: public std::enable_shared_from_this<Processor>*/ {
|
||||
class Processor :
|
||||
public std::enable_shared_from_this<Processor> {
|
||||
public:
|
||||
using PreProcessCallback = std::function<void(Object *const)>;
|
||||
using PostProcessCallback = std::function<void(Object *const)>;
|
||||
using ProcessCallback = std::function<bool(
|
||||
Object *const in, Object *const out, Processor *const parent)>;
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent)>;
|
||||
|
||||
explicit Processor(std::int32_t proc_period = 0);
|
||||
virtual ~Processor();
|
||||
|
@ -45,6 +49,7 @@ class Processor /*: public std::enable_shared_from_this<Processor>*/ {
|
|||
|
||||
void RemoveChild(const std::shared_ptr<Processor> &child);
|
||||
|
||||
std::shared_ptr<Processor> GetParent();
|
||||
std::list<std::shared_ptr<Processor>> GetChilds();
|
||||
|
||||
void SetPreProcessCallback(PreProcessCallback callback);
|
||||
|
@ -71,7 +76,8 @@ class Processor /*: public std::enable_shared_from_this<Processor>*/ {
|
|||
protected:
|
||||
virtual Object *OnCreateOutput() = 0;
|
||||
virtual bool OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) = 0;
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) = 0;
|
||||
|
||||
private:
|
||||
/** Run in standalone thread. */
|
||||
|
@ -101,20 +107,44 @@ class Processor /*: public std::enable_shared_from_this<Processor>*/ {
|
|||
PostProcessCallback post_callback_;
|
||||
ProcessCallback callback_;
|
||||
|
||||
Processor *parent_;
|
||||
// Processor *parent_;
|
||||
std::shared_ptr<Processor> parent_;
|
||||
std::list<std::shared_ptr<Processor>> childs_;
|
||||
|
||||
std::thread thread_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void iterate_processors(
|
||||
void iterate_processors_PtoC_after(
|
||||
const T &processors, std::function<void(std::shared_ptr<Processor>)> fn) {
|
||||
for (auto &&proc : processors) {
|
||||
fn(proc);
|
||||
iterate_processors(proc->GetChilds(), fn);
|
||||
iterate_processors_PtoC_after(proc->GetChilds(), fn);
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
void iterate_processors_PtoC_before(
|
||||
const T &processors, std::function<void(std::shared_ptr<Processor>)> fn) {
|
||||
for (auto &&proc : processors) {
|
||||
iterate_processors_PtoC_before(proc->GetChilds(), fn);
|
||||
fn(proc);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void iterate_processors_CtoP_before(
|
||||
T processor, std::function<void(std::shared_ptr<Processor>)> fn) {
|
||||
if (processor->GetParent() != nullptr)
|
||||
iterate_processors_CtoP_before(processor->GetParent(), fn);
|
||||
fn(processor);
|
||||
}
|
||||
template <typename T>
|
||||
void iterate_processors_CtoP_after(
|
||||
T processor, std::function<void(std::shared_ptr<Processor>)> fn) {
|
||||
fn(processor);
|
||||
if (processor->GetParent() != nullptr)
|
||||
iterate_processors_CtoP_after(processor->GetParent(), fn);
|
||||
}
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
|
|
|
@ -45,7 +45,8 @@ Object *DepthProcessor::OnCreateOutput() {
|
|||
}
|
||||
|
||||
bool DepthProcessor::OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) {
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) {
|
||||
MYNTEYE_UNUSED(parent)
|
||||
const ObjMat *input = Object::Cast<ObjMat>(in);
|
||||
ObjMat *output = Object::Cast<ObjMat>(out);
|
||||
|
|
|
@ -36,7 +36,8 @@ class DepthProcessor : public Processor {
|
|||
protected:
|
||||
Object *OnCreateOutput() override;
|
||||
bool OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) override;
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) override;
|
||||
private:
|
||||
std::shared_ptr<struct camera_calib_info_pair> calib_infos_;
|
||||
};
|
||||
|
|
|
@ -39,7 +39,8 @@ Object *DepthProcessorOCV::OnCreateOutput() {
|
|||
}
|
||||
|
||||
bool DepthProcessorOCV::OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) {
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) {
|
||||
MYNTEYE_UNUSED(parent)
|
||||
const ObjMat *input = Object::Cast<ObjMat>(in);
|
||||
ObjMat *output = Object::Cast<ObjMat>(out);
|
||||
|
|
|
@ -33,7 +33,8 @@ class DepthProcessorOCV : public Processor {
|
|||
protected:
|
||||
Object *OnCreateOutput() override;
|
||||
bool OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) override;
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) override;
|
||||
};
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
|
|
@ -43,7 +43,8 @@ Object *DisparityNormalizedProcessor::OnCreateOutput() {
|
|||
}
|
||||
|
||||
bool DisparityNormalizedProcessor::OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) {
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) {
|
||||
MYNTEYE_UNUSED(parent)
|
||||
const ObjMat *input = Object::Cast<ObjMat>(in);
|
||||
ObjMat *output = Object::Cast<ObjMat>(out);
|
||||
|
|
|
@ -33,7 +33,8 @@ class DisparityNormalizedProcessor : public Processor {
|
|||
protected:
|
||||
Object *OnCreateOutput() override;
|
||||
bool OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) override;
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) override;
|
||||
};
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
|
|
@ -66,7 +66,6 @@ DisparityProcessor::DisparityProcessor(DisparityProcessorType type,
|
|||
#endif
|
||||
#ifdef WITH_BM_SOBEL_FILTER
|
||||
} else if (type_ == DisparityProcessorType::BM) {
|
||||
int bmWinSize = 3;
|
||||
#ifdef WITH_OPENCV2
|
||||
LOG(ERROR) << "not supported in opencv 2.x";
|
||||
// int bmWinSize = 3;
|
||||
|
@ -147,7 +146,8 @@ Object *DisparityProcessor::OnCreateOutput() {
|
|||
}
|
||||
|
||||
bool DisparityProcessor::OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) {
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) {
|
||||
MYNTEYE_UNUSED(parent)
|
||||
const ObjMat2 *input = Object::Cast<ObjMat2>(in);
|
||||
ObjMat *output = Object::Cast<ObjMat>(out);
|
||||
|
|
|
@ -49,7 +49,8 @@ class DisparityProcessor : public Processor {
|
|||
protected:
|
||||
Object *OnCreateOutput() override;
|
||||
bool OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) override;
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) override;
|
||||
|
||||
private:
|
||||
cv::Ptr<cv::StereoSGBM> sgbm_matcher;
|
||||
|
|
|
@ -73,7 +73,8 @@ Object *PointsProcessor::OnCreateOutput() {
|
|||
}
|
||||
|
||||
bool PointsProcessor::OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) {
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) {
|
||||
MYNTEYE_UNUSED(parent)
|
||||
|
||||
float fx = calib_infos_->left.K[0];
|
||||
|
|
|
@ -38,7 +38,8 @@ class PointsProcessor : public Processor {
|
|||
protected:
|
||||
Object *OnCreateOutput() override;
|
||||
bool OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) override;
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<struct camera_calib_info_pair> calib_infos_;
|
||||
|
|
|
@ -41,7 +41,8 @@ Object *PointsProcessorOCV::OnCreateOutput() {
|
|||
}
|
||||
|
||||
bool PointsProcessorOCV::OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) {
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) {
|
||||
MYNTEYE_UNUSED(parent)
|
||||
const ObjMat *input = Object::Cast<ObjMat>(in);
|
||||
ObjMat *output = Object::Cast<ObjMat>(out);
|
||||
|
|
|
@ -35,7 +35,8 @@ class PointsProcessorOCV : public Processor {
|
|||
protected:
|
||||
Object *OnCreateOutput() override;
|
||||
bool OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) override;
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) override;
|
||||
|
||||
private:
|
||||
cv::Mat Q_;
|
||||
|
|
|
@ -417,7 +417,8 @@ Object *RectifyProcessor::OnCreateOutput() {
|
|||
}
|
||||
|
||||
bool RectifyProcessor::OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) {
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) {
|
||||
MYNTEYE_UNUSED(parent)
|
||||
const ObjMat2 *input = Object::Cast<ObjMat2>(in);
|
||||
ObjMat2 *output = Object::Cast<ObjMat2>(out);
|
||||
|
|
|
@ -77,7 +77,8 @@ class RectifyProcessor : public Processor {
|
|||
protected:
|
||||
Object *OnCreateOutput() override;
|
||||
bool OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) override;
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) override;
|
||||
|
||||
private:
|
||||
void InitParams(IntrinsicsEquidistant in_left,
|
||||
|
|
|
@ -61,7 +61,8 @@ Object *RectifyProcessorOCV::OnCreateOutput() {
|
|||
}
|
||||
|
||||
bool RectifyProcessorOCV::OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) {
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) {
|
||||
MYNTEYE_UNUSED(parent)
|
||||
const ObjMat2 *input = Object::Cast<ObjMat2>(in);
|
||||
ObjMat2 *output = Object::Cast<ObjMat2>(out);
|
||||
|
|
|
@ -51,7 +51,8 @@ class RectifyProcessorOCV : public Processor {
|
|||
protected:
|
||||
Object *OnCreateOutput() override;
|
||||
bool OnProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) override;
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) override;
|
||||
|
||||
private:
|
||||
void InitParams(IntrinsicsPinhole in_left,
|
||||
|
|
|
@ -809,7 +809,8 @@ void Synthetic::ProcessNativeStream(
|
|||
}
|
||||
|
||||
bool Synthetic::OnRectifyProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) {
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) {
|
||||
MYNTEYE_UNUSED(parent)
|
||||
if (plugin_ && plugin_->OnRectifyProcess(in, out)) {
|
||||
return true;
|
||||
|
@ -819,7 +820,8 @@ bool Synthetic::OnRectifyProcess(
|
|||
}
|
||||
|
||||
bool Synthetic::OnDisparityProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) {
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) {
|
||||
MYNTEYE_UNUSED(parent)
|
||||
if (plugin_ && plugin_->OnDisparityProcess(in, out)) {
|
||||
return true;
|
||||
|
@ -828,7 +830,8 @@ bool Synthetic::OnDisparityProcess(
|
|||
}
|
||||
|
||||
bool Synthetic::OnDisparityNormalizedProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) {
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) {
|
||||
MYNTEYE_UNUSED(parent)
|
||||
if (plugin_ && plugin_->OnDisparityNormalizedProcess(in, out)) {
|
||||
return true;
|
||||
|
@ -837,7 +840,8 @@ bool Synthetic::OnDisparityNormalizedProcess(
|
|||
}
|
||||
|
||||
bool Synthetic::OnPointsProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) {
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) {
|
||||
MYNTEYE_UNUSED(parent)
|
||||
if (plugin_ && plugin_->OnPointsProcess(in, out)) {
|
||||
return true;
|
||||
|
@ -846,7 +850,8 @@ bool Synthetic::OnPointsProcess(
|
|||
}
|
||||
|
||||
bool Synthetic::OnDepthProcess(
|
||||
Object *const in, Object *const out, Processor *const parent) {
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent) {
|
||||
MYNTEYE_UNUSED(parent)
|
||||
if (plugin_ && plugin_->OnDepthProcess(in, out)) {
|
||||
return true;
|
||||
|
|
|
@ -88,15 +88,20 @@ class Synthetic {
|
|||
void ProcessNativeStream(const Stream &stream, const api::StreamData &data);
|
||||
|
||||
bool OnRectifyProcess(
|
||||
Object *const in, Object *const out, Processor *const parent);
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent);
|
||||
bool OnDisparityProcess(
|
||||
Object *const in, Object *const out, Processor *const parent);
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent);
|
||||
bool OnDisparityNormalizedProcess(
|
||||
Object *const in, Object *const out, Processor *const parent);
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent);
|
||||
bool OnPointsProcess(
|
||||
Object *const in, Object *const out, Processor *const parent);
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent);
|
||||
bool OnDepthProcess(
|
||||
Object *const in, Object *const out, Processor *const parent);
|
||||
Object *const in, Object *const out,
|
||||
std::shared_ptr<Processor> const parent);
|
||||
|
||||
void OnRectifyPostProcess(Object *const out);
|
||||
void OnDisparityPostProcess(Object *const out);
|
||||
|
|
Loading…
Reference in New Issue
Block a user