stat_diff.C

Go to the documentation of this file.
00001 /* Gnome gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  *
00005  * plugin_helper reports your answers as
00006 author          =Percy Zahl
00007 email                   =zahl@users.sf.net
00008 pluginname              =stat_diff
00009 pluginmenuentry         =Stat Diff
00010 menupath                =Math/Filter 2D/
00011 entryplace              =Filter 2D
00012 shortentryplace =F2D
00013 abouttext               =Stationary Differentiation
00014 smallhelp               =Stationary Differentiation
00015 longhelp                =Stationary Differentiation
00016  * 
00017  * Gxsm Plugin Name: stat_diff.C
00018  * ========================================
00019  * 
00020  * Copyright (C) 1999 The Free Software Foundation
00021  *
00022  * Authors: Percy Zahl <zahl@fkp.uni-hannover.de>
00023  * additional features: Andreas Klust <klust@fkp.uni-hannover.de>
00024  *
00025  * This program is free software; you can redistribute it and/or modify
00026  * it under the terms of the GNU General Public License as published by
00027  * the Free Software Foundation; either version 2 of the License, or
00028  * (at your option) any later version.
00029  *
00030  * This program is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00033  * GNU General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU General Public License
00036  * along with this program; if not, write to the Free Software
00037  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00038  */
00039 
00040 
00041 /* Please do not change the Begin/End lines of this comment section!
00042  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00043  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00044  * All "% PlugInXXX" commentary tags are mandatory
00045  * All "% OptPlugInXXX" tags are optional and can be removed or commented in
00046  * --------------------------------------------------------------------------------
00047 % BeginPlugInDocuSection
00048 % PlugInDocuCaption: Stat Diff
00049 % PlugInName: stat_diff
00050 % PlugInAuthor: Percy Zahl
00051 % PlugInAuthorEmail: zahl@users.sf.net
00052 % PlugInMenuPath: Math/Filter 2D/Stat Diff
00053 
00054 % PlugInDescription
00055 Stationary Differentation in scan direction using a convolution kernel:
00056 \[ K_{ij} = C \cdot j \cdot e^{ - \frac{i^2}{r_y} - \frac{j^2}{r_x}} \]
00057 
00058 % PlugInUsage
00059 Call \GxsmMenu{Math/Filter 2D/Stat Diff}.
00060 
00061 % OptPlugInSources
00062 The active channel is used as data source.
00063 
00064 % OptPlugInDest
00065 The computation result is placed into an existing math channel, else
00066 into a new created math channel.
00067 
00068 % OptPlugInKnownBugs
00069 Crashes Gxsm -- pending to fix.
00070 
00071 % EndPlugInDocuSection
00072  * -------------------------------------------------------------------------------- 
00073  */
00074 
00075 #include <gtk/gtk.h>
00076 #include "config.h"
00077 #include "gxsm/plugin.h"
00078 
00079 // Plugin Prototypes
00080 static void stat_diff_init( void );
00081 static void stat_diff_about( void );
00082 static void stat_diff_configure( void );
00083 static void stat_diff_cleanup( void );
00084 
00085 // Define Type of math plugin here, only one line should be commented in!!
00086 #define GXSM_ONE_SRC_PLUGIN__DEF
00087 // #define GXSM_TWO_SRC_PLUGIN__DEF
00088 
00089 // Math-Run-Function, use only one of (automatically done :=)
00090 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00091 // "OneSrc" Prototype
00092  static gboolean stat_diff_run( Scan *Src, Scan *Dest );
00093 #else
00094 // "TwoSrc" Prototype
00095  static gboolean stat_diff_run( Scan *Src1, Scan *Src2, Scan *Dest );
00096 #endif
00097 
00098 // Fill in the GxsmPlugin Description here
00099 GxsmPlugin stat_diff_pi = {
00100   NULL,                   // filled in and used by Gxsm, don't touch !
00101   NULL,                   // filled in and used by Gxsm, don't touch !
00102   0,                      // filled in and used by Gxsm, don't touch !
00103   NULL,                   // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 
00104                           // filled in here by Gxsm on Plugin load, 
00105                           // just after init() is called !!!
00106   // ----------------------------------------------------------------------
00107   // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc
00108   "stat_diff-"
00109 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00110   "M1S"
00111 #else
00112   "M2S"
00113 #endif
00114   "-F2D",
00115   // Plugin's Category - used to autodecide on Pluginloading or ignoring
00116   // NULL: load, else
00117   // example: "+noHARD +STM +AFM"
00118   // load only, if "+noHARD: no hardware" and Instrument is STM or AFM
00119   // +/-xxxHARD und (+/-INST or ...)
00120   NULL,
00121   // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details)
00122   "Stationary Differentiation",                   
00123   // Author(s)
00124   "Percy Zahl",
00125   // Menupath to position where it is appendet to
00126   N_("_Math/Filter _2D/"),
00127   // Menuentry
00128   N_("Stat Diff"),
00129   // help text shown on menu
00130   N_("Stationary Differentiation"),
00131   // more info...
00132   "Stationary Differentiation",
00133   NULL,          // error msg, plugin may put error status msg here later
00134   NULL,          // Plugin Status, managed by Gxsm, plugin may manipulate it too
00135   // init-function pointer, can be "NULL", 
00136   // called if present at plugin load
00137   stat_diff_init,  
00138   // query-function pointer, can be "NULL", 
00139   // called if present after plugin init to let plugin manage it install itself
00140   NULL, // query should be "NULL" for Gxsm-Math-Plugin !!!
00141   // about-function, can be "NULL"
00142   // can be called by "Plugin Details"
00143   stat_diff_about,
00144   // configure-function, can be "NULL"
00145   // can be called by "Plugin Details"
00146   stat_diff_configure,
00147   // run-function, can be "NULL", if non-Zero and no query defined, 
00148   // it is called on menupath->"plugin"
00149   NULL, // run should be "NULL" for Gxsm-Math-Plugin !!!
00150   // cleanup-function, can be "NULL"
00151   // called if present at plugin removeal
00152   stat_diff_cleanup
00153 };
00154 
00155 // special math Plugin-Strucure, use
00156 // GxsmMathOneSrcPlugin stat_diff_m1s_pi -> "OneSrcMath"
00157 // GxsmMathTwoSrcPlugin stat_diff_m2s_pi -> "TwoSrcMath"
00158 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00159  GxsmMathOneSrcPlugin stat_diff_m1s_pi
00160 #else
00161  GxsmMathTwoSrcPlugin stat_diff_m2s_pi
00162 #endif
00163  = {
00164    // math-function to run, see prototype(s) above!!
00165    stat_diff_run
00166  };
00167 
00168 // Text used in Aboutbox, please update!!
00169 static const char *about_text = N_("Gxsm stat_diff Plugin\n\n"
00170                                    "Stationary Differentiation");
00171 
00172 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00173 // Essential Plugin Function!!
00174 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00175   stat_diff_pi.description = g_strdup_printf(N_("Gxsm MathOneArg stat_diff plugin %s"), VERSION);
00176   return &stat_diff_pi; 
00177 }
00178 
00179 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 
00180 // used to find out which Math Type the Plugin is!! 
00181 // Essential Plugin Function!!
00182 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00183 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) {
00184   return &stat_diff_m1s_pi; 
00185 }
00186 #else
00187 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 
00188   return &stat_diff_m2s_pi; 
00189 }
00190 #endif
00191 
00192 /* Here we go... */
00193 // init-Function
00194 static void stat_diff_init(void)
00195 {
00196   PI_DEBUG (DBG_L2, "stat_diff Plugin Init");
00197 }
00198 
00199 // about-Function
00200 static void stat_diff_about(void)
00201 {
00202   const gchar *authors[] = { stat_diff_pi.authors, NULL};
00203   gtk_widget_show(gnome_about_new ( stat_diff_pi.name,
00204                                     VERSION,
00205                                     N_("(C) 2000 the Free Software Foundation"),
00206                                     about_text,
00207                                     authors,
00208                                     NULL, NULL, NULL
00209                                     ));
00210 }
00211 
00212 // configure-Function
00213 static void stat_diff_configure(void)
00214 {
00215         if(stat_diff_pi.app)
00216                 stat_diff_pi.app->message("stat_diff Plugin Configuration");
00217 }
00218 
00219 // cleanup-Function
00220 static void stat_diff_cleanup(void)
00221 {
00222         PI_DEBUG (DBG_L2, "stat_diff Plugin Cleanup");
00223 }
00224 
00225 /*
00226  * use gradient (x) as data -- derivate_x -- Kernel
00227  */
00228 
00229 class MemDeriveXKrn : public MemDigiFilter{
00230 public:
00231         MemDeriveXKrn (double xms, double xns, int m, int n) : MemDigiFilter (xms, xns, m, n){};
00232         virtual gboolean CalcKernel (){
00233                 int i;
00234                 int kasump = 0;
00235                 double coef = 5.0;
00236   
00237                 if (xms < 0.5)  xms = 0.5;
00238                 if (xns < 0.5)  xns = 0.5;
00239 
00240                 const double asum = 5 + 8*xns*xms;
00241                 do{
00242                         kasump = 0;
00243                         for (i= -m; i<=m; i++)  {
00244                                 int j;
00245                                 for (j=0; j<=n; j++)    {
00246                                         const int tmp = (int)rint (coef*j * exp(-(i*i)/(xms*xms) - (j*j)/(xns*xns)));
00247                                         data->Z ( -data->Z (tmp, j+n, i+m), n-j, i+m);
00248                                         kasump += abs (tmp);
00249                                 }
00250                         }
00251                         coef /= 0.8 + 0.2*kasump/asum;
00252                 }while (kasump < asum);
00253                 return 0;
00254         };
00255 };
00256 
00257 // run-Function
00258 static gboolean stat_diff_run(Scan *Src, Scan *Dest)
00259 {
00260         double r = 5.;    // Get Radius
00261         gapp->ValueRequest("2D Convol. Filter Size", "Radius", "Stat.Diff. kernel size: s = 1+radius",
00262                            gapp->xsm->Unity, 0., Src->mem2d->GetNx()/10., ".0f", &r);
00263         int    s = 1+(int)(r + .9);
00264         MemDeriveXKrn krn(r,r, s,s);
00265         krn.Convolve(Src->mem2d, Dest->mem2d);
00266         return MATH_OK;
00267 }
00268 

Generated on Sat Apr 1 09:04:21 2006 for GXSM by  doxygen 1.4.6