C++;使用PCL时私有函数的继承 我一直试图在C++中使用PCL的PCA模块,但这是一个痛苦。有一次,我想切换需要使用setIndexes()函数操作的点的当前索引,但要真正进行更新,必须使用一个名为initCompute()的私有继承函数,否则它不会更改它们(或者至少我是这样理解的)。尽管如此,代码仍然不会出于某种原因更新索引。这是该类的文档,所有内容都可以使用,但我不知道如何对此函数进行变通,他们打算将其用于以下目的:
如何应对?这是编译时出现的错误C++;使用PCL时私有函数的继承 我一直试图在C++中使用PCL的PCA模块,但这是一个痛苦。有一次,我想切换需要使用setIndexes()函数操作的点的当前索引,但要真正进行更新,必须使用一个名为initCompute()的私有继承函数,否则它不会更改它们(或者至少我是这样理解的)。尽管如此,代码仍然不会出于某种原因更新索引。这是该类的文档,所有内容都可以使用,但我不知道如何对此函数进行变通,他们打算将其用于以下目的: ,c++,function,inheritance,pca,point-cloud-library,C++,Function,Inheritance,Pca,Point Cloud Library,如何应对?这是编译时出现的错误 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/pc
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 ()
函数“void clustering(pcl::PointCloud::ConstPtr,pcl::PointCloud::Ptr,pcl::PointCloud::Ptr,pcl::PointCloud::Ptr,float)”中的
/usr/include/pcl-1.7/pcl/common/impl/pca.hpp:64:1:错误:“bool pcl::pca::initCompute()[with PointT=pcl::PointXYZ]”是私有的
pcl::PCA::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;
pcl::PCA cpca=新的pcl::PCA;
cpca.setInputCloud(输入);
不管怎样,过了一会儿我就生气了,于是做了下面的事情。
我使用指针在for循环的开头创建了一个pca对象,然后使用delete在循环的末尾将其删除。这是一些分配和解除分配正在进行,这很可能不是最佳的,但它做到了。PCA对象本身只有144字节大,因为它主要使用指针来处理必要的元素。次要更新,只是检查我作为函数输入的东西是否得到了更新,它也得到了更新,所以问题不在那里。你能不能只调用,比如说,为你调用initCompute()
,不,我稍后使用getEigenVectors(),它做了与您所想的相同的事情,但结果保持不变。我现在用代码编辑这个问题。这很奇怪,因为它反过来会触发getMean()
和其他调用initCompute()
。您使用的是重写了其中一些方法的派生类吗?它说它是按原样继承的。我已经添加了代码片段以供检查。