Skip to content

Commit

Permalink
(Minor) Clean codes, e.g., managing double space, redundant line brea…
Browse files Browse the repository at this point in the history
…k, no-space, etc, via .clang-format
  • Loading branch information
LimHyungTae committed May 5, 2024
1 parent 0383de1 commit 6b60fdb
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 32 deletions.
6 changes: 3 additions & 3 deletions examples/teaser_cpp_fpfh/quatro_cpp_fpfh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ inline double getAngularError(Eigen::Matrix3d R_exp, Eigen::Matrix3d R_est) {
return std::abs(std::acos(fmin(fmax(((R_exp.transpose() * R_est).trace() - 1) / 2, -1.0), 1.0)));
}

inline void calcErrors(const Eigen::Matrix4d& T, const Eigen::Matrix3d est_rot, const Eigen::Vector3d est_ts,
double &rot_error, double& ts_error) {
inline void calcErrors(const Eigen::Matrix4d& T, const Eigen::Matrix3d est_rot,
const Eigen::Vector3d est_ts, double& rot_error, double& ts_error) {
rot_error = getAngularError(T.topLeftCorner(3, 3), est_rot);
ts_error = (T.topRightCorner(3, 1) - est_ts).norm();
}
Expand All @@ -33,7 +33,7 @@ inline void getParams(const double noise_bound, const std::string reg_type,
params.rotation_estimation_algorithm =
teaser::RobustRegistrationSolver::ROTATION_ESTIMATION_ALGORITHM::QUATRO;
params.inlier_selection_mode = teaser::RobustRegistrationSolver::INLIER_SELECTION_MODE::PMC_HEU;
} else if (reg_type == "TEASER") {
} else if (reg_type == "TEASER") {
params.rotation_estimation_algorithm =
teaser::RobustRegistrationSolver::ROTATION_ESTIMATION_ALGORITHM::GNC_TLS;
params.inlier_selection_mode = teaser::RobustRegistrationSolver::INLIER_SELECTION_MODE::PMC_EXACT;
Expand Down
3 changes: 1 addition & 2 deletions teaser/include/teaser/certification.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ class AbstractRotationCertifier {
*/
class DRSCertifier : public AbstractRotationCertifier {
public:

/**
* Solver for eigendecomposition solver / spectral decomposition.
*
* @brief For most cases, the default solvers in Eigen should be used.
* For extremely large matrices, it may make sense to use Spectra instead.
*/
enum class EIG_SOLVER_TYPE {
EIGEN = 0, ///< Use solvers in the Eigen library
EIGEN = 0, ///< Use solvers in the Eigen library
SPECTRA = 1, ///< Use solvers in the Spectra library
};

Expand Down
1 change: 0 additions & 1 deletion teaser/include/teaser/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,4 @@ class PointCloud {
std::vector<PointXYZ> points_;
};


} // namespace teaser
2 changes: 1 addition & 1 deletion teaser/include/teaser/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class MaxCliqueSolver {
/**
* Number of threads to use for the solver
*/
int num_threads = 1;
int num_threads = 1;
};

MaxCliqueSolver() = default;
Expand Down
2 changes: 1 addition & 1 deletion teaser/include/teaser/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@
auto t_end_##s = clock_##s.now(); \
std::chrono::duration<double, std::milli> diff_dur_##s = t_end_##s - t_start_##s; \
double diff_##s = diff_dur_##s.count();
#define TEASER_DEBUG_GET_TIMING(s)(double)(diff_##s / 1000.0)
#define TEASER_DEBUG_GET_TIMING(s) (double)(diff_##s / 1000.0)
#endif
12 changes: 6 additions & 6 deletions teaser/include/teaser/matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class Matcher {
* @param use_tuple_test
* @return
*/
std::vector<std::pair<int, int>>
calculateCorrespondences(const teaser::PointCloud& source_points, const teaser::PointCloud& target_points,
const teaser::FPFHCloud& source_features, const teaser::FPFHCloud& target_features,
bool use_absolute_scale = true, bool use_crosscheck = true,
bool use_tuple_test = true, float tuple_scale = 0);
std::vector<std::pair<int, int>> calculateCorrespondences(
const teaser::PointCloud& source_points, const teaser::PointCloud& target_points,
const teaser::FPFHCloud& source_features, const teaser::FPFHCloud& target_features,
bool use_absolute_scale = true, bool use_crosscheck = true, bool use_tuple_test = true,
float tuple_scale = 0);

private:
template <typename T> void buildKDTree(const std::vector<T>& data, KDTree* tree);
Expand All @@ -56,7 +56,7 @@ class Matcher {
std::vector<std::pair<int, int>> corres_;
std::vector<teaser::PointCloud> pointcloud_;
std::vector<Feature> features_;
std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > means_; // for normalization
std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f>> means_; // for normalization
float global_scale_;
};

Expand Down
10 changes: 5 additions & 5 deletions teaser/src/certification.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ teaser::DRSCertifier::certify(const Eigen::Matrix3d& R_solution,

// this initial guess lives in the affine subspace
// use 2 separate steps to limit slow evaluation on only the few non-zeros in the sparse matrix
#if EIGEN_VERSION_AT_LEAST(3,3,0)
#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
Eigen::SparseMatrix<double> M_init = Q_bar - mu * J_bar - lambda_bar_init;
#else
// fix for this bug in Eigen 3.2: https://eigen.tuxfamily.org/bz/show_bug.cgi?id=632
Expand Down Expand Up @@ -135,7 +135,7 @@ teaser::DRSCertifier::certify(const Eigen::Matrix3d& R_solution,
TEASER_DEBUG_INFO_MSG("PSD time: " << TEASER_DEBUG_GET_TIMING(PSD));

// projection to affine space
#if EIGEN_VERSION_AT_LEAST(3,3,0)
#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
temp_W = 2 * M_PSD - M - M_init;
#else
// fix for this bug in Eigen 3.2: https://eigen.tuxfamily.org/bz/show_bug.cgi?id=632
Expand All @@ -147,7 +147,7 @@ teaser::DRSCertifier::certify(const Eigen::Matrix3d& R_solution,
getOptimalDualProjection(temp_W, theta_prepended, inverse_map, &W_dual);
TEASER_DEBUG_STOP_TIMING(DualProjection);
TEASER_DEBUG_INFO_MSG("Dual Projection time: " << TEASER_DEBUG_GET_TIMING(DualProjection));
#if EIGEN_VERSION_AT_LEAST(3,3,0)
#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
M_affine = M_init + W_dual;
#else
// fix for this bug in Eigen 3.2: https://eigen.tuxfamily.org/bz/show_bug.cgi?id=632
Expand Down Expand Up @@ -604,7 +604,7 @@ void teaser::DRSCertifier::getLinearProjection(
temp_column.emplace_back(var_i_idx, var_j_idx, entry_val);
if (var_i_idx == var_j_idx) {
diag_inserted = true;
diag_idx = temp_column.size()-1;
diag_idx = temp_column.size() - 1;
}
}
}
Expand All @@ -623,7 +623,7 @@ void teaser::DRSCertifier::getLinearProjection(
temp_column.emplace_back(var_i_idx, var_j_idx, entry_val);
if (var_i_idx == var_j_idx) {
diag_inserted = true;
diag_idx = temp_column.size()-1;
diag_idx = temp_column.size() - 1;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion teaser/src/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ vector<int> teaser::MaxCliqueSolver::findMaxClique(teaser::Graph graph) {
for (int i = 1; i < k_cores->size(); ++i) {
// Note: k_core has size equals to num vertices + 1
if ((*k_cores)[i] >= max_core) {
C.push_back(i-1);
C.push_back(i - 1);
}
}
return C;
Expand Down
1 change: 0 additions & 1 deletion teaser/src/matcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* See LICENSE for the license information
*/


#include <Eigen/Core>
#include <Eigen/Geometry>
#include <flann/flann.hpp>
Expand Down
2 changes: 0 additions & 2 deletions teaser/src/registration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,11 @@ void teaser::QuatroSolver::solveForRotation(
weights(j) = sqrt(noise_bound_sq * mu * (mu + 1) / residuals_sq(j)) - mu;
assert(weights(j) >= 0 && weights(j) <= 1);
}

}

// Calculate cost
double cost_diff = std::abs(cost_ - prev_cost);


// Increase mu
mu = mu * params_.gnc_factor;
prev_cost = cost_;
Expand Down
4 changes: 2 additions & 2 deletions test/teaser/feature-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TEST(FPFHTest, CalculateFPFHFeaturesWithPCL) {
// Read a PCD file from disk.
pcl::PCLPointCloud2 cloud_blob;
pcl::io::loadPCDFile("./data/bunny.pcd", cloud_blob);
pcl::fromPCLPointCloud2 (cloud_blob, *cloud);
pcl::fromPCLPointCloud2(cloud_blob, *cloud);

// Estimate the normals.
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normalEstimation;
Expand All @@ -53,7 +53,7 @@ TEST(FPFHTest, CalculateFPFHFeaturesWithTeaserInterface) {
pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PCLPointCloud2 cloud_blob;
pcl::io::loadPCDFile("./data/bunny.pcd", cloud_blob);
pcl::fromPCLPointCloud2 (cloud_blob, *pcl_cloud);
pcl::fromPCLPointCloud2(cloud_blob, *pcl_cloud);
teaser::PointCloud input_cloud;
for (auto& p : *pcl_cloud) {
input_cloud.push_back({p.x, p.y, p.z});
Expand Down
5 changes: 2 additions & 3 deletions test/teaser/graph-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ TEST(GraphTest, BasicFunctions) {
teaser::Graph graph;
graph.populateVertices(2);
graph.addEdge(1, 0);
EXPECT_TRUE(graph.hasEdge(1,0));
EXPECT_TRUE(graph.hasEdge(1, 0));
EXPECT_TRUE(graph.hasVertex(1));
EXPECT_TRUE(graph.hasVertex(0));
EXPECT_EQ(graph.numEdges(), 1);
Expand Down Expand Up @@ -297,7 +297,7 @@ TEST(MaxCliqueSolverTest, FindMaxClique) {
std::copy(clique.begin(), clique.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
std::set<int> s(clique.begin(), clique.end());
std::vector<int> ref_clique{0,1,2,3,4};
std::vector<int> ref_clique{0, 1, 2, 3, 4};
for (const auto& i : ref_clique) {
EXPECT_TRUE(s.find(i) != s.end());
}
Expand Down Expand Up @@ -356,7 +356,6 @@ TEST(PMCTest, FindMaximumCliqueSingleThreaded) {
EXPECT_EQ(C.size(), 5);
}


TEST(PMCTest, FindMaximumCliqueMultiThreaded) {
// A complete graph with max clique # = 5
auto in = generateMockInput();
Expand Down
2 changes: 1 addition & 1 deletion test/teaser/matcher-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ TEST(FPFHMatcherTest, MatchCase1) {
ASSERT_EQ(tokens.size(), 2);
ref_correspondences.emplace_back(
// -1 because the ref correspondences use 1-index (MATLAB)
std::pair<int, int>{std::stoi(tokens[0])-1, std::stoi(tokens[1])-1});
std::pair<int, int>{std::stoi(tokens[0]) - 1, std::stoi(tokens[1]) - 1});
}

// compare calculated correspondences with reference correspondences
Expand Down
2 changes: 1 addition & 1 deletion test/teaser/rotation-solver-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST(RotationSolverTest, FGRRotation) {
Eigen::Matrix<double, 3, Eigen::Dynamic> dst_points = src_points;

// Set up FGR
teaser::FastGlobalRegistrationSolver::Params params{1000, 0.0337, 1.4, 1e-3};
teaser::FastGlobalRegistrationSolver::Params params{1000, 0.0337, 1.4, 1e-3};
teaser::FastGlobalRegistrationSolver fgr_solver(params);

Eigen::Matrix3d result;
Expand Down
4 changes: 2 additions & 2 deletions test/teaser/utils-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ TEST(UtilsTest, CalculatePointClusterDiameter) {
{
Eigen::Matrix<float, 3, Eigen::Dynamic> test_mat(3,3);
test_mat << -1, 0, 1,
-1, 0, 1,
-1, 0, 1;
-1, 0, 1,
-1, 0, 1;
float d = teaser::utils::calculateDiameter<float, 3>(test_mat);
EXPECT_NEAR(d, 3.4641, 0.0001);
}
Expand Down

0 comments on commit 6b60fdb

Please sign in to comment.