0

I'm using CGAL to construct a half-edge based structure of 2D Voronoi diagram. I chose the CGAL::Voronoi_diagram_2<DT,AT,AP> class to do that, and starting with the example provided by CGAL.

What confuses me now is: for the initial sites (which are loaded from file) added by the insert method as follow:

Site_2 t;
while ( ifs >> t ) { vd.insert(t); }

Things seem to be correct.

But when I try to add some extra sites by the insert method again, and use vd.is_valid() to check the validity, the assertion always return false. I enter the the is_valid() function and find that the following line:

valid = valid && ap_.is_valid(dual_);

is false since ap_.is_valid(dual_) return false. Since I'm new to CGAL, I only know that ap_ is some Adaption_policy class and here it is Delaunay_triangulation_caching_degeneracy_removal_policy_2.

I tried to comment this assertion, but the program crashed for some reason, which means apparently this assertion is necessary.

Does anyone know how to make this assertion correct? Thanks in advance.

Edit:

Following is the main part of my code (which uses OpenGL under GLUT, and I left out some unrelated part such as rendering):

#include <iostream>
#include <fstream>
#include <cassert>

#include <windows.h>
#include <gl\glut.h>
#include <cmath>

// includes for defining the Voronoi diagram adaptor
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Voronoi_diagram_2.h>
#include <CGAL/Delaunay_triangulation_adaptation_traits_2.h>
#include <CGAL/Delaunay_triangulation_adaptation_policies_2.h>
#include <CGAL/intersections.h>

// typedefs for defining the adaptor
typedef CGAL::Exact_predicates_inexact_constructions_kernel                  K;
typedef CGAL::Delaunay_triangulation_2<K>                                    DT;
typedef CGAL::Delaunay_triangulation_adaptation_traits_2<DT>                 AT;
typedef CGAL::Delaunay_triangulation_caching_degeneracy_removal_policy_2<DT> AP;
typedef CGAL::Voronoi_diagram_2<DT,AT,AP>                                    VD;

// typedef for the result type of the point location
typedef AT::Site_2                    Site_2;
typedef AT::Point_2                   Point_2;

typedef VD::Locate_result             Locate_result;
typedef VD::Vertex_handle             Vertex_handle;
typedef VD::Face_handle               Face_handle;
typedef VD::Halfedge_handle           Halfedge_handle;
typedef VD::Ccb_halfedge_circulator   Ccb_halfedge_circulator;

VD vd;

int Width = 640;
int Height = 480;


void myMouseClick(int button, int state, int x, int y)
{
    if (state != GLUT_DOWN) return;
    if (button == GLUT_LEFT_BUTTON)
    {
        double viewPort[4];
        glGetDoublev(GL_VIEWPORT, viewPort);
        Point_2 p0(x, viewPort[3] - y);
        vd.insert(Site_2(p0));
        assert(vd.is_valid());                 //here the assertion fails       
    }
    glutPostRedisplay();
}

int myInit()
{
    glShadeModel(GL_SMOOTH);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glEnable(GL_POINT_SMOOTH);

    // load voronoi data
    std::ifstream ifs("data/data2.dt.cin");
    assert( ifs );

    Site_2 t;
    while ( ifs >> t ) { vd.insert(t); }
    ifs.close();

    assert( vd.is_valid() );                       //here the assertion passes

    return 0;
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(Width, Height);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("2-D Voronoi Diagram");

    glutMouseFunc(myMouseClick);
    if(myInit() < 0) return -1;

    glutMainLoop();

    return 0;
}

Edit:

It seems that the CGAL::Delaunay_triangulation_caching_degeneracy_removal_policy_2<DT> policy's problem. I replace it with CGAL::Identity_policy_2<DT, AT>, the default one, and the assertion passes.

According to the documents, the former policy seems to find degeneracy edge in the voronoi diagram, but I don't see any one visually (I don't have reputation to upload the result, but the input data is the same as what I mentioned in the comment.

Narusaki
  • 97
  • 1
  • 2
  • 11
  • To be sure to understand fully what you mean, a small compilable example showing the pb would help. – sloriot Dec 11 '14 at 13:21
  • @sloriot For example, the `vd` insert four sites initially, i.e. (620, 240), (20, 240), (320, 440), (320, 40), and the shown voronoi diagram is correct. But when I try in `insert` another site, say (251, 578), the `is_valid()` assertion failed. – Narusaki Dec 11 '14 at 15:58
  • I mean something I only need to compile not write the code myself (that is the code you use). – sloriot Dec 11 '14 at 16:23

0 Answers0