Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

mainTalk.cpp

Go to the documentation of this file.
00001 #include <iomanip>
00002 #include "Core/Array/Arrays.h"
00003 
00004 #include "Core/Array/Pattern/PatNgbOp2dExtra2.h"
00005 #include "Core/Array/Pattern/PatNgbOp2dExtra.h"
00006 #include "Core/Array/Pattern/PatNgbOp2d.h"
00007 #include "Core/Array/Pattern/PatRecGenConv2d.h"
00008 #include "Core/Array/Pattern/PatGenConv2d.h"
00009 #include "Core/Array/Pattern/PatRecGenConv2dSep.h"
00010 #include "Core/Array/Pattern/PatGenConv2dSep.h"
00011 #include "Core/Array/Pattern/PatBinaryPixOp.h"
00012 #include "Core/Array/PrintData.h"
00013 #include "Core/Array/MakeFromData.h"
00014 #include "Core/Array/Set.h"
00015 #include "Core/Array/Trait/TalkBpo.h"
00016 #include "Core/Array/Trait/TalkBpoAssign.h"
00017 #include "Core/Array/Trait/TalkNgbP1Cnum.h"
00018 #include "Core/Array/Trait/TalkNgbP1Loop.h"
00019 #include "Core/Array/Trait/TalkNgbP2Loop.h"
00020 #include "Core/Array/Trait/TalkNgbPnLoop.h"
00021 #include "Core/Array/Trait/TalkNgbExtraP1Cnum.h"
00022 #include "Core/Array/Trait/TalkNgbExtraP1Loop.h"
00023 #include "Core/Array/Trait/TalkNgbExtraP2Loop.h"
00024 #include "Core/Array/Trait/TalkNgbExtraPnLoop.h"
00025 #include "Core/Array/Trait/TalkNgbExtra2P1Cnum.h"
00026 #include "Core/Array/Trait/TalkNgbExtra2P1Loop.h"
00027 #include "Core/Array/Trait/TalkNgbExtra2P2Loop.h"
00028 #include "Core/Array/Trait/TalkNgbExtra2PnLoop.h"
00029 
00030 #include "Basis/CmdOptions.h"
00031 
00032 namespace Impala
00033 {
00034 namespace Samples
00035 {
00036 namespace Talk
00037 {
00038 
00039 
00040 using namespace Impala::Core::Array;
00041 using namespace Impala::Core::Array::Trait;
00042 using namespace Impala::Core::Array::Pattern;
00043 
00044 static bool gVerbose;
00045 static bool gUniform;
00046 static bool gSmall;
00047 static bool gLarge;
00048 static int  gVType;
00049 static int  gWidth;
00050 static int  gHeight;
00051 
00052 void
00053 UpdateSizeArgument()
00054 {
00055     if (gSmall)
00056     {
00057         gWidth = 4;
00058         gHeight = 3;
00059     }
00060     else
00061     {
00062         if (gLarge)
00063         {
00064             gWidth = 13;
00065             gHeight = 9;
00066         }
00067         else
00068         {
00069             gWidth = 9;
00070             gHeight = 7;
00071         }
00072     }
00073 }
00074 
00075 double*
00076 TalkUniqueImage(int width, int height, double start, double inc)
00077 {
00078     int nPix = width * height;
00079     double* data = new double[nPix];
00080     for (int i=0 ; i<nPix ; i++)
00081     {
00082         data[i] = start;
00083         start += inc;
00084     }
00085     return data;
00086 }
00087 
00088 template<class ArrayT>
00089 ArrayT*
00090 TalkImage(std::string comment, double start, double inc, int bw, int bh)
00091 {
00092     double* ptr = TalkUniqueImage(gWidth, gHeight, start, inc);
00093     Array2dScalarReal64* aDouble =
00094         MakeFromData<Array2dScalarReal64>(ptr, gWidth, gHeight, bw, bh);
00095     ArrayT* res = 0;
00096     Set(res, aDouble);
00097     std::cout << comment << std::endl;
00098     PrintData(res, false);
00099     delete ptr;
00100     return res;
00101 }
00102 
00103 template<class ArrayT>
00104 ArrayT*
00105 TalkKernel(std::string comment, int dims, int dir = 1)
00106 {
00107     int width;
00108     int height;
00109     double val;
00110     if (dims == 1)
00111     {
00112         if (dir == 1)
00113         {
00114             width = 5;
00115             height = 1;
00116             val = 1.0 / 5;
00117         }
00118         else
00119         {
00120             width = 3;
00121             height = 1;
00122             val = 1.0 / 3;
00123         }
00124     }
00125     if (dims == 2)
00126     {
00127         width = 5;
00128         height = 3;
00129         val = 1.0 / (5*3);
00130     }
00131     ArrayT* ker = 0;
00132     double* kerData;
00133     if (gUniform)
00134     {
00135         int nPix = width * height;
00136         kerData = new double[nPix];
00137         for (int i=0 ; i<nPix ; i++)
00138             kerData[i] = val;
00139     }
00140     else
00141     {
00142         kerData = TalkUniqueImage(width, height, 1.1, 1.1);
00143     }
00144     Array2dScalarReal64* kerDouble =
00145         MakeFromData<Array2dScalarReal64>(kerData, width, height, 0, 0);
00146     Set(ker, kerDouble);
00147     std::cout << std::endl << comment << std::endl;
00148     PrintData(ker, false);
00149     delete kerData;
00150     return ker;
00151 }
00152 
00153 /************************************************************************/
00155 /************************************************************************/
00156 
00157 void
00158 DoTalkBpo2d()
00159 {
00160     std::cout << std::endl << std::endl << std::endl;
00161     std::cout << "=============== DoTalkBpo2d =================" << std::endl;
00162 
00163     typedef Array2dScalarReal64 SRC1T;
00164     typedef Array2dScalarReal64 SRC2T;
00165     typedef Array2dScalarReal64 REST;
00166 
00167     SRC1T* a1 = TalkImage<SRC1T>("Input image 1:", 0, 1.1, 2, 1);
00168     SRC2T* a2 = TalkImage<SRC2T>("Input image 2:", 101, 1.1, 1, 2);
00169 
00170     REST* res = 0;
00171     //TalkBpoPtrE1<REST, SRC1T, SRC2T> bpo(gVerbose, false);
00172     TalkBpoPtrEn<REST, SRC1T, SRC2T> bpo(gVerbose, false);
00173     PatBinaryPixOp(res, a1, a2, bpo);
00174     std::cout << std::endl << "result: " << std::endl;
00175     PrintData(res, false);
00176 
00177     //REST* res2 = 0;
00178     //TalkBpoVal<REST, SRC1T, SRC2T> bpo2(gVerbose, false);
00179     //PatBinaryPixOp(res2, a1, a2, bpo2);
00180     //std::cout << std::endl << "result val: " << std::endl;
00181     //PrintData(res2, false);
00182 
00183     //Array2dVec3Real64* res3 = 0;
00184     //Set(res3, a1);
00185     //std::cout << std::endl << "result3: " << std::endl;
00186     //PrintData(res3, false);
00187 
00188     //Array2dScalarReal64* a3 = 0;
00189     //Set(a3, res3);
00190     //std::cout << std::endl << "a3: " << std::endl;
00191     //PrintData(a3, false);
00192 }
00193 
00194 void
00195 DoTalkGenConv2d()
00196 {
00197     std::cout << std::endl << std::endl << std::endl;
00198     std::cout << "============== DoTalkGenConv2d =============" << std::endl;
00199 
00200     //typedef Array2dScalarInt32 SRCT;
00201     typedef Array2dScalarReal64 SRCT;
00202     //typedef Array2dVec3Real64 SRCT;
00203     typedef Array2dScalarReal64 KERT;
00204     //typedef Array2dVec3Real64 KERT;
00205     typedef Array2dScalarReal64 REST;
00206     //typedef Array2dVec3Real64 REST;
00207 
00208     SRCT* im = TalkImage<SRCT>("Input image: ", 0, 1, 3, 3);
00209 
00210     KERT* ker = TalkKernel<KERT>("kernel: ", 2);
00211 
00212     REST* res = 0;
00213     TalkBpoVal<KERT, KERT, KERT> bpo(gVerbose, false);
00214     TalkBpoAssignVal<KERT, KERT> bpoAss(gVerbose, false, 1000000);
00215     PatGenConv2d(res, im, ker, bpo, bpoAss);
00216 
00217     std::cout << std::endl << "result: " << std::endl;
00218     PrintData(res, false);
00219 }
00220 
00221 void
00222 DoTalkGenConv2dSep()
00223 {
00224     std::cout << std::endl << std::endl << std::endl;
00225     std::cout << "============== DoTalkGenConv2dSep =============" << std::endl;
00226 
00227     //typedef Array2dScalarInt32 SRCT;
00228     typedef Array2dScalarReal64 SRCT;
00229     //typedef Array2dVec3Real64 SRCT;
00230     typedef Array2dScalarReal64 KERT;
00231     //typedef Array2dVec3Real64 KERT;
00232     typedef Array2dScalarReal64 REST;
00233     //typedef Array2dVec3Real64 REST;
00234 
00235     SRCT* im = TalkImage<SRCT>("Input image: ", 0, 1, 3, 3);
00236 
00237     KERT* ker2 = TalkKernel<KERT>("k1d_3 image: ", 1, 2);
00238     KERT* ker1 = TalkKernel<KERT>("k1d_5 image: ", 1, 1);
00239 
00240     //REST* res = 0;
00241     //TalkBpoPtrE1<KERT, KERT, KERT> bpo(gVerbose, false);
00242     //TalkBpoAssignPtrE1<KERT, KERT> bpoAss(gVerbose, false, 1000000);
00243     //PatGenConv2dSep(res, im, ker1, ker2, bpo, bpoAss, gVType, 0);
00244     //std::cout << std::endl << "result: " << std::endl;
00245     //PrintData(res, false);
00246 
00247     //REST* res2 = 0;
00248     //TalkBpoPtrEn<KERT, KERT, KERT> bpo2(gVerbose, false);
00249     //TalkBpoAssignPtrEn<KERT, KERT> bpoAss2(gVerbose, false, 1000000);
00250     //PatGenConv2dSep(res2, im, ker1, ker2, bpo2, bpoAss2, gVType, 0);
00251     //std::cout << std::endl << "result: " << std::endl;
00252     //PrintData(res2, false);
00253 
00254     REST* res3 = 0;
00255     TalkBpoVal<KERT, KERT, KERT> bpo3(gVerbose, false);
00256     TalkBpoAssignVal<KERT, KERT> bpoAss3(gVerbose, false, 1000000);
00257     PatGenConv2dSep(res3, im, ker1, ker2, bpo3, bpoAss3, gVType, 0);
00258     std::cout << std::endl << "result: " << std::endl;
00259     PrintData(res3, false);
00260 }
00261 
00262 void
00263 DoTalkRecGenConv2d()
00264 {
00265     std::cout << std::endl << std::endl << std::endl;
00266     std::cout << "============== DoTalkRecGenConv2d =============" << std::endl;
00267 
00268     //typedef Array2dScalarInt32 SRCT;
00269     typedef Array2dScalarReal64 SRCT;
00270     //typedef Array2dVec3Real64 SRCT;
00271     typedef Array2dScalarReal64 KERT;
00272     //typedef Array2dVec3Real64 KERT;
00273     typedef Array2dScalarReal64 REST;
00274     //typedef Array2dVec3Real64 REST;
00275 
00276     SRCT* im = TalkImage<SRCT>("Input image: ", 0, 1, 3, 3);
00277 
00278     KERT* ker = TalkKernel<KERT>("kernel: ", 2);
00279 
00280     REST* res = 0;
00281     TalkBpoVal<KERT, KERT, KERT> bpo(gVerbose, true);
00282     TalkBpoAssignVal<KERT, KERT> bpoAss(gVerbose, false, 1000000);
00283     PatRecGenConv2d(res, im, ker, bpo, bpoAss);
00284 
00285     std::cout << std::endl << "result: " << std::endl;
00286     PrintData(res, false);
00287 }
00288 
00289 void
00290 DoTalkRecGenConv2dSep()
00291 {
00292     std::cout << std::endl << std::endl << std::endl;
00293     std::cout << "============== DoTalkRecGenConv2dSep =============" << std::endl;
00294 
00295     //typedef Array2dScalarInt32 SRCT;
00296     typedef Array2dScalarReal64 SRCT;
00297     //typedef Array2dVec3Real64 SRCT;
00298     typedef Array2dScalarReal64 KERT;
00299     //typedef Array2dVec3Real64 KERT;
00300     typedef Array2dScalarReal64 REST;
00301     //typedef Array2dVec3Real64 REST;
00302 
00303     SRCT* im = TalkImage<SRCT>("Input image: ", 0, 1, 5, 5);
00304 
00305     KERT* ker2 = TalkKernel<KERT>("k1d_3 image: ", 1, 2);
00306     KERT* ker1 = TalkKernel<KERT>("k1d_5 image: ", 1, 1);
00307 
00308     REST* res = 0;
00309     TalkBpoVal<KERT, KERT, KERT> bpo(gVerbose, true);
00310     TalkBpoAssignVal<KERT, KERT> bpoAss(gVerbose, false, 1000000);
00311     typedef KERT::ArithType KerArithT;
00312     KerArithT normFactor = Element::E1Cast(1, KerArithT());
00313     PatRecGenConv2dSep(res, im, ker1, ker2,
00314                          normFactor, normFactor, normFactor, normFactor,
00315                          bpo, bpoAss, 0);
00316 
00317     std::cout << std::endl << "result: " << std::endl;
00318     PrintData(res, false);
00319 }
00320 
00321 
00322 void
00323 DoTalkNgb2d()
00324 {
00325     std::cout << std::endl << std::endl << std::endl;
00326     std::cout << "=============== DoTalkNgb2d =================" << std::endl;
00327 
00328     typedef Array2dScalarInt32 SRCT;
00329     //typedef Array2dScalarReal64 SRCT;
00330     typedef Array2dScalarReal64 REST;
00331 
00332     SRCT* im = TalkImage<SRCT>("Input image:", 0, 1, 2, 1);
00333 
00334     REST* res = 0;
00335     TalkNgbP1Cnum<REST,SRCT> p1cnum(gVerbose);
00336     PatNgbOp2d(res, im, p1cnum);
00337     std::cout << std::endl << "result P1Cnum: " << std::endl;
00338     PrintData(res, false);
00339 
00340 
00341     TalkNgbP1Loop<REST,SRCT> p1loop(gVerbose, 5, 3);
00342     PatNgbOp2d(res, im, p1loop);
00343     std::cout << std::endl << "result P1Loop: " << std::endl;
00344     PrintData(res, false);
00345 
00346     TalkNgbP2Loop<REST,SRCT> p2loop(gVerbose, 5, 3);
00347     PatNgbOp2d(res, im, p2loop);
00348     std::cout << std::endl << "result P2Loop: " << std::endl;
00349     PrintData(res, false);
00350 
00351     TalkNgbPnLoop<REST,SRCT> pnloop(gVerbose, 5, 3);
00352     PatNgbOp2d(res, im, pnloop);
00353     std::cout << std::endl << "result PnLoop: " << std::endl;
00354     PrintData(res, false);
00355 }
00356 
00357 
00358 void
00359 DoTalkNgb2dExtra()
00360 {
00361     std::cout << std::endl << std::endl << std::endl;
00362     std::cout << "=============== DoTalkNgb2dExtra =================" << std::endl;
00363 
00364     typedef Array2dScalarInt32 SRCT;
00365     //typedef Array2dScalarReal64 SRCT;
00366     typedef Array2dScalarInt32 EXTRAT;
00367     typedef Array2dVec3Real64 REST;
00368 
00369     SRCT* im = TalkImage<SRCT>("Input image:", 0, 1, 2, 1);
00370     EXTRAT* extra = TalkImage<EXTRAT>("Extra image:", 100, 1, 2, 1);
00371 
00372     REST* res = 0;
00373     TalkNgbExtraP1Cnum<REST,SRCT,EXTRAT> p1cnum(gVerbose);
00374     PatNgbOp2dExtra(res, im, extra, p1cnum);
00375     std::cout << std::endl << "result P1Cnum: " << std::endl;
00376     PrintData(res, false);
00377 
00378     TalkNgbExtraP1Loop<REST,SRCT,EXTRAT> p1loop(gVerbose, 5, 3);
00379     PatNgbOp2dExtra(res, im, extra, p1loop);
00380     std::cout << std::endl << "result P1Loop: " << std::endl;
00381     PrintData(res, false);
00382 
00383     TalkNgbExtraP2Loop<REST,SRCT,EXTRAT> p2loop(gVerbose, 5, 3);
00384     PatNgbOp2dExtra(res, im, extra, p2loop);
00385     std::cout << std::endl << "result P2Loop: " << std::endl;
00386     PrintData(res, false);
00387 
00388     TalkNgbExtraPnLoop<REST,SRCT,EXTRAT> pnloop(gVerbose, 5, 3);
00389     PatNgbOp2dExtra(res, im, extra, pnloop);
00390     std::cout << std::endl << "result PnLoop: " << std::endl;
00391     PrintData(res, false);
00392 }
00393 
00394 
00395 void
00396 DoTalkNgb2dExtra2()
00397 {
00398     std::cout << std::endl << std::endl << std::endl;
00399     std::cout << "=============== DoTalkNgb2dExtra2 =================" << std::endl;
00400 
00401     typedef Array2dScalarInt32 SRCT;
00402     //typedef Array2dScalarReal64 SRCT;
00403     typedef Array2dScalarInt32 EXTRAT;
00404     typedef Array2dScalarInt32 EXTRA2T;
00405     typedef Array2dVec3Real64 REST;
00406 
00407     SRCT* im = TalkImage<SRCT>("Input image:", 0, 1, 2, 1);
00408     EXTRAT* extra = TalkImage<EXTRAT>("Extra image:", 100, 1, 2, 1);
00409     EXTRA2T* extra2 = TalkImage<EXTRA2T>("Extra2 image:", 1000, 1, 2, 1);
00410 
00411     REST* res = 0;
00412     TalkNgbExtra2P1Cnum<REST,SRCT,EXTRAT,EXTRA2T> p1cnum(gVerbose);
00413     PatNgbOp2dExtra2(res, im, extra, extra2, p1cnum);
00414     std::cout << std::endl << "result P1Cnum: " << std::endl;
00415     PrintData(res, false);
00416 
00417     TalkNgbExtra2P1Loop<REST,SRCT,EXTRAT,EXTRA2T> p1loop(gVerbose, 5, 3);
00418     PatNgbOp2dExtra2(res, im, extra, extra2, p1loop);
00419     std::cout << std::endl << "result P1Loop: " << std::endl;
00420     PrintData(res, false);
00421 
00422     TalkNgbExtra2P2Loop<REST,SRCT,EXTRAT,EXTRA2T> p2loop(gVerbose, 5, 3);
00423     PatNgbOp2dExtra2(res, im, extra, extra2, p2loop);
00424     std::cout << std::endl << "result P2Loop: " << std::endl;
00425     PrintData(res, false);
00426 
00427     TalkNgbExtra2PnLoop<REST,SRCT,EXTRAT,EXTRA2T> pnloop(gVerbose, 5, 3);
00428     PatNgbOp2dExtra2(res, im, extra, extra2, pnloop);
00429     std::cout << std::endl << "result PnLoop: " << std::endl;
00430     PrintData(res, false);
00431 }
00432 
00433 /************************************************************************/
00435 /************************************************************************/
00436 
00437 int
00438 mainTalk(int argc, char* argv[])
00439 {
00440     CmdOptions& options = CmdOptions::GetInstance();
00441     options.Initialise(false);
00442     options.AddOption(0, "verb", "", "0");
00443     options.AddOption(0, "unif", "", "0");
00444     options.AddOption(0, "small", "", "0");
00445     options.AddOption(0, "large", "", "0");
00446     options.AddOption(0, "log", "", "0");
00447     options.AddOption(0, "vType", "number", "6");
00448     if (! options.ParseArgs(argc, argv, "testName", 1))
00449         return 1;
00450 
00451     gVerbose = options.GetBool("verb");
00452     gUniform = options.GetBool("unif");
00453     gSmall = options.GetBool("small");
00454     gLarge = options.GetBool("large");
00455     gVType = options.GetInt("vType");
00456     bool log = options.GetBool("log");
00457     std::string tt = options.GetArg(0);
00458 
00459     std::cout << std::setprecision(10);
00460     UpdateSizeArgument();
00461 
00462     if (tt == "bpo2d")
00463         DoTalkBpo2d();
00464     if (tt == "genconv2d")
00465         DoTalkGenConv2d();
00466     if (tt == "genconv2dsep")
00467         DoTalkGenConv2dSep();
00468     if (tt == "recgenconv2d")
00469         DoTalkRecGenConv2d();
00470     if (tt == "recgenconv2dsep")
00471         DoTalkRecGenConv2dSep();
00472 
00473     if (tt == "ngb2d")
00474         DoTalkNgb2d();
00475     if (tt == "ngb2dextra")
00476         DoTalkNgb2dExtra();
00477     if (tt == "ngb2dextra2")
00478         DoTalkNgb2dExtra2();
00479 
00480     return 0;
00481 }
00482 
00483 } // namespace Talk
00484 } // namespace Samples
00485 } // namespace Impala
00486 
00487 int
00488 main(int argc, char* argv[])
00489 {
00490     return Impala::Samples::Talk::mainTalk(argc, argv);
00491 }

Generated on Fri Mar 19 09:30:40 2010 for ImpalaSrc by  doxygen 1.5.1