Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

ProjectInterface.cc

Go to the documentation of this file.
00001 #include "ProjectInterface.h"
00002 #include "Wireless/Socket.h"
00003 #include "Vision/SegmentedColorGenerator.h"
00004 #include "debuget.h"
00005 #include <exception>
00006 
00007 namespace ProjectInterface {
00008 
00009   bool displayException(const char * file, int line, const char * message, const std::exception* ex) {
00010     if(file!=NULL) {
00011       serr->printf("Exception caught at %s:%d => ",debuget::extractFilename(file),line);
00012     } else {
00013       serr->printf("Exception => ");
00014     }
00015     if(ex!=NULL) {
00016       serr->printf("'%s'",ex->what());
00017     } else {
00018       serr->printf("'%s'","Unknown type");
00019     }
00020     if(message!=NULL) {
00021       serr->printf(" (%s)\n",message);
00022     } else {
00023       serr->printf("\n");
00024     }
00025 #ifndef PLATFORM_APERIOS
00026     serr->printf("\tWhen running in gdb, try 'catch throw' to break where exceptions are first thrown.\n");
00027 #endif
00028     return true;
00029   }
00030   bool (*uncaughtException)(const char * file, int line, const char * message, const std::exception* ex)=&displayException;
00031 
00032   //! default implementation assigned to lookupColorIndexByName(); checks that #defSegmentedColorGenerator is non-NULL and returns getColorIndex on it
00033   unsigned int defLookupColorIndexByName(const std::string& name) {
00034     if(defSegmentedColorGenerator==NULL)
00035       return -1U;
00036     return defSegmentedColorGenerator->getColorIndex(name);
00037   }
00038   unsigned int (*lookupColorIndexByName)(const std::string& name)=&defLookupColorIndexByName;
00039   
00040   //! default value initially assigned to lookupColorIndexByRgb(); checks that #defSegmentedColorGenerator is non-NULL and returns getColorIndex on it
00041   unsigned int defLookupColorIndexByRgb(const rgb rgbval) {
00042     if(defSegmentedColorGenerator==NULL)
00043       return -1U;
00044     return defSegmentedColorGenerator->getColorIndex(rgbval);
00045   }
00046   //! returns color index for color with specified "representitive" RGB color
00047   unsigned int (*lookupColorIndexByRgb)(const rgb rgbval)=&defLookupColorIndexByRgb;
00048   
00049   //! default implementation assigned to lookupColorRGB(); checks that #defSegmentedColorGenerator is non-NULL and returns getColorRGB on it
00050   rgb defLookupColorRGB(unsigned int index) {
00051     if(defSegmentedColorGenerator==NULL)
00052       return rgb();
00053     return defSegmentedColorGenerator->getColorRGB(index);
00054   }
00055   rgb (*lookupColorRGB)(unsigned int index)=&defLookupColorRGB;
00056 
00057   //! default value initially assigned to lookupNumColors(); checks that #defSegmentedColorGenerator is non-NULL and returns getNumColors on it
00058   unsigned int defLookupNumColors() {
00059     if ( defSegmentedColorGenerator == NULL ) 
00060       return -1U; 
00061     return defSegmentedColorGenerator->getNumColors();
00062   }
00063   //! returns the number of indexed colors which are currently defined
00064   unsigned int (*lookupNumColors)() = &defLookupNumColors;
00065 
00066   //! displays an rgb value in the form '[r,g,b]'
00067   std::ostream& operator<<(std::ostream &os, const rgb &rgbval) {
00068     os << "[" << (unsigned int)rgbval.red
00069        << "," << (unsigned int)rgbval.green
00070        << "," << (unsigned int)rgbval.blue
00071        << "]";
00072     return os;
00073   }
00074 
00075   //! returns @a rgbval in the form 'r g b'
00076   std::string toString(const rgb &rgbval) {
00077     char buff[15];
00078     snprintf(buff,15,"%d %d %d",rgbval.red,rgbval.green,rgbval.blue);
00079     return buff;
00080   }
00081 
00082 
00083 
00084   //! A collection of the various stages of vision processing.  None of these are absolutely required, but are needed to run included demo behaviors and TekkotsuMon modules
00085   /*! @name Vision Setup */
00086   //! pointer to generator
00087   FilterBankGenerator * defRawCameraGenerator=NULL;
00088   FilterBankGenerator * defInterleavedYUVGenerator=NULL;
00089   JPEGGenerator * defColorJPEGGenerator=NULL;
00090   JPEGGenerator * defGrayscaleJPEGGenerator=NULL;
00091   PNGGenerator * defColorPNGGenerator=NULL;
00092   PNGGenerator * defGrayscalePNGGenerator=NULL;
00093   SegmentedColorGenerator * defSegmentedColorGenerator=NULL;
00094   RLEGenerator * defRLEGenerator=NULL;
00095   RegionGenerator * defRegionGenerator=NULL;
00096   //@}
00097 
00098   //! Default source IDs for the various generators; These are given default values, but you can reassign them if you like.
00099   /*! @name Vision SIDs */
00100   //! source id for event
00101   unsigned int visRawCameraSID=0;
00102 
00103   unsigned int visInterleaveSID=0;
00104 
00105   unsigned int visColorJPEGSID=0;
00106   unsigned int visGrayscaleJPEGSID=1;
00107 
00108   unsigned int visColorPNGSID=0;
00109   unsigned int visGrayscalePNGSID=1;
00110 
00111   unsigned int visSegmentSID=0;
00112 
00113   unsigned int visRLESID=0;
00114 
00115   unsigned int visRegionSID=0;
00116 
00117   unsigned int visPinkBallSID=0;
00118   unsigned int visBlueBallSID=1;
00119   unsigned int visGreenBallSID=2;
00120   unsigned int visYellowBallSID=3;
00121   unsigned int visHandSID=4;
00122   //@}
00123 
00124   //! Allows you to request a particular layer abstractly - this isn't used by the framework, just a suggestion for clarity
00125   /*! @name Layer Resolutions */
00126   unsigned int doubleLayer=5;
00127   unsigned int fullLayer=4;
00128   unsigned int halfLayer=3;
00129   unsigned int quarterLayer=2;
00130   unsigned int eighthLayer=1;
00131   unsigned int sixteenthLayer=0;
00132   //@}
00133 
00134 }
00135 
00136 /*! @file
00137  * @brief Provides instantiation of the non-required members of ProjectInterface
00138  * @author ejt (Creator)
00139  *
00140  * $Author: ejt $
00141  * $Name: tekkotsu-3_0 $
00142  * $Revision: 1.15 $
00143  * $State: Exp $
00144  * $Date: 2006/09/25 23:31:06 $
00145  */
00146 

Tekkotsu v3.0
Generated Wed Oct 4 00:03:45 2006 by Doxygen 1.4.7