Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SegmentedColorFilterBankEvent.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_SegmentedColorFilterBankEvent_h_
00003 #define INCLUDED_SegmentedColorFilterBankEvent_h_
00004 
00005 #include "Events/FilterBankEvent.h"
00006 #include "Vision/cmvision.h"
00007 #include <ext/hash_map>
00008 
00009 //! This event provides some additional color information over its superclass for image banks made up of indexed colors
00010 /*! The color information is stored using the CMVision library's data structures
00011  *
00012  *  Don't bother trying to access the region information which is also
00013  *  held in the color_class_state structures.  The RegionGenerator,
00014  *  doesn't fill in the global color information because each layer
00015  *  and channel is going to need its own region processing, so a
00016  *  single global structure only makes sense for the colors.
00017  */
00018 class SegmentedColorFilterBankEvent : public FilterBankEvent {
00019 public:
00020   typedef CMVision::color_class_state color_class_state; //!< use CMVision's color structure
00021   typedef __gnu_cxx::hash_map<const char*, unsigned int, __gnu_cxx::hash<const char*>, hashcmp_eqstr> hashmap; //!< a shorthand for the hash structure that CMVision expects for the color lookups
00022 
00023   //! constructor, to be used when first segmented, later stages should use the other constructor
00024   SegmentedColorFilterBankEvent(FilterBankGenerator* creator,EventBase::EventGeneratorID_t gid,size_t sid,EventBase::EventTypeID_t tid, FilterBankGenerator* segColorSrc, unsigned int nColors, color_class_state * colorInfos, const hashmap * clrNames)
00025     : FilterBankEvent(creator,gid,sid,tid), segsrc(segColorSrc), numColors(nColors), colors(colorInfos), colorNames(clrNames)
00026   {}
00027 
00028   //! constructor, allows you to pass along color information to later stages
00029   SegmentedColorFilterBankEvent(FilterBankGenerator* creator,EventBase::EventGeneratorID_t gid,size_t sid,EventBase::EventTypeID_t tid, const SegmentedColorFilterBankEvent& segevt )
00030     : FilterBankEvent(creator,gid,sid,tid), segsrc(segevt.segsrc), numColors(segevt.numColors), colors(segevt.colors), colorNames(segevt.colorNames)
00031   {}
00032 
00033   //! copy constructor (shallow copy -- the generator shouldn't be going anywhere)
00034   SegmentedColorFilterBankEvent(const SegmentedColorFilterBankEvent& fbk)
00035     : FilterBankEvent(fbk), segsrc(fbk.segsrc), numColors(fbk.numColors),
00036       colors(fbk.colors), colorNames(fbk.colorNames)
00037   {}
00038   
00039   //! assignment operator  (shallow copy -- the generator shouldn't be going anywhere)
00040   const SegmentedColorFilterBankEvent& operator=(const SegmentedColorFilterBankEvent& fbk) {
00041     EventBase::operator=(fbk);
00042     segsrc=fbk.segsrc; numColors=fbk.numColors;
00043     colors=fbk.colors; colorNames=fbk.colorNames;
00044     return *this;
00045   }
00046 
00047   virtual EventBase* clone() const { return new SegmentedColorFilterBankEvent(*this); }
00048 
00049   //don't do this until we actually override the LoadSave interface
00050   //virtual unsigned int getClassTypeID() const { return makeClassTypeID("SFBK"); }
00051 
00052   //! Gives access to underlying generator
00053   inline FilterBankGenerator* getSegmentedColorSource() const { return segsrc; }
00054 
00055   //! returns the number of different colors available
00056   inline unsigned int getNumColors() const { return numColors; }
00057 
00058   //! gives direct access to the color information
00059   inline const color_class_state * getColors() const { return colors; }
00060 
00061   //! gives direct access to the color information
00062   inline const color_class_state& getColor(unsigned int i) const { return colors[i]; }
00063 
00064   //! returns index of color corresponding to a string (uses a fast hash lookup)
00065   inline unsigned int getColorIndex(const char * name) const {
00066     hashmap::const_iterator i;
00067     i=colorNames->find(name);
00068     return (i==colorNames->end())?-1U:i->second;
00069   }
00070   
00071   //! returns index of color corresponding to a string (uses a fast hash lookup)
00072   inline unsigned int getColorIndex(const std::string& name) const { return getColorIndex(name.c_str()); }
00073   
00074   virtual classTypeID_t getClassTypeID() const { return autoRegisterSegmentedColorFilterBankEvent; }
00075   
00076 protected:
00077   //! pointer to generator which did the segmentation and therefore holds the color information
00078   FilterBankGenerator* segsrc;
00079   unsigned int numColors; //!< number of available colors
00080   const color_class_state * colors; //!< array of available colors
00081   const hashmap * colorNames; //!< hash map to look up index from name
00082 
00083   //! causes class type id to automatically be regsitered with EventBase's FamilyFactory (getTypeRegistry())
00084   /*! This is instantiated in EventBase.cc to save on file bloat */
00085   static const EventBase::classTypeID_t autoRegisterSegmentedColorFilterBankEvent;
00086   
00087   //! default constructor, only intended to be called from the FamilyFactory, followed by a loadXML...
00088   SegmentedColorFilterBankEvent() : FilterBankEvent(), segsrc(NULL), numColors(), colors(), colorNames() {}
00089   friend struct Factory0Arg<EventBase>::Factory<SegmentedColorFilterBankEvent>;
00090 };
00091 
00092 /*! @file 
00093  * @brief Defines SegmentedColorFilterBankEvent, an event provides some additional color information over its superclass for image banks made up of indexed colors
00094  * @author ejt (Creator)
00095  *
00096  * $Author: ejt $
00097  * $Name: tekkotsu-4_0 $
00098  * $Revision: 1.6 $
00099  * $State: Exp $
00100  * $Date: 2007/11/13 04:16:02 $
00101  */
00102 
00103 #endif

Tekkotsu v4.0
Generated Thu Nov 22 00:54:55 2007 by Doxygen 1.5.4