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
00080 enum
00081 {
00082
00087 DefaultFadeTimeMs = 5,
00088
00094 DefaultSilentTimeMs = 1
00095 };
00096
00097
00098
00119 explicit
00120 Distiller( double partialFadeTime = Distiller::DefaultFadeTimeMs/1000.0,
00121 double partialSilentTime = Distiller::DefaultSilentTimeMs/1000.0 );
00122
00123
00124
00125
00126
00152 #if ! defined(NO_TEMPLATE_MEMBERS)
00153 template< typename Container >
00154 typename Container::iterator distill( Container & partials );
00155 #else
00156 inline
00157 PartialList::iterator distill( PartialList & partials );
00158 #endif
00159
00161 #if ! defined(NO_TEMPLATE_MEMBERS)
00162 template< typename Container >
00163 typename Container::iterator operator() ( Container & partials );
00164 #else
00165 PartialList::iterator operator() ( PartialList & partials );
00166 #endif
00167
00189 #if ! defined(NO_TEMPLATE_MEMBERS)
00190 template< typename Container >
00191 static typename Container::iterator
00192 distill( Container & partials, double partialFadeTime,
00193 double partialSilentTime = DefaultSilentTimeMs/1000.0 );
00194 #else
00195 static inline PartialList::iterator
00196 distill( PartialList & partials, double partialFadeTime,
00197 double partialSilentTime = DefaultSilentTimeMs/1000.0 );
00198 #endif
00199
00200 private:
00201
00202
00203
00223 PartialList::iterator distill_list( PartialList & partials );
00224
00230 void distillOne( PartialList & partials, Partial::label_type label,
00231 PartialList & distilled );
00232
00233 };
00234
00235
00236
00237
00262
00263 #if ! defined(NO_TEMPLATE_MEMBERS)
00264 template< typename Container >
00265 typename Container::iterator Distiller::distill( Container & partials )
00266 {
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 PartialList pl( partials.begin(), partials.end() );
00277 PartialList::iterator it = distill_list( pl );
00278
00279
00280
00281 typename Container::iterator beginUnlabeled =
00282 std::copy( pl.begin(), it, partials.begin() );
00283
00284 typename Container::iterator endUnlabeled =
00285 std::copy( it, pl.end(), beginUnlabeled );
00286
00287
00288 partials.erase( endUnlabeled, partials.end() );
00289
00290 return beginUnlabeled;
00291 }
00292
00293
00294 template< >
00295 inline
00296 PartialList::iterator Distiller::distill( PartialList & partials )
00297 {
00298 debugger << "using PartialList version of distill to avoid copying" << endl;
00299 return distill_list( partials );
00300 }
00301 #else
00302 inline
00303 PartialList::iterator Distiller::distill( PartialList & partials )
00304 {
00305 return distill_list( partials );
00306 }
00307 #endif
00308
00309
00310
00311
00315
00316 #if ! defined(NO_TEMPLATE_MEMBERS)
00317 template< typename Container >
00318 typename Container::iterator Distiller::operator()( Container & partials )
00319 #else
00320 inline
00321 PartialList::iterator Distiller::operator()( PartialList & partials )
00322 #endif
00323 {
00324 return distill( partials );
00325 }
00326
00327
00328
00329
00351
00352 #if ! defined(NO_TEMPLATE_MEMBERS)
00353 template< typename Container >
00354 typename Container::iterator
00355 Distiller::distill( Container & partials, double partialFadeTime,
00356 double partialSilentTime )
00357 #else
00358 inline
00359 PartialList::iterator
00360 Distiller::distill( PartialList & partials, double partialFadeTime,
00361 double partialSilentTime )
00362 #endif
00363 {
00364 Distiller instance( partialFadeTime, partialSilentTime );
00365 return instance.distill( partials );
00366 }
00367
00368 }
00369
00370 #endif