findlocmax.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  * Gxsm Plugin Name: dummy.C
00006  * ========================================
00007  * 
00008  * Copyright (C) 1999 The Free Software Foundation
00009  *
00010  * Authors: Percy Zahl <zahl@fkp.uni-hannover.de>
00011  * additional features: Andreas Klust <klust@fkp.uni-hannover.de>
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00026  */
00027 
00028 
00029 /* Please do not change the Begin/End lines of this comment section!
00030  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00031  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00032  * All "% PlugInXXX" commentary tags are mandatory
00033  * All "% OptPlugInXXX" tags are optional
00034  * --------------------------------------------------------------------------------
00035 % BeginPlugInDocuSection
00036 % PlugInDocuCaption: Find local maxima -- SARLS
00037 % PlugInName: findlocmax
00038 % PlugInAuthor: M. Langer?
00039 % PlugInAuthorEmail: stefan_fkp@users.sf.net
00040 % PlugInMenuPath: Math/Misc/Find Loc Max
00041 
00042 % PlugInDescription
00043 Finds local maximan in a scan. One (unknown to me, PZ) unknown guy
00044 (M.Langer?) of the SARLS group in hannover wrote this PlugIn for
00045 searching of local maxima. It looks somehow specialized to me.
00046 
00047 % PlugInUsage
00048 It is only available from \GxsmMenu{Math/Misc/Find Loc Max} if the
00049 instrument type is set to SARLS or a reload of all PlugIns is forced.
00050 
00051 % OptPlugInSources
00052 The active channel is used as data source.
00053 
00054 %% OptPlugInObjects
00055 %A optional rectangle is used for data extraction...
00056 
00057 %% OptPlugInDest
00058 %The computation result is placed into an existing math channel, else
00059 %into a new created math channel.
00060 
00061 % OptPlugInFiles
00062 Saves a list of local maxima in Ascii format (List of X Y Z) to a file.
00063 
00064 %% OptPlugInRefs
00065 %Any references?
00066 
00067 %% OptPlugInKnownBugs
00068 %Are there known bugs? List! How to work around if not fixed?
00069 
00070 % OptPlugInNotes
00071 I would appreciate if one of the current SARLS group members could
00072 figure out more about this piece of code.
00073 
00074 %% OptPlugInHints
00075 %Any tips and tricks?
00076 
00077 % EndPlugInDocuSection
00078  * -------------------------------------------------------------------------------- 
00079  */
00080 
00081 
00082 #include <gtk/gtk.h>
00083 #include "config.h"
00084 #include "gxsm/plugin.h"
00085  
00086 using namespace std;
00087 
00088 
00089 static void findlocmax_init( void );
00090 static void findlocmax_about( void );
00091 static void findlocmax_configure( void );
00092 static void findlocmax_cleanup( void );
00093 static gboolean findlocmax_run( Scan *Src, Scan *Dest );
00094 
00095 GxsmPlugin findlocmax_pi = {
00096   NULL,
00097   NULL,
00098   0,
00099   NULL,
00100   "Findlocmax-M1S-Misc",
00101   "+SARLS",
00102   NULL,
00103   "Nobody?, PZ",
00104   N_("_Math/_Misc/"),
00105   N_("Find Loc Max"),
00106   N_("Sorry, no help for findlocmax filter!"),
00107   "no more info",
00108   NULL,
00109   NULL,
00110   findlocmax_init,
00111   NULL,
00112   findlocmax_about,
00113   findlocmax_configure,
00114   NULL,
00115   findlocmax_cleanup
00116 };
00117 
00118 GxsmMathOneSrcPlugin findlocmax_m1s_pi = {
00119   findlocmax_run
00120 };
00121 
00122 static const char *about_text = N_("Gxsm Findlocmax Plugin\n\n"
00123                                    "Who has coded this one? -- PZ");
00124 
00125 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00126   findlocmax_pi.description = g_strdup_printf(N_("Gxsm MathOneArg findlocmax plugin %s"), VERSION);
00127   return &findlocmax_pi; 
00128 }
00129 
00130 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) { 
00131   return &findlocmax_m1s_pi; 
00132 }
00133 
00134 static void findlocmax_init(void)
00135 {
00136   PI_DEBUG (DBG_L2, "Findlocmax Plugin Init");
00137 }
00138 
00139 static void findlocmax_about(void)
00140 {
00141   const gchar *authors[] = { findlocmax_pi.authors, NULL};
00142   gtk_widget_show(gnome_about_new ( findlocmax_pi.name,
00143                                     VERSION,
00144                                     N_("(C) 2000 the Free Software Foundation"),
00145                                     about_text,
00146                                     authors,
00147                                     NULL, NULL, NULL
00148                                     ));
00149 }
00150 
00151 static void findlocmax_configure(void)
00152 {
00153   if(findlocmax_pi.app)
00154     findlocmax_pi.app->message("Findlocmax Plugin Configuration");
00155 }
00156 
00157 static void findlocmax_cleanup(void)
00158 {
00159   PI_DEBUG (DBG_L2, "Findlocmax Plugin Cleanup");
00160 }
00161 
00162 static gboolean findlocmax_run(Scan *Src, Scan *Dest)
00163 {
00164   findlocmax_pi.app->message("Sorry Findlocmax Plugin is buggy, fix it! PZ");
00165   return MATH_OK;
00166 
00167 /* Suche lokaler Maxima im Fokusbereich (Kasten mit 10µm*10µm) */
00168 /* Version 0.2 ML  (23/11/98)                                  */
00169 
00170   int line,col,fokline,fokcol,fokxpoints,fokypoints;
00171   int peakx,peaky,newpeakx,newpeaky;
00172   double referenzpeak;
00173   ofstream f;
00174   int   i;
00175   const char *fname;
00176   PI_DEBUG (DBG_L2, "Suche lokaler Maxima und Ausgabe in ASCII-Datei"); 
00177   fokxpoints=(int)(50000/Src->data.s.dx);
00178   if (fokxpoints==0) fokxpoints=1;
00179   fokypoints=(int)(50000/Src->data.s.dy);
00180   if (fokypoints==0) fokypoints=1;
00181 
00182   /* Empty-Scan erzeugen, alle Datenpunkte Null setzen */
00183 
00184   for(line=0;line<Dest->data.s.ny;line++)
00185    for(col=0;col<Dest->data.s.nx;col++)
00186       Dest->mem2d->PutDataPkt(0,col, line);     
00187   
00188   /* Peaks aufspüren, mit einem Mindestabstand = Fokus = 10µm <- Variablen: fokxpoints, fokypoints */
00189   /* doppelte Peaks werden leider noch nicht rausgeworfen */
00190 
00191   for(line=0;line<(Src->mem2d->GetNy()-fokypoints);line=line+(fokypoints/2))
00192     for(col=0;col<(Src->mem2d->GetNx()-fokxpoints);col=col+(fokxpoints/2)){      
00193       peakx=col;
00194       peaky=line;  
00195       referenzpeak=Src->mem2d->GetDataPkt(col,line);            
00196       do{
00197         newpeakx=peakx; newpeaky=peaky;
00198           for(fokcol=(int)(newpeakx-fokxpoints); fokcol<=(newpeakx+fokxpoints); fokcol++)
00199         for(fokline=(int)(newpeaky-fokypoints); fokline<=(newpeaky+fokypoints); fokline++)
00200             if((fokcol>=0) && (fokcol<Src->mem2d->GetNx()) && (fokline>=0) && (fokline<Src->mem2d->GetNy())){
00201               if(referenzpeak<=(double)Src->mem2d->GetDataPkt(fokcol,fokline)){
00202                 referenzpeak=Src->mem2d->GetDataPkt(fokcol,fokline);
00203                 peakx=fokcol;
00204                 peaky=fokline;
00205                 }                        
00206               }   
00207         }while(((newpeakx-peakx)!=0) && ((newpeaky-peaky)!=0));
00208       for(fokline=(newpeaky-fokypoints); fokline<=(newpeaky+fokypoints); fokline++)
00209         for(fokcol=(newpeakx-fokxpoints); fokcol<=(newpeakx+fokxpoints); fokcol++)
00210           if((fokcol>=0) && (fokcol<Dest->mem2d->GetNx()) && (fokline>=0) && (fokline<Dest->mem2d->GetNy()))
00211             if(0<Dest->mem2d->GetDataPkt(fokcol,fokline))
00212               referenzpeak=0;
00213       Dest->mem2d->PutDataPkt((SHT)referenzpeak,newpeakx,newpeaky);     
00214     }    
00215         
00216   /* File Selector */
00217 
00218   do{
00219     fname = findlocmax_pi.app->file_dialog("asc File to Save LOCAL MAXIMA","","*.asc","");
00220     if (fname == NULL) return 1;
00221     if (strncmp(fname+strlen(fname)-4,".asc",4))
00222       strcat((char*)fname, ".asc");
00223     PI_DEBUG (DBG_L2, "Save File: " << fname);
00224     i=2;
00225     f.open(fname, ios::in);
00226     if(f.good()){
00227       f.close();
00228       if((i=XSM_SHOW_CHOICE(WRN_WARNING, fname, WRN_FILEEXISTS, 3, L_CANCEL, L_OVERWRITE, L_RETRY, 1)) == 1)
00229         return 1;
00230     }
00231   }while(i!=2);
00232   
00233   time_t t;
00234   time(&t); 
00235   f.open(fname, ios::out | ios::trunc);
00236   if(!f.good()){
00237     XSM_SHOW_ALERT(ERR_SORRY, ERR_FILEWRITE,fname,1);
00238     return 1;
00239   }
00240   f << "# LOKALE MAXIMA ASCII-Data\n" << "# Date: " << ctime(&t) << "# " << fname << endl;
00241   f << "# Fokuspoints x = " << fokxpoints << endl;
00242   f << "# Fokuspoints y = " << fokypoints << endl;
00243   f << "# Datenpunktabstand [A]  dx = " << Src->data.s.dx << endl;
00244   f << "# Datenpunktabstand [A]  dy = " << Src->data.s.dy << endl;
00245   f << "# x   y   Intensität" << endl ;
00246 
00247   for(line=0;line<Dest->data.s.ny;line++)
00248    for(col=0;col<Dest->data.s.nx;col++)
00249       if (Dest->mem2d->GetDataPkt(col, line)!=0)     
00250          f << col << " " << line << " " << Dest->mem2d->GetDataPkt(col, line) << endl;     
00251   f.close();
00252   return MATH_OK;
00253 }

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