$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
link_single_dmax_base.hh
1 // Copyright (C) 2009, 2011 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_BASE_HH_
28 # define SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SINGLE_DMAX_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/util/array.hh>
40 
41 # include <scribo/core/macros.hh>
42 # include <scribo/core/tag/anchor.hh>
43 # include <scribo/core/component_set.hh>
44 # include <scribo/core/object_links.hh>
45 
46 # include <scribo/primitive/link/internal/find_link.hh>
47 # include <scribo/primitive/link/internal/compute_anchor.hh>
48 # include <scribo/primitive/link/internal/link_functor_base.hh>
49 
50 # include <scribo/primitive/link/compute.hh>
51 
52 
53 namespace scribo
54 {
55 
56  namespace primitive
57  {
58 
59  namespace link
60  {
61 
62  namespace internal
63  {
64 
67  //
68  template <typename L, typename E>
70  : public link_functor_base<L, E>
71  {
73  typedef mln_result(accu::center<mln_psite(L)>) ms_t;
74 
75  public:
76 
77  typedef mln_site(L) P;
78 
79  link_single_dmax_base(const component_set<L>& components,
80  unsigned neighb_max_distance,
81  anchor::Direction direction);
82 
83 
84  bool verify_link_criterion_(unsigned current_object,
85  const P& start_point, const P& p,
86  anchor::Type anchor) const;
87 
88  void start_processing_object_(unsigned current_object);
89 
90  private:
91  float dmax_;
92  float neighb_max_distance_;
93  anchor::Direction direction_;
94  };
95 
96 
97 # ifndef MLN_INCLUDE_ONLY
98 
99 
100  template <typename L, typename E>
101  inline
104  unsigned neighb_max_distance,
105  anchor::Direction direction)
106 
107  : super_(components),
108  dmax_(0),
109  neighb_max_distance_(neighb_max_distance),
110  direction_(direction)
111  {
112  }
113 
114 
115  template <typename L, typename E>
116  inline
117  bool
118  link_single_dmax_base<L, E>::verify_link_criterion_(
119  unsigned current_object,
120  const P& start_point,
121  const P& p,
122  anchor::Type anchor) const
123  {
124  (void) current_object;
125  (void) anchor;
126 
127  float dist = math::abs(p[direction_] - start_point[direction_]);
128  return dist <= dmax_; // Not too far
129  }
130 
131 
132  template <typename L, typename E>
133  inline
134  void
135  link_single_dmax_base<L, E>::start_processing_object_(
136  unsigned current_object)
137  {
138  float
139  midcol = (this->components_(current_object).bbox().pmax()[direction_]
140  - this->components_(current_object).bbox().pmin()[direction_]) / 2;
141  dmax_ = midcol + neighb_max_distance_;
142  }
143 
144 
145 # endif // ! MLN_INCLUDE_ONLY
146 
147 
148  } // end of namespace scribo::primitive::link::internal
149 
150  } // end of namespace scribo::primitive::link
151 
152  } // end of namespace scribo::primitive
153 
154 } // end of namespace scribo
155 
156 
157 #endif // SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SINGLE_DMAX_BASE_HH_