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 =diff 00009 pluginmenuentry =Diff 00010 menupath =Math/Filter 1D/ 00011 entryplace =Filter 1D 00012 shortentryplace =F1D 00013 abouttext =1D Differentation 00014 smallhelp =1D Differentation 00015 longhelp =1D Differentation 00016 * 00017 * Gxsm Plugin Name: 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: 1dim differentation 00049 % PlugInName: diff 00050 % PlugInAuthor: Percy Zahl, Stefan Schroeder 00051 % PlugInAuthorEmail: zahl@users.sf.net 00052 % PlugInMenuPath: Math/Filter 1D/Diff 00053 00054 % PlugInDescription 00055 One dimensional differentation\dots 00056 00057 % PlugInUsage 00058 Call \GxsmMenu{Math/Filter 1D/Diff}. 00059 This plugin can be called from a 00060 remote-control script with the command \GxsmTT{action('diff\_PI')}. 00061 The kernel-size is then set to '5+1'. 00062 00063 % OptPlugInSources 00064 The active channel is used as data source. 00065 00066 % OptPlugInDest 00067 The computation result is placed into an existing math channel, else 00068 into a new created math channel. 00069 00070 % EndPlugInDocuSection 00071 * -------------------------------------------------------------------------------- 00072 */ 00073 00074 #include <gtk/gtk.h> 00075 #include "config.h" 00076 #include "gxsm/plugin.h" 00077 #include "../../common/pyremote.h" 00078 00079 // Plugin Prototypes 00080 static void diff_init( void ); 00081 static void diff_about( void ); 00082 static void diff_configure( void ); 00083 static void diff_cleanup( void ); 00084 00085 static void diff_non_interactive( GtkWidget *widget , gpointer pc); 00086 00087 // Define Type of math plugin here, only one line should be commented in!! 00088 #define GXSM_ONE_SRC_PLUGIN__DEF 00089 // #define GXSM_TWO_SRC_PLUGIN__DEF 00090 00091 // Math-Run-Function, use only one of (automatically done :=) 00092 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00093 // "OneSrc" Prototype 00094 00095 static gboolean diff_run( Scan *Src, Scan *Dest ); 00096 00097 static gboolean diff_run_radius( Scan *Src, Scan *Dest); 00098 00099 #else 00100 // "TwoSrc" Prototype 00101 static gboolean diff_run( Scan *Src1, Scan *Src2, Scan *Dest ); 00102 #endif 00103 00104 // Fill in the GxsmPlugin Description here 00105 GxsmPlugin diff_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 "diff-" 00115 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00116 "M1S" 00117 #else 00118 "M2S" 00119 #endif 00120 "-F1D", 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 "1D Differentation", 00129 // Author(s) 00130 "Percy Zahl", 00131 // Menupath to position where it is appendet to 00132 N_("_Math/Filter _1D/"), 00133 // Menuentry 00134 N_("Diff"), 00135 // help text shown on menu 00136 N_("1D Differentation"), 00137 // more info... 00138 "1D Differentation", 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 diff_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 diff_about, 00150 // configure-function, can be "NULL" 00151 // can be called by "Plugin Details" 00152 diff_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 diff_cleanup 00159 }; 00160 00161 // special math Plugin-Strucure, use 00162 // GxsmMathOneSrcPlugin diff_m1s_pi -> "OneSrcMath" 00163 // GxsmMathTwoSrcPlugin diff_m2s_pi -> "TwoSrcMath" 00164 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00165 GxsmMathOneSrcPlugin diff_m1s_pi 00166 #else 00167 GxsmMathTwoSrcPlugin diff_m2s_pi 00168 #endif 00169 = { 00170 // math-function to run, see prototype(s) above!! 00171 diff_run 00172 }; 00173 00174 // Text used in Aboutbox, please update!! 00175 static const char *about_text = N_("Gxsm diff Plugin\n\n" 00176 "1D Differentation"); 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 diff_pi.description = g_strdup_printf(N_("Gxsm MathOneArg diff plugin %s"), VERSION); 00182 return &diff_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 &diff_m1s_pi; 00191 } 00192 #else 00193 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 00194 return &diff_m2s_pi; 00195 } 00196 #endif 00197 00198 /* Here we go... */ 00199 // init-Function 00200 static void diff_init(void) 00201 { 00202 PI_DEBUG (DBG_L2, "diff Plugin Init"); 00203 // This is action remote stuff, stolen from the peak finder PI. 00204 remote_action_cb *ra; 00205 GtkWidget *dummywidget = gtk_menu_item_new(); 00206 00207 ra = g_new( remote_action_cb, 1); 00208 ra -> cmd = g_strdup_printf("diff_PI"); 00209 ra -> RemoteCb = &diff_non_interactive; 00210 ra -> widget = dummywidget; 00211 ra -> data = NULL; 00212 gapp->RemoteActionList = g_slist_prepend ( gapp->RemoteActionList, ra ); 00213 PI_DEBUG (DBG_L2, "diff-plugin: Adding new Remote Cmd: diff_PI"); 00214 // remote action stuff 00215 } 00216 00217 static void diff_non_interactive( GtkWidget *widget , gpointer pc ) 00218 { 00219 PI_DEBUG (DBG_L2, "diff-plugin: diff is called from script."); 00220 gapp->xsm->MathOperation(&diff_run_radius); 00221 return; 00222 } 00223 00224 // about-Function 00225 static void diff_about(void) 00226 { 00227 const gchar *authors[] = { diff_pi.authors, NULL}; 00228 gtk_widget_show(gnome_about_new ( diff_pi.name, 00229 VERSION, 00230 N_("(C) 2000 the Free Software Foundation"), 00231 about_text, 00232 authors, 00233 NULL, NULL, NULL 00234 )); 00235 } 00236 00237 // configure-Function 00238 static void diff_configure(void) 00239 { 00240 if(diff_pi.app) 00241 diff_pi.app->message("diff Plugin Configuration"); 00242 } 00243 00244 // cleanup-Function 00245 static void diff_cleanup(void) 00246 { 00247 PI_DEBUG (DBG_L2, "diff Plugin Cleanup"); 00248 } 00249 00250 /* 00251 * 1D differentiation kernel 00252 */ 00253 00254 class Mem1DDiffKrn : public MemDigiFilter{ 00255 public: 00256 Mem1DDiffKrn(double xms, double xns, int m, int n) : MemDigiFilter (xms, xns, m, n){}; 00257 virtual gboolean CalcKernel (){ 00258 int i,j; 00259 for (i= -m; i<=m; i++) 00260 for (j= -n; j<=n; j++) 00261 data->Z(rint(0), j+n, i+m); 00262 00263 for (i = 0, j= -n; j<=n;j++) 00264 data->Z (rint (sin (j)*exp (-(j*j)/(xns*xns))), j+n, i+m); 00265 00266 return 0; 00267 }; 00268 }; 00269 00270 // run-Function 00271 static gboolean diff_run(Scan *Src, Scan *Dest) 00272 { 00273 double r = 5.; // Get Radius 00274 gapp->ValueRequest("1D Convol. Filter Size", "Length", "Diff kernel size: s = 1+length", 00275 gapp->xsm->Unity, 0., Src->mem2d->GetNx()/10., ".0f", &r); 00276 00277 int s = 1+(int)(r + .9); // calc. approx Matrix Radius 00278 Mem1DDiffKrn krn (r,r, s,s); // Setup Kernelobject 00279 krn.Convolve (Src->mem2d, Dest->mem2d); // Do calculation of Kernel and then do convolution 00280 return MATH_OK; 00281 } 00282 00283 00284 00285 static gboolean diff_run_radius(Scan *Src, Scan *Dest) 00286 { // equals diff_run except dialog 00287 double r = 5.; // Get Radius 00288 int s = 1+(int)(r + .9); // calc. approx Matrix Radius 00289 Mem1DDiffKrn krn (r,r, s,s); // Setup Kernelobject 00290 krn.Convolve (Src->mem2d, Dest->mem2d); // Do calculation of Kernel and then do convolution 00291 return MATH_OK; 00292 }