Fawkes API  Fawkes Development Version
ht_accum.h
1 
2 /***************************************************************************
3  * ht_accum.h - Accumulator class for HoughTransform
4  *
5  * Created: Tue Jun 28 00:00:00 2005
6  * Copyright 2005 Hu Yuxiao <Yuxiao.Hu@rwth-aachen.de>
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef _FIREVISION_MODELS_SHAPE_ACCUMULATORS_HT_ACCUM_H_
25 #define _FIREVISION_MODELS_SHAPE_ACCUMULATORS_HT_ACCUM_H_
26 
27 #include <ostream>
28 #include <stdlib.h>
29 #include <vector>
30 
31 namespace firevision {
32 
33 class RhtAccNode
34 {
35 public:
36  RhtAccNode();
37  virtual ~RhtAccNode();
38  virtual void clear(int ignore);
39 
40 protected:
41  /** left */
43  /** right */
45  /** used for recycling */
47 };
48 
49 class RhtRNode : public RhtAccNode
50 {
51 public:
52  RhtRNode(int r);
53  void clear(void);
54  int insert(int r);
55  void dump(std::ostream &, int x, int y);
56  void clear(int r);
57  void getNodes(std::vector<std::vector<int>> *rv, int min_votes, int x, int y);
58 
59  static RhtRNode *generate(int r);
60  static void reset(void);
61  static void cleanup(void);
62 
63 protected:
64  /** r */
65  int r;
66  /** count */
67  int count;
68 
69 private:
70  static RhtRNode *reuse_head;
71  static RhtRNode *reuse_tail;
72 };
73 
74 class RhtYNode : public RhtAccNode
75 {
76 private:
77  static RhtYNode *reuse_head;
78  static RhtYNode *reuse_tail;
79 
80 public:
81  static RhtYNode *generate(int y);
82  static void reset(void);
83  static void cleanup(void);
84 
85 protected:
86  /** y */
87  int y;
88  /** r_root */
90 
91 public:
92  RhtYNode(int y);
93  int insert(int y, int r);
94  void dump(std::ostream &, int x);
95  void clear(int y);
96  void getNodes(std::vector<std::vector<int>> *rv, int min_votes, int x);
97 };
98 
99 class RhtXNode : public RhtAccNode
100 {
101 private:
102  static RhtXNode *reuse_head;
103  static RhtXNode *reuse_tail;
104 
105 public:
106  static RhtXNode *generate(int x);
107  static void reset(void);
108  static void cleanup(void);
109 
110 protected:
111  /** x */
112  int x;
113  /** y root */
114  RhtYNode *y_root;
115 
116 public:
117  RhtXNode(int x);
118  int insert(int x, int y, int r);
119  void dump(std::ostream &);
120  void clear(int x);
121  void getNodes(std::vector<std::vector<int>> *rv, int min_votes);
122 };
123 
124 class RhtAccumulator
125 {
126 private:
127  int x_max;
128  int y_max;
129  int r_max;
130  int max;
131 
132  RhtXNode *root;
133 
134  int num_votes;
135 
136 public:
137  RhtAccumulator();
138  ~RhtAccumulator();
139  int accumulate(int x, int y, int r);
140  int getMax(int &x, int &y, int &r) const;
141  void dump(std::ostream &);
142  void reset(void);
143  unsigned int getNumVotes() const;
144  std::vector<std::vector<int>> *getNodes(int min_count);
145 };
146 
147 } // end namespace firevision
148 
149 #endif
firevision::RhtRNode::getNodes
void getNodes(std::vector< std::vector< int >> *rv, int min_votes, int x, int y)
Get nodes.
Definition: ht_accum.cpp:351
firevision::RhtYNode::cleanup
static void cleanup(void)
Cleanup.
Definition: ht_accum.cpp:299
firevision::RhtYNode::insert
int insert(int y, int r)
Insert.
Definition: ht_accum.cpp:207
firevision::RhtXNode::clear
void clear(int x)
Clear.
Definition: ht_accum.cpp:167
firevision::RhtAccNode::left
RhtAccNode * left
left
Definition: ht_accum.h:51
firevision::RhtAccumulator::getNumVotes
unsigned int getNumVotes() const
Get number of votes.
Definition: ht_accum.cpp:512
firevision::RhtYNode::r_root
RhtRNode * r_root
r_root
Definition: ht_accum.h:93
firevision::RhtAccumulator::reset
void reset(void)
Reset.
Definition: ht_accum.cpp:450
firevision::RhtRNode
Definition: ht_accum.h:53
firevision::RhtRNode::clear
void clear(void)
Clear.
Definition: ht_accum.cpp:319
firevision::RhtAccNode::next
RhtAccNode * next
used for recycling
Definition: ht_accum.h:55
firevision::RhtAccumulator::accumulate
int accumulate(int x, int y, int r)
Accumulate new candidate.
Definition: ht_accum.cpp:467
firevision::RhtYNode
Definition: ht_accum.h:78
firevision::RhtXNode::cleanup
static void cleanup(void)
Cleanup.
Definition: ht_accum.cpp:183
firevision::RhtAccumulator::getNodes
std::vector< std::vector< int > > * getNodes(int min_count)
Get nodes.
Definition: ht_accum.cpp:522
firevision::RhtRNode::r
int r
r
Definition: ht_accum.h:69
firevision::RhtRNode::dump
void dump(std::ostream &, int x, int y)
Dump.
Definition: ht_accum.cpp:375
firevision::RhtXNode::generate
static RhtXNode * generate(int x)
Generate.
Definition: ht_accum.cpp:148
firevision::RhtAccNode::clear
virtual void clear(int ignore)
Clear.
Definition: ht_accum.cpp:72
firevision::RhtYNode::dump
void dump(std::ostream &, int x)
Dump.
Definition: ht_accum.cpp:250
firevision::RhtAccumulator
Definition: ht_accum.h:128
firevision::RhtXNode::x
int x
x
Definition: ht_accum.h:116
firevision::RhtRNode::count
int count
count
Definition: ht_accum.h:71
firevision::RhtYNode::generate
static RhtYNode * generate(int y)
Generate.
Definition: ht_accum.cpp:264
firevision::RhtAccNode::~RhtAccNode
virtual ~RhtAccNode()
Destructor.
Definition: ht_accum.cpp:64
firevision::RhtYNode::clear
void clear(int y)
Clear.
Definition: ht_accum.cpp:283
firevision::RhtRNode::RhtRNode
RhtRNode(int r)
Constructor.
Definition: ht_accum.cpp:311
firevision::RhtYNode::getNodes
void getNodes(std::vector< std::vector< int >> *rv, int min_votes, int x)
Get nodes.
Definition: ht_accum.cpp:230
firevision::RhtRNode::reset
static void reset(void)
Reset.
Definition: ht_accum.cpp:417
firevision::RhtAccNode
Definition: ht_accum.h:37
firevision::RhtAccumulator::getMax
int getMax(int &x, int &y, int &r) const
Get maximum.
Definition: ht_accum.cpp:490
firevision::RhtXNode
Definition: ht_accum.h:103
firevision::RhtXNode::dump
void dump(std::ostream &)
Dump to stream.
Definition: ht_accum.cpp:134
firevision::RhtXNode::insert
int insert(int x, int y, int r)
Insert node.
Definition: ht_accum.cpp:93
firevision::RhtRNode::insert
int insert(int r)
Insert.
Definition: ht_accum.cpp:329
firevision::RhtAccumulator::~RhtAccumulator
~RhtAccumulator()
Destructor.
Definition: ht_accum.cpp:441
firevision::RhtXNode::y_root
RhtYNode * y_root
y root
Definition: ht_accum.h:118
firevision::RhtXNode::getNodes
void getNodes(std::vector< std::vector< int >> *rv, int min_votes)
Get nodes.
Definition: ht_accum.cpp:115
firevision::RhtYNode::reset
static void reset(void)
Reset.
Definition: ht_accum.cpp:292
firevision::RhtAccNode::RhtAccNode
RhtAccNode()
Constructor.
Definition: ht_accum.cpp:58
firevision::RhtYNode::y
int y
y
Definition: ht_accum.h:91
firevision::RhtXNode::RhtXNode
RhtXNode(int x)
Constructor.
Definition: ht_accum.cpp:80
firevision::RhtAccumulator::dump
void dump(std::ostream &)
Dump.
Definition: ht_accum.cpp:502
firevision::RhtRNode::cleanup
static void cleanup(void)
Cleanup.
Definition: ht_accum.cpp:424
firevision::RhtAccNode::right
RhtAccNode * right
right
Definition: ht_accum.h:53
firevision::RhtAccumulator::RhtAccumulator
RhtAccumulator()
Constructor.
Definition: ht_accum.cpp:434
firevision::RhtRNode::generate
static RhtRNode * generate(int r)
Generate.
Definition: ht_accum.cpp:389
firevision::RhtYNode::RhtYNode
RhtYNode(int y)
Constructor.
Definition: ht_accum.cpp:195
firevision::RhtXNode::reset
static void reset(void)
Reset.
Definition: ht_accum.cpp:176