CGAL学习记录——降采样

层次化下采样

参数设置:

在这里插入图片描述

代码:

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_points.h>
#include <CGAL/hierarchy_simplify_point_set.h>
#include <CGAL/Memory_sizer.h>
#include <CGAL/Timer.h>
#include <vector>
#include <fstream>
// types
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point;


int main(int argc, char* argv[])
{
    //读取点云
    std::vector<Point> points;
    if (!CGAL::IO::read_points(argv[1], std::back_inserter(points)))
    {
        std::cerr << "Error: cannot read file " << std::endl;
        return EXIT_FAILURE;
    }
    std::cout << "采样前点数: " << points.size()  << std::endl;

    points.erase(CGAL::hierarchy_simplify_point_set(points,CGAL::parameters::size(100) .maximum_variation(0.01)),  points.end());
    std::size_t memory = CGAL::Memory_sizer().virtual_size();
    std::cout << "采样后点数: " << points.size() << std::endl;

    //保存点云
    CGAL::IO::write_points("out.xyz", points, CGAL::parameters::stream_precision(17));
    return EXIT_SUCCESS;
}

WLOP 下采样

参数:

在这里插入图片描述

效果:

在这里插入图片描述

代码:

#include <CGAL/Simple_cartesian.h>
#include <CGAL/wlop_simplify_and_regularize_point_set.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_points.h>
#include <vector>
#include <fstream>
#include <iostream>
// types
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point;
// Concurrency
typedef CGAL::Parallel_if_available_tag Concurrency_tag;
int main(int argc, char** argv)
{

    // 读取点云
    std::vector<Point> points;
    std::vector<Point> output;

    CGAL::IO::read_points(argv[1], std::back_inserter(points));
    //参数设置
    const double retain_percentage = 2;   // percentage of points to retain.
    const double neighbor_radius = 0.5;   // neighbors size.
    
    //WLOP
    CGAL::wlop_simplify_and_regularize_point_set<Concurrency_tag>
        (points, std::back_inserter(output),CGAL::parameters::select_percentage(retain_percentage). neighbor_radius(neighbor_radius));
    
    //保存
    CGAL::IO::write_points(argv[2], output, CGAL::parameters::stream_precision(17));
        
    return EXIT_SUCCESS;
}

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片