libeblearntools
/home/rex/ebltrunk/tools/libeblearntools/include/fprop_thread.h
00001 /***************************************************************************
00002  *   Copyright (C) 2011 by Pierre Sermanet *
00003  *   pierre.sermanet@gmail.com *
00004  *   All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Redistribution under a license not approved by the Open Source
00014  *       Initiative (http://www.opensource.org) must display the
00015  *       following acknowledgement in all advertising material:
00016  *        This product includes software developed at the Courant
00017  *        Institute of Mathematical Sciences (http://cims.nyu.edu).
00018  *     * The names of the authors may not be used to endorse or promote products
00019  *       derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00023  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00024  * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY
00025  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00026  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00028  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  ***************************************************************************/
00032 
00033 #ifndef FPROP_THREAD_H_
00034 #define FPROP_THREAD_H_
00035 
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 
00039 #include "defines_tools.h"
00040 #include "thread.h"
00041 #include "netconf.h"
00042 #include "configuration.h"
00043 
00044 using namespace std;
00045 
00046 namespace ebl {
00047 
00048 // switch between forward only buffers or also backward
00049 #define FPROP_SFUNC fs
00050 #define FPROP_SBUF fstate_idx
00051 #define SFUNC2(T) T,T,T,SBUF<T>
00052 #define SFUNC3(T) T,SBUF<T>,mstate<SBUF<T> >
00053 // backward
00054 // #define FPROP_SFUNC bbs
00055 // #define SBUF bbstate_idx
00056   
00058   // A detection thread class
00059 
00060   template <typename Tnet>
00061   class fprop_thread : public thread {
00062   public:
00069     fprop_thread(configuration &conf, mutex *om = NULL,
00070                      const char *name = "",
00071                      const char *arg2 = NULL, bool sync = true,
00072                      t_chans tc = CHANS_RGB);
00073     ~fprop_thread();
00074     
00076     virtual void execute();
00079     virtual bool set_data(idx<ubyte> &frame, string &frame_name, uint frame_id);
00087     virtual bool get_data(idx<ubyte> &frame, string &frame_name,
00088                           uint &frame_id);
00092     virtual bool set_dump(string &frame_fname, string &dump_fname);
00097     virtual bool dumped();
00100     virtual bool available();
00102     virtual void set_output_directory(string &out);
00103     
00104   private:
00107     void set_out_updated();
00108 
00110     // private members
00111   private:
00112     configuration                conf;
00113     const char                  *arg2;
00114     idx<ubyte>                   uframe;
00115     idx<Tnet>                    frame;
00116     mutex                        mutex_in;      // mutex for thread input
00117     mutex                        mutex_out;     // mutex for thread output
00118     bool                         in_updated;    // thread input updated
00119     bool                         out_updated;   // thread output updated
00120     bool                         bavailable;    // thread is available
00121     string                       frame_name;    // name of current frame
00122     uint                         frame_id;      
00123     string                       outdir;        // output directory
00124     using thread::mout; 
00125     using thread::merr; 
00126     t_chans                      color_space;
00127     bool                         bload_image;    
00128 
00129   public:
00130     detector<FPROP_SFUNC(Tnet)>       *pdetect;
00131   };
00132 
00133 } // end namespace ebl
00134 
00135 #include "fprop_thread.hpp"
00136 
00137 #endif /* FPROP_THREAD_H_ */
00138