00001 /* 00002 * Copyright (C) Gostai S.A.S., 2007. All rights reserved. 00003 * 00004 * This software is provided "as is" without warranty of any kind, 00005 * either expressed or implied, including but not limited to the 00006 * implied warranties of fitness for a particular purpose. 00007 * 00008 * See the LICENSE file for more information. 00009 * For comments, bug reports and feedback: http://www.urbiforge.com 00010 */ 00011 #ifndef VISIONBEHAVIOR_HH_ 00012 #define VISIONBEHAVIOR_HH_ 00013 00014 #include <iostream> 00015 #include <cxcore.h> 00016 #include <vector> 00017 #include <boost/variant.hpp> 00018 00019 #ifndef DEBUG 00020 #define DEBUG false 00021 #endif 00022 00029 template <class T> 00030 class VisionBehavior { 00031 protected: 00032 static bool debug; 00033 bool enabled; 00034 public: 00035 VisionBehavior(); 00037 virtual ~VisionBehavior() {}; 00038 void doComputations(const IplImage& img); 00040 virtual void writeOn(IplImage& img) const = 0; 00042 virtual void actOnKeyPressed(char& key) {key = key;}; 00044 virtual T& getResult() = 0; 00045 void switchOnOff(); 00046 private: 00047 virtual void emptyResult() = 0; 00049 virtual void compute(const IplImage& img) = 0; 00050 }; 00051 00052 template <class T> 00053 bool VisionBehavior<T>::debug = DEBUG; 00054 00055 template <class T> 00056 VisionBehavior<T>::VisionBehavior() { 00057 enabled = true; 00058 } 00059 00060 template <class T> 00061 void 00062 VisionBehavior<T>::doComputations(const IplImage& img) { 00063 if (enabled) 00064 compute(img); 00065 } 00066 00067 template <class T> 00068 void 00069 VisionBehavior<T>::switchOnOff() { 00070 if (enabled) 00071 emptyResult(); 00072 enabled = !enabled; 00073 } 00074 00075 #endif /* !VISIONBEHAVIOR_HH_ */