www.pudn.com > hbp0.1.zip > classPersonalia.cpp
/***************************************************************************
classPersonalia.cpp
Keeps track of different people
begin : Sun Feb 15 2004
copyright : (C) 2004 by Bob Mottram
email : fuzzgun@btinternet.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include
#include
#include "classPersonalia.h"
///
/// Constructor
///
classPersonalia::classPersonalia()
{
int i,j,k;
currentTime=0;
prev_personID=-1;
for (i=0;i
/// Destructor
///
classPersonalia::~classPersonalia()
{
updateAverages(currentTime);
save("c:\\develop\\hbp\\people.dat");
}
///
/// update the colour of clothing
///
/// A unique ID number for the person
/// red component of the clothing colour
/// green component of the clothing colour
/// blue component of the clothing colour
void classPersonalia::updateWardrobe(int personID, int r, int g, int b)
{
int i,min,dist,winner;
winner = currentWardrobeID[personID];
dist = abs(wardrobe[personID][winner][0] - r) +
abs(wardrobe[personID][winner][1] - g) +
abs(wardrobe[personID][winner][2] - b);
if (dist>50)
{
min=99999;
dist=0;
winner=-1;
for (i=0;i<5;i++)
{
dist = abs(wardrobe[personID][i][0] - r) +
abs(wardrobe[personID][i][1] - g) +
abs(wardrobe[personID][i][2] - b);
if (dist-1)
{
//update the wardrobe for the closest match
wardrobe[personID][winner][0] = wardrobe[personID][winner][0] + ((r - wardrobe[personID][winner][0])/2);
wardrobe[personID][winner][1] = wardrobe[personID][winner][1] + ((g - wardrobe[personID][winner][1])/2);
wardrobe[personID][winner][2] = wardrobe[personID][winner][2] + ((b - wardrobe[personID][winner][2])/2);
currentWardrobeID[personID] = winner;
}
}
///
/// update averages
///
void classPersonalia::updateAverages(long time_elapsed)
{
int i,j,k;
long observation_time;
if (time_elapsed>0)
{
for (i=0;i0)
{
intimacy[i][0] = (intimacy[i][0] + (intimacy[i][1] / observation_time))/2;
engagement[i][0] = (engagement[i][0] + ((engagement[i][1] * 100) / observation_time))/2;
expressiveness[i][0] = 0;
intensity[i][0] = 0;
aggressiveness[i][0] = 0;
verbosity[i][0] = 0;
instructiveness[i][0] = 0;
}
}
//store the history
for (j=PERSONAL_HISTORY-1;j>0;j--)
for (k=0;k<10;k++)
history[i][j][k] = history[i][j-1][k];
history[i][0][0] = familiarity[i][0];
history[i][0][1] = intimacy[i][0];
history[i][0][2] = engagement[i][0];
history[i][0][3] = expressiveness[i][0];
history[i][0][4] = intensity[i][0];
history[i][0][5] = aggressiveness[i][0];
history[i][0][6] = verbosity[i][0];
history[i][0][7] = instructiveness[i][0];
history[i][0][8] = currentWardrobeID[i];
}
}
}
///
/// update using the given person detector
///
/// person detection object
void classPersonalia::update(classHumunculus *persondetector)
{
int personID;
if (persondetector!=NULL)
{
personID = persondetector->personID - 1;
if ((personID>-1) && (personIDgetPersonName(personID,name[personID]);
initialised[personID]=true;
}
//increase the familiarity with this person
familiarity[personID][1]++;
//calculate intimacy
intimacy[personID][1] += persondetector->bodyWidth;
//if the person is within "personal space" range then assume they are engaging the robot
if (persondetector->bodyWidth>25) engagement[personID][1]++;
//update colour of clothing being worn
updateWardrobe(personID,persondetector->bodyColour[0],persondetector->bodyColour[1],persondetector->bodyColour[2]);
}
prev_personID = personID;
}
}
///
/// Save details about observed people
///
/// The filename to save to
void classPersonalia::save(char *filename)
{
int i,j,k;
FILE *fp;
fp = fopen(filename, "w");
if (fp != NULL)
{
fprintf(fp,"%d\n",MAX_PEOPLE);
for (i=0;i
/// Load details about observed people
///
/// The filename to load from
void classPersonalia::load(char *filename)
{
int i,j,k,NoOfPeople,p;
long v;
FILE *fp;
fp = fopen(filename, "r");
if (fp != NULL)
{
fscanf(fp,"%d\n",&NoOfPeople);
for (i=0;i