// // MPT_Deception.m // MPT_Deception // // Created by Andrew Salamon on 7/21/10. // Copyright 2010 Machine Perception Laboratory, University of California San Diego.. All rights reserved. // #import "MPT_Deception.h" #import "MPT_DeceptionStatus.h" #import @implementation MPT_Deception - (id)initWithBundle:(NSBundle *)_bundle { if( self = [super initWithBundle:_bundle] ) { NSString *ayPath = [_bundle pathForResource:@"ay" ofType:@"txt"]; NSString *vsPath = [_bundle pathForResource:@"vs" ofType:@"txt"]; if( ![ayPath length] || ![vsPath length] ) { NSLog( @"Unable to load data files for MPT_Deception." ); return nil; } deception = new mpt::Deception( [ayPath UTF8String], [vsPath UTF8String] ); if( ![NSBundle loadNibNamed:@"StatusView" owner:self] ) NSLog( @"Unable to load Status View for MPT_Deception plugin." ); // [statusView setScale:2]; // if we want it to start out big meter = [[MPT_MeterController alloc] initWithNibNamed:@"DeceptionDial" fromBundle:[self bundle]]; [meter setMin:-2.0]; [meter setMax:5.0]; [meter setCutoff:0.0]; [meter setLabel:[self localizedName]]; MPT_AUView *auView = [meter auView]; [auView addSubview:statusView]; [statusView setFrameOrigin:NSMakePoint(268.0, 48.0)]; [self setView:auView forLabel:[[self labels] objectAtIndex:0]]; } return self; } - (id)copyWithZone:(NSZone *)zone { return nil; } - (void)dealloc { delete deception; deception = nil; [super dealloc]; } - (void)awakeFromNib { [self initViews]; } - (NSString *)step { return MPT_PluginStep_Results; } - (NSString *)localizedName { return NSLocalizedStringFromTableInBundle(@"Deception", nil, [NSBundle bundleForClass:[self class]], @""); } - (NSString *)internalName { return @"deception"; } - (NSView *)prefPane { return nil; } - (void)initViews { NSString *label = [labels objectAtIndex:0]; if( label ) { MPT_AUView *view = [self viewForLabel:label]; if( !view ) { //view = statusView; view = [meter auView]; [view setAUString:label]; [self setView:view forLabel:label]; [view release]; } } } - (NSMutableDictionary *)processResults:(NSDictionary *)results usingController:(id)controller { BOOL faceFound = ([[results objectForKey:@"CERT.faces"] count] > 0); if( faceFound ) { id poseRes = [results objectForKey:@"edu.ucsd.mplab.plugins.PoseDetector"]; if( [poseRes count] != 3 ) { deception->interpolate( mpt::vectorD1D(), false ); return nil; } id auRes = [results objectForKey:@"edu.ucsd.mplab.plugins.CERT4_4_Weights"]; id blinkRes = [results objectForKey:@"edu.ucsd.mplab.plugins.BlinkAU"]; id addRes = [results objectForKey:@"edu.ucsd.mplab.plugins.AdditionalAUs3"]; std::vector aus; aus.push_back( [[auRes objectForKey:@"(AU 1) Inner Brow Raise"] doubleValue] ); aus.push_back( [[auRes objectForKey:@"(AU 2) Outer Brow Raise"] doubleValue] ); aus.push_back( [[auRes objectForKey:@"(AU 4) Brow Lower"] doubleValue] ); aus.push_back( [[auRes objectForKey:@"(AU 5) Eye Widen"] doubleValue] ); aus.push_back( [[addRes objectForKey:@"(AU 6) Cheek Raise"] doubleValue] ); aus.push_back( [[addRes objectForKey:@"(AU 7) Lids Tight"] doubleValue] ); aus.push_back( [[auRes objectForKey:@"(AU 9) Nose Wrinkle"] doubleValue] ); aus.push_back( [[auRes objectForKey:@"(AU 10) Lip Raise"] doubleValue] ); aus.push_back( [[auRes objectForKey:@"(AU 12) Lip Corner Pull"] doubleValue] ); aus.push_back( [[auRes objectForKey:@"(AU 14) Dimpler"] doubleValue] ); aus.push_back( [[auRes objectForKey:@"(AU 15) Lip Corner Depressor"] doubleValue] ); aus.push_back( [[auRes objectForKey:@"(AU 17) Chin Raise"] doubleValue] ); aus.push_back( [[addRes objectForKey:@"(AU 18) Lip Pucker"] doubleValue] ); aus.push_back( [[auRes objectForKey:@"(AU 20) Lip stretch"] doubleValue] ); aus.push_back( [[addRes objectForKey:@"(AU 23) Lip Tightener"] doubleValue] ); aus.push_back( [[addRes objectForKey:@"(AU 24) Lip Presser"] doubleValue] ); aus.push_back( [[addRes objectForKey:@"(AU 25) Lips Part"] doubleValue] ); aus.push_back( [[addRes objectForKey:@"(AU 26) Jaw Drop"] doubleValue] ); aus.push_back( [[addRes objectForKey:@"(AU 28) Lips Suck"] doubleValue] ); aus.push_back( [[blinkRes objectForKey:@"(AU 45) Blink/Eye Closure"] doubleValue] ); aus.push_back( [[poseRes objectForKey:@"Yaw"] doubleValue] ); aus.push_back( [[poseRes objectForKey:@"Pitch"] doubleValue] ); aus.push_back( [[poseRes objectForKey:@"Roll"] doubleValue] ); if( aus.size() != 23 ) { NSLog( @"Wrong number of AUs in MPT_Deception." ); deception->interpolate( mpt::vectorD1D(), false ); return nil; } deception->interpolate( aus, true ); } else { deception->interpolate( mpt::vectorD1D(), false ); } return nil; } - (IBAction)clear:(id)sender { deception->start(); // clear all data } - (IBAction)calculate:(id)sender { double value = deception->currentValue(); [[meter auView] addValue:value]; [statusView resetDynamicRange]; [statusView addValue:value]; } @end