Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
border/equalize.hh
1 // Copyright (C) 2007, 2008, 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_BORDER_EQUALIZE_HH
27 # define MLN_BORDER_EQUALIZE_HH
28 
35 # include <mln/border/resize.hh>
36 
37 
38 namespace mln
39 {
40 
41  namespace border
42  {
43 
58  template <typename I, typename J>
59  void equalize(const Image<I>& ima1, const Image<J>& ima2,
60  unsigned min_thickness);
61 
62 
63 
64 # ifndef MLN_INCLUDE_ONLY
65 
66  namespace impl
67  {
68 
69  template <typename I, typename J>
70  inline
71  void equalize_(const I& ima1, const J& ima2, unsigned min_thickness)
72  {
73  trace::entering("border::impl::equalize_");
74 
75  unsigned b1 = border::get(ima1), b2 = border::get(ima2);
76 
77  if (! (b1 == b2 && b2 >= min_thickness))
78  // Something has to be done.
79  {
80  if (b1 < min_thickness && b2 < min_thickness)
81  // Both images have to be border-resized.
82  {
83  border::resize(ima1, min_thickness);
84  border::resize(ima2, min_thickness);
85  }
86  else
87  // A single image has to be border-resized with
88  // the other image thickness.
89  if (b1 < min_thickness)
90  {
91  mln_assertion(b2 >= min_thickness);
92  border::resize(ima1, b2);
93  }
94  else
95  {
96  //mln_assertion(b2 < min_thickness); // why ?
97  mln_assertion(b1 >= min_thickness);
98  border::resize(ima2, b1);
99  }
100  }
101 
102  trace::exiting("border::impl::equalize_");
103  }
104 
105  } // end of namespace mln::border::impl
106 
107 
108  // Facade
109 
110  template <typename I, typename J>
111  inline
112  void equalize(const Image<I>& ima1_, const Image<J>& ima2_,
113  unsigned min_thickness)
114  {
115  trace::entering("border::equalize");
116 
117  //FIXME: check border
118  //mlc_is(mln_trait_image_border(I), trait::image::border::some)::check();
119  //mlc_is(mln_trait_image_border(J), trait::image::border::some)::check();
120  const I& ima1 = exact(ima1_);
121  const J& ima2 = exact(ima2_);
122  mln_precondition(ima1.is_valid() && ima2.is_valid());
123 
124  impl::equalize_(ima1, ima2, min_thickness);
125 
126  mln_postcondition(border::get(ima1) == border::get(ima2) &&
127  border::get(ima1) >= min_thickness &&
128  border::get(ima2) >= min_thickness);
129 
130  trace::exiting("border::equalize");
131  }
132 
133 # endif // ! MLN_INCLUDE_ONLY
134 
135  } // end of namespace mln::border
136 
137 } // end of namespace mln
138 
139 
140 #endif // ! MLN_BORDER_EQUALIZE_HH