mesh 2d with intersecting constraints seg faults while calling method refine_mesh()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

mesh 2d with intersecting constraints seg faults while calling method refine_mesh()

Fabio Romani

Hi,

 

Pretty new with CGAL coding. I'm trying to mesh shapes on different layers that could intersect each other.


I'm using this header file to setup my space:

#ifndef MESH_H

#define MESH_H


#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>

#include <CGAL/Constrained_Delaunay_triangulation_2.h>

#include <CGAL/Delaunay_mesher_2.h>

#include <CGAL/Delaunay_mesh_face_base_2.h>

#include <CGAL/Delaunay_mesh_vertex_base_2.h>

#include <CGAL/Delaunay_mesh_size_criteria_2.h>

#include <CGAL/lloyd_optimize_mesh_2.h>

#include <iostream>

#include <fstream>

#include <sstream>

#include <vector>

#include <list>

#include <string>

//#include <CGAL/Cartesian.h>


using namespace std;


typedef CGAL::Exact_predicates_inexact_constructions_kernel K;

//typedef CGAL::Triangulation_vertex_base_2<K> Vb;

typedef CGAL::Delaunay_mesh_vertex_base_2<K>                Vb;

typedef CGAL::Delaunay_mesh_face_base_2<K>                  Fb;

typedef CGAL::Triangulation_data_structure_2<Vb, Fb>        Tds;

typedef CGAL::Exact_predicates_tag                          Itag;

typedef CGAL::Constrained_Delaunay_triangulation_2<K, Tds, Itag>  CDT;

typedef CGAL::Delaunay_mesh_size_criteria_2<CDT>            Criteria;

typedef CGAL::Delaunay_mesher_2<CDT, Criteria>              Mesher;


typedef CDT::Vertex_handle Vertex_handle;

typedef CDT::Point         Point;

//typedef CGAL::Point_2<CGAL::Cartesian<double> >  Point;


class Mesh {

    CDT cdt;

    list< vector<Vertex_handle> > polygons;

    vector<Vertex_handle> polygon;

    // seeds are points that falls inside holes in the polygons

    // this is the way that the algorithm knows how to avoid

    // filling the holes

    std::list<Point> list_of_seeds;


public:

    Mesh();

    ~Mesh();

    Vertex_handle add_point(Point point);

    void add_constraint(Vertex_handle va, Vertex_handle vb);

    void add_seed(Point point);

    long n_vertices();

    Mesher run(Criteria criteria = Criteria(), bool optimize = false);

    void export_triangles_points(std::ofstream &cf, Mesher mesher);

    void read_polygons(ifstream &cf);


    bool import_database(ifstream &cf);

};


and this method to import my points:


void

Mesh::read_polygons(ifstream &cf)

{

    // type == [polygon, hole, point]

    string type, layer, net;

    int    npoly = 0, nhole = 0, npoint = 0;

    while(cf >> type)

    {

        unsigned long int n;

        if( type == "polygon" )

        {

            polygon.clear();

            // reading layer

            cf >> layer;

            // reading net

            cf >> net;

            // reading number of points

            cf >> n;

            cout << "*INFO* Importing polygon #" << ++npoly << " (" << n << " vertices)" << endl;

            while( n-- )

            {

                Point p;

                cf >> p;

//                p.add_property_map<Vertex_handle, string>().first;

                polygon.push_back(cdt.insert(p));

            }


            // adding constraints

            for( int i = 1; i < polygon.size(); i++ )

            {

                cdt.insert_constraint(polygon[i-1], polygon[i]);

            }

            cdt.insert_constraint(polygon[polygon.size()-1], polygon[0]);

        }

        else if( type == "point" )

        {

            cout << "*INFO* Importing point #" << ++npoint << endl;

            Point p;

            cf >> p;

            cdt.insert(p);

        }

        else

        {

        }

    }

}



and then I just run the mesher:


Mesher

Mesh::run(Criteria criteria, bool optimize)

{

    Mesher mesher(cdt);

    mesher.set_criteria(criteria);

    cout << "HEREEEEEEE" << endl;

    mesher.refine_mesh();

    if( optimize )

    {

        cout << "*INFO* Running lloyd optimizer..." << endl;

        // optimizing mesh

        CGAL::lloyd_optimize_mesh_2(cdt, CGAL::parameters::max_iteration_number = 10);

    }

    return mesher;

}


everything works ok if I don't have intersecting constraints...but at times I do and the program just seg faults.


According to the documentation online, CGAL should support intersecting constraints, so it could be just a matter of me not setting the CDT template properly.


Any help appreciated!


Thank


--
Fabio
Reply | Threaded
Open this post in threaded view
|

Re: mesh 2d with intersecting constraints seg faults while calling method refine_mesh()

Sebastien Loriot (GeometryFactory)
I cannot reproduce the pb in general (try the attached main.cpp).
Could you provide a compilable example showing the pb?

Thanks,

Sebastien.

On 03/15/2017 05:32 PM, Fabio Romani wrote:

> Hi,
>
>
>
> Pretty new with CGAL coding. I'm trying to mesh shapes on different
> layers that could intersect each other.
>
>
> I'm using this header file to setup my space:
>
> #ifndef MESH_H
>
> #define MESH_H
>
>
> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
>
> #include <CGAL/Constrained_Delaunay_triangulation_2.h>
>
> #include <CGAL/Delaunay_mesher_2.h>
>
> #include <CGAL/Delaunay_mesh_face_base_2.h>
>
> #include <CGAL/Delaunay_mesh_vertex_base_2.h>
>
> #include <CGAL/Delaunay_mesh_size_criteria_2.h>
>
> #include <CGAL/lloyd_optimize_mesh_2.h>
>
> #include <iostream>
>
> #include <fstream>
>
> #include <sstream>
>
> #include <vector>
>
> #include <list>
>
> #include <string>
>
> //#include <CGAL/Cartesian.h>
>
>
> using namespace std;
>
>
> typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
>
> //typedef CGAL::Triangulation_vertex_base_2<K> Vb;
>
> typedef CGAL::Delaunay_mesh_vertex_base_2<K>                Vb;
>
> typedef CGAL::Delaunay_mesh_face_base_2<K>                  Fb;
>
> typedef CGAL::Triangulation_data_structure_2<Vb, Fb>        Tds;
>
> typedef CGAL::Exact_predicates_tag                          Itag;
>
> typedef CGAL::Constrained_Delaunay_triangulation_2<K, Tds, Itag>  CDT;
>
> typedef CGAL::Delaunay_mesh_size_criteria_2<CDT>            Criteria;
>
> typedef CGAL::Delaunay_mesher_2<CDT, Criteria>              Mesher;
>
>
> typedef CDT::Vertex_handle Vertex_handle;
>
> typedef CDT::Point         Point;
>
> //typedef CGAL::Point_2<CGAL::Cartesian<double> >  Point;
>
>
> class Mesh {
>
>     CDT cdt;
>
>     list< vector<Vertex_handle> > polygons;
>
>     vector<Vertex_handle> polygon;
>
>     // seeds are points that falls inside holes in the polygons
>
>     // this is the way that the algorithm knows how to avoid
>
>     // filling the holes
>
>     std::list<Point> list_of_seeds;
>
>
> public:
>
>     Mesh();
>
>     ~Mesh();
>
>     Vertex_handle add_point(Point point);
>
>     void add_constraint(Vertex_handle va, Vertex_handle vb);
>
>     void add_seed(Point point);
>
>     long n_vertices();
>
>     Mesher run(Criteria criteria = Criteria(), bool optimize = false);
>
>     void export_triangles_points(std::ofstream &cf, Mesher mesher);
>
>     void read_polygons(ifstream &cf);
>
>
>     bool import_database(ifstream &cf);
>
> };
>
>
> and this method to import my points:
>
>
> void
>
> Mesh::read_polygons(ifstream &cf)
>
> {
>
>     // type == [polygon, hole, point]
>
>     string type, layer, net;
>
>     int    npoly = 0, nhole = 0, npoint = 0;
>
>     while(cf >> type)
>
>     {
>
>         unsigned long int n;
>
>         if( type == "polygon" )
>
>         {
>
>             polygon.clear();
>
>             // reading layer
>
>             cf >> layer;
>
>             // reading net
>
>             cf >> net;
>
>             // reading number of points
>
>             cf >> n;
>
>             cout << "*INFO* Importing polygon #" << ++npoly << " (" << n
> << " vertices)" << endl;
>
>             while( n-- )
>
>             {
>
>                 Point p;
>
>                 cf >> p;
>
> //                p.add_property_map<Vertex_handle, string>().first;
>
>                 polygon.push_back(cdt.insert(p));
>
>             }
>
>
>             // adding constraints
>
>             for( int i = 1; i < polygon.size(); i++ )
>
>             {
>
>                 cdt.insert_constraint(polygon[i-1], polygon[i]);
>
>             }
>
>             cdt.insert_constraint(polygon[polygon.size()-1], polygon[0]);
>
>         }
>
>         else if( type == "point" )
>
>         {
>
>             cout << "*INFO* Importing point #" << ++npoint << endl;
>
>             Point p;
>
>             cf >> p;
>
>             cdt.insert(p);
>
>         }
>
>         else
>
>         {
>
>         }
>
>     }
>
> }
>
>
>
> and then I just run the mesher:
>
>
> Mesher
>
> Mesh::run(Criteria criteria, bool optimize)
>
> {
>
>     Mesher mesher(cdt);
>
>     mesher.set_criteria(criteria);
>
>     cout << "HEREEEEEEE" << endl;
>
>     mesher.refine_mesh();
>
>     if( optimize )
>
>     {
>
>         cout << "*INFO* Running lloyd optimizer..." << endl;
>
>         // optimizing mesh
>
>         CGAL::lloyd_optimize_mesh_2(cdt,
> CGAL::parameters::max_iteration_number = 10);
>
>     }
>
>     return mesher;
>
> }
>
>
> everything works ok if I don't have intersecting constraints...but at
> times I do and the program just seg faults.
>
>
> According to the documentation online, CGAL should support intersecting
> constraints, so it could be just a matter of me not setting the CDT
> template properly.
>
>
> Any help appreciated!
>
>
> Thank
>
>
> --
> Fabio

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss



main.cpp (1K) Download Attachment