$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
with_several_left_links.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_WITH_SEVERAL_LEFT_LINKS_HH
28 # define SCRIBO_PRIMITIVE_LINK_WITH_SEVERAL_LEFT_LINKS_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/concept/neighborhood.hh>
36 
37 # include <mln/util/array.hh>
38 
39 # include <scribo/primitive/link/with_single_left_link.hh>
40 # include <scribo/core/object_links.hh>
41 # include <scribo/core/component_set.hh>
42 # include <scribo/core/macros.hh>
43 
44 
45 namespace scribo
46 {
47 
48  namespace primitive
49  {
50 
51  namespace link
52  {
53 
59  //
60  template <typename L>
61  inline
62  object_links<L>
63  with_several_left_links(const component_set<L>& objects,
64  unsigned neighb_max_distance);
65 
66 
68  template <typename L>
69  inline
70  object_links<L>
71  with_several_left_links(const component_set<L>& comps);
72 
73 
74 # ifndef MLN_INCLUDE_ONLY
75 
76  template <typename L>
77  inline
78  object_links<L>
79  with_several_left_links(const component_set<L>& comps,
80  unsigned neighb_max_distance)
81  {
82  mln_trace("scribo::primitive::link::with_several_left_links");
83 
84  // -------
85  // <------X |
86  // | |
87  // | |
88  // <------X |
89  // | |
90  // | |
91  // <------X |
92  // -------
93 
94  // FIXME: make it faster.
95  internal::single_left_functor<L>
96  functor(comps, neighb_max_distance);
97  object_links<L> link_center = compute(functor, anchor::Center);
98  object_links<L> link_top = compute(functor, anchor::Top);
99  object_links<L> link_bot = compute(functor, anchor::Bottom);
100 
101 
102  object_links<L> final_link(comps);
103 
104  for_all_comps(i, comps)
105  {
106  if (link_center.is_linked(i))
107  final_link.update((i), link_center(i));
108  else if (link_top(i) == link_bot(i))
109  final_link.update(i, link_top(i));
110  else if (link_top.is_linked(i) && ! link_bot.is_linked(i))
111  final_link.update(i, link_top(i));
112  else if (link_bot.is_linked(i) && ! link_top.is_linked(i))
113  final_link.update(i, link_bot(i));
114  else
115  final_link.clear(i);
116  }
117 
118 
119 
120  return final_link;
121  }
122 
123 
124  template <typename L>
125  inline
126  object_links<L>
127  with_several_left_links(const component_set<L>& comps)
128  {
129  return with_several_left_links(comps);
130  }
131 
132 # endif // ! MLN_INCLUDE_ONLY
133 
134  } // end of namespace scribo::primitive::link
135 
136  } // end of namespace scribo::primitive
137 
138 } // end of namespace scribo
139 
140 #endif // ! SCRIBO_PRIMITIVE_LINK_WITH_SEVERAL_LEFT_LINKS_HH