Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GDIImageTest.cpp

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission : 
00003         Realtime Vision Processing System
00004     
00005     Copyright (C) 2003 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008     
00009     This file is part of Phission.
00010 
00011  ---------------------------------------------------------------------------*/
00012 #include <GDIImageTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int usage()
00017 {
00018     printf("\n\nUsage:\n");
00019     printf("\t--help            Display usage\n");
00020     printf("\t--test <value>    Loop <value> times and then close test\n");
00021     printf("\n\n");
00022 
00023     exit(1);
00024 }
00025 
00026 int     glbl_use_images = 1;
00027 int     glbl_users_supplied_image = 0;
00028 
00029 /* ------------------------------------------------------------------------ */
00030 int main(int argc, char *argv[] )
00031 {
00032     phFUNCTION("main")
00033     uint32_t    i           = 0;
00034 
00035     /* Note: If you use loaded_image for anything when glbl_use_images or 
00036              glbl_users_supplied_image is set, the image will be signalled and 
00037              copied to the pipeline and any listening class. */
00038     phImage             loaded_image;
00039     unsigned int        j           = 0;
00040     unsigned int        image_count = 2;
00041     phImage             *fileImages = NULL;
00042     char                filename[255];
00043     char                *userfilename = NULL;
00044     
00045     uint32_t    nDisplays = 1;
00046     int         displaysOpen= 1;
00047     int         trycount = 1;
00048     int         tries = 4;
00049     /* Utility class to ease the starting and stopping of displays, captures and
00050      * pipelines */
00051     phSystem    system;
00052     
00053     GDIDisplay  display(320,240,"GDIImageTest");
00054    
00055     /* Remove the code below when using this code as an example.
00056      * 
00057      * This just checks whether "--test" has been specified with
00058      * a time value argument. It's for testing all the examples
00059      * without the need for human intervention. */
00060     int             test = 0;
00061 
00062     phArgTable      *arg_parser = new phArgTable();
00063 
00064     /* Setup and parse all the arguments */
00065     rc = arg_parser->add("--test",&test,phARG_INT);
00066     phCHECK_RC(rc,NULL,"arg_parser->add");
00067     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00068     phCHECK_RC(rc,NULL,"arg_parser->add");
00069     rc = arg_parser->add("--file",&userfilename,phARG_CHAR);
00070     phCHECK_RC(rc,NULL,"arg_parser->add");
00071     
00072     rc = arg_parser->parse(argc,argv);
00073     phCHECK_RC(rc,NULL,"arg_parser->parse");
00074     
00075     if (userfilename != NULL)
00076     {
00077         glbl_users_supplied_image = 1;
00078     }
00079     
00080     if (image_count > 0)
00081     {
00082         fileImages = new phImage[image_count];
00083     }
00084     if (glbl_users_supplied_image == 1)
00085     {
00086          /* load the images */
00087          rc = fileImages[0].load(userfilename);
00088          phCHECK_RC(rc,NULL,"image loading failed");
00089 
00090          image_count = 1;
00091     }
00092     else if (glbl_use_images == 1)
00093     {
00094         /* load the images */
00095         for (i = 0; i < image_count; i++)
00096         {
00097             sprintf(filename,"../images/thisisatest_%u.ppm",
00098                     (unsigned int)i);
00099         
00100             rc = fileImages[i].load(filename);
00101             phCHECK_RC(rc,NULL,"image loading failed");
00102         }
00103     }
00104         
00105     if ((glbl_use_images == 1) || (glbl_users_supplied_image == 1))
00106     {
00107         display.setLiveSourceInput(&loaded_image);
00108     }
00109 
00110     rc = system.addDisplay(&display);
00111     phPRINT_RC(rc,NULL,"system.addDisplay(&display)");
00112     
00113 
00114     /* Display startup */
00115     rc = system.startup();
00116     phPRINT_RC(rc,NULL,"system.startup()");
00117    
00118     while (displaysOpen)
00119     {
00120 
00121         if ((glbl_use_images == 1) || (glbl_users_supplied_image == 1))
00122         {
00123             rc = loaded_image.setImage(fileImages[j]);
00124             phPRINT_RC(rc,NULL,"setImage failed");
00125             if (rc != 0) { displaysOpen = 0; continue; }
00126         
00127             j++;
00128             if (j >= image_count) j = 0;
00129         }
00130         
00131         /* Sleep a while, don't loop tightly */
00132         phMSleep(100);
00133         
00134         /* Yielding is optional. This gives up the thread's timeslice
00135          * to prevent slow response in other threads. It consumes more
00136          * CPU cycles than sleeping. Use it instead of sleeping if
00137          * this loop is processing anything */
00138         
00139         /* phYield(); */
00140         
00141         displaysOpen = 0;
00142         if (display.isOpen())
00143         {
00144             displaysOpen = 1;
00145         }
00146         
00147         if (nDisplays > 0)
00148         {
00149             displaysOpen = 0;
00150             for (i = 0; (i < nDisplays) && (displaysOpen == 0); i++)
00151             {
00152                 if (display.isOpen() == 1)
00153                 {
00154                     displaysOpen = 1;
00155                 }
00156             }
00157         }
00158         /* Remove this if block when using this code as an example */
00159         /* Set the loop control value to end the loop when testing */
00160         if (test > 0)
00161         { 
00162             test--;
00163             if (test == 0)
00164                 displaysOpen = 0;
00165         }
00166     }
00167 
00168     /* Display shutdown */
00169     rc = system.shutdown();
00170     phPRINT_RC(rc,NULL,"system.shutdown()");
00171 
00172 
00173 error:
00174     phFree(userfilename);
00175 
00176     phDelete(arg_parser);
00177 
00178     return phSUCCESS;
00179 }




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:05 2007 for phission by  doxygen 1.4.4