$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
linfty.hh
1 // Copyright (C) 2007, 2008, 2009, 2012 EPITA Research and Development
2 // Laboratory (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 MLN_NORM_LINFTY_HH
28 # define MLN_NORM_LINFTY_HH
29 
36 
37 # include <mln/math/abs.hh>
38 # include <mln/algebra/vec.hh>
39 
40 
41 namespace mln
42 {
43 
44  namespace norm
45  {
46 
50 
51  template <unsigned n, typename C>
52  C linfty(const C (&vec)[n]);
53 
54  template <unsigned n, typename C>
55  C linfty(const algebra::vec<n,C>& vec);
57 
58 
63 
64  template <unsigned n, typename C>
65  C linfty_distance(const C (&vec1)[n], const C (&vec2)[n]);
66 
67  template <unsigned n, typename C>
68  C linfty_distance(const algebra::vec<n,C>& vec1,
69  const algebra::vec<n,C>& vec2);
71 
72 
73 # ifndef MLN_INCLUDE_ONLY
74 
75  namespace impl
76  {
77 
78  template <unsigned n, typename C, typename V>
79  inline
80  C linfty_(const V& vec)
81  {
82  C m = 0;
83  for (unsigned i = 0; i < n; ++i)
84  {
85  // Compute the maximal component absolute value of the
86  // vector.
87  C mc = mln::math::abs(vec[i]);
88  if (mc > m)
89  m = mc;
90  }
91  return m;
92  }
93 
94  template <unsigned n, typename C, typename V>
95  inline
96  C linfty_distance_(const V& vec1, const V& vec2)
97  {
98  C d = 0;
99  for (unsigned i = 0; i < n; ++i)
100  {
101  // Compute the maximal absolute value of the distance
102  // between components of the same index.
103  C dc = mln::math::abs(vec1[i] - vec2[i]);
104  if (dc > d)
105  d = dc;
106  }
107  return d;
108  }
109 
110  } // end of namespace mln::norm::impl
111 
112 
113  /*----------.
114  | Facades. |
115  `----------*/
116 
117  template <unsigned n, typename C>
118  inline
119  C linfty(const C (&vec)[n])
120  {
121  return impl::linfty_<n, C>(vec);
122  }
123 
124  template <unsigned n, typename C>
125  inline
126  C linfty(const algebra::vec<n,C>& vec)
127  {
128  return impl::linfty_<n, C>(vec);
129  }
130 
131  template <unsigned n, typename C>
132  inline
133  C linfty_distance(const C (&vec1)[n], const C (&vec2)[n])
134  {
135  return impl::linfty_distance_<n, C>(vec1, vec2);
136  }
137 
138  template <unsigned n, typename C>
139  inline
140  C linfty_distance(const algebra::vec<n,C>& vec1,
141  const algebra::vec<n,C>& vec2)
142  {
143  return impl::linfty_distance_<n, C>(vec1, vec2);
144  }
145 
146 # endif // ! MLN_INCLUDE_ONLY
147 
148  } // end of namespace mln::norm
149 
150 } // end of namespace mln
151 
152 
153 #endif // ! MLN_NORM_LINFTY_HH