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 /** a "slice" is a row of consecutive pixels
00037    (horizontal) */
00038 struct ZSlice {
00039   int leftX;    /**< left X */
00040   int rightX;   /**< right X */
00041   int y;        /**< Y value */
00042 };
00043 
00044 /** a region is a stack of slices,
00045    together with the y-position of the slice at the top */
00046 //struct ZRegion {
00047 //  std::vector<ZSlice*> *slices;       /**< slices */
00048 //  int topSliceY;              /**< top slice Y */
00049 //};
00050 
00051 /** a region is a stack of slices,
00052    together with the y-position of the slice at the top */
00053 class ZRegion {
00054         public:
00055                 std::vector<ZSlice*> *slices;   /**< slices */
00056                 int topSliceY;          /**< top slice Y */
00057
00058                 ZRegion();
00059                 virtual ~ZRegion();
00060                 void clear();
00061 };
00062
00063 class Zauberstab {
00064  public:
00065   Zauberstab();
00066   ~Zauberstab();
00067
00068   void setThreshold(unsigned int t);
00069   unsigned int getThreshold();
00070   void setBuffer(unsigned char *b, unsigned int w, unsigned int h);
00071   void findRegion(unsigned int seedX, unsigned int seedY);
00072   void addRegion(unsigned int seedX, unsigned int seedY);
00073   void addRegion(ZRegion *region2);
00074   void deleteRegion();
00075   void deleteRegion(unsigned int seedX, unsigned int seedY);
00076   void deleteRegion(ZRegion *region2);
00077   bool isEmptyRegion();
00078
00079   ZRegion * getRegion() const;
00080   std::vector< fawkes::rectangle_t >  getSelection();
00081
00082  private:
00083   unsigned int threshold;
00084   ZRegion *region;
00085   unsigned char *buffer;
00086   unsigned int width;
00087   unsigned int height;
00088
00089   ZRegion* privFindRegion(unsigned int seedX, unsigned int seedY);
00090   ZSlice* findSlice(unsigned int x, unsigned int y,
00091                     unsigned int vSeed, int uSeed = -1);
00092   bool isSimilarV(unsigned int v1, unsigned int v2);
00093   bool isSimilarU(unsigned int u1, unsigned int u2);
00094   bool isSimilarUV(unsigned int u1, unsigned int u2,
00095                    unsigned int v1, unsigned int v2);
00096 };
00097
00098
00099 #endif
00100