smooth.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              =smooth
00009 pluginmenuentry         =Smooth
00010 menupath                =Math/Filter 2D/
00011 entryplace              =Filter 2D
00012 shortentryplace =F2D
00013 abouttext               =Gaussian smooth using 2D convolution.
00014 smallhelp               =gaus smooth
00015 longhelp                =Gausian smooth
00016  * 
00017  * Gxsm Plugin Name: smooth.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: Smooth
00049 % PlugInName: smooth
00050 % PlugInAuthor: Percy Zahl
00051 % PlugInAuthorEmail: zahl@users.sf.net
00052 % PlugInMenuPath: Math/Filter 2D/Smooth
00053 
00054 % PlugInDescription
00055 A 2D Gausian smooth is calculated via convolution with a Gaus-Kernel:
00056 
00057 \[ K_{ij} = 4*e^{-\frac{i^2+j^2}{r^2}} \]
00058 
00059 % PlugInUsage
00060 Call \GxsmMenu{Math/Filter 2D/Smooth}.
00061 
00062 % OptPlugInSources
00063 The active channel is used as data source.
00064 
00065 % OptPlugInDest
00066 The computation result is placed into an existing math channel, else
00067 into a new created math channel.
00068 
00069 % OptPlugInHints
00070 Alternative: Use the Fourier-Filter methods Gaus-Stop/Pass for huge
00071 convolutions, it's faster!
00072 
00073 % EndPlugInDocuSection
00074  * -------------------------------------------------------------------------------- 
00075  */
00076 
00077 #include <gtk/gtk.h>
00078 #include "config.h"
00079 #include "gxsm/plugin.h"
00080 #include "../../common/pyremote.h"
00081 
00082 // Plugin Prototypes
00083 static void smooth_init( void );
00084 static void smooth_about( void );
00085 static void smooth_configure( void );
00086 static void smooth_cleanup( void );
00087 
00088 static gboolean smooth_run_radius(Scan *Src, Scan *Dest);
00089 static void smooth_non_interactive( GtkWidget *widget , gpointer pc );
00090 
00091 // Define Type of math plugin here, only one line should be commented in!!
00092 #define GXSM_ONE_SRC_PLUGIN__DEF
00093 // #define GXSM_TWO_SRC_PLUGIN__DEF
00094 
00095 // Math-Run-Function, use only one of (automatically done :=)
00096 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00097 // "OneSrc" Prototype
00098  static gboolean smooth_run( Scan *Src, Scan *Dest );
00099 #else
00100 // "TwoSrc" Prototype
00101  static gboolean smooth_run( Scan *Src1, Scan *Src2, Scan *Dest );
00102 #endif
00103 
00104 // Fill in the GxsmPlugin Description here
00105 GxsmPlugin smooth_pi = {
00106   NULL,                   // filled in and used by Gxsm, don't touch !
00107   NULL,                   // filled in and used by Gxsm, don't touch !
00108   0,                      // filled in and used by Gxsm, don't touch !
00109   NULL,                   // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 
00110                           // filled in here by Gxsm on Plugin load, 
00111                           // just after init() is called !!!
00112   // ----------------------------------------------------------------------
00113   // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc
00114   "smooth-"
00115 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00116   "M1S"
00117 #else
00118   "M2S"
00119 #endif
00120   "-F2D",
00121   // Plugin's Category - used to autodecide on Pluginloading or ignoring
00122   // NULL: load, else
00123   // example: "+noHARD +STM +AFM"
00124   // load only, if "+noHARD: no hardware" and Instrument is STM or AFM
00125   // +/-xxxHARD und (+/-INST or ...)
00126   NULL,
00127   // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details)
00128   "Gaus smooth",                   
00129   // Author(s)
00130   "Percy Zahl",
00131   // Menupath to position where it is appendet to
00132   N_("_Math/Filter _2D/"),
00133   // Menuentry
00134   N_("Smooth"),
00135   // help text shown on menu
00136   N_("Gaus smooth"),
00137   // more info...
00138   "gaus smooth",
00139   NULL,          // error msg, plugin may put error status msg here later
00140   NULL,          // Plugin Status, managed by Gxsm, plugin may manipulate it too
00141   // init-function pointer, can be "NULL", 
00142   // called if present at plugin load
00143   smooth_init,  
00144   // query-function pointer, can be "NULL", 
00145   // called if present after plugin init to let plugin manage it install itself
00146   NULL, // query should be "NULL" for Gxsm-Math-Plugin !!!
00147   // about-function, can be "NULL"
00148   // can be called by "Plugin Details"
00149   smooth_about,
00150   // configure-function, can be "NULL"
00151   // can be called by "Plugin Details"
00152   smooth_configure,
00153   // run-function, can be "NULL", if non-Zero and no query defined, 
00154   // it is called on menupath->"plugin"
00155   NULL, // run should be "NULL" for Gxsm-Math-Plugin !!!
00156   // cleanup-function, can be "NULL"
00157   // called if present at plugin removeal
00158   smooth_cleanup
00159 };
00160 
00161 // special math Plugin-Strucure, use
00162 // GxsmMathOneSrcPlugin smooth_m1s_pi -> "OneSrcMath"
00163 // GxsmMathTwoSrcPlugin smooth_m2s_pi -> "TwoSrcMath"
00164 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00165  GxsmMathOneSrcPlugin smooth_m1s_pi
00166 #else
00167  GxsmMathTwoSrcPlugin smooth_m2s_pi
00168 #endif
00169  = {
00170    // math-function to run, see prototype(s) above!!
00171    smooth_run
00172  };
00173 
00174 // Text used in Aboutbox, please update!!
00175 static const char *about_text = N_("Gxsm smooth Plugin\n\n"
00176                                    "Gaus smooth using a 2D convolution.");
00177 
00178 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00179 // Essential Plugin Function!!
00180 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00181   smooth_pi.description = g_strdup_printf(N_("Gxsm MathOneArg smooth plugin %s"), VERSION);
00182   return &smooth_pi; 
00183 }
00184 
00185 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 
00186 // used to find out which Math Type the Plugin is!! 
00187 // Essential Plugin Function!!
00188 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00189 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) {
00190   return &smooth_m1s_pi; 
00191 }
00192 #else
00193 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 
00194   return &smooth_m2s_pi; 
00195 }
00196 #endif
00197 
00198 /* Here we go... */
00199 // init-Function
00200 static void smooth_init(void)
00201 {
00202   PI_DEBUG (DBG_L2, "smooth Plugin Init");
00203 
00204 // This is action remote stuff, stolen from the peak finder PI.
00205   remote_action_cb *ra;
00206   GtkWidget *dummywidget = gtk_menu_item_new();
00207 
00208   ra = g_new( remote_action_cb, 1);
00209   ra -> cmd = g_strdup_printf("smooth_PI");
00210   ra -> RemoteCb = &smooth_non_interactive;
00211   ra -> widget = dummywidget;
00212   ra -> data = NULL;
00213   gapp->RemoteActionList = g_slist_prepend ( gapp->RemoteActionList, ra );
00214   PI_DEBUG (DBG_L2, "smooth-plugin: Adding new Remote Cmd: smooth_PI");
00215 // remote action stuff
00216 }
00217 
00218 static void smooth_non_interactive( GtkWidget *widget , gpointer pc )
00219 {
00220   PI_DEBUG (DBG_L2, "smooth-plugin: smooth is called from script.");
00221 
00222 //  cout << "pc: " << ((gchar**)pc)[1] << endl;
00223 //  cout << "pc: " << ((gchar**)pc)[2] << endl;
00224 //  cout << "pc: " << atof(((gchar**)pc)[2]) << endl;
00225 
00226   gapp->xsm->MathOperation(&smooth_run_radius);
00227   return;
00228 
00229 }
00230 
00231 // about-Function
00232 static void smooth_about(void)
00233 {
00234   const gchar *authors[] = { smooth_pi.authors, NULL};
00235   gtk_widget_show(gnome_about_new ( smooth_pi.name,
00236                                     VERSION,
00237                                     N_("(C) 2000 the Free Software Foundation"),
00238                                     about_text,
00239                                     authors,
00240                                     NULL, NULL, NULL
00241                                     ));
00242 }
00243 
00244 // configure-Function
00245 static void smooth_configure(void)
00246 {
00247   if(smooth_pi.app)
00248     smooth_pi.app->message("smooth Plugin Configuration");
00249 }
00250 
00251 // cleanup-Function
00252 static void smooth_cleanup(void)
00253 {
00254         PI_DEBUG (DBG_L2, "smooth Plugin Cleanup");
00255 }
00256 
00257 /*
00258  * special kernels for MemDigiFilter
00259  * Gausian Smooth Kernel
00260  */
00261 
00262 class MemSmoothKrn : public MemDigiFilter{
00263 public:
00264         MemSmoothKrn (double xms, double xns, int m, int n):MemDigiFilter (xms, xns, m, n){};
00265         virtual gboolean CalcKernel (){
00266                 int i,j;
00267                 for (i= -m; i<=m; i++)
00268                         for (j = -n; j<=n; j++)
00269                                 data->Z (rint (4*exp (-(i*i)/(xms*xms) -(j*j)/(xns*xns))), j+n, i+m); 
00270                 return 0;
00271         };
00272 };
00273 
00274 
00275 // run-Function
00276 static gboolean smooth_run(Scan *Src, Scan *Dest)
00277 {
00278         double r = 5.;    // Get Radius
00279         gapp->ValueRequest("2D Convol. Filter Size", "Radius", "Smooth kernel size: s = 1+radius",
00280                            gapp->xsm->Unity, 0., Src->mem2d->GetNx()/10., ".0f", &r);
00281 
00282         int    s = 1+(int)(r + .9); // calc. approx Matrix Radius
00283         MemSmoothKrn krn(r,r, s,s); // Setup Kernelobject
00284         krn.Convolve(Src->mem2d, Dest->mem2d); // Do calculation of Kernel and then do convolution
00285         return MATH_OK;
00286 }
00287 
00288 
00289 static gboolean smooth_run_radius(Scan *Src, Scan *Dest)
00290 {
00291         // equals smooth-run except ValueRequest
00292         double r = 5.0;    // Get Radius
00293 
00294         int    s = 1+(int)(r + .9); // calc. approx Matrix Radius
00295         MemSmoothKrn krn(r,r, s,s); // Setup Kernelobject
00296         krn.Convolve(Src->mem2d, Dest->mem2d); // Do calculation of Kernel and then do convolution
00297         return MATH_OK;
00298 }
00299 

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