ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
CorrespondenceChecker.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 #include <Logging.h>
11 #include <ecvPointCloud.h>
12 
13 #include <Eigen/Dense>
14 
15 namespace cloudViewer {
16 namespace pipelines {
17 namespace registration {
18 
20  const ccPointCloud &source,
21  const ccPointCloud &target,
22  const CorrespondenceSet &corres,
23  const Eigen::Matrix4d & /*transformation*/) const {
24  for (size_t i = 0; i < corres.size(); i++) {
25  for (size_t j = i + 1; j < corres.size(); j++) {
26  // check edge ij
27  double dis_source = (source.getEigenPoint(corres[i](0)) -
28  source.getEigenPoint(corres[j](0)))
29  .norm();
30  double dis_target = (target.getEigenPoint(corres[i](1)) -
31  target.getEigenPoint(corres[j](1)))
32  .norm();
33  if (dis_source < dis_target * similarity_threshold_ ||
34  dis_target < dis_source * similarity_threshold_) {
35  return false;
36  }
37  }
38  }
39  return true;
40 }
41 
43  const ccPointCloud &source,
44  const ccPointCloud &target,
45  const CorrespondenceSet &corres,
46  const Eigen::Matrix4d &transformation) const {
47  for (const auto &c : corres) {
48  const auto &pt = source.getEigenPoint(c(0));
49  Eigen::Vector3d pt_trans =
50  (transformation * Eigen::Vector4d(pt(0), pt(1), pt(2), 1.0))
51  .block<3, 1>(0, 0);
52  if ((target.getEigenPoint(c(1)) - pt_trans).norm() >
54  return false;
55  }
56  }
57  return true;
58 }
59 
61  const ccPointCloud &source,
62  const ccPointCloud &target,
63  const CorrespondenceSet &corres,
64  const Eigen::Matrix4d &transformation) const {
65  if (!source.hasNormals() || !target.hasNormals()) {
67  "[CorrespondenceCheckerBasedOnNormal::Check] Pointcloud has no "
68  "normals.");
69  return true;
70  }
71  double cos_normal_angle_threshold = std::cos(normal_angle_threshold_);
72  for (const auto &c : corres) {
73  const auto &normal = source.getEigenNormal(c(0));
74  Eigen::Vector3d normal_trans =
75  (transformation *
76  Eigen::Vector4d(normal(0), normal(1), normal(2), 0.0))
77  .block<3, 1>(0, 0);
78  if (target.getEigenNormal(c(1)).dot(normal_trans) <
79  cos_normal_angle_threshold) {
80  return false;
81  }
82  }
83  return true;
84 }
85 
86 } // namespace registration
87 } // namespace pipelines
88 } // namespace cloudViewer
double normal[3]
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Eigen::Vector3d getEigenNormal(size_t index) const
bool hasNormals() const override
Returns whether normals are enabled or not.
Eigen::Vector3d getEigenPoint(size_t index) const
bool Check(const ccPointCloud &source, const ccPointCloud &target, const CorrespondenceSet &corres, const Eigen::Matrix4d &transformation) const override
Function to check if two points can be aligned.
bool Check(const ccPointCloud &source, const ccPointCloud &target, const CorrespondenceSet &corres, const Eigen::Matrix4d &transformation) const override
Function to check if two points can be aligned.
bool Check(const ccPointCloud &source, const ccPointCloud &target, const CorrespondenceSet &corres, const Eigen::Matrix4d &transformation) const override
Function to check if two points can be aligned.
#define LogWarning(...)
Definition: Logging.h:72
std::vector< Eigen::Vector2i > CorrespondenceSet
Generic file read and write utility for python interface.