Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

RLEGenerator Class Reference

Generates RLE compressed FilterBankEvents (generally from indexed color images from, say, SegmentedColorGenerator). More...

#include <RLEGenerator.h>

Inheritance diagram for RLEGenerator:

Detailed Description

Generates RLE compressed FilterBankEvents (generally from indexed color images from, say, SegmentedColorGenerator).

Uses the CMVision library for main processing.

getImage() will return the first run, from the upper left hand corner. The type is RLEGenerator::run.

The RLE produced isn't quite optimal in terms of size. To make it easier to directly process the RLE for recognition tasks, each run will be broken at the end of the row. So a solid image will still contain height runs instead of just one.

Also, the run structures contain extra fields to be used for region connecting. These fields aren't sent over wireless, and are filled in by the RegionGenerator. I don't necessarily like the tight coupling between the RLE and Region Generators that this requires, but it saves a copy of the data and allows us to use CMVision instead of rewriting.

Note that since the amount of data for each row is variable (depends on the complexity of that row) the row stride and skip are useless. You'll have to process the RLE yourself to find a given index.

If the incoming events is a SegmentedColorFilterBankEvents, then it will post a SegmentedColorFilterBank to retain additional color information. If the event is of a different format, it will post a regular FilterBankEvent.

Note that although you could hook this class up to a raw intensity image, it is primarily of use with segmented color images because it doesn't handle gradients or noise well at all - this type of encoding/compression assumes cartoonish images of large blocks of flat color. However, if you have some kind of other preprocessing that also provides suitable data, this can encode it for you.

The format used for serialization is: (code is in saveBuffer())

  • <FilterBankGenerator: superclass header> (First saves the superclass's info)
  • <string: "RLEImage"> (remember a 'string' is len+str+0; so this is the literal "\010\0\0\0RLEImage\0"; also remember "\010" is octal for 8)
  • <unsigned int: num_runs> (how many runs will follow)
  • for each of num_runs:
    • <char: color> (index value of color of run)
    • <short: x> (x position of start of run ("unknown" runs are skipped - assume index 0 for pixels which are jumped))
    • <short: width> (length of run, will not exceed remaining width of image)

Note that the RLEGenerator doesn't save the color infomation regarding what each index value "means". This is just a compression stage, pure and simple. You'll need to look at the RLEGenerator's source (probably SegmentedColorGenerator, but doesn't have to be) to determine how to interpret the indicies.

See also:
SegCamBehavior for information on transmission over wireless.
FilterBankGenerator more information on serialization

Definition at line 63 of file RLEGenerator.h.

List of all members.

Public Types

typedef CMVision::uchar cmap_t
 the type to use for a color index
typedef CMVision::run< cmap_trun
 use the CMVision library's run structure

Public Member Functions

 RLEGenerator (unsigned int mysid, FilterBankGenerator *fbg, EventBase::EventTypeID_t tid)
 constructor
virtual ~RLEGenerator ()
 destructor
virtual void doEvent ()
 should receive FilterBankEvents from any standard format FilterBankGenerator (like RawCameraGenerator)
virtual unsigned int getBinSize () const
virtual unsigned int loadBuffer (const char buf[], unsigned int len, const char *filename=NULL)
virtual unsigned int saveBuffer (char buf[], unsigned int len) const
virtual unsigned int getNumRuns (unsigned int layer, unsigned int chan)
 returns the number of runs for the image
virtual rungetRuns (unsigned int layer, unsigned int chan)
 returns the actual runs of the specified image -- returned pointer is to internal storage; do not free
virtual const rungetRun (unsigned int layer, unsigned int chan, unsigned int i)
 returns a specific run of the specified image
virtual void setNumRuns (unsigned int layer, unsigned int chan, unsigned int num)
 in case you have inserted or removed runs during postprocessing, call this to update the count
virtual size_t getImageSize (unsigned int layer, unsigned int chan) const
 returns the number of bytes used for the data returned by getImage() - if the data varies in size (e.g. jpeg compression), will return 0 if the image hasn't been calculated yet (so call it after getImage())

Static Public Member Functions

static std::string getClassDescription ()
 Gives a short description of what this class of behaviors does... you should override this (but don't have to).

Protected Member Functions

virtual void setDimensions ()
 sets the width, height, skip and stride, as well as maxRuns
virtual void setNumImages (unsigned int nLayers, unsigned int nChannels)
 resizes the filter bank information storage area, you should override this to do your setup and call it from your constructor
virtual unsigned char * createImageCache (unsigned int layer, unsigned int chan) const
 simply creates a new data region and returns it
virtual void calcImage (unsigned int layer, unsigned int chan)
 a single call to the CMVision library to do the work, and we're done.
virtual void destruct ()
 deletes the arrays
unsigned int calcExpMaxRuns (unsigned int layer) const
 uses a heuristic to predict the maximum number of runs expected per layer

Protected Attributes

unsigned int ** numRuns
 a matrix of ints, holds the number of used runs for each image
unsigned int * maxRuns
 the maximum number of runs possible for each layer

Static Protected Attributes

static const unsigned int MIN_EXP_RUN_LENGTH = 8
 The expected minimum average length of each run.
static const unsigned int XMIT_BYTES_PER_RUN = sizeof(cmap_t)+sizeof(short)+sizeof(short)
 number of bytes needed to send each run

Private Member Functions

 RLEGenerator (const RLEGenerator &fbk)
 don't call
const RLEGeneratoroperator= (const RLEGenerator &fbk)
 don't call

Member Typedef Documentation

the type to use for a color index

Definition at line 65 of file RLEGenerator.h.

use the CMVision library's run structure

Definition at line 66 of file RLEGenerator.h.


Constructor & Destructor Documentation

RLEGenerator::RLEGenerator ( unsigned int  mysid,
FilterBankGenerator fbg,
EventBase::EventTypeID_t  tid 
)

constructor

TODO - after RLEGraphics is inplace, replace the 'tid' parameter in FBG's constructor call!

Definition at line 10 of file RLEGenerator.cc.

virtual RLEGenerator::~RLEGenerator (  )  [virtual]

destructor

Definition at line 72 of file RLEGenerator.h.

RLEGenerator::RLEGenerator ( const RLEGenerator fbk  )  [private]

don't call


Member Function Documentation

unsigned int RLEGenerator::calcExpMaxRuns ( unsigned int  layer  )  const [protected]

uses a heuristic to predict the maximum number of runs expected per layer

Definition at line 108 of file RLEGenerator.h.

Referenced by setDimensions(), and setNumImages().

void RLEGenerator::calcImage ( unsigned int  layer,
unsigned int  chan 
) [protected, virtual]

a single call to the CMVision library to do the work, and we're done.

Implements FilterBankGenerator.

Definition at line 153 of file RLEGenerator.cc.

unsigned char * RLEGenerator::createImageCache ( unsigned int  layer,
unsigned int  chan 
) const [protected, virtual]

simply creates a new data region and returns it

Implements FilterBankGenerator.

Definition at line 147 of file RLEGenerator.cc.

Referenced by loadBuffer().

void RLEGenerator::destruct (  )  [protected, virtual]

deletes the arrays

Reimplemented from FilterBankGenerator.

Definition at line 160 of file RLEGenerator.cc.

Referenced by ~RLEGenerator().

void RLEGenerator::doEvent (  )  [virtual]

should receive FilterBankEvents from any standard format FilterBankGenerator (like RawCameraGenerator)

Reimplemented from FilterBankGenerator.

Definition at line 21 of file RLEGenerator.cc.

unsigned int RLEGenerator::getBinSize (  )  const [virtual]

The loadBuffer() functions of the included subclasses aren't tested, so don't assume they'll work without a little debugging...

Reimplemented from FilterBankGenerator.

Definition at line 54 of file RLEGenerator.cc.

static std::string RLEGenerator::getClassDescription (  )  [static]

Gives a short description of what this class of behaviors does... you should override this (but don't have to).

If you do override this, also consider overriding getDescription() to return it

Reimplemented from BehaviorBase.

Definition at line 77 of file RLEGenerator.h.

virtual size_t RLEGenerator::getImageSize ( unsigned int  layer,
unsigned int   
) const [virtual]

returns the number of bytes used for the data returned by getImage() - if the data varies in size (e.g. jpeg compression), will return 0 if the image hasn't been calculated yet (so call it after getImage())

Reimplemented from FilterBankGenerator.

Definition at line 96 of file RLEGenerator.h.

virtual unsigned int RLEGenerator::getNumRuns ( unsigned int  layer,
unsigned int  chan 
) [virtual]

returns the number of runs for the image

Definition at line 87 of file RLEGenerator.h.

Referenced by RegionGenerator::calcImage().

virtual const run& RLEGenerator::getRun ( unsigned int  layer,
unsigned int  chan,
unsigned int  i 
) [virtual]

returns a specific run of the specified image

Definition at line 91 of file RLEGenerator.h.

virtual run* RLEGenerator::getRuns ( unsigned int  layer,
unsigned int  chan 
) [virtual]

returns the actual runs of the specified image -- returned pointer is to internal storage; do not free

Definition at line 89 of file RLEGenerator.h.

unsigned int RLEGenerator::loadBuffer ( const char  buf[],
unsigned int  len,
const char *  filename = NULL 
) [virtual]

this isn't really tested, don't rely on it working without a little debugging... specifically, doesn't set parent or next fields

Reimplemented from FilterBankGenerator.

Definition at line 67 of file RLEGenerator.cc.

const RLEGenerator& RLEGenerator::operator= ( const RLEGenerator fbk  )  [private]

don't call

unsigned int RLEGenerator::saveBuffer ( char  buf[],
unsigned int  len 
) const [virtual]

The loadBuffer() functions of the included subclasses aren't tested, so don't assume they'll work without a little debugging...

Reimplemented from FilterBankGenerator.

Definition at line 99 of file RLEGenerator.cc.

Referenced by SegCam::writeRLE().

void RLEGenerator::setDimensions (  )  [protected, virtual]

sets the width, height, skip and stride, as well as maxRuns

Reimplemented from FilterBankGenerator.

Definition at line 126 of file RLEGenerator.cc.

void RLEGenerator::setNumImages ( unsigned int  nLayers,
unsigned int  nChannels 
) [protected, virtual]

resizes the filter bank information storage area, you should override this to do your setup and call it from your constructor

In general, it isn't expected that FilterBankGenerator's should necessarily be dynamically resizeable (although it would be nice), which is why this isn't public. If yours is, just add some pubic accessor functions which call this. In general, the included subclasses should be able to handle being resized, but there's no reason to do so since the system won't be changing its available resolutions at run time.

The default implementation is a no-op if(numLayers==nLayers && numChannels==nChannels)

Reimplemented from FilterBankGenerator.

Definition at line 133 of file RLEGenerator.cc.

Referenced by RLEGenerator().

virtual void RLEGenerator::setNumRuns ( unsigned int  layer,
unsigned int  chan,
unsigned int  num 
) [virtual]

in case you have inserted or removed runs during postprocessing, call this to update the count

Definition at line 94 of file RLEGenerator.h.


Member Data Documentation

unsigned int* RLEGenerator::maxRuns [protected]

the maximum number of runs possible for each layer

Definition at line 111 of file RLEGenerator.h.

Referenced by calcImage(), createImageCache(), destruct(), getBinSize(), loadBuffer(), setDimensions(), and setNumImages().

const unsigned int RLEGenerator::MIN_EXP_RUN_LENGTH = 8 [static, protected]

The expected minimum average length of each run.

Definition at line 99 of file RLEGenerator.h.

Referenced by calcExpMaxRuns().

unsigned int** RLEGenerator::numRuns [protected]

a matrix of ints, holds the number of used runs for each image

Definition at line 110 of file RLEGenerator.h.

Referenced by calcImage(), destruct(), getBinSize(), getImageSize(), getNumRuns(), loadBuffer(), saveBuffer(), setNumImages(), and setNumRuns().

const unsigned int RLEGenerator::XMIT_BYTES_PER_RUN = sizeof(cmap_t)+sizeof(short)+sizeof(short) [static, protected]

number of bytes needed to send each run

Definition at line 100 of file RLEGenerator.h.

Referenced by getBinSize().


The documentation for this class was generated from the following files:

Tekkotsu v5.1CVS
Generated Mon May 9 04:59:15 2016 by Doxygen 1.6.3