CGAL-WLOP算法

CGAL-WLOP

CGAL库中有针对点云处理的专门模块,其中实现了WLOP算法,这里记录下使用方法。


安装CGAL

参考链接

代码

  1. 官方文档http://doc.cgal.org/latest/Point_set_processing_3/group PkgPointSetProcessing.html
  2. 主要用到CGAL库中CGAL::wlop_simplify_and_regularize_point_set()函数,函数原型如下
    CGAL::wlop_simplify_and_regularize_point_set    (   
    RandomAccessIterator    first,
    RandomAccessIterator    beyond,
    OutputIterator      output,
    PointPMap        point_pmap,
    double          select_percentage,
    double          radius,
    unsigned int        iter_number,
    bool            require_uniform_sampling,
    const Kernel &
    )
    • first: 输入点vector的开始(.begin)
    • beyond: 输入点vector的结束(.end)
    • output: 输出点vector的开始
    • point_pmap: 点的类型,如果使用CGAL的Kernel::Point_3类型,该项可忽略
    • select_percentage: 保留输入点的百分比(默认值5%)
    • radius: 点的邻域半径(很重要的参数,需要仔细调整,如果太小会导致分布不均匀,太大运行时间很长。默认值是输入点云的8倍平均间隙)
    • iter_number: 迭代次数(默认值35)
    • require_uniform_sampling: 是否需要均匀采样(默认值false)
    • const Kernel &: 和point_pmap一样,可忽略
  3. wlop.cpp
    
    #include <CGAL/Simple_cartesian.h>
    #include <CGAL/wlop_simplify_and_regularize_point_set.h>
    #include <CGAL/IO/read_xyz_points.h>
    #include <CGAL/IO/write_xyz_points.h>
    #include <vector>
    #include <fstream>
    #include <iostream>

// types typedef CGAL::Simple_cartesian Kernel; typedef Kernel::Point_3 Point; // Concurrency

ifdef CGAL_LINKED_WITH_TBB

typedef CGAL::Parallel_tag Concurrency_tag;

else

typedef CGAL::Sequential_tag Concurrency_tag;

endif

int main(int argc, char* argv) { const char input_filename = (argc>1)?argv[1]:"../data/in/teeth.xyz"; const char* output_filename = (argc>2)?argv[2]:"../data/out/teeth_out_wlop.xyz"; // Reads a .xyz point set file in points[] std::vector points; std::ifstream stream(input_filename); if (!stream || !CGAL::read_xyz_points(stream, std::back_inserter(points))) { std::cerr << "Error: cannot read file " << input_filename << std::endl; return EXIT_FAILURE; }

std::vector<Point> output;
//parameters
const double retain_percentage = 2;   // percentage of points to retain.
const double neighbor_radius = 0.9;   // neighbors size.
CGAL::wlop_simplify_and_regularize_point_set
                        <Concurrency_tag>
                        (points.begin(), 
                        points.end(),
                        std::back_inserter(output),
                        retain_percentage,
                        neighbor_radius,
                        10,
                        true
                        );

std::ofstream out(output_filename);
return EXIT_SUCCESS;

}

4. 为了方便引入CGAL,使用CMake来创建工程,CMakeLists.txt文件内容如如下
```txt
cmake_minimum_required (VERSION 2.4)
if(COMMAND cmake_policy)
    cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

project (wlop)

IF(WIN32)
    find_package(CGAL QUIET REQUIRED COMPONENTS Core )
ELSE(WIN32)
    find_package(CGAL QUIET COMPONENTS Core )
ENDIF(WIN32)

IF(CGAL_FOUND)
    MESSAGE("CGAL found   ${CGAL_USE_FILE}")
    INCLUDE( ${CGAL_USE_FILE} )
    SET( CMAKE_VERBOSE_MAKEFILE OFF )
ELSE(CGAL_FOUND)
    MESSAGE("Error : CGAL not found")
ENDIF(CGAL_FOUND)

AUX_SOURCE_DIRECTORY(./src SOURCES)

ADD_EXECUTABLE(wlop ${SOURCES})

TARGET_LINK_LIBRARIES(wlop CGAL)
  1. 打包如下链接。在根目录运行
    • 如果是Linux或者macOS
      mkdir build
      cd build
      cmake ..
      make

      make成功后运行

      ./wlop

      data/out文件夹下就有输出,data/in是输入,一个牙齿的点云模型。

    • 如果是Windows就用cmake工具产生vs工程编译运行。