ht_accum.h

00001
00002 /***************************************************************************
00003  *  ht_accum.h - Accumulator class for HoughTransform
00004  *
00005  *  Generated: Tue Jun 28 2005
00006  *  Copyright  2005  Hu Yuxiao      <Yuxiao.Hu@rwth-aachen.de>
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023
00024 #ifndef __FIREVISION_HT_ACCUM_H_
00025 #define __FIREVISION_HT_ACCUM_H_
00026 
00027 #include <stdlib.h>
00028 #include <ostream>
00029 #include <vector>
00030
00031 class RhtAccNode
00032 {
00033  public:
00034   RhtAccNode();
00035   virtual ~RhtAccNode();
00036   virtual void clear(int ignore);
00037
00038  protected:
00039   /** left */
00040   RhtAccNode* left;
00041   /** right */
00042   RhtAccNode* right;
00043   /** used for recycling */
00044   RhtAccNode* next;
00045 };
00046
00047 class RhtRNode : public RhtAccNode
00048 {
00049  public:
00050   RhtRNode(int r);
00051   void clear(void);
00052   int  insert(int r);
00053   void dump(std::ostream&, int x, int y);
00054   void clear(int r);
00055   void getNodes(std::vector< std::vector< int > > *rv, int min_votes, int x, int y);
00056
00057   static RhtRNode* generate(int r);
00058   static void reset(void);
00059   static void cleanup(void);
00060
00061  protected:
00062   /** r */
00063   int r;
00064   /** count */
00065   int count;
00066
00067  private:
00068   static RhtRNode* reuse_head;
00069   static RhtRNode* reuse_tail;
00070 };
00071
00072 class RhtYNode : public RhtAccNode
00073 {
00074  private:
00075   static RhtYNode* reuse_head;
00076   static RhtYNode* reuse_tail;
00077  public:
00078   static RhtYNode* generate(int y);
00079   static void reset(void);
00080   static void cleanup(void);
00081
00082  protected:
00083   /** y */
00084   int y;
00085   /** r_root */
00086   RhtRNode* r_root;
00087
00088  public:
00089   RhtYNode(int y);
00090   int insert(int y, int r);
00091   void dump(std::ostream&, int x);
00092   void clear(int y);
00093   void getNodes(std::vector< std::vector< int > > *rv, int min_votes, int x);
00094 };
00095
00096 class RhtXNode : public RhtAccNode
00097 {
00098  private:
00099   static RhtXNode* reuse_head;
00100   static RhtXNode* reuse_tail;
00101  public:
00102   static RhtXNode* generate(int x);
00103   static void reset(void);
00104   static void cleanup(void);
00105
00106  protected:
00107   /** x */
00108   int x;
00109   /** y root */
00110   RhtYNode* y_root;
00111
00112  public:
00113   RhtXNode(int x);
00114   int insert(int x, int y, int r);
00115   void dump(std::ostream&);
00116   void clear (int x);
00117   void getNodes(std::vector< std::vector< int > > *rv, int min_votes);
00118 };
00119
00120 class RhtAccumulator
00121 {
00122  private:
00123   int           x_max;
00124   int           y_max;
00125   int           r_max;
00126   int           max;
00127
00128   RhtXNode*     root;
00129
00130   int             num_votes;
00131
00132  public:
00133   RhtAccumulator();
00134   ~RhtAccumulator();
00135   int accumulate(int x, int y, int r);
00136   int getMax(int& x, int& y, int& r) const;
00137   void dump(std::ostream&);
00138   void reset(void);
00139   unsigned int getNumVotes() const;
00140   std::vector< std::vector< int > > * getNodes(int min_count);
00141 };
00142
00143 #endif // __FIREVISION_HT_ACCUM_H_
00144