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

X11MoveTest.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 <X11MoveTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int glbl_disable_displays = 0;
00017 
00018 /* ------------------------------------------------------------------------ */
00019 int usage ()
00020 {
00021     printf("\n\nUsage:\n");
00022     printf("\t--help            Display usage\n");
00023     printf("\t--ndisplays <int> Number of displays to create and move\n");     
00024     printf("\t--nodisplay       Disable the allocation, opening or any use of a display.\n");
00025     printf("\t--test <value>    Run test by performing 'value' moves and then exit.\n");
00026     printf("\n\n");
00027     exit(1);
00028 }
00029         
00030 /* ------------------------------------------------------------------------ */
00031 int main(int argc, char *argv[] )
00032 {
00033     phFUNCTION("main")
00034 
00035     unsigned int    i           = 0;
00036 
00037     int x = 0;
00038     int y = 0;
00039     unsigned int disp = 0;
00040 
00041     unsigned int        nDisplays   = 4;
00042     char                title[255];
00043     int                 displaysOpen= 1;
00044     phDisplayInterface  **display   = NULL;
00045 
00046     uint32_t            width   = 320;
00047     uint32_t            height  = 240;
00048     
00049     char        *capture_path   = NULL;
00050     int         channel         = 0;
00051         
00052 #ifdef WIN32
00053     VFWSource           *capture = new VFWSource();
00054 #else
00055     V4LCapture          *capture = new V4LCapture();
00056 #endif
00057         
00058     /* Utility class to ease the starting and stopping of displays, captures and
00059      * pipelines */
00060     phSystem        system;
00061    
00062     /* Remove the code below when using this code as an example.
00063      * 
00064      * This just checks whether "--test" has been specified with
00065      * a time value argument. It's for testing all the examples
00066      * without the need for human intervention. */
00067     int             test = 0;
00068 
00069     phArgTable      *arg_parser = new phArgTable();
00070 
00071     rc = arg_parser->add("--test",&test,phARG_INT);
00072     phCHECK_RC(rc,NULL,"arg_parser->add");
00073     rc = arg_parser->add("--ndisplays",&nDisplays,phARG_INT);
00074     phCHECK_RC(rc,NULL,"arg_parser->add");
00075     rc = arg_parser->add("--nodisplay",&glbl_disable_displays,phARG_BOOL);
00076     phCHECK_RC(rc,NULL,"arg_parser->add");
00077     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00078     phCHECK_RC(rc,NULL,"arg_parser->add");
00079     
00080     rc = arg_parser->add("--path",&capture_path,phARG_CHAR);
00081     phCHECK_RC(rc,NULL,"arg_parser->add");
00082 
00083     rc = arg_parser->add("--channel",&channel,phARG_INT);
00084     phCHECK_RC(rc,NULL,"arg_parser->add");
00085     
00086     rc = arg_parser->parse(argc,argv);
00087     phCHECK_RC(rc,NULL,"arg_parser->parse");
00088     
00089     if (glbl_disable_displays) nDisplays = 0;
00090     if (nDisplays < 0) nDisplays = 0;
00091 
00092     capture->set(width,height,capture_path);
00093     capture->setFormat(phImageBGRA32);
00094 #if 1
00095     capture->setChannel(channel);
00096     capture->setColour(65000);
00097     capture->setHue(65500);
00098     capture->setContrast(31000);
00099     capture->setBrightness(29000);
00100 #else
00101     capture->setChannel(channel);
00102     capture->setColour(35000);
00103     capture->setHue(35500);
00104     capture->setContrast(31000);
00105     capture->setBrightness(35000);
00106 #endif
00107  
00108     rc = system.addCapture(capture);
00109     phPRINT_RC(rc,NULL,"system.addCapture(capture)");
00110 
00111     display = new phDisplayInterface *[nDisplays];
00112     phCHECK_NULLPTR(display,"new","new phDisplayInterface *[nDisplays];");
00113 
00114     for (i = 0; i < nDisplays; i++)
00115     {
00116         sprintf(title,"X11LiveSourceTest[%u]",i);
00117         
00118         display[i] = new X11Display(width,height,title);
00119         
00120         /* Set all parameters for the display so when the phSystem
00121          * starts them up, they are the desired size*/
00122         display[i]->setLiveSourceInput(capture->getLiveSourceOutput());
00123         
00124         rc = system.addDisplay(display[i]);
00125         phPRINT_RC(rc,NULL,"system.addDisplay(display[i])");
00126     }
00127             
00128 
00129     /* startup */
00130     rc = system.startup();
00131     phPRINT_RC(rc,NULL,"system.startup()");
00132    
00133     for (i = 0; i < nDisplays; i++)
00134     {
00135         rc = display[i]->move(10 + (320 * i),200);
00136         phCHECK_RC(rc,NULL,"display[i]->move");        
00137     }
00138     x = 10;
00139     y = 200;
00140     
00141     displaysOpen = 1;
00142     while (displaysOpen)
00143     {
00144         /* Sleep a while, don't loop tightly */
00145 
00146         /* phMSleep(100); */
00147         phMSleep(1);
00148 
00149         x++;
00150         if (x > 400) 
00151         {
00152             x = 10;
00153         }
00154         y++;
00155         if (y > 400)
00156         {
00157             y = 200;
00158             disp++;
00159            
00160             if (disp >= nDisplays)
00161             {
00162                 disp = 0;
00163                 x = 10;
00164             }
00165         }
00166         
00167         rc = display[disp]->move(x + 10 + (320 * disp),y);
00168         phPRINT_RC(rc,NULL,"display[%d]->move(%d,%d)\n",
00169                  disp,
00170                  x + 10 + (320 * disp),
00171                  y);
00172         
00173         /* Yielding is optional. This gives up the thread's timeslice
00174          * to prevent slow response in other threads. It consumes more
00175          * CPU cycles than sleeping. Use it instead of sleeping if
00176          * this loop is processing anything */
00177         
00178         /* phYield(); */
00179         
00180         if (nDisplays > 0)
00181         {   
00182             displaysOpen = 0;
00183             for (i = 0; (i < nDisplays) && (displaysOpen == 0); i++)
00184             {
00185                 if (display[i]->isOpen() == 1)
00186                 {
00187                     displaysOpen = 1;
00188                 }
00189             }
00190         }
00191         
00192         /* Remove this if block when using this code as an example */
00193         /* Set the loop control value to end the loop when testing */
00194         if (test > 0)
00195         { 
00196             test--;
00197             if (test == 0)
00198                 displaysOpen = 0;
00199         }
00200     }
00201 
00202     rc = system.shutdown();
00203     phPRINT_RC(rc,NULL,"system.shutdown()");
00204 
00205 
00206 error:
00207     phDelete(capture);
00208 
00209     for (i = 0; (i < nDisplays) && (display != NULL); i++)
00210     {
00211         phDelete(display[i]);
00212     }
00213  
00214     phDeleteArray(display);
00215 
00216     phFree(capture_path);
00217     phDelete(arg_parser);
00218 
00219     return phSUCCESS;
00220 }




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