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 #include <mln/core/image/image1d.hh>
00027 #include <mln/core/image/image2d.hh>
00028 #include <mln/debug/iota.hh>
00029 #include <mln/border/mirror.hh>
00030 #include <mln/value/int_u8.hh>
00031 #include <mln/value/int_s8.hh>
00032 #include <mln/opt/element.hh>
00033 
00034 
00035 namespace mln
00036 {
00037 
00038   template <typename T>
00039   void chck1d (int cols, int border, T ref[])
00040   {
00041     int c = cols + 2 * border;
00042 
00043     image1d<T> ima(cols, border);
00044     debug::iota(ima);
00045     border::mirror(ima);
00046 
00047     for (int i = 0; i < c; ++i)
00048       mln_assertion(opt::element(ima, i) == ref[i]);
00049   }
00050 
00051   template <typename T>
00052   void chck2d (int rows, int cols, int border, T ref[])
00053   {
00054     int r = rows + 2 * border;
00055     int c = cols + 2 * border;
00056 
00057     image2d<T> ima(rows, cols, border);
00058     debug::iota(ima);
00059     border::mirror(ima);
00060 
00061     for (int i = 0; i < c * r; ++i)
00062       mln_assertion(opt::element(ima, i) == ref[i]);
00063   }
00064 
00065 }
00066 
00067 
00068 int
00069 main (void)
00070 {
00071   using namespace mln;
00072 
00073 
00074   std::cerr << "Tests border::mirror:" << std::endl;
00075 
00076   {
00077     std::cerr << "  in 1d :" << std::endl;
00078 
00079     {
00080       (std::cerr << "    on int_u8 with border = 3 ... ").flush ();
00081 
00082       typedef value::int_u8 T;
00083       int border = 3;
00084       int cols = 2;
00085       T ref[8] = {2, 2, 1, 1, 2, 2, 1, 1};
00086 
00087       chck1d(cols, border, ref);
00088       std::cerr << "OK" << std::endl;
00089     }
00090 
00091     {
00092       (std::cerr << "    on    int with border = 2 ... ").flush ();
00093 
00094       typedef int T;
00095       int border = 2;
00096       int cols = 3;
00097       T ref[7] = {2, 1, 1, 2, 3, 3, 2};
00098 
00099       chck1d(cols, border, ref);
00100       std::cerr << "OK" << std::endl;
00101     }
00102 
00103     {
00104       (std::cerr << "    on int_s8 with border = 1 ... ").flush ();
00105 
00106       typedef value::int_s8 T;
00107       int border = 1;
00108       int cols = 2;
00109       T ref[4] = {1, 1, 2, 2};
00110 
00111       chck1d(cols, border, ref);
00112       std::cerr << "OK" << std::endl;
00113     }
00114 
00115     {
00116       (std::cerr << "    on    int with border = 0 ... ").flush ();
00117       typedef int T;
00118       int border = 0;
00119       int cols = 4;
00120       T ref[4] = {1, 2, 3, 4};
00121 
00122       chck1d(cols, border, ref);
00123       std::cerr << "OK" << std::endl;
00124     }
00125 
00126   } 
00127 
00128   {
00129     std::cerr << "  in 2d :" << std::endl;
00130 
00131     {
00132       (std::cerr << "    on    int with border = 3 ... ").flush ();
00133       typedef int T;
00134       int border = 3;
00135       int rows = 4;
00136       int cols = 5;
00137       T ref[110] =
00138         {
00139            1,  1,  1, 11, 12, 13, 14, 15,  5,  5,  5,
00140            1,  1,  1,  6,  7,  8,  9, 10,  5,  5,  5,
00141            1,  1,  1,  1,  2,  3,  4,  5,  5,  5,  5,
00142            3,  2,  1,  1,  2,  3,  4,  5,  5,  4,  3,
00143            8,  7,  6,  6,  7,  8,  9, 10, 10,  9,  8,
00144           13, 12, 11, 11, 12, 13, 14, 15, 15, 14, 13,
00145           18, 17, 16, 16, 17, 18, 19, 20, 20, 19, 18,
00146           16, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20,
00147           16, 16, 16, 11, 12, 13, 14, 15, 20, 20, 20,
00148           16, 16, 16,  6,  7,  8,  9, 10, 20, 20, 20
00149         };
00150 
00151       chck2d(rows, cols, border, ref);
00152       std::cerr << "OK" << std::endl;
00153     }
00154 
00155     {
00156       (std::cerr << "    on int_u8 with border = 3 ... ").flush ();
00157       typedef value::int_u8 T;
00158       int border = 2;
00159       int rows = 4;
00160       int cols = 5;
00161       T ref[72] =
00162         {
00163            1,  1,  6,  7,  8,  9, 10,  5,  5,
00164            1,  1,  1,  2,  3,  4,  5,  5,  5,
00165            2,  1,  1,  2,  3,  4,  5,  5,  4,
00166            7,  6,  6,  7,  8,  9, 10, 10,  9,
00167           12, 11, 11, 12, 13, 14, 15, 15, 14,
00168           17, 16, 16, 17, 18, 19, 20, 20, 19,
00169           16, 16, 16, 17, 18, 19, 20, 20, 20,
00170           16, 16, 11, 12, 13, 14, 15, 20, 20
00171         };
00172 
00173       chck2d(rows, cols, border, ref);
00174       std::cerr << "OK" << std::endl;
00175     }
00176 
00177     {
00178       (std::cerr << "    on int_s8 with border = 1 ... ").flush ();
00179       typedef value::int_s8 T;
00180       int border = 1;
00181       int rows = 4;
00182       int cols = 5;
00183       T ref[49] =
00184         {
00185            1,  1,  2,  3,  4,  5,  5,
00186            1,  1,  2,  3,  4,  5,  5,
00187            6,  6,  7,  8,  9, 10, 10,
00188           11, 11, 12, 13, 14, 15, 15,
00189           16, 16, 17, 18, 19, 20, 20,
00190           16, 16, 17, 18, 19, 20, 20
00191         };
00192 
00193       chck2d(rows, cols, border, ref);
00194       std::cerr << "OK" << std::endl;
00195     }
00196 
00197     {
00198       (std::cerr << "    on    int with border = 0 ... ").flush ();
00199       typedef int T;
00200       int border = 0;
00201       int rows = 4;
00202       int cols = 5;
00203       T ref[20] =
00204         {
00205            1,  2,  3,  4,  5,
00206            6,  7,  8,  9,  10,
00207           11, 12, 13, 14, 15,
00208           16, 17, 18, 19, 20
00209         };
00210 
00211       chck2d(rows, cols, border, ref);
00212       std::cerr << "OK" << std::endl;
00213     }
00214 
00215   } 
00216 
00217 }