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

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