$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
display_edge.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 MLN_WORLD_INTER_PIXEL_DISPLAY_EDGE_HH
27 # define MLN_WORLD_INTER_PIXEL_DISPLAY_EDGE_HH
28 
33 
34 # include <mln/core/image/image2d.hh>
35 # include <mln/core/image/dmorph/image_if.hh>
36 # include <mln/data/fill.hh>
37 # include <mln/world/inter_pixel/is_separator.hh>
38 # include <mln/opt/at.hh>
39 
40 namespace mln
41 {
42 
43  namespace world
44  {
45 
46  namespace inter_pixel
47  {
48 
60  template <typename I>
61  inline
62  I display_edge(const I& ima, mln_value(I) bg, unsigned zoom);
63 
64 # ifndef MLN_INCLUDE_ONLY
65 
66 
67  template <typename I>
68  inline
69  I display_edge(const I& ima, mln_value(I) bg, unsigned zoom)
70  {
71  box2d b = ima.bbox();
72  I output(make::box2d(((b.pmin()[0] + 1) / 2) * (zoom + 1),
73  ((b.pmin()[1] + 1) / 2) * (zoom + 1),
74  ((b.pmax()[0] + 1) / 2 + 1) * (zoom + 1) - 2,
75  ((b.pmax()[1] + 1) / 2 + 1) * (zoom + 1) - 2));
76  data::fill(output, bg);
77  typedef image_if<const I, is_separator> edge_t;
78  edge_t edge = ima | is_separator();
79  mln_piter(edge_t) p(edge.domain());
80  for_all(p)
81  if (p.row() % 2) // horizontal edge
82  {
83  unsigned row = (p.row() / 2 + 1) * (zoom + 1) - 1;
84  unsigned col = (p.col() / 2) * (zoom + 1);
85  for (unsigned i = 0; i < zoom; ++i)
86  opt::at(output, row, col + i) = ima(p);
87  }
88  else // vertical edge
89  {
90  unsigned row = (p.row() / 2) * (zoom + 1);
91  unsigned col = (p.col() / 2 + 1) * (zoom + 1) - 1;
92  for (unsigned i = 0; i < zoom; ++i)
93  opt::at(output, row + i, col) = ima(p);
94  }
95  return output;
96  }
97 
98 
99 # endif // ! MLN_INCLUDE_ONLY
100 
101  } // end of namespace mln::world::inter_pixel
102 
103  } // end of namespace mln::world
104 
105 } // end of namespace mln
106 
107 #endif // ! MLN_WORLD_INTER_PIXEL_DISPLAY_EDGE_HH