$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
with_several_right_links.hh
1 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef SCRIBO_PRIMITIVE_LINK_WITH_SEVERAL_RIGHT_LINKS_HH
27 # define SCRIBO_PRIMITIVE_LINK_WITH_SEVERAL_RIGHT_LINKS_HH
28 
34 
35 # include <mln/core/concept/image.hh>
36 # include <mln/core/concept/neighborhood.hh>
37 
38 # include <mln/util/array.hh>
39 
40 # include <scribo/primitive/link/with_single_right_link.hh>
41 # include <scribo/core/object_links.hh>
42 # include <scribo/core/component_set.hh>
43 # include <scribo/core/macros.hh>
44 
45 
46 namespace scribo
47 {
48 
49  namespace primitive
50  {
51 
52  namespace link
53  {
54 
55  using namespace mln;
56 
62  //
63  template <typename L>
64  inline
65  object_links<L>
66  with_several_right_links(const component_set<L>& comps,
67  unsigned neighb_max_distance);
68 
70  template <typename L>
71  inline
72  object_links<L>
73  with_several_right_links(const component_set<L>& comps);
74 
75 
76 # ifndef MLN_INCLUDE_ONLY
77 
78 
79  template <typename L>
80  inline
81  object_links<L>
82  with_several_right_links(const component_set<L>& comps,
83  unsigned neighb_max_distance)
84  {
85  mln_trace("scribo::primitive::link::with_several_right_links");
86 
87  // -------
88  // | X------->
89  // | |
90  // | |
91  // | X------->
92  // | |
93  // | |
94  // | X------->
95  // -------
96 
97  // FIXME: make it faster.
98  internal::single_right_functor<L>
99  functor(comps, neighb_max_distance);
100  object_links<L> link_center = compute(functor, anchor::Center);
101  object_links<L> link_top = compute(functor, anchor::Top);
102  object_links<L> link_bot = compute(functor, anchor::Bottom);
103 
104 
105  object_links<L> final_link(comps);
106 
107  for_all_comps(i, comps)
108  {
109  if (link_center.is_linked(i))
110  final_link.update(i, link_center(i));
111  else if (link_top(i) == link_bot(i))
112  final_link.update(i, link_top(i));
113  else if (link_top.is_linked(i) && ! link_bot.is_linked(i))
114  final_link.update(i, link_top(i));
115  else if (link_bot.is_linked(i) && ! link_top.is_linked(i))
116  final_link.update(i, link_bot(i));
117  else
118  final_link.clear(i);
119  }
120 
121  return final_link;
122  }
123 
124 
125  template <typename L>
126  inline
127  object_links<L>
128  with_several_right_links(const component_set<L>& comps)
129  {
130  return with_several_right_links(comps, mln_max(unsigned));
131  }
132 
133 
134 # endif // ! MLN_INCLUDE_ONLY
135 
136  } // end of namespace scribo::primitive::link
137 
138  } // end of namespace scribo::primitive
139 
140 } // end of namespace scribo
141 
142 #endif // ! SCRIBO_PRIMITIVE_LINK_WITH_SEVERAL_RIGHT_LINKS_HH