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

phImageReadTest.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 <phImageReadTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int glbl_disable_displays = 0;
00017 
00018 /* ------------------------------------------------------------------------ */
00019 int usage()
00020 {
00021     printf("\n\n Usage:\n");
00022     printf("\t--help                 Display this usage message.\n\n");
00023     printf("\t-f | --file <filename> Filename of the image (.ppm or .jpg/.jpeg\n");
00024     printf("\t--nodisplay            Disable the allocation, opening or any use of a display.\n\n");
00025     printf("\t--test <value>         Sleep <value> milliseconds before closing (valid values > 0)\n");
00026     printf("\n\n");
00027     exit(1);
00028 }
00029 
00030 /* ------------------------------------------------------------------------ */
00031 int main(int argc, char *argv[] )
00032 {
00033     phFUNCTION("main")
00034 
00035     phImage             *image      = new phImage();
00036 
00037     uint32_t            width       = 0;
00038     uint32_t            height      = 0;
00039 
00040     int                 displaysOpen= 1;
00041     
00042     char                *filename   = NULL;
00043 
00044     phDisplayInterface  *display    = NULL;
00045     
00046     /* Utility class to ease the starting and stopping of displays, captures and
00047      * pipelines */
00048     phSystem        *system = new phSystem();
00049    
00050     /* Remove the code below when using this code as an example.
00051      * 
00052      * This just checks whether "--test" has been specified with
00053      * a time value argument. It's for testing all the examples
00054      * without the need for human intervention. */
00055     int             test = 0;
00056 
00057     phArgTable      *arg_parser = new phArgTable();
00058 
00059     /* Setup and parse all the arguments */
00060     rc = arg_parser->add("--test",&test,phARG_INT);
00061     phCHECK_RC(rc,NULL,"arg_parser->add");
00062     rc = arg_parser->add("--file",&filename,phARG_CHAR);
00063     phCHECK_RC(rc,NULL,"arg_parser->add");
00064     rc = arg_parser->add("-f",&filename,phARG_CHAR);
00065     phCHECK_RC(rc,NULL,"arg_parser->add");
00066     rc = arg_parser->add("--nodisplay",(void *)&glbl_disable_displays,phARG_BOOL);
00067     phCHECK_RC(rc,NULL,"arg_parser->add");
00068     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00069     phCHECK_RC(rc,NULL,"arg_parser->add");
00070     
00071     rc = arg_parser->parse(argc,argv);
00072     phCHECK_RC(rc,NULL,"arg_parser->parse");
00073 
00074     if (filename == NULL)
00075     {
00076         phPRINT("File name not given. Use -f / --file option. Use --help for more info.\n");
00077         goto error;
00078     }
00079     phPROGRESS("Opening file %s\n",filename);
00080     rc = image->load(filename);
00081     phCHECK_RC(rc,NULL,"image->load(%s) failed.",filename);
00082 
00083     width = image->getWidth();
00084     height= image->getHeight();
00085 
00086     if (glbl_disable_displays == 0)
00087     {
00088     #if defined(WIN32)
00089         display = new GDIDisplay(width,height,"phImageReadTest");
00090     #else
00091         display = new X11Display(width,height,"phImageReadTest");
00092     #endif
00093         
00094         /* Link the image to the display. Loading a new image
00095          * will generate a live source signal */
00096         rc = display->setInput(image);
00097         phCHECK_RC(rc,NULL,"display->setInput(%p)",image);
00098         
00099         rc = system->addDisplay(display);
00100         phPRINT_RC(rc,NULL,"system->addDisplay(display)");
00101     }
00102 
00103     /* startup */
00104     rc = system->startup();
00105     phPRINT_RC(rc,NULL,"system->startup()");
00106 
00107     while (displaysOpen)
00108     {
00109         /* phMSleep(100); */
00110         
00111         /* Yielding is optional. This gives up the thread's timeslice
00112          * to prevent slow response in other threads. It consumes more
00113          * CPU cycles than sleeping. Use it instead of sleeping if
00114          * this loop is processing anything */
00115         
00116         /* phYield(); */
00117         
00118         if (glbl_disable_displays == 0)
00119         {
00120             displaysOpen = 0;
00121             if (display->isOpen())
00122             {
00123                 displaysOpen = 1;
00124             }
00125         }
00126         else
00127         {
00128             displaysOpen = 0;
00129         }
00130         
00131         /* Remove this if block when using this code as an example */
00132         /* Set the loop control value to end the loop when testing */
00133         if (test > 0)
00134         { 
00135             phMSleep(test);
00136             displaysOpen = 0;
00137         }
00138         else
00139         {
00140             /* Sleep a while, don't loop tightly */
00141             phMSleep(500);
00142         }
00143     }
00144 
00145     /* no phCHECK_RCs after this 'error' label */
00146 error:
00147     rc = system->shutdown();
00148     phPRINT_RC(rc,NULL,"system->shutdown()");
00149 
00150     phDelete(display);
00151     phDelete(arg_parser);
00152     phDelete(image);
00153     phDelete(system);
00154 
00155     phFree(filename);
00156     
00157     return phSUCCESS;
00158 }




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:06 2007 for phission by  doxygen 1.4.4