Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kdTreeFLANN] sigmentation fault #6208

Closed
YeHuanjie opened this issue Dec 30, 2024 · 19 comments
Closed

[kdTreeFLANN] sigmentation fault #6208

YeHuanjie opened this issue Dec 30, 2024 · 19 comments
Labels
kind: bug Type of issue status: triage Labels incomplete

Comments

@YeHuanjie
Copy link
Contributor

input point cloud size is 69641
find knn = 1, but nn_indices[0] is 1036443930
image

@YeHuanjie YeHuanjie added kind: bug Type of issue status: triage Labels incomplete labels Dec 30, 2024
@YeHuanjie
Copy link
Contributor Author

code is here:

		pcl::PointCloud<pcl::PointNormal>::Ptr p_(new pcl::PointCloud<pcl::PointNormal>());
		pcl::PointCloud<pcl::PointNormal>::Ptr q_(new pcl::PointCloud<pcl::PointNormal>());
		p_->resize(icp_model_cloud_->size());
		q_->resize(scene_with_normals_->size());
		std::cout << "icp_model_cloud_ num: " << icp_model_cloud_->size() << std::endl;
		std::cout << "scene_with_normals_ num: " << scene_with_normals_->size() << std::endl;
		int corres = 0;
		pcl::KdTreeFLANN<pcl::PointNormal> tree;
		tree.setInputCloud(scene_with_normals_);
		std::vector<int> nn_indices(1);
		std::vector<float> nn_dists(1);
		// For each point in the source PointCloud
		for (int i = 0; i < icp_model_cloud_->points.size(); i++)
		{
			if (!std::isfinite(icp_model_cloud_->points[i].x) ||
				!std::isfinite(icp_model_cloud_->points[i].y) ||
				!std::isfinite(icp_model_cloud_->points[i].z))
			{
				continue;
			}
			// Find nearest neighbor in the target (query)
			tree.nearestKSearch(icp_model_cloud_->points[i], 1, nn_indices, nn_dists);
			if (nn_dists[0] <= 0.005*0.005)
			{
				p_->points[corres] = icp_model_cloud_->points[i];
				q_->points[corres] = scene_with_normals_->points[nn_indices[0]];
				corres++;
			}
		}
		scene_with_normals_ = q_;
		icp_model_cloud_ = p_;
		scene_with_normals_->points.resize(corres);
		icp_model_cloud_->points.resize(corres);

@mvieth
Copy link
Member

mvieth commented Dec 30, 2024

  • Which operating system do you use?
  • Which PCL version do you use? How did you install it?
  • Which compiler do you use?
  • Do you use CMake to build your own code?

@YeHuanjie
Copy link
Contributor Author

ubuntu20.04
pcl-1.14.0
gnu-9.4.0
yes
It seems that the bug related to point num. The code works when voxel filter is applied.
the num of icp_model_cloud reduces from 163357 to 12066.

@mvieth
Copy link
Member

mvieth commented Dec 30, 2024

Can you upload the point clouds you are using as zipped PCD files? Then I can try to reproduce the problem on my computer. The number of points (163357) should not be a problem.

@YeHuanjie
Copy link
Contributor Author

sadly, uploading zip file is forbidden on this computer. which function shoud i check?

@mvieth
Copy link
Member

mvieth commented Dec 30, 2024

  • find out for which i the problem happens, for example by checking scene_with_normals_->points.size() <= nn_indices[0]
  • find out for which point (icp_model_cloud_->points[i]) the problem happens, and check if it is unusual in any way (print xyz, maybe it is far away from the other points?)
  • are nn_indices and nn_dists always of size 1? Does nearestKSearch always return 1?
  • maybe run the program with valgrind, to check for uninitialized memory use etc.

@YeHuanjie
Copy link
Contributor Author

YeHuanjie commented Dec 31, 2024

I remake and rerun the code, but the result is different.
Here is some gdb prints:

scene_with_normals_->size()=69641
scene_with_normals_->points.size()=69641
nn_indices[0]=999879106
i=152177
icp_model_cloud_->points.size()=163357
icp_model_cloud_->points[i].x=-0.0373063833
icp_model_cloud_->points[i].y=-0.0159869026
icp_model_cloud_->points[i].z=0.749509454
(gdb) p nn_indices
$7 = std::vector of length 1, capacity 1 = {999879106}
(gdb) p nn_dists 
$8 = std::vector of length 1, capacity 1 = {1.51427466e-05}

To prevent any omissions, the full text is attached.

i = 152177
voxel_size = 0.00100000005
voxel_grid_src = {<pcl::Filterpcl::PointNormal> = {<pcl::PCLBasepcl::PointNormal> = {vptr.PCLBase = 0x555555acb790 <vtable for pcl::VoxelGridpcl::PointNormal+16>,
input
= std::shared_ptr<const pcl::PointCloudpcl::PointNormal> (use count 2, weak count 0) = {get() = 0x555555b48620},
indices_ = std::shared_ptr<std::vector<int, std::allocator >> (use count 1, weak count 0) = {get() = 0x555555b80e60}, use_indices_ = false, fake_indices_ = true},
removed_indices_ = std::shared_ptr<std::vector<int, std::allocator >> (use count 1, weak count 0) = {get() = 0x555555b81700}, filter_name_ = "VoxelGrid",
extract_removed_indices_ = false},
leaf_size_ = {<Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> >> = {<Eigen::MatrixBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> >> = {<Eigen::DenseBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 1, 0, 4, 1>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 1, 0, 4, 1>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 1, 0, 4, 1>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> >> = {}, }, }, }, }, }, m_storage = {m_data = {array = {0.00100000005, 0.00100000005, 0.00100000005, 1}}}}, },
inverse_leaf_size_ = {<Eigen::PlainObjectBase<Eigen::Array<float, 4, 1, 0, 4, 1> >> = {<Eigen::ArrayBase<Eigen::Array<float, 4, 1, 0, 4, 1> >> = {<Eigen::DenseBase<Eigen::Array<float, 4, 1, 0, 4, 1> >> = {<Eigen::DenseCoeffsBase<Eigen::Array<float, 4, 1, 0, 4, 1>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Array<float, 4, 1, 0, 4, 1>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Array<float, 4, 1, 0, 4, 1>, 0>> = {<Eigen::EigenBase<Eigen::Array<float, 4, 1, 0, 4, 1> >> = {}, }, }, }, }, }, m_storage = {m_data = {array = {999.999939, 999.999939, 999.999939, 1}}}}, }, downsample_all_data_ = true,
save_leaf_layout_ = false, leaf_layout_ = std::vector of length 0, capacity 0,
min_b_ = {<Eigen::PlainObjectBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::MatrixBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {}, }, }, }, }, }, m_storage = {m_data = {array = {-67, -57, 737, 0}}}}, },
max_b_ = {<Eigen::PlainObjectBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::MatrixBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {}, }, }, }, }, }, m_storage = {m_data = {array = {14, 25, 781, 0}}}}, },
div_b_ = {<Eigen::PlainObjectBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::MatrixBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {}, }, }, }, }, }, m_storage = {m_data = {array = {82, 83, 45, 0}}}}, },
divb_mul_ = {<Eigen::PlainObjectBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::MatrixBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {}, }, }, }, }, }, m_storage = {m_data = {array = {1, 82, 6806, 0}}}}, }, filter_field_name_ = "", filter_limit_min_ = -3.4028234663852886e+38,
filter_limit_max_ = 3.4028234663852886e+38, filter_limit_negative_ = false, min_points_per_voxel_ = 0}
cloud_src_downsampled = std::shared_ptr<pcl::PointCloudpcl::PointNormal> (use count 2, weak count 0) = {get() = 0x555555b83400}
voxel_grid_tgt = {<pcl::Filterpcl::PointNormal> = {<pcl::PCLBasepcl::PointNormal> = {vptr.PCLBase = 0x555555acb790 <vtable for pcl::VoxelGridpcl::PointNormal+16>,
input
= std::shared_ptr<const pcl::PointCloudpcl::PointNormal> (use count 3, weak count 0) = {get() = 0x555555b483a0},
indices_ = std::shared_ptr<std::vector<int, std::allocator >> (use count 1, weak count 0) = {get() = 0x555555b81920}, use_indices_ = false, fake_indices_ = true},
removed_indices_ = std::shared_ptr<std::vector<int, std::allocator >> (use count 1, weak count 0) = {get() = 0x555555b81940}, filter_name_ = "VoxelGrid",
extract_removed_indices_ = false},
leaf_size_ = {<Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> >> = {<Eigen::MatrixBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> >> = {<Eigen::DenseBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 1, 0, 4, 1>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 1, 0, 4, 1>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 1, 0, 4, 1>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> >> = {}, }, }, }, }, }, m_storage = {m_data = {array = {0.00100000005, 0.00100000005, 0.00100000005, 1}}}}, },
inverse_leaf_size_ = {<Eigen::PlainObjectBase<Eigen::Array<float, 4, 1, 0, 4, 1> >> = {<Eigen::ArrayBase<Eigen::Array<float, 4, 1, 0, 4, 1> >> = {<Eigen::DenseBase<Eigen::Array<float, 4, 1, 0, 4, 1> >> = {<Eigen::DenseCoeffsBase<Eigen::Array<float, 4, 1, 0, 4, 1>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Array<float, 4, 1, 0, 4, 1>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Array<float, 4, 1, 0, 4, 1>, 0>> = {<Eigen::EigenBase<Eigen::Array<float, 4, 1, 0, 4, 1> >> = {}, }, }, <No data fiel--Type for more, q to quit, c to continue without paging--
ds>}, }, }, m_storage = {m_data = {array = {999.999939, 999.999939, 999.999939, 1}}}}, }, downsample_all_data_ = true,
save_leaf_layout_ = false, leaf_layout_ = std::vector of length 0, capacity 0,
min_b_ = {<Eigen::PlainObjectBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::MatrixBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {}, }, }, }, }, }, m_storage = {m_data = {array = {-59, -52, 741, 0}}}}, },
max_b_ = {<Eigen::PlainObjectBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::MatrixBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {}, }, }, }, }, }, m_storage = {m_data = {array = {18, 27, 770, 0}}}}, },
div_b_ = {<Eigen::PlainObjectBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::MatrixBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {}, }, }, }, }, }, m_storage = {m_data = {array = {78, 80, 30, 0}}}}, },
divb_mul_ = {<Eigen::PlainObjectBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::MatrixBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<int, 4, 1, 0, 4, 1>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<int, 4, 1, 0, 4, 1> >> = {}, }, }, }, }, }, m_storage = {m_data = {array = {1, 78, 6240, 0}}}}, }, filter_field_name_ = "", filter_limit_min_ = -3.4028234663852886e+38,
filter_limit_max_ = 3.4028234663852886e+38, filter_limit_negative_ = false, min_points_per_voxel_ = 0}
cloud_tgt_downsampled = std::shared_ptr<pcl::PointCloudpcl::PointNormal> (use count 5, weak count 0) = {get() = 0x555555b834c0}
icp = {<pcl::IterativeClosestPoint<pcl::PointNormal, pcl::PointNormal, float>> = {<pcl::Registration<pcl::PointNormal, pcl::PointNormal, float>> = {<pcl::PCLBasepcl::PointNormal> = {vptr.PCLBase = 0x555555acb720 <vtable for pcl::IterativeClosestPointWithNormals<pcl::PointNormal, pcl::PointNormal, float>+16>,
input
= std::shared_ptr<const pcl::PointCloudpcl::PointNormal> (use count 2, weak count 0) = {get() = 0x555555b83400},
indices_ = std::shared_ptr<std::vector<int, std::allocator >> (use count 1, weak count 0) = {get() = 0x55555b33aeb0}, use_indices_ = false, fake_indices_ = true},
reg_name_ = "IterativeClosestPointWithNormals",
tree_ = std::shared_ptr<pcl::search::KdTree<pcl::PointNormal, pcl::KdTreeFLANN<pcl::PointNormal, flann::L2_Simple > >> (use count 2, weak count 0) = {
get() = 0x55555ad84a10},
tree_reciprocal_ = std::shared_ptr<pcl::search::KdTree<pcl::PointNormal, pcl::KdTreeFLANN<pcl::PointNormal, flann::L2_Simple > >> (use count 2, weak count 0) = {
get() = 0x55555b37b5a0}, nr_iterations_ = 7, max_iterations_ = 100, ransac_iterations_ = 0,
target_ = std::shared_ptr<const pcl::PointCloudpcl::PointNormal> (use count 5, weak count 0) = {get() = 0x555555b834c0},
final_transformation_ = {<Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::MatrixBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::DenseBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {}, }, }, }, }, }, m_storage = {m_data = {array = {0.986296177, -0.158968806, -0.044147443, 0, 0.162263617, 0.983055651, 0.0852787942, 0,
0.029842712, -0.0912736803, 0.995378792, 0, -0.0167847667, 0.0691758022, 0.00646259263, 1}}}}, },
transformation_ = {<Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::MatrixBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::DenseBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {}, }, }, }, }, }, m_storage = {m_data = {array = {0.999999344, -0.00113168708, 8.96892452e-05, 0, 0.00113168231, 0.999999344, 5.33861239e-05,
0, -8.97496066e-05, -5.32845916e-05, 1, 0, 8.29009805e-05, 1.58835865e-05, 1.10158248e-06, 1}}}}, },
previous_transformation_ = {<Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::MatrixBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::DenseBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {}, }, }, }, }, }, m_storage = {m_data = {array = {1, 0.000320077204, -0.000109066939, 0, -0.000320064311, 1, 0.000118015203, 0,
0.000109104716, -0.000117980286, 1, 0, -8.80759908e-05, 9.93743743e-05, 8.67963195e-07, 1}}}}, }, transformation_epsilon_ = 1e-08,
transformation_rotation_epsilon_ = 0, euclidean_fitness_epsilon_ = -1.7976931348623157e+308, corr_dist_threshold_ = 1.3407807929942596e+154,
--Type for more, q to quit, c to continue without paging--
inlier_threshold_ = 0.050000000000000003, converged_ = true, min_number_correspondences_ = 3,
correspondences_ = std::shared_ptr<std::vector<pcl::Correspondence, Eigen::aligned_allocatorpcl::Correspondence >> (use count 1, weak count 0) = {
get() = 0x55555abfa1d0},
transformation_estimation_ = std::shared_ptr<pcl::registration::TransformationEstimation<pcl::PointNormal, pcl::PointNormal, float>> (use count 2, weak count 0) = {
get() = 0x55555b36d220},
correspondence_estimation_ = std::shared_ptr<pcl::registration::CorrespondenceEstimationBase<pcl::PointNormal, pcl::PointNormal, float>> (use count 2, weak count 0) = {
get() = 0x55555b392540}, correspondence_rejectors_ = std::vector of length 1, capacity 1 = {
std::shared_ptrpcl::registration::CorrespondenceRejector (use count 2, weak count 0) = {get() = 0x55555b389ac0}}, target_cloud_updated_ = false,
source_cloud_updated_ = true, force_no_recompute_ = false, force_no_recompute_reciprocal_ = false,
update_visualizer_ = {<std::Maybe_unary_or_binary_function<void, pcl::PointCloudpcl::PointNormal const&, std::vector<int, std::allocator > const&, pcl::PointCloudpcl::PointNormal const&, std::vector<int, std::allocator > const&>> = {}, std::_Function_base = {static M_max_size = 16, static M_max_align = 8,
M_functor = {M_unused = {M_object = 0x0, M_const_object = 0x0, M_function_pointer = 0x0, M_member_pointer = NULL},
M_pod_data = "\000\000\000\000\000\000\000\000`\321\377\377\377\177\000"}, M_manager = 0x0}, M_invoker = 0x7fffffffd357},
point_representation
= std::shared_ptr<const pcl::PointRepresentationpcl::PointNormal> (empty) = {get() = 0x0}},
convergence_criteria
= std::shared_ptr<pcl::registration::DefaultConvergenceCriteria> (use count 1, weak count 0) = {get() = 0x55555ad7c7a0}, x_idx_offset
= 0,
y_idx_offset
= 4, z_idx_offset
= 8, nx_idx_offset
= 16, ny_idx_offset
= 20, nz_idx_offset
= 24, use_reciprocal_correspondence
= false, source_has_normals
= true,
target_has_normals
= true, need_source_blob = true, need_target_blob_ = true}, use_symmetric_objective_ = false, enforce_same_direction_normals_ = true}
point_to_plane = std::shared_ptr<pcl::registration::TransformationEstimationSymmetricPointToPlaneLLS<pcl::PointNormal, pcl::PointNormal, float>> (use count 2, weak count 0) = {
get() = 0x55555b36d220}
ce = std::shared_ptr<pcl::registration::CorrespondenceEstimationNormalShooting<pcl::PointNormal, pcl::PointNormal, pcl::PointNormal, float>> (use count 2, weak count 0) = {
get() = 0x55555b392540}

rej = std::shared_ptrpcl::registration::CorrespondenceRejectorSurfaceNormal (use count 2, weak count 0) = {get() = 0x55555b389ac0}
ori_model_point_cloud = std::shared_ptr<pcl::PointCloudpcl::PointNormal> (use count 1, weak count 0) = {get() = 0x55555bd3d760}
p_ = std::shared_ptr<pcl::PointCloudpcl::PointNormal> (use count 1, weak count 0) = {get() = 0x55555ab8ae40}
q_ = std::shared_ptr<pcl::PointCloudpcl::PointNormal> (use count 1, weak count 0) = {get() = 0x55555c2a79c0}
corres = 88351
tree = {<pcl::KdTreepcl::PointNormal> = {vptr.KdTree = 0x555555ac97e0 <vtable for pcl::KdTreeFLANN<pcl::PointNormal, flann::L2_Simple >+16>,
input
= std::shared_ptr<const pcl::PointCloudpcl::PointNormal> (use count 3, weak count 0) = {get() = 0x555555b483a0},
indices_ = std::shared_ptr<const std::vector<int, std::allocator >> (empty) = {get() = 0x0}, epsilon_ = 0, min_pts_ = 1, sorted_ = true,
point_representation_ = std::shared_ptr<const pcl::PointRepresentationpcl::PointNormal> (use count 1, weak count 0) = {get() = 0x55555b392980}},
flann_index_ = std::shared_ptr<flann::Index<flann::L2_Simple >> (use count 1, weak count 0) = {get() = 0x55555c2a5330},
cloud_ = std::shared_ptr (use count 1, weak count 0) = {get() = 0x55555c1125e0}, index_mapping_ = std::vector of length 69641, capacity 69641 = {1016300183, 0, 0, 0,
986621397, -1122837456, 1061125777, 1065353216, 1047925860, -1103157139, -1082926071, 0, 1016300183, 0, 0, 0, 982502076, -1122774085, 1061124519, 1065353216, 1043470968,
-1111256763, -1082464008, 0, 1017597554, 0, 0, 0, 986621397, -1122837456, 1061125777, 1065353216, 1047925860, -1103157139, -1082926071, 0, 1016300183, 0, 0, 0, 982502076,
-1122774085, 1061124519, 1065353216, 1043470968, -1111256763, -1082464008, 0, 1017597554, 0, 0, 0, 982502076, -1122774085, 1061124519, 1065353216, 1043470968, -1111256763,
-1082464008, 0, 1017597554, 0, 0, 0, 986621397, -1122837456, 1061125777, 1065353216, 1047925860, -1103157139, -1082926071, 0, 1016300183, 0, 0, 0, 982502076, -1122774085,
1061124519, 1065353216, 1043470968, -1111256763, -1082464008, 0, 1017597554, 0, 0, 0, 986621397, -1122837456, 1061125777, 1065353216, 1047925860, -1103157139, -1082926071,
0, 1016300183, 0, 0, 0, 986621397, -1122837456, 1061125777, 1065353216, 1047925860, -1103157139, -1082926071, 0, 1016300183, 0, 0, 0, 982502076, -1122774085, 1061124519,
1065353216, 1043470968, -1111256763, -1082464008, 0, 1017597554, 0, 0, 0, 986621397, -1122837456, 1061125777, 1065353216, 1047925860, -1103157139, -1082926071, 0,
1016300183, 0, 0, 0, 982502076, -1122774085, 1061124519, 1065353216, 1043470968, -1111256763, -1082464008, 0, 1017597554, 0, 0, 0, 982502076, -1122774085, 1061124519,
1065353216, 1043470968, -1111256763, -1082464008, 0, 1017597554, 0, 0, 0, 986621397, -1122837456, 1061125777, 1065353216, 1047925860, -1103157139, -1082926071, 0,
1016300183, 0, 0, 0, 982502076, -1122774085, 1061124519, 1065353216, 1043470968, -1111256763, -1082464008, 0, 1017597554, 0, 0, 0, 986621397, -1122837456, 1061125777,
1065353216, 1047925860, -1103157139, -1082926071, 0, 1016300183, 0, 0, 0, 982502076, -1122774085, 1061124519, 1065353216...}, identity_mapping_ = true, dim_ = 3,
total_nr_points_ = 69641, param_k_ = {checks = -1, eps = 0, sorted = true, max_neighbors = -1, use_heap = flann::FLANN_Undefined, cores = 1, matrices_in_gpu_ram = false},
param_radius_ = {checks = -1, eps = 0, sorted = true, max_neighbors = -1, use_heap = flann::FLANN_Undefined, cores = 1, matrices_in_gpu_ram = false}}
nn_indices = std::vector of length 1, capacity 1 = {999879106}
--Type for more, q to quit, c to continue without paging--
nn_dists = std::vector of length 1, capacity 1 = {1.51427466e-05}
icp1 = {<pcl::IterativeClosestPoint<pcl::PointNormal, pcl::PointNormal, float>> = {<pcl::Registration<pcl::PointNormal, pcl::PointNormal, float>> = {<pcl::PCLBasepcl::PointNormal> = {vptr.PCLBase = 0x3f7af8aabe48240c, input = <error reading variable: Cannot access memory at address 0x3bb0b016bddc229f>,
indices_ = <error reading variable: Cannot access memory at address 0x3e49e3c03f798ce0>, use_indices_ = 25, fake_indices_ = 167},
reg_name_ = <error: Cannot access memory at address 0xbcbf81ccbd9d9f66>,

  tree_ = std::shared_ptr<pcl::search::KdTree<pcl::PointNormal, pcl::KdTreeFLANN<pcl::PointNormal, flann::L2_Simple<float> > >> (use count -443987883, weak count 283935559) = {get() = 0x7fffffffd1f0}, 
  tree_reciprocal_ = std::shared_ptr<pcl::search::KdTree<pcl::PointNormal, pcl::KdTreeFLANN<pcl::PointNormal, flann::L2_Simple<float> > >> (use count 1437894288, weak count 21844) = {get() = 0x7fffffffd220}, nr_iterations_ = -11760, max_iterations_ = 32767, ransac_iterations_ = 1432461356, 
  target_ = std::shared_ptr<const pcl::PointCloud<pcl::PointNormal>> (use count 1437894288, weak count 21844) = {get() = 0x7fffffffd248}, 
  final_transformation_ = {<Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::MatrixBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::DenseBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, m_storage = {m_data = {array = {-nan(0x7fd240), 4.59163468e-41, -nan(0x7fd357), 4.59163468e-41, 2.48107846e+13, 
            3.0611365e-41, 2.48112543e+13, 3.0611365e-41, 2.48107846e+13, 3.0611365e-41, 2.48112543e+13, 3.0611365e-41, -nan(0x7fd248), 4.59163468e-41, -nan(0x7fd240), 
            4.59163468e-41}}}}, <No data fields>}, 
  transformation_ = {<Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::MatrixBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::DenseBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, m_storage = {m_data = {array = {-nan(0x7fd357), 4.59163468e-41, 2.48112543e+13, 3.0611365e-41, -nan(0x7fd2b0), 
            4.59163468e-41, 6.73088065e-35, -1.16953805e-18, 2.48107846e+13, 3.0611365e-41, 2.48107846e+13, 3.0611365e-41, -nan(0x7fd2c0), 4.59163468e-41, 1.5637676e+13, 
            3.0611365e-41}}}}, <No data fields>}, 
  previous_transformation_ = {<Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::MatrixBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::DenseBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<float, 4, 4, 0, 4, 4>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >> = {<No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, m_storage = {m_data = {array = {-nan(0x7fd298), 4.59163468e-41, -nan(0x7fd357), 4.59163468e-41, 2.48107846e+13, 
            3.0611365e-41, 2.48112543e+13, 3.0611365e-41, -nan(0x7fd300), 4.59163468e-41, 1.56066434e+13, 3.0611365e-41, 2.4810751e+13, 3.0611365e-41, -nan(0x7fd357), 
            4.59163468e-41}}}}, <No data fields>}, transformation_epsilon_ = 4.6355708467695755e-310, transformation_rotation_epsilon_ = 4.6355708467806426e-310, 
  euclidean_fitness_epsilon_ = 6.9533558072682122e-310, corr_dist_threshold_ = 4.6355708467806426e-310, inlier_threshold_ = 6.9533558072682122e-310, converged_ = 67, 
  min_number_correspondences_ = 21845, 
  correspondences_ = std::shared_ptr<std::vector<pcl::Correspondence, Eigen::aligned_allocator<pcl::Correspondence> >> (use count -2912256, weak count 8388606) = {
    get() = 0x0}, 
  transformation_estimation_ = std::shared_ptr<pcl::registration::TransformationEstimation<pcl::PointNormal, pcl::PointNormal, float>> (expired, weak count 1065353216) = {
    get() = 0x555555b485b0}, 
  correspondence_estimation_ = std::shared_ptr<pcl::registration::CorrespondenceEstimationBase<pcl::PointNormal, pcl::PointNormal, float>> (use count 2630916, weak count 91488255) = {get() = 0x7fffffffd360}, correspondence_rejectors_ = std::vector of length 14, capacity 2932030616797 = {
    <error reading variable: Cannot access memory at address 0x3f80000000000008>, <error reading variable: Cannot access memory at address 0x313122202c5d7d65>, 
    <error reading variable: Cannot access memory at address 0x29>, <error reading variable: Cannot access memory at address 0x100000009>, 
    <error reading variable: Cannot access memory at address 0xb9>, std::shared_ptr<pcl::registration::CorrespondenceRejector> (use count 1546231920, weak count 21844) = {
      get() = 0x7fffebe53be0 <main_arena+96>}, warning: can't find linker symbol for virtual table for `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>' value

warning: can't find linker symbol for virtual table for `std::Sp_counted_base<(gnu_cxx::Lock_policy)2>' value
std::shared_ptrpcl::registration::CorrespondenceRejector (use count -337298464, weak count 32766) = {get() = 0x0},
std::shared_ptrpcl::registration::CorrespondenceRejector (empty) = {get() = 0x0}, std::shared_ptrpcl::registration::CorrespondenceRejector (empty) = {
get() = 0x555555b48640}, std::shared_ptrpcl::registration::CorrespondenceRejector (empty) = {get() = 0x0},
std::shared_ptrpcl::registration::CorrespondenceRejector (use count 1061512977, weak count 1065353215) = {get() = 0x555559a40400},
<error reading variable: Cannot access memory at address 0x100027e25>, std::shared_ptrpcl::registration::CorrespondenceRejector (empty) = {get() = 0x1},
std::shared_ptrpcl::registration::CorrespondenceRejector (empty) = {get() = 0x0}}, target_cloud_updated
= 144, source_cloud_updated
= 134, force_no_recompute
= 180,
force_no_recompute_reciprocal
= 85,
--Type for more, q to quit, c to continue without paging--
update_visualizer_ = {<std::_Maybe_unary_or_binary_function<void, pcl::PointCloudpcl::PointNormal const&, std::vector<int, std::allocator > const&, pcl::PointCloudpcl::PointNormal const&, std::vector<int, std::allocator > const&>> = {}, std::_Function_base = {static _M_max_size = 16, static _M_max_align = 8,
_M_functor = {_M_unused = {_M_object = 0x7fffffffd390, _M_const_object = 0x7fffffffd390, _M_function_pointer = 0x7fffffffd390,
_M_member_pointer = (void (std::_Undefined_class::*)(std::_Undefined_class * const)) 0x7fffffffd390, this adjustment 93824993042183},

        _M_pod_data = "\220\323\377\377\377\177\000\000\a\237aUUU\000"}, _M_manager = 0x555555b485b0}, _M_invoker = 0x555555b48690}, 
  point_representation_ = std::shared_ptr<const pcl::PointRepresentation<pcl::PointNormal>> (expired, weak count 1065353216) = {get() = 0x7fffffffd3b0}}, 
convergence_criteria_ = std::shared_ptr<pcl::registration::DefaultConvergenceCriteria<float>> (use count 504361728, weak count -1991748103) = {get() = 0x7fffffffd3b0}, 
x_idx_offset_ = 93824998475184, y_idx_offset_ = 93824998475408, z_idx_offset_ = 140737488344032, nx_idx_offset_ = 93824993045319, ny_idx_offset_ = 93824998475184, 
nz_idx_offset_ = 93824998475408, use_reciprocal_correspondence_ = 14, source_has_normals_ = 144, target_has_normals_ = 4, need_source_blob_ = false, 
need_target_blob_ = false}, use_symmetric_objective_ = false, enforce_same_direction_normals_ = false}

point_to_plane1 = std::shared_ptr<pcl::registration::TransformationEstimationSymmetricPointToPlaneLLS<pcl::PointNormal, pcl::PointNormal, float>> (use count 70469732, weak count 10276) = {get() = 0x7fffffffd070}
ce1 = <error reading variable: Cannot access memory at address 0xf1cd97f0356661a8>

@YeHuanjie
Copy link
Contributor Author

YeHuanjie commented Dec 31, 2024

Here is the ASAN result:
eval_on_hikvision.h:669 ==> q_->points[corres] = scene_with_normals_->points[nn_indices[0]];
It seems that heap-buffer-overflow causes the fault.

=================================================================
==9982==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7f1b948799d0 at pc 0x55a045a97427 bp 0x7ffd21147b50 sp 0x7ffd21147b40
WRITE of size 48 at 0x7f1b948799d0 thread T0
    #0 0x55a045a97426 in HIKSymmICPTest::ICP() /home/tplink/factory_simulation/test_pcl/src/eval_on_hikvision.h:669
    #1 0x55a045a91723 in HIKICPEvalBase::Process() /home/tplink/factory_simulation/test_pcl/src/eval_on_hikvision.h:362
    #2 0x55a045a6f863 in EvalOnHikvision() /home/tplink/factory_simulation/test_pcl/src/eval_on_hikvision.cc:194
    #3 0x55a045497abc in main /home/tplink/factory_simulation/test_pcl/src/main.cc:47
    #4 0x7f1b98f2a082 in __libc_start_main ../csu/libc-start.c:308
    #5 0x55a04549741d in _start (/home/tplink/factory_simulation/test_pcl/build/pcl_test+0x791241d)

0x7f1b948799d0 is located 0 bytes to the right of 3342800-byte region [0x7f1b94549800,0x7f1b948799d0)
allocated by thread T0 here:
    #0 0x7f1bb5ff9808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x55a0454cb3f2 in Eigen::internal::handmade_aligned_malloc(unsigned long, unsigned long) /usr/local/include/eigen3/Eigen/src/Core/util/Memory.h:105
    #2 0x55a0454cb575 in Eigen::internal::aligned_malloc(unsigned long) /usr/local/include/eigen3/Eigen/src/Core/util/Memory.h:188
    #3 0x55a0455766de in Eigen::aligned_allocator<pcl::PointNormal>::allocate(unsigned long, void const*) /usr/local/include/eigen3/Eigen/src/Core/util/Memory.h:916
    #4 0x55a04555a973 in std::allocator_traits<Eigen::aligned_allocator<pcl::PointNormal> >::allocate(Eigen::aligned_allocator<pcl::PointNormal>&, unsigned long) /usr/include/c++/9/bits/alloc_traits.h:305
    #5 0x55a045536939 in std::_Vector_base<pcl::PointNormal, Eigen::aligned_allocator<pcl::PointNormal> >::_M_allocate(unsigned long) /usr/include/c++/9/bits/stl_vector.h:343
    #6 0x55a045578e78 in std::vector<pcl::PointNormal, Eigen::aligned_allocator<pcl::PointNormal> >::_M_default_append(unsigned long) /usr/include/c++/9/bits/vector.tcc:635
    #7 0x55a04555d9ae in std::vector<pcl::PointNormal, Eigen::aligned_allocator<pcl::PointNormal> >::resize(unsigned long) /usr/include/c++/9/bits/stl_vector.h:937
    #8 0x55a04553af13 in pcl::PointCloud<pcl::PointNormal>::resize(unsigned long) /usr/local/include/pcl-1.14/pcl/point_cloud.h:464
    #9 0x55a045a95d02 in HIKSymmICPTest::ICP() /home/tplink/factory_simulation/test_pcl/src/eval_on_hikvision.h:647
    #10 0x55a045a91723 in HIKICPEvalBase::Process() /home/tplink/factory_simulation/test_pcl/src/eval_on_hikvision.h:362
    #11 0x55a045a6f863 in EvalOnHikvision() /home/tplink/factory_simulation/test_pcl/src/eval_on_hikvision.cc:194
    #12 0x55a045497abc in main /home/tplink/factory_simulation/test_pcl/src/main.cc:47
    #13 0x7f1b98f2a082 in __libc_start_main ../csu/libc-start.c:308
    #14 0x55a04549741d in _start (/home/tplink/factory_simulation/test_pcl/build/pcl_test+0x791241d)

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/tplink/factory_simulation/test_pcl/src/eval_on_hikvision.h:669 in HIKSymmICPTest::ICP()
Shadow bytes around the buggy address:
  0x0fe3f29072e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe3f29072f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe3f2907300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe3f2907310: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe3f2907320: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0fe3f2907330: 00 00 00 00 00 00 00 00 00 00[fa]fa fa fa fa fa
  0x0fe3f2907340: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0fe3f2907350: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0fe3f2907360: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0fe3f2907370: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0fe3f2907380: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
=================================================================
==9982==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f1bb601a478 bp 0x00000000000f sp 0x7ffd21146628 T0)
==9982==The signal is caused by a READ memory access.
==9982==Hint: address points to the zero page.
    #0 0x7f1bb601a477 in __sanitizer::StackDepotBase<__sanitizer::StackDepotNode, 1, 20>::find(__sanitizer::StackDepotNode*, __sanitizer::StackTrace, unsigned int) ../../../../src/libsanitizer/sanitizer_common/sanitizer_stackdepotbase.h:63
    #1 0x7f1bb601a611 in __sanitizer::StackDepotBase<__sanitizer::StackDepotNode, 1, 20>::Put(__sanitizer::StackTrace, bool*) ../../../../src/libsanitizer/sanitizer_common/sanitizer_stackdepotbase.h:105
    #2 0x7f1bb601a24b in __sanitizer::StackDepotPut(__sanitizer::StackTrace) ../../../../src/libsanitizer/sanitizer_common/sanitizer_stackdepot.cc:110
    #3 0x7f1bb5f18151 in __asan::Allocator::Allocate(unsigned long, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType, bool) ../../../../src/libsanitizer/asan/asan_allocator.cc:508
    #4 0x7f1bb5f147ec in __asan::asan_memalign(unsigned long, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType) ../../../../src/libsanitizer/asan/asan_allocator.cc:922
    #5 0x7f1bb5ffb545 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cc:104
    #6 0x55a045af270a in __gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::allocate(unsigned long, void const*) /usr/include/c++/9/ext/new_allocator.h:114
    #7 0x55a045ae1eb3 in std::allocator_traits<std::allocator<std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > > >::allocate(std::allocator<std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >&, unsigned long) /usr/include/c++/9/bits/alloc_traits.h:443
    #8 0x55a045ad5497 in std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::_M_get_node() /usr/include/c++/9/bits/stl_tree.h:580
    #9 0x55a045b12b34 in std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >* std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::_M_create_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> const&>(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> const&) /usr/include/c++/9/bits/stl_tree.h:630
    #10 0x55a045b0cfb1 in std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >* std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::_Alloc_node::operator()<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> const&>(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> const&) const /usr/include/c++/9/bits/stl_tree.h:548
    #11 0x55a045b0427f in std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >* std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::_M_clone_node<std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::_Alloc_node>(std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > const*, std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::_Alloc_node&) /usr/include/c++/9/bits/stl_tree.h:658
    #12 0x55a045af45f8 in std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >* std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::_M_copy<std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::_Alloc_node>(std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > const*, std::_Rb_tree_node_base*, std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::_Alloc_node&) /usr/include/c++/9/bits/stl_tree.h:1880
    #13 0x55a045ae459d in std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >* std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::_M_copy<std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::_Alloc_node>(std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > > const&, std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::_Alloc_node&) /usr/include/c++/9/bits/stl_tree.h:906
    #14 0x55a045ad91f3 in std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::_M_copy(std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > > const&) /usr/include/c++/9/bits/stl_tree.h:917
    #15 0x55a045acd9ec in std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::_Rb_tree(std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > > const&) /usr/include/c++/9/bits/stl_tree.h:955
    #16 0x55a045ab9d4c in std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, flann::any, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > >::map(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, flann::any, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > > const&) /usr/include/c++/9/bits/stl_map.h:205
    #17 0x55a045af5509 in flann::NNIndex<flann::L2_Simple<float> >::NNIndex(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, flann::any, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > > const&, flann::L2_Simple<float>) /usr/local/include/flann/algorithms/nn_index.h:85
    #18 0x55a045ae4f12 in flann::KDTreeSingleIndex<flann::L2_Simple<float> >::KDTreeSingleIndex(flann::Matrix<float> const&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, flann::any, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > > const&, flann::L2_Simple<float>) /usr/local/include/flann/algorithms/kdtree_single_index.h:100
    #19 0x55a045ada69e in flann::NNIndex<flann::L2_Simple<float> >* flann::create_index_<flann::KDTreeSingleIndex, flann::L2_Simple<float>, float>(flann::Matrix<float>, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, flann::any, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > > const&, flann::L2_Simple<float> const&, flann::enable_if<flann::valid_combination<flann::KDTreeSingleIndex, flann::L2_Simple<float>, float>::value, void>::type*) /usr/local/include/flann/algorithms/all_indices.h:132
    #20 0x55a045acf4cd in flann::NNIndex<flann::L2_Simple<float> >* flann::create_index_by_type<flann::L2_Simple<float> >(flann::flann_algorithm_t, flann::Matrix<flann::L2_Simple<float>::ElementType> const&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, flann::any, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > > const&, flann::L2_Simple<float> const&) /usr/local/include/flann/algorithms/all_indices.h:157
    #21 0x55a045aba93a in flann::Index<flann::L2_Simple<float> >::Index(flann::Matrix<float> const&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, flann::any, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flann::any> > > const&, flann::L2_Simple<float>) /usr/local/include/flann/flann.hpp:113
    #22 0x55a045aa3ce0 in pcl::KdTreeFLANN<pcl::PointNormal, flann::L2_Simple<float> >::setInputCloud(std::shared_ptr<pcl::PointCloud<pcl::PointNormal> const> const&, std::shared_ptr<std::vector<int, std::allocator<int> > const> const&) /usr/local/include/pcl-1.14/pcl/kdtree/impl/kdtree_flann.hpp:131
    #23 0x7f1bab5dbb39 in pcl::search::KdTree<pcl::PointNormal, pcl::KdTreeFLANN<pcl::PointNormal, flann::L2_Simple<float> > >::setInputCloud(std::shared_ptr<pcl::PointCloud<pcl::PointNormal> const> const&, std::shared_ptr<std::vector<int, std::allocator<int> > const> const&) (/usr/local/lib/libpcl_search.so.1.14+0x140b39)
    #24 0x55a04553a415 in pcl::Registration<pcl::PointNormal, pcl::PointNormal, float>::initCompute() /usr/local/include/pcl-1.14/pcl/registration/impl/registration.hpp:85
    #25 0x55a04551f263 in pcl::Registration<pcl::PointNormal, pcl::PointNormal, float>::align(pcl::PointCloud<pcl::PointNormal>&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&) /usr/local/include/pcl-1.14/pcl/registration/impl/registration.hpp:176
    #26 0x55a0455004de in pcl::Registration<pcl::PointNormal, pcl::PointNormal, float>::align(pcl::PointCloud<pcl::PointNormal>&) /usr/local/include/pcl-1.14/pcl/registration/impl/registration.hpp:168
    #27 0x55a045a98053 in HIKSymmICPTest::ICP() /home/tplink/factory_simulation/test_pcl/src/eval_on_hikvision.h:695
    #28 0x55a045a91723 in HIKICPEvalBase::Process() /home/tplink/factory_simulation/test_pcl/src/eval_on_hikvision.h:362
    #29 0x55a045a6f863 in EvalOnHikvision() /home/tplink/factory_simulation/test_pcl/src/eval_on_hikvision.cc:194
    #30 0x55a045497abc in main /home/tplink/factory_simulation/test_pcl/src/main.cc:47
    #31 0x7f1b98f2a082 in __libc_start_main ../csu/libc-start.c:308
    #32 0x55a04549741d in _start (/home/tplink/factory_simulation/test_pcl/build/pcl_test+0x791241d)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ../../../../src/libsanitizer/sanitizer_common/sanitizer_stackdepotbase.h:63 in __sanitizer::StackDepotBase<__sanitizer::StackDepotNode, 1, 20>::find(__sanitizer::StackDepotNode*, __sanitizer::StackTrace, unsigned int)
==9982==ABORTING

@YeHuanjie
Copy link
Contributor Author

The same code and input data do not always cause a crash.
It seems to happen only about 50% of the time.
There have also been instances where the crash occurs during the destruction of the kd-tree (specifically, free()).

@YeHuanjie
Copy link
Contributor Author

I rebuild pcl-1.14.0 with -DCMAKE_BUILD_TYPE=debug
crash occurs during calculating normals with kdtree
image

@mvieth
Copy link
Member

mvieth commented Dec 31, 2024

Can you upload your CMakeLists.txt and the PCLConfig.cmake from your computer? (zipped, for example)

@YeHuanjie
Copy link
Contributor Author

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
project(pcl_test)

IF (UNIX)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -g -O0 -ggdb -fopenmp -lpthread")
	# ASAN
	# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -fsanitize=undefined -fsanitize=leak -fsanitize-recover=all -fno-omit-frame-pointer -fno-stack-protector")
	# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=address -fsanitize=undefined -fsanitize=leak -fsanitize-recover=all -fno-omit-frame-pointer -fno-stack-protector")
ENDIF (UNIX)

find_package(PCL REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

find_package(VTK REQUIRED)
include_directories(${VTK_INCLUDE_DIRS})

find_package(nlohmann_json REQUIRED)
include_directories(${nlohmann_json_INCLUDE_DIR})

include_directories("src")
file(GLOB_RECURSE ALL_LIBRARY_HDRS "./src/*.h")
file(GLOB_RECURSE ALL_LIBRARY_SRCS "./src/*.cc")

file(GLOB_RECURSE MAIN "./src/main.cc")
list(REMOVE_ITEM ALL_LIBRARY_SRCS ${MAIN})

add_executable(pcl_test ${MAIN} ${ALL_LIBRARY_HDRS} ${ALL_LIBRARY_SRCS})

target_link_libraries(pcl_test ${PCL_LIBRARIES})
target_link_libraries(pcl_test ${OpenCV_LIBS})
target_link_libraries(pcl_test ${VTK_LIBRARIES})
target_link_libraries(pcl_test nlohmann_json::nlohmann_json)

#target_link_libraries(pcl_test
#	-fsanitize=address
#	-fsanitize=undefined
#	-fsanitize=leak
#	-fsanitize-recover=all
#	-fno-omit-frame-pointer
#	-fno-stack-protector)

install(TARGETS pcl_test RUNTIME DESTINATION bin)

PCLConfig.cmake

# ------------------------------------------------------------------------------------
# Helper to use PCL from outside project
#
# target_link_libraries(my_fabulous_target PCL_XXX_LIBRARIES) where XXX is the
# upper cased xxx from :
# 
# - common
# - kdtree
# - octree
# - search
# - sample_consensus
# - filters
# - 2d
# - geometry
# - io
# - features
# - ml
# - segmentation
# - visualization
# - surface
# - registration
# - keypoints
# - tracking
# - recognition
# - stereo
# - outofcore
# - people
#
# PCL_INCLUDE_DIRS is filled with PCL and available 3rdparty headers
# PCL_LIBRARY_DIRS is filled with PCL components libraries install directory and
# 3rdparty libraries paths
#
#                                   www.pointclouds.org
#------------------------------------------------------------------------------------

# Set default policy behavior similar to minimum requirement version
cmake_policy(VERSION 3.10)

# explicitly set policies we already support in newer cmake versions
if(POLICY CMP0074)
  # TODO: update *_ROOT variables to be PCL_*_ROOT or equivalent.
  # CMP0074 directly affects how Find* modules work and *_ROOT variables.  Since
  # this is a config file that will be consumed by parent projects with (likely)
  # NEW behavior, we need to push a policy stack.
  cmake_policy(SET CMP0074 NEW)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Modules")

### ---[ some useful macros
macro(pcl_report_not_found _reason)
  unset(PCL_FOUND)
  unset(PCL_LIBRARIES)
  unset(PCL_COMPONENTS)
  unset(PCL_INCLUDE_DIRS)
  unset(PCL_LIBRARY_DIRS)
  unset(PCL_DEFINITIONS)
  if(PCL_FIND_REQUIRED)
    message(FATAL_ERROR ${_reason})
  elseif(NOT PCL_FIND_QUIETLY)
    message(WARNING ${_reason})
  endif()
  return()
endmacro()

macro(pcl_message)
  if(NOT PCL_FIND_QUIETLY)
    message(${ARGN})
  endif()
endmacro()

# Remove duplicate libraries
macro(pcl_remove_duplicate_libraries _unfiltered_libraries _filtered_libraries)
  set(${_filtered_libraries})
  set(_debug_libraries)
  set(_optimized_libraries)
  set(_other_libraries)
  set(_waiting_for_debug 0)
  set(_waiting_for_optimized 0)
  set(_library_position -1)
  foreach(library ${${_unfiltered_libraries}})
    if("${library}" STREQUAL "debug")
      set(_waiting_for_debug 1)
    elseif("${library}" STREQUAL "optimized")
      set(_waiting_for_optimized 1)
    elseif(_waiting_for_debug)
      list(FIND _debug_libraries "${library}" library_position)
      if(library_position EQUAL -1)
        list(APPEND ${_filtered_libraries} debug ${library})
        list(APPEND _debug_libraries ${library})
      endif()
      set(_waiting_for_debug 0)
    elseif(_waiting_for_optimized)
      list(FIND _optimized_libraries "${library}" library_position)
      if(library_position EQUAL -1)
        list(APPEND ${_filtered_libraries} optimized ${library})
        list(APPEND _optimized_libraries ${library})
      endif()
      set(_waiting_for_optimized 0)
    else()
      list(FIND _other_libraries "${library}" library_position)
      if(library_position EQUAL -1)
        list(APPEND ${_filtered_libraries} ${library})
        list(APPEND _other_libraries ${library})
      endif()
    endif()
  endforeach()
endmacro()

### ---[ 3rd party libraries
macro(find_boost)
  if(PCL_ALL_IN_ONE_INSTALLER)
    set(BOOST_ROOT "${PCL_ROOT}/3rdParty/Boost")
  elseif(NOT BOOST_INCLUDEDIR)
    set(BOOST_INCLUDEDIR "/usr/include")
  endif()
  
  set(Boost_ADDITIONAL_VERSIONS
    "1.71.0" "1.71"
    "1.84.0" "1.84" "1.83.0" "1.83" "1.82.0" "1.82" "1.81.0" "1.81" "1.80.0" "1.80"
    "1.79.0" "1.79" "1.78.0" "1.78" "1.77.0" "1.77" "1.76.0" "1.76" "1.75.0" "1.75" 
    "1.74.0" "1.74" "1.73.0" "1.73" "1.72.0" "1.72" "1.71.0" "1.71" "1.70.0" "1.70"
    "1.69.0" "1.69" "1.68.0" "1.68" "1.67.0" "1.67" "1.66.0" "1.66" "1.65.1" "1.65.0" "1.65")
  
  find_package(Boost 1.65.0 ${QUIET_} COMPONENTS system filesystem iostreams serialization)

  set(BOOST_FOUND ${Boost_FOUND})
  set(BOOST_INCLUDE_DIRS "${Boost_INCLUDE_DIR}")
  set(BOOST_LIBRARY_DIRS "${Boost_LIBRARY_DIRS}")
  set(BOOST_LIBRARIES ${Boost_LIBRARIES})
  if(WIN32 AND NOT MINGW AND NOT "${BOOST_DEFINITIONS}" MATCHES "BOOST_ALL_NO_LIB")
    string(APPEND BOOST_DEFINITIONS -DBOOST_ALL_NO_LIB)
  endif()
endmacro()

macro(find_eigen3)
  if(PCL_ALL_IN_ONE_INSTALLER)
    set(Eigen3_DIR "${PCL_ROOT}/3rdParty/Eigen3/share/eigen3/cmake/")
  endif()
  find_package(Eigen3 3.3 REQUIRED NO_MODULE)
  if(NOT EIGEN3_FOUND AND Eigen3_FOUND)
    set(EIGEN3_FOUND ${Eigen3_FOUND})
  endif()
  # In very new Eigen versions, EIGEN3_INCLUDE_DIR(S) is not defined any more, only the target:
  if(TARGET Eigen3::Eigen)
    set(EIGEN3_LIBRARIES Eigen3::Eigen)
  endif()
endmacro()

#remove this as soon as qhull is shipped with FindQhull.cmake
macro(find_qhull)
  if(PCL_ALL_IN_ONE_INSTALLER)
    set(QHULL_ROOT "${PCL_ROOT}/3rdParty/Qhull")
  elseif(NOT QHULL_ROOT)
    get_filename_component(QHULL_ROOT "" PATH)
  endif()

  set(PCL_QHULL_REQUIRED_TYPE DONTCARE)
  find_package(Qhull)
endmacro()

#remove this as soon as libopenni is shipped with FindOpenni.cmake
macro(find_openni)
  if(PCL_FIND_QUIETLY)
    set(OpenNI_FIND_QUIETLY TRUE)
  endif()

  if(NOT OPENNI_ROOT AND ("" STREQUAL "TRUE"))
    set(OPENNI_INCLUDE_DIRS_HINT "")
    get_filename_component(OPENNI_LIBRARY_HINT "OPENNI_LIBRARY-NOTFOUND" PATH)
  endif()

  find_package(OpenNI)
endmacro()

#remove this as soon as libopenni2 is shipped with FindOpenni2.cmake
macro(find_openni2)
  if(PCL_FIND_QUIETLY)
    set(OpenNI2_FIND_QUIETLY TRUE)
  endif()

  if(NOT OPENNI2_ROOT AND ("" STREQUAL "TRUE"))
    set(OPENNI2_INCLUDE_DIRS_HINT "")
    get_filename_component(OPENNI2_LIBRARY_HINT "OPENNI2_LIBRARY-NOTFOUND" PATH)
  endif()

  find_package(OpenNI2)
endmacro()

#remove this as soon as the Ensenso SDK is shipped with FindEnsenso.cmake
macro(find_ensenso)
  if(PCL_FIND_QUIETLY)
    set(ensenso_FIND_QUIETLY TRUE)
  endif()

  if(NOT ENSENSO_ROOT AND ("" STREQUAL "TRUE"))
    get_filename_component(ENSENSO_ABI_HINT "ENSENSO_INCLUDE_DIR-NOTFOUND" PATH)
  endif()

  find_package(Ensenso)
endmacro()

#remove this as soon as the davidSDK is shipped with FinddavidSDK.cmake
macro(find_davidSDK)
  if(PCL_FIND_QUIETLY)
    set(DAVIDSDK_FIND_QUIETLY TRUE)
  endif()

  if(NOT davidSDK_ROOT AND ("" STREQUAL "TRUE"))
    get_filename_component(DAVIDSDK_ABI_HINT DAVIDSDK_INCLUDE_DIR-NOTFOUND PATH)
  endif()

  find_package(davidSDK)
endmacro()

macro(find_dssdk)
  if(PCL_FIND_QUIETLY)
    set(DSSDK_FIND_QUIETLY TRUE)
  endif()
  if(NOT DSSDK_DIR AND ("" STREQUAL "TRUE"))
    get_filename_component(DSSDK_DIR_HINT "" PATH)
  endif()

  find_package(DSSDK)
endmacro()

macro(find_rssdk)
  if(PCL_FIND_QUIETLY)
    set(RSSDK_FIND_QUIETLY TRUE)
  endif()
  if(NOT RSSDK_DIR AND ("" STREQUAL "TRUE"))
    get_filename_component(RSSDK_DIR_HINT "" PATH)
  endif()

  find_package(RSSDK)
endmacro()

macro(find_rssdk2)
  if(PCL_ALL_IN_ONE_INSTALLER)
    set(realsense2_DIR "${PCL_ROOT}/3rdParty/librealsense2/lib/cmake/realsense2" CACHE PATH "The directory containing realsense2Config.cmake")
  elseif(NOT realsense2_DIR)
    get_filename_component(realsense2_DIR "" PATH)
    set(realsense2_DIR "${realsense2_DIR}/lib/cmake/realsense2" CACHE PATH "The directory containing realsense2Config.cmake")
  endif()
  find_package(RSSDK2)
endmacro()

#remove this as soon as flann is shipped with FindFlann.cmake
macro(find_flann)
  if(PCL_ALL_IN_ONE_INSTALLER)
    set(FLANN_ROOT "${PCL_ROOT}/3rdParty/Flann")
  elseif(NOT FLANN_ROOT)
    set(FLANN_ROOT "/usr/local")
  endif()

  set(PCL_FLANN_REQUIRED_TYPE DONTCARE)
  find_package(FLANN)
endmacro()

macro(find_VTK)
  if(PCL_ALL_IN_ONE_INSTALLER AND NOT ANDROID)
    if(EXISTS "${PCL_ROOT}/3rdParty/VTK/lib/cmake")
      set(VTK_DIR "${PCL_ROOT}/3rdParty/VTK/lib/cmake/vtk-9.4" CACHE PATH "The directory containing VTKConfig.cmake")
    else()
      set(VTK_DIR "${PCL_ROOT}/3rdParty/VTK/lib/vtk-9.4" CACHE PATH "The directory containing VTKConfig.cmake")
    endif()
  elseif(NOT VTK_DIR AND NOT ANDROID)
    set(VTK_DIR "/usr/local/lib/cmake/vtk-9.4" CACHE PATH "The directory containing VTKConfig.cmake")
  endif()
  if(NOT ANDROID)
    find_package(VTK ${QUIET_} COMPONENTS ${PCL_VTK_COMPONENTS})
  endif()
endmacro()

macro(find_libusb)
  find_package(libusb)
endmacro()

macro(find_glew)
  find_package(GLEW)
endmacro()

# Finds each component external libraries if any
# The functioning is as following
# try to find _lib
# |--> _lib found ==> include the headers,
# |                   link to its library directories or include _lib_USE_FILE
# `--> _lib not found
#                   |--> _lib is optional ==> disable it (thanks to the guardians)
#                   |                         and warn
#                   `--> _lib is required
#                                       |--> component is required explicitly ==> error
#                                       `--> component is induced ==> warn and remove it
#                                                                     from the list

function(find_external_library _component _lib _is_optional)
  if("${_lib}" STREQUAL "boost")
    find_boost()
  elseif("${_lib}" STREQUAL "eigen3")
    find_eigen3()
  elseif("${_lib}" STREQUAL "flann")
    find_flann()
  elseif("${_lib}" STREQUAL "qhull")
    find_qhull()
  elseif("${_lib}" STREQUAL "openni")
    find_openni()
  elseif("${_lib}" STREQUAL "openni2")
    find_openni2()
  elseif("${_lib}" STREQUAL "ensenso")
    find_ensenso()
  elseif("${_lib}" STREQUAL "davidSDK")
    find_davidSDK()
  elseif("${_lib}" STREQUAL "dssdk")
    find_dssdk()
  elseif("${_lib}" STREQUAL "rssdk")
    find_rssdk()
  elseif("${_lib}" STREQUAL "rssdk2")
    find_rssdk2()
  elseif("${_lib}" STREQUAL "vtk")
    find_VTK()
  elseif("${_lib}" STREQUAL "libusb")
    find_libusb()
  elseif("${_lib}" STREQUAL "glew")
    find_glew()
  elseif("${_lib}" STREQUAL "opengl")
    find_package(OpenGL)
  elseif("${_lib}" STREQUAL "pcap")
    find_package(Pcap)
  elseif("${_lib}" STREQUAL "png")
    find_package(PNG)
  elseif("${_lib}" STREQUAL "OpenMP")
    find_package(OpenMP COMPONENTS CXX)
    # the previous find_package call sets OpenMP_CXX_LIBRARIES, but not OPENMP_LIBRARIES, which is used further down
    # we can link to the CMake target OpenMP::OpenMP_CXX by setting the following:
    set(OPENMP_LIBRARIES OpenMP::OpenMP_CXX)
  else()
    message(WARNING "${_lib} is not handled by find_external_library")
  endif()

  string(TOUPPER "${_component}" COMPONENT)
  string(TOUPPER "${_lib}" LIB)
  string(REGEX REPLACE "[.-]" "_" LIB ${LIB})
  if(${LIB}_FOUND)
    list(APPEND PCL_${COMPONENT}_INCLUDE_DIRS ${${LIB}_INCLUDE_DIRS})
    set(PCL_${COMPONENT}_INCLUDE_DIRS ${PCL_${COMPONENT}_INCLUDE_DIRS} PARENT_SCOPE)
    
    if(${LIB} MATCHES "VTK")
      if(${${LIB}_VERSION_MAJOR} GREATER_EQUAL 9)
        set(ISVTK9ORGREATER TRUE)
      endif()
    endif()
    
    if(${LIB}_USE_FILE AND NOT ISVTK9ORGREATER )
      include(${${LIB}_USE_FILE})
    else()
      list(APPEND PCL_${COMPONENT}_LIBRARY_DIRS "${${LIB}_LIBRARY_DIRS}")
      set(PCL_${COMPONENT}_LIBRARY_DIRS ${PCL_${COMPONENT}_LIBRARY_DIRS} PARENT_SCOPE)
    endif()
    if(${LIB}_LIBRARIES)
      list(APPEND PCL_${COMPONENT}_LINK_LIBRARIES "${${LIB}_LIBRARIES}")
      set(PCL_${COMPONENT}_LINK_LIBRARIES ${PCL_${COMPONENT}_LINK_LIBRARIES} PARENT_SCOPE)
      set(PCL_${LIB}_LIBRARIES ${${LIB}_LIBRARIES} PARENT_SCOPE) # Later appended to PCL_LIBRARIES
    endif()
    if(${LIB}_DEFINITIONS AND NOT ${LIB} STREQUAL "VTK")
      list(APPEND PCL_${COMPONENT}_DEFINITIONS ${${LIB}_DEFINITIONS})
      set(PCL_${COMPONENT}_DEFINITIONS ${PCL_${COMPONENT}_DEFINITIONS} PARENT_SCOPE)
    endif()
  else()
    if("${_is_optional}" STREQUAL "OPTIONAL")
      list(APPEND PCL_${COMPONENT}_DEFINITIONS "-DDISABLE_${LIB}")
      pcl_message("** WARNING ** ${_component} features related to ${_lib} will be disabled")
    elseif("${_is_optional}" STREQUAL "REQUIRED")
      if((NOT PCL_FIND_ALL) OR (PCL_FIND_ALL EQUAL 1))
        pcl_report_not_found("${_component} is required but ${_lib} was not found")
      elseif(PCL_FIND_ALL EQUAL 0)
        # raise error and remove _component from PCL_TO_FIND_COMPONENTS
        string(TOUPPER "${_component}" COMPONENT)
        pcl_message("** WARNING ** ${_component} will be disabled cause ${_lib} was not found")
        list(REMOVE_ITEM PCL_TO_FIND_COMPONENTS ${_component})
      endif()
    endif()
  endif()
endfunction()

macro(pcl_check_external_dependency _component)
endmacro()

#flatten dependencies recursivity is great \o/
macro(compute_dependencies TO_FIND_COMPONENTS)
  foreach(component ${${TO_FIND_COMPONENTS}})
    set(pcl_component pcl_${component})
    if(${pcl_component}_int_dep AND (NOT PCL_FIND_ALL))
      foreach(dependency ${${pcl_component}_int_dep})
        list(FIND ${TO_FIND_COMPONENTS} ${component} pos)
        list(FIND ${TO_FIND_COMPONENTS} ${dependency} found)
        if(found EQUAL -1)
          set(pcl_dependency pcl_${dependency})
          if(${pcl_dependency}_int_dep)
            list(INSERT ${TO_FIND_COMPONENTS} ${pos} ${dependency})
            if(pcl_${dependency}_ext_dep)
              list(APPEND pcl_${component}_ext_dep ${pcl_${dependency}_ext_dep})
            endif()
            if(pcl_${dependency}_opt_dep)
              list(APPEND pcl_${component}_opt_dep ${pcl_${dependency}_opt_dep})
            endif()
            compute_dependencies(${TO_FIND_COMPONENTS})
          else()
            list(INSERT ${TO_FIND_COMPONENTS} 0 ${dependency})
          endif()
        endif()
      endforeach()
    endif()
  endforeach()
endmacro()

### ---[ Find PCL

if(PCL_FIND_QUIETLY)
  set(QUIET_ QUIET)
else()
  set(QUIET_)
endif()

find_package(PkgConfig QUIET)

file(TO_CMAKE_PATH "${PCL_DIR}" PCL_DIR)
if(WIN32 AND NOT MINGW)
# PCLConfig.cmake is installed to PCL_ROOT/cmake
  get_filename_component(PCL_ROOT "${PCL_DIR}" PATH)
  if(EXISTS "${PCL_ROOT}/3rdParty")
    set(PCL_ALL_IN_ONE_INSTALLER ON)
  endif()
else()
# PCLConfig.cmake is installed to PCL_ROOT/share/pcl-x.y
  get_filename_component(PCL_ROOT "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE)
endif()

# check whether PCLConfig.cmake is found into a PCL installation or in a build tree
if(EXISTS "${PCL_ROOT}/include/pcl-${PCL_VERSION_MAJOR}.${PCL_VERSION_MINOR}/pcl/pcl_config.h")
  # Found a PCL installation
  # pcl_message("Found a PCL installation")
  set(PCL_CONF_INCLUDE_DIR "${PCL_ROOT}/include/pcl-${PCL_VERSION_MAJOR}.${PCL_VERSION_MINOR}")
  set(PCL_LIBRARY_DIRS "${PCL_ROOT}/lib")
elseif(EXISTS "${PCL_ROOT}/include/pcl/pcl_config.h")
  # Found a non-standard (likely ANDROID) PCL installation
  # pcl_message("Found a PCL installation")
  set(PCL_CONF_INCLUDE_DIR "${PCL_ROOT}/include")
  set(PCL_LIBRARY_DIRS "${PCL_ROOT}/lib")
elseif(EXISTS "${PCL_DIR}/include/pcl/pcl_config.h")
  # Found PCLConfig.cmake in a build tree of PCL
  # pcl_message("PCL found into a build tree.")
  set(PCL_CONF_INCLUDE_DIR "${PCL_DIR}/include") # for pcl_config.h
  set(PCL_LIBRARY_DIRS "${PCL_DIR}/lib")
else()
  pcl_report_not_found("PCL can not be found on this machine")
endif()

set(PCL_INCLUDE_DIRS "${PCL_CONF_INCLUDE_DIR}")

#set a suffix for debug libraries
set(PCL_DEBUG_SUFFIX "")
set(PCL_RELEASE_SUFFIX "")

set(PCL_SHARED_LIBS "ON")

#set SSE flags used compiling PCL
list(APPEND PCL_DEFINITIONS  -DEIGEN_HAS_CXX17_OVERALIGN=0)
list(APPEND PCL_COMPILE_OPTIONS -msse4.2 -mfpmath=sse -march=native)

#set AVX flags used compiling PCL
list(APPEND PCL_COMPILE_OPTIONS -mavx2)

set(pcl_all_components  common kdtree octree search sample_consensus filters 2d geometry io features ml segmentation visualization surface registration keypoints tracking recognition stereo outofcore people)
list(LENGTH pcl_all_components PCL_NB_COMPONENTS)

#list each component dependencies IN PCL
set(pcl_kdtree_int_dep common )
set(pcl_octree_int_dep common )
set(pcl_search_int_dep common kdtree octree )
set(pcl_sample_consensus_int_dep common search )
set(pcl_filters_int_dep common sample_consensus search kdtree octree )
set(pcl_2d_int_dep common filters )
set(pcl_geometry_int_dep common )
set(pcl_io_int_dep common octree )
set(pcl_features_int_dep common search kdtree octree filters 2d )
set(pcl_ml_int_dep common )
set(pcl_segmentation_int_dep common geometry search sample_consensus kdtree octree features filters ml )
set(pcl_visualization_int_dep common io kdtree geometry search octree )
set(pcl_surface_int_dep common search kdtree octree )
set(pcl_registration_int_dep common octree kdtree search sample_consensus features filters )
set(pcl_keypoints_int_dep common search kdtree octree features filters )
set(pcl_tracking_int_dep common search kdtree filters octree )
set(pcl_recognition_int_dep common io search kdtree octree features filters registration sample_consensus ml )
set(pcl_stereo_int_dep common io )
set(pcl_outofcore_int_dep common io filters octree visualization )
set(pcl_people_int_dep common kdtree search sample_consensus filters io visualization geometry segmentation octree )


#list each component external dependencies (ext means mandatory and opt means optional)
set(pcl_common_ext_dep eigen3 boost )
set(pcl_kdtree_ext_dep flann )
set(pcl_search_ext_dep flann )
set(pcl_io_ext_dep boost eigen3 )
set(pcl_visualization_ext_dep vtk )


set(pcl_filters_opt_dep OpenMP )
set(pcl_2d_opt_dep vtk )
set(pcl_io_opt_dep pcap png vtk libusb OpenMP )
set(pcl_features_opt_dep OpenMP )
set(pcl_segmentation_opt_dep OpenMP )
set(pcl_visualization_opt_dep )
set(pcl_surface_opt_dep qhull vtk OpenMP )
set(pcl_registration_opt_dep OpenMP )
set(pcl_keypoints_opt_dep OpenMP )
set(pcl_tracking_opt_dep OpenMP )


# VTK components required by PCL
set(PCL_VTK_COMPONENTS "ChartsCore;CommonColor;CommonComputationalGeometry;CommonCore;CommonDataModel;CommonExecutionModel;CommonMath;CommonMisc;CommonTransforms;FiltersCore;FiltersExtraction;FiltersGeneral;FiltersGeometry;FiltersModeling;FiltersSources;ImagingCore;ImagingSources;InteractionImage;InteractionStyle;InteractionWidgets;IOCore;IOGeometry;IOImage;IOLegacy;IOPLY;RenderingAnnotation;RenderingCore;RenderingContext2D;RenderingLOD;RenderingFreeType;ViewsCore;ViewsContext2D;RenderingOpenGL2;RenderingContextOpenGL2")

set(pcl_header_only_components 2d cuda_common geometry gpu_tracking modeler in_hand_scanner point_cloud_editor cloud_composer)

include(FindPackageHandleStandardArgs)

#check if user provided a list of components
#if no components at all or full list is given set PCL_FIND_ALL
if(PCL_FIND_COMPONENTS)
  list(LENGTH PCL_FIND_COMPONENTS PCL_FIND_COMPONENTS_LENGTH)
  if(PCL_FIND_COMPONENTS_LENGTH EQUAL PCL_NB_COMPONENTS)
    set(PCL_TO_FIND_COMPONENTS ${pcl_all_components})
    set(PCL_FIND_ALL 1)
  else()
    set(PCL_TO_FIND_COMPONENTS ${PCL_FIND_COMPONENTS})
  endif()
else()
  set(PCL_TO_FIND_COMPONENTS ${pcl_all_components})
  set(PCL_FIND_ALL 1)
endif()

compute_dependencies(PCL_TO_FIND_COMPONENTS)

# We do not need to find components that have been found already, e.g. during previous invocation
# of find_package(PCL). Filter them out.
foreach(component ${PCL_TO_FIND_COMPONENTS})
  string(TOUPPER "${component}" COMPONENT)
  if(NOT PCL_${COMPONENT}_FOUND)
    list(APPEND _PCL_TO_FIND_COMPONENTS ${component})
  endif()
endforeach()
set(PCL_TO_FIND_COMPONENTS ${_PCL_TO_FIND_COMPONENTS})
unset(_PCL_TO_FIND_COMPONENTS)

if(NOT PCL_TO_FIND_COMPONENTS)
  return()
endif()

# compute external dependencies per component
foreach(component ${PCL_TO_FIND_COMPONENTS})
    foreach(opt ${pcl_${component}_opt_dep})
      find_external_library(${component} ${opt} OPTIONAL)
    endforeach()
    foreach(ext ${pcl_${component}_ext_dep})
      find_external_library(${component} ${ext} REQUIRED)
    endforeach()
endforeach()

foreach(component ${PCL_TO_FIND_COMPONENTS})
  set(pcl_component pcl_${component})
  string(TOUPPER "${component}" COMPONENT)

  pcl_message(STATUS "looking for PCL_${COMPONENT}")

  string(REGEX REPLACE "^cuda_(.*)$" "\\1" cuda_component "${component}")
  string(REGEX REPLACE "^gpu_(.*)$" "\\1" gpu_component "${component}")

  find_path(PCL_${COMPONENT}_INCLUDE_DIR
    NAMES pcl/${component}
          pcl/apps/${component}
          pcl/cuda/${cuda_component} pcl/cuda/${component}
          pcl/gpu/${gpu_component} pcl/gpu/${component}
    HINTS ${PCL_INCLUDE_DIRS}
    PATH_SUFFIXES
          ${component}/include
          apps/${component}/include
          cuda/${cuda_component}/include
          gpu/${gpu_component}/include
    DOC "path to ${component} headers"
    NO_DEFAULT_PATH)
  mark_as_advanced(PCL_${COMPONENT}_INCLUDE_DIR)

  if(PCL_${COMPONENT}_INCLUDE_DIR)
    list(APPEND PCL_${COMPONENT}_INCLUDE_DIRS "${PCL_${COMPONENT}_INCLUDE_DIR}")
  else()
    #pcl_message("No include directory found for pcl_${component}.")
  endif()

  set(FPHSA_NAME_MISMATCHED 1) # Suppress warnings, see https://cmake.org/cmake/help/v3.17/module/FindPackageHandleStandardArgs.html
  # Skip find_library for header only modules
  list(FIND pcl_header_only_components ${component} _is_header_only)
  if(_is_header_only EQUAL -1)
    find_library(PCL_${COMPONENT}_LIBRARY ${pcl_component}${PCL_RELEASE_SUFFIX}
      HINTS ${PCL_LIBRARY_DIRS}
      DOC "path to ${pcl_component} library"
      NO_DEFAULT_PATH)
    get_filename_component(${component}_library_path
      ${PCL_${COMPONENT}_LIBRARY}
      PATH)
    mark_as_advanced(PCL_${COMPONENT}_LIBRARY)

    find_library(PCL_${COMPONENT}_LIBRARY_DEBUG ${pcl_component}${PCL_DEBUG_SUFFIX}
      HINTS ${PCL_LIBRARY_DIRS}
      DOC "path to ${pcl_component} library debug"
      NO_DEFAULT_PATH)
    mark_as_advanced(PCL_${COMPONENT}_LIBRARY_DEBUG)

    if(PCL_${COMPONENT}_LIBRARY_DEBUG)
      get_filename_component(${component}_library_path_debug
        ${PCL_${COMPONENT}_LIBRARY_DEBUG}
        PATH)
    endif()

    # Restrict this to Windows users
    if(NOT PCL_${COMPONENT}_LIBRARY AND WIN32)
      # might be debug only
      set(PCL_${COMPONENT}_LIBRARY ${PCL_${COMPONENT}_LIBRARY_DEBUG})
    endif()

    find_package_handle_standard_args(PCL_${COMPONENT} DEFAULT_MSG
      PCL_${COMPONENT}_LIBRARY PCL_${COMPONENT}_INCLUDE_DIR)
  else()
    find_package_handle_standard_args(PCL_${COMPONENT} DEFAULT_MSG
      PCL_${COMPONENT}_INCLUDE_DIR)
  endif()
  unset(FPHSA_NAME_MISMATCHED)

  if(PCL_${COMPONENT}_FOUND)
    if(NOT "${PCL_${COMPONENT}_INCLUDE_DIRS}" STREQUAL "")
      set(_filtered "")
      foreach(_inc ${PCL_${COMPONENT}_INCLUDE_DIRS})
        if(EXISTS ${_inc})
          list(APPEND _filtered "${_inc}")
        endif()
      endforeach()
      list(REMOVE_DUPLICATES _filtered)
      set(PCL_${COMPONENT}_INCLUDE_DIRS ${_filtered})
      list(APPEND PCL_INCLUDE_DIRS ${_filtered})
    endif()
    mark_as_advanced(PCL_${COMPONENT}_INCLUDE_DIRS)
    if(_is_header_only EQUAL -1)
      list(APPEND PCL_DEFINITIONS ${PCL_${COMPONENT}_DEFINITIONS})
      list(APPEND PCL_LIBRARY_DIRS ${component_library_path})
      if(PCL_${COMPONENT}_LIBRARY_DEBUG)
        list(APPEND PCL_LIBRARY_DIRS ${component_library_path_debug})
      endif()
      list(APPEND PCL_COMPONENTS ${pcl_component})
      mark_as_advanced(PCL_${COMPONENT}_LIBRARY PCL_${COMPONENT}_LIBRARY_DEBUG)
    endif()
    # Append internal dependencies
    foreach(int_dep ${pcl_${component}_int_dep})
      string(TOUPPER "${int_dep}" INT_DEP)
      if(PCL_${INT_DEP}_FOUND)
        list(APPEND PCL_${COMPONENT}_INCLUDE_DIRS ${PCL_${INT_DEP}_INCLUDE_DIRS})
        if(PCL_${INT_DEP}_LIBRARIES)
          list(APPEND PCL_${COMPONENT}_LINK_LIBRARIES "${PCL_${INT_DEP}_LIBRARIES}")
        endif()
      endif()
    endforeach()
    if(_is_header_only EQUAL -1)
      add_library(${pcl_component} SHARED IMPORTED)
      if(PCL_${COMPONENT}_LIBRARY_DEBUG)
        set_target_properties(${pcl_component}
          PROPERTIES
            IMPORTED_CONFIGURATIONS "RELEASE;DEBUG"
            IMPORTED_LOCATION_RELEASE "${PCL_${COMPONENT}_LIBRARY}"
            IMPORTED_LOCATION_DEBUG "${PCL_${COMPONENT}_LIBRARY_DEBUG}"
            IMPORTED_IMPLIB_RELEASE "${PCL_${COMPONENT}_LIBRARY}"
            IMPORTED_IMPLIB_DEBUG "${PCL_${COMPONENT}_LIBRARY_DEBUG}"
        )
      else()
        set_target_properties(${pcl_component}
          PROPERTIES
            IMPORTED_LOCATION "${PCL_${COMPONENT}_LIBRARY}"
            IMPORTED_IMPLIB "${PCL_${COMPONENT}_LIBRARY}"
        )
      endif()
    else() # header-only
      add_library(${pcl_component} INTERFACE IMPORTED)
    endif()

    foreach(def ${PCL_DEFINITIONS})
      string(REPLACE " " ";" def2 ${def})
      string(REGEX REPLACE "^-D" "" def3 "${def2}")
      list(APPEND definitions ${def3})
    endforeach()
    if(CMAKE_VERSION VERSION_LESS 3.11)
      set_target_properties(${pcl_component}
        PROPERTIES
          INTERFACE_COMPILE_DEFINITIONS "${definitions}"
          INTERFACE_COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:CXX>:${PCL_COMPILE_OPTIONS}>"
          INTERFACE_COMPILE_FEATURES "cxx_std_14"
          INTERFACE_INCLUDE_DIRECTORIES "${PCL_${COMPONENT}_INCLUDE_DIRS};${PCL_CONF_INCLUDE_DIR}"
          INTERFACE_LINK_LIBRARIES "${PCL_${COMPONENT}_LINK_LIBRARIES}"
      )
    else()
      set_target_properties(${pcl_component}
        PROPERTIES
          INTERFACE_COMPILE_DEFINITIONS "${definitions}"
          INTERFACE_COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:CXX>:${PCL_COMPILE_OPTIONS}>"
          INTERFACE_COMPILE_FEATURES "cxx_std_14"
          INTERFACE_INCLUDE_DIRECTORIES "${PCL_${COMPONENT}_INCLUDE_DIRS};${PCL_CONF_INCLUDE_DIR}"
      )
      # If possible, we use target_link_libraries to avoid problems with link-type keywords,
      # see https://github.com/PointCloudLibrary/pcl/issues/2989
      # target_link_libraries on imported libraries is supported only since CMake 3.11
      target_link_libraries(${pcl_component} INTERFACE ${PCL_${COMPONENT}_LINK_LIBRARIES})
    endif()
    set(PCL_${COMPONENT}_LIBRARIES ${pcl_component})
  endif()
endforeach()

if(NOT "${PCL_INCLUDE_DIRS}" STREQUAL "")
  list(REMOVE_DUPLICATES PCL_INCLUDE_DIRS)
endif()

if(NOT "${PCL_LIBRARY_DIRS}" STREQUAL "")
  list(REMOVE_DUPLICATES PCL_LIBRARY_DIRS)
endif()

if(NOT "${PCL_DEFINITIONS}" STREQUAL "")
  list(REMOVE_DUPLICATES PCL_DEFINITIONS)
endif()

pcl_remove_duplicate_libraries(PCL_COMPONENTS PCL_LIBRARIES)

# Add 3rd party libraries, as user code might include our .HPP implementations
list(APPEND PCL_LIBRARIES ${PCL_BOOST_LIBRARIES} ${PCL_OPENNI_LIBRARIES} ${PCL_OPENNI2_LIBRARIES} ${PCL_ENSENSO_LIBRARIES} ${PCL_davidSDK_LIBRARIES} ${PCL_DSSDK_LIBRARIES} ${PCL_RSSDK_LIBRARIES} ${PCL_RSSDK2_LIBRARIES} ${PCL_VTK_LIBRARIES})
if (TARGET FLANN::FLANN)
  list(APPEND PCL_LIBRARIES FLANN::FLANN)
endif()

if(TARGET QHULL::QHULL)
    list(APPEND PCL_LIBRARIES QHULL::QHULL)
endif()

find_package_handle_standard_args(PCL DEFAULT_MSG PCL_LIBRARIES PCL_INCLUDE_DIRS)
mark_as_advanced(PCL_LIBRARIES PCL_INCLUDE_DIRS PCL_LIBRARY_DIRS)

@mvieth
Copy link
Member

mvieth commented Dec 31, 2024

And the output of VERBOSE=1 make from your project, please. I would like to see the flags given to the compiler.

@YeHuanjie
Copy link
Contributor Author

YeHuanjie commented Dec 31, 2024

build:

/usr/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_SERIALIZATION_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DDIY_NO_THREADS -DEIGEN_HAS_CXX17_OVERALIGN=0 -DFMT_SHARED -DGLAD_API_CALL_EXPORT -DH5_BUILT_AS_DYNAMIC_LIB -DJSON_DIAGNOSTICS=0 -DJSON_USE_IMPLICIT_CONVERSIONS=1 -DVTK_HAS_OGGTHEORA_SUPPORT -Dkiss_fft_scalar=double -Dqh_QHpointer -I/home/tplink/factory_simulation/test_pcl/src -isystem /usr/local/include/eigen3 -isystem /usr/local/include/pcl-1.14 -isystem /usr/local/include/opencv4 -isystem /usr/local/include/vtk-9.4 -isystem /usr/local/include/vtk-9.4/token -isystem /usr/local/include/vtk-9.4/vtknlohmannjson/include -isystem /usr/local/include/vtk-9.4/vtknlohmannjson -isystem /usr/local/include/vtk-9.4/vtkkissfft -isystem /usr/local/include/vtk-9.4/vtkfreetype/include -isystem /usr/local/include/vtk-9.4/vtkzlib -isystem /usr/local/include/vtk-9.4/vtkglad -isystem /usr/local/include/vtk-9.4/vtkloguru -isystem /usr/local/include/vtk-9.4/vtkfmt -isystem /usr/local/include/vtk-9.4/vtkhdf5 -isystem /usr/local/include/vtk-9.4/vtkhdf5/src -isystem /usr/local/include/vtk-9.4/vtkhdf5/hl/src -isystem /usr/local/include/vtk-9.4/vtktheora -isystem /usr/local/include/vtk-9.4/vtkogg/include -isystem /usr/local/include/vtk-9.4/vtkogg -isystem /usr/local/include/vtk-9.4/vtknetcdf -isystem /usr/local/include/vtk-9.4/vtkjsoncpp -isystem /usr/local/include/vtk-9.4/vtkioss -isystem /usr/local/include/vtk-9.4/vtkexodusII -isystem /usr/local/include/vtk-9.4/vtklibxml2/include -isystem /usr/local/include/vtk-9.4/vtklibxml2 -isystem /usr/local/include/vtk-9.4/vtkpng -isystem /usr/local/include/vtk-9.4/vtkgl2ps -isystem /usr/local/include/vtk-9.4/vtkpugixml -isystem /usr/local/include/vtk-9.4/vtklibproj/src -isystem /usr/local/include/vtk-9.4/vtksqlite -isystem /usr/local/include/vtk-9.4/vtkexpat -isystem /usr/local/include/vtk-9.4/vtklz4 -isystem /usr/local/include/vtk-9.4/vtklzma -isystem /usr/local/include/vtk-9.4/vtkjpeg -isystem /usr/local/include/vtk-9.4/vtkmetaio -isystem /usr/local/include/vtk-9.4/vtktiff/libtiff -isystem /usr/local/include/vtk-9.4/vtkverdict -isystem /usr/local/include/vtk-9.4/vtkdoubleconversion -std=c++17 -g -O0 -ggdb -fopenmp -lpthread -msse4.2 -mfpmath=sse -march=native -mavx2 -fopenmp -MD -MT CMakeFiles/pcl_test.dir/src/icp_test_on_ours.cc.o -MF CMakeFiles/pcl_test.dir/src/icp_test_on_ours.cc.o.d -o CMakeFiles/pcl_test.dir/src/icp_test_on_ours.cc.o -c /home/tplink/factory_simulation/test_pcl/src/icp_test_on_ours.cc

@YeHuanjie
Copy link
Contributor Author

YeHuanjie commented Dec 31, 2024

link :

/usr/local/bin/cmake -E cmake_link_script CMakeFiles/pcl_test.dir/link.txt --verbose=1
/usr/bin/c++  -std=c++17 -g -O0 -ggdb -fopenmp -lpthread CMakeFiles/pcl_test.dir/src/main.cc.o CMakeFiles/pcl_test.dir/src/align_incomplete_models_test.cc.o CMakeFiles/pcl_test.dir/src/align_models_test.cc.o CMakeFiles/pcl_test.dir/src/batch_test_tless.cc.o CMakeFiles/pcl_test.dir/src/common/time.cc.o CMakeFiles/pcl_test.dir/src/eval_on_hikvision.cc.o CMakeFiles/pcl_test.dir/src/eval_on_itodd.cc.o CMakeFiles/pcl_test.dir/src/eval_on_tless.cc.o CMakeFiles/pcl_test.dir/src/icp_test_on_lm_pbr.cc.o CMakeFiles/pcl_test.dir/src/icp_test_on_ours.cc.o CMakeFiles/pcl_test.dir/src/icp_test_on_tless.cc.o CMakeFiles/pcl_test.dir/src/icp_test_on_tless_pbr.cc.o CMakeFiles/pcl_test.dir/src/interactive_icp_test.cc.o CMakeFiles/pcl_test.dir/src/midpoint_subdivision.cc.o CMakeFiles/pcl_test.dir/src/pcl_demo.cc.o CMakeFiles/pcl_test.dir/src/pcl_official_icp_test.cc.o CMakeFiles/pcl_test.dir/src/pcl_official_pose_estimation.cc.o CMakeFiles/pcl_test.dir/src/point_to_plane_icp_test_on_lm_bop.cc.o CMakeFiles/pcl_test.dir/src/point_to_plane_icp_unit_meter_test_on_lm_bop.cc.o CMakeFiles/pcl_test.dir/src/point_to_point_icp_test_on_lm_bop.cc.o CMakeFiles/pcl_test.dir/src/transform/rigid_transform.cc.o CMakeFiles/pcl_test.dir/src/transform/timestamped_transform.cc.o CMakeFiles/pcl_test.dir/src/transform/transform.cc.o CMakeFiles/pcl_test.dir/src/utils.cc.o -o pcl_test   -L/usr/local/lib  -Wl,-rpath,/usr/local/lib: /usr/local/lib/libpcl_surface.so /usr/local/lib/libpcl_keypoints.so /usr/local/lib/libpcl_tracking.so /usr/local/lib/libpcl_recognition.so /usr/local/lib/libpcl_stereo.so /usr/local/lib/libpcl_outofcore.so /usr/local/lib/libpcl_people.so /usr/lib/x86_64-linux-gnu/libboost_system.so.1.71.0 /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.71.0 /usr/lib/x86_64-linux-gnu/libboost_iostreams.so.1.71.0 /usr/lib/x86_64-linux-gnu/libboost_serialization.so.1.71.0 /usr/local/lib/libflann_cpp.so.1.9.2 /usr/lib/x86_64-linux-gnu/libqhull_r.so /usr/local/lib/libopencv_highgui.so.4.10.0 /usr/local/lib/libopencv_ml.so.4.10.0 /usr/local/lib/libopencv_objdetect.so.4.10.0 /usr/local/lib/libopencv_photo.so.4.10.0 /usr/local/lib/libopencv_stitching.so.4.10.0 /usr/local/lib/libopencv_video.so.4.10.0 /usr/local/lib/libopencv_videoio.so.4.10.0 /usr/local/lib/libvtkWrappingTools-9.4.so.9.4 /usr/local/lib/libvtkViewsInfovis-9.4.so.9.4 /usr/local/lib/libvtkTestingRendering-9.4.so.9.4 /usr/local/lib/libvtkTestingCore-9.4.so.9.4 /usr/local/lib/libvtkRenderingLabel-9.4.so.9.4 /usr/local/lib/libvtkRenderingLICOpenGL2-9.4.so.9.4 /usr/local/lib/libvtkRenderingImage-9.4.so.9.4 /usr/local/lib/libvtkRenderingCellGrid-9.4.so.9.4 /usr/local/lib/libvtkRenderingVolumeOpenGL2-9.4.so.9.4 /usr/local/lib/libvtkIOVeraOut-9.4.so.9.4 /usr/local/lib/libvtkIOTecplotTable-9.4.so.9.4 /usr/local/lib/libvtkIOSegY-9.4.so.9.4 /usr/local/lib/libvtkIOParallelXML-9.4.so.9.4 /usr/local/lib/libvtkIOOggTheora-9.4.so.9.4 /usr/local/lib/libvtktheora-9.4.so.9.4 /usr/local/lib/libvtkogg-9.4.so.9.4 /usr/local/lib/libvtkIONetCDF-9.4.so.9.4 /usr/local/lib/libvtkIOMotionFX-9.4.so.9.4 /usr/local/lib/libvtkIOParallel-9.4.so.9.4 /usr/local/lib/libvtkIOMINC-9.4.so.9.4 /usr/local/lib/libvtkIOLSDyna-9.4.so.9.4 /usr/local/lib/libvtkIOImport-9.4.so.9.4 /usr/local/lib/libvtkIOIOSS-9.4.so.9.4 /usr/local/lib/libvtkioss-9.4.so.9.4 /usr/local/lib/libvtkIOHDF-9.4.so.9.4 /usr/local/lib/libvtkIOFLUENTCFF-9.4.so.9.4 /usr/local/lib/libvtkIOVideo-9.4.so.9.4 /usr/local/lib/libvtkIOMovie-9.4.so.9.4 /usr/local/lib/libvtkIOFDS-9.4.so.9.4 /usr/local/lib/libvtkIOInfovis-9.4.so.9.4 /usr/local/lib/libvtklibxml2-9.4.so.9.4 /usr/local/lib/libvtkIOExportPDF-9.4.so.9.4 /usr/local/lib/libvtklibharu-9.4.so.9.4 /usr/local/lib/libvtkIOExportGL2PS-9.4.so.9.4 /usr/local/lib/libvtkRenderingGL2PSOpenGL2-9.4.so.9.4 /usr/local/lib/libvtkgl2ps-9.4.so.9.4 /usr/local/lib/libvtkIOExodus-9.4.so.9.4 /usr/local/lib/libvtkIOEngys-9.4.so.9.4 /usr/local/lib/libvtkIOEnSight-9.4.so.9.4 /usr/local/lib/libvtkIOERF-9.4.so.9.4 /usr/local/lib/libvtkIOCityGML-9.4.so.9.4 /usr/local/lib/libvtkIOChemistry-9.4.so.9.4 /usr/local/lib/libvtkIOCesium3DTiles-9.4.so.9.4 /usr/local/lib/libvtkIOCONVERGECFD-9.4.so.9.4 /usr/local/lib/libvtkIOCGNSReader-9.4.so.9.4 /usr/local/lib/libvtkIOAsynchronous-9.4.so.9.4 /usr/local/lib/libvtkIOExport-9.4.so.9.4 /usr/local/lib/libvtkRenderingVtkJS-9.4.so.9.4 /usr/local/lib/libvtkRenderingSceneGraph-9.4.so.9.4 /usr/local/lib/libvtkIOAMR-9.4.so.9.4 /usr/local/lib/libvtkInfovisLayout-9.4.so.9.4 /usr/local/lib/libvtkImagingStencil-9.4.so.9.4 /usr/local/lib/libvtkImagingStatistics-9.4.so.9.4 /usr/local/lib/libvtkImagingMorphological-9.4.so.9.4 /usr/local/lib/libvtkImagingMath-9.4.so.9.4 /usr/local/lib/libvtkImagingFourier-9.4.so.9.4 /usr/local/lib/libvtkIOSQL-9.4.so.9.4 /usr/local/lib/libvtkGeovisCore-9.4.so.9.4 /usr/local/lib/libvtkFiltersTopology-9.4.so.9.4 /usr/local/lib/libvtkFiltersTensor-9.4.so.9.4 /usr/local/lib/libvtkFiltersSelection-9.4.so.9.4 /usr/local/lib/libvtkFiltersSMP-9.4.so.9.4 /usr/local/lib/libvtkFiltersProgrammable-9.4.so.9.4 /usr/local/lib/libvtkFiltersPoints-9.4.so.9.4 /usr/local/lib/libvtkFiltersParallelImaging-9.4.so.9.4 /usr/local/lib/libvtkFiltersTemporal-9.4.so.9.4 /usr/local/lib/libvtkFiltersImaging-9.4.so.9.4 /usr/local/lib/libvtkFiltersGeometryPreview-9.4.so.9.4 /usr/local/lib/libvtkFiltersGeneric-9.4.so.9.4 /usr/local/lib/libvtkFiltersFlowPaths-9.4.so.9.4 /usr/local/lib/libvtkFiltersAMR-9.4.so.9.4 /usr/local/lib/libvtkFiltersParallel-9.4.so.9.4 /usr/local/lib/libvtkDomainsChemistryOpenGL2-9.4.so.9.4 /usr/local/lib/libvtkDomainsChemistry-9.4.so.9.4 /usr/local/lib/libpcl_registration.so /usr/local/lib/libpcl_segmentation.so /usr/local/lib/libpcl_features.so /usr/local/lib/libpcl_filters.so /usr/local/lib/libpcl_sample_consensus.so /usr/local/lib/libpcl_ml.so /usr/local/lib/libpcl_visualization.so /usr/local/lib/libpcl_search.so /usr/local/lib/libpcl_kdtree.so /usr/local/lib/libpcl_io.so /usr/local/lib/libpcl_octree.so /usr/lib/x86_64-linux-gnu/libpthread.so /usr/lib/gcc/x86_64-linux-gnu/9/libgomp.so /usr/lib/x86_64-linux-gnu/libpthread.so /usr/lib/gcc/x86_64-linux-gnu/9/libgomp.so /usr/lib/x86_64-linux-gnu/libpng.so /usr/lib/x86_64-linux-gnu/libz.so /usr/local/lib/libvtkInteractionImage-9.4.so.9.4 /usr/local/lib/libvtkIOPLY-9.4.so.9.4 /usr/local/lib/libvtkRenderingLOD-9.4.so.9.4 /usr/local/lib/libvtkViewsContext2D-9.4.so.9.4 /usr/local/lib/libvtkRenderingContextOpenGL2-9.4.so.9.4 /usr/local/lib/libpcl_common.so /usr/lib/x86_64-linux-gnu/libboost_system.so.1.71.0 /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.71.0 /usr/lib/x86_64-linux-gnu/libboost_iostreams.so.1.71.0 /usr/lib/x86_64-linux-gnu/libboost_serialization.so.1.71.0 -Wl,-whole-archive /usr/local/lib/libflann_cpp_s.a /usr/lib/x86_64-linux-gnu/liblz4.so -Wl,-no-whole-archive /usr/local/lib/libopencv_imgcodecs.so.4.10.0 /usr/local/lib/libopencv_calib3d.so.4.10.0 /usr/local/lib/libopencv_dnn.so.4.10.0 /usr/local/lib/libopencv_features2d.so.4.10.0 /usr/local/lib/libopencv_flann.so.4.10.0 /usr/local/lib/libopencv_imgproc.so.4.10.0 /usr/local/lib/libopencv_core.so.4.10.0 /usr/local/lib/libvtkChartsCore-9.4.so.9.4 /usr/local/lib/libvtkViewsCore-9.4.so.9.4 /usr/local/lib/libvtkInteractionWidgets-9.4.so.9.4 /usr/local/lib/libvtkInteractionStyle-9.4.so.9.4 /usr/local/lib/libvtkRenderingAnnotation-9.4.so.9.4 /usr/local/lib/libvtkImagingHybrid-9.4.so.9.4 /usr/local/lib/libvtkImagingColor-9.4.so.9.4 /usr/local/lib/libvtkRenderingVolume-9.4.so.9.4 /usr/local/lib/libvtkInfovisCore-9.4.so.9.4 /usr/local/lib/libvtkRenderingContext2D-9.4.so.9.4 /usr/local/lib/libvtkRenderingFreeType-9.4.so.9.4 /usr/local/lib/libvtkfreetype-9.4.so.9.4 /usr/local/lib/libvtkjsoncpp-9.4.so.9.4 /usr/local/lib/libvtkexodusII-9.4.so.9.4 /usr/local/lib/libvtknetcdf-9.4.so.9.4 /usr/local/lib/libvtkIOGeometry-9.4.so.9.4 /usr/local/lib/libvtkcgns-9.4.so.9.4 /usr/local/lib/libvtkhdf5_hl-9.4.so.9.4 /usr/local/lib/libvtkhdf5-9.4.so.9.4 /usr/local/lib/libvtklibproj-9.4.so.9.4 /usr/local/lib/libvtksqlite-9.4.so.9.4 /usr/local/lib/libvtkImagingGeneral-9.4.so.9.4 /usr/local/lib/libvtkFiltersExtraction-9.4.so.9.4 /usr/local/lib/libvtkParallelDIY-9.4.so.9.4 /usr/local/lib/libvtkIOXML-9.4.so.9.4 /usr/local/lib/libvtkFiltersTexture-9.4.so.9.4 /usr/local/lib/libvtkFiltersStatistics-9.4.so.9.4 /usr/local/lib/libvtkFiltersModeling-9.4.so.9.4 /usr/local/lib/libvtkParallelCore-9.4.so.9.4 /usr/local/lib/libvtkRenderingOpenGL2-9.4.so.9.4 /usr/local/lib/libvtkIOImage-9.4.so.9.4 /usr/local/lib/libvtkpng-9.4.so.9.4 /usr/local/lib/libvtkDICOMParser-9.4.so.9.4 /usr/local/lib/libvtkmetaio-9.4.so.9.4 /usr/local/lib/libvtktiff-9.4.so.9.4 /usr/local/lib/libvtkjpeg-9.4.so.9.4 /usr/local/lib/libvtkRenderingHyperTreeGrid-9.4.so.9.4 /usr/local/lib/libvtkFiltersHybrid-9.4.so.9.4 /usr/local/lib/libvtkImagingSources-9.4.so.9.4 /usr/local/lib/libvtkImagingCore-9.4.so.9.4 /usr/local/lib/libvtkFiltersHyperTree-9.4.so.9.4 /usr/local/lib/libvtkRenderingUI-9.4.so.9.4 /usr/lib/x86_64-linux-gnu/libX11.so /usr/local/lib/libvtkglad-9.4.so.9.4 /usr/local/lib/libvtkIOLegacy-9.4.so.9.4 /usr/local/lib/libvtkIOCellGrid-9.4.so.9.4 /usr/local/lib/libvtkFiltersCellGrid-9.4.so.9.4 /usr/local/lib/libvtkRenderingCore-9.4.so.9.4 /usr/local/lib/libvtkCommonColor-9.4.so.9.4 /usr/local/lib/libvtkFiltersSources-9.4.so.9.4 /usr/local/lib/libvtkFiltersGeneral-9.4.so.9.4 /usr/local/lib/libvtkCommonComputationalGeometry-9.4.so.9.4 /usr/local/lib/libvtkfmt-9.4.so.9.4 /usr/local/lib/libvtkFiltersVerdict-9.4.so.9.4 /usr/local/lib/libvtkFiltersGeometry-9.4.so.9.4 /usr/local/lib/libvtkFiltersCore-9.4.so.9.4 /usr/local/lib/libvtkFiltersReduction-9.4.so.9.4 /usr/local/lib/libvtkverdict-9.4.so.9.4 /usr/local/lib/libvtkIOXMLParser-9.4.so.9.4 /usr/local/lib/libvtkIOCore-9.4.so.9.4 /usr/local/lib/libvtkCommonExecutionModel-9.4.so.9.4 /usr/local/lib/libvtkCommonDataModel-9.4.so.9.4 /usr/local/lib/libvtkCommonTransforms-9.4.so.9.4 /usr/local/lib/libvtkpugixml-9.4.so.9.4 /usr/local/lib/libvtkCommonSystem-9.4.so.9.4 /usr/local/lib/libvtkCommonMisc-9.4.so.9.4 /usr/local/lib/libvtkCommonMath-9.4.so.9.4 /usr/local/lib/libvtkCommonCore-9.4.so.9.4 /usr/local/lib/libvtkloguru-9.4.so.9.4 /usr/local/lib/libvtktoken-9.4.so.9.4 /usr/local/lib/libvtkdoubleconversion-9.4.so.9.4 -lpthread /usr/local/lib/libvtkkissfft-9.4.so.9.4 /usr/local/lib/libvtkzlib-9.4.so.9.4 /usr/local/lib/libvtklz4-9.4.so.9.4 /usr/local/lib/libvtklzma-9.4.so.9.4 /usr/local/lib/libvtksys-9.4.so.9.4 -ldl /usr/local/lib/libvtkexpat-9.4.so.9.4

@mvieth
Copy link
Member

mvieth commented Dec 31, 2024

My best guess is that it is some kind of memory alignment issue. PCL and Eigen (used within PCL) require a certain alignment of certain classes, depending on architecture options (whether SSE, AVX, etc are enabled or not). However, the flags all look correct. You could try building your own code as C++14 instead of C++17 because it seems like you also built PCL as C++14 (default in PCL 1.14.0). This should not be a problem, but it would be good to rule that out.
Do you do any cross-compiling, or do you compile PCL and your own code, and run the program all on the same computer? Which computer do you use (CPU model)?
Another thing that you should rule out: is there any interference between PCL and one of the other libraries you use (OpenCV, nlohmann_json). For that, you should create a separate project that only uses PCL, and copy only the code where the error happens.

@mvieth
Copy link
Member

mvieth commented Jan 1, 2025

And another thing: point clouds have a field is_dense which specifies whether the points may contain NaN or infinite values. If is_dense==true, then PCL's algorithms will not check each point again for finite-ness (it is faster to not check again and again if this is guaranteed anyway). When you create a PointCloud , then is_dense is true by default. However, if you then put invalid (NaN/infinite) data into it, that is an error. To be safe, you can try setting is_dense=false for every PointCloud and see if that fixes anything.

@YeHuanjie
Copy link
Contributor Author

YeHuanjie commented Jan 2, 2025

After setting is_dense=false, calculating normals is OK in debug mode!
I will try to reproduce the above bug with pcl-debug.

@YeHuanjie
Copy link
Contributor Author

I figure out what happened with the code. There is a bug in the line 4:

q_->resize(scene_with_normals_->size());

It should be:

int max_size = std::max(icp_model_cloud_->size(), scene_with_normals_->size());
q_->resize(max_size);

The code aims to find the nearest neighbors between model points and scene points.
Because there will be multiple model points corresponding to the same scene point.
Also, the number of model points may be greater than the number of scene points.
In summary, there is no bug in kdTreeFLANN but my code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Type of issue status: triage Labels incomplete
Projects
None yet
Development

No branches or pull requests

2 participants