ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
feature.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include <ecvFeature.h>
9 #include <ecvPointCloud.h>
10 
11 #include "pybind/docstring.h"
12 #include "pybind/utility/utility.h"
13 
14 namespace cloudViewer {
15 namespace pipelines {
16 namespace registration {
17 
18 void pybind_feature(py::module &m) {
19  // cloudViewer.utility.Feature
20  py::class_<utility::Feature, std::shared_ptr<utility::Feature>> feature(
21  m, "Feature", "Class to store featrues for registration.");
22  py::detail::bind_default_constructor<utility::Feature>(feature);
23  py::detail::bind_copy_functions<utility::Feature>(feature);
24  feature.def("resize", &utility::Feature::Resize, "dim"_a, "n"_a,
25  "Resize feature data buffer to ``dim x n``.")
26  .def("dimension", &utility::Feature::Dimension,
27  "Returns feature dimensions per point.")
28  .def("num", &utility::Feature::Num, "Returns number of points.")
29  .def("select_by_index", &utility::Feature::SelectByIndex,
30  "Function to select features from input Feature group into "
31  "output Feature group.",
32  "indices"_a, "invert"_a = false)
33  .def_readwrite("data", &utility::Feature::data_,
34  "``dim x n`` float64 numpy array: Data buffer "
35  "storing features.")
36  .def("__repr__", [](const utility::Feature &f) {
37  return std::string(
38  "Feature class with "
39  "dimension "
40  "= ") +
42  std::string(" and num = ") + std::to_string(f.Num()) +
43  std::string("\nAccess its data via data member.");
44  });
45  docstring::ClassMethodDocInject(m, "Feature", "dimension");
46  docstring::ClassMethodDocInject(m, "Feature", "num");
47  docstring::ClassMethodDocInject(m, "Feature", "resize",
48  {{"dim", "Feature dimension per point."},
49  {"n", "Number of points."}});
51  m, "Feature", "select_by_index",
52  {{"indices", "Indices of features to be selected."},
53  {"invert",
54  "Set to ``True`` to invert the selection of indices."}});
55 }
56 
57 void pybind_feature_methods(py::module &m) {
58  m.def("compute_fpfh_feature", &utility::ComputeFPFHFeature,
59  "Function to compute FPFH feature for a point cloud", "input"_a,
60  "search_param"_a, "indices"_a = py::none());
62  m, "compute_fpfh_feature",
63  {
64  {"input", "The Input point cloud."},
65  {"search_param", "KDTree KNN search parameter."},
66  {"indices",
67  "Indices to select points for feature computation."},
68  });
69 
70  m.def("correspondences_from_features",
72  "Function to find nearest neighbor correspondences from features",
73  "source_features"_a, "target_features"_a, "mutual_filter"_a = false,
74  "mutual_consistency_ratio"_a = 0.1f);
76  m, "correspondences_from_features",
77  {{"source_features", "The source features stored in (dim, N)."},
78  {"target_features", "The target features stored in (dim, M)."},
79  {"mutual_filter",
80  "filter correspondences and return the collection of (i, j) s.t. "
81  "source_features[i] and target_features[j] are mutually the "
82  "nearest neighbor."},
83  {"mutual_consistency_ratio",
84  "Threshold to decide whether the number of filtered "
85  "correspondences is sufficient. Only used when mutual_filter is "
86  "enabled."}});
87 }
88 
89 } // namespace registration
90 } // namespace pipelines
91 } // namespace cloudViewer
Class to store featrues for registration.
Definition: ecvFeature.h:29
std::shared_ptr< Feature > SelectByIndex(const std::vector< size_t > &indices, bool invert=false) const
Selects features from input Feature group, with indices in indices, and returns a new Feature group w...
size_t Dimension() const
Returns feature dimensions per point.
Definition: ecvFeature.h:40
void Resize(int dim, int n)
Definition: ecvFeature.h:35
size_t Num() const
Returns number of points.
Definition: ecvFeature.h:42
Eigen::MatrixXd data_
Data buffer storing features.
Definition: ecvFeature.h:54
void ClassMethodDocInject(py::module &pybind_module, const std::string &class_name, const std::string &function_name, const std::unordered_map< std::string, std::string > &map_parameter_body_docs)
Definition: docstring.cpp:27
void FunctionDocInject(py::module &pybind_module, const std::string &function_name, const std::unordered_map< std::string, std::string > &map_parameter_body_docs)
Definition: docstring.cpp:76
void pybind_feature(py::module &m)
Definition: feature.cpp:18
void pybind_feature_methods(py::module &m)
Definition: feature.cpp:57
std::shared_ptr< Feature > ComputeFPFHFeature(const ccPointCloud &input, const geometry::KDTreeSearchParam &search_param=geometry::KDTreeSearchParamKNN(), const utility::optional< std::vector< size_t >> &indices=utility::nullopt)
CorrespondenceSet CorrespondencesFromFeatures(const Feature &source_features, const Feature &target_features, bool mutual_filter=false, float mutual_consistency_ratio=0.1)
Function to find correspondences via 1-nearest neighbor feature matching. Target is used to construct...
Generic file read and write utility for python interface.
std::string to_string(const T &n)
Definition: Common.h:20