00001 #ifndef INCLUDE_DISTILLER_H
00002 #define INCLUDE_DISTILLER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "Partial.h"
00037 #include "PartialList.h"
00038 #include "PartialUtils.h"
00039
00040 #include "Notifier.h"
00041
00042 #include <algorithm>
00043
00044
00045 namespace Loris {
00046
00047
00048
00049
00068
00069 class Distiller
00070 {
00071
00072
00073 double _fadeTime, _gapTime;
00074
00075
00076 public:
00077
00078
00079
00082 static const double DefaultFadeTime;
00083
00086 static const double DefaultSilentTime;
00087
00088
00089
00110 explicit
00111 Distiller( double partialFadeTime = Distiller::DefaultFadeTime,
00112 double partialSilentTime = Distiller::DefaultSilentTime );
00113
00114
00115
00116
00117
00143 #if ! defined(NO_TEMPLATE_MEMBERS)
00144 template< typename Container >
00145 typename Container::iterator distill( Container & partials );
00146 #else
00147 inline
00148 PartialList::iterator distill( PartialList & partials );
00149 #endif
00150
00152 #if ! defined(NO_TEMPLATE_MEMBERS)
00153 template< typename Container >
00154 typename Container::iterator operator() ( Container & partials );
00155 #else
00156 PartialList::iterator operator() ( PartialList & partials );
00157 #endif
00158
00180 #if ! defined(NO_TEMPLATE_MEMBERS)
00181 template< typename Container >
00182 static typename Container::iterator
00183 distill( Container & partials, double partialFadeTime,
00184 double partialSilentTime = Distiller::DefaultSilentTime );
00185 #else
00186 static inline PartialList::iterator
00187 distill( PartialList & partials, double partialFadeTime,
00188 double partialSilentTime = Distiller::DefaultSilentTime );
00189 #endif
00190
00191 private:
00192
00193
00194
00214 PartialList::iterator distill_list( PartialList & partials );
00215
00221 void distillOne( PartialList & partials, Partial::label_type label,
00222 PartialList & distilled );
00223
00224 };
00225
00226
00227
00228
00253
00254 #if ! defined(NO_TEMPLATE_MEMBERS)
00255 template< typename Container >
00256 typename Container::iterator Distiller::distill( Container & partials )
00257 {
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 PartialList pl( partials.begin(), partials.end() );
00268 PartialList::iterator it = distill_list( pl );
00269
00270
00271
00272 typename Container::iterator beginUnlabeled =
00273 std::copy( pl.begin(), it, partials.begin() );
00274
00275 typename Container::iterator endUnlabeled =
00276 std::copy( it, pl.end(), beginUnlabeled );
00277
00278
00279 partials.erase( endUnlabeled, partials.end() );
00280
00281 return beginUnlabeled;
00282 }
00283
00284
00285 template< >
00286 inline
00287 PartialList::iterator Distiller::distill( PartialList & partials )
00288 {
00289 debugger << "using PartialList version of distill to avoid copying" << endl;
00290 return distill_list( partials );
00291 }
00292 #else
00293 inline
00294 PartialList::iterator Distiller::distill( PartialList & partials )
00295 {
00296 return distill_list( partials );
00297 }
00298 #endif
00299
00300
00301
00302
00306
00307 #if ! defined(NO_TEMPLATE_MEMBERS)
00308 template< typename Container >
00309 typename Container::iterator Distiller::operator()( Container & partials )
00310 #else
00311 inline
00312 PartialList::iterator Distiller::operator()( PartialList & partials )
00313 #endif
00314 {
00315 return distill( partials );
00316 }
00317
00318
00319
00320
00342
00343 #if ! defined(NO_TEMPLATE_MEMBERS)
00344 template< typename Container >
00345 typename Container::iterator
00346 Distiller::distill( Container & partials, double partialFadeTime,
00347 double partialSilentTime )
00348 #else
00349 inline
00350 PartialList::iterator
00351 Distiller::distill( PartialList & partials, double partialFadeTime,
00352 double partialSilentTime )
00353 #endif
00354 {
00355 Distiller instance( partialFadeTime, partialSilentTime );
00356 return instance.distill( partials );
00357 }
00358
00359 }
00360
00361 #endif