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 =local_height 00009 pluginmenuentry =Local height 00010 menupath =Math/Filter 2D/ 00011 entryplace =Filter 2D 00012 shortentryplace =F2D 00013 abouttext =computes locale height using a convolution filter 00014 smallhelp =compute local height 00015 longhelp =computes locale height using a convolution filter 00016 * 00017 * Gxsm Plugin Name: local_height.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: Local height 00049 % PlugInName: local_height 00050 % PlugInAuthor: Percy Zahl 00051 % PlugInAuthorEmail: zahl@users.sf.net 00052 % PlugInMenuPath: Math/Filter 2D/Local height 00053 00054 % PlugInDescription 00055 Computes the local height via convolution. 00056 00057 % PlugInUsage 00058 Call \GxsmMenu{Math/Filter 2D/Local height}. 00059 00060 % OptPlugInSources 00061 The active channel is used as data source. 00062 00063 % OptPlugInDest 00064 The computation result is placed into an existing math channel, else 00065 into a new created math channel. 00066 00067 % EndPlugInDocuSection 00068 * -------------------------------------------------------------------------------- 00069 */ 00070 00071 #include <gtk/gtk.h> 00072 #include "config.h" 00073 #include "gxsm/plugin.h" 00074 00075 // Plugin Prototypes 00076 static void local_height_init( void ); 00077 static void local_height_about( void ); 00078 static void local_height_configure( void ); 00079 static void local_height_cleanup( void ); 00080 00081 // Define Type of math plugin here, only one line should be commented in!! 00082 #define GXSM_ONE_SRC_PLUGIN__DEF 00083 // #define GXSM_TWO_SRC_PLUGIN__DEF 00084 00085 // Math-Run-Function, use only one of (automatically done :=) 00086 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00087 // "OneSrc" Prototype 00088 static gboolean local_height_run( Scan *Src, Scan *Dest ); 00089 #else 00090 // "TwoSrc" Prototype 00091 static gboolean local_height_run( Scan *Src1, Scan *Src2, Scan *Dest ); 00092 #endif 00093 00094 // Fill in the GxsmPlugin Description here 00095 GxsmPlugin local_height_pi = { 00096 NULL, // filled in and used by Gxsm, don't touch ! 00097 NULL, // filled in and used by Gxsm, don't touch ! 00098 0, // filled in and used by Gxsm, don't touch ! 00099 NULL, // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 00100 // filled in here by Gxsm on Plugin load, 00101 // just after init() is called !!! 00102 // ---------------------------------------------------------------------- 00103 // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc 00104 "local_height-" 00105 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00106 "M1S" 00107 #else 00108 "M2S" 00109 #endif 00110 "-F2D", 00111 // Plugin's Category - used to autodecide on Pluginloading or ignoring 00112 // NULL: load, else 00113 // example: "+noHARD +STM +AFM" 00114 // load only, if "+noHARD: no hardware" and Instrument is STM or AFM 00115 // +/-xxxHARD und (+/-INST or ...) 00116 NULL, 00117 // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details) 00118 "computes locale height using a convolution filter", 00119 // Author(s) 00120 "Percy Zahl", 00121 // Menupath to position where it is appendet to 00122 N_("_Math/Filter _2D/"), 00123 // Menuentry 00124 N_("Local height"), 00125 // help text shown on menu 00126 N_("computes locale height using a convolution filter"), 00127 // more info... 00128 "compute local height", 00129 NULL, // error msg, plugin may put error status msg here later 00130 NULL, // Plugin Status, managed by Gxsm, plugin may manipulate it too 00131 // init-function pointer, can be "NULL", 00132 // called if present at plugin load 00133 local_height_init, 00134 // query-function pointer, can be "NULL", 00135 // called if present after plugin init to let plugin manage it install itself 00136 NULL, // query should be "NULL" for Gxsm-Math-Plugin !!! 00137 // about-function, can be "NULL" 00138 // can be called by "Plugin Details" 00139 local_height_about, 00140 // configure-function, can be "NULL" 00141 // can be called by "Plugin Details" 00142 local_height_configure, 00143 // run-function, can be "NULL", if non-Zero and no query defined, 00144 // it is called on menupath->"plugin" 00145 NULL, // run should be "NULL" for Gxsm-Math-Plugin !!! 00146 // cleanup-function, can be "NULL" 00147 // called if present at plugin removeal 00148 local_height_cleanup 00149 }; 00150 00151 // special math Plugin-Strucure, use 00152 // GxsmMathOneSrcPlugin local_height_m1s_pi -> "OneSrcMath" 00153 // GxsmMathTwoSrcPlugin local_height_m2s_pi -> "TwoSrcMath" 00154 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00155 GxsmMathOneSrcPlugin local_height_m1s_pi 00156 #else 00157 GxsmMathTwoSrcPlugin local_height_m2s_pi 00158 #endif 00159 = { 00160 // math-function to run, see prototype(s) above!! 00161 local_height_run 00162 }; 00163 00164 // Text used in Aboutbox, please update!! 00165 static const char *about_text = N_("Gxsm local_height Plugin\n\n" 00166 "computes locale height using a convolution filter"); 00167 00168 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 00169 // Essential Plugin Function!! 00170 GxsmPlugin *get_gxsm_plugin_info ( void ){ 00171 local_height_pi.description = g_strdup_printf(N_("Gxsm MathOneArg local_height plugin %s"), VERSION); 00172 return &local_height_pi; 00173 } 00174 00175 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 00176 // used to find out which Math Type the Plugin is!! 00177 // Essential Plugin Function!! 00178 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00179 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) { 00180 return &local_height_m1s_pi; 00181 } 00182 #else 00183 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 00184 return &local_height_m2s_pi; 00185 } 00186 #endif 00187 00188 /* Here we go... */ 00189 // init-Function 00190 static void local_height_init(void) 00191 { 00192 PI_DEBUG (DBG_L2, "local_height Plugin Init"); 00193 } 00194 00195 // about-Function 00196 static void local_height_about(void) 00197 { 00198 const gchar *authors[] = { local_height_pi.authors, NULL}; 00199 gtk_widget_show(gnome_about_new ( local_height_pi.name, 00200 VERSION, 00201 N_("(C) 2000 the Free Software Foundation"), 00202 about_text, 00203 authors, 00204 NULL, NULL, NULL 00205 )); 00206 } 00207 00208 // configure-Function 00209 static void local_height_configure(void) 00210 { 00211 if(local_height_pi.app) 00212 local_height_pi.app->message("local_height Plugin Configuration"); 00213 } 00214 00215 // cleanup-Function 00216 static void local_height_cleanup(void) 00217 { 00218 PI_DEBUG (DBG_L2, "local_height Plugin Cleanup"); 00219 } 00220 00221 /* 00222 * Local Height Kernel 00223 */ 00224 00225 class MemLclhtKrn : public MemDigiFilter{ 00226 public: 00227 MemLclhtKrn(double xms, double xns, int m, int n) : MemDigiFilter (xms, xns, m, n){}; 00228 virtual gboolean CalcKernel(){ 00229 int i; 00230 const double r_squared = 7.0; 00231 double c0 = 5.0; 00232 double c1 = c0/r_squared; 00233 double ksump, kasump; 00234 00235 if(xms < 0.5) xms = 0.5; 00236 if(xns < 0.5) xns = 0.5; 00237 const double asum = 5 + 8*xns*xms; 00238 do{ 00239 kasump = ksump=0.; 00240 for(i= -m;i<=m;i++) { 00241 int j; 00242 const double isq = i*i/xms; 00243 for(j= -n;j<=n;j++) { 00244 const double i_jsq = j*j/xns + isq; 00245 data->Z( ksump += c0*exp(-i_jsq)-c1*i_jsq*exp(-i_jsq/r_squared), 00246 j+n, i+m); 00247 kasump += fabs(data->Z(j+n,i+m)); 00248 } 00249 } 00250 if(kasump < asum) 00251 c0 /= 0.9 + 0.1*kasump/asum; 00252 if(ksump > 0) 00253 c1 += 0.3*c1*ksump/(double)kasump; 00254 else if(ksump < 0) { 00255 c1 += 0.1*c1*ksump/(double)kasump; 00256 c0 -= 0.1*c0*ksump/(double)kasump; 00257 } 00258 } while(fabs(ksump) > 0.3); // != 0 00259 return 0; 00260 }; 00261 }; 00262 00263 // run-Function 00264 static gboolean local_height_run(Scan *Src, Scan *Dest) 00265 { 00266 double r = 5.; // Get Radius 00267 gapp->ValueRequest("2D Convol. Filter Size", "Radius", "Local Height kernel size: s = 1+radius", 00268 gapp->xsm->Unity, 0., Src->mem2d->GetNx()/10., ".0f", &r); 00269 int s = 1+(int)(r + .9); 00270 MemLclhtKrn krn(r,r, s,s); 00271 krn.Convolve(Src->mem2d, Dest->mem2d); 00272 return MATH_OK; 00273 } 00274 00275