Skip to Content.
Sympa Menu

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

Subject: CGAL users discussion list

List archive

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


Chronological Thread 
  • From: "Sebastien Loriot (GeometryFactory)" <>
  • To:
  • Subject: Re: [cgal-discuss] Bug in triangulate_polyhedron.h?
  • Date: Fri, 18 Oct 2013 14:59:31 -0700
  • Organization: GeometryFactory

Hello,

If I understand correctly what you are trying to do, you are calling
a function which is meant to be used to triangulate a polygon in an
arbitrary plane to fill a hole in a polyhedron, and the boundary of this hole is a closed polyline in 3D space (not planar).

Am I correct?

Sebastien.


On 10/18/2013 12:56 PM, Ramón Casero Cañas wrote:

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.
//
// Note that confusingly, mesh.border_halfedges_begin() gives a
// pointer to the halfedge that is NOT a border in a border
// edge. The border halfedge is instead
// mesh.border_halfedges_begin()->opposite()
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.


--
Dr. Ramón Casero Cañas

Oxford e-Research Centre (OeRC)
University of Oxford
7 Keble Rd
Oxford OX1 3QG

tlf +44 (0) 1865 610739
web http://www.cs.ox.ac.uk/people/Ramon.CaseroCanas
photos http://www.flickr.com/photos/rcasero/




Archive powered by MHonArc 2.6.18.

Top of Page