From 05c5c1f23867b5885a7a8674ff3c570b635e8e34 Mon Sep 17 00:00:00 2001 From: John Zhao Date: Sat, 5 Jan 2019 23:16:14 +0800 Subject: [PATCH] refactor(types): protected calib model member --- include/mynteye/types.h | 13 +++++++++---- src/mynteye/api/api.cc | 2 +- src/mynteye/api/processor/rectify_processor.cc | 4 ++-- src/mynteye/device/channel/bytes.cc | 8 ++++---- src/mynteye/device/channel/file_channel.cc | 4 +--- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/mynteye/types.h b/include/mynteye/types.h index ddb63b7..a6fd97c 100644 --- a/include/mynteye/types.h +++ b/include/mynteye/types.h @@ -417,16 +417,21 @@ inline std::ostream &operator<<(std::ostream &os, struct MYNTEYE_API IntrinsicsBase { IntrinsicsBase() { - calib_model = CalibrationModel::UNKNOW; + calib_model_ = CalibrationModel::UNKNOW; } virtual ~IntrinsicsBase() {} /** The calibration model */ - CalibrationModel calib_model; + CalibrationModel calib_model() const { + return calib_model_; + } /** The width of the image in pixels */ std::uint16_t width; /** The height of the image in pixels */ std::uint16_t height; + + protected: + CalibrationModel calib_model_; }; /** @@ -435,7 +440,7 @@ struct MYNTEYE_API IntrinsicsBase { */ struct MYNTEYE_API IntrinsicsPinhole : public IntrinsicsBase { IntrinsicsPinhole() { - calib_model = CalibrationModel::PINHOLE; + calib_model_ = CalibrationModel::PINHOLE; } /** The focal length of the image plane, as a multiple of pixel width */ double fx; @@ -465,7 +470,7 @@ using Intrinsics = IntrinsicsPinhole; */ struct MYNTEYE_API IntrinsicsEquidistant : public IntrinsicsBase { IntrinsicsEquidistant() { - calib_model = CalibrationModel::KANNALA_BRANDT; + calib_model_ = CalibrationModel::KANNALA_BRANDT; } /** The distortion coefficients: k2,k3,k4,k5,mu,mv,u0,v0 */ double coeffs[8]; diff --git a/src/mynteye/api/api.cc b/src/mynteye/api/api.cc index e6986f6..1299bdb 100644 --- a/src/mynteye/api/api.cc +++ b/src/mynteye/api/api.cc @@ -296,7 +296,7 @@ std::string API::GetInfo(const Info &info) const { IntrinsicsPinhole API::GetIntrinsics(const Stream &stream) const { auto in = GetIntrinsicsBase(stream); - if (in->calib_model == CalibrationModel::PINHOLE) { + if (in->calib_model() == CalibrationModel::PINHOLE) { return *std::dynamic_pointer_cast(in); } throw std::runtime_error("Intrinsics is not pinhole model" diff --git a/src/mynteye/api/processor/rectify_processor.cc b/src/mynteye/api/processor/rectify_processor.cc index 334575a..09d1e4e 100644 --- a/src/mynteye/api/processor/rectify_processor.cc +++ b/src/mynteye/api/processor/rectify_processor.cc @@ -43,12 +43,12 @@ std::string RectifyProcessor::Name() { void RectifyProcessor::NotifyImageParamsChanged() { auto in_left = device_->GetIntrinsics(Stream::LEFT); auto in_right = device_->GetIntrinsics(Stream::RIGHT); - if (in_left->calib_model == CalibrationModel::PINHOLE) { + if (in_left->calib_model() == CalibrationModel::PINHOLE) { InitParams( *std::dynamic_pointer_cast(in_left), *std::dynamic_pointer_cast(in_right), device_->GetExtrinsics(Stream::RIGHT, Stream::LEFT)); - } else if (in_left->calib_model == + } else if (in_left->calib_model() == CalibrationModel::KANNALA_BRANDT) { InitParams( *std::dynamic_pointer_cast(in_left), diff --git a/src/mynteye/device/channel/bytes.cc b/src/mynteye/device/channel/bytes.cc index b84c66f..b0624f9 100644 --- a/src/mynteye/device/channel/bytes.cc +++ b/src/mynteye/device/channel/bytes.cc @@ -32,7 +32,7 @@ std::string _from_data(const std::uint8_t *data, std::size_t count) { std::size_t from_data(IntrinsicsBase *in, const std::uint8_t *data, bool get_size) { - switch (in->calib_model) { + switch (in->calib_model()) { case CalibrationModel::PINHOLE: return from_data(dynamic_cast(in), data, get_size); @@ -40,7 +40,7 @@ std::size_t from_data(IntrinsicsBase *in, const std::uint8_t *data, return from_data(dynamic_cast(in), data, get_size); default: - LOG(FATAL) << "Unknown calib model: " << in->calib_model; + LOG(FATAL) << "Unknown calib model: " << in->calib_model(); } } @@ -163,7 +163,7 @@ std::size_t _to_data(std::string value, std::uint8_t *data, std::size_t count) { std::size_t to_data(const IntrinsicsBase *in, std::uint8_t *data, bool set_size) { - switch (in->calib_model) { + switch (in->calib_model()) { case CalibrationModel::PINHOLE: return to_data(dynamic_cast(in), data, set_size); @@ -171,7 +171,7 @@ std::size_t to_data(const IntrinsicsBase *in, std::uint8_t *data, return to_data(dynamic_cast(in), data, set_size); default: - LOG(FATAL) << "Unknown calib model: " << in->calib_model; + LOG(FATAL) << "Unknown calib model: " << in->calib_model(); } } diff --git a/src/mynteye/device/channel/file_channel.cc b/src/mynteye/device/channel/file_channel.cc index f24df2c..e7342d0 100644 --- a/src/mynteye/device/channel/file_channel.cc +++ b/src/mynteye/device/channel/file_channel.cc @@ -334,10 +334,8 @@ std::size_t ImgParamsParser::GetFromData_new( i += bytes::from_data(in_left.get(), data + i, false); i += bytes::from_data(in_right.get(), data + i, false); i += bytes::from_data(&ex_right_to_left, data + i); - in_left->calib_model = calib_model; in_left->width = width; in_left->height = height; - in_right->calib_model = calib_model; in_right->width = width; in_right->height = height; (*img_params)[{width, height}] = {true, version.to_string(), @@ -369,7 +367,7 @@ std::size_t ImgParamsParser::SetToData_new( for (auto &&entry : *img_params) { auto &¶ms = entry.second; // calib_model, 1 - data[i] = static_cast(params.in_left->calib_model); + data[i] = static_cast(params.in_left->calib_model()); i += 1; // width, 2 bytes::_to_data(params.in_left->width, data + i);