Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 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_BALL_HH 00027 # define MLN_WIN_BALL_HH 00028 00032 00033 # include <mln/core/internal/classical_window_base.hh> 00034 # include <mln/core/dpoint.hh> 00035 # include <mln/core/site_set/box.hh> 00036 # include <mln/fun/i2v/all_to.hh> 00037 00038 00039 namespace mln 00040 { 00041 00042 // Forward declaration. 00043 namespace win { template <typename G, typename C> struct ball; } 00044 00045 00046 namespace trait 00047 { 00048 00049 template <typename G, typename C> 00050 struct window_< mln::win::ball<G,C> > : classical_window_ 00051 { 00052 }; 00053 00054 } // end of namespace trait 00055 00056 00057 00058 namespace win 00059 { 00060 00070 template <typename G, typename C> 00071 struct ball : public internal::classical_window_base< dpoint<G,C>, ball<G,C> > 00072 { 00073 00077 ball(unsigned diameter); 00078 00080 unsigned diameter() const; 00081 00084 unsigned delta_() const; 00085 00086 void print_(std::ostream& ostr) const; 00087 00088 protected: 00089 unsigned diameter_; 00090 }; 00091 00092 00093 00094 # ifndef MLN_INCLUDE_ONLY 00095 00096 00097 template <typename G, typename C> 00098 inline 00099 ball<G,C>::ball(unsigned diameter) 00100 : diameter_(diameter) 00101 { 00102 mln_precondition(diameter % 2 == 1); 00103 unsigned 00104 radius = diameter / 2, 00105 sqr_radius = radius * radius; 00106 typedef point<G,C> P; 00107 box<P> b(all_to(-radius), all_to(+radius)); 00108 P O = literal::origin; 00109 mln_piter(box<P>) p(b); 00110 for_all(p) 00111 { 00112 unsigned d = 0; 00113 for (unsigned i = 0; i < P::dim; ++i) 00114 d += p[i] * p[i]; 00115 if (d <= sqr_radius) 00116 this->insert(p - O); 00117 } 00118 } 00119 00120 template <typename G, typename C> 00121 inline 00122 unsigned ball<G,C>::diameter() const 00123 { 00124 return diameter_; 00125 } 00126 00127 template <typename G, typename C> 00128 inline 00129 unsigned ball<G,C>::delta_() const 00130 { 00131 return diameter_ / 2; 00132 } 00133 00134 template <typename G, typename C> 00135 inline 00136 void 00137 ball<G,C>::print_(std::ostream& ostr) const 00138 { 00139 ostr << "[" << G::dim << "D ball: diameter=" << diameter_ << ']'; 00140 } 00141 00142 # endif // ! MLN_INCLUDE_ONLY 00143 00144 } // end of namespace mln::win 00145 00146 } // end of namespace mln 00147 00148 00149 00150 #endif // ! MLN_WIN_BALL_HH