Skip to content

Commit

Permalink
static code analysis (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
koide3 authored Apr 8, 2024
1 parent 47d9085 commit ff8269e
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion include/small_gicp/ann/incremental_voxelmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct IncrementalVoxelMap {

/// @brief Constructor
/// @param leaf_size Voxel size
IncrementalVoxelMap(double leaf_size) : inv_leaf_size(1.0 / leaf_size), lru_horizon(100), lru_clear_cycle(10), lru_counter(0) {}
explicit IncrementalVoxelMap(double leaf_size) : inv_leaf_size(1.0 / leaf_size), lru_horizon(100), lru_clear_cycle(10), lru_counter(0) {}

/// @brief Number of points in the voxelmap
size_t size() const { return flat_voxels.size(); }
Expand Down
10 changes: 6 additions & 4 deletions include/small_gicp/ann/kdtree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ class UnsafeKdTreeGeneric {

/// @brief Constructor
/// @param points Input points
UnsafeKdTreeGeneric(const PointCloud& points) : points(points), index(3, *this, nanoflann::KDTreeSingleIndexAdaptorParams(10)) { index.buildIndex(); }
explicit UnsafeKdTreeGeneric(const PointCloud& points) : points(points), index(3, *this, nanoflann::KDTreeSingleIndexAdaptorParams(10)) { index.buildIndex(); }

/// @brief Constructor
/// @param points Input points
/// @params num_threads Number of threads used for building the index (This argument is only valid for OMP implementation)
UnsafeKdTreeGeneric(const PointCloud& points, int num_threads) : points(points), index(3, *this, nanoflann::KDTreeSingleIndexAdaptorParams(10)) { index.buildIndex(num_threads); }
explicit UnsafeKdTreeGeneric(const PointCloud& points, int num_threads) : points(points), index(3, *this, nanoflann::KDTreeSingleIndexAdaptorParams(10)) {
index.buildIndex(num_threads);
}

~UnsafeKdTreeGeneric() {}

Expand Down Expand Up @@ -58,11 +60,11 @@ class KdTreeGeneric {

/// @brief Constructor
/// @param points Input points
KdTreeGeneric(const std::shared_ptr<const PointCloud>& points) : points(points), tree(*points) {}
explicit KdTreeGeneric(const std::shared_ptr<const PointCloud>& points) : points(points), tree(*points) {}

/// @brief Constructor
/// @param points Input points
KdTreeGeneric(const std::shared_ptr<const PointCloud>& points, int num_threads) : points(points), tree(*points, num_threads) {}
explicit KdTreeGeneric(const std::shared_ptr<const PointCloud>& points, int num_threads) : points(points), tree(*points, num_threads) {}

~KdTreeGeneric() {}

Expand Down
2 changes: 1 addition & 1 deletion include/small_gicp/benchmark/benchmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ std::string summarize(const Container& container, const Transform& transform) {

struct KittiDataset {
public:
KittiDataset(const std::string& dataset_path, size_t max_num_data = std::numeric_limits<size_t>::max()) {
explicit KittiDataset(const std::string& dataset_path, size_t max_num_data = 1000000) {
std::vector<std::string> filenames;
for (auto path : std::filesystem::directory_iterator(dataset_path)) {
if (path.path().extension() != ".bin") {
Expand Down
6 changes: 3 additions & 3 deletions include/small_gicp/factors/plane_icp_factor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ struct PointToPlaneICPFactor {
const auto& target_normal = traits::normal(target, target_index);

const Eigen::Vector4d residual = traits::point(target, target_index) - transed_source_pt;
const Eigen::Vector4d error = target_normal.array() * residual.array();
const Eigen::Vector4d err = target_normal.array() * residual.array();

Eigen::Matrix<double, 4, 6> J = Eigen::Matrix<double, 4, 6>::Zero();
J.block<3, 3>(0, 0) = target_normal.template head<3>().asDiagonal() * T.linear() * skew(traits::point(source, source_index).template head<3>());
J.block<3, 3>(0, 3) = target_normal.template head<3>().asDiagonal() * (-T.linear());

*H = J.transpose() * J;
*b = J.transpose() * error;
*e = 0.5 * error.squaredNorm();
*b = J.transpose() * err;
*e = 0.5 * err.squaredNorm();

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion include/small_gicp/points/point_cloud.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct PointCloud {
/// @brief Constructor
/// @param points Points to initialize the point cloud
template <typename T, int D, typename Allocator>
PointCloud(const std::vector<Eigen::Matrix<T, D, 1>, Allocator>& points) {
explicit PointCloud(const std::vector<Eigen::Matrix<T, D, 1>, Allocator>& points) {
this->resize(points.size());
for (size_t i = 0; i < points.size(); i++) {
this->point(i) << points[i].template cast<double>().template head<3>(), 1.0;
Expand Down
4 changes: 4 additions & 0 deletions include/small_gicp/registration/optimizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ struct LevenbergMarquardtOptimizer {
result.H = H;
result.b = b;
result.error = e;

if (!success) {
break;
}
}

result.num_inliers = std::count_if(factors.begin(), factors.end(), [](const auto& factor) { return factor.inlier(); });
Expand Down
4 changes: 1 addition & 3 deletions include/small_gicp/util/lie.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,14 @@ inline Eigen::Matrix3d skew(const Eigen::Vector3d& x) {
inline Eigen::Quaterniond so3_exp(const Eigen::Vector3d& omega) {
double theta_sq = omega.dot(omega);

double theta;
double imag_factor;
double real_factor;
if (theta_sq < 1e-10) {
theta = 0;
double theta_quad = theta_sq * theta_sq;
imag_factor = 0.5 - 1.0 / 48.0 * theta_sq + 1.0 / 3840.0 * theta_quad;
real_factor = 1.0 - 1.0 / 8.0 * theta_sq + 1.0 / 384.0 * theta_quad;
} else {
theta = std::sqrt(theta_sq);
double theta = std::sqrt(theta_sq);
double half_theta = 0.5 * theta;
imag_factor = std::sin(half_theta) / theta;
real_factor = std::cos(half_theta);
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/odometry_benchmark_fast_gicp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace small_gicp {

class FastGICPOdometryEstimation : public OnlineOdometryEstimation {
public:
FastGICPOdometryEstimation(const OdometryEstimationParams& params) : OnlineOdometryEstimation(params), T(Eigen::Isometry3d::Identity()) {
explicit FastGICPOdometryEstimation(const OdometryEstimationParams& params) : OnlineOdometryEstimation(params), T(Eigen::Isometry3d::Identity()) {
gicp.setCorrespondenceRandomness(params.num_neighbors);
gicp.setMaxCorrespondenceDistance(params.max_correspondence_distance);
gicp.setNumThreads(params.num_threads);
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/odometry_benchmark_fast_vgicp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace small_gicp {

class FastVGICPOdometryEstimation : public OnlineOdometryEstimation {
public:
FastVGICPOdometryEstimation(const OdometryEstimationParams& params) : OnlineOdometryEstimation(params), T(Eigen::Isometry3d::Identity()) {
explicit FastVGICPOdometryEstimation(const OdometryEstimationParams& params) : OnlineOdometryEstimation(params), T(Eigen::Isometry3d::Identity()) {
vgicp.setCorrespondenceRandomness(params.num_neighbors);
vgicp.setResolution(params.voxel_resolution);
vgicp.setMaxCorrespondenceDistance(params.max_correspondence_distance);
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/odometry_benchmark_pcl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace small_gicp {

class PCLOnlineOdometryEstimation : public OnlineOdometryEstimation {
public:
PCLOnlineOdometryEstimation(const OdometryEstimationParams& params) : OnlineOdometryEstimation(params), T(Eigen::Isometry3d::Identity()) {
explicit PCLOnlineOdometryEstimation(const OdometryEstimationParams& params) : OnlineOdometryEstimation(params), T(Eigen::Isometry3d::Identity()) {
gicp.setCorrespondenceRandomness(params.num_neighbors);
gicp.setMaxCorrespondenceDistance(params.max_correspondence_distance);
}
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/odometry_benchmark_small_gicp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace small_gicp {

class SmallGICPOnlineOdometryEstimation : public OnlineOdometryEstimation {
public:
SmallGICPOnlineOdometryEstimation(const OdometryEstimationParams& params) : OnlineOdometryEstimation(params), T(Eigen::Isometry3d::Identity()) {}
explicit SmallGICPOnlineOdometryEstimation(const OdometryEstimationParams& params) : OnlineOdometryEstimation(params), T(Eigen::Isometry3d::Identity()) {}

Eigen::Isometry3d estimate(const PointCloud::Ptr& points) override {
Stopwatch sw;
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/odometry_benchmark_small_gicp_model_tbb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace small_gicp {

class SmallGICPModelOnlineOdometryEstimationTBB : public OnlineOdometryEstimation {
public:
SmallGICPModelOnlineOdometryEstimationTBB(const OdometryEstimationParams& params)
explicit SmallGICPModelOnlineOdometryEstimationTBB(const OdometryEstimationParams& params)
: OnlineOdometryEstimation(params),
control(tbb::global_control::max_allowed_parallelism, params.num_threads),
T_world_lidar(Eigen::Isometry3d::Identity()) {}
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/odometry_benchmark_small_gicp_omp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace small_gicp {

class SmallGICPOnlineOdometryEstimationOMP : public OnlineOdometryEstimation {
public:
SmallGICPOnlineOdometryEstimationOMP(const OdometryEstimationParams& params) : OnlineOdometryEstimation(params), T_world_lidar(Eigen::Isometry3d::Identity()) {}
explicit SmallGICPOnlineOdometryEstimationOMP(const OdometryEstimationParams& params) : OnlineOdometryEstimation(params), T_world_lidar(Eigen::Isometry3d::Identity()) {}

Eigen::Isometry3d estimate(const PointCloud::Ptr& points) override {
Stopwatch sw;
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/odometry_benchmark_small_gicp_pcl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace small_gicp {

class SmallGICPPCLOdometryEstimation : public OnlineOdometryEstimation {
public:
SmallGICPPCLOdometryEstimation(const OdometryEstimationParams& params) : OnlineOdometryEstimation(params), T(Eigen::Isometry3d::Identity()) {
explicit SmallGICPPCLOdometryEstimation(const OdometryEstimationParams& params) : OnlineOdometryEstimation(params), T(Eigen::Isometry3d::Identity()) {
gicp.setCorrespondenceRandomness(params.num_neighbors);
gicp.setMaxCorrespondenceDistance(params.max_correspondence_distance);
gicp.setNumThreads(params.num_threads);
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/odometry_benchmark_small_gicp_tbb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace small_gicp {

class SmallGICPOnlineOdometryEstimationTBB : public OnlineOdometryEstimation {
public:
SmallGICPOnlineOdometryEstimationTBB(const OdometryEstimationParams& params)
explicit SmallGICPOnlineOdometryEstimationTBB(const OdometryEstimationParams& params)
: OnlineOdometryEstimation(params),
control(tbb::global_control::max_allowed_parallelism, params.num_threads),
T(Eigen::Isometry3d::Identity()) {}
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/odometry_benchmark_small_gicp_tbb_flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SmallGICPFlowEstimationTBB : public OdometryEstimation {
InputFrame::Ptr source; // Source frame
};

SmallGICPFlowEstimationTBB(const OdometryEstimationParams& params)
explicit SmallGICPFlowEstimationTBB(const OdometryEstimationParams& params)
: OdometryEstimation(params),
control(tbb::global_control::max_allowed_parallelism, params.num_threads),
throughput(0.0) {
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/odometry_benchmark_small_vgicp_model_tbb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace small_gicp {

class SmallVGICPModelOnlineOdometryEstimationTBB : public OnlineOdometryEstimation {
public:
SmallVGICPModelOnlineOdometryEstimationTBB(const OdometryEstimationParams& params)
explicit SmallVGICPModelOnlineOdometryEstimationTBB(const OdometryEstimationParams& params)
: OnlineOdometryEstimation(params),
control(tbb::global_control::max_allowed_parallelism, params.num_threads),
T_world_lidar(Eigen::Isometry3d::Identity()) {}
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/odometry_benchmark_small_vgicp_omp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace small_gicp {

class SmallVGICPOnlineOdometryEstimationOMP : public OnlineOdometryEstimation {
public:
SmallVGICPOnlineOdometryEstimationOMP(const OdometryEstimationParams& params) : OnlineOdometryEstimation(params), T(Eigen::Isometry3d::Identity()) {}
explicit SmallVGICPOnlineOdometryEstimationOMP(const OdometryEstimationParams& params) : OnlineOdometryEstimation(params), T(Eigen::Isometry3d::Identity()) {}

Eigen::Isometry3d estimate(const PointCloud::Ptr& points) override {
Stopwatch sw;
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/odometry_benchmark_small_vgicp_tbb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace small_gicp {

class SmallVGICPOnlineOdometryEstimationTBB : public OnlineOdometryEstimation {
public:
SmallVGICPOnlineOdometryEstimationTBB(const OdometryEstimationParams& params)
explicit SmallVGICPOnlineOdometryEstimationTBB(const OdometryEstimationParams& params)
: OnlineOdometryEstimation(params),
control(tbb::global_control::max_allowed_parallelism, params.num_threads),
T(Eigen::Isometry3d::Identity()) {}
Expand Down

0 comments on commit ff8269e

Please sign in to comment.