Created
June 7, 2018 10:41
-
-
Save MaelRL/2250c5a84f452a54bda6547930dbb00d to your computer and use it in GitHub Desktop.
Weighted AS2 with CGAL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> | |
#include <CGAL/Alpha_shape_2.h> | |
#include <CGAL/Alpha_shape_face_base_2.h> | |
#include <CGAL/Alpha_shape_vertex_base_2.h> | |
#include <CGAL/Regular_triangulation_2.h> | |
#include <fstream> | |
#include <iostream> | |
#include <list> | |
#include <vector> | |
typedef CGAL::Exact_predicates_inexact_constructions_kernel K; | |
typedef K::FT FT; | |
typedef K::Point_2 Point; | |
typedef K::Weighted_point_2 Weighted_point; | |
typedef K::Segment_2 Segment; | |
typedef CGAL::Regular_triangulation_vertex_base_2<K> Rvb; | |
typedef CGAL::Alpha_shape_vertex_base_2<K,Rvb> Vb; | |
typedef CGAL::Regular_triangulation_face_base_2<K> Rf; | |
typedef CGAL::Alpha_shape_face_base_2<K,Rf> Fb; | |
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds; | |
typedef CGAL::Regular_triangulation_2<K,Tds> Triangulation_2; | |
typedef CGAL::Alpha_shape_2<Triangulation_2> Alpha_shape_2; | |
typedef Alpha_shape_2::Alpha_shape_edges_iterator Alpha_shape_edges_iterator; | |
template <class OutputIterator> | |
void alpha_edges(const Alpha_shape_2& A, OutputIterator out) | |
{ | |
Alpha_shape_edges_iterator it = A.alpha_shape_edges_begin(), | |
end = A.alpha_shape_edges_end(); | |
for( ; it!=end; ++it) | |
*out++ = A.segment(*it); | |
} | |
// Reads a list of points and returns a list of segments corresponding to | |
// the weighted Alpha Shape. | |
int main() | |
{ | |
std::vector<Weighted_point> wpoints; | |
wpoints.push_back(Weighted_point(Point(4, 5.7), FT(16))); | |
wpoints.push_back(Weighted_point(Point(2.5, 5), FT(4))); | |
wpoints.push_back(Weighted_point(Point(3, 3), FT(0))); | |
wpoints.push_back(Weighted_point(Point(6, 4), FT(-9))); | |
wpoints.push_back(Weighted_point(Point(8, 3), FT(0))); | |
Alpha_shape_2 A(wpoints.begin(), wpoints.end(), FT(10000), Alpha_shape_2::GENERAL); | |
std::vector<Segment> segments; | |
alpha_edges(A, std::back_inserter(segments)); | |
std::cout << "Alpha Shape computed" << std::endl; | |
std::cout << segments.size() << " alpha shape edges" << std::endl; | |
std::cout << "Optimal alpha: " << *A.find_optimal_alpha(1)<<std::endl; | |
std::cout << "Faces... " << std::endl; | |
for(Alpha_shape_2::Finite_faces_iterator face_it = A.faces_begin(); | |
face_it != A.faces_end(); ++face_it) | |
{ | |
std::cout << "face: " << std::endl | |
<< "\t" << face_it->vertex(0)->point() << std::endl | |
<< "\t" << face_it->vertex(1)->point() << std::endl | |
<< "\t" << face_it->vertex(2)->point() << std::endl; | |
std::cout << "squared radius: " | |
<< K().compute_squared_radius_smallest_orthogonal_circle_2_object()( | |
face_it->vertex(0)->point(), face_it->vertex(1)->point(), face_it->vertex(2)->point()) | |
<< std::endl; | |
std::cout << "AS sq_r: " << A.squared_radius(face_it) << std::endl; | |
} | |
std::cout << "alpha values" << std::endl; | |
for(Alpha_shape_2::Alpha_iterator alph_it = A.alpha_begin(); | |
alph_it != A.alpha_end(); ++alph_it) | |
{ | |
std::cout << "value: " << *alph_it << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment