CGAL常用方法

​//求距离
CGAL::squared_distance(plane, center);

//求向量夹角
CGAL::approximate_angle(plane.orthogonal_vector(), block_plane.orthogonal_vector())

//求平方面积
CGAL::squared_area()

//求面积
CGAL::area()

//求体积
CGAL::volume(p0, p1, p2, p3)

//求凸包
CGAL::convex_hull_2(points.begin(), points.end(), std::back_inserter(result));

//求BOX
CGAL::bbox_2(polygon.begin(), polygon.end())

//是否相交
CGAL::do_intersect

//求交点
CGAL::intersection(edge, plane())

//BOX是否重叠
CGAL::do_overlap()

//多边形是否包含点
if (CGAL::bounded_side_2(polygon1.begin(), polygon1.end(), point3) == CGAL::ON_BOUNDED_SIDE) {}

//mesh是否包含点
CGAL::Side_of_triangle_mesh<Polyhedron, K> inside(poly);
CGAL::Bounded_side res = inside(points[i]);
if (res == CGAL::ON_BOUNDED_SIDE) { }
if (res == CGAL::ON_BOUNDARY) {  }

//方向共线、左转、右转
CGAL::orientation(p, q, r)

//是否共线
CGAL::collinear(p, q, r)

//是否平行
CGAL::parallel()

//四点是否共面
CGAL::coplanar()

//求中点
CGAL::midpoint(p, q)

//叉乘,法向量
CGAL::cross_product(v1, v2)

//点乘
CGAL::scalar_product()

//转double
CGAL::to_double

//开方
CGAL::sqrt

//绝对值
CGAL::abs

//求质心
CGAL::centroid(points[0], points[1], points[2])

//环绕中心
CGAL::circumcenter()

//计算重心,点带权重
CGAL::barycenter()

//求法向量
CGAL::unit_normal(points[0], points[1], points[2])
GAL::Polygon_mesh_processing::compute_face_normal(faceId, mesh);

//求多边形差集
std::vector<EC::Polygon_with_holes_2> holes;
CGAL::difference(rectangle_polygon, polygon, std::back_inserter(holes));

//判断结果类型与赋值
CGAL::Object result = CGAL::intersection(a, b);
Point2d pt;
if (CGAL::assign(pt, result)) {
}

//平分线、面
CGAL::bisector()

//点云异常点删除
typename Point_set::iterator rout_it = CGAL::remove_outliers<CGAL::Sequential_tag>
(points, 24, points.parameters().threshold_percent (5.0));
points.remove(rout_it, points.end());
points.collect_garbage();

//点云平均间隔计算
double spacing = CGAL::compute_average_spacing<CGAL::Sequential_tag> (points, 6);

//点云抽稀
double spacing = CGAL::compute_average_spacing<CGAL::Sequential_tag> (points, 6);
typename Point_set::iterator gsim_it = CGAL::grid_simplify_point_set (points, 2. * spacing);
points.remove(gsim_it, points.end());
points.collect_garbage();

//点云平滑
CGAL::jet_smooth_point_set<CGAL::Sequential_tag> (points, 24);

//点云法线估计
CGAL::jet_estimate_normals<CGAL::Sequential_tag>(points, 24);
typename Point_set::iterator unoriented_points_begin =
CGAL::mst_orient_normals(points, 24);
points.remove (unoriented_points_begin, points.end());

//拟合平面
Plane plane;
linear_least_squares_fitting_3(points.begin(), points.end(),
plane, CGAL::Dimension_tag<0>());

//先进向前表面重建
typedef std::array<std::size_t, 3> Facet;
std::vector<Facet> facets;
CGAL::advancing_front_surface_reconstruction(points.points().begin(),points.points().end(),
std::back_inserter(facets));

//尺度空间表面重建
CGAL::Scale_space_surface_reconstruction_3<Kernel> reconstruct
(points.points().begin(), points.points().end());
reconstruct.increase_scale (4, CGAL::Scale_space_reconstruction_3::Jet_smoother<Kernel>());
reconstruct.reconstruct_surface (CGAL::Scale_space_reconstruction_3::Advancing_front_mesher<Kernel>(0.5));
for (Point_set::Index idx : points)
//points.point (idx)
for (const auto& facet : CGAL::make_range (reconstruct.facets_begin(), reconstruct.facets_end()))
// facet

//多边形网格三角化
PMP::triangulate_faces(mesh);

//多形边集转mesh
std::vector<Point_3> points;
std::vector<std::vector<size_t>> polygons;
PMP::repair_polygon_soup(points, polygons);
PMP::orient_polygon_soup(points, polygons);
Surface_Mesh mesh;
PMP::polygon_soup_to_polygon_mesh(points, polygons, mesh);

//点投影到平面
std::vector<Point2d> projectedPoints;
for (Point3d& item : points) {
projectedPoints.push_back(plane.to_2d(plane.projection(item)));
}
Polygon2d poly(projectedPoints.begin(), projectedPoints.end());

//BOOL求并集
PMP::corefine_and_compute_union(mesh1, mesh2, result);

//读写ply
std::ofstream stream(path.toLocal8Bit(), std::ios::binary);
stream.precision(17);
if (!CGAL::IO::write_PLY(stream, mesh)) {
qDebug() << "mesh write error";
}

std::ifstream stream(path.toLocal8Bit());
if (!CGAL::IO::read_PLY(stream, mesh)) {
qDebug() << "mesh read error";
}

//平移mesh
PMP::transform(Affine_transformation_3(CGAL::Translation(),
Vector_3(FT(0), FT(0), FT(1))), polyhedron);

 
//多边形凸分解
std::list<Polygon_2> polys;
CGAL::approx_convex_partition_2(poly.begin(), poly.end(), std::back_inserter(polys));

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值