00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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;
00141
00142
00143
00144
00145
00146 };
00147
00148
00149
00150
00151
00152
00153 F2D_HistoHOP::F2D_HistoHOP()
00154 {
00155
00156 fd_HistoHOP = create_form_HistoHOP();
00157 fd_HistoHOPCpy = new FD_HistoHOP;
00158 memcpy(fd_HistoHOPCpy, fd_HistoHOP, sizeof(FD_HistoHOP));
00159 fl_set_form_atclose(fd_HistoHOPCpy->HistoHOP, cb_do_close, 0);
00160
00161
00162 rx = 1.0; ry = 1.0;
00163 thres = 10.0;
00164 *hopFile = '\0';
00165 hopFileOK = 0;
00166
00167
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
00203 if (hopFile[0] != '\0') {
00204 hopStream = new ofstream(hopFile);
00205 if (!hopStream->good()) {
00206 hopFileOK = 0;
00207
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
00224
00225
00226 SHT lim = (SHT)(gapp->xsm->Inst->XA2Dig(1000) / gapp->xsm->Inst->ZA2Dig(1000) * thres);
00227
00228
00229
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
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
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;
00258 int xfe = 0;
00259 int xte = 0;
00260 int x = 0;
00261
00262 while (x < Dest->mem2d->GetNx()-1) {
00263
00264
00265 xfs = x;
00266 while ( *(linebuf+x) && x < Dest->mem2d->GetNx()-1) x++;
00267 xfe = x;
00268
00269
00270 while ( ! *(linebuf+x) && x < Dest->mem2d->GetNx()-1) x++;
00271 xte = x;
00272
00273
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
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
00284 if (hopFileOK) {
00285 *hopStream << Src->data.s.dx*(xfe-xfs);
00286 *hopStream << " " << Src->data.s.dz*(*(srcbuf+xfe) - *(srcbuf+xfs));
00287 *hopStream << " " << Src->data.s.dx*(xte-xfe);
00288 *hopStream << " " << Src->data.s.dz*(*(srcbuf+xte) - *(srcbuf+xfe));
00289 *hopStream << '\n';
00290 }
00291
00292 }
00293
00294 Dest->mem2d->PutDataLine(line, linebuf);
00295 }
00296
00297 }
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