mirror of https://github.com/CGAL/cgal
improved code readability
This commit is contained in:
parent
51b672d5ab
commit
324085767e
|
|
@ -6,7 +6,9 @@ Alpha shape.
|
|||
************************************************************************/
|
||||
|
||||
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Filtered_kernel.h>
|
||||
#include <CGAL/algorithm.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
|
@ -18,19 +20,10 @@ Alpha shape.
|
|||
#include <CGAL/Delaunay_triangulation_2.h>
|
||||
#include <CGAL/Alpha_shape_2.h>
|
||||
|
||||
// Choose an exact number type.
|
||||
#ifdef CGAL_USE_LEDA
|
||||
# include <CGAL/leda_integer.h>
|
||||
typedef leda_integer coord_type;
|
||||
#elif defined CGAL_USE_GMP
|
||||
# include <CGAL/Gmpz.h>
|
||||
typedef CGAL::Gmpz coord_type;
|
||||
#else
|
||||
# include <CGAL/MP_Float.h>
|
||||
typedef CGAL::MP_Float coord_type;
|
||||
#endif
|
||||
typedef double coord_type;
|
||||
|
||||
typedef CGAL::Cartesian<coord_type> K;
|
||||
typedef CGAL::Simple_cartesian<coord_type> SC;
|
||||
typedef CGAL::Filtered_kernel<SC> K;
|
||||
|
||||
typedef K::Point_2 Point;
|
||||
typedef K::Segment_2 Segment;
|
||||
|
|
@ -39,6 +32,7 @@ typedef K::Line_2 Line;
|
|||
typedef K::Triangle_2 Triangle;
|
||||
|
||||
typedef CGAL::Alpha_shape_euclidean_traits_2<K> Gt;
|
||||
|
||||
typedef CGAL::Alpha_shape_vertex_base_2<Gt> Vb;
|
||||
typedef CGAL::Alpha_shape_face_base_2<Gt> Fb;
|
||||
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
|
||||
|
|
@ -64,20 +58,18 @@ typedef Alpha_shape_2::Edge_circulator Edge_circulator;
|
|||
|
||||
typedef Alpha_shape_2::Coord_type Coord_type;
|
||||
typedef Alpha_shape_2::Alpha_iterator Alpha_iterator;
|
||||
typedef Alpha_shape_2::Alpha_shape_edges_iterator Alpha_shape_edges_iterator;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
std::vector<Gt::Segment>
|
||||
construct_alpha_shape(const std::list<Point> &V_p,
|
||||
const Coord_type &Alpha,
|
||||
bool mode)
|
||||
// Generate Alpha Shape
|
||||
template <class InputIterator, class OutputIterator>
|
||||
void
|
||||
alpha_edges(InputIterator begin, InputIterator end,
|
||||
const Coord_type &Alpha,
|
||||
bool mode,
|
||||
OutputIterator out)
|
||||
{
|
||||
std::vector<Gt::Segment> V_seg;
|
||||
Alpha_shape_2 A;
|
||||
|
||||
int n = A.make_alpha_shape(V_p.begin(), V_p.end());
|
||||
std::cout << "Inserted " << n << " points" << std::endl;
|
||||
Alpha_shape_2 A(begin,end);
|
||||
|
||||
if (mode)
|
||||
{ A.set_mode(Alpha_shape_2::GENERAL); }
|
||||
|
|
@ -85,36 +77,29 @@ construct_alpha_shape(const std::list<Point> &V_p,
|
|||
{ A.set_mode(Alpha_shape_2::REGULARIZED); };
|
||||
A.set_alpha(Alpha);
|
||||
|
||||
//V_seg << A;
|
||||
//return V_seg;
|
||||
|
||||
return A.op_vect_seg(V_seg);
|
||||
for(Alpha_shape_edges_iterator it = A.alpha_shape_edges_begin();
|
||||
it != A.alpha_shape_edges_end();
|
||||
++it){
|
||||
*out++ = A.segment(*it);
|
||||
}
|
||||
}
|
||||
|
||||
template <class OutputIterator>
|
||||
bool
|
||||
file_input(std::list<Point>& L)
|
||||
file_input(OutputIterator out)
|
||||
{
|
||||
|
||||
std::ifstream is("./data/fin", std::ios::in);
|
||||
|
||||
if(is.fail())
|
||||
{
|
||||
std::cerr << "unable to open file for input" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
CGAL::set_ascii_mode(is);
|
||||
if(is.fail()){
|
||||
std::cerr << "unable to open file for input" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
int n;
|
||||
is >> n;
|
||||
std::cout << "Reading " << n << " points" << std::endl;
|
||||
Point p;
|
||||
for( ; n>0 ; n--)
|
||||
{
|
||||
is >> p;
|
||||
L.push_back(p);
|
||||
}
|
||||
std::cout << "Points inserted" << std::endl;
|
||||
std::cout << "Reading " << n << " points from file" << std::endl;
|
||||
CGAL::copy_n(std::istream_iterator<Point>(is), n, out);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -122,10 +107,16 @@ file_input(std::list<Point>& L)
|
|||
|
||||
int main()
|
||||
{
|
||||
std::list<Point> L;
|
||||
file_input(L);
|
||||
std::vector<Gt::Segment> V =
|
||||
construct_alpha_shape(L,Coord_type(10000),Alpha_shape_2::GENERAL);
|
||||
std::list<Point> points;
|
||||
if(! file_input(std::back_inserter(points))){
|
||||
return -1;
|
||||
}
|
||||
std::vector<Segment> segments;
|
||||
alpha_edges(points.begin(), points.end(),
|
||||
Coord_type(10000),Alpha_shape_2::GENERAL,
|
||||
std::back_inserter(segments));
|
||||
|
||||
std::cout << segments.size() << " alpha shape edges" << std::endl;
|
||||
std::cout << "Alpha Shape computed" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,44 +1,22 @@
|
|||
/***********************************************************************
|
||||
|
||||
Prend une liste de points et renvoie une liste de segments
|
||||
correspondant a l'Alpha Shape.
|
||||
|
||||
************************************************************************/
|
||||
|
||||
|
||||
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Filtered_kernel.h>
|
||||
#include <CGAL/algorithm.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#include <CGAL/Alpha_shape_euclidean_traits_2.h>
|
||||
|
||||
#include <CGAL/Alpha_shape_vertex_base_2.h>
|
||||
|
||||
#include <CGAL/Triangulation_face_base_2.h>
|
||||
#include <CGAL/Alpha_shape_face_base_2.h>
|
||||
|
||||
#include <CGAL/Delaunay_triangulation_2.h>
|
||||
#include <CGAL/Alpha_shape_2.h>
|
||||
|
||||
//Choose the best number type as possible
|
||||
#ifdef CGAL_USE_LEDA
|
||||
# include <CGAL/leda_integer.h>
|
||||
typedef leda_integer coord_type;
|
||||
#elif defined CGAL_USE_GMP
|
||||
# include <CGAL/Gmpz.h>
|
||||
typedef CGAL::Gmpz coord_type;
|
||||
#else
|
||||
# include <CGAL/MP_Float.h>
|
||||
typedef CGAL::MP_Float coord_type;
|
||||
#endif
|
||||
typedef double coord_type;
|
||||
|
||||
typedef CGAL::Cartesian<coord_type> K;
|
||||
typedef CGAL::Simple_cartesian<coord_type> SC;
|
||||
typedef CGAL::Filtered_kernel<SC> K;
|
||||
|
||||
typedef K::Point_2 Point;
|
||||
typedef K::Segment_2 Segment;
|
||||
|
|
@ -47,6 +25,7 @@ typedef K::Line_2 Line;
|
|||
typedef K::Triangle_2 Triangle;
|
||||
|
||||
typedef CGAL::Alpha_shape_euclidean_traits_2<K> Gt;
|
||||
|
||||
typedef CGAL::Alpha_shape_vertex_base_2<Gt> Vb;
|
||||
typedef CGAL::Alpha_shape_face_base_2<Gt> Fb;
|
||||
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
|
||||
|
|
@ -72,23 +51,18 @@ typedef Alpha_shape_2::Edge_circulator Edge_circulator;
|
|||
|
||||
typedef Alpha_shape_2::Coord_type Coord_type;
|
||||
typedef Alpha_shape_2::Alpha_iterator Alpha_iterator;
|
||||
typedef Alpha_shape_2::Alpha_shape_vertices_iterator alpha_vertices_iterator;
|
||||
typedef Alpha_shape_2::Alpha_shape_edges_iterator alpha_edges_iterator;
|
||||
typedef Alpha_shape_2::Alpha_shape_edges_iterator Alpha_shape_edges_iterator;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
std::vector<Gt::Segment>
|
||||
construct_alpha_shape(const std::list<Point> &V_p,
|
||||
const Coord_type &Alpha,
|
||||
bool mode)
|
||||
// Generate Alpha Shape
|
||||
template <class InputIterator, class OutputIterator>
|
||||
void
|
||||
alpha_edges(InputIterator begin, InputIterator end,
|
||||
const Coord_type &Alpha,
|
||||
bool mode,
|
||||
OutputIterator out)
|
||||
{
|
||||
std::vector<Gt::Segment> V_seg;
|
||||
Alpha_shape_2 A;
|
||||
|
||||
int n = A.make_alpha_shape(V_p.begin(), V_p.end());
|
||||
std::cout << "Alpha Shape computed" << std::endl;
|
||||
std::cout << "Inserted " << n << " points" << std::endl;
|
||||
Alpha_shape_2 A(begin,end);
|
||||
|
||||
if (mode)
|
||||
{ A.set_mode(Alpha_shape_2::GENERAL); }
|
||||
|
|
@ -96,55 +70,30 @@ construct_alpha_shape(const std::list<Point> &V_p,
|
|||
{ A.set_mode(Alpha_shape_2::REGULARIZED); };
|
||||
A.set_alpha(Alpha);
|
||||
|
||||
//V_seg << A;
|
||||
//return V_seg;
|
||||
alpha_vertices_iterator A_v_it;
|
||||
alpha_edges_iterator A_e_it;
|
||||
Point p, q;
|
||||
|
||||
for(A_v_it = A.Alpha_shape_vertices_begin(); A_v_it !=
|
||||
A.Alpha_shape_vertices_end(); A_v_it++)
|
||||
{
|
||||
p = (*A_v_it)->point();
|
||||
//std::cout << p << std::endl;
|
||||
}
|
||||
|
||||
|
||||
for(A_e_it = A.Alpha_shape_edges_begin(); A_e_it !=
|
||||
A.Alpha_shape_edges_end(); A_e_it++)
|
||||
{
|
||||
p = A.segment(A_e_it->first,A_e_it->second).source();
|
||||
q = A.segment(A_e_it->first,A_e_it->second).target();
|
||||
//std::cout << p << " ----- " << q << std::endl;
|
||||
}
|
||||
std::cout << "Alpha Shape checked" << std::endl;
|
||||
return A.op_vect_seg(V_seg);
|
||||
for(Alpha_shape_edges_iterator it = A.alpha_shape_edges_begin();
|
||||
it != A.alpha_shape_edges_end();
|
||||
++it){
|
||||
*out++ = A.segment(*it);
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
template <class OutputIterator>
|
||||
bool
|
||||
file_input(std::list<Point>& L)
|
||||
file_input(OutputIterator out)
|
||||
{
|
||||
|
||||
std::ifstream is("./data/fin", std::ios::in);
|
||||
|
||||
if(is.fail())
|
||||
{
|
||||
std::cerr << "unable to open file for input" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
CGAL::set_ascii_mode(is);
|
||||
if(is.fail()){
|
||||
std::cerr << "unable to open file for input" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
int n;
|
||||
is >> n;
|
||||
std::cout << "Reading " << n << " points" << std::endl;
|
||||
Point p;
|
||||
for( ; n>0 ; n--)
|
||||
{
|
||||
is >> p;
|
||||
L.push_back(p);
|
||||
}
|
||||
std::cout << "Points inserted" << std::endl;
|
||||
std::cout << "Reading " << n << " points from file" << std::endl;
|
||||
CGAL::copy_n(std::istream_iterator<Point>(is), n, out);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -152,9 +101,16 @@ file_input(std::list<Point>& L)
|
|||
|
||||
int main()
|
||||
{
|
||||
std::list<Point> L;
|
||||
file_input(L);
|
||||
std::vector<Gt::Segment> V =
|
||||
construct_alpha_shape(L,Coord_type(10000),Alpha_shape_2::GENERAL);
|
||||
std::list<Point> points;
|
||||
if(! file_input(std::back_inserter(points))){
|
||||
return -1;
|
||||
}
|
||||
std::vector<Segment> segments;
|
||||
alpha_edges(points.begin(), points.end(),
|
||||
Coord_type(10000),Alpha_shape_2::GENERAL,
|
||||
std::back_inserter(segments));
|
||||
|
||||
std::cout << segments.size() << " alpha shape edges" << std::endl;
|
||||
std::cout << "Alpha Shape computed" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue