histogram.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: histogram.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 /* Please do not change the Begin/End lines of this comment section!
00029  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00030  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00031  * All "% PlugInXXX" commentary tags are mandatory
00032  * All "% OptPlugInXXX" tags are optional
00033  * --------------------------------------------------------------------------------
00034 % BeginPlugInDocuSection
00035 % PlugInDocuCaption: Histogram
00036 
00037 % PlugInName: histogram
00038 
00039 % PlugInAuthor: Percy Zahl
00040 
00041 % PlugInAuthorEmail: zahl@users.sf.net
00042 
00043 % PlugInMenuPath: Math/Statistics/Histogram
00044 
00045 % PlugInDescription
00046 The Histogram plugin calculates the Z-value distribution (typically a
00047 height histogram) of the active channel using a default (estimated from data)
00048 or user provided number of bins.
00049 
00050 % PlugInUsage
00051 Call it from Gxsm Math/Statistics menu. It will prompt for the number
00052 of bins and provides a estimated number as default. Also the current
00053 min/max Z-value limits and range is shown for informative purpose.
00054 
00055 % OptPlugInSources
00056 The active channel is used as data source.
00057 
00058 % OptPlugInObjects
00059 A optional rectangle can not be used. Use crop before!
00060 
00061 % OptPlugInDest
00062 The computation result is placed into an new profile view.
00063 
00064 %% OptPlugInConfig
00065 %The number of bins can be set.
00066 
00067 %% OptPlugInFiles
00068 %Needs/creates no files.
00069 
00070 %% OptPlugInRefs
00071 %nope.
00072 
00073 %% OptPlugInKnownBugs
00074 %No known.
00075 
00076 %% OptPlugInNotes
00077 %Hmm, no notes\dots
00078 
00079 % OptPlugInHints
00080 Find out what happenes with more or less bins!
00081 
00082 % EndPlugInDocuSection
00083  * -------------------------------------------------------------------------------- 
00084  */
00085 
00086 #include <math.h>
00087 #include <gtk/gtk.h>
00088 #include "config.h"
00089 #include "gxsm/plugin.h"
00090 #include "gxsm/action_id.h"
00091 #include "gxsm/app_profile.h"
00092 
00093 static void histogram_init( void );
00094 static void histogram_about( void );
00095 static void histogram_configure( void );
00096 static void histogram_cleanup( void );
00097 static gboolean histogram_run( Scan *Src );
00098 
00099 GxsmPlugin histogram_pi = {
00100   NULL,
00101   NULL,
00102   0,
00103   NULL,
00104   "Histogram-M1S-Stat",
00105   NULL,
00106   NULL,
00107   "Percy Zahl",
00108   N_("_Math/_Statistics/"),
00109   N_("Histogram"),
00110   N_("calc. Z (height) Distribution"),
00111   "no more info",
00112   NULL,
00113   NULL,
00114   histogram_init,
00115   NULL,
00116   histogram_about,
00117   histogram_configure,
00118   NULL,
00119   histogram_cleanup
00120 };
00121 
00122 GxsmMathOneSrcNoDestPlugin histogram_m1s_pi = {
00123   histogram_run
00124 };
00125 
00126 static const char *about_text = N_("Gxsm Histogram Plugin\n\n"
00127                                    "calculates Z (height) distribution / Histogram");
00128 static UnitObj *Events = NULL;
00129 
00130 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00131   histogram_pi.description = g_strdup_printf(N_("Gxsm MathOneArg histogram plugin %s"), VERSION);
00132   return &histogram_pi; 
00133 }
00134 
00135 GxsmMathOneSrcNoDestPlugin *get_gxsm_math_one_src_no_dest_plugin_info( void ) { 
00136   return &histogram_m1s_pi; 
00137 }
00138 
00139 static void histogram_init(void)
00140 {
00141   PI_DEBUG (DBG_L2, "Histogram Plugin Init");
00142 }
00143 
00144 static void histogram_about(void)
00145 {
00146   const gchar *authors[] = { histogram_pi.authors, NULL};
00147   gtk_widget_show(gnome_about_new ( histogram_pi.name,
00148                                     VERSION,
00149                                     N_("(C) 2000 the Free Software Foundation"),
00150                                     about_text,
00151                                     authors,
00152                                     NULL, NULL, NULL
00153                                     ));
00154 }
00155 
00156 static void histogram_configure(void)
00157 {
00158         if(histogram_pi.app)
00159                 histogram_pi.app->message("Histogram Plugin Configuration");
00160 }
00161 
00162 static void histogram_cleanup(void)
00163 {
00164         PI_DEBUG (DBG_L2, "Histogram Plugin Cleanup");
00165         if (Events){
00166                 delete Events;
00167                 Events = NULL;
00168         }
00169 }
00170 
00171 static gboolean histogram_run(Scan *Src)
00172 {
00173         PI_DEBUG (DBG_L2, "TR Histogram");
00174         double high, low, zrange, dz, bin_width, dz_norm;
00175         double dnum;
00176         int    bin_num;
00177         gchar *lp, *hp, *rp, *dzp ;
00178         if (!Events){
00179                 Events = new UnitObj("#","#","g","Count");
00180                 Events->SetAlias ("Events");
00181         }
00182 
00183 
00184         Src->mem2d->HiLo(&high, &low, FALSE, NULL, NULL, 1);
00185         dz  = Src->data.s.dz;
00186         low  *= dz;
00187         high *= dz;
00188         zrange = high-low;
00189         gchar *txt = g_strdup_printf("Enter number of bins:\n"
00190                                      "Zmin: %s (%g) ... Zmax: %s (%g)\n"
00191                                      "Zrange: %s (%g)\n" 
00192                                      "dZ: %s (%g)\n"
00193                                      "Max Bins: %d\n", 
00194                                      lp=Src->data.Zunit->UsrString(low), low,
00195                                      hp=Src->data.Zunit->UsrString(high), high,
00196                                      rp=Src->data.Zunit->UsrString(zrange), zrange, 
00197                                      dzp=Src->data.Zunit->UsrString(dz), dz,
00198                                      (int)(zrange/dz));
00199         g_free(lp);
00200         g_free(hp);
00201         g_free(rp);
00202         g_free(dzp);
00203         dnum = zrange/dz/3; // +/-1 dz (3dz) in ein bin per default
00204         histogram_pi.app->ValueRequest ("Enter Value", "Number of Bins", txt,
00205                                         Events,
00206                                         1., zrange/dz, "g", &dnum);
00207         g_free(txt);
00208         
00209         bin_num   = (int)dnum;
00210         bin_width = zrange / bin_num;
00211         dz_norm   = 1./bin_width;
00212 
00213         txt = g_strdup_printf ("Histogram of %d bins, %g width", bin_num, bin_width);
00214         ProfileControl *pc = new ProfileControl (txt, 
00215                                                  bin_num, 
00216                                                  Src->data.Zunit, Events, 
00217                                                  low, high, "Histogram");
00218         g_free (txt);
00219 
00220         for(int i = 0; i < bin_num; i++)
00221                 pc->SetPoint (i, 0.);
00222 
00223         for(int col = 0; col < Src->mem2d->GetNx(); col++)
00224                 for(int line = 0; line < Src->mem2d->GetNy(); line++){
00225                         double f  = (dz*Src->mem2d->GetDataPkt(col,line) - low) / bin_width;
00226                         int bin   = (int)f;
00227         
00228                         if (bin < bin_num){
00229                                 double f1 = (bin+1) * bin_width;
00230                                 if ((f+dz_norm) > f1){ // partiell in bin, immer rechter Rand, da bin>0 && bin < f
00231                                         pc->AddPoint (bin, f-bin);
00232                                         ++bin;
00233                                         if (bin < bin_num)
00234                                                 pc->AddPoint (bin, bin-f); // 1.-(f-(bin-1))
00235                                 }
00236                                 else // full inside of bin
00237                                         pc->AddPoint (bin, 1.);
00238                         }
00239                 }
00240   
00241         pc->drawScans ();
00242         pc->UpdateArea ();
00243         pc->show ();
00244 
00245         histogram_pi.app->xsm->AddProfile (pc); // give it to Surface, it takes care about removing it...
00246         pc->unref (); // nothing depends on it, so decrement refcount
00247 
00248         return MATH_OK;
00249 }

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