SMIL  0.9.1
DMorphoMaxTreeCriteria.hpp
1 #ifndef MORPHO_MAX_TREE_ATTRIBUTES_H_
2 #define MORPHO_MAX_TREE_ATTRIBUTES_H_
3 
4 #include <complex>
5 #include <memory>
6 #include <queue>
7 
8 
9 #include "DMorphoHierarQ.hpp"//BMI
10 
11 namespace smil
12 {
13 
15 template<class tAttType>
17 {
18 public:
20 
21  virtual ~GenericCriterion(){}
22 
23 public:
24  virtual void initialize() = 0;
25  virtual void reset() = 0;
26  virtual void merge(GenericCriterion* other_criteron) = 0;
27  virtual void update(const size_t x, const size_t y,const size_t z) = 0;
28  virtual bool operator < (const tAttType& other_attribute) = 0;
29  tAttType getAttributeValue()
30  {
31  compute();
32  return attribute_value_;
33  }
34 
35 protected:
36  virtual void compute() = 0;
37 
38 protected:
39  tAttType attribute_value_;
40 
41 };
42 
44 class AreaCriterion : public GenericCriterion<size_t>
45 {
46 public:
47  AreaCriterion(){initialize();}
48 
49  virtual ~AreaCriterion(){}
50 
51 public:
52  virtual void initialize()
53  {
54  attribute_value_ = 1;
55  }
56 
57  virtual void reset()
58  {
59  attribute_value_ = 0;
60  }
61 
62  virtual void merge(GenericCriterion* other_criteron)
63  {
64  attribute_value_ += dynamic_cast<AreaCriterion&>(*other_criteron).attribute_value_;
65  }
66 
67  virtual void update(SMIL_UNUSED const size_t x, SMIL_UNUSED const size_t y, SMIL_UNUSED const size_t z)
68  {
69  attribute_value_ += 1;
70  }
71  virtual bool operator < (const size_t& other_attribute){
72  return (attribute_value_ < other_attribute);
73  }
74 protected:
75 
76  virtual void compute(){}
77 };
78 
80 class HeightCriterion : public GenericCriterion<size_t>
81 {
82 public:
83  HeightCriterion(){initialize();}
84 
85  virtual ~HeightCriterion(){}
86 
87 public:
88  virtual void initialize()
89  {
90  attribute_value_ = 0;
91  y_max_ = std::numeric_limits<size_t>::min();//lowest instead of min in Andres code
92  y_min_ = std::numeric_limits<size_t>::max();
93  }
94 
95  virtual void reset()
96  {
97  initialize();
98  }
99 
100  virtual void merge(GenericCriterion* other_criteron)
101  {
102  y_max_ = std::max(y_max_, dynamic_cast<HeightCriterion&>(*other_criteron).y_max_);
103  y_min_ = std::min(y_min_, dynamic_cast<HeightCriterion&>(*other_criteron).y_min_);
104  }
105 
106  virtual void update(SMIL_UNUSED const size_t x, const size_t y, SMIL_UNUSED const size_t z)
107  {
108 
109  y_max_ = std::max(y_max_, y);
110  y_min_ = std::min(y_min_, y);
111  }
112  virtual bool operator < (const size_t& other_attribute){
113  return (attribute_value_ < other_attribute);
114  }
115 
116 protected:
117  virtual void compute()
118  {
119  attribute_value_ = y_max_ - y_min_ + 1;
120  }
121 
122 private:
123  size_t y_max_;// BMI: int in Andres code
124  size_t y_min_;// BMI: int in Andres code
125 };
126 
127 
128 
130 class WidthCriterion : public GenericCriterion<size_t>
131 {
132 public:
133  WidthCriterion(){initialize();}
134 
135  virtual ~WidthCriterion(){}
136 
137 public:
138  virtual void initialize()
139  {
140  attribute_value_ = 0;
141  x_max_ = std::numeric_limits<size_t>::min();//lowest instead of min in Andres code
142  x_min_ = std::numeric_limits<size_t>::max();
143  }
144 
145  virtual void reset()
146  {
147  initialize();
148  }
149 
150  virtual void merge(GenericCriterion* other_criteron)
151  {
152  x_max_ = std::max(x_max_, dynamic_cast<WidthCriterion&>(*other_criteron).x_max_);
153  x_min_ = std::min(x_min_, dynamic_cast<WidthCriterion&>(*other_criteron).x_min_);
154  }
155 
156  virtual void update(const size_t x, SMIL_UNUSED const size_t y, SMIL_UNUSED const size_t z)
157  {
158  x_max_ = std::max(x_max_, x);
159  x_min_ = std::min(x_min_, x);
160  }
161  virtual bool operator < (const size_t & other_attribute){
162  return (attribute_value_ < other_attribute);
163  }
164 
165 protected:
166  virtual void compute()
167  {
168  attribute_value_ = x_max_ - x_min_ + 1;
169  }
170 
171 private:
172  size_t x_max_;// BMI: int in Andres code
173  size_t x_min_;// BMI: int in Andres code
174 };
175 
176 
177 
178 
179 struct HA{
180  size_t H;
181  size_t A;
182  };
183 struct HWA{
184  size_t H;
185  size_t W;
186  size_t A;
187  };
188 
190  class HACriterion : public GenericCriterion< HA>
191 {
192 public:
193  HACriterion(){initialize();}
194 
195  virtual ~HACriterion(){}
196 
197 public:
198  virtual void initialize()
199  {
200 
201  attribute_value_.H = 1;
202  attribute_value_.A = 0;
203 
204  y_max_ = std::numeric_limits<size_t>::min();//lowest instead of min in Andres code
205  y_min_ = std::numeric_limits<size_t>::max();
206  }
207 
208  virtual void reset()
209  {
210  initialize();
211  }
212 
213  virtual void merge(GenericCriterion* other_criteron)
214  {
215  attribute_value_.A += dynamic_cast<HACriterion&>(*other_criteron).getAttributeValue().A;
216 
217  y_max_ = std::max(y_max_, dynamic_cast<HACriterion&>(*other_criteron).y_max_);
218  y_min_ = std::min(y_min_, dynamic_cast<HACriterion&>(*other_criteron).y_min_);
219 
220  }
221 
222  virtual void update(SMIL_UNUSED const size_t x, const size_t y, SMIL_UNUSED const size_t z)
223  {
224  attribute_value_.A += 1;
225  y_max_ = std::max(y_max_, y);
226  y_min_ = std::min(y_min_, y);
227  }
228  virtual bool operator < (const HA& other_attribute){// AttributeOpen with this criterion would be a Height Opening
229  return (attribute_value_.H < other_attribute.H);
230  }
231 
232 protected:
233  virtual void compute()
234  {
235  attribute_value_.H = y_max_ - y_min_ + 1;
236  }
237 
238 private:
239  size_t y_max_;// BMI: int in Andres code
240  size_t y_min_;// BMI: int in Andres code
241 };
242 
244  class HWACriterion : public GenericCriterion< HWA >
245 {
246 public:
247  HWACriterion(){initialize();}
248 
249  virtual ~HWACriterion(){}
250 
251 public:
252  virtual void initialize()
253  {
254 
255  attribute_value_.H = 1;
256  attribute_value_.W = 1;
257  attribute_value_.A = 0;
258 
259  x_max_ = std::numeric_limits<size_t>::min();//lowest instead of min in Andres code
260  x_min_ = std::numeric_limits<size_t>::max();
261 
262  y_max_ = std::numeric_limits<size_t>::min();//lowest instead of min in Andres code
263  y_min_ = std::numeric_limits<size_t>::max();
264  }
265 
266  virtual void reset()
267  {
268  initialize();
269  }
270 
271  virtual void merge(GenericCriterion* other_criteron)
272  {
273  attribute_value_.A += dynamic_cast<HWACriterion&>(*other_criteron).getAttributeValue().A;
274 
275  x_max_ = std::max(x_max_, dynamic_cast<HWACriterion&>(*other_criteron).x_max_);
276  x_min_ = std::min(x_min_, dynamic_cast<HWACriterion&>(*other_criteron).x_min_);
277 
278  y_max_ = std::max(y_max_, dynamic_cast<HWACriterion&>(*other_criteron).y_max_);
279  y_min_ = std::min(y_min_, dynamic_cast<HWACriterion&>(*other_criteron).y_min_);
280 
281  }
282 
283  virtual void update(const size_t x, const size_t y, SMIL_UNUSED const size_t z)
284  {
285  attribute_value_.A += 1;
286  x_max_ = std::max(x_max_, x);
287  x_min_ = std::min(x_min_, x);
288 
289  y_max_ = std::max(y_max_, y);
290  y_min_ = std::min(y_min_, y);
291  }
292  virtual bool operator < (const HWA& other_attribute){// AttributeOpen with this criterion would be a Height Opening
293  return (attribute_value_.H < other_attribute.H);
294  }
295 
296 protected:
297  virtual void compute()
298  {
299  attribute_value_.W = x_max_ - x_min_ + 1;
300  attribute_value_.H = y_max_ - y_min_ + 1;
301  }
302 
303 private:
304  size_t x_max_;// BMI: int in Andres code
305  size_t x_min_;
306 
307  size_t y_max_;
308  size_t y_min_;
309 };
310 
311 
312 
313 
314 } // namespace smil
315 
316 
317 #endif // MORPHO_MAX_TREE_ATTRIBUTES_H_
318 
319 
320 
321 
Height criterion. Useful for Height Opening/Closing algorithms based on max-tree. ...
Definition: DMorphoMaxTreeCriteria.hpp:80
Definition: DColorConvert.h:38
Area criterion. Useful for Area Opening/Closing algorithms based on max-tree.
Definition: DMorphoMaxTreeCriteria.hpp:44
HeightArea criterion. Useful for Height Opening/Closing algorithms based on max-tree.
Definition: DMorphoMaxTreeCriteria.hpp:244
Definition: DMorphoMaxTreeCriteria.hpp:183
Width criterion. Useful for Width Opening/Closing algorithms based on max-tree.
Definition: DMorphoMaxTreeCriteria.hpp:130
Generic criterion for the max-tree. A user-defined criterion should be derived from this class...
Definition: DMorphoMaxTreeCriteria.hpp:16
HeightArea criterion. Useful for Height Opening/Closing algorithms based on max-tree.
Definition: DMorphoMaxTreeCriteria.hpp:190
Definition: DMorphoMaxTreeCriteria.hpp:179