Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

ProjectInterface.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_ProjectInterface_h_
00003 #define INCLUDED_ProjectInterface_h_
00004 
00005 #include "Vision/colors.h"
00006 #include <string>
00007 
00008 class BehaviorBase;
00009 class FilterBankGenerator;
00010 class SegmentedColorGenerator;
00011 class RLEGenerator;
00012 class RegionGenerator;
00013 class JPEGGenerator;
00014 class PNGGenerator;
00015 namespace std {
00016   class exception;
00017 }
00018 
00019 //! A collection of the global variables which should be set by a project to use the Tekkotsu framework
00020 /*! This namespace a few variables needed for initialization of the
00021  *  framework, but mainly declares variables which are used by demo
00022  *  behaviors.  Although the variables are declared here, and
00023  *  some default values provided, it is up to your project to define
00024  *  the actual values used for your own project.  This provides a way
00025  *  to reassign conflicts between values provided by the framework vs.
00026  *  those you might wish to add to your project.
00027  *  
00028  *  Currently, all required members are references (so they can't be
00029  *  set to NULL and you'll get errors if you leave them out) and all
00030  *  optional settings are pointers so you can ignore them if you want.
00031  *  
00032  *  The "optional" variables are used by demo behaviors, and thus
00033  *  if you remove all of the demo behaviors, you won't need to define
00034  *  the corresponding interface values here.
00035  *
00036  *  If you want to add new ID values for your project, create a new
00037  *  'globals.h' or some such in your project -- you don't need to
00038  *  add them here since this file is shared by all projects which
00039  *  use the framework, you shouldn't need to modify it for each
00040  *  project.
00041  */
00042 namespace ProjectInterface {
00043   
00044   //! REQUIRED: you must define a behavior which will be started when the boot is complete
00045   /*! This is similar in idea to the Linux init process - it should do
00046    *  some basic initialization and then launch any other behavior you
00047    *  would like to run at boot.
00048    *  To avoid static initialization ordering issues, this is a function
00049    *  which will be called after environment setup is complete, which
00050    *  should then return a behavior to use as the startup behavior.
00051    *  This behavior should not be reference counted, and probably makes
00052    *  most sense to implement as a static local variable of the function.
00053    *  (Each call should return the same behavior) */
00054   BehaviorBase& startupBehavior();
00055 
00056   //! The exception handler for exceptions which have fallen through to base Tekkotsu functions
00057   /*! You can override this to install your own handler by assigning a
00058    *  new function.  This defaults to displayException(), which
00059    *  <b>does not</b> call abort() (which would otherwise be the
00060    *  default if the exception fell through).
00061    *  @param file The file where the exception was caught (usually just pass __FILE__), or NULL
00062    *  @param line The line number where the exception was caught (usually just pass __LINE__), if @a file is NULL, @a line is ignored
00063    *  @param message An addition message, or NULL
00064    *  @param ex The exception which was caught, or NULL if it is was not a std::exception subclass
00065    *  @return true if the exception was handled, false if the exception should be rethrown */
00066   extern bool (*uncaughtException)(const char * file, int line, const char * message, const std::exception* ex);
00067 
00068   //! Displays information about an exception on #serr, provides a default value for #uncaughtException
00069   /*! You can call this directly from your own code any time you would like an exception error message.
00070    *  @param file The file where the exception was caught (usually just pass __FILE__), or NULL
00071    *  @param line The line number where the exception was caught (usually just pass __LINE__), if @a file is NULL, @a line is ignored
00072    *  @param message An addition message, or NULL
00073    *  @param ex The exception which was caught, or NULL if it is was not a std::exception subclass
00074    *  @return true, indicating the exception was handled adequately */
00075   bool displayException(const char * file, int line, const char * message, const std::exception* ex);
00076   
00077   //! allows you to override how colors are defined -- by default, this will be set to a function which passes the call to defSegmentedColorGenerator
00078   /*! As per SegmentedColorGenerator::getColorIndex(), if @a name is not valid, return -1U */
00079   extern unsigned int (*lookupColorIndexByName)(const std::string& name);
00080   //! allows you to override how colors are defined -- by default, this will be set to a function which passes the call to defSegmentedColorGenerator
00081         extern unsigned int (*lookupColorIndexByRgb)(const rgb rgbval);
00082   //! allows you to override how colors are defined -- by default, this will be set to a function which passes the call to defSegmentedColorGenerator
00083   /*! As per SegmentedColorGenerator::getColorRGB(), if @a index is not valid, return black (rgb()) */
00084   extern rgb (*lookupColorRGB)(unsigned int index);
00085   
00086   //! Returns the index corresponding to a color of specified name by calling lookupColorIndexByName()
00087   /*! As per SegmentedColorGenerator::getColorIndex(), if @a name is not valid, return -1U */
00088   inline unsigned int getColorIndex(const std::string& name) { if(lookupColorIndexByName==NULL) return -1U; return (*lookupColorIndexByName)(name); }
00089   //! Returns the index corresponding to an rgb value  by calling lookupColorIndexByRgb()
00090         inline unsigned int getColorIndex(const rgb rgbval) { if(lookupColorIndexByRgb==NULL) return -1U; return (*lookupColorIndexByRgb)(rgbval); }
00091   //! Returns rgb value corresponding to a color of specified name by calling lookupColorRGB(lookupColorIndexByName())
00092   /*! As per SegmentedColorGenerator::getColorRGB(), if @a name is not valid, return black (rgb()) */
00093   inline rgb getColorRGB(const std::string& name)  { if(lookupColorIndexByName==NULL || lookupColorRGB==NULL) return rgb(); return (*lookupColorRGB)((*lookupColorIndexByName)(name)); }
00094   //! Returns rgb value corresponding to a color of specified name by calling lookupColorRGB()
00095   /*! As per SegmentedColorGenerator::getColorRGB(), if @a index is not valid, return black (rgb()) */
00096   inline rgb getColorRGB(unsigned int index)  { if(lookupColorRGB==NULL) return rgb(); return (*lookupColorRGB)(index); }
00097   
00098   extern unsigned int (*lookupNumColors)();
00099   //! Returns the number of colors, obtained from defSegmentedColorGenerator
00100   inline unsigned int getNumColors() { if (lookupNumColors == NULL) return -1U; return (*lookupNumColors)(); }
00101 
00102   std::ostream& operator<<(std::ostream &os, const rgb &rgbval);
00103   std::string toString(const rgb &rgbval);
00104 
00105 
00106   //! 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
00107   /*! @name Vision Setup */
00108   //! pointer to generator
00109   extern FilterBankGenerator * defRawCameraGenerator;
00110   extern FilterBankGenerator * defInterleavedYUVGenerator;
00111   extern JPEGGenerator * defColorJPEGGenerator;
00112   extern JPEGGenerator * defGrayscaleJPEGGenerator;
00113   extern PNGGenerator * defColorPNGGenerator;
00114   extern PNGGenerator * defGrayscalePNGGenerator;
00115   extern SegmentedColorGenerator * defSegmentedColorGenerator;
00116   extern RLEGenerator * defRLEGenerator;
00117   extern RegionGenerator * defRegionGenerator;
00118   //@}
00119 
00120   //! Default source IDs for the various generators; These are given default values, but you can reassign them if you like.
00121   /*! @name Vision SIDs */
00122   //! source id for event
00123   extern unsigned int visRawCameraSID;
00124   extern unsigned int visInterleaveSID;
00125   extern unsigned int visColorJPEGSID;
00126   extern unsigned int visGrayscaleJPEGSID;
00127   extern unsigned int visColorPNGSID;
00128   extern unsigned int visGrayscalePNGSID;
00129   extern unsigned int visSegmentSID;
00130   extern unsigned int visRLESID;
00131   extern unsigned int visRegionSID;
00132   extern unsigned int visPinkBallSID;
00133   extern unsigned int visBlueBallSID;
00134   extern unsigned int visGreenBallSID;
00135   extern unsigned int visYellowBallSID;
00136   extern unsigned int visHandSID;
00137   //@}
00138 
00139   //! Allows you to request a particular layer abstractly - this isn't used by the framework, just a suggestion for clarity
00140   /*! @name Layer Resolutions */
00141   extern unsigned int doubleLayer;   //!< ERS-2xx: 352*288; ERS-7 416*320 (requires non-trivial computation)
00142   extern unsigned int fullLayer;     //!< ERS-2xx: 176*144; ERS-7 208*160
00143   extern unsigned int halfLayer;     //!< ERS-2xx: 88*72; ERS-7 104*80
00144   extern unsigned int quarterLayer;  //!< ERS-2xx: 44*36; ERS-7 52*40
00145   extern unsigned int eighthLayer;   //!< ERS-2xx: 22*18; ERS-7 26*20 (simply a bigger interleave referencing quarterLayer)
00146   extern unsigned int sixteenthLayer;//!< ERS-2xx: 11*9; ERS-7 13*10 (simply a bigger interleave referencing quarterLayer)
00147   //@}
00148 }
00149 
00150 /*! @file
00151  * @brief Defines ProjectInterface namespace - a collection of the global variables which should be set by a project to use the Tekkotsu framework
00152  * @author ejt (Creator)
00153  *
00154  * $Author: dst $
00155  * $Name: tekkotsu-3_0 $
00156  * $Revision: 1.13 $
00157  * $State: Exp $
00158  * $Date: 2006/07/14 06:48:55 $
00159  */
00160 
00161 #endif

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