Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
hough_transform.h
1 
2 /***************************************************************************
3  * hough_transform.h - Hough Transform
4  *
5  * Created: Mon Dec 28 2009 18:65:04 (based on FireVision's HtAccum)
6  * Copyright 2009 Tim Niemueller [www.niemueller.de]
7  * 2005 Hu Yuxiao <Yuxiao.Hu@rwth-aachen.de> (FireVision)
8  *
9  ****************************************************************************/
10 
11 /* This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version. A runtime exception applies to
15  * this software (see LICENSE.GPL_WRE file mentioned below for details).
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Library General Public License for more details.
21  *
22  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
23  */
24 
25 #ifndef __PLUGINS_LASERHT_HT_ACCUM_H_
26 #define __PLUGINS_LASERHT_HT_ACCUM_H_
27 
29  private:
30  class Node {
31  friend class HoughTransform;
32  public:
33  Node(HoughTransform *ht, unsigned int dims, int value = 0);
34  ~Node();
35 
36  unsigned int insert(int *values);
37 
38  unsigned int num_nodes();
39  unsigned int depth();
40 
41  unsigned int filter(int **values, unsigned int min_count);
42 
43  private:
44  Node(HoughTransform *ht, Node *parent, unsigned int dims, int value = 0);
45  Node(HoughTransform *ht = 0);
46 
47  void reinit(Node *parent, unsigned int dims, int value) {
48  __parent = parent;
49  __left = __right = __dim_next = 0;
50  __value = value;
51  __dims = dims;
52  }
53 
54  Node * filter(Node *tail, unsigned int min_count);
55  unsigned int filtered_length();
56 
57  private:
58  unsigned int __dims;
59 
60  unsigned int __count;
61  int __value;
62 
63  HoughTransform *__ht;
64 
65  Node *__parent; // that is the "value parent", not necessarily tree parent
66  Node *__left;
67  Node *__right;
68  Node *__dim_next;
69 
70  Node *__filter_next;
71 
72  // for re-use (avoiding re-allocations)
73  Node *__reuse_next;
74  };
75 
76  public:
77  HoughTransform(unsigned int num_dims);
79 
80  void process(int **values, unsigned int num_values);
81  unsigned int max(int *values) const;
82 
83  unsigned int filter(int **values, unsigned int min_count);
84 
85  void reset();
86 
87  Node * root();
88 
89  inline Node * create_node(Node *parent, unsigned int dims, int value = 0)
90  {
91  if (__reuse_cur != 0) {
92  Node *rv = __reuse_cur;
93  rv->reinit(parent, dims, value);
94  __reuse_cur = __reuse_cur->__reuse_next;
95  return rv;
96  } else {
97  Node *rv = new Node(this, parent, dims, value);
98  __reuse_tail->__reuse_next = rv;
99  __reuse_tail = rv;
100  return rv;
101  }
102  }
103 
104  private:
105  Node *__root;
106  Node *__reuse_head;
107  Node *__reuse_cur;
108  Node *__reuse_tail;
109 
110  unsigned int __num_dims;
111  unsigned int __max_count;
112  int *__max_values;
113 };
114 
115 
116 #endif