使用PCL时私有函数的C ++继承

时间:2016-06-21 12:12:18

标签: c++ function inheritance pca point-cloud-library

我一直在尝试使用C ++中的PCL PCA模块,但这很痛苦。有时候我想使用setIndices()函数切换需要操作的点的当前索引,但是为了实际进行更新,有一个私有的继承函数,一个HAS使用称为initCompute(),否则它不会不要改变它们(或者至少是我理解它的方式)。从来没有,代码原样,由于某种原因不更新索引。这是该类的文档,一切正常,但我不知道如何为这个函数做一个解决方法,他们打算用于这些目的: http://docs.pointclouds.org/trunk/classpcl_1_1_p_c_a.html

如何处理?这是编译时的错误。

In function ‘void clustering(pcl::PointCloud<pcl::PointXYZ>::ConstPtr, pcl::PointCloud<pcl::PointXYZL>::Ptr, pcl::PointCloud<pcl::PointXYZRGB>::Ptr, pcl::PointCloud<pcl::PointXYZ>::Ptr, float)’:
/usr/include/pcl-1.7/pcl/common/impl/pca.hpp:64:1: error: ‘bool pcl::PCA<PointT>::initCompute() [with PointT = pcl::PointXYZ]’ is private
 pcl::PCA<PointT>::initCompute () 

这是代码:

pcl::PCA<pcl::PointXYZ>  cpca = new pcl::PCA<pcl::PointXYZ>;
cpca.setInputCloud(input);
std::cout << "We're now performing the cluster elimination!" << endl;
Eigen::Matrix3f pca_matrix; //serves to hold the eigenvectors, and never got updated...hence the couts for checking.

for (int i = 0; i < nclusters; ++i, n++)
{
    // the next two lines had to be done so, I found that in a forum, the library just behaves a bit strange.
    pcl::PointIndices::Ptr pi_ptr(new pcl::PointIndices);
    pi_ptr->indices = cluster_indices[i].indices;
    cout << "Current size is: " << pi_ptr->indices.size() << endl;//this shows different sizes on every turn
    //now can use pi_ptr
    cpca.setIndices(pi_ptr);
    pca_matrix = cpca.getEigenVectors();
    // but here I get the same vectors every time
    std::cout << "vector " << n << " " << pca_matrix(0,0) << " " << pca_matrix(0,1) << " " << pca_matrix(0,2) << endl;
    std::cout << "vector " << n << " " << pca_matrix(1,0) << " " << pca_matrix(1,1) << " " << pca_matrix(1,2) << endl;
    std::cout << "vector " << n << " " << pca_matrix(2,0) << " " << pca_matrix(2,1) << " " << pca_matrix(2,2) << endl;

1 个答案:

答案 0 :(得分:0)

无论如何,一段时间后我生气了,并做了以下事情。 我使用指针在for循环的开头创建了一个pca对象,然后在循环结束时使用delete删除它。在那里进行一些分配和解除分配很可能不是最优的,但它确实有效。 PCA对象本身只有144个字节,因为它主要使用指针来处理必要的元素。