如何解决使用 Cgals 的 mst_orient_normals() 定向点法线,同时保持原始点顺序
Cgals 的 mst_orient_normals()
方法修改输入点的顺序,以便首先打包所有成功定向的点,并在第一个点上返回一个具有无方向法线的迭代器。我想保持输入点的顺序。为了实现这一点,我目前需要使用如下所示的专用索引(请注意,此代码仅供参考)。有没有更有效的方法来实现这一点,而不涉及向元组添加索引然后按该索引排序?
#include <Cgal/pca_estimate_normals.h>
#include <Cgal/mst_orient_normals.h>
#include <Cgal/property_map.h>
#include <Cgal/Exact_predicates_inexact_constructions_kernel.h>
#include <Cgal/tags.h>
typedef Cgal::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point3;
typedef Kernel::Vector_3 Vector;
typedef std::tuple<int,Point3,Vector> PointVectorTuple;
typedef std::vector<PointVectorTuple> PointListwithindex;
typedef Cgal::Parallel_if_available_tag Concurrency_tag;
int main(int argc,char*argv[])
{
unsigned int nb_neighbors_pca_normals = 18; // K-nearest neighbors = 3 rings (estimate normals by PCA)
unsigned int nb_neighbors_mst = 18; // K-nearest neighbors (orient normals by MST)
PointListwithindex pointswithindex;
/**
Load indices,coordinates,and zero vector (normal in this case) into pointswithindex
**/
// Estimates normals direction.
Cgal::pca_estimate_normals<Concurrency_tag>(pointswithindex,nb_neighbors_pca_normals,Cgal::parameters::point_map (Cgal::Nth_of_tuple_property_map<1,PointVectorTuple>()).
normal_map (Cgal::Nth_of_tuple_property_map<2,PointVectorTuple>()));
// Orients normals.
PointListwithindex::iterator unoriented_points_begin =
Cgal::mst_orient_normals(pointswithindex,nb_neighbors_mst,PointVectorTuple>()).
normal_map(Cgal::Nth_of_tuple_property_map<2,PointVectorTuple>()));
// Sort list back by into original order using the index
std::sort(pointswithindex.begin(),pointswithindex.end(),[](const PointVectorTuple & a,const PointVectorTuple & b) {
return (std::get<0>(a) < std::get<0>(b));
});
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。