CGAL:二维约束Delaunay三角剖分-向约束添加信息



在将信息(如int)添加到三角测量器对象之前,可以将信息附加到点。我这样做是因为一方面我需要一个int标志,我使用lateron来定义我的纹理坐标,另一方面我使用一个索引,这样我就可以创建一个索引VBO。http://doc.cgal.org/latest/Triangulation_2/Triangulation_2_2info_insert_with_pair_iterator_2_8cpp-example.html

但我只想插入约束边,而不是点。如果我插入两个CGAL,会返回奇怪的结果,因为点已经被输入两次(一次作为点,一次作为受约束边的点)。http://doc.cgal.org/latest/Triangulation_2/Triangulation_2_2constrained_8cpp-example.html

是否可以以与点信息相同的方式连接到"约束",以便在迭代生成的面之前只能使用此函数cdt.insert_constraint( Point(j,0), Point(j,6));

Lateron当我在三角形上循环时,我需要一些方法来访问我之前定义的int标志。像这样,但不是在尖点上,而是在由约束边定义的线段的"末端"上:

for(CDT::Finite_faces_iterator fit = m_cdt.finite_faces_begin(); fit != m_cdt.finite_faces_end(); ++fit, ++k) {
int j = k*3;
for(int i=0; i < 3; i++) {
indices[j+i] = fit->vertex(i)->info().first;
}
}

这个问题是我在这里发布的另一个问题的一部分:约束(Delaunay)三角测量。由于这是一个自己的问题,我第二次独立发布了它。

问题的作者自己找到了解决方案,但没有公布答案。所以,我会做的。


答案位于官方网站上的这些例子和解释中。

将描述当您只需要Point的自定义类时的情况。

获取MyPointC2的来源并修改/添加您需要的内容。

#ifndef MY_POINTC2_H
#define MY_POINTC2_H
#include <CGAL/Origin.h>
class Point_i2 {
private:
double vec[2];
int ind;
public:
Point_i2() : ind(0)
{
*vec = 0;
*(vec+1) = 0;
}
Point_i2(const double x, const double y, int i = 0) : ind(i)
{
*vec = x;
*(vec+1) = y;
}
const double& x() const  { return *vec; }
const double& y() const { return *(vec+1); }
double & x() { return *vec; }
double& y() { return *(vec+1); }
int index() const { return ind; }
int& index() { return ind; }
bool operator==(const Point_i2 &p) const
{
return ( *vec == *(p.vec) )  && ( *(vec+1) == *(p.vec + 1) && ( ind == p.ind) );
}
bool operator!=(const Point_i2 &p) const
{
return !(*this == p);
}
};
#endif // MY_POINTC2_H

然后创建新内核:

#ifndef MYKERNEL_H
#define MYKERNEL_H
#include <CGAL/Cartesian.h>
#include "Point_i2.h"
// K_ is the new kernel, and K_Base is the old kernel
template < typename K_, typename K_Base >
class MyCartesian_base
: public K_Base::template Base<K_>::Type
{
typedef typename K_Base::template Base<K_>::Type   OldK;
public:
typedef K_                                Kernel;
typedef Point_i2                         Point_2;
template < typename Kernel2 >
struct Base { typedef MyCartesian_base<Kernel2, K_Base>  Type; };
};
template < typename FT_ >
struct MyKernel
: public CGAL::Type_equality_wrapper<
MyCartesian_base<MyKernel<FT_>, CGAL::Cartesian<FT_> >,
MyKernel<FT_> >
{};

现在我们可以使用我们的新内核而不是默认内核:

typedef MyKernel<double>                   MK;
typedef CGAL::Filtered_kernel_adaptor<MK>  K;

最新更新