OctoCorr.C

Go to the documentation of this file.
00001 /* Gnome gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  *
00005  * Quick nine points Gxsm Plugin GUIDE by PZ:
00006  * ------------------------------------------------------------
00007  * 1.) Make a copy of this "OctoCorr.C" to "your_plugins_name.C"!
00008  * 2.) Replace all "OctoCorr" by "your_plugins_name" 
00009  *     --> please do a search and replace starting here NOW!! (Emacs doese preserve caps!)
00010  * 3.) Decide: One or Two Source Math: see line 54
00011  * 4.) Fill in GxsmPlugin Structure, see below
00012  * 5.) Replace the "about_text" below a desired
00013  * 6.) * Optional: Start your Code/Vars definition below (if needed more than the run-fkt itself!), 
00014  *       Goto Line 155 ff. please, and see comment there!!
00015  * 7.) Fill in math code in OctoCorr_run(), 
00016  *     have a look at the Data-Access methods infos at end
00017  * 8.) Add OctoCorr.C to the Makefile.am in analogy to others
00018  * 9.) Make a "make; make install"
00019  * A.) Call Gxsm->Tools->reload Plugins, be happy!
00020  * ... That's it!
00021  * 
00022  * Gxsm Plugin Name: OctoCorr.C
00023  * ========================================
00024  * 
00025  * Copyright (C) 1999 The Free Software Foundation
00026  *
00027  * Authors: Percy Zahl <zahl@fkp.uni-hannover.de>
00028  * additional features: Andreas Klust <klust@fkp.uni-hannover.de>
00029  *
00030  * This program is free software; you can redistribute it and/or modify
00031  * it under the terms of the GNU General Public License as published by
00032  * the Free Software Foundation; either version 2 of the License, or
00033  * (at your option) any later version.
00034  *
00035  * This program is distributed in the hope that it will be useful,
00036  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00037  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00038  * GNU General Public License for more details.
00039  *
00040  * You should have received a copy of the GNU General Public License
00041  * along with this program; if not, write to the Free Software
00042  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00043  */
00044 
00045 /* Please do not change the Begin/End lines of this comment section!
00046  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00047  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00048  * All "% PlugInXXX" commentary tags are mandatory
00049  * All "% OptPlugInXXX" tags are optional
00050  * --------------------------------------------------------------------------------
00051 % BeginPlugInDocuSection
00052 % PlugInDocuCaption: SPA--LEED octopole distorsion correction
00053 % PlugInName: OctoCorr
00054 % PlugInAuthor: Percy Zahl
00055 % PlugInAuthorEmail: zahl@users.sf.net
00056 % PlugInMenuPath: Math/Transformation/Octo Corr
00057 
00058 % PlugInDescription
00059 This is a experimental filter to reduce the SPA--LEED typical octopole
00060 cuishion distorsion using a "ab-initio" like approch.  This plugin
00061 applies the inverse of this distorsion to any image.
00062 
00063 Input parameters are: Energy, Stepsize and Origin (invariant Point, if
00064 not set the user is prompted for coordinates!).  A free parameter $b$
00065 (distorsion strength, may be left at default value (-0.4)).
00066 
00067 % PlugInUsage
00068 Place a point object and call \GxsmMenu{Math/Transformation/Octo
00069 Corr}.
00070 
00071 % OptPlugInSources
00072 The active channel is used as data source.
00073 
00074 % OptPlugInObjects
00075 A point object is needed to mark the center of distorsion symmetry
00076 (invariant point).
00077 
00078 % OptPlugInDest
00079 The computation result is placed into an existing math channel, 
00080 else into a new created math channel.
00081 
00082 %% OptPlugInConfig
00083 %
00084 
00085 %% OptPlugInNotes
00086 %
00087 
00088 %% OptPlugInHints
00089 %
00090 
00091 % EndPlugInDocuSection
00092  * -------------------------------------------------------------------------------- 
00093  */
00094 
00095 #include <gtk/gtk.h>
00096 #include "config.h"
00097 #include "gxsm/plugin.h"
00098 
00099 // Plugin Prototypes
00100 static void OctoCorr_init( void );
00101 static void OctoCorr_about( void );
00102 static void OctoCorr_configure( void );
00103 static void OctoCorr_cleanup( void );
00104 
00105 // Define Type of math plugin here, only one line should be commented in!!
00106 #define GXSM_ONE_SRC_PLUGIN__DEF
00107 // #define GXSM_TWO_SRC_PLUGIN__DEF
00108 
00109 // Math-Run-Function, use only one of (automatically done :=)
00110 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00111 // "OneSrc" Prototype
00112  static gboolean OctoCorr_run( Scan *Src, Scan *Dest );
00113 #else
00114 // "TwoSrc" Prototype
00115  static gboolean OctoCorr_run( Scan *Src1, Scan *Src2, Scan *Dest );
00116 #endif
00117 
00118 // Fill in the GxsmPlugin Description here
00119 GxsmPlugin OctoCorr_pi = {
00120   NULL,                   // filled in and used by Gxsm, don't touch !
00121   NULL,                   // filled in and used by Gxsm, don't touch !
00122   0,                      // filled in and used by Gxsm, don't touch !
00123   NULL,                   // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 
00124                           // filled in here by Gxsm on Plugin load, 
00125                           // just after init() is called !!!
00126   // ----------------------------------------------------------------------
00127   // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc
00128   "OctoCorr-"
00129 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00130   "M1S"
00131 #else
00132   "M2S"
00133 #endif
00134   "-TR",
00135   // Plugin's Category - used to autodecide on Pluginloading or ignoring
00136   // NULL: load, else
00137   // example: "+noHARD +STM +AFM"
00138   // load only, if "+noHARD: no hardware" and Instrument is STM or AFM
00139   // +/-xxxHARD und (+/-INST or ...)
00140   NULL,
00141   // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details)
00142   " Octopole Correction, use for SPA-LEED image geometry correction",
00143   // Author(s)
00144   "Percy Zahl",
00145   // Menupath to position where it is appendet to
00146   N_("_Math/_Transformations/"),
00147   // Menuentry
00148   N_("OctoCorr"),
00149   // help text shown on menu
00150   N_("for SPA-LEED: to correct octopole distorsions"),
00151   // more info...
00152   "no more info",
00153   NULL,          // error msg, plugin may put error status msg here later
00154   NULL,          // Plugin Status, managed by Gxsm, plugin may manipulate it too
00155   // init-function pointer, can be "NULL", 
00156   // called if present at plugin load
00157   OctoCorr_init,  
00158   // query-function pointer, can be "NULL", 
00159   // called if present after plugin init to let plugin manage it install itself
00160   NULL, // query should be "NULL" for Gxsm-Math-Plugin !!!
00161   // about-function, can be "NULL"
00162   // can be called by "Plugin Details"
00163   OctoCorr_about,
00164   // configure-function, can be "NULL"
00165   // can be called by "Plugin Details"
00166   OctoCorr_configure,
00167   // run-function, can be "NULL", if non-Zero and no query defined, 
00168   // it is called on menupath->"plugin"
00169   NULL, // run should be "NULL" for Gxsm-Math-Plugin !!!
00170   // cleanup-function, can be "NULL"
00171   // called if present at plugin removeal
00172   OctoCorr_cleanup
00173 };
00174 
00175 // special math Plugin-Strucure, use
00176 // GxsmMathOneSrcPlugin OctoCorr_m1s_pi -> "OneSrcMath"
00177 // GxsmMathTwoSrcPlugin OctoCorr_m2s_pi -> "TwoSrcMath"
00178 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00179  GxsmMathOneSrcPlugin OctoCorr_m1s_pi
00180 #else
00181  GxsmMathTwoSrcPlugin OctoCorr_m2s_pi
00182 #endif
00183  = {
00184    // math-function to run, see prototype(s) above!!
00185    OctoCorr_run
00186  };
00187 
00188 // Text used in Aboutbox, please update!!
00189 static const char *about_text = N_("Gxsm OctoCorr Plugin\n\n"
00190                                    "The SPA-LEED octopole causes a cushion distorsion\n"
00191                                    "of the electron deflection.\n"
00192                                    "This pluging applies the inverse of this distorsion to\n"
00193                                    "any image.\n"
00194                                    "Input parameters are:\n"
00195                                    " Energy, Stepsize and Origin (invariant Point)\n"
00196                                    " Free parameter \"b\" (distorsion strength)\n"
00197                                    );
00198 
00199 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00200 // Essential Plugin Function!!
00201 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00202   OctoCorr_pi.description = g_strdup_printf(N_("Gxsm MathOneArg OctoCorr plugin %s"), VERSION);
00203   return &OctoCorr_pi; 
00204 }
00205 
00206 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 
00207 // used to find out which Math Type the Plugin is!! 
00208 // Essential Plugin Function!!
00209 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00210 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) {
00211   return &OctoCorr_m1s_pi; 
00212 }
00213 #else
00214 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 
00215   return &OctoCorr_m2s_pi; 
00216 }
00217 #endif
00218 
00219 // 5.) Start here with the plugins code, vars def., etc.... here.
00220 // ----------------------------------------------------------------------
00221 //
00222 
00223 
00224 // init-Function
00225 static void OctoCorr_init(void)
00226 {
00227   PI_DEBUG (DBG_L2, "OctoCorr Plugin Init");
00228 }
00229 
00230 // about-Function
00231 static void OctoCorr_about(void)
00232 {
00233   const gchar *authors[] = { OctoCorr_pi.authors, NULL};
00234   gtk_widget_show(gnome_about_new ( OctoCorr_pi.name,
00235                                     VERSION,
00236                                     N_("(C) 2000 the Free Software Foundation"),
00237                                     about_text,
00238                                     authors,
00239                                     NULL, NULL, NULL
00240                                     ));
00241 }
00242 
00243 // configure-Function
00244 static void OctoCorr_configure(void)
00245 {
00246   if(OctoCorr_pi.app)
00247     OctoCorr_pi.app->message("OctoCorr Plugin Configuration");
00248 }
00249 
00250 // cleanup-Function
00251 static void OctoCorr_cleanup(void)
00252 {
00253   PI_DEBUG (DBG_L2, "OctoCorr Plugin Cleanup");
00254 }
00255 
00256 
00257 // run-Function
00258 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00259  static gboolean OctoCorr_run(Scan *Src, Scan *Dest)
00260 #else
00261  static gboolean OctoCorr_run(Scan *Src1, Scan *Src2, Scan *Dest)
00262 #endif
00263 {
00264   // put plugins math code here...
00265   int i,j;
00266   double jj,ii;
00267   double Ux, Uy, U, E, s, a, b;
00268   double Ldx, Ldy, nX0, nY0, Ux0, Uy0;
00269 
00270   E = Src->data.s.Energy;
00271   OctoCorr_pi.app->ValueRequest("Enter Value", "Energy", 
00272                                 "I need the scan Energy.",
00273                                 OctoCorr_pi.app->xsm->EnergyUnit, 
00274                                 0.1, 500., ".2f", &E);
00275   Ldx = Src->data.s.dx;
00276   OctoCorr_pi.app->ValueRequest("Enter Value", "Ldx", 
00277                                 "dx, X step size.",
00278                                 OctoCorr_pi.app->xsm->VoltUnit, 
00279                                 1e-5, 10., ".2f", &Ldx);
00280   Ldy = Src->data.s.dy;
00281   OctoCorr_pi.app->ValueRequest("Enter Value", "Ldy", 
00282                                 "dy, Y step size.",
00283                                 OctoCorr_pi.app->xsm->VoltUnit, 
00284                                 1e-5, 10., ".2f", &Ldy);
00285 
00286   if(Src->PktVal == 1){
00287     nX0 = Src->Pkt2d[0].x;
00288     nY0 = Src->Pkt2d[0].y;
00289   }else{
00290     nX0 = Src->data.s.x0/Ldx; // + .SPA_OrgX;
00291     nY0 = Src->data.s.y0/Ldy; // + .SPA_OrgX;
00292     OctoCorr_pi.app->ValueRequest("Enter Value", "X index",
00293                                   "invariant Point (can use Point Obj!)", 
00294                                   OctoCorr_pi.app->xsm->Unity, 
00295                                   -1000, 1000., ".2f", &nX0);
00296     
00297     OctoCorr_pi.app->ValueRequest("Enter Value", "Y index",
00298                                   "invariant Point (can use Point Obj!)", 
00299                                   OctoCorr_pi.app->xsm->Unity, 
00300                                   -1000., 1000., ".2f", &nY0);
00301   }
00302 
00303   Ux0 = ((double)nX0-(double)Src->data.s.nx/2.)*Ldx;
00304   Uy0 = ((double)nY0-(double)Src->data.s.ny/2.)*Ldy;
00305 
00306 #define xMap(I) (Ux0+((double)(I)-(double)Src->data.s.nx/2.)*Ldx)
00307 #define yMap(I) (Uy0+((double)(I)-(double)Src->data.s.ny/2.)*Ldy)
00308 
00309   //  b = -0.22;
00310   b = -0.4;
00311 
00312   OctoCorr_pi.app->ValueRequest("Enter Value", "b (strength)", 
00313                                 "may not be changed!",
00314                                 OctoCorr_pi.app->xsm->Unity, 
00315                                 -2., 2., ".2f", &b);
00316 
00317   Ux = xMap(Src->data.s.nx); Uy=yMap(Src->data.s.ny);
00318   U  = sqrt(Ux*Ux + Uy*Uy);
00319   a  = 1. - b*U/E;
00320   for(i=0; i<Dest->mem2d->GetNy(); i++){
00321     Uy = yMap(i);
00322     for(j=0; j<Dest->mem2d->GetNx(); j++){
00323       Ux = xMap(j);
00324       U = sqrt(Ux*Ux + Uy*Uy);
00325       s = a + b*sqrt(U/E);
00326       jj = (double)(j-nX0)*s + nX0;
00327       ii = (double)(i-nY0)*s + nY0;
00328       if(ii >= (double)(Dest->mem2d->GetNy()-1) 
00329          || jj >= (double)(Dest->mem2d->GetNx()-1) || ii < 1. || jj < 1.)
00330         Dest->mem2d->PutDataPkt(0., j,i);
00331       else
00332         Dest->mem2d->PutDataPkt(Src->mem2d->GetDataPktInterpol(jj,ii), j,i);
00333     }
00334   }
00335 
00336   return MATH_OK;
00337 }
00338 

Generated on Sat Apr 1 09:04:24 2006 for GXSM by  doxygen 1.4.6