38 #include <pcl/recognition/hv/greedy_verification.h>
40 template<
typename ModelT,
typename SceneT>
45 recognition_models_.clear ();
46 points_explained_by_rm_.clear ();
49 mask_.resize (visible_models_.size ());
50 for (std::size_t i = 0; i < visible_models_.size (); i++)
54 points_explained_by_rm_.resize (scene_cloud_downsampled_->size ());
57 for (std::size_t m = 0; m < visible_models_.size (); m++)
59 RecognitionModelPtr recog_model (
new RecognitionModel);
62 recog_model->id_ =
static_cast<int> (m);
66 voxel_grid.
setLeafSize (resolution_, resolution_, resolution_);
67 voxel_grid.
filter (*(recog_model->cloud_));
69 std::vector<int> explained_indices;
70 std::vector<int> outliers;
72 std::vector<float> nn_distances;
74 for (std::size_t i = 0; i < recog_model->cloud_->size (); i++)
76 if (!scene_downsampled_tree_->radiusSearch ((*recog_model->cloud_)[i], inliers_threshold_, nn_indices, nn_distances,
77 std::numeric_limits<int>::max ()))
79 outliers.push_back (
static_cast<int> (i));
83 for (std::size_t k = 0; k < nn_distances.size (); k++)
85 explained_indices.push_back (nn_indices[k]);
90 std::sort (explained_indices.begin (), explained_indices.end ());
91 explained_indices.erase (std::unique (explained_indices.begin (), explained_indices.end ()), explained_indices.end ());
93 recog_model->bad_information_ =
static_cast<int> (outliers.size ());
94 recog_model->explained_ = explained_indices;
95 recog_model->good_information_ =
static_cast<int> (explained_indices.size ());
96 recog_model->regularizer_ = regularizer_;
98 recognition_models_.push_back (recog_model);
100 for (
const int &explained_index : explained_indices)
102 points_explained_by_rm_[explained_index].push_back (recog_model);
109 template<
typename ModelT,
typename SceneT>
115 std::vector<bool> best_solution_;
116 best_solution_.resize (recognition_models_.size ());
118 for (std::size_t i = 0; i < recognition_models_.size (); i++)
120 if (
static_cast<float> (recognition_models_[i]->good_information_) > (regularizer_
121 *
static_cast<float> (recognition_models_[i]->bad_information_)))
123 best_solution_[i] =
true;
124 updateGoodInformation (
static_cast<int> (i));
127 best_solution_[i] =
false;
130 for (std::size_t i = 0; i < best_solution_.size (); i++)
132 if (best_solution_[i])
134 mask_[indices_models_[i].index_] =
true;
138 mask_[indices_models_[i].index_] =
false;
143 #define PCL_INSTANTIATE_GreedyVerification(T1,T2) template class PCL_EXPORTS pcl::GreedyVerification<T1,T2>;
void filter(PointCloud &output)
Calls the filtering method and returns the filtered dataset in output.
A greedy hypothesis verification method.
void verify() override
Starts verification.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
VoxelGrid assembles a local 3D grid over a given PointCloud, and downsamples + filters the data.
void setLeafSize(const Eigen::Vector4f &leaf_size)
Set the voxel grid leaf size.
IndicesAllocator<> Indices
Type used for indices in PCL.