// Copyright (c) 2005 Stanford University (USA). // 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 Lesser General Public License as // published by the Free Software Foundation; version 2.1 of the License. // See the file LICENSE.LGPL distributed with CGAL. // // 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) : Daniel Russel #ifndef CGAL_KINETIC_KINETIC_DELAUNAY_2_H #define CGAL_KINETIC_KINETIC_DELAUNAY_2_H #include #include #include #include #include #include #include #include #include #include #include #include CGAL_KINETIC_BEGIN_NAMESPACE template class Delaunay_edge_failure_event { public: //! Make sure that the s has been advanced Delaunay_edge_failure_event(typename This::SOC_certificate &s, const typename This::Edge &e, This *kdel): s_(s), e_(e), kdel_(kdel) { //if (!s.empty()) s_.pop(); } void process(const typename This::Time&) { kdel_->flip(e_); } void write(std::ostream &out) const { out << "Flip " << This::TDS_helper::origin(e_)->point() << "," << This::TDS_helper::destination(e_)->point(); } protected: typename This::SOC_certificate s_; const typename This::Edge e_; This *kdel_; }; template class Delaunay_hull_edge_failure_event { public: //! Make sure that the s has been advanced Delaunay_hull_edge_failure_event(typename This::O2_certificate &s, const typename This::Edge &e, This *kdel): s_(s), e_(e), kdel_(kdel) { //if (!s.empty()) s_.pop(); } void process(const typename This::Time&) { kdel_->flip(e_); } void write(std::ostream &out) const { out << "Flip " << This::TDS_helper::origin(e_)->point() << "," << This::TDS_helper::destination(e_)->point(); } protected: typename This::O2_certificate s_; const typename This::Edge e_; This *kdel_; }; template std::ostream& operator<<(std::ostream &out, const Delaunay_edge_failure_event &e) { e.write(out); return out; } template std::ostream& operator<<(std::ostream &out, const Delaunay_hull_edge_failure_event &e) { e.write(out); return out; } //! A 2D kinetic Delaunay triangulation. /*! Points are added via the Moving_point_table, so the public interface is very limited. See kinetic_Delaunay_2.cc for a useage example. */ template , CGAL::Kinetic::Delaunay_triangulation_face_base_2 > > > class Delaunay_triangulation_2: public Ref_counted > { public: typedef Delaunay_triangulation_2 This; typedef typename Simulation_traits::Kinetic_kernel Kinetic_kernel; typedef typename Simulation_traits::Simulator Simulator; typedef typename Simulation_traits::Active_objects_table Moving_point_table; typedef typename Moving_point_table::Key Point_key; typedef typename Simulator::Event_key Event_key; //typedef typename Simulator::Root_stack Root_stack; typedef typename Simulator::Time Time; typedef typename Delaunay::Edge_circulator Edge_circulator; typedef typename Delaunay::Face_circulator Face_circulator; typedef typename Delaunay::Finite_edges_iterator Finite_edges_iterator; //typedef typename Delaunay::Edge_iterator Edge_iterator; typedef typename Delaunay::Geom_traits::Point_2 Del_point; typedef typename Delaunay::Vertex_handle Vertex_handle; typedef typename Delaunay::Face_handle Face_handle; typedef typename Delaunay::Edge Edge; typedef typename Delaunay::All_faces_iterator Face_iterator; typedef typename Delaunay::All_edges_iterator Edge_iterator; typedef typename Kinetic_kernel::Positive_side_of_oriented_circle_2 SOC; typedef typename Kinetic_kernel::Positive_orientation_2 O2; typedef typename SOC::result_type SOC_certificate; typedef typename O2::result_type O2_certificate; typedef internal::Triangulation_data_structure_helper_2 TDS_helper; typedef Delaunay_edge_failure_event SOC_event; typedef Delaunay_hull_edge_failure_event O2_event; friend class Delaunay_edge_failure_event; friend class Delaunay_hull_edge_failure_event; typedef typename CGAL::Kinetic::Simulator_kds_listener Simulator_listener; friend class CGAL::Kinetic::Simulator_kds_listener; typedef typename CGAL::Kinetic::Active_objects_listener_helper Moving_point_table_listener; friend class CGAL::Kinetic::Active_objects_listener_helper; public: Delaunay_triangulation_2(Simulation_traits st, Visitor w= Visitor()): traits_(st), del_(traits_.instantaneous_kernel_object()), soc_(traits_.kinetic_kernel_object().positive_side_of_oriented_circle_2_object()), o2_(traits_.kinetic_kernel_object().positive_orientation_2_object()), watcher_(w) { siml_ = Simulator_listener(st.simulator_pointer(), this); motl_= Moving_point_table_listener(st.active_objects_table_pointer(), this); } //! Just write the objects in order; void write(std::ostream &out) const { out << del_; } typedef Delaunay Triangulation; const Triangulation &triangulation(const typename Simulator::NT &t) const { //update_instantaneous_kernel_time(); del_.geom_traits().set_time(t); return del_; } typedef typename Delaunay::Triangulation_data_structure Triangulation_data_structure; const Triangulation_data_structure &triangulation_data_structure() const { return del_.tds(); } /*const std::set& recent_edges() const { return new_edges_; }*/ //! Verify that the current state of the void audit() const { audit_structure(); CGAL_KINETIC_LOG(CGAL::Kinetic::LOG_LOTS, *this); if (del_.dimension() != 2) return; Delaunay sdel(traits_.instantaneous_kernel_object()); sdel.geom_traits().set_time(traits_.simulator_pointer()->rational_current_time()); sdel.insert(traits_.active_objects_table_pointer()->keys_begin(), traits_.active_objects_table_pointer()->keys_end()); CGAL_KINETIC_LOG(CGAL::Kinetic::LOG_LOTS, sdel << std::endl); CGAL_assertion(del_.dimension() == sdel.dimension()); for (typename Delaunay::All_vertices_iterator vit = sdel.all_vertices_begin(); vit != sdel.all_vertices_end(); ++vit) { bool found=false; //Object_key k= vit->point(); for (typename Delaunay::All_vertices_iterator vit2= del_.all_vertices_begin(); vit2 != del_.all_vertices_end(); ++vit2) { //Object_key k2= vit2->point(); if (vit->point() == vit2->point()) { found=true; //int d= vit->degree(); //int d2= vit2->degree(); CGAL_assertion(vit->degree() == vit2->degree()); } } CGAL_assertion(found); } } void set_has_certificates(bool) { // always has certificates } bool has_certificates() { return true; } void audit_structure() const { if (del_.dimension() != 2) return; CGAL_KINETIC_LOG(CGAL::Kinetic::LOG_LOTS, *this); /*for (typename Delaunay::All_edges_iterator eit= del_.all_edges_begin(); eit != del_.all_edges_end(); ++eit) { Event_key key= TDS_helper::get_undirected_edge_label(*eit); CGAL_assertion(key); typename Simulator::Root_stack s= compute_failure_time(*eit); if (key == traits_.simulator_pointer()->null_event()) { CGAL_exactness_assertion(s.top() == std::numeric_limits