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 =bg_z_drift 00009 pluginmenuentry =Z drift correct 00010 menupath =Math/Background/ 00011 entryplace =Background 00012 shortentryplace =BG 00013 abouttext =Corrects a slow and smooth Z drifting using a polynominal fit. 00014 smallhelp =smooth Z drift correction 00015 longhelp =Corrects a slow and smooth Z drifting using a polynominal fit. 00016 * 00017 * Gxsm Plugin Name: bg_z_drift.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 Z drift correction 00049 % PlugInName: bg_z_drift 00050 % PlugInAuthor: Percy Zahl 00051 % PlugInAuthorEmail: zahl@users.sf.net 00052 % PlugInMenuPath: Math/Background/Z drift correct 00053 00054 % PlugInDescription 00055 Corrects a slow and smooth variing Z drift using a polynominal fit for 00056 averaged line heights. 00057 00058 % PlugInUsage 00059 Call \GxsmMenu{Math/Background/Z drift correct}. It asks for the 00060 degree ($2, 3, 4, \dots 13$) used for the polynominal (least squares) 00061 fit, $5$th order is the default. 00062 00063 % OptPlugInSources 00064 The active channel is used as data source. 00065 00066 % OptPlugInObjects 00067 A optional rectangle can be used to restrict the X range used for 00068 calculation the average scan line height. The Y coordinates of the 00069 rectangle are ignored. 00070 00071 % OptPlugInDest 00072 The computation result is placed into an existing math channel, else 00073 into a new created math channel. 00074 00075 %% OptPlugInNotes 00076 %If you have any additional notes 00077 00078 %% OptPlugInHints 00079 %Any tips and tricks? 00080 00081 % EndPlugInDocuSection 00082 * -------------------------------------------------------------------------------- 00083 */ 00084 00085 #include <gtk/gtk.h> 00086 #include "config.h" 00087 #include "gxsm/plugin.h" 00088 #include "gxsm/regress.h" 00089 00090 // Plugin Prototypes 00091 static void bg_z_drift_init( void ); 00092 static void bg_z_drift_about( void ); 00093 static void bg_z_drift_configure( void ); 00094 static void bg_z_drift_cleanup( void ); 00095 00096 // Define Type of math plugin here, only one line should be commented in!! 00097 #define GXSM_ONE_SRC_PLUGIN__DEF 00098 // #define GXSM_TWO_SRC_PLUGIN__DEF 00099 00100 // Math-Run-Function, use only one of (automatically done :=) 00101 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00102 // "OneSrc" Prototype 00103 static gboolean bg_z_drift_run( Scan *Src, Scan *Dest ); 00104 #else 00105 // "TwoSrc" Prototype 00106 static gboolean bg_z_drift_run( Scan *Src1, Scan *Src2, Scan *Dest ); 00107 #endif 00108 00109 // Fill in the GxsmPlugin Description here 00110 GxsmPlugin bg_z_drift_pi = { 00111 NULL, // filled in and used by Gxsm, don't touch ! 00112 NULL, // filled in and used by Gxsm, don't touch ! 00113 0, // filled in and used by Gxsm, don't touch ! 00114 NULL, // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 00115 // filled in here by Gxsm on Plugin load, 00116 // just after init() is called !!! 00117 // ---------------------------------------------------------------------- 00118 // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc 00119 "bg_z_drift-" 00120 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00121 "M1S" 00122 #else 00123 "M2S" 00124 #endif 00125 "-BG", 00126 // Plugin's Category - used to autodecide on Pluginloading or ignoring 00127 // NULL: load, else 00128 // example: "+noHARD +STM +AFM" 00129 // load only, if "+noHARD: no hardware" and Instrument is STM or AFM 00130 // +/-xxxHARD und (+/-INST or ...) 00131 NULL, 00132 // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details) 00133 "Corrects a slow and smooth Z drifting using a polynominal fit.", 00134 // Author(s) 00135 "Percy Zahl", 00136 // Menupath to position where it is appendet to 00137 N_("_Math/_Background/"), 00138 // Menuentry 00139 N_("Z drift correct"), 00140 // help text shown on menu 00141 N_("Corrects a slow and smooth Z drifting using a polynominal fit."), 00142 // more info... 00143 "smooth Z drift correction", 00144 NULL, // error msg, plugin may put error status msg here later 00145 NULL, // Plugin Status, managed by Gxsm, plugin may manipulate it too 00146 // init-function pointer, can be "NULL", 00147 // called if present at plugin load 00148 bg_z_drift_init, 00149 // query-function pointer, can be "NULL", 00150 // called if present after plugin init to let plugin manage it install itself 00151 NULL, // query should be "NULL" for Gxsm-Math-Plugin !!! 00152 // about-function, can be "NULL" 00153 // can be called by "Plugin Details" 00154 bg_z_drift_about, 00155 // configure-function, can be "NULL" 00156 // can be called by "Plugin Details" 00157 bg_z_drift_configure, 00158 // run-function, can be "NULL", if non-Zero and no query defined, 00159 // it is called on menupath->"plugin" 00160 NULL, // run should be "NULL" for Gxsm-Math-Plugin !!! 00161 // cleanup-function, can be "NULL" 00162 // called if present at plugin removeal 00163 bg_z_drift_cleanup 00164 }; 00165 00166 // special math Plugin-Strucure, use 00167 // GxsmMathOneSrcPlugin bg_z_drift_m1s_pi -> "OneSrcMath" 00168 // GxsmMathTwoSrcPlugin bg_z_drift_m2s_pi -> "TwoSrcMath" 00169 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00170 GxsmMathOneSrcPlugin bg_z_drift_m1s_pi 00171 #else 00172 GxsmMathTwoSrcPlugin bg_z_drift_m2s_pi 00173 #endif 00174 = { 00175 // math-function to run, see prototype(s) above!! 00176 bg_z_drift_run 00177 }; 00178 00179 // Text used in Aboutbox, please update!! 00180 static const char *about_text = N_("Gxsm bg_z_drift Plugin\n\n" 00181 "Corrects a slow and smooth Z drifting using a polynominal fit."); 00182 00183 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 00184 // Essential Plugin Function!! 00185 GxsmPlugin *get_gxsm_plugin_info ( void ){ 00186 bg_z_drift_pi.description = g_strdup_printf(N_("Gxsm MathOneArg bg_z_drift plugin %s"), VERSION); 00187 return &bg_z_drift_pi; 00188 } 00189 00190 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 00191 // used to find out which Math Type the Plugin is!! 00192 // Essential Plugin Function!! 00193 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00194 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) { 00195 return &bg_z_drift_m1s_pi; 00196 } 00197 #else 00198 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 00199 return &bg_z_drift_m2s_pi; 00200 } 00201 #endif 00202 00203 /* Here we go... */ 00204 // init-Function 00205 static void bg_z_drift_init(void) 00206 { 00207 PI_DEBUG (DBG_L2, "bg_z_drift Plugin Init"); 00208 } 00209 00210 // about-Function 00211 static void bg_z_drift_about(void) 00212 { 00213 const gchar *authors[] = { bg_z_drift_pi.authors, NULL}; 00214 gtk_widget_show(gnome_about_new ( bg_z_drift_pi.name, 00215 VERSION, 00216 N_("(C) 2000 the Free Software Foundation"), 00217 about_text, 00218 authors, 00219 NULL, NULL, NULL 00220 )); 00221 } 00222 00223 // configure-Function 00224 static void bg_z_drift_configure(void) 00225 { 00226 if(bg_z_drift_pi.app) 00227 bg_z_drift_pi.app->message("bg_z_drift Plugin Configuration"); 00228 } 00229 00230 // cleanup-Function 00231 static void bg_z_drift_cleanup(void) 00232 { 00233 PI_DEBUG (DBG_L2, "bg_z_drift Plugin Cleanup"); 00234 } 00235 00236 // run-Function 00237 static gboolean bg_z_drift_run(Scan *Src, Scan *Dest) 00238 { 00239 int line, col, order=3; 00240 double UsrOrder; 00241 double *YProfile; 00242 double *YProfileX; 00243 double py; 00244 MOUSERECT msr; 00245 00246 MkMausSelect(Src->Pkt2d, &msr, Dest->mem2d->GetNx(), Dest->mem2d->GetNy()); 00247 00248 if( msr.xSize < 1 || msr.ySize < 1) 00249 return MATH_SELECTIONERR; 00250 00251 YProfile = new double[Src->mem2d->GetNy()]; 00252 YProfileX = new double[Src->mem2d->GetNy()]; 00253 00254 PI_DEBUG (DBG_L3, "X-left:" << msr.xLeft << " X-right:" << msr.xRight); 00255 00256 for(line=0; line < Dest->mem2d->GetNy(); line++){ 00257 YProfile[line] = 0.; 00258 YProfileX[line] = (double)line; 00259 for(col=msr.xLeft; col < msr.xRight; col++) 00260 YProfile[line] += Src->mem2d->GetDataPkt(col,line); 00261 YProfile[line] /= (double)msr.xSize; 00262 } 00263 00264 UsrOrder=5.; 00265 gapp->ValueRequest("Enter Value", "Order", "I need the order of regression polynom.", 00266 gapp->xsm->Unity, 2., 13., ".0f", &UsrOrder); 00267 00268 order = (int)UsrOrder; if(order < 2 || order > 13) order=3; 00269 StatInp s(order, YProfileX, YProfile, Src->mem2d->GetNy()); 00270 00271 std::ofstream poly; 00272 poly.open("/tmp/poly.asc", std::ios::out); 00273 00274 for(line=0; line<Dest->data.s.ny; line++){ 00275 py = s.GetPoly((double)line); 00276 poly << YProfileX[line] << " " << YProfile[line] << " " << py << std::endl; 00277 for(col=0; col<Dest->data.s.nx; col++) 00278 Dest->mem2d->PutDataPkt(Src->mem2d->GetDataPkt(col,line) - py, col, line); 00279 } 00280 00281 poly.close(); 00282 00283 return MATH_OK; 00284 }