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 =curvature 00009 pluginmenuentry =Curvature 00010 menupath =Math/Filter 2D/ 00011 entryplace =Filter 2D 00012 shortentryplace =F2D 00013 abouttext =computes curvature 00014 smallhelp =compute curvature 00015 longhelp =computes curvature via convolution 00016 * 00017 * Gxsm Plugin Name: curvature.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: Curvature 00049 % PlugInName: curvature 00050 % PlugInAuthor: Percy Zahl 00051 % PlugInAuthorEmail: zahl@users.sf.net 00052 % PlugInMenuPath: Math/Filter 2D/Curvature 00053 00054 % PlugInDescription 00055 Curvature calculation. 00056 00057 % PlugInUsage 00058 Call \GxsmMenu{Math/Filter 2D/Curvature}. 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 curvature_init( void ); 00077 static void curvature_about( void ); 00078 static void curvature_configure( void ); 00079 static void curvature_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 curvature_run( Scan *Src, Scan *Dest ); 00089 #else 00090 // "TwoSrc" Prototype 00091 static gboolean curvature_run( Scan *Src1, Scan *Src2, Scan *Dest ); 00092 #endif 00093 00094 // Fill in the GxsmPlugin Description here 00095 GxsmPlugin curvature_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 "curvature-" 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 local curvature via convolution.", 00119 // Author(s) 00120 "Percy Zahl", 00121 // Menupath to position where it is appendet to 00122 N_("_Math/Filter _2D/"), 00123 // Menuentry 00124 N_("Curvature"), 00125 // help text shown on menu 00126 N_("compute local curvature"), 00127 // more info... 00128 "Computes local curvature using 2D convolution.", 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 curvature_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 curvature_about, 00140 // configure-function, can be "NULL" 00141 // can be called by "Plugin Details" 00142 curvature_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 curvature_cleanup 00149 }; 00150 00151 // special math Plugin-Strucure, use 00152 // GxsmMathOneSrcPlugin curvature_m1s_pi -> "OneSrcMath" 00153 // GxsmMathTwoSrcPlugin curvature_m2s_pi -> "TwoSrcMath" 00154 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00155 GxsmMathOneSrcPlugin curvature_m1s_pi 00156 #else 00157 GxsmMathTwoSrcPlugin curvature_m2s_pi 00158 #endif 00159 = { 00160 // math-function to run, see prototype(s) above!! 00161 curvature_run 00162 }; 00163 00164 // Text used in Aboutbox, please update!! 00165 static const char *about_text = N_("Gxsm curvature Plugin\n\n" 00166 "Computes the local curvature using convolution."); 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 curvature_pi.description = g_strdup_printf(N_("Gxsm MathOneArg curvature plugin %s"), VERSION); 00172 return &curvature_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 &curvature_m1s_pi; 00181 } 00182 #else 00183 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 00184 return &curvature_m2s_pi; 00185 } 00186 #endif 00187 00188 /* Here we go... */ 00189 // init-Function 00190 static void curvature_init(void) 00191 { 00192 PI_DEBUG (DBG_L2, "curvature Plugin Init"); 00193 } 00194 00195 // about-Function 00196 static void curvature_about(void) 00197 { 00198 const gchar *authors[] = { curvature_pi.authors, NULL}; 00199 gtk_widget_show(gnome_about_new ( curvature_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 curvature_configure(void) 00210 { 00211 if(curvature_pi.app) 00212 curvature_pi.app->message("curvature Plugin Configuration"); 00213 } 00214 00215 // cleanup-Function 00216 static void curvature_cleanup(void) 00217 { 00218 PI_DEBUG (DBG_L2, "curvature Plugin Cleanup"); 00219 } 00220 00221 /* 00222 * use curvature (second derivative) as height [lderiv_kernel] 00223 */ 00224 00225 class MemCurvatureKrn : public MemDigiFilter{ 00226 public: 00227 MemCurvatureKrn (double xms, double xns, int m, int n) : MemDigiFilter (xms, xns, m, n){}; 00228 virtual gboolean CalcKernel (){ 00229 int i; 00230 double c0 = 6.0, c1=4.0; 00231 double ksump, kasump; 00232 00233 if (xms < 0.5) xms = 0.5; 00234 if (xns < 0.5) xns = 0.5; 00235 double asum = 5 + 8*xns*xms; 00236 do{ 00237 kasump = ksump = 0.; 00238 for (i= -m;i<=m;i++) { 00239 int j; 00240 double isq = i*i/xms; 00241 for (j= -n;j<=n;j++) { 00242 double i_jsq = j*j/xns+isq; 00243 data->Z (ksump += (c0-c1*i_jsq)*exp(-i_jsq), j+n,i+m); 00244 kasump += fabs (data->Z(j+n,i+m)); 00245 } 00246 } 00247 if (kasump < asum) 00248 c0 /= 0.9 + 0.1*kasump/asum; 00249 if (ksump > 0) 00250 c1 += 0.3*c1*ksump/(double)kasump; 00251 else if (ksump < 0) { 00252 c1 += 0.1*c1*ksump/(double)kasump; 00253 c0 -= 0.1*c0*ksump/(double)kasump; 00254 } 00255 }while (fabs (ksump) > 0.3); // != 0 00256 data->Zadd (-ksump, n,m); 00257 return 0; 00258 }; 00259 }; 00260 00261 // run-Function 00262 static gboolean curvature_run(Scan *Src, Scan *Dest) 00263 { 00264 double r = 5.; // Get Radius 00265 gapp->ValueRequest("2D Convol. Filter Size", "Radius", "Curvature kernel size: s = 1+radius", 00266 gapp->xsm->Unity, 0., Src->mem2d->GetNx()/10., ".0f", &r); 00267 int s = 1+(int)(r + .9); 00268 MemCurvatureKrn krn (r,r, s,s); 00269 krn.Convolve (Src->mem2d, Dest->mem2d); 00270 return MATH_OK; 00271 } 00272 00273