1

I am using PCL with C++ and want to perform PCA on an already clustered pointcloud (that is on every individual cluster). The idea is to eliminate all clusters that are too large/small by measuring their size along the eigenvectors. So intended algorithm is :Get eigenvectors of every cluster, project the cluster points on the corresponding eigenvectors in order to measure maximum distances of points along these dimensions, and from there eliminate all clusters that have "bad" dimensions/ratio of dimensions. I am having difficulties with the implementation. The more help you could spare, the merrier. This is how my data is organized (just to be clear, these are snippets, cluster_indices have already been extracted properly which is checked), and what I started:

std::vector<pcl::PointIndices> cluster_indices;
pcl::PCA<pcl::PointXYZ> cpca = new pcl::PCA<pcl::PointXYZ>;
cpca.setInputCloud(input);
Eigen::Vector3f pca_vector(3,3);
// and now iterating with a for loop over the clusters, but having issues using setIndices already
for (std::vector<pcl::PointIndices>::const_iterator it = cluster_indices.begin (); it != cluster_indices.end (); ++it, n++)
{
    cpca.setIndices(it->indices); //not sure what to put in brackets, everything I thought of returns an error!
    pca_vector = cpca.getEigenVectors();
}
  • Does this code as it stands now even compile ? For instance, line number 2 must be taking a pointer, not a value type. – Arunmu Jun 19 '16 at 08:22
  • Sadly no, I cannot figure out what to actually put in setIndices method brackets. I see that it is supposed to be a pointer, and I tried stuff like &(it->indices) because I thought that would give me the address of the indices themselves... Especially annoying is the fact that "it" is a const_iterator and I have no idea how to deal with that. –  Jun 19 '16 at 08:27
  • The only thing that crashes with the code is setIndicess because it requires IndicesPtr&, and I am not sure what exactly how to provide it correctly. –  Jun 19 '16 at 08:33
  • And what is the type of `it->indices`. As of now it returns a member of `PointIndices` named `indices`. – Arunmu Jun 19 '16 at 08:36
  • exactly, it->indices is a vector of int's, so because I need to provide an address I just gave the vector, because vectors point to the first element. –  Jun 19 '16 at 08:44
  • In the meantime I found that I can project the points using http://docs.pointclouds.org/1.0.0/classpcl_1_1_p_c_a.html#ae9c772ee3930778cb1d86a939fad752c –  Jun 19 '16 at 08:53
  • Also, the 2nd line doesn't need to take in a pointer. –  Jun 19 '16 at 09:05

1 Answers1

0

It seems that there is a general issue with this. So I found this solution: Instead of iterating with pointers, use a regular iterator, and then use these formulation. PointIndicesPtr pi_ptr(new PointIndices); pi_ptr->indices = cluster_indices[i].indices; //now can use pi_ptr as input