Main Page   Compound List   File List   Compound Members   File Members  

ImageDisplay.h

00001 
00002 #ifndef IMAGE_DISPLAY_H
00003 #define IMAGE_DISPLAY_H
00004 
00005 #include <glow.h>
00006 #include <pthread.h>
00007 
00008 #include "Image.h"
00009 
00010 
00011 GLOW_NAMESPACE_USING
00012 
00013 template< typename T >
00014 class ImageDisplay
00015 {
00016 public:
00017 /* Public Data Definitions */
00018         
00019         T*                      win;
00020         
00021         static T*               windowId;
00022         static GlowWindowParams params;
00023 
00024 public:
00025 /* Public Methods */
00026         ImageDisplay(int width, int height, char* title);
00027         
00028         static void createWindow();
00029 
00030         void operator << (ImageRGB&  img) { *win << img; }
00031         void operator << (ImageGrey& img) { *win << img; }
00032         void operator << (Image&     img) { *win << img; }
00033 
00034 };
00035 
00036 
00037 /* Globals */
00038 extern pthread_mutex_t mut;
00039 extern pthread_cond_t cond;
00040 extern bool request;
00041 extern void (*createFirstWindow)();
00042 
00043 
00044 /* Class Data Members */
00045 template< typename T >
00046 T* ImageDisplay< T >::windowId = 0;
00047 
00048 template< typename T >
00049 GlowWindowParams ImageDisplay< T >::params;
00050  
00051 
00052 /* Class Methods */
00053 
00054 template< typename T >
00055 ImageDisplay< T >::ImageDisplay(int width, int height, char* title)
00056 {
00057         pthread_mutex_lock(&mut);
00058         {
00059                 while (request)
00060                         pthread_cond_wait(&cond, &mut);
00061                 
00062                 params.width  = width;
00063                 params.height = height;
00064                 params.title  = title;
00065                 
00066                 request  = true;
00067                 windowId = 0;
00068 
00069                 createFirstWindow = createWindow;
00070                 
00071                 pthread_cond_signal(&cond);
00072         }
00073         pthread_mutex_unlock(&mut);
00074 
00075         Glow::SetIdleFunc(createWindow);
00076 
00077         pthread_mutex_lock(&mut);
00078         {
00079                 while (request)
00080                         pthread_cond_wait(&cond, &mut);
00081 
00082                 win = windowId;
00083         }
00084         pthread_mutex_unlock(&mut);
00085 
00086         Glow::SetIdleFunc(NULL);
00087 }
00088 
00089 
00090 template< typename T>
00091 void ImageDisplay< T >::createWindow( void )
00092 {
00093         if (pthread_mutex_trylock(&mut)) return;
00094         if (request) {
00095                 windowId = new T(params.width, params.height, params.title);
00096                 request = false;
00097                 pthread_cond_signal(&cond);
00098         }
00099         pthread_mutex_unlock(&mut);
00100 }
00101 
00102 
00103 #endif  // IMAGE_DISPLAY_H

Generated on Thu Mar 11 11:43:51 2004 for libRTImageDisplay by doxygen1.2.18