Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Bug in triangulate_polyhedron.h?

Subject: CGAL users discussion list

List archive

[cgal-discuss] Bug in triangulate_polyhedron.h?


Chronological Thread 
  • From: rcasero <>
  • To:
  • Subject: [cgal-discuss] Bug in triangulate_polyhedron.h?
  • Date: Fri, 18 Oct 2013 13:04:26 -0700 (PDT)

[Sorry if duplicated. I think the mailing list rejected the attached files
sent by email.]

Hi all,

I have a triangular mesh (attached as x.csv for vertices and tri.csv for
triangles) with some holes, and I'm using CGAL to fill the holes and then
triangulate the polygons that cover the holes. To triangulate the hole I'm
using

CGAL-4.2/demo/Polyhedron/include/CGAL/triangulate_polyhedron.h

This is where the bug is, I believe.

Full code of the program is here

https://code.google.com/p/gerardus/source/browse/trunk/matlab/CgalToolbox/CgalTriFillHoles.cpp

but I highlight the parts of interest.

/* CGAL headers */
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Subdivision_method_3.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/triangulate_polyhedron.h>
#include "PolyhedronBuilder.h"

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Point_3<Kernel> Point;
typedef Polyhedron::Facet Facet;
typedef Polyhedron::Facet_iterator Facet_iterator;
typedef Polyhedron::Vertex_handle Vertex_handle;
typedef Polyhedron::Vertex_iterator
Vertex_iterator;
typedef Polyhedron::Halfedge_around_facet_circulator
Halfedge_around_facet_circulator;


I read the mesh from Matlab into a CGAL::Polyhedron_3

// polyhedron to contain the input mesh
Polyhedron mesh;
PolyhedronBuilder<Polyhedron> builder(matlabImport, inTRI, inX);
mesh.delegate(builder);

https://code.google.com/p/gerardus/source/browse/trunk/matlab/CgalToolbox/PolyhedronBuilder.h


Then the holes get filled with

// sort halfedges such that the non-border edges precede the

// border edges. We need to do this before any halfedge iterator

// operations are valid

mesh.normalize_border();



// number of holes we have filled
mwIndex n = 0;


// a closed mesh with no holes will have no border edges. What we do
// is grab a border halfedge and close the associated hole. This
// makes the rest of the iterators invalid, so we have to normalize
// the mesh again. Then we iterate, looking for a new border
// halfedge, filling the hole, etc.
while (!mesh.is_closed()) {


// exit if user pressed Ctrl+C
ctrlcCheckPoint(__FILE__, __LINE__);


// get the first hole we can find, and close it
mesh.fill_hole(mesh.border_halfedges_begin()->opposite());


// increase the counter of number of holes we have filled
n++;


// renormalize mesh so that halfedge iterators are again valid
mesh.normalize_border();


}


Finally, we want to triangulate all the facets in the mesh, and this is
where the segfault happens

// Split all facets to triangles
CGAL::triangulate_polyhedron<Polyhedron>(mesh);

This calls the class here

https://code.google.com/p/gerardus/source/browse/trunk/cpp/src/third-party/CGAL-4.2/demo/Polyhedron/include/CGAL/triangulate_polyhedron.h

This is not the main point, but note that I had to change

typedef CGAL::No_intersection_tag Itag;

to

typedef CGAL::Exact_predicates_tag Itag;

Otherwise, I get an error

sorry, this triangulation does not deal with
intersecting constraints

The segfault happens exactly in the "// then modify the polyhedron" block.
There's a hole with 15 vertices (facet with index 9127) with coordinates

0.015412 0.012213 0.01467
0.015387 0.012213 0.01467
0.015387 0.012213 0.014646
0.015387 0.012213 0.014621
0.01493 0.012264 0.014841
0.014422 0.012416 0.014914
0.014244 0.012467 0.015061
0.014219 0.012467 0.015085
0.014143 0.012467 0.015134
0.01493 0.012289 0.01489
0.014981 0.012264 0.01489
0.015006 0.012264 0.01489
0.015031 0.012264 0.01489
0.015057 0.012264 0.01489
0.015412 0.012213 0.014694

that has been filled with a polygon, and when the polygon modification is in
its 18th iteration in the triangulation function, it has acquired the
vertices:

const typename CDT::Vertex_handle va = fh->vertex(cdt. cw(index));
const typename CDT::Vertex_handle vb = fh->vertex(cdt.ccw(index));

It finds that this is an strictly internal edge, and tries to do

decorator.set_vertex(h, va->info()->vertex());
decorator.set_vertex(h->opposite(), vb->info()->vertex());

However, va->info() == NULL at this point, so va->info()->vertex() throws a
segfault.


Best regards,

Ramon.

tri.csv <http://cgal-discuss.949826.n4.nabble.com/file/n4658250/tri.csv>
x.csv <http://cgal-discuss.949826.n4.nabble.com/file/n4658250/x.csv>



--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Bug-in-triangulate-polyhedron-h-tp4658250.html
Sent from the cgal-discuss mailing list archive at Nabble.com.



Archive powered by MHonArc 2.6.18.

Top of Page