$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
from_single_left_link.hh
1 // Copyright (C) 2010, 2011, 2013 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_RELINK_FROM_SINGLE_LEFT_LINK_HH
28 # define SCRIBO_PRIMITIVE_RELINK_FROM_SINGLE_LEFT_LINK_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/concept/neighborhood.hh>
36 
37 # include <mln/accu/center.hh>
38 
39 # include <mln/labeling/compute.hh>
40 
41 # include <mln/math/abs.hh>
42 
43 # include <mln/util/array.hh>
44 
45 
46 # include <scribo/core/macros.hh>
47 # include <scribo/core/component_set.hh>
48 # include <scribo/core/object_links.hh>
49 # include <scribo/core/object_groups.hh>
50 
51 # include <scribo/primitive/group/apply.hh>
52 # include <scribo/primitive/group/from_single_link.hh>
53 # include <scribo/primitive/link/with_single_left_link.hh>
54 # include <scribo/primitive/link/internal/find_link.hh>
55 # include <scribo/primitive/link/internal/link_single_dmax_base.hh>
56 
57 # include <scribo/primitive/link/compute.hh>
58 
59 
60 namespace scribo
61 {
62 
63  namespace primitive
64  {
65 
66  namespace regroup
67  {
68 
75  //
76  template <typename L>
77  inline
78  object_groups<L>
79  from_single_left_link(const object_groups<L>& groups,
80  unsigned neighb_max_distance);
81 
82 
85  template <typename L>
86  inline
87  object_groups<L>
88  from_single_left_link(const object_groups<L>& groups);
89 
90 
91 # ifndef MLN_INCLUDE_ONLY
92 
93 
94  // Facades
95 
96  template <typename L>
97  inline
98  object_groups<L>
99  from_single_left_link(const object_groups<L>& groups,
100  unsigned neighb_max_distance)
101  {
102  mln_trace("scribo::primitive::regroup::from_single_left_link");
103 
104  mln_precondition(groups.is_valid());
105 
106 
107  object_groups<L> output = groups.duplicate();
108 
110  component_set<L>
111  components = primitive::group::apply(groups, relabel_fun);
112 
113  object_links<L>
114  links = primitive::link::with_single_left_link(components, neighb_max_distance);
115 
116  object_groups<L>
117  new_groups = primitive::group::from_single_link(links);
118 
119  // Preserve the original groups ids but merge newly regrouped
120  // groups.
121  for_all_groups(g, new_groups)
122  if (new_groups(g).card() > 1)
123  for (unsigned i = 1; i < new_groups(g).component_ids().nelements(); ++i)
124  output(relabel_fun(new_groups(g).component_ids()(0)))
125  .merge(output(relabel_fun(new_groups(g).component_ids()(i))));
126 
127  return output;
128  }
129 
130 
131  template <typename L>
132  inline
133  object_groups<L>
134  from_single_left_link(const object_groups<L>& groups)
135  {
136  return from_single_left_link(groups, mln_max(unsigned));
137  }
138 
139 
140 # endif // ! MLN_INCLUDE_ONLY
141 
142  } // end of namespace scribo::primitive::regroup
143 
144  } // end of namespace scribo::primitive
145 
146 } // end of namespace scribo
147 
148 #endif // ! SCRIBO_PRIMITIVE_LINK_FROM_SINGLE_LEFT_LINK_HH