Fawkes API  Fawkes Development Version
zauberstab.h
00001 
00002 /***************************************************************************
00003  *  zauberstab.h - Header of class "Zauberstab"
00004  *                 which offers methods for finding 
00005  *                 maximal, color-contiguous region
00006  *                 around a seed pixel
00007  *
00008  *  Generated: Mon Jul 02 2005
00009  *  Copyright  2005       Martin Heracles  <Martin.Heracles@rwth-aachen.de>
00010  *             2005-2006  Tim Niemueller [www.niemueller.de]
00011  *
00012  ****************************************************************************/
00013 
00014 /*  This program is free software; you can redistribute it and/or modify
00015  *  it under the terms of the GNU General Public License as published by
00016  *  the Free Software Foundation; either version 2 of the License, or
00017  *  (at your option) any later version. A runtime exception applies to
00018  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00019  *
00020  *  This program is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU Library General Public License for more details.
00024  *
00025  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00026  */
00027 
00028 #ifndef __FIREVISION_FVUTILS_ZAUBERSTAB_H_
00029 #define __FIREVISION_FVUTILS_ZAUBERSTAB_H_
00030 
00031 #include <fvutils/base/types.h>
00032 
00033 #include <vector>
00034 
00035 
00036 namespace firevision {
00037 #if 0 /* just to make Emacs auto-indent happy */
00038 }
00039 #endif
00040 
00041 /** a "slice" is a row of consecutive pixels
00042    (horizontal) */
00043 struct ZSlice {
00044   int leftX;    /**< left X */
00045   int rightX;   /**< right X */
00046   int y;        /**< Y value */
00047 };
00048 
00049 /** a region is a stack of slices,
00050    together with the y-position of the slice at the top */
00051 //struct ZRegion {
00052 //  std::vector<ZSlice*> *slices;       /**< slices */
00053 //  int topSliceY;              /**< top slice Y */
00054 //};
00055 
00056 /** a region is a stack of slices,
00057    together with the y-position of the slice at the top */
00058 class ZRegion {
00059         public:
00060                 std::vector<ZSlice*> *slices;   /**< slices */
00061                 int topSliceY;          /**< top slice Y */
00062                 
00063                 ZRegion();
00064                 virtual ~ZRegion();
00065                 void clear();
00066 };
00067 
00068 class Zauberstab {
00069  public:
00070   Zauberstab();
00071   ~Zauberstab();
00072 
00073   void setThreshold(unsigned int t);
00074   unsigned int getThreshold();
00075   void setBuffer(unsigned char *b, unsigned int w, unsigned int h);
00076   void findRegion(unsigned int seedX, unsigned int seedY);
00077   void addRegion(unsigned int seedX, unsigned int seedY);
00078   void addRegion(ZRegion *region2);
00079   void deleteRegion();
00080   void deleteRegion(unsigned int seedX, unsigned int seedY);
00081   void deleteRegion(ZRegion *region2);
00082   bool isEmptyRegion();
00083 
00084   ZRegion * getRegion() const;
00085   std::vector< fawkes::rectangle_t >  getSelection();
00086 
00087  private:
00088   unsigned int threshold;
00089   ZRegion *region;
00090   unsigned char *buffer;
00091   unsigned int width;
00092   unsigned int height;
00093 
00094   ZRegion* privFindRegion(unsigned int seedX, unsigned int seedY);
00095   ZSlice* findSlice(unsigned int x, unsigned int y, 
00096                     unsigned int vSeed, int uSeed = -1);
00097   bool isSimilarV(unsigned int v1, unsigned int v2);
00098   bool isSimilarU(unsigned int u1, unsigned int u2);
00099   bool isSimilarUV(unsigned int u1, unsigned int u2,
00100                    unsigned int v1, unsigned int v2);
00101 };
00102 
00103 } // end namespace firevision
00104 
00105 
00106 #endif
00107