$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
line_components.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_DRAW_LINE_COMPONENTS_HH
28 # define SCRIBO_DRAW_LINE_COMPONENTS_HH
29 
33 # include <mln/util/object_id.hh>
34 
35 # include <scribo/core/line_set.hh>
36 # include <scribo/core/component_set.hh>
37 
38 
39 namespace scribo
40 {
41  namespace draw
42  {
43 
44  using namespace mln;
45 
46  template <typename L, typename I>
47  void
48  line_components(Image<I>& input_,
49  const line_set<L>& lines,
50  const line_info<L>& line,
51  const mln_value(I)& value);
52 
53 
54 # ifndef MLN_INCLUDE_ONLY
55 
56 
57  template <typename L, typename I>
58  void
59  line_components(Image<I>& input_,
60  const line_set<L>& lines,
61  const line_info<L>& line,
62  const mln_value(I)& value)
63  {
64  mln_trace("scribo::draw::line_components");
65 
66  I& input = exact(input_);
67 
68  mln_precondition(input.is_valid());
69 
70  const component_set<L>& comp_set = lines.components();
71  const L& labeled_image = lines.components().labeled_image();
72 
73  const mln::util::array<component_id_t>& component_ids = line.component_ids();
74 
75  for_all_elements(i, component_ids)
76  {
77  const unsigned c = component_ids(i);
78  const mln_value(L) v = c;
79  const box2d& bbox = comp_set(c).bbox();
80 
81  const unsigned index = labeled_image.offset_of_point(bbox.pmin());
82  const unsigned index2 = input.offset_of_point(bbox.pmin());
83  const mln_value(L)* ptr_in = &(labeled_image.element(index));
84  mln_value(I)* ptr_out = &(input.element(index2));
85  const unsigned nrows = bbox.height();
86  const unsigned ncols = bbox.width();
87  const int delta = labeled_image.delta_offset(dpoint2d(+1, -ncols));
88  const int delta2 = input.delta_offset(dpoint2d(+1, -ncols));
89 
90  for (unsigned k = 0; k < nrows; ++k)
91  {
92  for (unsigned j = 0; j < ncols; ++j)
93  {
94  if (*ptr_in == v)
95  *ptr_out = value;
96  ++ptr_out;
97  ++ptr_in;
98  }
99 
100  ptr_out += delta2;
101  ptr_in += delta;
102  }
103  }
104 
105  }
106 
107 
108 # endif // ! MLN_INCLUDE_ONLY
109 
110  } // end of namespace scribo::draw
111 } // end of namespace scribo
112 
113 #endif // ! SCRIBO_DRAW_LINE_COMPONENTS_HH