2014-01-17 130 views
2

在將點添加到三角函數對象之前,可以將信息(如整數)附加到點。我這樣做是因爲我一方面需要一個int標誌,我稍後用它來定義我的紋理座標,另一方面我使用了一個索引,以便我可以創建索引的VBO。 http://doc.cgal.org/latest/Triangulation_2/Triangulation_2_2info_insert_with_pair_iterator_2_8cpp-example.htmlCGAL:2D約束Delaunay三角剖分 - 向約束添加信息

但不是點我只想插入約束邊。如果我插入兩個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標誌。像acutal點,但受約束定義段的「目的」這個而不是邊緣:

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

這個問題的另外一個問題我張貼在這裏的一部分:Constrained (Delaunay) Triangulation。 由於這是它自己的問題,我獨立發佈了第二次。

+0

貌似我終於解決了!遵循以下說明: http://doc.cgal.org/latest/Kernel_23/index.html#sectionextensiblekernel – HesselKRaymond

+0

您可以發表一個自己的答案,並說明您的解決方案嗎?我不確定你的評論中是否有描述。 – lrineau

回答

0

問題的作者發現自己的解決方案,但沒有發佈答案。所以,我會做。


坐落在官方網站上那些examplesexplanation答案。

將描述您只需要自定義類爲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;