// // MPTPluginController.m // // Created by Andrew Salamon on 9/25/06. // Copyright 2006 __MyCompanyName__. All rights reserved. // #import "MPTPluginController.h" #import #import @interface MPTPluginController(PrivateMethods) - (void)loadFilters; - (void)setViewRanges:(MPT_AUView *)aView; @end static const int AU = 101; @implementation MPTPluginController - (id)init { if( self = [super init] ) { smiles = new MPSmile; smiles->setPixelMax( 1.0 ); [self loadFilters]; [self setDoFilters:YES]; } return self; } - (void)dealloc { delete smiles; delete filters; [super dealloc]; } - (BOOL)doFilters { return doFilters; } - (void)setDoFilters:(BOOL)value { if( doFilters != value ) { doFilters = value; NSEnumerator *viewEnum = [views objectEnumerator]; while( MPT_AUView *aView = [viewEnum nextObject] ) { [self setViewRanges:aView]; } } } - (BOOL)loadLabels { labels = [[NSArray alloc] initWithObjects:[self localizedName], nil]; return YES; } - (NSString *)pluginID { NSString *ident = [super pluginID]; if( [ident length] > 0 ) return ident; return @"edu.ucsd.mplab.plugins.SmileDetector"; } - (NSString *)localizedName { return NSLocalizedStringFromTableInBundle(@"Smile Detector", nil, [NSBundle bundleForClass:[self class]], @""); } - (NSString *)internalName { return @"smiles"; } - (NSString *)step { return MPT_PluginStep_AfterFaces; } - (void)setView:(MPT_AUView *)newView forLabel:(NSString *)label { [super setView:newView forLabel:label]; [self setViewRanges:newView]; } - (void)setViewRanges:(MPT_AUView *)aView { [aView resetDynamicRange]; if( doFilters ) { [aView setDefaultMin:0.0]; [aView setDefaultMax:1.0]; } else { [aView setDefaultMin:-0.5]; [aView setDefaultMax:0.5]; } } - (BOOL)processFaces:(EyeFaceList &)faces fromEyefinder:(MPTSlidingWindow *)eyefinder withImage:(RImage &)pixels { RIntegral* pfIntegral = static_cast*>(eyefinder->getIntegralPtr().get()); if( SMD_NO_ERR == smiles->findSmilesGivenEyes( pixels, faces, 1.0f, pfIntegral ) ) { if( doFilters && (faces.size() > 0) ) { double value = faces.begin()->activation; value = filters->filterValue( AU, value, true ); faces.begin()->activation = value; } return YES; } return NO; } - (double)processFace:(FaceObject &)face withImage:(RImage &)pixels { smiles->findSmilesFromFace( pixels, face, 1.0 ); if( doFilters ) { return filters->filterValue( AU, face.activation, true ); } return face.activation; } - (void)processNoFace { if( doFilters ) { filters->filterValue( AU, 0.0, false ); } } - (void)loadFilters { NSBundle *CERTFramework = [NSBundle bundleWithIdentifier:@"edu.ucsd.mplab.CERTFramework"]; NSString *tablesDir = [[CERTFramework resourcePath] stringByAppendingPathComponent:@"likelihood_tables"]; std::string dir( ([tablesDir length]?[tablesDir UTF8String]:"") ); std::vector auLabels; auLabels.push_back(AU); filters = new ExpressionFilterWrapper( auLabels, dir ); } @end