CGAL:2D约束Delaunay三角测量 - 向约束添加信息 [英] CGAL: 2D Constrained Delaunay Triangulation - Adding information to constraints

查看:697
本文介绍了CGAL:2D约束Delaunay三角测量 - 向约束添加信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

It is possible to attach informations (like ints) to points before adding them up to the triangulator object. I do this since I need on the one hand an int-flag that I use lateron to define my texture coordinates and on the other hand an index which I use so that I can create a indexed 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

But instead of points I only want to insert constraint-edges. If I insert both CGAL returns strange results since points have been fed into two times (once as point and once as point of a constrained edge). http://doc.cgal.org/latest/Triangulation_2/Triangulation_2_2constrained_8cpp-example.html

可以以与点信息相同的方式连接到约束,以便我只能使用此函数<$在我对所得到的面进行迭代之前,c $ c> cdt.insert_constraint(Point(j,0),Point(j,6)); ?

Is it possible to connect in the same way as with points information to "Constraints" so that I can only use this function cdt.insert_constraint( Point(j,0), Point(j,6)); before I iterate over the resulting faces?

当我循环遍历三角形时,我需要一些方法来访问我之前定义的int标志。像这样,但不是在acutal点,但由约束边缘定义的段的结束:

Lateron when I loop over the triangles I need some way to access the int-flags that I defined before. Like this but not on acutal points but the "ends" of a segment defined by the constraint edges:

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)三角测量

This question is part of another question I posted here: Constrained (Delaunay) Triangulation. Since it's a question of its own I posted it a second time independently.

推荐答案

由于问题的作者发现了解决方案为自己,但没有发布答案。

Author of question found the solution for himself, but did not post the answer. So, I will do it.

答案位于示例

The answer located in those examples and explanation on official website.

将描述 Point $ c>。

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

Take the source of MyPointC2 and modify/add what you need.

#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_> >
{};

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

And now we can use our new kernel instead of default:

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

这篇关于CGAL:2D约束Delaunay三角测量 - 向约束添加信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆