Subject: CGAL users discussion list
List archive
[cgal-discuss] some basic clarifications needed regarding copying Constrained Triangulations
Chronological Thread
- From: <>
- To:
- Subject: [cgal-discuss] some basic clarifications needed regarding copying Constrained Triangulations
- Date: Sun, 31 Mar 2013 01:59:15 +0100 (CET)
Hi,
I need some basic clarification regarding copying constrained edges of a CT
into another new CT. I perform it in the following manner :
1. Loop through all constrained edges of old CT.
2. Take vertices/end-points on edges.
ct_Face_handle fh1 = eit->first;
ct_Vertex_handle vh1 = fh1->vertex(fh1->cw(eit->second));
ct_Vertex_handle vh2 = fh1->vertex(fh1->ccw(eit->second));
3. Now I keep a vector to mark the vertices I push. I have an id for each
vertex in the info() item of the vertex.
So, I first check if I pushed any of these vertices already in CT. If yes I
obtain the handle from the already stored vertex handles in a vector. [I keep
all the inserted vertex handles into a vector.]. If the vertex is not already
inserted then I push this vertex into the vhandles (see below).
std::deque<bool> infos(nv, false); //Num of vertices = nv
std::vector<ct_Vertex_handle> vhandles(nv);
4. Insert the constraint for edge.
I am observing the flowing :
Sometime I get segmentation faults plus the behavior is erratic. I mean to say
I keep getting intersecting constraint or collinear faces error.
[Although most of the times I need to change the location of vertices and then
compute CT, but I need to check that I am doing alright for the base case of
copying a CT. ]
Questions
1 Is there a possibility that the vertex handle gets changed while inserting
points/edges in a CT. Note that I maintain the boolean vector infos and vertex
handles.
2. Is there any other easy way to copy constrained edges and create a CT.
-- I use CT and CDT both in my code, and I am not very well versed with cgal.
So I hope that I am not messing up the cgal structures needed for CT/CDT.
Hence I put my header files + code snippet below.
Any suggestions or comments. [Full Code snippet below]
Thanks
R
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Delaunay_mesher_2.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <CGAL/Triangulation_face_base_with_info_2.h>
#include <CGAL/Delaunay_mesh_face_base_2.h>
#include <CGAL/Delaunay_mesh_size_criteria_2.h>
//#include <CGAL/Triangulation_conformer_2.h>
//#include <CGAL/Delaunay_triangulation_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_2<K> Vbase;
typedef CGAL::Delaunay_mesh_face_base_2<K> Fbase;
//typedef CGAL::Constrained_triangulation_face_base_2<K> Fbase;
typedef CGAL::Triangulation_face_base_with_info_2<p_ii, K, Fbase> Fb;
typedef CGAL::Triangulation_vertex_base_with_info_2<int, K, Vbase> Vb;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds;
//typedef CGAL::No_intersection_tag Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, Tds> 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 cgal_Point;
typedef CDT::Vertex Vertex;
typedef CDT::Vertex_iterator Vertex_iterator;
typedef CDT::Face Face;
typedef CDT::Face_iterator Face_iterator;
typedef CDT::Face_circulator Face_circulator;
typedef CDT::Face_handle Face_handle;
typedef std::vector<Vertex_handle> Vec_Vertex_handle ; // CCW Order
typedef CDT::Finite_faces_iterator finite_face_iterator;
typedef CDT::Edge Edge;
typedef CDT::Edge_iterator Edge_iterator;
typedef std::pair<Vertex_handle, Vertex_handle> VHP; // vertex_handle_pair;
typedef std::vector<std::pair<Vertex_handle, Vertex_handle> > VofVHP; //
vector_of_vertex_handle_pairs
typedef std::vector<Vertex_handle> VofVH; // Vector of Vertex handle
typedef CDT::Edge_circulator Edge_circulator;
typedef CDT::Vertex_circulator Vertex_circulator;
typedef CDT::Finite_vertices_iterator finite_vertices_iterator;
typedef CDT::Finite_edges_iterator finite_edges_iterator;
//CT typdedefs
typedef CGAL::Constrained_triangulation_face_base_2<K> ct_Fbase;
typedef CGAL::Triangulation_face_base_with_info_2<p_ii, K, ct_Fbase> ct_Fb;
typedef CGAL::Triangulation_data_structure_2<Vb, ct_Fb> ct_Tds;
typedef CGAL::Constrained_triangulation_2<K, ct_Tds> CT;
typedef CT::Vertex_handle ct_Vertex_handle;
typedef CT::Point ct_cgal_Point;
typedef CT::Vertex ct_Vertex;
typedef CT::Vertex_iterator ct_Vertex_iterator;
typedef CT::Face ct_Face;
typedef CT::Face_iterator ct_Face_iterator;
typedef CT::Face_circulator ct_Face_circulator;
typedef CT::Face_handle ct_Face_handle;
typedef CT::Finite_faces_iterator ct_finite_face_iterator;
typedef CT::Edge ct_Edge;
typedef CT::Edge_iterator ct_Edge_iterator;
typedef CT::Edge_circulator ct_Edge_circulator;
typedef CT::Vertex_circulator ct_Vertex_circulator;
typedef CT::Finite_vertices_iterator ct_finite_vertices_iterator;
typedef CT::Finite_edges_iterator ct_finite_edges_iterator;
Code snippet for copying CT :
// ** ** set.size() = Number of vertices in original CT
CT tct; //New CT ; CT - Old CT
std::deque<bool> infos(set.size(),false);
std::vector<ct_Vertex_handle> vhandles(set.size());
ct_Edge_iterator eit = cdt.edges_begin(), ebeyond =
cdt.edges_end();
while(eit!=ebeyond)
{
if(ct.is_constrained(*eit))
{
ct_Face_handle fh1 = eit->first;
ct_Vertex_handle vh1 = fh1->vertex(fh1-
>cw(eit->second));
ct_Vertex_handle vh2 = fh1->vertex(fh1-
>ccw(eit->second));
int vinfo1 = vh1->info(), vinfo2 = vh2-
>info();
cgal_Point p1 = vh1->point();
cgal_Point p2 = vh2->point();
ct_Face_handle fh2 = fh1->neighbor((eit-
>second));
bool is_v1_pushed=false, is_v2_pushed = false;
if(infos[vinfo1]) is_v1_pushed=true;
if(infos[vinfo2]) is_v2_pushed=true;
ct_Vertex_handle cvh1, cvh2;
if(!is_v1_pushed)
{
cvh1 = tct.insert(p1);
cvh1->info()=vinfo1;
infos[vinfo1]=true;
vhandles[vinfo1]=cvh1;
}
if(!is_v2_pushed)
{
cvh2 = tct.insert(p2);
cvh2->info()=vinfo2;
infos[vinfo2]=true;
vhandles[vinfo2]=cvh2;
}
cvh1= vhandles[vinfo1]; cvh2=
vhandles[vinfo2];
tct.insert_constraint(cvh1,cvh2);assert(tct.is_edge(cvh1,cvh2));
}
++eit;
}
- [cgal-discuss] some basic clarifications needed regarding copying Constrained Triangulations, ratneshkumar21, 03/31/2013
Archive powered by MHonArc 2.6.18.