Add vertex info before inserting constraints

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

Add vertex info before inserting constraints

malcolm
Hi,
I am using the Constrained_Delaunay_triangulation_2 class. I want to attach
vertex info to the constraint vertices before calling insert_constraint, in
the same way as I can add info to vertices before inserting in a
triangulation. I cannot find a CGAL method to do this. Here's my code

#include <CGAL\Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>

#include <vector>

class VertexInfo
{
public:
        double data;
        int index;

        VertexInfo() {}
        VertexInfo(double e, int i)
                :data(e), index(i) {}
};

typedef CGAL::Exact_predicates_inexact_constructions_kernel                
Kernel;
typedef CGAL::Exact_predicates_tag            Itag;
typedef CGAL::Triangulation_vertex_base_with_info_2<VertexInfo, Kernel> Vb;
typedef CGAL::Constrained_triangulation_face_base_2<Kernel>    Fb;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb>                        
Tds;
typedef CGAL::Constrained_Delaunay_triangulation_2<Kernel, Tds, Itag>  
Delaunay;
typedef Kernel::Point_2                                                                    
CGAL_Point;

int main()
{
        Delaunay T;
        std::vector< std::pair<CGAL_Point, VertexInfo> > points;
        points.push_back(std::make_pair(CGAL_Point(0.123456789, 0), VertexInfo(0.3,
-1)));
        points.push_back(std::make_pair(CGAL_Point(1, 0), VertexInfo(0.5, -1)));
        points.push_back(std::make_pair(CGAL_Point(0, 1), VertexInfo(1.3, -1)));
        points.push_back(std::make_pair(CGAL_Point(1, 1), VertexInfo(0.8, -1)));
        points.push_back(std::make_pair(CGAL_Point(2, 2), VertexInfo(0.3, -1)));

        // Triangulate
        T.insert(points.begin(), points.end());

        std::vector< std::pair<CGAL_Point, VertexInfo> > constraintPts;
        constraintPts.push_back(std::make_pair(CGAL_Point(10, 10), VertexInfo(1.3,
0)));

        // how do I add constraints with vertex just like above?
        T.insert_constraint(constraintPts.begin(), constraintPts.end()); // this
gives a compiler error

        return 0;
}

If this is not possible, I would like to get the vertex handles of the
constrained vertices and then attach the vertex info to each vertex. Is this
possible?



--
Sent from: http://cgal-discuss.949826.n4.nabble.com/

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


Reply | Threaded
Open this post in threaded view
|

Re: Add vertex info before inserting constraints

chrism
insert_constraint takes 2 points or vertex handles, and sets an edge between the two to be a constraint.

These constraint vertexes will exist in the triangulation, so just insert them as normal, and obtain a handle to them.

// these will be your constraints
Vertex_handle vh = cdt.insert(Point(x,y)); // can insert with info or whatever
Vertex_handle vh1 = cdt.insert(Point(x1,y1));

and then you can insert the constraint
cdt.insert_constraint(vh,vh1);

I do it this way as I'm reading in points from a file. I'm unsure how you obtain the vertex handles if you use the .begin(), .end() insertion approach you showed. But this should get you started at least.

Cheers
Chris


On Fri, Apr 12, 2019 at 1:08 AM malcolm <[hidden email]> wrote:
Hi,
I am using the Constrained_Delaunay_triangulation_2 class. I want to attach
vertex info to the constraint vertices before calling insert_constraint, in
the same way as I can add info to vertices before inserting in a
triangulation. I cannot find a CGAL method to do this. Here's my code

#include <CGAL\Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>

#include <vector>

class VertexInfo
{
public:
        double data;
        int index;

        VertexInfo() {}
        VertexInfo(double e, int i)
                :data(e), index(i) {}
};

typedef CGAL::Exact_predicates_inexact_constructions_kernel               
Kernel;
typedef CGAL::Exact_predicates_tag                                                  Itag;
typedef CGAL::Triangulation_vertex_base_with_info_2<VertexInfo, Kernel> Vb;
typedef CGAL::Constrained_triangulation_face_base_2<Kernel>                 Fb;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb>                         
Tds;
typedef CGAL::Constrained_Delaunay_triangulation_2<Kernel, Tds, Itag>   
Delaunay;
typedef Kernel::Point_2                                                                   
CGAL_Point;

int main()
{
        Delaunay T;
        std::vector< std::pair<CGAL_Point, VertexInfo> > points;
        points.push_back(std::make_pair(CGAL_Point(0.123456789, 0), VertexInfo(0.3,
-1)));
        points.push_back(std::make_pair(CGAL_Point(1, 0), VertexInfo(0.5, -1)));
        points.push_back(std::make_pair(CGAL_Point(0, 1), VertexInfo(1.3, -1)));
        points.push_back(std::make_pair(CGAL_Point(1, 1), VertexInfo(0.8, -1)));
        points.push_back(std::make_pair(CGAL_Point(2, 2), VertexInfo(0.3, -1)));

        // Triangulate
        T.insert(points.begin(), points.end());

        std::vector< std::pair<CGAL_Point, VertexInfo> > constraintPts;
        constraintPts.push_back(std::make_pair(CGAL_Point(10, 10), VertexInfo(1.3,
0)));

        // how do I add constraints with vertex just like above?
        T.insert_constraint(constraintPts.begin(), constraintPts.end()); // this
gives a compiler error

        return 0;
}

If this is not possible, I would like to get the vertex handles of the
constrained vertices and then attach the vertex info to each vertex. Is this
possible?



--
Sent from: http://cgal-discuss.949826.n4.nabble.com/

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


Reply | Threaded
Open this post in threaded view
|

Re: Add vertex info before inserting constraints

malcolm
Thanks Chris. I think this will do in the present situation. I will have to
separately insert each pair of points from the polyline constraint, get the
handles and attach the vertex info.

Ideally, I am looking to insert the info for all the points at once. Doens't
seem to be possible with the current API.



--
Sent from: http://cgal-discuss.949826.n4.nabble.com/

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