Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 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 // height_ < depth_ && width_ < depth_. 00179 return depth_ / 2; 00180 else 00181 // height_ < depth_ <= width_. 00182 return width_ / 2; 00183 else 00184 if (height_ > width_) 00185 // depth_ <= height_ && width_ <= height_. 00186 return height_ / 2; 00187 else 00188 // depth_ <= height_ <= width_. 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 } // end of namespace mln::win 00204 00205 } // end of namespace mln 00206 00207 00208 #endif // ! MLN_WIN_CUBOID3D_HH