CGAL 在网格中查找内部点
CGAL find interior points in a mesh
我试图使用CGAL来查找三角形网格内部的点。(即不在其边界上的点集。这里有一个类似的示例,用于使用函数 CGAL::Side_of_triangle_mesh<> 的 3D 网格。任何人都可以帮助/建议如何修改2D三角测量?
我的测试代码只是创建两个正方形,一个在另一个内部,然后在原点放置一个种子(打一个洞(,然后执行 2D Delaunay 三角测量。当我调用side_of_triangle_mesh<>类时:
Point_2 p = points2D[i];
CGAL::Bounded_side res = inside2D(p);
我收到错误:
/usr/local/include/CGAL/Side_of_triangle_mesh.h:164:16: Candidate function not viable: no known conversion from 'Point_2' (aka 'Point_2<CGAL::Epick>') to 'const Point' (aka 'const Point_3<CGAL::Epick>') for 1st argument
这是否意味着side_of_triangle_mesh仅适用于 3D Polyhedron_3网格?如果是这样,任何人都可以建议一种为 2D 网格执行此操作的方法吗?
我的测试代码如下:谢谢
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Delaunay_mesh_vertex_base_2.h>
#include <CGAL/Delaunay_mesh_face_base_2.h>
#include <CGAL/Delaunay_mesh_size_criteria_2.h>
#include <CGAL/Side_of_triangle_mesh.h>
#include <vector>
#include <CGAL/Delaunay_mesher_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;
typedef CGAL::Triangle_2<K> triangle;
typedef CGAL::Delaunay_mesh_vertex_base_2<K> Vb;
typedef CGAL::Delaunay_mesh_face_base_2<K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, Tds> CDT;
typedef CDT::Vertex_handle Vertex_handle;
typedef CGAL::Delaunay_mesh_size_criteria_2<CDT> Criteria;
int main(int argc, char* argv[])
{
// Create a vector of the points
//
std::vector<Point_2> points2D ;
points2D.push_back(Point_2(-5.0, -5.0)); // ----------
points2D.push_back(Point_2( 5.0, -5.0)); // | OUTER
points2D.push_back(Point_2( 5.0, 5.0)); // | SQUARE
points2D.push_back(Point_2(-5.0, 5.0)); // ----------
points2D.push_back(Point_2(-2.5, -2.5)); // ----------
points2D.push_back(Point_2( 2.5, -2.5)); // | INNER
points2D.push_back(Point_2( 2.5, 2.5)); // | SQUARE
points2D.push_back(Point_2(-2.5, 2.5)); // ----------
size_t numTestPoints = points2D.size();
// Create a constrained delaunay triangulation and add the points
//
CDT cdt;
std::vector<Vertex_handle> vhs;
for (unsigned int i=0; i<numTestPoints; ++i){
vhs.push_back(cdt.insert(points2D[i]));
}
// Creare constraints of the sides of the mesh
//
cdt.insert_constraint(vhs[0],vhs[1]);
cdt.insert_constraint(vhs[1],vhs[2]);
cdt.insert_constraint(vhs[2],vhs[3]);
cdt.insert_constraint(vhs[3],vhs[0]);
cdt.insert_constraint(vhs[4],vhs[5]);
cdt.insert_constraint(vhs[5],vhs[6]);
cdt.insert_constraint(vhs[6],vhs[7]);
cdt.insert_constraint(vhs[7],vhs[4]);
// Create a seed to make sure the inner square is a hole
//
std::list<Point_2> list_of_seeds;
list_of_seeds.push_back(Point_2(0, 0));
// Refine the mesh into triangles of max side length '1' and ensuring seeds are 'holes'
//
CGAL::refine_Delaunay_mesh_2(cdt, list_of_seeds.begin(), list_of_seeds.end(),
Criteria(0.125, 1),false);
// Call side_of_triangle_mesh
//
CGAL::Side_of_triangle_mesh<CDT, K> inside2D(cdt) ;
int n_inside = 0;
int n_boundary = 0;
for(unsigned int i=0; i<numTestPoints; ++i)
{
Point_2 p = points2D[i];
CGAL::Bounded_side res = inside2D(p);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// NO MATCHING FUNCTION Call
if (res == CGAL::ON_BOUNDED_SIDE) { ++n_inside; }
if (res == CGAL::ON_BOUNDARY) { ++n_boundary; }
}
std::cerr << "2D results for query size: " << cdt.number_of_vertices() << std::endl;
std::cerr << " " << n_inside << " points inside " << std::endl;
std::cerr << " " << n_boundary << " points on boundary " << std::endl;
return 0 ;
}
多亏了@sloriot我才明白了这个问题。最重要的是,您不能将 CGAL::Side_of_triangle_mesh<> 用于 2D Delaunay 网格。相反,你要做的是遍历网格中的所有顶点,并通过查看顶点周围的所有相邻面来测试每个顶点。如果任何面在域之外,则顶点或点位于网格的边缘。
以下是更正后的代码:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Delaunay_mesh_vertex_base_2.h>
#include <CGAL/Delaunay_mesh_face_base_2.h>
#include <CGAL/Delaunay_mesh_size_criteria_2.h>
#include <vector>
#include <CGAL/Delaunay_mesher_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;
typedef CGAL::Delaunay_mesh_vertex_base_2<K> Vb;
typedef CGAL::Delaunay_mesh_face_base_2<K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, Tds> CDT;
typedef CDT::Vertex_handle Vertex_handle;
typedef CGAL::Delaunay_mesh_size_criteria_2<CDT> Criteria;
typedef CDT::Vertex_iterator Vertex_iterator;
typedef CDT::Vertex Vertex;
typedef CDT::Face Face ;
typedef Face::Face_handle Face_handle ;
typedef CDT::Face_circulator Face_circulator ;
int main(int argc, char* argv[])
{
// Create a vector of the points
//
std::vector<Point_2> points2D ;
points2D.push_back(Point_2(-5.0, -5.0)); // ----------
points2D.push_back(Point_2( 5.0, -5.0)); // | OUTER
points2D.push_back(Point_2( 5.0, 5.0)); // | SQUARE
points2D.push_back(Point_2(-5.0, 5.0)); // ----------
points2D.push_back(Point_2(-2.5, -2.5)); // ----------
points2D.push_back(Point_2( 2.5, -2.5)); // | INNER
points2D.push_back(Point_2( 2.5, 2.5)); // | SQUARE
points2D.push_back(Point_2(-2.5, 2.5)); // ----------
size_t numTestPoints = points2D.size();
// Create a constrained delaunay triangulation and add the points
//
CDT cdt;
std::vector<Vertex_handle> vhs;
for (unsigned int i=0; i<numTestPoints; ++i){
vhs.push_back(cdt.insert(points2D[i]));
}
// Creare constraints of the sides of the mesh
//
cdt.insert_constraint(vhs[0],vhs[1]);
cdt.insert_constraint(vhs[1],vhs[2]);
cdt.insert_constraint(vhs[2],vhs[3]);
cdt.insert_constraint(vhs[3],vhs[0]);
cdt.insert_constraint(vhs[4],vhs[5]);
cdt.insert_constraint(vhs[5],vhs[6]);
cdt.insert_constraint(vhs[6],vhs[7]);
cdt.insert_constraint(vhs[7],vhs[4]);
// Create a seed to make sure the inner square is a hole
//
std::list<Point_2> list_of_seeds;
list_of_seeds.push_back(Point_2(0, 0));
// Refine the mesh into triangles of max side length '1' and ensuring seeds are 'holes'
//
CGAL::refine_Delaunay_mesh_2(cdt, list_of_seeds.begin(), list_of_seeds.end(),
Criteria(0.125, 1.5),false);
// The mesh is now created. The next bit swings around each vertex point checking that
// all faces around it are in the domain. If any are not then the vertex is on the
// edge of the mesh.
// thanks to @sloriot for this
//
Vertex v ;
std::vector<Point_2> interior_points ;
std::vector<Point_2> boundary_points ;
CDT::Locate_type loc = CDT::Locate_type::VERTEX ;
int li;
Vertex_iterator vit = cdt.vertices_begin(), beyond = cdt.vertices_end() ;
while (vit != beyond) {
v = *vit ;
Point_2 query = vit->point();
Face_handle f = cdt.locate(query, loc, li);
bool current_face_in_domain ;
Face_handle start = f ;
do {
current_face_in_domain = f->is_in_domain() ;
Vertex_handle vh = f->vertex(li);
f = f->neighbor(cdt.ccw(li));
li = f->index(vh) ;
}
while(current_face_in_domain && f != start) ;
if (f == start) {
interior_points.push_back(query) ;
}else{
boundary_points.push_back(query) ;
}
++vit ;
}
printf("Boundary points:n");
for(auto p = boundary_points.begin(); p != boundary_points.end(); ++p){
printf("%f,%fn",p->x(), p->y()) ;
}
printf("interior points:n");
for(auto p = interior_points.begin(); p != interior_points.end(); ++p){
printf("%f,%fn",p->x(), p->y()) ;
}
return 0 ;
}
当你运行它时,你应该得到类似的东西:这
您必须使用 locate
函数。它将返回包含查询点的人脸句柄。然后,您需要使用 is_in_domain()
成员函数检查人脸是否在域中。
请注意,如果要执行多个查询,则应首先将所有查询点放在一个容器中,然后使用hilbert_sort
对它们进行排序并使用前一个点的位置作为定位函数的第二个参数。
下面是如何在边界情况下获取事件面的示例代码:
CDT_2 mesh;
CGAL::Locate_type loc;
int li;
Point_2 query;
Face_handle f = mesh.locate(query, loc, li);
switch(loc)
{
case FACE:
f->is_in_domain();
break;
case EDGE:
{
bool face_1_in_domain = f->is_in_domain(); // first incident face status
bool face_2_in_domain = f->neighbor(li)->is_in_domain(); // second incident face status
break;
}
case VERTEX:
{
// turn around f->vertex(li)
Face_handle start = f;
do{
bool current_face_in_domain = f->is_in_domain();
Vertex_handle v = f->vertex(mesh.cw(li));
f = f->neighbor(mesh.ccw(li));
li = f->index(v);
}
while(f!=current);
break;
}
default:
// outside of the domain.
}
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 在C++中查找文件
- 将函数类成员映射到类本身内部
- 模板元程序查找相似的连续类型名称
- 在UNIX系统中使用DIR查找文件的字节大小
- 查找最接近的大于当前数字的数字的索引
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 查找后更改类变量
- 使用正则表达式regex_search在字符串中查找字符串
- Boost Spirit,获取迭代器内部语义动作
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 内联函数中具有内部链接的全局变量
- CGAL 在网格中查找内部点
- 如何查找查看一个字符串是否位于另一个字符串内部并替换它
- 类(模板)成员函数体内部的ADL查找
- 查找有效内部圆形内部阵列的索引
- 查找具有内部边界检查的类似向量的类
- 符号查找错误时,使用我的Qt插件从共享库内部
- 使用内部函数在数组中查找下一个非零
- 如果一个元素存在于成对的向量中,则在类内部查找