Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

BufferedImageGenerator.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_BufferedImageGenerator_h_
00003 #define INCLUDED_BufferedImageGenerator_h_
00004 
00005 #include "FilterBankGenerator.h"
00006 #include "RawCameraGenerator.h"
00007 
00008 //! Receives camera frames as they are loaded by the simulator -- or eventually other sources
00009 class BufferedImageGenerator : public FilterBankGenerator {
00010 public:
00011   //!Stores information about the current frame, (not the image itself, but meta data a pointer to it)
00012   struct ImageSource {
00013     //!constructor
00014     ImageSource() : width(0), height(0), channels(0), frameIndex(0), layer(0), img(NULL) {}
00015     //!copy constructor
00016     ImageSource(const ImageSource& src) : width(src.width), height(src.height), channels(src.channels), frameIndex(src.frameIndex), layer(src.layer), img(src.img) {}
00017     //!assignment operator
00018     ImageSource& operator=(const ImageSource& src) { width=src.width; height=src.height; channels=src.channels; frameIndex=src.frameIndex; layer=src.layer; img=src.img; return *this; } 
00019     unsigned int width; //!< the width of #img
00020     unsigned int height; //!< the height of #img
00021     unsigned int channels; //!< the number of color channels in #img
00022     unsigned int frameIndex; //!< the serial number of the current frame (should be a unique, increasing ID)
00023 
00024     //! indicates what resolution layer of the pipeline this should be used at
00025     /*! Negative values are interpreted as "from the top", so -1 is the topmost layer, -2 is next-to-top, and so on.\n
00026      *  Non-negative values are interpreted as direct layer values, so 0 indicates bottommost layer, 1 indicates next-to-bottom, and so on. */
00027     unsigned int layer; 
00028 
00029     //! pointer to the first byte of the image buffer
00030     /*! img should be stored in a channel-interleaved format, e.g. RGBRGBRGB... */
00031     unsigned char * img;
00032   };
00033 
00034   //! constructor
00035   BufferedImageGenerator(const std::string& name,EventBase::EventGeneratorID_t mgid, unsigned int msid, unsigned int nLayers, EventBase::EventGeneratorID_t srcgid, unsigned int srcsid)
00036     : FilterBankGenerator(name,mgid,msid,srcgid,srcsid), imgsrc(), isAllocated(NULL)
00037   { 
00038     /* As a root stage, we need to listen to all incoming image
00039      * events, even if we don't currently have listeners of our own --
00040      * This is just in case user code directly accesses a generator
00041      * and we have to retroactively go back and dig up the previous
00042      * frame */
00043     unsetAutoListen();
00044     
00045     setNumImages(nLayers,RawCameraGenerator::NUM_CHANNELS);
00046   }
00047   //!destructor
00048   virtual ~BufferedImageGenerator() { destruct(); }
00049   
00050   //! need to override EventGeneratorBase's lazy listening -- as a root stage, need to remember each frame, just in case it might be used
00051   virtual void doStart() { FilterBankGenerator::doStart(); addSrcListener(); }
00052 
00053   virtual void doEvent();
00054   
00055   virtual unsigned int getBinSize() const;
00056   
00057   virtual unsigned int loadBuffer(const char buf[], unsigned int len, const char* filename=NULL);
00058   
00059   virtual unsigned int saveBuffer(char buf[], unsigned int len) const;
00060   
00061   virtual unsigned int saveFileStream(FILE* f) const; //!< overrridden to allow saving direct to file without an extra buffer copy
00062 
00063   virtual void freeCaches();
00064   virtual void invalidateCaches();
00065   
00066 protected:
00067   virtual unsigned char * createImageCache(unsigned int layer, unsigned int channel) const;
00068   virtual void calcImage(unsigned int layer, unsigned int channel) ;
00069   virtual void setDimensions();
00070   virtual void destruct();
00071   virtual void setNumImages(unsigned int nLayers, unsigned int nChannels);
00072 
00073   //! duplicates pixels to make a higher resolution version of @a srcLayer, @a chan into @a destLayer, @a chan
00074   /*! Doesn't do anything fancy like blurring or smoothing */
00075   virtual void upsampleImage(unsigned int srcLayer, unsigned int chan, unsigned int destLayer);
00076   //! averages blocks of pixels to make smaller images
00077   virtual void downsampleImage(unsigned int destLayer, unsigned int chan);
00078   //! calculates the x-derivative
00079   virtual void calcDx(unsigned int layer, unsigned int srcChan=RawCameraGenerator::CHAN_Y, unsigned int dstChan=RawCameraGenerator::CHAN_Y_DX);
00080   //! calculates the x-derivative
00081   virtual void calcDy(unsigned int layer, unsigned int srcChan=RawCameraGenerator::CHAN_Y, unsigned int dstChan=RawCameraGenerator::CHAN_Y_DY);
00082   //! calculates the diagonal derivative
00083   virtual void calcDxDy(unsigned int layer);
00084   
00085   ImageSource imgsrc; //!< the data storage of the current image (not the image itself, but meta data a pointer to it)
00086   bool ** isAllocated; //!< for each image in the filterbank, a bool to account whether the pointer is to an external resource or a self-allocated resource
00087   
00088 private:
00089   BufferedImageGenerator(const BufferedImageGenerator&); //!< don't call
00090   BufferedImageGenerator& operator=(const BufferedImageGenerator&); //!< don't call
00091 };
00092 
00093 //! input from std stream, no-op except eat a pointer value
00094 inline std::istream& operator>>(std::istream& s, BufferedImageGenerator::ImageSource& i) { void * x; return s>>x; }
00095 //! output to std stream, just dumps address of structure
00096 inline std::ostream& operator<<(std::ostream& s, const BufferedImageGenerator::ImageSource& i) { return s << &i; }
00097 
00098 /*! @file
00099  * @brief Describes BufferedImageGenerator, which receives camera frames as they are loaded by the simulator -- or eventually other sources
00100  * @author Ethan Tira-Thompson (ejt) (Creator)
00101  */
00102 
00103 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:36 2016 by Doxygen 1.6.3