$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rectangle2d.hh
1 // Copyright (C) 2007, 2008, 2009, 2013 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_WIN_RECTANGLE2D_HH
28 # define MLN_WIN_RECTANGLE2D_HH
29 
35 
36 # include <mln/core/internal/classical_window_base.hh>
37 # include <mln/core/alias/dpoint2d.hh>
38 # include <mln/core/def/coord.hh>
39 
40 
41 namespace mln
42 {
43 
45 
46 
47  namespace win
48  {
49 
65  struct rectangle2d : public internal::classical_window_base< dpoint2d, rectangle2d >
66  {
74  rectangle2d(unsigned height, unsigned width);
75 
76 
78  unsigned height() const;
79 
81  unsigned width() const;
82 
84  unsigned area() const;
85 
87  const std::vector<dpoint2d>& std_vector() const;
88 
89 
91 
94  unsigned delta_() const;
95 
96  void print_(std::ostream& ostr) const;
98 
99  protected:
100 
101  unsigned height_, width_;
102  };
103 
104 
105 
106 # ifndef MLN_INCLUDE_ONLY
107 
108  inline
109  rectangle2d::rectangle2d(unsigned height, unsigned width)
110  : height_(height),
111  width_(width)
112  {
113  mln_precondition(height % 2 == 1 && width % 2 == 1);
114  const def::coord drow = (def::coord) (height / 2);
115  const def::coord dcol = (def::coord) (width / 2);
116 
117  for (def::coord row = (def::coord) -drow; row <= drow; ++row)
118  for (def::coord col = (def::coord) -dcol; col <= dcol; ++col)
119  this->insert(dpoint2d(row, col));
120  }
121 
122  inline
123  unsigned rectangle2d::height() const
124  {
125  return height_;
126  }
127 
128  inline
129  unsigned rectangle2d::width() const
130  {
131  return width_;
132  }
133 
134  inline
135  unsigned rectangle2d::area() const
136  {
137  return width_ * height_;
138  }
139 
140  inline
141  unsigned rectangle2d::delta_() const
142  {
143  return width_ > height_ ? width_ / 2 : height_ / 2;
144  }
145 
146  inline
147  const std::vector<dpoint2d>&
149  {
150  return win_.std_vector();
151  }
152 
153  inline
154  void
155  rectangle2d::print_(std::ostream& ostr) const
156  {
157  ostr << "[rectangle2d: width=" << width_ << ", height=" << height_ << ']';
158  }
159 
160 # endif // ! MLN_INCLUDE_ONLY
161 
162  } // end of namespace mln::win
163 
164 } // end of namespace mln
165 
166 
167 
168 // When rectangle2d is involved, one surely also wants:
169 # include <mln/win/hline2d.hh>
170 # include <mln/win/vline2d.hh>
171 
172 
173 #endif // ! MLN_WIN_RECTANGLE2D_HH