baseinfo.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 "intarea.C" to "your_plugins_name.C"!
00008  * 2.) Replace all "intarea" 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 intarea_run(), 
00016  *     have a look at the Data-Access methods infos at end
00017  * 8.) Add intarea.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: baseinfo.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 /* Please do not change the Begin/End lines of this comment section!
00045  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00046  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00047  * All "% PlugInXXX" commentary tags are mandatory
00048  * All "% OptPlugInXXX" tags are optional
00049  * --------------------------------------------------------------------------------
00050 % BeginPlugInDocuSection
00051 % PlugInDocuCaption: Statistic base info
00052 % PlugInName: baseinfo
00053 % PlugInAuthor: Stefan Schr\"oder
00054 % PlugInAuthorEmail: stefan_fkp@users.sf.net
00055 % PlugInMenuPath: Math/Statistics/Baseinfo
00056 
00057 % PlugInDescription
00058 This plugin calculates some basic statistical information about the
00059 active scan or a selected rectangle within the active scan:
00060 
00061 \begin{description}
00062   \item[Abs. $Z$ min:] Minimum $Z$-value and its coordinate
00063   \item[Abs. $Z$ max:] Maximum $Z$-value and its coordinate
00064   \item[$\boldmath \sum Z$:] Sum of all $Z$-values
00065   \item[$\boldmath \sum Z^2$:] Sum of all squared $Z$-values
00066   \item[Averaged $Z$:] Average of all $Z$-values:
00067   \[ \overline Z = \frac{1}{A} \sum_{x,y} Z(x,y) \mbox{ mit } A:= x\cdot y \]
00068   \item[RMS-roughness:] root mean square roughness:
00069   \begin{eqnarray*}
00070     \sigma^2 &=& \frac{1}{A} \int_A d\vec x \, [(Z(x,y) - \overline Z)^2] \\
00071              &=& \frac{1}{A} [\sum_{x,y} Z(x,y)^2 
00072                   - 2 \overline Z \sum_{x,y} Z(x,y) + \sum_{x,y} \overline Z^2]\\
00073              &=& \frac{1}{A} [\sum Z(x,y)^2 - 2 \overline Z \sum Z + \overline Z ^2 \sum 1]\\
00074              &=& \frac{1}{A} [\sum Z(x,y)^2 - 2 \overline Z \sum Z + \overline Z ^2 A]
00075   \end{eqnarray*}
00076 \end{description}
00077 
00078 % to translate/update:
00079 %  Bei der Begutachtung von $\sigma$ ist auf ein gutmütiges Verhalten des
00080 %  Mittelwertes zu achten.
00081 %  Auf der Standardausgabe werden die ermittelten Werte ausgegeben, um
00082 %  ein Markieren mit der Maus zu ermöglichen.
00083 %  Der Pixelmode ist z.Z. nicht implementiert.
00084 
00085 
00086 % PlugInUsage
00087 Choose Baseinfo from the \GxsmMenu{Math/Statistics/Baseinfo} menu.
00088 
00089 % OptPlugInSources
00090 You need one active scan.
00091 
00092 % OptPlugInObjects
00093 If a rectangle is selected the calculated information applies to the
00094 content of the rectangle. Otherwise, the whole scan is analyzed.
00095 
00096 % OptPlugInDest
00097 A dialog box appears, which contains the information in tabular form.
00098 You can press 'Dump to Stdout' to print the information on the console.
00099 Pressing 'Dump to comment' concatenates the calculated information to
00100 the comment field of this scan in the main window.
00101 
00102 % OptPlugInConfig
00103 None.
00104 
00105 % OptPlugInKnownBugs
00106 During the calculation of rms-roughness or the sum overflows can occur
00107 even in medium sized scans. You better choose a smaller region then.
00108 
00109 % OptPlugInNotes
00110 Calculated parameters are (with example values):
00111 \begin{tabbing}
00112 rms-roughness:  \= x \kill
00113 Area: > (-35.0571 $\mu$m,-600.586 $\mu$m)-(-18.0728 $\mu$m,-656.711 $\mu$m)\\
00114 Area size: >      18450 Int$^2$\\
00115 Minimum: >        98 Int \\
00116 Min Pos: >        (-27.942 $\mu$m,-600.815 $\mu$m)\\
00117 Maximum: >        10438 Int\\
00118 Max Pos: >        (-31.6143 $\mu$m,-628.763 $\mu$m)\\
00119 Sum:     >        4.95591e+07 Int\\
00120 Sum Sq:  >        1.86421e+09 Int\\
00121 Average: >        2686.13 Int\\
00122 rms-roughness:  >     nan Int
00123 \end{tabbing}
00124 
00125 % EndPlugInDocuSection
00126  *
00127 --------------------------------------------------------------------------------
00128  */
00129 
00130 #include <sstream>
00131 
00132 #include <gtk/gtk.h>
00133 #include "config.h"
00134 #include "gxsm/plugin.h"
00135 
00136 
00137 using namespace std;
00138 
00139 
00140 // Plugin Prototypes
00141 static void baseinfo_init( void );
00142 static void baseinfo_about( void );
00143 static void baseinfo_configure( void );
00144 static void baseinfo_cleanup( void );
00145 
00146 static gboolean baseinfo_run( Scan *Src );
00147 
00148 // Fill in the GxsmPlugin Description here
00149 GxsmPlugin baseinfo_pi = {
00150   NULL,                   // filled in and used by Gxsm, don't touch !
00151   NULL,                   // filled in and used by Gxsm, don't touch !
00152   0,                      // filled in and used by Gxsm, don't touch !
00153   NULL,                   // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 
00154                           // filled in here by Gxsm on Plugin load, 
00155                           // just after init() is called !!!
00156   // ----------------------------------------------------------------------
00157   // Plugins Name, CodeStly is like: Name-M1S[ND]|M2S-BG|F1D|F2D|ST|TR|Misc
00158   "Baseinfo-M1SND-ST",
00159   NULL,
00160   // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details)
00161   "Basic statistic information",
00162   // Author(s)
00163   "Stefan Schroeder",
00164   // Menupath to position where it is appendet to
00165   "_Math/_Statistics/",
00166   // Menuentry
00167   N_("Baseinfo"),
00168   // help text shown on menu
00169   N_("Basic statistic info."),
00170   // more info...
00171   "no more info",
00172   NULL,          // error msg, plugin may put error status msg here later
00173   NULL,          // Plugin Status, managed by Gxsm, plugin may manipulate it too
00174   // init-function pointer, can be "NULL", 
00175   // called if present at plugin load
00176   baseinfo_init,  
00177   // query-function pointer, can be "NULL", 
00178   // called if present after plugin init to let plugin manage it install itself
00179   NULL, // query should be "NULL" for Gxsm-Math-Plugin !!!
00180   // about-function, can be "NULL"
00181   // can be called by "Plugin Details"
00182   baseinfo_about,
00183   // configure-function, can be "NULL"
00184   // can be called by "Plugin Details"
00185   baseinfo_configure,
00186   // run-function, can be "NULL", if non-Zero and no query defined, 
00187   // it is called on menupath->"plugin"
00188   NULL, // run should be "NULL" for Gxsm-Math-Plugin !!!
00189   // cleanup-function, can be "NULL"
00190   // called if present at plugin removeal
00191   baseinfo_cleanup
00192 };
00193 
00194 // special math Plugin-Strucure, use
00195 GxsmMathOneSrcNoDestPlugin baseinfo_m1s_pi = {
00196   baseinfo_run
00197 };
00198 
00199 // Text used in Aboutbox, please update!!a
00200 static const char *about_text = N_("Gxsm Plugin\n\n"
00201                                    "Basic statistic information.");
00202 
00203 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00204 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00205   baseinfo_pi.description = g_strdup_printf(N_("Gxsm MathOneArg baseinfo plugin %s"), VERSION);
00206   return &baseinfo_pi; 
00207 }
00208 
00209 // Symbol "get_gxsm_math_one[_no_dest]|two_src_plugin_info" is resolved by dlsym from Gxsm, 
00210 // used to find out which Math Type the Plugin is!! 
00211 // Essential Plugin Function!!
00212 
00213 GxsmMathOneSrcNoDestPlugin *get_gxsm_math_one_src_no_dest_plugin_info( void ) {
00214   return &baseinfo_m1s_pi; 
00215 }
00216 
00217 // 5.) Start here with the plugins code, vars def., etc.... here.
00218 // ----------------------------------------------------------------------
00219 //
00220 
00221 /* Holds the String for dumping on STDOUT */
00222 ostringstream info;
00223 
00224 
00225 /* callback fuer delete_event*/
00226 gint delete_event( GtkWidget *widget, GdkEvent  *event, gpointer   data )
00227 {
00228                 return(MATH_OK); 
00229 }
00230 
00231 
00232 // init-Function
00233 static void baseinfo_init(void)
00234 {
00235   PI_DEBUG (DBG_L2, "baseinfo Plugin Init");
00236 }
00237 
00238 // about-Function
00239 static void baseinfo_about(void)
00240 {
00241   const gchar *authors[] = { baseinfo_pi.authors, NULL};
00242   gtk_widget_show(gnome_about_new ( baseinfo_pi.name,
00243                                     VERSION,
00244                                     N_("(C) 2000 the Free Software Foundation"),
00245                                     about_text,
00246                                     authors,
00247                                     NULL, NULL, NULL
00248                                     ));
00249 }
00250 
00251 // configure-Function
00252 static void baseinfo_configure(void)
00253 {
00254   if(baseinfo_pi.app)
00255     baseinfo_pi.app->message("Baseinfo Plugin Configuration");
00256 }
00257 
00258 // cleanup-Function
00259 static void baseinfo_cleanup(void)
00260 {
00261   PI_DEBUG (DBG_L2, "Baseinfo Plugin Cleanup");
00262 }
00263 
00264 int ok_button_callback( GtkWidget *widget, gpointer data)
00265 {
00266   printf("OK pressed. \n");
00267   return 0;
00268 }
00269 
00270 void dump_button_callback( GtkWidget *widget, gpointer data)
00271 {
00272   cout << info << endl;
00273 }
00274 
00275 void comment_button_callback( GtkWidget *widget, gpointer data)
00276 {
00277   // Add info to comment-field.
00278   gapp->xsm->data.ui.comment = g_strconcat( gapp->xsm->data.ui.comment, (const gchar*)info.str().c_str(), NULL);
00279   // Update textfield on screen.
00280   gapp->spm_update_all();
00281 }
00282 
00283 
00284 // run-Function
00285 static gboolean baseinfo_run(Scan *Src)
00286 {
00287   int line, col, minline, mincol, maxline, maxcol;
00288   double akt, minimum, maximum, summe;
00289   double sumsquare;
00290   int left, right, top, bottom;
00291   double rms;
00292   double unitleft, unitright, unittop, unitbottom;
00293   double unitmincol, unitminline, unitmaxcol, unitmaxline; 
00294   double area, average;
00295   MOUSERECT msr;
00296   MkMausSelect(Src->Pkt2d, &msr, Src->mem2d->GetNx(), Src->mem2d->GetNy());
00297 
00298   if( msr.xSize  < 1 || msr.ySize < 1){
00299     left   = 0; 
00300     right  = Src->mem2d->GetNx();
00301     top    = 0;
00302     bottom = Src->mem2d->GetNy();
00303     area   = right * bottom;
00304   }
00305   else{
00306     left   = msr.xLeft;
00307     right  = msr.xRight;
00308     top    = msr.yTop;
00309     bottom = msr.yBottom;
00310     area   = msr.Area;
00311   }
00312 
00313   summe = 0.;
00314   sumsquare = 0.;
00315   minimum = maximum = Src->mem2d->GetDataPkt (0, 0);
00316  
00317   minline = maxline = top;
00318   mincol = maxcol = left;
00319 
00320   for(col = left; col < right; col++){
00321     for(line = top; line < bottom; line++){
00322       akt = Src->mem2d->GetDataPkt(col, line);
00323       summe += akt;
00324       sumsquare += akt*akt;
00325 
00326       if (akt > maximum) {
00327         maximum = akt;
00328         maxline = line; maxcol = col;
00329       }
00330       if (akt < minimum){
00331         minimum = akt;
00332         minline = line; mincol = col;
00333       }
00334     }
00335   }
00336 
00337   average = summe / area;
00338   rms = ( sumsquare - 2*average*summe + average*average*area );
00339   rms = rms/area;
00340   rms = sqrt(rms);
00341 
00342   // convert pixelvalues to Unitvalues (but without Unitlabel)
00343   unitleft = Src->mem2d->data->GetXLookup(left);
00344   unitright= Src->mem2d->data->GetXLookup(right-1);
00345   unittop  = Src->mem2d->data->GetYLookup(top);
00346   unitbottom = Src->mem2d->data->GetYLookup(bottom-1);
00347 
00348   unitmincol =Src->mem2d->data->GetXLookup(mincol);
00349   unitminline=Src->mem2d->data->GetYLookup(minline);
00350   unitmaxcol =Src->mem2d->data->GetXLookup(maxcol);
00351   unitmaxline=Src->mem2d->data->GetYLookup(maxline);
00352 
00353   GtkWidget *mywin;
00354   GtkWidget *clist;
00355   GtkWidget *button1, *button2, *button3;
00356   GtkWidget *vbox;
00357   GtkWidget *hbox;
00358 
00359   mywin = gtk_dialog_new();
00360   vbox  = gtk_vbox_new(FALSE, 0);
00361   hbox  = gtk_hbox_new(FALSE, 0);
00362   gtk_container_add (GTK_CONTAINER (mywin), vbox);
00363 
00364   gchar *tab_titel[3] = {"Information", "DA Values", "Unitvalues"}; 
00365   clist = gtk_clist_new_with_titles( 3, tab_titel);
00366 
00367   // OK Button
00368   button1 = gtk_button_new_with_label ("OK");
00369   gtk_box_pack_start (GTK_BOX(hbox), button1, TRUE, TRUE, 10);
00370   gtk_signal_connect (GTK_OBJECT (button1), "clicked",
00371                       GTK_SIGNAL_FUNC (ok_button_callback), NULL);
00372   gtk_widget_show (button1);
00373 
00374   // Dump to stdout Button
00375   button2 = gtk_button_new_with_label ("Dump to Stdout");
00376   gtk_box_pack_start (GTK_BOX(hbox), button2, FALSE, TRUE, 10);
00377   gtk_signal_connect (GTK_OBJECT (button2), "clicked",
00378                       GTK_SIGNAL_FUNC (dump_button_callback), NULL);
00379   gtk_widget_show (button2);
00380 
00381   // Dump to comment Button
00382   button3 = gtk_button_new_with_label ("Dump to Comment");
00383   gtk_box_pack_start (GTK_BOX(hbox), button3, FALSE, TRUE, 10);
00384   gtk_signal_connect (GTK_OBJECT (button3), "clicked",
00385                       GTK_SIGNAL_FUNC (comment_button_callback), NULL);
00386   gtk_widget_show (button3);
00387 
00388   gtk_clist_set_column_width (GTK_CLIST(clist), 0, 200);
00389   gtk_clist_set_column_width (GTK_CLIST(clist), 1, 150);
00390   gtk_clist_set_column_width (GTK_CLIST(clist), 2, 400);
00391   
00392   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (mywin)->vbox), // Korrekt
00393                        clist, TRUE, TRUE, 10);
00394   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (mywin)->vbox), // Korrekt
00395                        hbox, FALSE, TRUE, 10);
00396 
00397   gtk_widget_show (hbox);
00398   gtk_widget_show (clist);
00399   gtk_widget_show (vbox);
00400   gtk_widget_show (mywin);
00401 
00402   gtk_clist_clear((GtkCList *) clist);
00403   gchar dummy0[64], dummy1[64], dummy2[64]; // Is 64 enough or dynamically?
00404   gchar *dummy_texte[] = {dummy0, dummy1, dummy2};
00405 
00406         //Area was
00407   sprintf(dummy0, N_("Area was: "));
00408   sprintf(dummy1, "(%i,%i)-(%i,%i)",left,top,right-1,bottom-1);
00409   sprintf(dummy2, "(%s,%s)-(%s,%s)",    Src->data.Xunit->UsrString(unitleft),
00410                                         Src->data.Yunit->UsrString(unittop),
00411                                         Src->data.Xunit->UsrString(unitright),
00412                                         Src->data.Yunit->UsrString(unitbottom));
00413   gtk_clist_append((GtkCList *) clist, dummy_texte);
00414 
00415         //Area
00416   sprintf(dummy0, N_("Area: "));
00417   sprintf(dummy1, "%f", area);
00418   sprintf(dummy2, "%s", Src->data.Zunit->UsrStringSqr(area));
00419   gtk_clist_append((GtkCList *) clist, dummy_texte);
00420 
00421         //Minimum
00422   sprintf(dummy0, N_("Minimum: "));
00423   sprintf(dummy1, "%g", minimum);
00424   sprintf(dummy2, Src->data.Zunit->UsrString(Src->mem2d->GetDataPkt(mincol,minline)*(Src->data.s.dz)));
00425   gtk_clist_append((GtkCList *) clist, dummy_texte);
00426 
00427 
00428   // Minimum-pos
00429   sprintf(dummy0, N_("Minimum-Pos: "));
00430   sprintf(dummy1, "(%i,%i)", mincol, minline);
00431   sprintf(dummy2, "(%s,%s)", Src->data.Xunit->UsrString(unitmincol), Src->data.Yunit->UsrString(unitminline));
00432   gtk_clist_append((GtkCList *) clist, dummy_texte);
00433         //Maximum
00434   sprintf(dummy0, N_("Maximum: "));
00435   sprintf(dummy1, "%g", maximum);
00436   sprintf(dummy2, "%s", Src->data.Zunit->UsrString(Src->mem2d->GetDataPkt(maxcol,maxline)*(Src->data.s.dz)));
00437   gtk_clist_append((GtkCList *) clist, dummy_texte);
00438         //Maximum-pos
00439   sprintf(dummy0, N_("Maximum-Pos: "));
00440   sprintf(dummy1, "(%i,%i)", maxcol, maxline);
00441   sprintf(dummy2, "(%s,%s)", Src->data.Xunit->UsrString(unitmaxcol), Src->data.Yunit->UsrString(unitmaxline));
00442   gtk_clist_append((GtkCList *) clist, dummy_texte);
00443         //sum
00444   sprintf(dummy0, N_("Sum: "));
00445   sprintf(dummy1, "%g", summe);
00446   sprintf(dummy2, "%s", Src->data.Zunit->UsrString(summe));
00447   gtk_clist_append((GtkCList *) clist, dummy_texte);
00448         //sumsq
00449   sprintf(dummy0, N_("Sum Squares: "));
00450   sprintf(dummy1, "%g", sumsquare);
00451   sprintf(dummy2, "%s", Src->data.Zunit->UsrString(sumsquare));
00452   gtk_clist_append((GtkCList *) clist, dummy_texte);
00453         //ave
00454   sprintf(dummy0, N_("Average: "));
00455   sprintf(dummy1, "%f", average);
00456   sprintf(dummy2, "%s", Src->data.Zunit->UsrString(average));
00457   gtk_clist_append((GtkCList *) clist, dummy_texte);
00458         //rms
00459   sprintf(dummy0, N_("rms-roughness: "));
00460   sprintf(dummy1, "%f", rms);
00461   sprintf(dummy2, "%s", Src->data.Zunit->UsrString(rms));
00462   gtk_clist_append((GtkCList *) clist, dummy_texte);
00463 
00464   info << N_("Area was: \t") 
00465    << "\t(" << left << "," << top << ")-(" << right-1 << "," << bottom-1 << ")"    << "\t(" << Src->data.Xunit->UsrString(unitleft) << "," << Src->data.Yunit->UsrString(unittop)<<")-("<<  
00466              Src->data.Xunit->UsrString(unitright) << "," << Src->data.Yunit->UsrString(unitbottom) << ")" << endl
00467    << N_("Area size: \t") << area << "px^2,  \t" << Src->data.Zunit->UsrStringSqr(area)<< endl
00468 
00469    << N_("Minimum: \t") << minimum << "px  \t" <<Src->data.Zunit->UsrString(minimum) <<endl
00470    << N_("Min Pos: \t") << "(" << mincol << "," << minline << ")" << "\t(" << Src->data.Xunit->UsrString(unitmincol) << "," << Src->data.Yunit->UsrString(unitminline)<<")" << endl
00471    << N_("Maximum: \t") << maximum << "px  \t" << Src->data.Zunit->UsrString(maximum) <<endl
00472    << N_("Max Pos: \t") << "(" << maxcol    << "," << maxline << ")"  << "\t(" << Src->data.Xunit->UsrString(unitmaxcol) << "," << Src->data.Yunit->UsrString(unitmaxline)<<")" << endl
00473 
00474    << N_("Sum: \t\t")   << summe            << "px  \t"    << Src->data.Zunit->UsrString(summe) <<endl
00475    << N_("Sum Sq: \t")  << sumsquare        << "px^2 \t" << Src->data.Zunit->UsrString(sumsquare) <<endl
00476    << N_("Average: \t") << average          << "px \t"   << Src->data.Zunit->UsrString(average) <<endl 
00477    << N_("rms-roughness: \t") << rms        << "\t"       << Src->data.Zunit->UsrString(rms)  <<endl
00478    << ends;
00479 
00480         //  g_free(tab_titel);
00481         //  g_free(dummy0); g_free(dummy1); g_free(dummy2);
00482   return MATH_OK;
00483 }

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