-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflat_point.hpp
93 lines (76 loc) · 2.88 KB
/
flat_point.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//w
// Created by avell on 16/03/18.
//
#include <pcl/segmentation/region_growing.h>
#include <pcl/filters/passthrough.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/common/centroid.h>
template <typename PointT, typename NormalT>
class FlatPoint : public pcl::RegionGrowing<PointT,NormalT>{
public:
FlatPoint<PointT,NormalT>() :
centroids_ (0),
is_computed_centroid_info (false),
centroids_cloud_ (new pcl::PointCloud<PointT>),
centroids_normals_ (new pcl::PointCloud<pcl::Normal>)
{};
std::string getClusterState(){
return !this->clusters_.empty()?"Something":"Empty";
}
std::vector<Eigen::Vector4f> getCentroids() {
if (this->centroids_.size() == 0){
std::vector<pcl::PointIndices> clusters;
if (this->clusters_.size() != 0)
clusters = this->clusters_;
else {
//Compute the whole process
this->extract(clusters);
}
for (const pcl::PointIndices &cluster : clusters) {
Eigen::Vector4f centroid;
pcl::compute3DCentroid(*this->input_, cluster, centroid);
centroids_.push_back(centroid);
}
}
// Vector of seeds
return this->centroids_;
}
pcl::PointCloud<pcl::Normal>::Ptr getCentroidsNormals(){
if(!is_computed_centroid_info)
compute_centroid_info();
return centroids_normals_;
}
global::Cloud::Ptr getCentroidsCloud(){
if(!is_computed_centroid_info)
compute_centroid_info();
global::Cloud::Ptr c (new global::Cloud());
pcl::copyPointCloud(*centroids_cloud_,*c);
return c;
}
protected:
std::vector<Eigen::Vector4f> centroids_;
boost::shared_ptr <pcl::PointCloud<PointT>> centroids_cloud_;
boost::shared_ptr <pcl::PointCloud<pcl::Normal> > centroids_normals_;
bool is_computed_centroid_info;
void compute_centroid_info(){
getCentroids();
std::vector<int> nn_indices (1);
std::vector<float> nn_dists (1);
for(const Eigen::Vector4f ¢roid: centroids_ ){
PointT p;
p.x = centroid[0]; p.y = centroid[1]; p.z = centroid[2];
this->search_->nearestKSearch(p,1, nn_indices, nn_dists);
centroids_cloud_->points.push_back(this->input_->points[nn_indices[0]]);
nn_indices[0] = this->neighbour_number_;
nn_dists[0] = this->neighbour_number_;
this->search_->nearestKSearch(p,this->neighbour_number_, nn_indices, nn_dists);
for(const int &p_i: nn_indices){
if(this->normals_->points[p_i].normal_x != 0) {
centroids_normals_->points.push_back(this->normals_->points[p_i]);
break;
}
}
}
is_computed_centroid_info = true;
}
};