CGAL: 2D Constrained Delaunay Triangulation - Adding information to constraints

强颜欢笑 提交于 2019-12-24 03:01:07

问题


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

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

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?

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;
    }
}

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.


回答1:


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.

Will describe the case when you need just custom class for Point.

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

Then create new kernel:

#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;


来源:https://stackoverflow.com/questions/21186485/cgal-2d-constrained-delaunay-triangulation-adding-information-to-constraints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!