libeblearngui
/home/rex/ebltrunk/tools/libeblearngui/include/ebl_arch_gui.h
00001 /***************************************************************************
00002  *   Copyright (C) 2009 Pierre Sermanet   *
00003  *   pierre.sermanet@gmail.com   *
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *     * Redistributions of source code must retain the above copyright
00008  *       notice, this list of conditions and the following disclaimer.
00009  *     * Redistributions in binary form must reproduce the above copyright
00010  *       notice, this list of conditions and the following disclaimer in the
00011  *       documentation and/or other materials provided with the distribution.
00012  *     * Redistribution under a license not approved by the Open Source
00013  *       Initiative (http://www.opensource.org) must display the
00014  *       following acknowledgement in all advertising material:
00015  *        This product includes software developed at the Courant
00016  *        Institute of Mathematical Sciences (http://cims.nyu.edu).
00017  *     * The names of the authors may not be used to endorse or promote products
00018  *       derived from this software without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
00021  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023  * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY
00024  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00027  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  ***************************************************************************/
00031 
00032 #ifndef EBL_ARCH_GUI_H_
00033 #define EBL_ARCH_GUI_H_
00034 
00035 #include "libidxgui.h"
00036 #include "ebl_arch.h"
00037 #include "ebl_march.h"
00038 #include "ebl_answer.h"
00039 
00040 #define MAXWIDTH 1000
00041 #define MAXHEIGHT 1000
00042 #define TEXT_MIN_HEIGHT 50
00043 #define TEXT_MARGIN 170
00044 #define MODULES_HSPACE 2
00045 
00046 namespace ebl {
00047 
00048   // module_1_1_gui ////////////////////////////////////////////////////////////
00049 
00050   class EXPORT module_1_1_gui {
00051   public:
00052     int  display_wid_fprop;
00053     int  display_wid_bprop;
00054     int  display_wid_bbprop;
00055     static uint cnt;
00056 
00057   module_1_1_gui(int fwid = -1)
00058     : display_wid_fprop(fwid), display_wid_bprop(-1), display_wid_bbprop(-1) {};
00059     virtual ~module_1_1_gui() {};
00060 
00061 #define DISPLAY_PROTO_1_1(name, Tin, Tout)                              \
00062     template<typename T, class Tstate>                                  \
00063       void name(module_1_1<T,Tstate> &m, Tin &in, Tout &out, uint h0 = 0, \
00064                 uint w0 = 0, double dzoom = 1.0, T vmin = 0, T vmax = 0, \
00065                 bool show_out = true, int wid = -1, const char *wname = NULL);
00066 
00067 #define DISPLAY2_PROTO_1_1(name, Tin, Tout)                             \
00068     template<typename T, class Tstate>                                  \
00069       void name(module_1_1<T,Tstate> &m, Tin &in, Tout &out, uint &h0,  \
00070                 uint &w0, double dzoom = 1.0, T vmin = 0, T vmax = 0,   \
00071                 bool show_out = true, int wid = -1, const char *wname = NULL);
00072 
00073     // in: Tstate out: Tstate
00074     DISPLAY_PROTO_1_1(display_fprop, Tstate, Tstate)
00075     DISPLAY_PROTO_1_1(display_bprop, Tstate, Tstate)
00076     DISPLAY_PROTO_1_1(display_bbprop, Tstate, Tstate)
00077     DISPLAY2_PROTO_1_1(display_fprop2, Tstate, Tstate)
00078     DISPLAY2_PROTO_1_1(display_bprop2, Tstate, Tstate)
00079     DISPLAY2_PROTO_1_1(display_bbprop2, Tstate, Tstate)
00080     // in: Tstate out: mstate<Tstate>
00081     DISPLAY_PROTO_1_1(display_fprop, Tstate, mstate<Tstate>)
00082     DISPLAY_PROTO_1_1(display_bprop, Tstate, mstate<Tstate>)
00083     DISPLAY_PROTO_1_1(display_bbprop, Tstate, mstate<Tstate>)
00084     DISPLAY2_PROTO_1_1(display_fprop2, Tstate, mstate<Tstate>)
00085     DISPLAY2_PROTO_1_1(display_bprop2, Tstate, mstate<Tstate>)
00086     DISPLAY2_PROTO_1_1(display_bbprop2, Tstate, mstate<Tstate>)
00087     // in: mstate<Tstate> out: Tstate
00088     DISPLAY_PROTO_1_1(display_fprop, mstate<Tstate>, Tstate)
00089     DISPLAY_PROTO_1_1(display_bprop, mstate<Tstate>, Tstate)
00090     DISPLAY_PROTO_1_1(display_bbprop, mstate<Tstate>, Tstate)
00091     DISPLAY2_PROTO_1_1(display_fprop2, mstate<Tstate>, Tstate)
00092     DISPLAY2_PROTO_1_1(display_bprop2, mstate<Tstate>, Tstate)
00093     DISPLAY2_PROTO_1_1(display_bbprop2, mstate<Tstate>, Tstate)
00094     // in: mstate<Tstate> out: mstate<Tstate>
00095     DISPLAY_PROTO_1_1(display_fprop, mstate<Tstate>, mstate<Tstate>)
00096     DISPLAY_PROTO_1_1(display_bprop, mstate<Tstate>, mstate<Tstate>)
00097     DISPLAY_PROTO_1_1(display_bbprop, mstate<Tstate>, mstate<Tstate>)
00098     DISPLAY2_PROTO_1_1(display_fprop2, mstate<Tstate>, mstate<Tstate>)
00099     DISPLAY2_PROTO_1_1(display_bprop2, mstate<Tstate>, mstate<Tstate>)
00100     DISPLAY2_PROTO_1_1(display_bbprop2, mstate<Tstate>, mstate<Tstate>)
00101 
00102     
00103 
00104 
00105     template<typename T, class Tstate>
00106       void display_internals(module_1_1<T,Tstate> &m, unsigned int &h0,
00107                              unsigned int &w0, double zoom = 1.0,
00108                              T vmin = 0, T vmax = 0, int wid = -1,
00109                              const char *wname = NULL,
00110                              uint maxwidth = MAXWIDTH);
00111   };
00113   // module_2_1_gui
00114 
00115   class module_2_1_gui {
00116   private:
00117     uint         display_wid_fprop;
00118 
00119   public:
00120     module_2_1_gui() {};
00121     virtual ~module_2_1_gui() {};
00122 
00123 #define DISPLAY_PROTO_2_1(name)                                         \
00124     template<typename T, class Tstate, class Tin2, class Tout>          \
00125       void name(module_2_1<T,Tstate,Tstate,Tout> &m,                    \
00126                 Tstate &in1, Tin2 &in2, Tout &out,                      \
00127                 unsigned int &h0, unsigned int &w0,                     \
00128                 double dzoom = 1.0, T vmin = 0, T vmax = 0,             \
00129                 bool show_out = true,                                   \
00130                 int wid = -1, const char *wname = NULL);
00131 
00132     DISPLAY_PROTO_2_1(display_fprop)
00133     DISPLAY_PROTO_2_1(display_bprop)
00134     DISPLAY_PROTO_2_1(display_bbprop)
00135   };
00136 
00137   // layers_gui ////////////////////////////////////////////////////////////////
00138 
00139   class layers_gui {
00140   public:
00141     layers_gui(int wid = -1) : m11g(wid) {};
00142     virtual ~layers_gui() {};
00143 
00144 #define DISPLAY_PROTO_LAYERSN(name, Tin, Tout)                          \
00145     template<typename T, class Tstate>                                  \
00146       static void name(module_1_1_gui &g, layers<T,Tstate> &ln, Tin &in, \
00147                        Tout &out, uint &h0, uint &w0, double dzoom = 1.0, \
00148                        T vmin = 0, T vmax = 0, bool show_out = false);
00149 
00150     // in: Tstate out: Tstate
00151     DISPLAY_PROTO_LAYERSN(display_fprop, Tstate, Tstate)
00152     DISPLAY_PROTO_LAYERSN(display_bprop, Tstate, Tstate)
00153     DISPLAY_PROTO_LAYERSN(display_bbprop, Tstate, Tstate)
00154     // in: Tstate out: mstate<Tstate>
00155     DISPLAY_PROTO_LAYERSN(display_fprop, Tstate, mstate<Tstate>)
00156     DISPLAY_PROTO_LAYERSN(display_bprop, Tstate, mstate<Tstate>)
00157     DISPLAY_PROTO_LAYERSN(display_bbprop, Tstate, mstate<Tstate>)
00158     // in: mstate<Tstate> out: Tstate
00159     DISPLAY_PROTO_LAYERSN(display_fprop, mstate<Tstate>, Tstate)
00160     DISPLAY_PROTO_LAYERSN(display_bprop, mstate<Tstate>, Tstate)
00161     DISPLAY_PROTO_LAYERSN(display_bbprop, mstate<Tstate>, Tstate)
00162     // in: mstate<Tstate> out: mstate<Tstate>
00163     DISPLAY_PROTO_LAYERSN(display_fprop, mstate<Tstate>, mstate<Tstate>)
00164     DISPLAY_PROTO_LAYERSN(display_bprop, mstate<Tstate>, mstate<Tstate>)
00165     DISPLAY_PROTO_LAYERSN(display_bbprop, mstate<Tstate>, mstate<Tstate>)
00166 
00167     
00168     template<typename T, class Tstate>
00169       void display_internals(layers<T,Tstate> &ln,
00170                              unsigned int &h0, unsigned int &w0,
00171                              double dzoom = 1.0,
00172                              T vmin = 0, T vmax = 0, uint maxwidth = MAXWIDTH);
00173 
00176     template<typename T, class Tstate>
00177       void display_internals(module_1_1<T,Tstate> &m,
00178                              unsigned int &h0, unsigned int &w0,
00179                              double dzoom = 1.0,
00180                              T vmin = 0, T vmax = 0, uint maxwidth = MAXWIDTH);
00181 
00182   protected:
00183     module_1_1_gui      m11g;
00184   };
00185 
00186   // ms_module_gui /////////////////////////////////////////////////////////////
00187 
00188   class ms_module_gui {
00189   public:
00190     ms_module_gui(int wid = -1) : m11g(wid) {};
00191     virtual ~ms_module_gui() {};
00192 
00193 #define DISPLAY_PROTO_MSMODULE(name, Tin, Tout)                         \
00194     template<typename T, class Tstate>                                  \
00195       static void name(module_1_1_gui &g, ms_module<T,Tstate> &ln, Tin &in, \
00196                        Tout &out, uint &h0, uint &w0, double dzoom = 1.0, \
00197                        T vmin = 0, T vmax = 0, bool show_out = false);
00198 
00199     // in: mstate<Tstate> out: mstate<Tstate>
00200     DISPLAY_PROTO_MSMODULE(display_fprop, mstate<Tstate>, mstate<Tstate>)
00201     DISPLAY_PROTO_MSMODULE(display_bprop, mstate<Tstate>, mstate<Tstate>)
00202     DISPLAY_PROTO_MSMODULE(display_bbprop, mstate<Tstate>, mstate<Tstate>)
00203 
00204   protected:
00205     module_1_1_gui      m11g;
00206   };
00207 
00209   // layers_2_gui
00210 
00211 /*   class layers_2_gui { */
00212 /*   public: */
00213 /*     layers_2_gui() {}; */
00214 /*     virtual ~layers_2_gui() {}; */
00215 
00216 /* #define DISPLAY_PROTO_LAYERS2(name)                          \ */
00217 /*     template<typename T, class Tstate>                                                       \ */
00218 /*       static void name(module_1_1_gui &g,                            \ */
00219 /*                     layers_2<T,Tstate> &ln,                                  \ */
00220 /*                     Tstate &in, Tstate &out,                 \ */
00221 /*                     unsigned int &h0, unsigned int &w0,              \ */
00222 /*                     double dzoom = 1.0,                              \ */
00223 /*                     T vmin = 0, T vmax = 0,                          \ */
00224 /*                     bool show_out = false); */
00225 
00226 /*     DISPLAY_PROTO_LAYERS2(display_fprop) */
00227 /*     DISPLAY_PROTO_LAYERS2(display_bprop) */
00228 /*     DISPLAY_PROTO_LAYERS2(display_bbprop) */
00229 /*   }; */
00230 
00232   // trainable_module_gui
00233 
00234   class trainable_module_gui {
00235   public:
00236     trainable_module_gui() {};
00237     virtual ~trainable_module_gui() {};
00238 
00239 #define DISPLAY_PROTO_TRAINABLE(name)                                   \
00240     template<typename T, class Tin1, class Tin2, class Ten,typename Tds1,typename Tds2> \
00241       static void name(trainable_module<T,Tds1,Tds2,Tin1,Tin1,Ten> &dse, \
00242                        Tin1 &i1, Tin2 &i2, Ten &energy,                 \
00243                        unsigned int &h0, unsigned int &w0,              \
00244                        double zoom, T vmin = 0, T vmax = 0,             \
00245                        bool show_out = true,                            \
00246                        int wid = -1, const char *wname = NULL);
00247 
00248     DISPLAY_PROTO_TRAINABLE(display_fprop)
00249     DISPLAY_PROTO_TRAINABLE(display_bprop)
00250     DISPLAY_PROTO_TRAINABLE(display_bbprop)
00251   };
00252 
00253 } // namespace ebl {
00254 
00255 #include "ebl_arch_gui.hpp"
00256 
00257 #endif /* EBL_ARCH_GUI_H_ */