source: level2/competencies/FaceClassifier/src/SceneState.cpp @ 234

Revision 233, 2.1 KB checked in by dave, 10 years ago (diff)

added yarp interface

Line 
1// Copyright (C) 2009 foam
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation; either version 2 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17#include "SceneState.h"
18
19using namespace std;
20using namespace yarp::os;
21
22SceneState::SceneState()
23{
24        cerr<<"connecting to yarp..."<<endl;
25        m_YarpPort.open("/faceclassifier");
26}
27
28SceneState::~SceneState()
29{
30}
31       
32void SceneState::Update()
33{
34        // for each person present this frame
35        for (map<unsigned int, User>::iterator i=m_CurrentFrame.begin();
36                i!=m_CurrentFrame.end(); i++)
37        {
38                // look for in the last frame
39                map<unsigned int, User>::iterator l=m_LastFrame.find(i->first);
40                if (l==m_LastFrame.end())
41                {
42                        // new person!
43                        SendAppeared(i->first, i->second);
44                }
45        }
46       
47        // for each person present last frame
48        for (map<unsigned int, User>::iterator i=m_LastFrame.begin();
49                i!=m_LastFrame.end(); i++)
50        {
51                // look for in the current frame
52                map<unsigned int, User>::iterator l=m_CurrentFrame.find(i->first);
53                if (l==m_CurrentFrame.end())
54                {
55                        // disappeared!
56                        SendDisappeared(i->first);
57                }
58        }
59       
60        m_LastFrame=m_CurrentFrame;
61        m_CurrentFrame.clear();
62}
63
64void SceneState::SendAppeared(unsigned int ID, const User &u)
65{
66cerr<<"SendAppeared "<<ID<<endl;
67        Bottle b; 
68        b.clear();
69        b.add("user appeared");
70        b.add((int)ID);
71        b.add(u.m_Confidence);
72        m_YarpPort.write(b);
73}
74
75void SceneState::SendDisappeared(unsigned int ID)
76{
77cerr<<"SendDisappeared "<<ID<<endl;
78        Bottle b; 
79        b.clear();
80        b.add("user disappeared");
81        b.add((int)ID);
82        m_YarpPort.write(b);
83}
84
85void SceneState::AddPresent(unsigned int id, const User &u)
86{
87        m_CurrentFrame[id]=u;
88}
Note: See TracBrowser for help on using the repository browser.