test-LeakDetector.C

Go to the documentation of this file.
00001 /*!@file BeoSub/test-LeakDetector.C Leak Detector for BeoSub */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003   //
00005 // by the University of Southern California (USC) and the iLab at USC.  //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BeoSub/test-LeakDetector.C $
00035 // $Id: test-LeakDetector.C 6990 2006-08-11 18:13:51Z rjpeters $
00036 //
00037 
00038 // - Syamsul
00039 
00040 
00041 #include "Devices/BeoChip.H"
00042 #include "BeoSub/BeoSub.H"
00043 
00044 
00045 //just because of the virtual funcs
00046 class BeoSubLeakDetector : public BeoSub {
00047         public:
00048         BeoSubLeakDetector(OptionManager& mgr,const std::string& descrName,const std::string& tagName);
00049         virtual void turnOpen(Angle, bool);
00050         virtual void advanceRel(float f, bool);
00051         virtual Image<PixRGB<byte> > grabImage(BeoSubCamera) const ;
00052         virtual void dropMarker(bool md);
00053 };
00054 
00055 //leak detector class
00056 class LeakDetector : public ModelComponent {
00057 
00058         public:
00059                 LeakDetector(OptionManager& mgr,
00060                                 const std::string& descrName="LeakDetector",
00061                                 const std::string& tagName="LeakDetector");
00062                 void setBeoChip(nub::soft_ref<BeoChip>& bc);
00063                 void setBeoSub(nub::soft_ref<BeoSubLeakDetector>& sub);
00064                 bool getState() {return leakState;}
00065 
00066                 ~LeakDetector();
00067 
00068         protected:
00069                 void start1();
00070                 void stop1();
00071 
00072                 //get reference from beochip
00073 
00074         private:
00075                 nub::soft_ref<BeoChip> itsBeoChip;
00076                 nub::soft_ref<BeoSubLeakDetector> itsBeoSub;
00077                 void dispatchBeoChipEvent(BeoChipEventType t, int valint, float valfloat);
00078                 bool leakState;
00079 
00080         friend class LeakDetectorListener;
00081 
00082 };
00083 
00084 
00085 //listener for Leak Detector
00086 class LeakDetectorListener :public BeoChipListener{
00087         public:
00088                 LeakDetectorListener(nub::soft_ref<LeakDetector>& ld) : itsLeakDetector(ld) {}
00089 
00090                 void event(const BeoChipEventType t, const int valint, const float valfloat) {
00091                         LDEBUG("Event type %d , vint : %d , vfloat : %f", int(t),valint,valfloat);
00092                         itsLeakDetector->dispatchBeoChipEvent(t,valint,valfloat);
00093 
00094                 }
00095 
00096         private:
00097                 nub::soft_ref<LeakDetector> itsLeakDetector;
00098 
00099 };
00100 
00101 
00102 //leak detector implementation
00103 LeakDetector::LeakDetector(OptionManager& mgr,const std::string& descrName,const std::string& tagName):
00104                                 ModelComponent(mgr,descrName,tagName)
00105 {
00106 }
00107 
00108 LeakDetector::~LeakDetector() {
00109         //pthread_mutex_destroy(&itsMutex);
00110 }
00111 
00112 void LeakDetector::start1() {
00113         //start thread to listen to leak detector sensor
00114         //itsKeepGoing = true;
00115         //pthread_mutex_create(&itsRunner,NULL,LeakDetector_run,(void*)this);
00116         return;
00117 }
00118 
00119 void LeakDetector::stop1() {
00120         //itsKeepGoing = false;
00121         usleep(300000); //thread exiting.
00122         return;
00123 
00124 }
00125 
00126 void LeakDetector::setBeoChip(nub::soft_ref<BeoChip>& bc) {
00127         itsBeoChip = bc;
00128 
00129 }
00130 
00131 void LeakDetector::setBeoSub(nub::soft_ref<BeoSubLeakDetector>& sub) {
00132 
00133         itsBeoSub = sub ;
00134 }
00135 
00136 void LeakDetector::dispatchBeoChipEvent(BeoChipEventType t, int valint, float valfloat) {
00137 
00138         LDEBUG("Event : %d, valint : %d valfloat : %f",int(t),valint, valfloat);
00139 
00140         //sub do something to kill yourself.
00141         return;
00142 
00143 }
00144 
00145 BeoSubLeakDetector::BeoSubLeakDetector(OptionManager& mgr, const std::string& descrName,const std::string& tagName):
00146                 BeoSub(mgr,descrName,tagName){}
00147 
00148 void BeoSubLeakDetector::turnOpen(Angle, bool) {
00149         LERROR("Not Implemented!");
00150         return;
00151 }
00152 
00153 void BeoSubLeakDetector::advanceRel(float relPos, bool) {
00154         LERROR("Not Implemented!");
00155         return;
00156 }
00157 
00158  void BeoSubLeakDetector::dropMarker(bool md) {
00159         LERROR("Not Implemented!");
00160         return;
00161 }
00162 
00163  Image<PixRGB<byte> > BeoSubLeakDetector::grabImage(BeoSubCamera) const {
00164          LERROR("Not Implemented!");
00165          return Image< PixRGB<byte> >();
00166 
00167 }
00168 
00169 int main() {
00170 
00171         ModelManager manager("Testing Leak Detector");
00172         //create beochip
00173         nub::soft_ref<BeoChip> beochip(new BeoChip(manager)) ;
00174         manager.addSubComponent(beochip);
00175 
00176         //create beosub
00177         nub::soft_ref<BeoSubLeakDetector> sub(new BeoSubLeakDetector(manager,"BeoSubLeakDetector","BeoSubLeakDetector"));
00178         manager.addSubComponent(sub);
00179 
00180         //create Leak detector
00181         nub::soft_ref<LeakDetector> leakDetector(new LeakDetector(manager));
00182         manager.addSubComponent(leakDetector);
00183 
00184         //give leak detector beochip and sub reference
00185         leakDetector->setBeoChip(beochip);
00186         leakDetector->setBeoSub(sub);
00187 
00188         //create leak detector listener
00189         rutz::shared_ptr<LeakDetectorListener> ldLis(new LeakDetectorListener(leakDetector));
00190         rutz::shared_ptr<BeoChipListener> bcLis;
00191         bcLis.dynCastFrom(ldLis);
00192         beochip->setListener(bcLis);
00193 
00194         manager.start();
00195 
00196 }
00197 
00198 
Generated on Sun May 8 08:40:20 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3