• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

fill_full.cc

00001 // Copyright (C) 2007, 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 #include <mln/border/fill.hh>
00027 #include <mln/data/fill.hh>
00028 #include <mln/opt/element.hh>
00029 #include <mln/core/image/image1d.hh>
00030 #include <mln/core/image/image2d.hh>
00031 #include <mln/core/image/image3d.hh>
00032 #include <mln/value/int_u8.hh>
00033 #include <mln/value/int_u16.hh>
00034 #include <mln/value/int_s8.hh>
00035 #include <mln/value/int_s16.hh>
00036 #include <mln/value/rgb8.hh>
00037 #include <mln/value/rgb16.hh>
00038 #include <mln/value/float01_8.hh>
00039 #include <mln/value/float01_16.hh>
00040 #include <mln/debug/println_with_border.hh>
00041 
00042 
00043 using namespace mln;
00044 
00045 
00046 template <typename T>
00047 void
00048 check1d(unsigned row, unsigned border, T& value, T& v)
00049 {
00050   image1d<T> ima(row, border);
00051   data::fill (ima, v);
00052   border::fill (ima, value);
00053 
00054   unsigned i = 0;
00055   for(i = 0; i < border; ++i)
00056     mln_assertion (opt::element(ima, i) == value);
00057   unsigned bo = border + row;
00058   for(; i < bo; ++i)
00059     mln_assertion (opt::element(ima, i) == v);
00060   bo += border;
00061   for(; i < bo; ++i)
00062     mln_assertion (opt::element(ima, i) == value);
00063 }
00064 
00065 template <typename T>
00066 void
00067 check2d(unsigned row, unsigned col, unsigned border, T& value, T& v)
00068 {
00069   image2d<T> ima(row, col, border);
00070   data::fill (ima, v);
00071   border::fill (ima, value);
00072 
00073   unsigned c = col + 2 * border;
00074   unsigned r = row + 2 * border;
00075   unsigned bo = c * border + border;
00076   unsigned i = 0;
00077   unsigned u = col + border;
00078   unsigned ww = r * c;
00079 
00080   for(i = 0; i < bo; ++i)
00081     mln_assertion (opt::element(ima, i) == value);
00082   bo += c * row;
00083   for(; i < bo; ++i)
00084     {
00085       unsigned cur = i % c;
00086       if (cur < border || cur >= u)
00087         mln_assertion (opt::element(ima, i) == value);
00088       else
00089         mln_assertion (opt::element(ima, i) == v);
00090     }
00091   for(; i < ww; ++i)
00092     mln_assertion (opt::element(ima, i) == value);
00093 }
00094 
00095 template <typename T>
00096 void
00097 check3d(unsigned sli, unsigned row, unsigned col, unsigned border, T& value, T& v)
00098 {
00099   image3d<T> ima(sli, row, col, border);
00100   data::fill (ima, v);
00101   border::fill (ima, value);
00102 
00103   unsigned c = col + 2 * border;
00104   unsigned r = row + 2 * border;
00105   unsigned bo = c * border + border;
00106   unsigned i = 0;
00107   unsigned u = col + border;
00108   unsigned ww = r * c;
00109 
00110   for(i = 0; i < bo; ++i)
00111     mln_assertion (opt::element(ima, i) == value);
00112   bo += c * row;
00113   for(; i < bo; ++i)
00114     {
00115       unsigned cur = i % c;
00116       if (cur < border || cur >= u)
00117         mln_assertion (opt::element(ima, i) == value);
00118       else
00119         mln_assertion (opt::element(ima, i) == v);
00120     }
00121   for(; i < ww; ++i)
00122     mln_assertion (opt::element(ima, i) == value);
00123 }
00124 
00125 
00126 int
00127 main (void)
00128 {
00129   int limits = 10;
00130 
00131   {
00132     typedef int T;
00133     T value = (T) -1;
00134     T v = 42;
00135 
00136     for (int i = 1; i < limits; ++i)
00137       for (int j = 1; j < limits; ++j)
00138             check1d(i, j, value, v);
00139 
00140     for (int i = 1; i < limits; ++i)
00141       for (int j = 1; j < limits; ++j)
00142         for (int k = 1; k < limits; ++k)
00143             check2d(i, j, k, value, v);
00144   }
00145 
00146   {
00147     typedef unsigned T;
00148     T value = (T) -1;
00149     T v = 42;
00150 
00151     for (int i = 1; i < limits; ++i)
00152       for (int j = 1; j < limits; ++j)
00153             check1d(i, j, value, v);
00154 
00155     for (int i = 1; i < limits; ++i)
00156       for (int j = 1; j < limits; ++j)
00157         for (int k = 1; k < limits; ++k)
00158             check2d(i, j, k, value, v);
00159   }
00160 
00161   {
00162     typedef value::int_u8 T;
00163     T value = 255;
00164     T v = 42;
00165 
00166     for (int i = 1; i < limits; ++i)
00167       for (int j = 1; j < limits; ++j)
00168             check1d(i, j, value, v);
00169 
00170     for (int i = 1; i < limits; ++i)
00171       for (int j = 1; j < limits; ++j)
00172         for (int k = 1; k < limits; ++k)
00173             check2d(i, j, k, value, v);
00174   }
00175 
00176   {
00177     typedef value::int_u16 T;
00178     T value = 65535;
00179     T v = 42;
00180 
00181     for (int i = 1; i < limits; ++i)
00182       for (int j = 1; j < limits; ++j)
00183             check1d(i, j, value, v);
00184 
00185     for (int i = 1; i < limits; ++i)
00186       for (int j = 1; j < limits; ++j)
00187         for (int k = 1; k < limits; ++k)
00188             check2d(i, j, k, value, v);
00189   }
00190 
00191   {
00192     typedef value::int_s8 T;
00193     T value = 127;
00194     T v = 42;
00195 
00196     for (int i = 1; i < limits; ++i)
00197       for (int j = 1; j < limits; ++j)
00198             check1d(i, j, value, v);
00199 
00200     for (int i = 1; i < limits; ++i)
00201       for (int j = 1; j < limits; ++j)
00202         for (int k = 1; k < limits; ++k)
00203             check2d(i, j, k, value, v);
00204   }
00205 
00206   {
00207     typedef value::int_s16 T;
00208     T value = 32767;
00209     T v = 42;
00210 
00211     for (int i = 1; i < limits; ++i)
00212       for (int j = 1; j < limits; ++j)
00213             check1d(i, j, value, v);
00214 
00215     for (int i = 1; i < limits; ++i)
00216       for (int j = 1; j < limits; ++j)
00217         for (int k = 1; k < limits; ++k)
00218             check2d(i, j, k, value, v);
00219   }
00220 
00221   {
00222     typedef value::rgb8 T;
00223     T value = T(255, 255, 255);
00224     T v = T(42, 0, 0);
00225 
00226     for (int i = 1; i < limits; ++i)
00227       for (int j = 1; j < limits; ++j)
00228             check1d(i, j, value, v);
00229 
00230     for (int i = 1; i < limits; ++i)
00231       for (int j = 1; j < limits; ++j)
00232         for (int k = 1; k < limits; ++k)
00233             check2d(i, j, k, value, v);
00234   }
00235 
00236   {
00237     typedef value::rgb16 T;
00238     T value = T(65535, 65535, 65535);
00239     T v = T(42, 0, 0);
00240 
00241     for (int i = 1; i < limits; ++i)
00242       for (int j = 1; j < limits; ++j)
00243             check1d(i, j, value, v);
00244 
00245     for (int i = 1; i < limits; ++i)
00246       for (int j = 1; j < limits; ++j)
00247         for (int k = 1; k < limits; ++k)
00248             check2d(i, j, k, value, v);
00249   }
00250 
00251 
00252   {
00253     typedef value::float01_8 T;
00254     T value = static_cast<T>(0.9999f);
00255     T v = static_cast<T>(0.111f);
00256 
00257     for (int i = 1; i < limits; ++i)
00258       for (int j = 1; j < limits; ++j)
00259             check1d(i, j, value, v);
00260 
00261     for (int i = 1; i < limits; ++i)
00262       for (int j = 1; j < limits; ++j)
00263         for (int k = 1; k < limits; ++k)
00264             check2d(i, j, k, value, v);
00265   }
00266 
00267   {
00268     typedef value::float01_16 T;
00269     T value = static_cast<T>(0.9999f);
00270     T v = static_cast<T>(0.111f);
00271 
00272     for (int i = 1; i < limits; ++i)
00273       for (int j = 1; j < limits; ++j)
00274             check1d(i, j, value, v);
00275 
00276     for (int i = 1; i < limits; ++i)
00277       for (int j = 1; j < limits; ++j)
00278         for (int k = 1; k < limits; ++k)
00279             check2d(i, j, k, value, v);
00280   }
00281 
00282 
00283 }

Generated on Tue Oct 4 2011 15:23:46 for Milena (Olena) by  doxygen 1.7.1