linear_stat_diff.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  * plugin_helper reports your answers as
00006 author          =Percy Zahl
00007 email                   =zahl@users.sf.net
00008 pluginname              =linear_stat_diff
00009 pluginmenuentry         =Lin stat diff
00010 menupath                =Math/Filter 1D/
00011 entryplace              =Filter 1D
00012 shortentryplace =F1D
00013 abouttext               =Linear stationary differentation
00014 smallhelp               =Linear stationary differentation
00015 longhelp                =Linear stationary differentation
00016  * 
00017  * Gxsm Plugin Name: linear_stat_diff.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: Linear stationary differentation
00049 % PlugInName: linear_stat_diff
00050 % PlugInAuthor: Percy Zahl
00051 % PlugInAuthorEmail: zahl@users.sf.net
00052 % PlugInMenuPath: Math/Filter 1D/Lin stat diff
00053 
00054 % PlugInDescription
00055 Edge enhancement via differentation as follows:
00056 \[ I_i = \frac{1}{9}\sum_{k=i-4}^{i+4}Z_k \]
00057 \[ Z'_i = \frac{1}{4}\frac{Z_i - I_i }
00058           {\sqrt{\frac{1}{2}\sum_{k=i-4}^{i+4}\left(Z_k-I_k\right)^2}}
00059         + \frac{I_i}{2}
00060 \]
00061 
00062 % PlugInUsage
00063 Call \GxsmMenu{Math/Filter 1D/Lin stat diff}.
00064 
00065 % OptPlugInSources
00066 The active channel is used as data source.
00067 
00068 %% OptPlugInObjects
00069 %A optional rectangle is used for data extraction...
00070 
00071 % OptPlugInDest
00072 The computation result is placed into an existing math channel, else
00073 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 %If you have any additional notes
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 linear_stat_diff_init( void );
00103 static void linear_stat_diff_about( void );
00104 static void linear_stat_diff_configure( void );
00105 static void linear_stat_diff_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 linear_stat_diff_run( Scan *Src, Scan *Dest );
00115 #else
00116 // "TwoSrc" Prototype
00117  static gboolean linear_stat_diff_run( Scan *Src1, Scan *Src2, Scan *Dest );
00118 #endif
00119 
00120 // Fill in the GxsmPlugin Description here
00121 GxsmPlugin linear_stat_diff_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   "linear_stat_diff-"
00131 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00132   "M1S"
00133 #else
00134   "M2S"
00135 #endif
00136   "-F1D",
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   "Linear stationary differentation",                   
00145   // Author(s)
00146   "Percy Zahl",
00147   // Menupath to position where it is appendet to
00148   N_("_Math/Filter _1D/"),
00149   // Menuentry
00150   N_("Lin stat diff"),
00151   // help text shown on menu
00152   N_("Linear stationary differentation"),
00153   // more info...
00154   "Linear stationary differentation",
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   linear_stat_diff_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   linear_stat_diff_about,
00166   // configure-function, can be "NULL"
00167   // can be called by "Plugin Details"
00168   linear_stat_diff_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   linear_stat_diff_cleanup
00175 };
00176 
00177 // special math Plugin-Strucure, use
00178 // GxsmMathOneSrcPlugin linear_stat_diff_m1s_pi -> "OneSrcMath"
00179 // GxsmMathTwoSrcPlugin linear_stat_diff_m2s_pi -> "TwoSrcMath"
00180 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00181  GxsmMathOneSrcPlugin linear_stat_diff_m1s_pi
00182 #else
00183  GxsmMathTwoSrcPlugin linear_stat_diff_m2s_pi
00184 #endif
00185  = {
00186    // math-function to run, see prototype(s) above!!
00187    linear_stat_diff_run
00188  };
00189 
00190 // Text used in Aboutbox, please update!!
00191 static const char *about_text = N_("Gxsm linear_stat_diff Plugin\n\n"
00192                                    "Linear stationary differentation");
00193 
00194 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00195 // Essential Plugin Function!!
00196 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00197   linear_stat_diff_pi.description = g_strdup_printf(N_("Gxsm MathOneArg linear_stat_diff plugin %s"), VERSION);
00198   return &linear_stat_diff_pi; 
00199 }
00200 
00201 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 
00202 // used to find out which Math Type the Plugin is!! 
00203 // Essential Plugin Function!!
00204 #ifdef GXSM_ONE_SRC_PLUGIN__DEF
00205 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) {
00206   return &linear_stat_diff_m1s_pi; 
00207 }
00208 #else
00209 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 
00210   return &linear_stat_diff_m2s_pi; 
00211 }
00212 #endif
00213 
00214 /* Here we go... */
00215 // init-Function
00216 static void linear_stat_diff_init(void)
00217 {
00218   PI_DEBUG (DBG_L2, "linear_stat_diff Plugin Init");
00219 }
00220 
00221 // about-Function
00222 static void linear_stat_diff_about(void)
00223 {
00224   const gchar *authors[] = { linear_stat_diff_pi.authors, NULL};
00225   gtk_widget_show(gnome_about_new ( linear_stat_diff_pi.name,
00226                                     VERSION,
00227                                     N_("(C) 2000 the Free Software Foundation"),
00228                                     about_text,
00229                                     authors,
00230                                     NULL, NULL, NULL
00231                                     ));
00232 }
00233 
00234 // configure-Function
00235 static void linear_stat_diff_configure(void)
00236 {
00237   if(linear_stat_diff_pi.app)
00238     linear_stat_diff_pi.app->message("linear_stat_diff Plugin Configuration");
00239 }
00240 
00241 // cleanup-Function
00242 static void linear_stat_diff_cleanup(void)
00243 {
00244         PI_DEBUG (DBG_L2, "linear_stat_diff Plugin Cleanup");
00245 }
00246 
00247 // run-Function
00248 static gboolean linear_stat_diff_run(Scan *Src, Scan *Dest)
00249 {
00250         double stda, sum, dif;
00251 
00252         if (Src->mem2d->GetNx () < 5) 
00253                 return MATH_SIZEERR;
00254 
00255         double *i1 = new double[Src->mem2d->GetNx ()];
00256         double *i2 = new double[Src->mem2d->GetNx ()];
00257 
00258         for(int line=0; line < Dest->mem2d->GetNy (); ++line){
00259                 for(int i=4; i < Dest->mem2d->GetNx ()-4; ++i){
00260                         stda = 0.;
00261                         sum = 0.;
00262                         for(int j=i-4; j <= i+4; ++j)
00263                                 sum += Src->mem2d->GetDataPkt (j, line);
00264                         sum /= 9.;
00265                         i1[i] = sum;
00266                         for(int j=i-4; j <= i+4; ++j){
00267                                 dif = Src->mem2d->GetDataPkt (j, line) - sum;
00268                                 stda += dif * dif;
00269                         }
00270                         i2[i] = sqrt (stda/9.);
00271                 }
00272                 for(int i=0; i<4; ++i){
00273                         i1[i] = i1[4];
00274                         i2[i] = i2[4];
00275                 }
00276                 for(int i=Dest->mem2d->GetNx ()-4; i<Dest->mem2d->GetNx (); ++i){
00277                         i1[i] = i1[Dest->mem2d->GetNx ()-4-1];
00278                         i2[i] = i2[Dest->mem2d->GetNx ()-4-1];
00279                 }
00280 
00281                 for(int col=0; col < Dest->mem2d->GetNx (); ++col)
00282                         Dest->mem2d->PutDataPkt (25.*(Src->mem2d->GetDataPkt (col, line)-i1[col])
00283                                                  /(i2[col]+2.) + i1[col]/2., 
00284                                                  col, line);
00285         }
00286         delete[] i2;
00287         delete[] i1;
00288         
00289         return MATH_OK;
00290 }

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