00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef MLN_WIN_CUBOID3D_HH
00027 # define MLN_WIN_CUBOID3D_HH
00028
00032
00033 # include <mln/core/internal/classical_window_base.hh>
00034 # include <mln/core/alias/dpoint3d.hh>
00035
00036
00037 namespace mln
00038 {
00039
00040 mln_internal_add_classical_window_trait(cuboid3d);
00041
00042
00043 namespace win
00044 {
00045
00080 struct cuboid3d : public internal::classical_window_base< dpoint3d, cuboid3d >
00081 {
00089 cuboid3d(unsigned depth, unsigned height, unsigned width);
00090
00091
00095 unsigned depth() const;
00097 unsigned height() const;
00099 unsigned width() const;
00101
00103 unsigned volume() const;
00104
00107 unsigned delta_() const;
00108
00109 void print_(std::ostream& ostr) const;
00110
00111 protected:
00113 unsigned depth_;
00115 unsigned height_;
00117 unsigned width_;
00118 };
00119
00120
00121
00122 # ifndef MLN_INCLUDE_ONLY
00123
00124 inline
00125 cuboid3d::cuboid3d(unsigned depth, unsigned height, unsigned width)
00126 : depth_(depth),
00127 height_(height),
00128 width_(width)
00129 {
00130 mln_precondition(height % 2 == 1 && width % 2 == 1);
00131 const def::coord
00132 dsli = static_cast<def::coord>(depth / 2),
00133 drow = static_cast<def::coord>(height / 2),
00134 dcol = static_cast<def::coord>(width / 2),
00135 minus_dsli = static_cast<def::coord>(- dsli),
00136 minus_drow = static_cast<def::coord>(- drow),
00137 minus_dcol = static_cast<def::coord>(- dcol);
00138 for (def::coord sli = minus_dsli; sli <= dsli; ++sli)
00139 for (def::coord row = minus_drow; row <= drow; ++row)
00140 for (def::coord col = minus_dcol; col <= dcol; ++col)
00141 insert(dpoint3d(sli, row, col));
00142 }
00143
00144 inline
00145 unsigned
00146 cuboid3d::depth() const
00147 {
00148 return depth_;
00149 }
00150
00151 inline
00152 unsigned
00153 cuboid3d::height() const
00154 {
00155 return height_;
00156 }
00157
00158 inline
00159 unsigned
00160 cuboid3d::width() const
00161 {
00162 return width_;
00163 }
00164
00165 inline
00166 unsigned
00167 cuboid3d::volume() const
00168 {
00169 return depth_ * width_ * height_;
00170 }
00171
00172 inline
00173 unsigned
00174 cuboid3d::delta_() const
00175 {
00176 if (depth_ > height_)
00177 if (depth_ > width_)
00178
00179 return depth_ / 2;
00180 else
00181
00182 return width_ / 2;
00183 else
00184 if (height_ > width_)
00185
00186 return height_ / 2;
00187 else
00188
00189 return width_ / 2;
00190 }
00191
00192 inline
00193 void
00194 cuboid3d::print_(std::ostream& ostr) const
00195 {
00196 ostr << "[cuboid3d: width=" << depth_
00197 << ", depth=" << width_
00198 << ", height=" << height_ << ']';
00199 }
00200
00201 # endif // ! MLN_INCLUDE_ONLY
00202
00203 }
00204
00205 }
00206
00207
00208 #endif // ! MLN_WIN_CUBOID3D_HH