Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

/home/slang/XVision2/src/Pipes/PipeIterator.h

00001 #ifndef _PIPEITERATOR_H_
00002 #define _PIPEITERATOR_H_
00003 
00004 #include <XVImageIterator.h>
00005 #include <PipeImage.h>
00006 
00007 // PipeIterator stuff
00008 
00009 class EndOfImageException : public BrokenPipe { public:
00010   EndOfImageException() : BrokenPipe("EndOfImageException") {}
00011   EndOfImageException( char * err ) : BrokenPipe(err) {} };
00012 
00013 template <class PIXEL_IN, class PIXEL_OUT>
00014 class PixelPipeModule{
00015 
00016   typedef PIXEL_OUT (* FUNTYPE) (PIXEL_IN);
00017 
00018 protected:
00019 
00020   FUNTYPE fun;
00021 
00022 public:
00023 
00024   PixelPipeModule(FUNTYPE f) : fun(f) {}
00025   PIXEL_OUT operator () (PIXEL_IN p){ return fun(p); }
00026 };
00027 
00028 template <class IMTYPE>
00029 class HiddenPixelPipeSrc{
00030 
00031   typedef IMTYPE IMAGE_IN;
00032   typedef typename IMTYPE::PIXELTYPE PIXEL;
00033 
00034 public:
00035 
00036   const Pipe<IMAGE_IN > * srcPipe;
00037 
00038   HiddenPixelPipeSrc(const Pipe<IMAGE_IN > * p) : srcPipe(p) {}
00039   inline PIXEL map( PIXEL p1 ) const  { return p1; }
00040 };
00041 
00042 template <class PIN, class POUT, class PREV>
00043 class HiddenPixelPipe{
00044 
00045   typedef POUT                                  PIXEL_OUT;
00046   typedef typename PREV::IMAGE_IN               IMAGE_IN;
00047   typedef typename IMAGE_IN::PIXELTYPE          PIXEL_IN;
00048   typedef PixelPipeModule<PIN, PIXEL_OUT > PIXMODULE; 
00049   
00050 protected:
00051   
00052   const PREV      prev;
00053   const PIXMODULE fun;
00054   
00055 public:
00056 
00057   const Pipe<IMAGE_IN > * srcPipe;
00058 
00059   HiddenPixelPipe(const PREV & p, const PIXMODULE & f) : 
00060     prev(p), fun(f), srcPipe(p.srcPipe) {} 
00061 
00062   inline PIXEL_OUT map(PIXEL_IN p ) const { 
00063     return (const_cast<PIXMODULE >(fun))(prev.map(p));
00064   }
00065 };
00066 
00067 template <class TO, class PIXEL_OUT>
00068 class PixelPipeIterator{
00069 
00070   typedef TO RESULT_OUT;
00071 
00072 public:
00073   
00074   RESULT_OUT * result;
00075   
00076   PixelPipeIterator() : result(0) {} 
00077   
00078   template <class IMAGE_IN, class TCLASS>
00079   void iterate(IMAGE_IN & im, TCLASS * c, typename TCLASS::PIXEL_OUT (TCLASS::*push) (typename TCLASS::PIXEL_IN) ) const {
00080     this->reset(im.Width(), im.Height());
00081     XVImageIterator<typename TCLASS::PIXEL_IN > iter(im);
00082     for(; !iter.end(); ++iter){
00083       this->pile(((*c).*push)(*iter));
00084     }
00085   };
00086   
00087   inline virtual void reset(int, int) = 0;
00088   
00089   inline virtual void pile(PIXEL_OUT) = 0;
00090 };
00091 
00092 template <class IMAGE>
00093 class PixelImageOutIterator : public PixelPipeIterator<IMAGE, typename IMAGE::PIXELTYPE > {
00094   
00095   typedef typename IMAGE::PIXELTYPE PIXEL;
00096 
00097  protected:
00098 
00099   XVImageWIterator<PIXEL > * witer;
00100 
00101  public:
00102 
00103   inline virtual void reset(int w, int h){ 
00104     if(result) delete result;
00105     result = new IMAGE(w, h);
00106     //    if(witer) delete witer;
00107     witer = new XVImageWIterator<PIXEL >(*result);
00108   }
00109 
00110   inline virtual void pile(PIXEL p){
00111     (*(*witer)) = p;
00112     ++(*witer);
00113   }
00114 };
00115 
00116 template <class PIXEL>
00117 class PixelRGBIterator : public PixelImageOutIterator<XVImageRGB<PIXEL > > {};
00118 
00119 template <class PIXEL>
00120 class PixelScalarIterator : public PixelImageOutIterator<XVImageScalar<PIXEL > > {};
00121 
00122 template <class PI, class PP>
00123 class HiddenPixelPipeHolder : public PipeModule<typename PI::RESULT_OUT > {
00124   
00125   typedef typename PP::IMAGE_IN   IMAGE_IN;
00126   typedef typename PI::RESULT_OUT OBJ_OUT;
00127   typedef typename PP::PIXEL_IN   PIXEL_IN;
00128   typedef typename PP::PIXEL_OUT  PIXEL_OUT;
00129   
00130 protected:
00131   
00132   const Pipe<IMAGE_IN > * pred;
00133 
00134   const PP  * pixelPipe;
00135   const PI  * iterator;
00136 
00137   inline void check(void){
00138     PipeModule<OBJ_OUT >::check( pred );
00139   }
00140 
00141 public:
00142   
00143   HiddenPixelPipeHolder(const PP * p, const PI * i) : 
00144     pixelPipe(p), iterator(i), pred(p->srcPipe) {}
00145   
00146   Pipe<OBJ_OUT > operator () (void) const {
00147     HiddenPixelPipeHolder<PI, PP> * hppHolder = new HiddenPixelPipeHolder<PI, PP>(*this);    
00148     return Pipe<OBJ_OUT >(hppHolder);
00149   }
00150 
00151   OBJ_OUT compute_local_fn(int fc) {
00152 
00153     check();
00154     (*iterator).iterate((const_cast<Pipe<IMAGE_IN > >(*pred))->get_value(fc), pixelPipe, & PP::map);
00155     return *(iterator->result);
00156   }
00157 };
00158 
00159 template <class IMAGE_IN, class PIXEL_IN, class PIXEL_OUT> 
00160 inline HiddenPixelPipe<PIXEL_IN, PIXEL_OUT, 
00161                              HiddenPixelPipeSrc<IMAGE_IN > >
00162 operator |= ( const PixelPipeModule<PIXEL_IN, PIXEL_OUT > & fun, 
00163            const Pipe<IMAGE_IN > & srcPipe ){ 
00164 
00165   return HiddenPixelPipe<PIXEL_IN, PIXEL_OUT, 
00166                          HiddenPixelPipeSrc<IMAGE_IN > >(HiddenPixelPipeSrc<IMAGE_IN >( & srcPipe ), fun);
00167 };
00168 
00169 template <class PIXEL_IN, class PIXEL_OUT, class PREV_PIXEL_IN, class PREV>
00170 inline HiddenPixelPipe<PIXEL_IN, PIXEL_OUT, HiddenPixelPipe<PREV_PIXEL_IN, PIXEL_IN, PREV > >
00171 operator |= ( const PixelPipeModule<PIXEL_IN, PIXEL_OUT > & fun, 
00172            const HiddenPixelPipe<PREV_PIXEL_IN, PIXEL_IN, PREV > & pp ){
00173   return HiddenPixelPipe<PIXEL_IN, PIXEL_OUT, HiddenPixelPipe<PREV_PIXEL_IN, PIXEL_IN, PREV > >(pp, fun);
00174 };
00175 
00176 template <class OBJ_OUT, class PIXEL_OUT, class PREV>
00177 inline Pipe<OBJ_OUT >
00178 operator |= ( const PixelPipeIterator<OBJ_OUT, PIXEL_OUT > & pi,
00179            const PREV & pp ){
00180 
00181   HiddenPixelPipeHolder<PixelPipeIterator<OBJ_OUT, PIXEL_OUT >, PREV > hppi(&pp, &pi);
00182   return hppi();
00183 };
00184 
00185 #endif

Generated at Thu Mar 29 22:37:28 2001 for XVision by doxygen1.2.0 written by Dimitri van Heesch, © 1997-2000