$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
separator_to_pixels.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_SEPARATOR_TO_PIXELS_HH
27 # define MLN_WORLD_INTER_PIXEL_SEPARATOR_TO_PIXELS_HH
28 
34 
35 # include <mln/core/concept/gpoint.hh>
36 # include <mln/core/concept/site_proxy.hh>
37 # include <mln/world/inter_pixel/is_pixel.hh>
38 # include <mln/world/inter_pixel/is_separator.hh>
39 
40 
41 namespace mln
42 {
43 
44  namespace world
45  {
46 
47  namespace inter_pixel
48  {
49 
50 
51  template <typename P>
52  void
53  separator_to_pixels(const Gpoint<P>& s,
54  Gpoint<P>& p1, Gpoint<P>& p2);
55 
56  template <typename Ps, typename P>
57  void
58  separator_to_pixels(const Site_Proxy<Ps>& s,
59  Gpoint<P>& p1, Gpoint<P>& p2);
60 
61 
62 # ifndef MLN_INCLUDE_ONLY
63 
64 
65  template <typename P>
66  inline
67  void
68  separator_to_pixels(const Gpoint<P>& s_,
69  Gpoint<P>& p1_, Gpoint<P>& p2_)
70  {
71  const P& s = exact(s_);
72  P& p1 = exact(p1_);
73  P& p2 = exact(p2_);
74 
75 # ifndef NDEBUG
76  {
77  // Pre-condition.
78  is_separator is_separator_;
79  mln_precondition(is_separator_(s));
80  (void) is_separator_;
81  }
82 # endif // ! NDEBUG
83 
84  // FIXME: 2D only.
85  if (s.row() % 2)
86  {
87  // Horizontal edge.
88  p1 = point2d(s.row() - 1, s.col());
89  p2 = point2d(s.row() + 1, s.col());
90  }
91  else
92  {
93  // Vertical edge.
94  p1 = point2d(s.row(), s.col() - 1);
95  p2 = point2d(s.row(), s.col() + 1);
96  }
97 
98 # ifndef NDEBUG
99  {
100  // Post-conditions.
101  is_pixel is_pixel_;
102  mln_postcondition(is_pixel_(p1));
103  mln_postcondition(is_pixel_(p2));
104  (void) is_pixel_;
105  }
106 # endif // ! NDEBUG
107  }
108 
109  template <typename Ps, typename P>
110  inline
111  void
112  separator_to_pixels(const Site_Proxy<Ps>& s_,
113  Gpoint<P>& p1_, Gpoint<P>& p2_)
114  {
115  const Ps& s = exact(s_);
116  P& p1 = exact(p1_);
117  P& p2 = exact(p2_);
118 
119 # ifndef NDEBUG
120  {
121  // Pre-condition.
122  is_separator is_separator_;
123  mln_precondition(is_separator_(s));
124  (void) is_separator_;
125  }
126 # endif // ! NDEBUG
127 
128  separator_to_pixels(s.to_site(), p1, p2);
129 
130 # ifndef NDEBUG
131  {
132  // Post-conditions.
133  is_pixel is_pixel_;
134  mln_postcondition(is_pixel_(p1));
135  mln_postcondition(is_pixel_(p2));
136  (void) is_pixel_;
137  }
138 # endif // ! NDEBUG
139  }
140 
141 # endif // ! MLN_INCLUDE_ONLY
142 
143  } // end of namespace mln::world::inter_pixel
144 
145  } // end of namespace mln::world
146 
147 } // end of namespace mln
148 
149 #endif // ! MLN_WORLD_INTER_PIXEL_SEPARATOR_TO_PIXELS_HH