$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
link_single_dmax_ratio_base.hh
1 // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
2 // (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SINGLE_DMAX_RATIO_BASE_HH_
28 # define SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SINGLE_DMAX_RATIO_BASE_HH_
29 
34 
35 
36 # include <mln/accu/center.hh>
37 # include <mln/labeling/compute.hh>
38 # include <mln/math/abs.hh>
39 # include <mln/math/max.hh>
40 # include <mln/util/array.hh>
41 
42 # include <scribo/core/macros.hh>
43 # include <scribo/core/tag/anchor.hh>
44 # include <scribo/core/component_set.hh>
45 # include <scribo/core/object_links.hh>
46 
47 # include <scribo/core/concept/dmax_functor.hh>
48 
49 # include <scribo/primitive/link/internal/compute_anchor.hh>
50 # include <scribo/primitive/link/internal/find_link.hh>
51 # include <scribo/primitive/link/internal/link_functor_base.hh>
52 
53 # include <scribo/primitive/link/compute.hh>
54 
55 
56 namespace scribo
57 {
58 
59  namespace primitive
60  {
61 
62  namespace link
63  {
64 
65  namespace internal
66  {
67 
70  //
71  template <typename L, typename F, typename E>
73  : public link_functor_base<L,E>
74  {
76  typedef mln_result(accu::center<mln_psite(L)>) ms_t;
77 
78  public:
79 
80  typedef mln_site(L) P;
81 
83  anchor::Direction direction,
84  const DMax_Functor<F>& dmax_f);
85 
86 
87 
88  bool verify_link_criterion_(unsigned current_object,
89  const P& start_point, const P& p,
90  anchor::Type anchor) const;
91 
92  mln_site(L) start_point_(unsigned current_object,
93  anchor::Type anchor);
94 
95  void start_processing_object_(unsigned current_object);
96 
97  protected:
98  const F dmax_f_;
99  float dmax_;
100  anchor::Direction direction_;
101  };
102 
103 
104 # ifndef MLN_INCLUDE_ONLY
105 
106 
107  template <typename L, typename F, typename E>
108  inline
111  anchor::Direction direction,
112  const DMax_Functor<F>& dmax_f)
113 
114  : super_(components),
115  dmax_f_(exact(dmax_f)),
116  dmax_(0),
117  direction_(direction)
118  {
119  }
120 
121  template <typename L, typename F, typename E>
122  inline
123  bool
124  link_single_dmax_ratio_base<L, F, E>::verify_link_criterion_(
125  unsigned current_object,
126  const P& start_point,
127  const P& p,
128  anchor::Type anchor) const
129  {
130  (void) current_object;
131  (void) anchor;
132 
133  float dist = math::abs(p[direction_] - start_point[direction_]);
134  return dist <= dmax_; // Not too far
135  }
136 
137 
138  template <typename L, typename F, typename E>
139  inline
140  mln_site(L)
141  link_single_dmax_ratio_base<L, F, E>::start_point_(unsigned current_object,
142  anchor::Type anchor)
143  {
144  return internal::compute_anchor(this->components_,
145  current_object, anchor);
146  }
147 
148 
149  template <typename L, typename F, typename E>
150  inline
151  void
152  link_single_dmax_ratio_base<L, F, E>::start_processing_object_(
153  unsigned current_object)
154  {
155  dmax_ = dmax_f_(this->components_.info(current_object).bbox());
156 
157 
158 // float
159 // w = this->components_.info(current_object).bbox().width();
160 // // h = this->components_.info(current_object).bbox().height();
161 
162 // // FIXME: default case
163 // // dmax_ = (w / 2.0f) + (dmax_ratio_ * math::max(w, h));
164 
165 // // FIXME: to use for paragraph alignment
166 // dmax_ = (w / 2.0f) + (dmax_ratio_ * w);
167 
168  // FIXME: to use for newspapers like ICDAR documents!
169 // dmax_ = (w / 2.0f) + (h + w);
170 
171  // FIXME: more general use case for newspapers
172 // dmax_ = (w / 2.0f) + dmax_ratio_ * (h + w);
173 
174 
175  // FIXME: WE WANT TO PROVIDE A DMAX RULE THROUGH A FUNCTOR.
176  }
177 
178 
179 # endif // ! MLN_INCLUDE_ONLY
180 
181 
182  } // end of namespace scribo::primitive::link::internal
183 
184  } // end of namespace scribo::primitive::link
185 
186  } // end of namespace scribo::primitive
187 
188 } // end of namespace scribo
189 
190 
191 #endif // SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SINGLE_DMAX_RATIO_BASE_HH_