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/sweep_observer.h $ 00015 // $Id: sweep_observer.h 29549 2006-03-16 14:02:34Z hachenb $ 00016 // 00017 // 00018 // Author(s) : Michael Seel <seel@mpi-sb.mpg.de> 00019 #ifndef CGAL_SWEEP_OBSERVER_H 00020 #define CGAL_SWEEP_OBSERVER_H 00021 00022 #include <list> 00023 00024 namespace CGAL { 00025 00026 // TR is traits 00027 template <typename TR> 00028 class client_base 00029 { 00030 public: 00031 virtual void call(TR) const = 0; 00032 virtual ~client_base() {} 00033 }; 00034 00035 00036 template <typename TR> 00037 class Event_hook 00038 { 00039 typedef client_base<TR>* p_client_base; 00040 typedef std::list< p_client_base > clientlist; 00041 protected: 00042 clientlist clients; 00043 public: 00044 Event_hook() : clients() {} 00045 ~Event_hook() { 00046 while ( !clients.empty() ) { 00047 delete (*clients.begin()); 00048 clients.pop_front(); 00049 } 00050 } 00051 00052 void operator()(TR t) const 00053 { if ( clients.empty() ) return; 00054 for ( typename clientlist::const_iterator it=clients.begin(); 00055 it != clients.end(); ++it ) 00056 (*it)->call(t); 00057 } 00058 00059 void attach(p_client_base psb) 00060 { clients.push_back(psb); } 00061 00062 }; 00063 00064 00065 // TR is traits, OBS is observer 00066 template <class OBS, class TR> 00067 class client : public client_base<TR> 00068 { 00069 protected: 00070 OBS& obs_ref; 00071 void (OBS::* p_fnc)(TR); 00072 // pointer to member of Observer which works on an object of type TR 00073 public: 00074 client( OBS& obs, void (OBS::* p_fnc_init)(TR) ) : 00075 obs_ref(obs), p_fnc(p_fnc_init) {} 00076 00077 void call(TR t) const 00078 { (obs_ref.*p_fnc)(t); } 00079 }; 00080 00081 00082 template <class OBS, class TR> 00083 inline void attach(Event_hook<TR>& h, 00084 OBS& obs, void (OBS::* p_fct)(TR t)) 00085 { 00086 client<OBS,TR>* ps = new client<OBS,TR>(obs,p_fct); 00087 h.attach( (client_base<TR>*) ps); 00088 } 00089 00090 /*{\Moptions outfile=sweep_observer.man}*/ 00091 /*{\Manpage {sweep_observer}{GPS,VT} 00092 {Observing the plane sweep class}{Obs}}*/ 00093 /*{\Mdefinition The data type |\Mname| provides an observer approach 00094 to the visualization of a sweep algorithm realized by |GPS = 00095 generic_sweep<T>| by means of an event mechanism. It allows to 00096 connect the events of an instance of |GPS| to the visualization 00097 operations provided by the traits class |VT|.}*/ 00098 00099 template <class GPS, class VT> 00100 class sweep_observer { 00101 00102 VT vt; 00103 00104 typedef typename GPS::TRAITS GPSTRAITS; 00105 typedef typename VT::VDEVICE VDEVICE; 00106 00107 void post_init_animation(GPSTRAITS& gpst) 00108 { vt.post_init_animation(gpst); } 00109 00110 void pre_event_animation(GPSTRAITS& gpst) 00111 { vt.pre_event_animation(gpst); } 00112 00113 void post_event_animation(GPSTRAITS& gpst) 00114 { vt.post_event_animation(gpst); } 00115 00116 void post_completion_animation(GPSTRAITS& gpst) 00117 { vt.post_completion_animation(gpst); } 00118 00119 public : 00120 00121 /*{\Mcreation 3cm}*/ 00122 00123 sweep_observer() : vt() {} 00124 /*{\Mcreate creates an object of type |VT| which can support a 00125 visualization device to visualize a sweep object of type |GPS|.}*/ 00126 00127 sweep_observer(GPS& gps); 00128 /*{\Mcreate creates an object of type |VT| which can support a 00129 visualization device to visualize a sweep object of type |GPS| 00130 and makes it an observer of |gps|.}*/ 00131 00132 /*{\Moperations 2cm 2cm}*/ 00133 00134 void attach(GPS& gps); 00135 /*{\Mop makes |\Mvar| an observer of |gps|.}*/ 00136 00137 VDEVICE& device() 00138 { return vt.device(); } 00139 00140 }; 00141 00142 /*{\Mexample 00143 A typical sweep observation based on |\Mname| looks like the following 00144 little program: 00145 \begin{Mverb} 00146 typedef generic_sweep<triang_sweep_traits> triang_sweep; 00147 triang_sweep Ts(...); 00148 sweep_observer< triang_sweep, 00149 cgal_window_stream_ts_visualization > Obs(Ts); 00150 Ts.sweep(); 00151 \end{Mverb} 00152 This would visualize the sweep actions in the observer window by means 00153 of the visualization functions provided in 00154 |cgal_\-window_\-stream_\-ts_\-visualization| 00155 }*/ 00156 00157 00158 template <class GPS, class VT> 00159 sweep_observer<GPS,VT>:: 00160 sweep_observer(GPS& gps) : vt() { attach(gps); } 00161 00162 template <class GPS, class VT> 00163 void 00164 sweep_observer<GPS,VT>::attach(GPS& gps) 00165 { 00166 CGAL::attach(gps.post_init_hook, *this, 00167 &sweep_observer::post_init_animation); 00168 CGAL::attach(gps.pre_event_hook, *this, 00169 &sweep_observer::pre_event_animation); 00170 CGAL::attach(gps.post_event_hook, *this, 00171 &sweep_observer::post_event_animation); 00172 CGAL::attach(gps.post_completion_hook, *this, 00173 &sweep_observer::post_completion_animation); 00174 } 00175 00176 #ifdef THIS_IS_JUST_A_CONCEPT_DEFINITION 00177 00178 /*{\Moptions outfile=vgps_concept.man}*/ 00179 /*{\Manpage {GPS_visualization_concept}{} 00180 {Visualization of the generic plane sweep}{C}}*/ 00181 class GPS_visualization_concept { 00182 /*{\Mdefinition |\Mtype| is the concept for the second template 00183 parameter |VT| of the sweep observer |sweep_observer<GPS,VT>| defined 00184 above. It provides the interface to adapt the sweep observation 00185 process to a visualization device. }*/ 00186 00187 /*{\Mtypes 5}*/ 00188 typedef some_visualization_device VDEVICE; 00189 /*{\Mtypemember the visualization device}*/ 00190 00191 /*{\Mcreation 3}*/ 00192 GPS_visualization_concept(); 00193 /*{\Mcreate can be used to initialize and display the visualization 00194 device.}*/ 00195 00196 /*{\Moperations}*/ 00197 00198 void post_init_animation(GPS::TRAITS& gpst) 00199 /*{\Mop animation actions after the initialization of the sweep.}*/ 00200 void pre_event_animation(GPS::TRAITS& gpst) 00201 /*{\Mop animation actions before each event handling.}*/ 00202 void post_event_animation(GPS::TRAITS& gpst) 00203 /*{\Mop animation actions after each event handling.}*/ 00204 void post_completion_animation(GPS::TRAITS& gpst) 00205 /*{\Mop animation actions after the completion phase of the sweep.}*/ 00206 VDEVICE& device() 00207 /*{\Mop access operation to the visualization device.}*/ 00208 00209 /*{\Mtext Note that the entry point for visualization of the sweep 00210 is the access to an object |gpst| of type |GPS::TRAITS|. This is the 00211 sweep traits class triggering the sweep within the generic sweep 00212 framework and storing all status information of the sweep. Thereby it 00213 contains also all information necessary for visualization. |\Mvar| 00214 obtains access to this object at defined event points and can thereby 00215 analyze the status of |gpst| and trigger corresponding visualization 00216 actions via its visualization methods.}*/ 00217 00218 }; 00219 00220 #endif // THIS_IS_JUST_A_CONCEPT_DEFINITION 00221 00222 } // namespace CGAL 00223 00224 #endif // CGAL_SWEEP_OBSERVER_H 00225