$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
win/line.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_WIN_LINE_HH
27 # define MLN_WIN_LINE_HH
28 
32 
33 # include <mln/core/internal/classical_window_base.hh>
34 # include <mln/core/dpoint.hh>
35 
36 
37 namespace mln
38 {
39 
40  // Forward declaration.
41  namespace win { template <typename M, unsigned i, typename C> struct line; }
42 
43 
44  namespace trait
45  {
46 
47  template <typename M, unsigned i, typename C>
48  struct window_< mln::win::line<M,i,C> > : classical_window_
49  {
50  };
51 
52  } // end of namespace trait
53 
54 
55 
56  namespace win
57  {
58 
72  template <typename M, unsigned i, typename C>
73  struct line : public internal::classical_window_base< dpoint<M, C>, line<M,i,C> >
74  {
76  enum { dir = i };
77 
81  line(unsigned length);
82 
84  unsigned length() const;
85 
87  unsigned size() const;
88 
91  unsigned delta_() const;
92 
93  void print_(std::ostream& ostr) const;
94 
95  protected:
96  unsigned length_;
97  };
98 
99 
100 
101 # ifndef MLN_INCLUDE_ONLY
102 
103 
104  template <typename M, unsigned i, typename C>
105  inline
106  line<M,i,C>::line(unsigned length)
107  : length_(length)
108  {
109  metal::bool_< i < M::dim >::check();
110  mln_precondition(length % 2 == 1);
111  dpoint<M,C> n;
112  n.set_all(0);
113  const def::coord
114  dc = static_cast<def::coord>(length / 2),
115  minus_dc = static_cast<def::coord>(- dc);
116  for (def::coord c = minus_dc; c <= dc; ++c)
117  {
118  n[i] = c;
119  this->insert(n);
120  }
121  }
122 
123  template <typename M, unsigned i, typename C>
124  inline
125  unsigned line<M,i,C>::length() const
126  {
127  return length_;
128  }
129 
130  template <typename M, unsigned i, typename C>
131  inline
132  unsigned line<M,i,C>::size() const
133  {
134  return length_;
135  }
136 
137  template <typename M, unsigned i, typename C>
138  inline
139  unsigned line<M,i,C>::delta_() const
140  {
141  return length_ / 2;
142  }
143 
144  template <typename M, unsigned i, typename C>
145  inline
146  void
147  line<M,i,C>::print_(std::ostream& ostr) const
148  {
149  ostr << "[line: length=" << length_ << ']';
150  }
151 
152 # endif // ! MLN_INCLUDE_ONLY
153 
154  } // end of namespace mln::win
155 
156 } // end of namespace mln
157 
158 
159 
160 #endif // ! MLN_WIN_LINE_HH