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 * 00007 * Gxsm Plugin Name: parabolregress.C 00008 * ======================================== 00009 * 00010 * Copyright (C) 1999 The Free Software Foundation 00011 * 00012 * Authors: Percy Zahl <zahl@fkp.uni-hannover.de> 00013 * additional features: Andreas Klust <klust@fkp.uni-hannover.de> 00014 * 00015 * This program is free software; you can redistribute it and/or modify 00016 * it under the terms of the GNU General Public License as published by 00017 * the Free Software Foundation; either version 2 of the License, or 00018 * (at your option) any later version. 00019 * 00020 * This program is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * You should have received a copy of the GNU General Public License 00026 * along with this program; if not, write to the Free Software 00027 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 00028 */ 00029 00030 00031 /* Please do not change the Begin/End lines of this comment section! 00032 * this is a LaTeX style section used for auto generation of the PlugIn Manual 00033 * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks! 00034 * All "% PlugInXXX" commentary tags are mandatory 00035 * All "% OptPlugInXXX" tags are optional and can be removed or commented in 00036 * -------------------------------------------------------------------------------- 00037 % BeginPlugInDocuSection 00038 % PlugInDocuCaption: 2nd order scanline correction 00039 % PlugInName: parabolregress 00040 % PlugInAuthor: Stefan Schr\"oder 00041 % PlugInAuthorEmail: stefan_fkp@users.sf.net 00042 % PlugInMenuPath: Math/Background/Line: 2nd order 00043 00044 % PlugInDescription 00045 Second order line by line background correction: The 2nd order best fit of the 00046 Z data of each line is computed and subtracted as background. 00047 00048 This filter can be used for a quick and easy background correction of 00049 sample tilt and possible offset changes inbetween lines. Additionally, the 00050 correction of an overlaying parabola, e.g. due to the geometry of the 00051 experimental setup (bending piezo tube) is 00052 00053 % PlugInUsage 00054 Activate a scan and select \GxsmMenu{Math/Background/Line: 2nd order}. 00055 00056 %% OptPlugInSection: replace this by the section caption 00057 %all following lines until next tag are going into this section 00058 %... 00059 00060 %% OptPlugInSubSection: replace this line by the subsection caption 00061 %all following lines until next tag are going into this subsection 00062 %... 00063 00064 %% you can repeat OptPlugIn(Sub)Sections multiple times! 00065 00066 % OptPlugInSources 00067 The active channel is used as data source. 00068 00069 %% OptPlugInObjects 00070 %A optional rectangle is used for data extraction... 00071 00072 % OptPlugInDest 00073 The result is put into a new created math channel. 00074 00075 %% OptPlugInConfig 00076 %describe the configuration options of your plug in here! 00077 00078 %% OptPlugInFiles 00079 %Does it uses, needs, creates any files? Put info here! 00080 00081 %% OptPlugInRefs 00082 %Any references? 00083 00084 %% OptPlugInKnownBugs 00085 %Are there known bugs? List! How to work around if not fixed? 00086 00087 % OptPlugInNotes 00088 The algorithm is unchecked. 00089 00090 %% OptPlugInHints 00091 %Any tips and tricks? 00092 00093 % EndPlugInDocuSection 00094 * -------------------------------------------------------------------------------- 00095 */ 00096 00097 #include <gtk/gtk.h> 00098 #include "config.h" 00099 #include "gxsm/plugin.h" 00100 00101 // Plugin Prototypes 00102 static void parabolregress_init( void ); 00103 static void parabolregress_about( void ); 00104 static void parabolregress_configure( void ); 00105 static void parabolregress_cleanup( void ); 00106 00107 // Define Type of math plugin here, only one line should be commented in!! 00108 #define GXSM_ONE_SRC_PLUGIN__DEF 00109 // #define GXSM_TWO_SRC_PLUGIN__DEF 00110 00111 // Math-Run-Function, use only one of (automatically done :=) 00112 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00113 // "OneSrc" Prototype 00114 static gboolean parabolregress_run( Scan *Src, Scan *Dest ); 00115 #else 00116 // "TwoSrc" Prototype 00117 static gboolean parabolregress_run( Scan *Src1, Scan *Src2, Scan *Dest ); 00118 #endif 00119 00120 // Fill in the GxsmPlugin Description here 00121 GxsmPlugin parabolregress_pi = { 00122 NULL, // filled in and used by Gxsm, don't touch ! 00123 NULL, // filled in and used by Gxsm, don't touch ! 00124 0, // filled in and used by Gxsm, don't touch ! 00125 NULL, // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 00126 // filled in here by Gxsm on Plugin load, 00127 // just after init() is called !!! 00128 // ---------------------------------------------------------------------- 00129 // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc 00130 "parabolregress-" 00131 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00132 "M1S" 00133 #else 00134 "M2S" 00135 #endif 00136 "-BG", 00137 // Plugin's Category - used to autodecide on Pluginloading or ignoring 00138 // NULL: load, else 00139 // example: "+noHARD +STM +AFM" 00140 // load only, if "+noHARD: no hardware" and Instrument is STM or AFM 00141 // +/-xxxHARD und (+/-INST or ...) 00142 NULL, 00143 // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details) 00144 "Line by line 2nd order background correction.", 00145 // Author(s) 00146 "stefan", 00147 // Menupath to position where it is appendet to 00148 N_("_Math/_Background/"), 00149 // Menuentry 00150 N_("Line: 2nd order"), 00151 // help text shown on menu 00152 N_("Line by line 2nd order regression"), 00153 // more info... 00154 "This plugin does a second order regression on the active scan, line by line.", 00155 NULL, // error msg, plugin may put error status msg here later 00156 NULL, // Plugin Status, managed by Gxsm, plugin may manipulate it too 00157 // init-function pointer, can be "NULL", 00158 // called if present at plugin load 00159 parabolregress_init, 00160 // query-function pointer, can be "NULL", 00161 // called if present after plugin init to let plugin manage it install itself 00162 NULL, // query should be "NULL" for Gxsm-Math-Plugin !!! 00163 // about-function, can be "NULL" 00164 // can be called by "Plugin Details" 00165 parabolregress_about, 00166 // configure-function, can be "NULL" 00167 // can be called by "Plugin Details" 00168 parabolregress_configure, 00169 // run-function, can be "NULL", if non-Zero and no query defined, 00170 // it is called on menupath->"plugin" 00171 NULL, // run should be "NULL" for Gxsm-Math-Plugin !!! 00172 // cleanup-function, can be "NULL" 00173 // called if present at plugin removeal 00174 parabolregress_cleanup 00175 }; 00176 00177 // special math Plugin-Strucure, use 00178 // GxsmMathOneSrcPlugin parabolregress_m1s_pi -> "OneSrcMath" 00179 // GxsmMathTwoSrcPlugin parabolregress_m2s_pi -> "TwoSrcMath" 00180 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00181 GxsmMathOneSrcPlugin parabolregress_m1s_pi 00182 #else 00183 GxsmMathTwoSrcPlugin parabolregress_m2s_pi 00184 #endif 00185 = { 00186 // math-function to run, see prototype(s) above!! 00187 parabolregress_run 00188 }; 00189 00190 // Text used in Aboutbox, please update!! 00191 static const char *about_text = N_("Gxsm parabolregress Plugin\n"); 00192 00193 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 00194 // Essential Plugin Function!! 00195 GxsmPlugin *get_gxsm_plugin_info ( void ){ 00196 parabolregress_pi.description = g_strdup_printf(N_("Gxsm MathOneArg parabolregress plugin %s"), VERSION); 00197 return ¶bolregress_pi; 00198 } 00199 00200 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 00201 // used to find out which Math Type the Plugin is!! 00202 // Essential Plugin Function!! 00203 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00204 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) { 00205 return ¶bolregress_m1s_pi; 00206 } 00207 #else 00208 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 00209 return ¶bolregress_m2s_pi; 00210 } 00211 #endif 00212 00213 /* Here we go... */ 00214 // init-Function 00215 static void parabolregress_init(void) 00216 { 00217 PI_DEBUG (DBG_L2, "parabolregress Plugin Init"); 00218 } 00219 00220 // about-Function 00221 static void parabolregress_about(void) 00222 { 00223 const gchar *authors[] = { parabolregress_pi.authors, NULL}; 00224 gtk_widget_show(gnome_about_new ( parabolregress_pi.name, 00225 VERSION, 00226 N_("(C) 2000 the Free Software Foundation"), 00227 about_text, 00228 authors, 00229 NULL, NULL, NULL 00230 )); 00231 } 00232 00233 // configure-Function 00234 static void parabolregress_configure(void) 00235 { 00236 if(parabolregress_pi.app) 00237 parabolregress_pi.app->message("parabolregress Plugin Configuration"); 00238 } 00239 00240 // cleanup-Function 00241 static void parabolregress_cleanup(void) 00242 { 00243 PI_DEBUG (DBG_L2, "parabolregress Plugin Cleanup"); 00244 } 00245 00246 // run-Function 00247 static gboolean parabolregress_run(Scan *Src, Scan *Dest) 00248 { 00249 // For more math-access methods have a look at xsmmath.C 00250 // simple example for 1sourced Mathoperation: Source is taken and 100 added. 00251 // for(int line=0; line < Dest->mem2d->GetNy (); line++) 00252 // for(int col=0; col < Dest->mem2d->GetNx (); col++) 00253 // Dest->mem2d->PutDataPkt (Src->mem2d->GetDataPkt (line, col) + 100, line, col); 00254 00255 PI_DEBUG (DBG_L2, "Bg Poly2nd 1D Plugin parabolregress"); 00256 00257 double M0, M1, M2, li; 00258 double N = (double)Src->mem2d->GetNx(); 00259 double D = (N*N-1.0)*(N*N-4.0); 00260 double a, b, c, lb; 00261 00262 ZData *SrcZ, *DestZ; 00263 SrcZ = Src->mem2d->data; 00264 DestZ = Dest->mem2d->data; 00265 00266 00267 for (int line=0; line < Src->mem2d->GetNy(); line++) { 00268 00269 SrcZ->SetPtr(0,line); 00270 M0 = 0.0; M1 = 0.0; M2 = 0.0; 00271 00272 for (int col = 0; col < Src->mem2d->GetNx(); col++) { 00273 li = (double)col; 00274 M0 += lb = SrcZ->GetNext(); 00275 M1 += lb * li; 00276 M2 += lb * li*li; 00277 } 00278 00279 M0 /= N; 00280 M1 /= N; 00281 M2 /= N; 00282 00283 a = (3.*(N+1.)*(N+2.)/D)*((3.*N*N+3.*N+2.)*M0-6*(2*N+1.)*M1+10.*M2); 00284 b = 00285 -6./D*(3*(N+1.)*(N+2.)*(2.*N+1.)*M0-2.*(2.*N+1.)*(8.*N+11.)*M1+30.*(N+1.)*M2); 00286 c = 30./D*((N+1.)*(N+2.)*M0-6.*(N+1.)*M1+6.*M2); 00287 00288 SrcZ->SetPtr(0,line); 00289 DestZ->SetPtr(0,line); 00290 00291 for (int col = 0; col < Src->mem2d->GetNx(); col++) { 00292 li = (double)col; 00293 DestZ->SetNext(SrcZ->GetNext() - (a + b*li + c*li*li)); 00294 } 00295 } 00296 return MATH_OK; 00297 } 00298 00299