histoHOP.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: histohop.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 #include <gtk/gtk.h>
00029 #include "config.h"
00030 #include "gxsm/plugin.h"
00031 
00032 static void histohop_init( void );
00033 static void histohop_about( void );
00034 static void histohop_configure( void );
00035 static void histohop_cleanup( void );
00036 static gboolean histohop_run( Scan *Src, Scan *Dest );
00037 
00038 GxsmPlugin histohop_pi = {
00039   NULL,
00040   NULL,
00041   0,
00042   NULL,
00043   "Histohop-M1S-F1D",
00044   "-spaHARD",
00045   NULL,
00046   "HOP, AK, PZ",
00047   N_("_Math/_Statistics/"),
00048   N_("Histo HOP"),
00049   N_("Histo HOP Stat."),
00050   "no more info",
00051   NULL,
00052   NULL,
00053   histohop_init,
00054   NULL,
00055   histohop_about,
00056   histohop_configure,
00057   NULL,
00058   histohop_cleanup
00059 };
00060 
00061 GxsmMathOneSrcPlugin histohop_m1s_pi = {
00062   histohop_run
00063 };
00064 
00065 static const char *about_text = N_("Gxsm Histohop Plugin\n\n"
00066                                    "calculates histohop.");
00067 
00068 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00069   histohop_pi.description = g_strdup_printf(N_("Gxsm MathOneArg histohop plugin %s"), VERSION);
00070   return &histohop_pi; 
00071 }
00072 
00073 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) { 
00074   return &histohop_m1s_pi; 
00075 }
00076 
00077 static void histohop_init(void)
00078 {
00079   PI_DEBUG (DBG_L2, "Histohop Plugin Init");
00080 }
00081 
00082 static void histohop_about(void)
00083 {
00084   const gchar *authors[] = { histohop_pi.authors, NULL};
00085   gtk_widget_show(gnome_about_new ( histohop_pi.name,
00086                                     VERSION,
00087                                     N_("(C) 2000 the Free Software Foundation"),
00088                                     about_text,
00089                                     authors,
00090                                     NULL, NULL, NULL
00091                                     ));
00092 }
00093 
00094 static void histohop_configure(void)
00095 {
00096   if(histohop_pi.app)
00097     histohop_pi.app->message("Histohop Plugin Configuration");
00098 }
00099 
00100 static void histohop_cleanup(void)
00101 {
00102   PI_DEBUG (DBG_L2, "Histohop Plugin Cleanup");
00103 }
00104 
00105 static gboolean histohop_run(Scan *Src, Scan *Dest)
00106 {
00107   if(histohop_pi.app)
00108     histohop_pi.app->message("make it alive again!");
00109   return MATH_OK;
00110 }
00111 
00112 
00113 #ifdef Who_makes_Histo_HOP_gxsm_conform_qqq
00114 
00115 
00116 // histoHOP filter
00117 typedef enum {
00118   F2D_HISTOHOP_PCS_RX, F2D_HISTOHOP_PCS_RY,
00119   F2D_HISTOHOP_PCS_THRES,
00120   F2D_HISTOHOP_PCS_ANZAHL
00121 } F2D_HISTOHOP_PCS_LIST;
00122 
00123 class F2D_HistoHOP : public Filter
00124 {
00125 friend void histoHOPAction(FL_OBJECT *ob, long data);
00126  public:
00127   F2D_HistoHOP();
00128   ~F2D_HistoHOP();
00129 
00130   void hide();
00131   void draw();
00132 
00133   gboolean exec(MATHOPPARAMS);
00134 
00135  private:
00136   double rx, ry, thres;
00137   char hopFile[256];
00138   int hopFileOK;
00139   ofstream *hopStream;
00140   int detectOnly;          // TRUE: do only step detection
00141   /*
00142   FD_HistoHOP *fd_HistoHOP;
00143   FD_HistoHOP *fd_HistoHOPCpy;
00144   Param_Control *pcs[F2D_HISTOHOP_PCS_ANZAHL];
00145   */
00146 };
00147 
00148 
00149 // F2D_Histohop
00150 // Filter zur Berechnung von Terrassenlängen und Stufenhöhenverteilungen
00151 // war: histoHOP Filter in PMSTM
00152 // entwickelt von Holger Pietsch (HOP), s.a. seine Diss
00153 F2D_HistoHOP::F2D_HistoHOP()
00154 {
00155   // create form and copy
00156   fd_HistoHOP = create_form_HistoHOP();
00157   fd_HistoHOPCpy = new FD_HistoHOP;  // Shadow of Pointers to Objects
00158   memcpy(fd_HistoHOPCpy, fd_HistoHOP, sizeof(FD_HistoHOP));     // copy Pointers
00159   fl_set_form_atclose(fd_HistoHOPCpy->HistoHOP, cb_do_close, 0);
00160 
00161   // init private variables
00162   rx = 1.0; ry = 1.0;
00163   thres = 10.0;
00164   *hopFile = '\0';
00165   hopFileOK = 0;
00166   
00167   // init parameter control system:
00168   pcs[F2D_HISTOHOP_PCS_RX]     = new Param_Control(xsm->Unity,   MLD_WERT_NICHT_OK, &rx, 1., 9., "2.0f");
00169   pcs[F2D_HISTOHOP_PCS_RY]     = new Param_Control(xsm->Unity,   MLD_WERT_NICHT_OK, &ry, 1., 9., "2.0f");
00170   pcs[F2D_HISTOHOP_PCS_THRES]  = new Param_Control(xsm->Unity,   MLD_WERT_NICHT_OK, &thres, -999., 999., "3.1f");
00171 
00172   pcs[F2D_HISTOHOP_PCS_RX]->Put_Value(fd_HistoHOPCpy->kern_rx);
00173   pcs[F2D_HISTOHOP_PCS_RY]->Put_Value(fd_HistoHOPCpy->kern_ry);
00174   pcs[F2D_HISTOHOP_PCS_THRES]->Put_Value(fd_HistoHOPCpy->threshold);
00175 }
00176 
00177 F2D_HistoHOP::~F2D_HistoHOP()
00178 {
00179   delete fd_HistoHOPCpy;
00180 
00181   for (int i = 0; i < F2D_HISTOHOP_PCS_ANZAHL; i++)
00182     if (pcs[i]) delete pcs[i];
00183 }
00184 
00185 void F2D_HistoHOP::hide()
00186 {
00187   fl_hide_form(fd_HistoHOPCpy->HistoHOP);
00188 }
00189 
00190 void F2D_HistoHOP::draw()
00191 {
00192   fl_show_form(fd_HistoHOPCpy->HistoHOP, FL_PLACE_FREE | FL_FIX_SIZE, FL_TRANSIENT, F2D_TITLE);
00193 }
00194 
00195 gboolean F2D_HistoHOP::exec(MATHOPPARAMS)
00196 {
00197   XSMDEBUG("F2D HistoHOP");
00198 
00199   SHT *linebuf = new SHT[Src->mem2d->GetNx()];
00200   SHT *srcbuf  = new SHT[Src->mem2d->GetNx()];
00201 
00202   // open hopfile for writing
00203   if (hopFile[0] != '\0') {
00204     hopStream = new ofstream(hopFile);
00205     if (!hopStream->good()) {
00206       hopFileOK = 0;
00207       // Error message ????
00208       return MATH_FILE_ERROR;
00209     }
00210     else {
00211       hopFileOK = 1;
00212 
00213       *hopStream << "# histoHOP data file\n";
00214       *hopStream << "# generated by $Name:  $ $Revision: 1.5 $\n";
00215       *hopStream << "# \n";
00216       *hopStream << "# format: facet length, facet height, terrace length, and terrace heigth\n";
00217       *hopStream << "# (all values in Angstrom)\n";
00218       *hopStream << "# \n";
00219     }
00220   }
00221 
00222 
00223   // threshold:
00224   //* PZ: es wäre schön hier NICHT ...Inst-> verwenden zu müssen... 
00225   //* PZ: tut´s nicht auch data.s... ?
00226   SHT lim = (SHT)(gapp->xsm->Inst->XA2Dig(1000) / gapp->xsm->Inst->ZA2Dig(1000) * thres);
00227 
00228   // compute derivative in x-direction, store derivative in Dest
00229   // (StatDiff filter)
00230   int    sx = 1+(int)(rx + .9);
00231   int    sy = 1+(int)(ry + .9);
00232   MemDeriveXKrn krn(rx,ry, sx,sy);
00233   krn.Convolve(Src->mem2d, Dest->mem2d);
00234 
00235   // look for steps
00236   for (int line=0; line < Dest->mem2d->GetNy(); line++) {
00237     Dest->mem2d->GetDataLine(line, linebuf);
00238 
00239     for (int col = 0; col < Dest->mem2d->GetNx(); col++)
00240       if ( abs(*(linebuf+col)) > lim )
00241         *(linebuf+col) = 1;
00242       else
00243         *(linebuf+col) = 0;
00244 
00245     Dest->mem2d->PutDataLine(line, linebuf);
00246   }
00247 
00248   if (!detectOnly) {
00249 
00250     // compute terraces and facettes
00251     for (int line=0; line < Dest->mem2d->GetNy(); line++) {
00252 
00253       if (hopFileOK)  *hopStream << "# scan row: " << line << '\n';
00254 
00255       Dest->mem2d->GetDataLine(line, linebuf);
00256       Src->mem2d->GetDataLine(line, srcbuf);
00257       int xfs = 0;  // facet start pos
00258       int xfe = 0;  // facet end pos
00259       int xte = 0;  // terrace end pos
00260       int x   = 0;  // current pos
00261 
00262       while (x < Dest->mem2d->GetNx()-1) {
00263       
00264         // find facette
00265         xfs = x;
00266         while ( *(linebuf+x) && x < Dest->mem2d->GetNx()-1)  x++;
00267         xfe = x;
00268 
00269         // find terrace
00270         while ( ! *(linebuf+x) && x < Dest->mem2d->GetNx()-1)  x++;
00271         xte = x;
00272 
00273         // interpolate data on facet
00274         for (int col=xfs; col < xfe; col++)
00275           *(linebuf+col) = *(srcbuf+xfs) + 
00276             (SHT)( (double)(*(srcbuf+xfe)-*(srcbuf+xfs)) / (double)(xfe-xfs) * (col-xfs) );
00277 
00278         // interpolate data on terrace
00279         for (int col=xfe; col < xte; col++)
00280           *(linebuf+col) = *(srcbuf+xfe) + 
00281             (SHT)( (double)(*(srcbuf+xte)-*(srcbuf+xfe)) / (double)(xte-xfe) * (col-xfe) );
00282 
00283         // write data to statistic file
00284         if (hopFileOK) {
00285           *hopStream << Src->data.s.dx*(xfe-xfs);                                // facet length
00286           *hopStream << "  " << Src->data.s.dz*(*(srcbuf+xfe) - *(srcbuf+xfs));  // facet height
00287           *hopStream << "  " << Src->data.s.dx*(xte-xfe);                        // terrace length
00288           *hopStream << "  " << Src->data.s.dz*(*(srcbuf+xte) - *(srcbuf+xfe));  // terrace height
00289           *hopStream << '\n';
00290         }
00291 
00292       }
00293       
00294       Dest->mem2d->PutDataLine(line, linebuf);
00295     }
00296 
00297   }  // end if(!detectOnly)
00298 
00299   delete linebuf;
00300   delete srcbuf;
00301 
00302   if (hopFileOK)  delete hopStream;
00303 
00304   return MATH_OK;
00305 }
00306 
00307 gboolean ST_HistoHOP_FD(MATHOPPARAMS)
00308 {
00309   return xsm->f2D_HistoHOP->exec(Src, Dest);
00310 }
00311 
00312 #endif // Histo HOP

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