我想对点云集群执行贪婪三角剖分。我制作了一个与 PCL 示例代码几乎相同的函数,如下所示:
template<typename PointT>
void GreedyTriangles(int Id, typename pcl::PointCloud<PointT>::Ptr cloud)
{
// Normal estimation*
pcl::NormalEstimation<PointT, pcl::Normal> n;
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
pcl::search::KdTree<PointT>::Ptr tree(new pcl::search::KdTree<PointT>);
tree->setInputCloud(cloud);
n.setInputCloud(cloud);
n.setSearchMethod(tree);
n.setKSearch(20);
n.compute(*normals);
//* normals should not contain the point normals + surface curvatures
// Concatenate the XYZ and normal fields*
pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals(new pcl::PointCloud<pcl::PointNormal>);
pcl::concatenateFields(*cloud, *normals, *cloud_with_normals);
//* cloud_with_normals = cloud + normals
// Create search tree*
pcl::search::KdTree<pcl::PointNormal>::Ptr tree2(new pcl::search::KdTree<pcl::PointNormal>);
tree2->setInputCloud(cloud_with_normals);
// Initialize objects
pcl::GreedyProjectionTriangulation<pcl::PointNormal> gp3;
pcl::PolygonMesh triangles;
// Set the maximum distance between connected points (maximum edge length)
gp3.setSearchRadius(0.025);
// Set typical values for the parameters
gp3.setMu(2.5);
gp3.setMaximumNearestNeighbors(100);
gp3.setMaximumSurfaceAngle(M_PI / 4); // 45 degrees
gp3.setMinimumAngle(M_PI / 18); // 10 degrees
gp3.setMaximumAngle(2 * M_PI / 3); // 120 degrees
gp3.setNormalConsistency(false);
// Get result
gp3.setInputCloud(cloud_with_normals);
gp3.setSearchMethod(tree2);
gp3.reconstruct(triangles);
// Additional vertex information
std::vector<int> parts = gp3.getPartIDs();
std::vector<int> states = gp3.getPointStates();
//pcl::io::saveVTKFile("mesh"+ to_string(Id) +".vtk", triangles);
}
我刚刚删除了最初在 PCL 示例中的以下行,认为每个集群都可以直接用作云(我不确定这是否可能导致错误)
// Load input file into a PointCloud<T> with an appropriate type
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PCLPointCloud2 cloud_blob;
pcl::io::loadPCDFile ("bun0.pcd", cloud_blob);
pcl::fromPCLPointCloud2 (cloud_blob, *cloud);
//* the data should be available in cloud
我这样调用函数:
for (pcl::PointCloud<PointT>::Ptr cluster : cloudClusters)
{
if (cluster->points.size() > 4000)
GreedyTriangles<PointT>(clusterId, cluster);
我的点云是 XYZRGB(是 pcl::PointXYZRGB)。
我收到以下错误:
Build started...
1>------ Build started: Project: environment, Configuration: Release x64 ------
1>cl : command line warning D9002: ignoring unknown option '-std=c++11'
1>environment.cpp
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/visualization/point_cloud_color_handlers.h(610,11): warning C4996: 'pcl::visualization::PointCloudColorHandler<pcl::PCLPointCloud2>::getColor': use getColor() without parameters instead
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/io/low_level_io.h(73,16): warning C4996: '_open': This function or variable may be unsafe. Consider using _sopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/io/low_level_io.h(78,16): warning C4996: '_open': This function or variable may be unsafe. Consider using _sopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>The use of BOOST_*_ENDIAN and BOOST_BYTE_ORDER is deprecated. Please include <boost/predef/other/endian.h> and use BOOST_ENDIAN_*_BYTE instead
1>C:\workspace\SFND_Lidar_Obstacle_Detection-master\src\environment.cpp(220,11): warning C4101: 'ratio': unreferenced local variable
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/visualization/point_cloud_color_handlers.h(108,11): warning C4996: 'pcl::visualization::PointCloudColorHandler<PointT>::getColor': use getColor() without parameters instead
1> with
1> [
1> PointT=pcl::PointXYZL
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/visualization/point_cloud_color_handlers.h(106): message : while compiling class template member function 'vtkSmartPointer<vtkDataArray> pcl::visualization::PointCloudColorHandler<PointT>::getColor(void) const'
1> with
1> [
1> PointT=pcl::PointXYZL
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/visualization/point_cloud_color_handlers.h(119): message : see reference to function template instantiation 'vtkSmartPointer<vtkDataArray> pcl::visualization::PointCloudColorHandler<PointT>::getColor(void) const' being compiled
1> with
1> [
1> PointT=pcl::PointXYZL
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/visualization/point_cloud_color_handlers.h(505): message : see reference to class template instantiation 'pcl::visualization::PointCloudColorHandler<PointT>' being compiled
1> with
1> [
1> PointT=pcl::PointXYZL
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/visualization/pcl_visualizer.h(906): message : see reference to class template instantiation 'pcl::visualization::PointCloudColorHandlerLabelField<pcl::PointXYZL>' being compiled
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/point_traits.h(166,5): error C2499: 'pcl::traits::datatype<PointOutT,Key>': a class cannot be its own base class
1> with
1> [
1> PointOutT=pcl::PointNormal,
1> Key=arg
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/common/concatenate.h(66): message : see reference to class template instantiation 'pcl::traits::datatype<PointOutT,Key>' being compiled
1> with
1> [
1> PointOutT=pcl::PointNormal,
1> Key=arg
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/for_each_type.h(80): message : see reference to function template instantiation 'void pcl::NdConcatenateFunctor<PointIn1T,PointOutT>::operator ()<arg>(void)' being compiled
1> with
1> [
1> PointIn1T=pcl::PointXYZRGB,
1> PointOutT=pcl::PointNormal
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/for_each_type.h(80): message : see reference to function template instantiation 'void pcl::NdConcatenateFunctor<PointIn1T,PointOutT>::operator ()<arg>(void)' being compiled
1> with
1> [
1> PointIn1T=pcl::PointXYZRGB,
1> PointOutT=pcl::PointNormal
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/for_each_type.h(87): message : see reference to function template instantiation 'void pcl::for_each_type_impl<false>::execute<iter,LastIterator,F>(F)' being compiled
1> with
1> [
1> LastIterator=last,
1> F=pcl::NdConcatenateFunctor<pcl::PointXYZRGB,pcl::PointNormal>
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/for_each_type.h(87): message : see reference to function template instantiation 'void pcl::for_each_type_impl<false>::execute<iter,LastIterator,F>(F)' being compiled
1> with
1> [
1> LastIterator=last,
1> F=pcl::NdConcatenateFunctor<pcl::PointXYZRGB,pcl::PointNormal>
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/for_each_type.h(87): message : see reference to function template instantiation 'void pcl::for_each_type_impl<false>::execute<iter,LastIterator,F>(F)' being compiled
1> with
1> [
1> LastIterator=last,
1> F=pcl::NdConcatenateFunctor<pcl::PointXYZRGB,pcl::PointNormal>
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/for_each_type.h(98): message : see reference to function template instantiation 'void pcl::for_each_type_impl<false>::execute<first,last,F>(F)' being compiled
1> with
1> [
1> F=pcl::NdConcatenateFunctor<pcl::PointXYZRGB,pcl::PointNormal>
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/common/impl/io.hpp(332): message : see reference to function template instantiation 'void pcl::for_each_type<FieldList1,pcl::NdConcatenateFunctor<PointIn1T,PointOutT>>(F)' being compiled
1> with
1> [
1> PointIn1T=pcl::PointXYZRGB,
1> PointOutT=pcl::PointNormal,
1> F=pcl::NdConcatenateFunctor<pcl::PointXYZRGB,pcl::PointNormal>
1> ]
1>C:\workspace\SFND_Lidar_Obstacle_Detection-master\src\environment.cpp(374): message : see reference to function template instantiation 'void pcl::concatenateFields<pcl::PointXYZRGB,PointOutT,pcl::PointNormal>(const pcl::PointCloud<pcl::PointXYZRGB> &,const pcl::PointCloud<PointOutT> &,pcl::PointCloud<pcl::PointNormal> &)' being compiled
1> with
1> [
1> PointOutT=pcl::Normal
1> ]
1>C:\workspace\SFND_Lidar_Obstacle_Detection-master\src\environment.cpp(596): message : see reference to function template instantiation 'void GreedyTriangles<PointT>(int,boost::shared_ptr<pcl::PointCloud<PointT>>)' being compiled
1> with
1> [
1> PointT=pcl::PointXYZRGB
1> ]
1>C:\workspace\SFND_Lidar_Obstacle_Detection-master\src\environment.cpp(1222): message : see reference to function template instantiation 'void loadPcdfromBag<pcl::PointXYZRGB>(std::string)' being compiled
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/point_traits.h(173,1): error C2664: 'int boost::mpl::assertion_failed<false>(boost::mpl::assert<false>::type)': cannot convert argument 1 from 'boost::mpl::failed ************(__cdecl pcl::traits::datatype<PointOutT,Key>::POINT_TYPE_NOT_PROPERLY_REGISTERED::* ***********)(PointT &)' to 'boost::mpl::assert<false>::type'
1> with
1> [
1> PointOutT=pcl::PointNormal,
1> Key=arg,
1> PointT=pcl::PointNormal
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/point_traits.h(174,1): message : No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\Program Files\PCL 1.10.0\3rdParty\Boost\include\boost-1_72\boost/mpl/assert.hpp(83,5): message : see declaration of 'boost::mpl::assertion_failed'
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/common/concatenate.h(66,4): error C2039: 'type': is not a member of 'pcl::traits::datatype<PointOutT,Key>'
1> with
1> [
1> PointOutT=pcl::PointNormal,
1> Key=arg
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/common/concatenate.h(66): message : see declaration of 'pcl::traits::datatype<PointOutT,Key>'
1> with
1> [
1> PointOutT=pcl::PointNormal,
1> Key=arg
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/common/concatenate.h(66,1): error C2061: syntax error: identifier 'type'
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/common/concatenate.h(70,1): error C2061: syntax error: identifier 'OutT'
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/common/concatenate.h(68,1): error C2065: 'OutT': undeclared identifier
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/common/concatenate.h(68,1): error C2923: 'std::is_same': 'OutT' is not a valid template type argument for parameter '_Ty2'
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/common/concatenate.h(68,1): error C2955: 'std::is_same': use of class template requires template argument list
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xtr1common(84): message : see declaration of 'std::is_same'
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/point_traits.h(154,5): error C2499: 'pcl::traits::offset<PointOutT,Key>': a class cannot be its own base class
1> with
1> [
1> PointOutT=pcl::PointNormal,
1> Key=arg
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/common/concatenate.h(71): message : see reference to class template instantiation 'pcl::traits::offset<PointOutT,Key>' being compiled
1> with
1> [
1> PointOutT=pcl::PointNormal,
1> Key=arg
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/point_traits.h(159,1): error C2664: 'int boost::mpl::assertion_failed<false>(boost::mpl::assert<false>::type)': cannot convert argument 1 from 'boost::mpl::failed ************(__cdecl pcl::traits::offset<PointOutT,Key>::POINT_TYPE_NOT_PROPERLY_REGISTERED::* ***********)(PointT &)' to 'boost::mpl::assert<false>::type'
1> with
1> [
1> PointOutT=pcl::PointNormal,
1> Key=arg,
1> PointT=pcl::PointNormal
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/point_traits.h(160,1): message : No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\Program Files\PCL 1.10.0\3rdParty\Boost\include\boost-1_72\boost/mpl/assert.hpp(83,5): message : see declaration of 'boost::mpl::assertion_failed'
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/common/concatenate.h(71,92): error C2039: 'value': is not a member of 'pcl::traits::offset<PointOutT,Key>'
1> with
1> [
1> PointOutT=pcl::PointNormal,
1> Key=arg
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/common/concatenate.h(71): message : see declaration of 'pcl::traits::offset<PointOutT,Key>'
1> with
1> [
1> PointOutT=pcl::PointNormal,
1> Key=arg
1> ]
1>C:\Program Files\PCL 1.10.0\include\pcl-1.10\pcl/common/concatenate.h(71,1): error C2065: 'value': undeclared identifier
1>Done building project "environment.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
我对 PCL 或 C++ 没有那么丰富的经验,并且真的需要帮助解决这些错误。