From 191ba733b14c2bf7e213563b6ffd900513c6d821 Mon Sep 17 00:00:00 2001 From: feixyz10 Date: Sat, 27 Feb 2021 17:55:29 +0800 Subject: [PATCH] add factory ... --- common/macro/macros.h | 23 +++++++++-------------- common/math/fitting.h | 14 -------------- common/pcl/pcl_utils.h | 3 +-- common/registerer/registerer.cc | 0 common/registerer/registerer.h | 19 +++++++++++++++++++ common/time/timer.cc | 4 ++++ common/time/timer.h | 4 +--- 7 files changed, 34 insertions(+), 33 deletions(-) create mode 100644 common/registerer/registerer.cc create mode 100644 common/registerer/registerer.h diff --git a/common/macro/macros.h b/common/macro/macros.h index b7108ec..96a2e1f 100644 --- a/common/macro/macros.h +++ b/common/macro/macros.h @@ -12,18 +12,13 @@ classname &operator=(const classname &) = delete; // adapted form baidu apollo cyber/common/macros.h -#define DECLARE_SINGLETON(classname) \ - public: \ - static classname *Instance() { \ - static std::unique_ptr instance{nullptr}; \ - if (!instance) { \ - static std::once_flag flag; \ - std::call_once(flag, \ - [&] { instance.reset(new (std::nothrow) classname()); }); \ - } \ - return instance.get(); \ - } \ - \ - private: \ - classname() = default; \ +#define DECLARE_SINGLETON(classname) \ + public: \ + static classname *Instance() { \ + static classname instance; \ + return &instance; \ + } \ + \ + private: \ + classname() = default; \ DISALLOW_COPY_AND_ASSIGN(classname) diff --git a/common/math/fitting.h b/common/math/fitting.h index 9c2e756..ebd7030 100644 --- a/common/math/fitting.h +++ b/common/math/fitting.h @@ -74,18 +74,4 @@ Eigen::Vector4d FitPlane(const pcl::PointCloud &cloud, return coeffs; } -// template -// Eigen::Vector4d FitPlane(const pcl::PointCloud &cloud) { -// Eigen::MatrixX3f A(cloud.size(), 3); // NOLINT -// Eigen::VectorXf b(cloud.size()); -// b.setConstant(-1.0); -// size_t i = 0; -// for (const auto &p : cloud) { -// A.row(i++) << p.x, p.y, p.z; -// } -// Eigen::Vector3f sol = A.colPivHouseholderQr().solve(b); -// Eigen::Vector4d coeff(sol(0), sol(1), sol(2), 1.0); -// return coeff / sol.norm(); -// } - } // namespace common \ No newline at end of file diff --git a/common/pcl/pcl_utils.h b/common/pcl/pcl_utils.h index fe64b4c..9ff213b 100644 --- a/common/pcl/pcl_utils.h +++ b/common/pcl/pcl_utils.h @@ -62,7 +62,6 @@ template inline void TransformPointCloud(const Pose3d &pose, const pcl::PointCloud &cloud_in, pcl::PointCloud *const cloud_out) { - ACHECK(cloud_out); pcl::transformPointCloud(cloud_in, *cloud_out, pose.TransMat().cast()); } @@ -78,7 +77,7 @@ void RemovePoints(const pcl::PointCloud &cloud_in, } size_t j = 0; for (size_t i = 0; i < cloud_in.size(); ++i) { - const auto pt = cloud_in.points[i]; + const auto &pt = cloud_in.points[i]; if (check(pt)) { if (removed_indices) removed_indices->push_back(i); continue; diff --git a/common/registerer/registerer.cc b/common/registerer/registerer.cc new file mode 100644 index 0000000..e69de29 diff --git a/common/registerer/registerer.h b/common/registerer/registerer.h new file mode 100644 index 0000000..ccf8205 --- /dev/null +++ b/common/registerer/registerer.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include +#include + +#include "common/log/log.h" +#include "common/macro/macros.h" + +template +class AbstractFactory { + virtual ~AbstractFactory() = default; + virtual std::shared_ptr Create() = 0; +}; + +template +class ConcreteFactory { + virtual std::shared_ptr Create() = 0; +}; \ No newline at end of file diff --git a/common/time/timer.cc b/common/time/timer.cc index 057ae25..45c8305 100644 --- a/common/time/timer.cc +++ b/common/time/timer.cc @@ -4,6 +4,10 @@ namespace common { +void Timer::Tic() { + start_ = std::chrono::system_clock::now(); +} + double Timer::Toc(char unit) { ACHECK(unit == 's' || unit == 'm' || unit == 'u') << "Only 's'(second), 'm'(millisecond) and 'u'(microsecond) are " diff --git a/common/time/timer.h b/common/time/timer.h index 833f2b3..5e66930 100644 --- a/common/time/timer.h +++ b/common/time/timer.h @@ -13,9 +13,7 @@ class Timer { Tic(); } - void Tic() { - start_ = std::chrono::system_clock::now(); - } + void Tic(); // unit: 's' = second, 'm' = millisecond, 'u' = microsecond double Toc(char unit = 'm');