$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
top_right.hh
1 // Copyright (C) 2012 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_GEOM_TOP_RIGHT_HH
27 # define MLN_GEOM_TOP_RIGHT_HH
28 
32 
33 # include <mln/core/concept/image.hh>
34 # include <mln/geom/bbox.hh>
35 
36 
37 namespace mln
38 {
39 
40  namespace geom
41  {
42 
48  template <typename I>
49  mln_site(I) top_right(const Image<I>& ima);
50 
51 
55  template <typename B>
56  mln_site(B) top_right(const Box<B>& b);
57 
58 # ifndef MLN_INCLUDE_ONLY
59 
60 
61  namespace impl
62  {
63 
64  template <typename B>
65  inline
66  mln_site(B) top_right_2d(const Box<B>& b_)
67  {
68  const B& b = exact(b_);
69  mln_site(B) top_right(b.pmin().row(),
70  b.pmax().col());
71  return top_right;
72  }
73 
74  template <typename B>
75  inline
76  mln_site(B) top_right_3d(const Box<B>& b_)
77  {
78  const B& b = exact(b_);
79  mln_site(B) top_right(b.pmin().sli(),
80  b.pmin().row(),
81  b.pmax().col());
82  return top_right;
83  }
84 
85  } // end of namespace mln::geom::impl
86 
87 
88  namespace internal
89  {
90 
91  // Not implemented.
92  template <unsigned n>
93  struct top_right_dispatch_impl;
94 
95  // 2d
96  template <>
97  struct top_right_dispatch_impl<2>
98  {
99  template <typename B>
100  inline
101  mln_site(B) run(const Box<B>& box) const
102  {
103  return impl::top_right_2d(box);
104  }
105  };
106 
107  // 3d
108  template <>
109  struct top_right_dispatch_impl<3>
110  {
111  template <typename B>
112  inline
113  mln_site(B) run(const Box<B>& box) const
114  {
115  return impl::top_right_3d(box);
116  }
117  };
118 
119 
120  template <typename B>
121  inline
122  mln_site(B) top_right_dispatch(const Box<B>& box)
123  {
124  typedef mln_site(B) P;
125  return top_right_dispatch_impl<P::dim>().run(box);
126  }
127 
128  } // end of namespace mln::geom::internal
129 
130 
131  // Facades
132 
133  template <typename I>
134  inline
135  mln_site(I) top_right(const Image<I>& ima)
136  {
137  mln_precondition(exact(ima).is_valid());
138  mln_site(I) output = internal::top_right_dispatch(exact(ima).domain());
139 
140  return output;
141  }
142 
143  template <typename B>
144  inline
145  mln_site(B) top_right(const Box<B>& b)
146  {
147  mln_precondition(exact(b).is_valid());
148  mln_site(B) output = internal::top_right_dispatch(b);
149 
150  return output;
151  }
152 
153 # endif // ! MLN_INCLUDE_ONLY
154 
155  } // end of namespace mln::geom
156 
157 } // end of namespace mln
158 
159 
160 #endif // ! MLN_GEOM_TOP_RIGHT_HH