Change output of processor to smart pointer
This commit is contained in:
parent
a119b36f72
commit
d3a67b7d29
|
@ -17,6 +17,8 @@
|
|||
|
||||
#include <opencv2/core/core.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
@ -41,6 +43,11 @@ struct MYNTEYE_API Object {
|
|||
static const T *Cast(const Object *obj) {
|
||||
return dynamic_cast<const T *>(obj);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static std::shared_ptr<T> Cast(const std::shared_ptr<Object> &obj) {
|
||||
return std::dynamic_pointer_cast<T>(obj);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -139,9 +139,9 @@ bool Processor::Process(const Object &in) {
|
|||
return true;
|
||||
}
|
||||
|
||||
Object *Processor::GetOutput() {
|
||||
std::shared_ptr<Object> Processor::GetOutput() {
|
||||
std::lock_guard<std::mutex> lk(mtx_result_);
|
||||
return output_result_.get();
|
||||
return std::shared_ptr<Object>(std::move(output_result_));
|
||||
}
|
||||
|
||||
std::uint64_t Processor::GetDroppedCount() {
|
||||
|
|
|
@ -65,7 +65,7 @@ class Processor /*: public std::enable_shared_from_this<Processor>*/ {
|
|||
* Returns the last output.
|
||||
* @note Returns null if not output now.
|
||||
*/
|
||||
Object *GetOutput();
|
||||
std::shared_ptr<Object> GetOutput();
|
||||
|
||||
std::uint64_t GetDroppedCount();
|
||||
|
||||
|
|
|
@ -155,30 +155,30 @@ api::StreamData Synthetic::GetStreamData(const Stream &stream) {
|
|||
auto &&device = api_->device();
|
||||
return data2api(device->GetLatestStreamData(stream));
|
||||
} else if (mode == MODE_SYNTHETIC) {
|
||||
switch (stream) {
|
||||
case Stream::LEFT_RECTIFIED: {
|
||||
if (stream == Stream::LEFT_RECTIFIED || stream == Stream::RIGHT_RECTIFIED) {
|
||||
static std::shared_ptr<ObjMat2> output = nullptr;
|
||||
auto &&processor = find_processor<RectifyProcessor>(processor_);
|
||||
Object *out = processor->GetOutput();
|
||||
auto &&out = processor->GetOutput();
|
||||
if (out != nullptr) {
|
||||
ObjMat2 *output = Object::Cast<ObjMat2>(out);
|
||||
return {nullptr, output->first, nullptr};
|
||||
// Obtain the output, out will be nullptr if get again immediately.
|
||||
output = Object::Cast<ObjMat2>(out);
|
||||
}
|
||||
VLOG(2) << "Rectify not ready now";
|
||||
} break;
|
||||
case Stream::RIGHT_RECTIFIED: {
|
||||
auto &&processor = find_processor<RectifyProcessor>(processor_);
|
||||
Object *out = processor->GetOutput();
|
||||
if (out != nullptr) {
|
||||
ObjMat2 *output = Object::Cast<ObjMat2>(out);
|
||||
if (output != nullptr) {
|
||||
if (stream == Stream::LEFT_RECTIFIED) {
|
||||
return {nullptr, output->first, nullptr};
|
||||
} else {
|
||||
return {nullptr, output->second, nullptr};
|
||||
}
|
||||
}
|
||||
VLOG(2) << "Rectify not ready now";
|
||||
} break;
|
||||
return {};
|
||||
}
|
||||
switch (stream) {
|
||||
case Stream::DISPARITY: {
|
||||
auto &&processor = find_processor<DisparityProcessor>(processor_);
|
||||
Object *out = processor->GetOutput();
|
||||
auto &&out = processor->GetOutput();
|
||||
if (out != nullptr) {
|
||||
ObjMat *output = Object::Cast<ObjMat>(out);
|
||||
auto &&output = Object::Cast<ObjMat>(out);
|
||||
return {nullptr, output->value, nullptr};
|
||||
}
|
||||
VLOG(2) << "Disparity not ready now";
|
||||
|
@ -186,27 +186,27 @@ api::StreamData Synthetic::GetStreamData(const Stream &stream) {
|
|||
case Stream::DISPARITY_NORMALIZED: {
|
||||
auto &&processor =
|
||||
find_processor<DisparityNormalizedProcessor>(processor_);
|
||||
Object *out = processor->GetOutput();
|
||||
auto &&out = processor->GetOutput();
|
||||
if (out != nullptr) {
|
||||
ObjMat *output = Object::Cast<ObjMat>(out);
|
||||
auto &&output = Object::Cast<ObjMat>(out);
|
||||
return {nullptr, output->value, nullptr};
|
||||
}
|
||||
VLOG(2) << "Disparity normalized not ready now";
|
||||
} break;
|
||||
case Stream::POINTS: {
|
||||
auto &&processor = find_processor<PointsProcessor>(processor_);
|
||||
Object *out = processor->GetOutput();
|
||||
auto &&out = processor->GetOutput();
|
||||
if (out != nullptr) {
|
||||
ObjMat *output = Object::Cast<ObjMat>(out);
|
||||
auto &&output = Object::Cast<ObjMat>(out);
|
||||
return {nullptr, output->value, nullptr};
|
||||
}
|
||||
VLOG(2) << "Points not ready now";
|
||||
} break;
|
||||
case Stream::DEPTH: {
|
||||
auto &&processor = find_processor<DepthProcessor>(processor_);
|
||||
Object *out = processor->GetOutput();
|
||||
auto &&out = processor->GetOutput();
|
||||
if (out != nullptr) {
|
||||
ObjMat *output = Object::Cast<ObjMat>(out);
|
||||
auto &&output = Object::Cast<ObjMat>(out);
|
||||
return {nullptr, output->value, nullptr};
|
||||
}
|
||||
VLOG(2) << "Depth not ready now";
|
||||
|
|
Loading…
Reference in New Issue
Block a user