/home/fwph/code/wurde/rde/core/capabilities/FaceDetector.cpp

Go to the documentation of this file.
00001 
00029 #include <FaceDetector.H>
00030 #include <CommsManager.H>
00031 #include <Logger.H>
00032 
00033 // $Id: Type.cpp 68 2007-02-01 17:56:57Z fwph $
00034 
00035 using namespace WURDE;
00036 
00037 FaceDetector::FaceDetector(const std::string & streamname){
00038        init(streamname,STRAT_NORMAL,"Any");
00039 
00040        //global name will be set later
00041        m_haveGlobalname=false;
00042 }
00043 
00044 FaceDetector::FaceDetector(const ConnectionStrategy & strategy,const std::string & gblName){
00045        init("Any",strategy,gblName);
00046 
00047        if(strategy==STRAT_NORMAL){
00048               //then the global name really specifies the streamname,
00049               // and the global name should be assigned automagically once we have
00050               // confirmation that the stream has been started
00051               m_haveGlobalname=false;   
00052        }
00053 
00054        m_haveStream=false;
00055        
00056 }
00057 
00058 FaceDetector::FaceDetector(const std::string &streamname,const std::string &gblName){
00059        init(streamname,STRAT_NORMAL,gblName);
00060 }
00061 
00062 void FaceDetector::init(const std::string &streamname,const ConnectionStrategy &strategy,const std::string &gblName){
00063   m_globalname=gblName;
00064   m_streamname=streamname;
00065 
00066   myCOMObject=NULL;
00067   
00068   //  data.source=streamname.c_str();
00069   requests=info;
00070 
00071   m_queue=false;
00072   m_supplier=false;
00073   m_doTimestamp=true;
00074   m_doTag=true;
00075 
00076   m_doPublishData=false;
00077   m_doPublishInfo=false;
00078 
00079   m_initialize=false;
00080   m_strategy=strategy;
00081 
00082   m_haveStream=true;
00083   m_haveGlobalname=true;
00084   m_doPublishData=false;
00085   m_doPublishInfo=false;
00086 
00087   m_doAutoPing=true;
00088 
00089   info.source=streamname;
00090   requests.source=m_globalname;
00091   info.target="Any";
00092   requests.target=streamname;
00093   info.timestamp.now();
00094   requests.timestamp.now();
00095 
00096   m_streamRequest=STAT_NULL;
00097   
00098   m_sourceModule="Unknown";
00099 }
00100 
00101 
00102 FaceDetector::~FaceDetector(){
00103   myManager=NULL;
00104   if(myCOMObject){
00105 
00106          //      delete myCOMObject;
00107   }
00108 }
00109 
00110 
00111 void FaceDetector::activateSupplier(){
00112        if(m_haveStream){
00113               m_supplier=true;
00114               m_globalname=m_streamname;
00115               m_haveGlobalname=true;
00116               m_initialize=false;
00117               if(myCOMObject){
00118                       //                     myCOMObject=new CMUIPCRobotProtocol::CMUIPCFaceDetector(m_globalname);
00119                      myCOMObject->setGlobalName(m_globalname);
00120                      myCOMObject->setStreamName(m_streamname);
00121                      myCOMObject->setInfo(&requests);
00122                      myCOMObject->setRequests(&info);
00123                      myCOMObject->setStaging(&data);
00124                      myCOMObject->activateSupplier();
00125                      myCOMObject->setAutoPing(m_doAutoPing);
00126                      myCOMObject->setInfoVector(&m_requestVector);
00127                      myCOMObject->setRequestVector(&m_infoVector);
00128                      myCOMObject->setDataVector(&m_dataVector);
00129 
00130                      data.source=m_streamname;
00131                      info.source=m_streamname;
00132 
00133                      if(m_queue){
00134                             myCOMObject->setQueueMode(true);
00135                      }
00136 
00137               }else{
00138                       g_fatal("Attempted to activateSupplier before setting a COMObject Please just use registerSupplier.");
00139                       exit(-1);
00140               }
00141         data.foundFaces.clear();
00142        }else{
00143               //this shouldn't happen, but there's no real problem with it.
00144               //it'd just be dumb.
00145               m_initialize=true;
00146               m_supplier=true;
00147        }
00148        
00149        requests=info;
00150 
00151 }
00152 
00153 void FaceDetector::activateConsumer(){
00154        std::string localname;
00155        
00156        if(m_haveStream){
00157               m_initialize=false;
00158               m_supplier=false;
00159               if(myCOMObject&&myManager){
00160                       /* global name so we don't have conflicts with the naming service */
00161                       if(!m_haveGlobalname&&m_strategy==STRAT_NORMAL){
00162                               m_globalname=myManager->getName()+FACEDETECTOR+m_streamname+"Consumer";
00163                               m_haveGlobalname=true;
00164                       }
00165 
00166                      myCOMObject->setGlobalName(m_globalname);
00167                      myCOMObject->setStreamName(m_streamname);
00168                      requests.source=m_globalname;
00169                      data.source=m_streamname;
00170                      info.source=m_streamname;
00171                      myCOMObject->setInfo(&info);
00172                      myCOMObject->setRequests(&requests);
00173                      myCOMObject->setStaging(&data);
00174                      myCOMObject->setAutoPing(m_doAutoPing);
00175                      myCOMObject->activateConsumer();
00176                      myCOMObject->setInfoVector(&m_infoVector);
00177                      myCOMObject->setRequestVector(&m_requestVector);
00178                      myCOMObject->setDataVector(&m_dataVector);
00179 
00180                      if(m_queue){
00181                             myCOMObject->setQueueMode(true);
00182                      }
00183               }else{
00184                       g_fatal("Attempted to activateConsumer before setting a COMObject and CommsManager. Please use registerConsumer instead.");
00185                      exit(-1);
00186               }
00187 
00188         data.foundFaces.clear();
00189        }else{
00190               //no stream, so we can't connect yet. tell the system 
00191               //to initialize as soon as we've got one
00192               m_initialize=true;
00193        }
00194 
00195 }
00196 
00197 void FaceDetector::runUpdate(){
00198        if(myCOMObject){
00199 
00200               myCOMObject->runUpdate(m_doPublishData,m_doPublishInfo);
00201               
00202               m_doPublishData=false;
00203               m_doPublishInfo=false;
00204               
00205        }
00206 }
00207 
00208 void FaceDetector::setManager(CommsManager *myManager_){
00209 
00210   if(!myCOMObject){
00211     myManager=myManager_;
00212   }
00213 
00214 }
00215 
00216 void FaceDetector::setQueueMode(const bool & val){
00217 
00218        if(!myCOMObject){
00219               m_queue=val;
00220        }else if(!m_queue&&val){
00221               m_queue=val;
00222               myCOMObject->setDataVector(&m_dataVector);
00223               myCOMObject->setQueueMode(true);
00224 
00225        }else if(!val&&m_queue){
00226               m_queue=val;
00227               myCOMObject->setQueueMode(false);
00228               while(!m_dataVector.empty()){
00229                      m_dataVector.pop();
00230               }
00231               while(!m_infoVector.empty()){
00232                      m_infoVector.pop();
00233               }
00234               while(!m_requestVector.empty()){
00235                      m_requestVector.pop();
00236               }
00237        }
00238 }
00239 
00240 bool FaceDetector::newData(){
00241        if(m_queue){
00242               return !m_dataVector.empty();
00243        }else{
00244               if(myCOMObject){
00245                      return myCOMObject->newData();
00246               }
00247        }
00248 
00249        return false;
00250 }
00251 
00252 bool FaceDetector::newInfo(){
00253        if(m_queue){
00254               if(m_supplier){
00255                      return !m_requestVector.empty();
00256               }
00257 
00258               return !m_infoVector.empty();
00259        }else{
00260               if(myCOMObject){
00261                      return myCOMObject->newInfo();
00262               }
00263        }
00264 
00265 
00266        return false;
00267 }
00268 
00269 void FaceDetector::publishData(){
00270        if(m_supplier){
00271               if(m_doTimestamp){
00272                      data.timestamp.now();
00273               }
00274               if(m_doTag){
00275                      data.source=m_globalname;
00276               }
00277               if(m_queue){
00278                      FaceDetectorDataStruct temp;
00279         temp.foundFaces.clear();
00280                      temp.foundFaces=data.foundFaces;
00281 temp.source=data.source;
00282 temp.timestamp=data.timestamp;
00283  
00284                      m_dataVector.push(temp);
00285                               //                     m_dataVector.push(data);
00286               }
00287               m_doPublishData=true;
00288        }
00289 }
00290 
00291 void FaceDetector::publishInfo(){
00292        if(m_supplier){
00293 
00294               info.mType=MESSAGE_INFO;
00295               if(m_doTimestamp){
00296                      info.timestamp.now();
00297               }
00298 
00299               if(m_doTag){
00300                      info.source=m_globalname;
00301                      info.target="Any";
00302               }
00303 
00304               if(m_queue){
00305                      FaceDetectorInfoStruct temp;
00306                      
00307                     
00308                      temp.source=info.source;
00309 temp.target=info.target;
00310 temp.timestamp=info.timestamp;
00311 temp.mType=info.mType;
00312 
00313                      m_infoVector.push(temp);
00314                     
00315                      //              m_infoVector.push(info);
00316               }
00317 
00318               m_doPublishInfo=true;
00319        }else{
00320 
00321               requests.mType=MESSAGE_REQUEST;
00322               
00323               if(m_doTimestamp){
00324                      requests.timestamp.now();
00325               }
00326 
00327               if(m_doTag){
00328                      requests.source=m_globalname;
00329                      requests.target=m_streamname;
00330               }
00331 
00332               if(m_queue){
00333                      FaceDetectorInfoStruct temp;
00334                      temp.source=requests.source;
00335 temp.target=requests.target;
00336 temp.timestamp=requests.timestamp;
00337 temp.mType=requests.mType;
00338 
00339                      m_requestVector.push(temp);
00340 
00341                      //              m_requestVector.push(requests);
00342               }
00343 
00344               m_doPublishInfo=true;
00345        }
00346 }
00347 
00348 FaceDetectorDataStruct FaceDetector::getNextData(){
00349        if(m_queue){
00350               FaceDetectorDataStruct retval;
00351         retval.foundFaces.clear();
00352               retval.source="NULL";
00353               if(m_dataVector.empty()){
00354                      return data;
00355               }
00356              
00357               retval.foundFaces=m_dataVector.front().foundFaces;
00358 retval.source=m_dataVector.front().source;
00359 retval.timestamp=m_dataVector.front().timestamp;
00360 
00361                        //             retval=m_dataVector.front();
00362               m_dataVector.pop();
00363               data=retval;
00364        
00365               return retval;
00366        }else{
00367               myCOMObject->resetData();
00368               return data;
00369        }
00370 }
00371 
00372 FaceDetectorInfoStruct FaceDetector::getNextInfo(){
00373        if(m_queue){
00374               FaceDetectorInfoStruct retval;
00375               retval.source="NULL";
00376               if(m_supplier){
00377                      if(m_requestVector.empty()){
00378                             return requests;
00379                      }
00380                      retval.source=m_requestVector.front().source;
00381 retval.target=m_requestVector.front().target;
00382 retval.timestamp=m_requestVector.front().timestamp;
00383 retval.mType=m_requestVector.front().mType;
00384 
00385                               //                     retval=m_requestVector.front();
00386                      m_requestVector.pop();
00387                      requests=retval;
00388                      return retval;
00389               }else{
00390                      if(m_infoVector.empty()){
00391                             return info;
00392                      }
00393                      retval.source=m_infoVector.front().source;
00394 retval.target=m_infoVector.front().target;
00395 retval.timestamp=m_infoVector.front().timestamp;
00396 retval.mType=m_infoVector.front().mType;
00397 
00398                      m_infoVector.pop();
00399                      info=retval;
00400                      // the requests struct really should get the values in 
00401                      // info
00402                      requests=info;
00403                      
00404                      return retval;
00405               }
00406        }else{
00407               myCOMObject->resetInfo();
00408               if(m_supplier){
00409                      return requests;
00410               }else{
00411                      // the requests struct really should get the values in 
00412                      // info
00413                      requests=info;
00414                      return info;
00415               }
00416        }
00417 }
00418 
00419 void FaceDetector::setStreamName(const std::string & name){
00420 
00421        if(m_supplier&&name=="Any"){
00422               return;
00423        }
00424 
00425        m_streamname=name;
00426        m_haveStream=true;
00427 
00428        if(m_supplier){
00429               m_globalname=name;
00430        }
00431        
00432        if(myCOMObject){
00433               myCOMObject->setStreamName(name);
00434        }
00435 
00436        if(m_initialize){
00437               if(m_supplier){
00438                      activateSupplier();
00439               }else{
00440                      activateConsumer();
00441               }
00442        }
00443 
00444        m_streamRequest=STAT_OKAY;
00445 }
00446 
00447 void FaceDetector::setGlobalName(const std::string & name){
00448        
00449        if(name=="Any"){
00450               return;
00451        }
00452 
00453        m_globalname=name;
00454        m_haveGlobalname=true;
00455        if(m_supplier){
00456               m_streamname=name;
00457        }
00458 
00459        if(myCOMObject){
00460               myCOMObject->setGlobalName(name);
00461        }
00462 }
00463 
00464 void FaceDetector::doPing(){
00465        if(myCOMObject){
00466               myCOMObject->doPing();
00467        }
00468 }
00469 
00470 void FaceDetector::setAutoPing(const bool & val){
00471        m_doAutoPing=val; 
00472        if(myCOMObject){
00473               myCOMObject->setAutoPing(val);
00474        }
00475 }
00476 
00477 

Generated on Thu Feb 1 15:31:52 2007 for WURDE by  doxygen 1.5.1