BWAPI
|
00001 // Copyright (c) 1997-2000 Max-Planck-Institute Saarbruecken (Germany). 00002 // All rights reserved. 00003 // 00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under 00005 // the terms of the Q Public License version 1.0. 00006 // See the file LICENSE.QPL distributed with CGAL. 00007 // 00008 // Licensees holding a valid commercial license may use this file in 00009 // accordance with the commercial license agreement provided with the software. 00010 // 00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00013 // 00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Nef_2/include/CGAL/generic_sweep.h $ 00015 // $Id: generic_sweep.h 28567 2006-02-16 14:30:13Z lsaboret $ 00016 // 00017 // 00018 // Author(s) : Michael Seel <seel@mpi-sb.mpg.de> 00019 #ifndef CGAL_GENERIC_SWEEP_H 00020 #define CGAL_GENERIC_SWEEP_H 00021 00022 /*{\Moptions print_title=yes}*/ 00023 /*{\Moptions section=subsection}*/ 00024 00025 00026 #include <CGAL/sweep_observer.h> 00027 00028 namespace CGAL { 00029 00030 /*{\Manpage {generic_sweep}{T}{A Generic Plane Sweep Framework}{PS}}*/ 00031 00032 template <typename T> 00033 class generic_sweep { 00034 00035 typedef generic_sweep<T> Self; 00036 00037 /*{\Mdefinition 00038 The data type |\Mname| provides a general framework for algorithms 00039 following the plane sweep paradigm. The plane sweep paradigm can be 00040 described as follows. A vertical line sweeps the plane from left to 00041 right and constructs the desired output incrementally left behind the 00042 sweep line. The sweep line maintains knowledge of the scenery of 00043 geometric objects and stops at points where changes of this knowledge 00044 relevant for the output occur. These points are called events. 00045 00046 A general plane sweep framework structures the execution of the 00047 sweep into phases and provides a storage place for all data structures 00048 necessary to execute the sweep. An object |\Mvar| of type |\Mname| 00049 maintains an object of type |T| which generally can be used to store 00050 necessary structures. The content is totally dependent of the sweep 00051 specification and thereby varies within the application domain of the 00052 framework. 00053 00054 The traits class |T| has to provide a set of types which define 00055 the input/output interface of the sweep: the input type |INPUT|, 00056 the output type |OUTPUT|, and a geometry kernel type |GEOMETRY|. 00057 00058 The natural phases which determine a sweep are 00059 \begin{Mverb} 00060 // INITIALIZATION 00061 initialize_structures(); 00062 check_invariants(); 00063 00064 // SWEEP LOOP 00065 while ( event_exists() ) { 00066 process_event(); 00067 check_invariants(); 00068 procede_to_next_event(); 00069 } 00070 00071 // COMPLETION 00072 complete_structures(); 00073 check_final(); 00074 \end{Mverb} 00075 00076 \begin{description} 00077 \item[ Initialization ] -- initializing the data structures, 00078 ensuring preconditions, checking invariants 00079 \item[ Sweep Loop ] -- iterating over all events, while handling 00080 the event stops, ensuring invariants and the soundness of all 00081 data structures and maybe triggering some animation tasks. 00082 \item[ Completion ] -- cleaning up some data structures and 00083 completing the output. 00084 \end{description} 00085 00086 The above subtasks are members of the class |T| which a 00087 model of our traits concept has to provide: 00088 \begin{Mverb} 00089 void T::initialize_structures(); 00090 bool T::event_exists(); 00091 void T::process_event(); 00092 void T::procede_to_next_event(); 00093 void T::complete_structures(); 00094 void T::check_invariants(); 00095 void T::check_final(); 00096 \end{Mverb} 00097 See specification of the traits class for |\Mname|. 00098 00099 00100 }*/ 00101 00102 T traits; 00103 00104 /*{\Mtypes 5}*/ 00105 public : 00106 00107 typedef T TRAITS; 00108 /*{\Mtypemember the traits class}*/ 00109 00110 typedef typename TRAITS::INPUT INPUT; 00111 /*{\Mtypemember the input interface.}*/ 00112 00113 typedef typename TRAITS::OUTPUT OUTPUT; 00114 /*{\Mtypemember the output container.}*/ 00115 00116 typedef typename TRAITS::GEOMETRY GEOMETRY; 00117 /*{\Mtypemember the geometry kernel.}*/ 00118 00119 /*{\Mevents 6.5}*/ 00120 00121 /*{\Mtext To enable animation of the sweep there are event hooks 00122 inserted which allow an observer to attach certain visualization 00123 actions to them. There are four such hooks: }*/ 00124 00125 Event_hook<TRAITS&> post_init_hook; 00126 /*{\Mevent triggered just after initialization.}*/ 00127 00128 Event_hook<TRAITS&> pre_event_hook; 00129 /*{\Mevent triggered just before the sweep event.}*/ 00130 00131 Event_hook<TRAITS&> post_event_hook; 00132 /*{\Mevent triggered just after the sweep event.}*/ 00133 00134 Event_hook<TRAITS&> post_completion_hook; 00135 /*{\Mevent triggered just after the completion phase.}*/ 00136 00137 /*{\Mtext All of these are triggered during the sweep with the instance 00138 of the |TRAITS| class that is stored inside the plane sweep object. 00139 Thus any animation operation attached to a hook can work on that class 00140 object which maintains the sweep status.}*/ 00141 00142 00143 /*{\Mcreation PS}*/ 00144 00145 generic_sweep(const INPUT& input, OUTPUT& output, 00146 const GEOMETRY& geometry = GEOMETRY()) : 00147 traits(input,output,geometry) {} 00148 00149 /*{\Mcreate creates a plane sweep object for a sweep on objects determined by 00150 |input| and delivers the result of the sweep in |output|. The traits 00151 class |T| specifies the models of all types and the implementations of all 00152 methods used by |\Mname|. At this point, it suffices to say that 00153 |INPUT| represents the input data type and |OUTPUT| represents the 00154 result data type. The |geometry| is an object providing object bound, 00155 geometry traits access.}*/ 00156 00157 generic_sweep(OUTPUT& output, const GEOMETRY& geometry = GEOMETRY()) : 00158 traits(output,geometry) {} 00159 /*{\Mcreate a simpler call of the above where |output| carries also 00160 the input.}*/ 00161 00162 /*{\Moperations}*/ 00163 00164 void sweep() 00165 /*{\Mop execute the plane sweep.}*/ 00166 { 00167 traits.initialize_structures(); 00168 traits.check_invariants(); 00169 post_init_hook(traits); 00170 00171 while ( traits.event_exists() ) { 00172 pre_event_hook(traits); 00173 traits.process_event(); 00174 post_event_hook(traits); 00175 traits.check_invariants(); 00176 traits.procede_to_next_event(); 00177 } 00178 traits.complete_structures(); 00179 traits.check_final(); 00180 post_completion_hook(traits); 00181 } 00182 00183 00184 /*{\Mexample 00185 A typical sweep based on |\Mname| looks like the following little 00186 program: 00187 \begin{Mverb} 00188 typedef std::list<POINT>::const_iterator iterator; 00189 typedef std::pair<iterator,iterator> iterator_pair; 00190 std::list<POINT> P; // fill input 00191 GRAPH<POINT,LINE> G; // the output 00192 generic_sweep<triang_sweep_traits> 00193 triangulation(iterator_pair(P.begin(),P.end()),G); 00194 triangulation.sweep(); 00195 \end{Mverb}}*/ 00196 00197 }; // generic_sweep<T> 00198 } // namespace CGAL 00199 00200 00201 00202 #endif // CGAL_GENERIC_SWEEP_H