$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
cuboid3d.hh
1 // Copyright (C) 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_CUBOID3D_HH
27 # define MLN_WIN_CUBOID3D_HH
28 
32 
33 # include <mln/core/internal/classical_window_base.hh>
34 # include <mln/core/alias/dpoint3d.hh>
35 
36 
37 namespace mln
38 {
39 
41 
42 
43  namespace win
44  {
45 
80  struct cuboid3d : public internal::classical_window_base< dpoint3d, cuboid3d >
81  {
89  cuboid3d(unsigned depth, unsigned height, unsigned width);
90 
91 
95  unsigned depth() const;
97  unsigned height() const;
99  unsigned width() const;
101 
103  unsigned volume() const;
104 
107  unsigned delta_() const;
108 
109  void print_(std::ostream& ostr) const;
110 
111  protected:
113  unsigned depth_;
115  unsigned height_;
117  unsigned width_;
118  };
119 
120 
121 
122 # ifndef MLN_INCLUDE_ONLY
123 
124  inline
125  cuboid3d::cuboid3d(unsigned depth, unsigned height, unsigned width)
126  : depth_(depth),
127  height_(height),
128  width_(width)
129  {
130  mln_precondition(height % 2 == 1 && width % 2 == 1);
131  const def::coord
132  dsli = static_cast<def::coord>(depth / 2),
133  drow = static_cast<def::coord>(height / 2),
134  dcol = static_cast<def::coord>(width / 2),
135  minus_dsli = static_cast<def::coord>(- dsli),
136  minus_drow = static_cast<def::coord>(- drow),
137  minus_dcol = static_cast<def::coord>(- dcol);
138  for (def::coord sli = minus_dsli; sli <= dsli; ++sli)
139  for (def::coord row = minus_drow; row <= drow; ++row)
140  for (def::coord col = minus_dcol; col <= dcol; ++col)
141  insert(dpoint3d(sli, row, col));
142  }
143 
144  inline
145  unsigned
146  cuboid3d::depth() const
147  {
148  return depth_;
149  }
150 
151  inline
152  unsigned
153  cuboid3d::height() const
154  {
155  return height_;
156  }
157 
158  inline
159  unsigned
160  cuboid3d::width() const
161  {
162  return width_;
163  }
164 
165  inline
166  unsigned
167  cuboid3d::volume() const
168  {
169  return depth_ * width_ * height_;
170  }
171 
172  inline
173  unsigned
174  cuboid3d::delta_() const
175  {
176  if (depth_ > height_)
177  if (depth_ > width_)
178  // height_ < depth_ && width_ < depth_.
179  return depth_ / 2;
180  else
181  // height_ < depth_ <= width_.
182  return width_ / 2;
183  else
184  if (height_ > width_)
185  // depth_ <= height_ && width_ <= height_.
186  return height_ / 2;
187  else
188  // depth_ <= height_ <= width_.
189  return width_ / 2;
190  }
191 
192  inline
193  void
194  cuboid3d::print_(std::ostream& ostr) const
195  {
196  ostr << "[cuboid3d: width=" << depth_
197  << ", depth=" << width_
198  << ", height=" << height_ << ']';
199  }
200 
201 # endif // ! MLN_INCLUDE_ONLY
202 
203  } // end of namespace mln::win
204 
205 } // end of namespace mln
206 
207 
208 #endif // ! MLN_WIN_CUBOID3D_HH