基本效果如下:

主要代码如下:

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/Writer_OFF.h>
#include <CGAL/Point_set_3/IO.h>
#include <CGAL/property_map.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Shape_detection/Efficient_RANSAC.h>
#include <CGAL/Polygonal_surface_reconstruction.h>
#include <CGAL/remove_outliers.h>
#include <CGAL/grid_simplify_point_set.h>
#include <CGAL/compute_average_spacing.h>
#include <CGAL/point_generators_3.h>
#include <CGAL/jet_estimate_normals.h>
#include <CGAL/pca_estimate_normals.h>
#include <CGAL/mst_orient_normals.h>
#include <CGAL/radial_orient_normals.h>
#include <CGAL/vcm_estimate_normals.h>
#define CGAL_USE_GLPK
#ifdef CGAL_USE_SCIP  // defined (or not) by CMake scripts, do not define by hand#include <CGAL/SCIP_mixed_integer_program_traits.h>
typedef CGAL::SCIP_mixed_integer_program_traits<double>                        MIP_Solver;#elif defined(CGAL_USE_GLPK)  // defined (or not) by CMake scripts, do not define by hand#include <CGAL/GLPK_mixed_integer_program_traits.h>
typedef CGAL::GLPK_mixed_integer_program_traits<double>                        MIP_Solver;#endif#if defined(CGAL_USE_GLPK) || defined(CGAL_USE_SCIP)#include <CGAL/Timer.h>#include <fstream>typedef CGAL::Exact_predicates_inexact_constructions_kernel      Kernel;typedef Kernel::Point_3                                          Point;
typedef Kernel::Vector_3                                        Vector;// Point with normal, and plane index
typedef boost::tuple<Point, Vector, int>                      PNI;
typedef std::vector<PNI>                                      Point_vector;
//using Point_vector  = CGAL::Point_set_3<PNI>;
typedef CGAL::Nth_of_tuple_property_map<0, PNI>                   Point_map;
typedef CGAL::Nth_of_tuple_property_map<1, PNI>                   Normal_map;
typedef CGAL::Nth_of_tuple_property_map<2, PNI>                   Plane_index_map;typedef CGAL::Shape_detection::Efficient_RANSAC_traits<Kernel, Point_vector, Point_map, Normal_map>     Traits;typedef CGAL::Shape_detection::Efficient_RANSAC<Traits>             Efficient_ransac;
typedef CGAL::Shape_detection::Plane<Traits>                        Plane;
typedef CGAL::Shape_detection::Sphere<Traits>                       Sphere;
typedef CGAL::Shape_detection::Cone<Traits>                           Cone;
typedef CGAL::Shape_detection::Torus<Traits>                      Torus;
typedef CGAL::Shape_detection::Cylinder<Traits>                       Cylinder;typedef CGAL::Shape_detection::Point_to_shape_index_map<Traits>     Point_to_shape_index_map;typedef CGAL::Polygonal_surface_reconstruction<Kernel>                                Polygonal_surface_reconstruction;
typedef CGAL::Surface_mesh<Point>                                                                        Surface_mesh;/*
* This example first extracts planes from the input point cloud
* (using RANSAC with default parameters) and then reconstructs
* the surface model from the planes.
*/
/**/// Boost includes.
#include <boost/function_output_iterator.hpp>// CGAL includes.
#include <CGAL/Timer.h>
#include <CGAL/Random.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>#include <CGAL/Point_set_3.h>
#include <CGAL/Point_set_3/IO.h>#include <CGAL/Shape_detection/Region_growing/Region_growing.h>
#include <CGAL/Shape_detection/Region_growing/Region_growing_on_point_set.h>
#include <CGAL/jet_smooth_point_set.h>class Index_map {public:using key_type = std::size_t;using value_type = int;using reference = value_type;using category = boost::readable_property_map_tag;Index_map() { }template<typename PointRange>Index_map(const PointRange& points,const std::vector< std::vector<std::size_t> >& regions) :m_indices(new std::vector<int>(points.size(), -1)) {for (std::size_t i = 0; i < regions.size(); ++i)for (const std::size_t idx : regions[i])(*m_indices)[idx] = static_cast<int>(i);(*m_indices)[points.size() - 1] = regions.size();(*m_indices)[points.size() - 2] = regions.size();}inline friend value_type get(const Index_map& index_map,const key_type key) {const auto& indices = *(index_map.m_indices);return indices[key];}void bujiu(){}
public:std::shared_ptr< std::vector<int> > m_indices;
};
int  region_grow(std::string & filename)
{CGAL::Timer t;// Type declarations.using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;using FT = typename Kernel::FT;using Point_3 = typename Kernel::Point_3;using Vector_3 = typename Kernel::Vector_3;using Input_range = CGAL::Point_set_3<Point_3>;using Point_map = typename Input_range::Point_map;using Normal_map = typename Input_range::Vector_map;using Neighbor_query = CGAL::Shape_detection::Point_set::K_neighbor_query<Kernel, Input_range, Point_map>;using Region_type = CGAL::Shape_detection::Point_set::Least_squares_plane_fit_region<Kernel, Input_range, Point_map, Normal_map>;using Region_growing = CGAL::Shape_detection::Region_growing<Input_range, Neighbor_query, Region_type>;using Indices = std::vector<std::size_t>;using Output_range = CGAL::Point_set_3<Point_3>;using Points_3 = std::vector<Point_3>;using Traits = CGAL::Shape_detection::Efficient_RANSAC_traits<Kernel, Input_range, Input_range::Point_map, Input_range::Vector_map>;using Efficient_ransac = CGAL::Shape_detection::Efficient_RANSAC<Traits>;using Plane = CGAL::Shape_detection::Plane<Traits>;using Sphere = CGAL::Shape_detection::Sphere<Traits>;using Cone = CGAL::Shape_detection::Cone<Traits>;using Torus = CGAL::Shape_detection::Torus<Traits>;using Cylinder = CGAL::Shape_detection::Cylinder<Traits>;using Point_to_shape_index_map = CGAL::Shape_detection::Point_to_shape_index_map<Traits>;using Polygonal_surface_reconstruction = CGAL::Polygonal_surface_reconstruction<Kernel>;using Surface_mesh = CGAL::Surface_mesh<Point>;// Concurrencyusing Concurrency_tag = CGAL::Parallel_if_available_tag;// Define an insert iterator.struct Insert_point_colored_by_region_index {using argument_type = Indices;using result_type = void;using Color_map =typename Output_range:: template Property_map<unsigned char>;const Input_range& m_input_range;const   Point_map  m_point_map;Output_range& m_output_range;std::size_t& m_number_of_regions;Color_map m_red, m_green, m_blue;Insert_point_colored_by_region_index(const Input_range& input_range,const   Point_map  point_map,Output_range& output_range,std::size_t& number_of_regions) :m_input_range(input_range),m_point_map(point_map),m_output_range(output_range),m_number_of_regions(number_of_regions) {m_red =m_output_range.template add_property_map<unsigned char>("red", 0).first;m_green =m_output_range.template add_property_map<unsigned char>("green", 0).first;m_blue =m_output_range.template add_property_map<unsigned char>("blue", 0).first;}result_type operator()(const argument_type& region) {CGAL::Random rand(static_cast<unsigned int>(m_number_of_regions));const unsigned char r =static_cast<unsigned char>(64 + rand.get_int(0, 192));const unsigned char g =static_cast<unsigned char>(64 + rand.get_int(0, 192));const unsigned char b =static_cast<unsigned char>(64 + rand.get_int(0, 192));for (const std::size_t index : region) {const auto& key = *(m_input_range.begin() + index);const Point_3& point = get(m_point_map, key);const auto it = m_output_range.insert(point);m_red[*it] = r;m_green[*it] = g;m_blue[*it] = b;}++m_number_of_regions;}}; // Insert_point_colored_by_region_index// Load xyz data either from a local folder or a user-provided file.//std::ifstream  in("data/Tile_+015_+029-twohouser.xyz");std::string pathname = filename;//"D:\\testdata\\xyz\\Tile_+014_+029_1.xyz";std::ifstream  in(pathname);// Reading input in XYZ formatInput_range point_set;if (!in || !CGAL::read_xyz_point_set(in, point_set)){std::cerr << "Can't read input file " << std::endl;return 0;}//Simplify point set//auto points_2_plane = [](Input_range& Input,std::vector< std::vector<std::size_t> > regions) {//  //};double spacing =  CGAL::compute_average_spacing<CGAL::Sequential_tag>(point_set, 70);auto gsim_it = CGAL::grid_simplify_point_set(point_set, spacing);point_set.remove(gsim_it, point_set.end());CGAL::jet_smooth_point_set<CGAL::Sequential_tag>(point_set, 24);point_set.collect_garbage();auto  box = CGAL::bounding_box(point_set.points().begin(), point_set.points().end());Point pminxy(box.xmin(), box.ymin(), box.zmin());Point pminz(box.xmax(), box.ymax(), box.zmin());point_set.insert(pminxy);point_set.insert(pminz);//if (point_set.has_normal_map())//{//   for (Input_range::iterator it = point_set.begin(); it != point_set.end(); ++it)//   {//     Vector n = point_set.normal(*it);//        n = -n / std::sqrt(n * n);//       point_set.normal(*it) = n;//   }//}//else//{if (point_set.has_normal_map())point_set.remove_normal_map();point_set.add_normal_map();CGAL::jet_estimate_normals<CGAL::Sequential_tag>(point_set, 8, point_set.parameters().degree_fitting(2));     // additional named parameter specific to jet_estimate_normals//}if (!point_set.has_normal_map()){std::cerr << " Failed: has_normal_map" << std::endl;return 0;}std::cout << "* loaded " << point_set.size() << " points with normals" << std::endl;// Default parameter values for the data file point_set_3.xyz.const std::size_t k = 16;const FT          max_distance_to_plane = FT(spacing * 1.21);const FT          max_accepted_angle = FT(35);const std::size_t min_region_size = 50;// Create instances of the classes Neighbor_query and Region_type.Neighbor_query neighbor_query(point_set,k,point_set.point_map());Region_type region_type(point_set,max_distance_to_plane, max_accepted_angle, min_region_size,point_set.point_map(), point_set.normal_map());// Create an instance of the region growing class.Region_growing region_growing(point_set, neighbor_query, region_type);// Run the algorithm.Output_range output_range;CGAL::Timer timer;std::vector< std::vector<std::size_t> > regions;timer.start();region_growing.detect(std::back_inserter(regions));std::size_t number_of_regions = 0;Insert_point_colored_by_region_index inserter(point_set, point_set.point_map(),output_range, number_of_regions);region_growing.detect(boost::make_function_output_iterator(inserter));timer.stop();// Print the number of found regions.std::cout << "* " << regions.size() << " regions have been found in " << timer.time() << " seconds"<< std::endl;std::string tmpply = pathname;tmpply = tmpply.replace(tmpply.find(".xyz"), 4, ".ply");const std::string path = tmpply;//"data/Tile_+015_+029-twohouser3333.ply";std::ofstream out(path);out << output_range;std::cout << "* found regions are saved in " << path << std::endl;out.close();Index_map index_map(point_set, regions);Polygonal_surface_reconstruction algo(point_set,point_set.point_map(),point_set.normal_map(),index_map);Surface_mesh model;std::cout << "Reconstructing...";if (!algo.reconstruct<MIP_Solver>(model, 0.43, 0.27, 0.3)) {std::cerr << " Failed: " << algo.error_message() << std::endl;return 0;}pathname = pathname.replace(pathname.find(".xyz"), 4, ".off");const std::string& output_file(pathname);std::ofstream output_stream(output_file.c_str());if (output_stream && CGAL::write_off(output_stream, model)) {// flush the bufferoutput_stream << std::flush;std::cout << " Done. Saved to " << output_file << ". Time: " << t.time() << " sec." << std::endl;}else {std::cerr << " Failed saving file." << std::endl;return 0;}return 1;
}

此方案需要先将房子一栋栋分开, 目前没研究, 房子是手动分开, 一栋栋处理的, CGAL使用版本5.1.5,boost6.18,gplk库

CGAL点云重建白膜相关推荐

  1. 3D点云重建原理及Pytorch实现

    3D点云重建原理及Pytorch实现 Pytorch: Learning Efficient Point Cloud Generation for Dense 3D Object Reconstruc ...

  2. python 3d重建_3D点云重建原理及Pytorch实现

    3D点云重建原理及Pytorch实现 Pytorch: Learning Efficient Point Cloud Generation for Dense 3D Object Reconstruc ...

  3. invalid floating point operation什么意思_Point-MVSNet:基于多视角的点云重建网络

    Point-Based Multi-View Stereo Network是一篇点云重建领域的文章,其工作内容为通过输入多张不同角度的图片,提取不同的点云特征,再进行融合,从而生成最终的点云. 1.介 ...

  4. 拒绝云服务商白嫖,Elasticsearch 和 Kibana 变更开源许可协议

    [CSDN 编者按]白嫖有罪!共享不是拿来主义,请尊重产权! 作者 | 八宝粥   责编 | 张文 出品 | CSDN(ID:CSDNnews) 头图 | CSDN 下载自东方 IC 每个开源项目都会 ...

  5. 图形处理(八)点云重建(上)点云滤波、尖锐特征边增采样、移除离群点

    之前帮导师搞过一个项目,涉及点云尖锐的特征边重建技术,很多文献看起来效果很好,然而都是坑爹的算法,鲁邦性很差,比如这篇paper<Feature Sensitive Surface Extrac ...

  6. unity导入FBX模型时出现材质丢失,模型为白膜的情况

    unity导入FBX模型时出现材质丢失,模型为白膜的情况 导入模型后点击该模型 修改属性即可:

  7. 基于SuperMap Idesktop 进行白膜拉伸的方式

    背景 最近项目中遇到了用到城市白膜效果展示,选择用超图的桌面进行白膜拉伸,发布三维缓存数据,在处理数据和配置颜色的时候,遇到了一些问题通过咨询技术服务,将关于拉伸的一些方法总结如下: 解决方案 一.方 ...

  8. Mars3D(含Cesium)数据及服务篇:城市建筑物转为3DTiles白膜格式

    1.城市建筑物白膜所需的shp数据介绍 在拥有如shp格式的建筑物二维面边界坐标数据,和高度或楼层数属性信息,再通过工具转换为三维立体的白膜建筑物3DTiles模型. Shapefile文件是ESRI ...

  9. 城市建筑三维白膜数据的制作

    城市建筑数据,指的是一个城市的建筑平面轮廓图,跟某栋建筑的详规.控规图纸不一样,而是城市范围内所有建筑的轮廓,轮廓可以简单的就一个矩形,或者多边形封闭区域,表达的是在这个区域内有栋建筑,不需要详细的信 ...

  10. cesium开发加载shapefile制作的白膜

    首先这里制作的shapefile白膜数据是.shp转为.gltf格式的支持cesium加载数据.其实还是一个json格式数据,具体是什么样如下图所示. {"accessors": ...

最新文章

  1. UE5蓝图初学课程 Unreal Engine 5: Blueprints for Beginners
  2. python进程的注意点(进程之间不共享全局变量、主进程会等待所有的子进程执行结束再结束)
  3. python答辩结束语_2018-08-17 结束答辩
  4. Documentum常见问题10-修改特定Type的显示图标
  5. 单例模式的几种实现方式及优缺点
  6. ImportError: cannot import name ‘options‘ from ‘pyecharts‘
  7. SDI, DVI, HDMI, DisplayPort的区别(Z)
  8. 想悄悄的做渗透测试?这里的工具足够你用了
  9. 命令历史及快捷键介绍
  10. select下拉选择框
  11. 7)Thymeleaf 内联表达式、文本、JavaScript、CSS
  12. java面试宝典pdf,给大家安排上!
  13. C++练习 - 字符转换
  14. [原创]网站文章页面添加分享按钮,百度按钮代码复制使用时不显示问题解决!
  15. 积分分汇界面将判断放到D层后,D层的写法
  16. js实现 动态密码的实现
  17. 今日行业报告更新10月25日
  18. Tensorflow深度学习之二十五:tf.py_func
  19. 一个半径为R的球沉入水中,球面顶部正好与水面相切,球的密度为1,求将球从水中取出所做的功
  20. 不格式化移动硬盘(u盘)做成pe

热门文章

  1. 计算机dll修复工具,DLL修复工具哪个好?五款修复能力强推荐
  2. java jre 1.8_jre1.8官方下载
  3. c语言打印字符图案,C语言-打印字符图形.doc
  4. FPS游戏方框透视原理分析及实现-C++语言
  5. ThinkPad SL400无线网卡的问题
  6. ThinkPad SL400使用手札
  7. Boobooke (播布客) 是个好网站
  8. 这样的文件操作有点玄——文件流学习 ( 二 )
  9. “时间复杂度”的另类解释
  10. 电脑网速慢怎么办?手把手教你提升网速