whitebox-LevelSpec.C

Go to the documentation of this file.
00001 /*!@file TestSuite/whitebox-LevelSpec.C Test the LevelSpec class */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003   //
00005 // by the University of Southern California (USC) and the iLab at USC.  //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Rob Peters <rjpeters@klab.caltech.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/TestSuite/whitebox-LevelSpec.C $
00035 // $Id: whitebox-LevelSpec.C 8630 2007-07-25 20:33:41Z rjpeters $
00036 //
00037 
00038 #include "Util/log.H"
00039 
00040 #include "Image/LevelSpec.H"
00041 #include "TestSuite/TestSuite.H"
00042 
00043 ///////////////////////////////////////////////////////////////////////
00044 //
00045 // Test functions
00046 //
00047 // note that these funny _xx_'s are just used as a hierarchical separator
00048 // (since double-underscore __ is not legal in C/C++ identifiers); the _xx_ is
00049 // expected to be replaced by something prettier, like "--", by the test
00050 // driver script.
00051 //
00052 ///////////////////////////////////////////////////////////////////////
00053 
00054 static void LevelSpec_xx_maxIndex_xx_1(TestSuite& suite)
00055 {
00056   uint sml = 4, delta_min = 3, delta_max = 4, level_min = 2, level_max = 4;
00057 
00058   LevelSpec spec(level_min, level_max, delta_min, delta_max, sml);
00059 
00060   REQUIRE_EQ(spec.maxIndex(), uint(6));
00061 }
00062 
00063 static void LevelSpec_xx_maxDepth_xx_1(TestSuite& suite)
00064 {
00065   uint sml = 4, delta_min = 3, delta_max = 4, level_min = 2, level_max = 4;
00066 
00067   LevelSpec spec(level_min, level_max, delta_min, delta_max, sml);
00068 
00069   REQUIRE_EQ(spec.maxDepth(), uint(9));
00070 }
00071 
00072 static void LevelSpec_xx_clevOK_xx_1(TestSuite& suite)
00073 {
00074   uint sml = 4, delta_min = 3, delta_max = 4, level_min = 2, level_max = 4;
00075 
00076   LevelSpec spec(level_min, level_max, delta_min, delta_max, sml);
00077 
00078   REQUIRE(!spec.clevOK(1));
00079   REQUIRE(spec.clevOK(2));
00080   REQUIRE(spec.clevOK(3));
00081   REQUIRE(spec.clevOK(4));
00082   REQUIRE(!spec.clevOK(5));
00083 }
00084 
00085 static void LevelSpec_xx_slevOK_xx_1(TestSuite& suite)
00086 {
00087   uint sml = 4, delta_min = 3, delta_max = 4, level_min = 2, level_max = 4;
00088 
00089   LevelSpec spec(level_min, level_max, delta_min, delta_max, sml);
00090 
00091   REQUIRE(!spec.slevOK(4));
00092   REQUIRE(spec.slevOK(5));
00093   REQUIRE(spec.slevOK(6));
00094   REQUIRE(spec.slevOK(7));
00095   REQUIRE(spec.slevOK(8));
00096   REQUIRE(!spec.slevOK(9));
00097 }
00098 
00099 static void LevelSpec_xx_delOK_xx_1(TestSuite& suite)
00100 {
00101   uint sml = 4, delta_min = 3, delta_max = 4, level_min = 2, level_max = 4;
00102 
00103   LevelSpec spec(level_min, level_max, delta_min, delta_max, sml);
00104 
00105   REQUIRE(!spec.delOK(2));
00106   REQUIRE(spec.delOK(3));
00107   REQUIRE(spec.delOK(4));
00108   REQUIRE(!spec.delOK(5));
00109 }
00110 
00111 static void LevelSpec_xx_csOK_xx_1(TestSuite& suite)
00112 {
00113   uint sml = 4, delta_min = 3, delta_max = 4, level_min = 2, level_max = 4;
00114 
00115   LevelSpec spec(level_min, level_max, delta_min, delta_max, sml);
00116 
00117   const bool n = false;
00118   const bool YY = true;
00119   bool expect_csok[10][10] =
00120     {
00121       //  (surround level)
00122       //   0  1  2  3  4  5  6  7  8  9
00123           {n, n, n, n, n, n, n, n, n, n}, // 0 (center level)
00124           {n, n, n, n, n, n, n, n, n, n}, // 1
00125           {n, n, n, n, n, YY,YY,n, n, n}, // 2
00126           {n, n, n, n, n, n, YY,YY,n, n}, // 3
00127           {n, n, n, n, n, n, n, YY,YY,n}, // 4
00128           {n, n, n, n, n, n, n, n, n, n}, // 5
00129           {n, n, n, n, n, n, n, n, n, n}, // 6
00130           {n, n, n, n, n, n, n, n, n, n}, // 7
00131           {n, n, n, n, n, n, n, n, n, n}, // 8
00132           {n, n, n, n, n, n, n, n, n, n}, // 9
00133     };
00134 
00135   for (uint c = 0; c < 10; ++c)
00136     for (uint s = 0; s < 10; ++s)
00137       REQUIRE_EQ(spec.csOK(c, s), expect_csok[c][s]);
00138 }
00139 
00140 static void LevelSpec_xx_convert_xx_1(TestSuite& suite)
00141 {
00142   uint sml = 4, delta_min = 3, delta_max = 4, level_min = 2, level_max = 4;
00143 
00144   LevelSpec spec(level_min, level_max, delta_min, delta_max, sml);
00145 
00146   struct CSI { uint center; uint surround; uint index; };
00147 
00148   CSI expect_csi[6] =
00149     {
00150       { 2, 5, 0 },
00151       { 3, 6, 1 },
00152       { 4, 7, 2 },
00153       { 2, 6, 3 },
00154       { 3, 7, 4 },
00155       { 4, 8, 5 },
00156     };
00157 
00158   for (uint i = 0; i < 6; ++i)
00159     {
00160       REQUIRE_EQ(spec.csToIndex(expect_csi[i].center,
00161                                 expect_csi[i].surround),
00162                  expect_csi[i].index);
00163 
00164       uint c = 0, s = 0;
00165       spec.indexToCS(expect_csi[i].index, c, s);
00166       REQUIRE_EQ(c, expect_csi[i].center);
00167       REQUIRE_EQ(s, expect_csi[i].surround);
00168     }
00169 }
00170 
00171 ///////////////////////////////////////////////////////////////////////
00172 //
00173 // main
00174 //
00175 ///////////////////////////////////////////////////////////////////////
00176 
00177 int main(int argc, const char** argv)
00178 {
00179   TestSuite suite;
00180 
00181   suite.ADD_TEST(LevelSpec_xx_maxIndex_xx_1);
00182   suite.ADD_TEST(LevelSpec_xx_maxDepth_xx_1);
00183   suite.ADD_TEST(LevelSpec_xx_clevOK_xx_1);
00184   suite.ADD_TEST(LevelSpec_xx_slevOK_xx_1);
00185   suite.ADD_TEST(LevelSpec_xx_delOK_xx_1);
00186   suite.ADD_TEST(LevelSpec_xx_csOK_xx_1);
00187   suite.ADD_TEST(LevelSpec_xx_convert_xx_1);
00188 
00189   suite.parseAndRun(argc, argv);
00190 
00191   return 0;
00192 }
00193 
00194 // ######################################################################
00195 /* So things look consistent in everyone's emacs... */
00196 /* Local Variables: */
00197 /* indent-tabs-mode: nil */
00198 /* End: */
Generated on Sun May 8 08:42:23 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3