Subject: CGAL users discussion list
List archive
- From:
- To:
- Subject: Re: Intersection of an edge of a 2.5D Delaunay Triangulation with a line
- Date: Mon, 14 Jan 2008 14:09:55 +0100
Hello all,
I thought I should answer my question on my own in case someone has a similar
problem.
There is a built in function for intersection with a line segment called
line_walk.
Here is a nice example: it shows a 2.5D Delaunay triangulation, which might
be used e.g. in terrain modelling. To each of the vertices there is an object
of class My_Vertex_info attached. That can be used for storing whatever
information is relevant to individual vertices. 4 points are Delaunay
triangulated and the two triangles are intersected with a line. The task is
to find the vertices, belonging to edges intersected by the line. The size of
the Line_face_circulator is the number of triangles intersected by the line
+2. The ->vertex(i), (where i =1,2,3) on the circulator gives access to one
of the three vertices of each triangle intersected by the line. At the end
the repeated vertices are removed.
Note: that is a 2.5D triangulation, which means that the third dimension is
ignored when calculating the intersections!
#include <list>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
struct K : CGAL::Exact_predicates_inexact_constructions_kernel {};
#include <CGAL/Triangulation_euclidean_traits_xy_3.h>
typedef CGAL::Triangulation_euclidean_traits_xy_3<K> Gt;
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_face_base_2.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
using namespace std;
class My_Vertex_info{};
typedef CGAL::Delaunay_triangulation_2<Gt,
CGAL::Triangulation_data_structure_2
<CGAL::Triangulation_vertex_base_with_info_2<My_Vertex_info,Gt>,
CGAL::Triangulation_face_base_2<Gt> > > Delaunay;
typedef Delaunay::Point CGAL_Point;
int main()
{
Delaunay dt;
CGAL_Point next_point1(1,1,0);
CGAL_Point next_point2(4,3,0);
CGAL_Point next_point3(1,4,0);
CGAL_Point next_point4(3,6,0);
Delaunay::Vertex_handle vh1 = dt.insert(next_point1);
Delaunay::Vertex_handle vh2 = dt.insert(next_point2);
Delaunay::Vertex_handle vh3 = dt.insert(next_point3);
Delaunay::Vertex_handle vh4 = dt.insert(next_point4);
CGAL_Point p1(1,6,1);
CGAL_Point p2(2,1,1);
Delaunay::Line_face_circulator lfc = dt.line_walk(p1, p2);
cout<<circulator_size(lfc)<<endl;
list<Delaunay::Vertex_handle> My_vertices;
for(int i=0; i<(circulator_size(lfc)-2); i++)
{
Delaunay::Vertex_handle vh_test1 = lfc->vertex(0);
My_vertices.push_back(vh_test1);
Delaunay::Vertex_handle vh_test2 = lfc->vertex(1);
My_vertices.push_back(vh_test2);
Delaunay::Vertex_handle vh_test3 = lfc->vertex(2);
My_vertices.push_back(vh_test3);
lfc++;
}
My_vertices.sort();My_vertices.unique();
for(list<Delaunay::Vertex_handle>::const_iterator i = My_vertices.begin(); i
!= My_vertices.end(); i++)
{
cout<<((*i)->point())[0]<<" "<<((*i)->point())[1]<<"
"<<((*i)->point())[2]<<endl;
}
}
Hope that's useful for others too. If someone has an idea how to get unique
vertex values in a way smarter than using the list, please let me know.
Angelina
- Intersection of an edge of a 2.5D Delaunay Triangulation with a line, novacheva, 01/09/2008
- [cgal-discuss] Voronoi diagram for line segments and plygones, Mir Abolfazl Mostafavi, 01/09/2008
- <Possible follow-up(s)>
- Re: Intersection of an edge of a 2.5D Delaunay Triangulation with a line, novacheva, 01/14/2008
Archive powered by MHonArc 2.6.16.