From cc498412f7cdf3937e6bc0bc19f95d1f1f4037ca Mon Sep 17 00:00:00 2001 From: Monique Teillaud Date: Thu, 4 Aug 2016 15:47:15 +0200 Subject: [PATCH] added face base with info (+ example) --- .../hyperbolic_color.cpp | 62 ++++++++++++++++ ...olic_triangulation_face_base_with_info_2.h | 71 +++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 Hyperbolic_triangulation_2/examples/Hyperbolic_triangulation_2/hyperbolic_color.cpp create mode 100644 Hyperbolic_triangulation_2/include/CGAL/Hyperbolic_triangulation_face_base_with_info_2.h diff --git a/Hyperbolic_triangulation_2/examples/Hyperbolic_triangulation_2/hyperbolic_color.cpp b/Hyperbolic_triangulation_2/examples/Hyperbolic_triangulation_2/hyperbolic_color.cpp new file mode 100644 index 00000000000..aed81c5131c --- /dev/null +++ b/Hyperbolic_triangulation_2/examples/Hyperbolic_triangulation_2/hyperbolic_color.cpp @@ -0,0 +1,62 @@ +#include + +// CGAL headers +#include + +#include + +#include +#include +#include + +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Hyperbolic_Delaunay_triangulation_traits_2< K > Gt; + +typedef Gt::Point_2 Point_2; + +typedef CGAL::Hyperbolic_triangulation_face_base_with_info_2 Fb; +typedef CGAL::Triangulation_data_structure_2 < + CGAL::Triangulation_vertex_base_2, Fb > TDS; +typedef CGAL::Hyperbolic_Delaunay_triangulation_2 Dt; + +int main() +{ + std::vector pts; + Point_2 p; + + std::ifstream ifs("input-file"); + while(ifs >> p) { + pts.push_back(p); + } + + Dt dt; + + dt.insert(pts.begin(),pts.end()); + Dt::Vertex_handle vo = dt.insert(Point_2(0,0)); + + int origin_faces = 0; + Dt::Hyperbolic_faces_iterator fit; + for (fit = dt.hyperbolic_faces_begin(); fit != dt.hyperbolic_faces_end(); ++fit) + if (fit->has_vertex(vo)) + { + fit->info() = CGAL::RED; + origin_faces++; + } + + int red_faces = 0; + for (fit = dt.hyperbolic_faces_begin(); fit != dt.hyperbolic_faces_end(); ++fit) + if (fit->info() == CGAL::RED) + red_faces++; + + assert(red_faces == origin_faces); + + std::cout << "number of points " << std::distance(pts.begin(),pts.end())+1 << std::endl; + std::cout << "Number of (finite) vertices: " << dt.number_of_vertices() << std::endl; + std::cout << "number of (finite) Euclidean faces: " << dt.number_of_faces() << std::endl; + std::cout << "number of hyperbolic faces: " << dt.number_of_hyperbolic_faces() << std::endl; + std::cout << "number of faces having the origin as vertex: " << origin_faces << std::endl; + + return 0; +} diff --git a/Hyperbolic_triangulation_2/include/CGAL/Hyperbolic_triangulation_face_base_with_info_2.h b/Hyperbolic_triangulation_2/include/CGAL/Hyperbolic_triangulation_face_base_with_info_2.h new file mode 100644 index 00000000000..79f322333e8 --- /dev/null +++ b/Hyperbolic_triangulation_2/include/CGAL/Hyperbolic_triangulation_face_base_with_info_2.h @@ -0,0 +1,71 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Monique Teillaud + + +#ifndef CGAL_HYPERBOLIC_TRIANGULATION_FACE_BASE_WITH_INFO_2_H +#define CGAL_HYPERBOLIC_TRIANGULATION_FACE_BASE_WITH_INFO_2_H + +#include + +namespace CGAL { + +template < typename Info_, typename GT, + typename Fb_ = Hyperbolic_triangulation_face_base_2 > +class Hyperbolic_triangulation_face_base_with_info_2 + : public Fb_ +{ + Info_ _info; +public: + typedef typename Fb_::Vertex_handle Vertex_handle; + typedef typename Fb_::Face_handle Face_handle; + typedef Info_ Info; + + template < typename TDS2 > + struct Rebind_TDS { + typedef typename Fb_::template Rebind_TDS::Other Fb2; + typedef Hyperbolic_triangulation_face_base_with_info_2 Other; + }; + + Hyperbolic_triangulation_face_base_with_info_2() + : Fb_() + {} + + Hyperbolic_triangulation_face_base_with_info_2(Vertex_handle v0, + Vertex_handle v1, + Vertex_handle v2) + : Fb_(v0, v1, v2) + {} + + Hyperbolic_triangulation_face_base_with_info_2(Vertex_handle v0, + Vertex_handle v1, + Vertex_handle v2, + Face_handle n0, + Face_handle n1, + Face_handle n2 ) + : Fb_(v0, v1, v2, n0, n1, n2) + {} + + const Info& info() const { return _info; } + Info& info() { return _info; } +}; + +} //namespace CGAL + +#endif // CGAL_HYPERBOLIC_TRIANGULATION_FACE_BASE_WITH_INFO_2_H