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

X11DisplayV4LSettingTest.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 <X11DisplayV4LSettingTest.h>
00013 #include <phission.h>
00014 
00015 #define testBRIGHTNESS 0
00016 #define testHUE 1
00017 #define testCOLOR 2
00018 #define testCONTRAST 3
00019 #define testWHITENESS 4
00020 #define testWIDTH 5
00021 #define testHEIGHT 6
00022 
00023 /* ------------------------------------------------------------------------ */
00024 int glbl_disable_displays = 0;
00025 
00026 /* ------------------------------------------------------------------------ */
00027 void usage()
00028 {
00029     printf("\n\nUsage:\n");
00030     printf("\t--help                Display usage\n");
00031     printf("\t--nodisplay           Disable the allocation, opening or any use of a display.\n");
00032     printf("\t--ndisplays <value>   Open nDisplays\n");
00033     printf("\t--test <value>        Perform <value> setting loops and then close test\n");
00034     printf("\n\n");
00035 
00036     exit(1);
00037 }
00038     
00039 /* ------------------------------------------------------------------------ */
00040 /* ------------------------------------------------------------------------ */
00041 int main(int argc, char *argv[] )
00042 {
00043     phFUNCTION("main")
00044 
00045     unsigned int    i           = 0;
00046 
00047     unsigned int        nDisplays   = 1;
00048     char                title[255];
00049     int                 displaysOpen= 1;
00050     phDisplayInterface  **display   = NULL;
00051     
00052     char        *capture_path   = NULL;
00053     int         channel         = 0;
00054         
00055 #ifdef WIN32
00056     VFWSource       *capture = new VFWSource();
00057 #else
00058     V4LCapture      *capture = new V4LCapture();
00059 #endif
00060         
00061     /* Utility class to ease the starting and stopping of displays, captures and
00062      * pipelines */
00063     phSystem        system;
00064 
00065     int setting_stage = 0;
00066     int setting_started = 0;
00067     int setting_step = 20;
00068     
00069     phArgTable      *arg_parser = new phArgTable();
00070    
00071     /* Remove the code below when using this code as an example.
00072      * 
00073      * This just checks whether "--test" has been specified with
00074      * a time value argument. It's for testing all the examples
00075      * without the need for human intervention. */
00076     int             test = 0;
00077 
00078     rc = arg_parser->add("--test",&test,phARG_INT);
00079     phCHECK_RC(rc,NULL,"arg_parser->add");
00080     
00081     rc = arg_parser->add("--ndisplays",&nDisplays,phARG_INT);
00082     phCHECK_RC(rc,NULL,"arg_parser->add");
00083     
00084     rc = arg_parser->add("--nodisplay",&glbl_disable_displays,phARG_BOOL);
00085     phCHECK_RC(rc,NULL,"arg_parser->add");
00086 
00087     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00088     phCHECK_RC(rc,NULL,"arg_parser->add");
00089     
00090     rc = arg_parser->add("--path",&capture_path,phARG_CHAR);
00091     phCHECK_RC(rc,NULL,"arg_parser->add");
00092 
00093     rc = arg_parser->add("--channel",&channel,phARG_INT);
00094     phCHECK_RC(rc,NULL,"arg_parser->add");
00095     
00096     rc = arg_parser->parse(argc,argv);
00097     phCHECK_RC(rc,NULL,"arg_parser->parse");
00098 
00099     if (glbl_disable_displays) nDisplays = 0;
00100 
00101     capture->set(320,240,capture_path);
00102     capture->setChannel(channel);
00103     capture->setBrightness(capture->getMaxBrightness() / 2);
00104     capture->setHue(capture->getMaxHue() / 2);
00105     capture->setColor(capture->getMaxColor() / 2);
00106     capture->setContrast(capture->getMaxContrast() / 2);
00107     capture->setWhiteness(capture->getMaxWhiteness() / 2);
00108     
00109     rc = system.addCapture(capture);
00110     phPRINT_RC(rc,NULL,"system.addCapture(capture)");
00111 
00112     display = new phDisplayInterface *[nDisplays];
00113     phCHECK_NULLPTR(display,"new","new phDisplayInterface *[nDisplays];");
00114 
00115     for (i = 0; i < nDisplays; i++)
00116     {
00117         sprintf(title,"X11DisplayV4LSettingTest[%u]",i);
00118         
00119         display[i] = new X11Display(320,240,title);
00120         
00121         /* Set all parameters for the display so when the phSystem
00122          * starts them up, they are the desired size*/
00123         display[i]->setLiveSourceInput(capture->getLiveSourceOutput());
00124         
00125         rc = system.addDisplay(display[i]);
00126         phPRINT_RC(rc,NULL,"system.addDisplay(display[i])");
00127     }
00128             
00129 
00130     /* startup */
00131     rc = system.startup();
00132     phPRINT_RC(rc,NULL,"system.startup()");
00133    
00134     displaysOpen = 1;
00135     while (displaysOpen)
00136     {
00137         /* Sleep a while, don't loop tightly */
00138         /* phMSleep(100); */
00139         phYield();
00140         switch (setting_stage)
00141         {
00142             /* ------------------------------------------------------------ */
00143             case testBRIGHTNESS:
00144                 /* Initialize the setting to it's lowest value */
00145                 if (setting_started == 0)
00146                 {
00147                     phPROGRESS("testBRIGHTNESS\n");
00148                     setting_started = 1;
00149                     capture->setBrightness(1);
00150                 }
00151                 /* When the value of the setting has reached it's upper
00152                  * limit, reset it to the middle and transition to the next */
00153                 if (capture->getBrightness() >= capture->getMaxBrightness())
00154                 {
00155                     capture->setBrightness(capture->getMaxBrightness() / 2);
00156                     setting_stage++;
00157                     setting_started = 0;
00158                 }
00159                 /* ... otherwise just increment the value but some amount */
00160                 else
00161                 {
00162                     capture->setBrightness(capture->getBrightness() + setting_step);
00163                 }
00164                 break;
00165             /* ------------------------------------------------------------ */
00166             case testHUE:
00167                 /* Initialize the setting to it's lowest value */
00168                 if (setting_started == 0)
00169                 {
00170                     phPROGRESS("testHUE\n");
00171                     capture->setHue(1);
00172                     setting_started = 1;
00173                 }
00174                 /* When the value of the setting has reached it's upper
00175                  * limit, reset it to the middle and transition to the next */
00176                 if (capture->getHue() >= capture->getMaxHue())
00177                 {
00178                     capture->setHue(capture->getMaxHue() / 2);
00179                     setting_stage++;
00180                     setting_started = 0;
00181                 }
00182                 /* ... otherwise just increment the value but some amount */
00183                 else
00184                 {
00185                     capture->setHue(capture->getHue() + setting_step);
00186                 }
00187                 break;
00188             /* ------------------------------------------------------------ */
00189             case testCOLOR:
00190                 /* Initialize the setting to it's lowest value */
00191                 if (setting_started == 0)
00192                 {
00193                     phPROGRESS("testCOLOR\n");
00194                     capture->setColor(1);
00195                     setting_started = 1;
00196                 }
00197                 /* When the value of the setting has reached it's upper
00198                  * limit, reset it to the middle and transition to the next */
00199                 if (capture->getColor() >= capture->getMaxColor())
00200                 {
00201                     capture->setColor(capture->getMaxColor() / 2);
00202                     setting_stage++;
00203                     setting_started = 0;
00204                 }
00205                 /* ... otherwise just increment the value but some amount */
00206                 else
00207                 {
00208                     capture->setColor(capture->getColor() + setting_step);
00209                 }
00210                 break;
00211             /* ------------------------------------------------------------ */
00212             case testCONTRAST:
00213                 if (setting_started == 0)
00214                 {
00215                     phPROGRESS("testCONTRAST\n");
00216                     capture->setContrast(1);
00217                     setting_started = 1;
00218                 }
00219                 /* When the value of the setting has reached it's upper
00220                  * limit, reset it to the middle and transition to the next */
00221                 if (capture->getContrast() >= capture->getMaxContrast())
00222                 {
00223                     capture->setContrast(capture->getMaxContrast() / 2);
00224                     setting_stage++;
00225                     setting_started = 0;
00226                 }
00227                 /* ... otherwise just increment the value but some amount */
00228                 else
00229                 {
00230                     capture->setContrast(capture->getContrast() + setting_step);
00231                 }
00232                 break;
00233             /* ------------------------------------------------------------ */
00234             case testWHITENESS:
00235                 /* Initialize the setting to it's lowest value */
00236                 if (setting_started == 0)
00237                 {
00238                     phPROGRESS("testWHITENESS\n");
00239                     capture->setWhiteness(1);
00240                     setting_started = 1;
00241                 }
00242                 /* When the value of the setting has reached it's upper
00243                  * limit, reset it to the middle and transition to the next */
00244                 if (capture->getWhiteness() >= capture->getMaxWhiteness())
00245                 {
00246                     capture->setWhiteness(capture->getMaxWhiteness() / 2);
00247                     setting_stage++;
00248                     setting_started = 0;
00249                 }
00250                 /* ... otherwise just increment the value but some amount */
00251                 else
00252                 {
00253                     capture->setWhiteness(capture->getWhiteness() + setting_step);
00254                 }
00255                 break;
00256             /* Can't do live testing of these just yet */
00257 #if 0
00258             /* ------------------------------------------------------------ */
00259             case testWIDTH:
00260                 /* Initialize the setting to it's lowest value */
00261                 if (setting_started == 0)
00262                 {
00263                     capture->setWidth(min_width);
00264                     setting_started = 1;
00265                 }
00266                 /* When the value of the setting has reached it's upper
00267                  * limit, reset it to the middle and transition to the next */
00268                 if (capture->getWidth() >= max_width)
00269                 {
00270                     capture->setWidth(default_width);
00271                     setting_stage++;
00272                     setting_started = 0;
00273                 }
00274                 /* ... otherwise just increment the value but some amount */
00275                 else
00276                 {
00277                     capture->setWidth(capture->getWidth() + 2);
00278                 }
00279                 break;
00280             /* ------------------------------------------------------------ */
00281             case testHEIGHT:
00282                 /* Initialize the setting to it's lowest value */
00283                 if (setting_started == 0)
00284                 {
00285                     capture->setHeight(min_height);
00286                     setting_started = 1;
00287                 }
00288                 /* When the value of the setting has reached it's upper
00289                  * limit, reset it to the middle and transition to the next */
00290                 if (capture->getHeight() >= max_height)
00291                 {
00292                     capture->setHeight(default_height);
00293                     setting_stage++;
00294                     setting_started = 0;
00295                 }
00296                 /* ... otherwise just increment the value but some amount */
00297                 else
00298                 {
00299                     capture->setHeight(capture->getHeight() + 2);
00300                 }
00301                 break;
00302 #endif
00303             /* ------------------------------------------------------------ */
00304             default:
00305                 phPROGRESS("\n");
00306                     setting_stage = 0;
00307                     setting_started = 0;
00308                     
00309                     if (test) 
00310                     {
00311                         test--;
00312                         if (test == 0)
00313                             displaysOpen = 0;
00314                     }
00315                 break;
00316         }
00317         
00318         /* Yielding is optional. This gives up the thread's timeslice
00319          * to prevent slow response in other threads. It consumes more
00320          * CPU cycles than sleeping. Use it instead of sleeping if
00321          * this loop is processing anything */
00322         
00323         /* phYield(); */
00324         
00325         if ((nDisplays > 0) && (displaysOpen))
00326         {   
00327             displaysOpen = 0;
00328             for (i = 0; (i < nDisplays) && (displaysOpen == 0); i++)
00329             {
00330                 if (display[i]->isOpen() == 1)
00331                 {
00332                     displaysOpen = 1;
00333                 }
00334             }
00335         }
00336     }
00337 
00338     rc = system.shutdown();
00339     phPRINT_RC(rc,NULL,"system.shutdown()");
00340 
00341 
00342 error:
00343     phDelete(capture);
00344 
00345     for (i = 0; (i < nDisplays) && (display != NULL); i++)
00346     {
00347         phDelete(display[i]);
00348     }
00349  
00350     phDeleteArray(display);
00351 
00352     phFree(capture_path);
00353     phDelete(arg_parser);
00354 
00355     return phSUCCESS;
00356 }




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