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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 #include <gtk/gtk.h>
00066 #include <glib.h>
00067 #include <math.h>
00068 #include "config.h"
00069 #include "gxsm/plugin.h"
00070
00071
00072 static void probe_image_extract_about( void );
00073 static void probe_image_extract_configuration( void );
00074 static gboolean probe_image_extract_run( Scan *Src, Scan *Dest );
00075
00076
00077 GxsmPlugin probe_image_extract_pi = {
00078 NULL,
00079 NULL,
00080 0,
00081 NULL,
00082 "Probe_Image_Extract-M1S-PX",
00083 NULL,
00084 NULL,
00085 "Bastian Weyers",
00086 "_Math/_Probe/",
00087 N_("Image Extract"),
00088 N_("Probe Image Extract of selection of scan"),
00089 "no more info",
00090 NULL,
00091 NULL,
00092 NULL,
00093 NULL,
00094 probe_image_extract_about,
00095 probe_image_extract_configuration,
00096 NULL,
00097 NULL
00098 };
00099
00100 GxsmMathOneSrcPlugin probe_image_extract_m1s_pi = {
00101 probe_image_extract_run
00102 };
00103
00104 static const char *about_text = N_("Gxsm (Raster-) Probe Image Extraction Math-Plugin\n\n"
00105 "Probe Event Data extraction:\n"
00106 "A new image is generated from specified probe data.");
00107
00108 double IndexDefault = 0.;
00109 double IndexLast = 0.;
00110
00111 GxsmPlugin *get_gxsm_plugin_info ( void ){
00112 probe_image_extract_pi.description = g_strdup_printf(N_("Gxsm MathOneArg probe_image_extract plugin %s"), VERSION);
00113 return &probe_image_extract_pi;
00114 }
00115
00116 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) {
00117 return &probe_image_extract_m1s_pi;
00118 }
00119
00120 static void probe_image_extract_about(void)
00121 {
00122 const gchar *authors[] = { probe_image_extract_pi.authors, NULL};
00123 gtk_widget_show(gnome_about_new ( probe_image_extract_pi.name,
00124 VERSION,
00125 N_("(C) 2000 the Free Software Foundation"),
00126 about_text,
00127 authors,
00128 NULL, NULL, NULL
00129 ));
00130 }
00131
00132 static void probe_image_extract_configuration( void ){
00133 probe_image_extract_pi.app->ValueRequest("Enter Number", "Index",
00134 "Default set index for data extraction.",
00135 probe_image_extract_pi.app->xsm->Unity,
00136 0., 20., ".0f", &IndexDefault);
00137 }
00138
00139 gint find_probe (gpointer *se, gpointer *default_probe_event){
00140 return (((EventEntry*) ((ScanEvent*)se)->event_list->data)->description_id () == 'P' ? 0:-1);
00141 }
00142
00143 gint compare_events_distance (ScanEvent *a, ScanEvent *b, double *xy){
00144 double da = a->distance2 (xy);
00145 double db = b->distance2 (xy);
00146 if (da < db) return -1;
00147 if (da > db) return 1;
00148 return 0;
00149 }
00150
00151 gint check_probe (ProbeEntry *a, ProbeEntry *b, char *Source2){
00152
00153 for (int j=0; j<b->get_chunk_size (); j++){
00154 if (! strncmp (b->get_label (j), Source2, 4)) return j;
00155 }
00156
00157 return -1;
00158 }
00159
00160 void ChangeValue (GtkComboBox* Combo, gchar **string){
00161 GtkTreeIter iter;
00162 GtkTreeModel *model;
00163 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (Combo), &iter);
00164 model = gtk_combo_box_get_model (GTK_COMBO_BOX (Combo));
00165 gtk_tree_model_get (model, &iter, 0, &(*string), -1);
00166
00167 }
00168
00169 void ChangeIndex (GtkSpinButton *spinner, double *index){
00170 *index = gtk_spin_button_get_value (spinner);
00171
00172
00173 }
00174
00175 void Dialog (ProbeEntry* defaultprobe, gchar **Source1, gchar **Source2, double *index){
00176
00177 GtkWidget *dialog;
00178 GtkWidget *label;
00179 GtkWidget *vbox;
00180 GtkWidget *hbox;
00181 GtkWidget *source1_combo;
00182 GtkWidget *source2_combo;
00183 GtkWidget *spinner;
00184 GtkAdjustment *spinner_adj;
00185
00186 char* Source1_lookup[] = { "Zmon", "Umon", "Time", "XS", "YS",
00187 "ZS", "Bias", "Phase", NULL};
00188
00189 char* Source2_lookup[] = { "ADC0", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5-I","ADC6","ADC7",
00190 "Zmon", "LockIn0", "LockIn1stA", "LockIn1stB", "LockIn2ndA",
00191 "LockIn2ndB", NULL};
00192
00193 dialog = gtk_dialog_new_with_buttons (_("Settings"),
00194 NULL,
00195 (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
00196 GTK_STOCK_OK,
00197 GTK_RESPONSE_ACCEPT,
00198 NULL);
00199
00200 vbox = gtk_vbox_new (FALSE, 0);
00201 gtk_widget_show (vbox);
00202 gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),
00203 vbox, FALSE, FALSE, GNOME_PAD);
00204
00205 hbox = gtk_hbox_new (FALSE, 0);
00206 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
00207 gtk_widget_show (hbox);
00208 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
00209
00210 label = gtk_label_new (_("Source for layer: "));
00211 gtk_widget_show (label);
00212 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
00213
00214 source1_combo = gtk_combo_box_new_text ();
00215 gtk_combo_box_append_text (GTK_COMBO_BOX (source1_combo), "Index");
00216 for (int i=0; i<defaultprobe->get_chunk_size (); i++){
00217 int j=0;
00218 while (Source1_lookup[j]){
00219 if (!strncmp (defaultprobe->get_label (i), Source1_lookup[j], 4)){
00220 gtk_combo_box_append_text (GTK_COMBO_BOX (source1_combo), defaultprobe->get_label (i));
00221 break;
00222 }
00223 j++;
00224 }
00225 }
00226 gtk_combo_box_set_active (GTK_COMBO_BOX (source1_combo), 0);
00227 ChangeValue(GTK_COMBO_BOX (source1_combo), &(*Source1));
00228 gtk_widget_show (source1_combo);
00229 gtk_signal_connect(GTK_OBJECT (source1_combo), "changed", GTK_SIGNAL_FUNC (ChangeValue), &(*Source1));
00230 gtk_box_pack_start (GTK_BOX (hbox), source1_combo, FALSE, FALSE, 0);
00231
00232
00233 hbox = gtk_hbox_new (FALSE, 0);
00234 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
00235 gtk_widget_show (hbox);
00236 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
00237
00238 label = gtk_label_new (_("Channel to map: "));
00239 gtk_widget_show (label);
00240 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
00241
00242 source2_combo = gtk_combo_box_new_text ();
00243 for (int i=0; i<defaultprobe->get_chunk_size (); i++){
00244 int j=0;
00245 while (Source2_lookup[j]){
00246 if (!strncmp (defaultprobe->get_label (i), Source2_lookup[j], 4)){
00247 gtk_combo_box_append_text (GTK_COMBO_BOX (source2_combo), defaultprobe->get_label (i));
00248 break;
00249 }
00250 j++;
00251 }
00252 }
00253 gtk_combo_box_set_active (GTK_COMBO_BOX (source2_combo), 0);
00254 ChangeValue(GTK_COMBO_BOX (source2_combo), &(*Source2));
00255 gtk_widget_show (source2_combo);
00256 gtk_signal_connect(GTK_OBJECT (source2_combo), "changed", GTK_SIGNAL_FUNC (ChangeValue), &(*Source2));
00257 gtk_box_pack_start (GTK_BOX (hbox), source2_combo, FALSE, FALSE, 0);
00258
00259 hbox = gtk_hbox_new (FALSE, 0);
00260 gtk_container_set_border_width (GTK_CONTAINER (hbox), 8);
00261 gtk_widget_show (hbox);
00262 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
00263
00264 label = gtk_label_new (_("Image Filter\n0 (sharp) ... 10 (smooth)"));
00265 gtk_widget_show (label);
00266 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
00267
00268 spinner_adj = (GtkAdjustment *) gtk_adjustment_new (IndexLast, 0.0, 10.0, 0.1, 1.0, 1.0);
00269 spinner = gtk_spin_button_new (spinner_adj, 0.1, 1);
00270 gtk_widget_show (spinner);
00271 gtk_signal_connect(GTK_OBJECT (spinner), "changed", GTK_SIGNAL_FUNC (ChangeIndex), &(*index));
00272 gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0);
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 gtk_dialog_run(GTK_DIALOG(dialog));
00284 gtk_widget_destroy (dialog);
00285
00286 }
00287
00288
00289
00290 static gboolean probe_image_extract_run(Scan *Src, Scan *Dest)
00291 {
00292 PI_DEBUG (DBG_L2, "Probe_Image_Extract Scan");
00293
00294 int numsets = Dest->mem2d->GetNv ();
00295 int avgvectors = 5;
00296 double radius;
00297 double xy[2];
00298 double index = IndexLast;
00299 gchar *Source1;
00300 gchar *Source2;
00301 int iSource1 = -1;
00302 int iSource2 = -1;
00303 int jSource2 = -1;
00304 int Nx = Src->mem2d->GetNx ();
00305 int Ny = Src->mem2d->GetNy ();
00306 int xmin, xmax, ymin, ymax;
00307
00308
00309 GSList *ProbeEventList = g_slist_find_custom (Src->mem2d->scan_event_list, NULL, (GCompareFunc)find_probe);
00310 ScanEvent* default_probe_event = (ScanEvent*) ProbeEventList->data;
00311 if (!default_probe_event) return MATH_OK;
00312 ProbeEntry* defaultprobe = (ProbeEntry*) default_probe_event->event_list->data;
00313
00314 Dialog (defaultprobe, &Source1, &Source2, &index);
00315 IndexLast = index;
00316
00317
00318 PI_DEBUG (DBG_L2, "Source1 = " << Source1 << std::endl);
00319 PI_DEBUG (DBG_L2, "Source2 = " << Source2 << std::endl);
00320 PI_DEBUG (DBG_L2, "Index: " << index << std::endl);
00321
00322
00323 for (int j=0; j<defaultprobe->get_chunk_size (); j++){
00324
00325 if (! strncmp (defaultprobe->get_label (j), Source1, 4)) iSource1 = j;
00326 if (! strncmp (defaultprobe->get_label (j), Source2, 4)) iSource2 = j;
00327 }
00328 if (iSource2 < 0) return MATH_OK;
00329
00330 numsets = defaultprobe->get_num_sets ();
00331 Dest->mem2d->Resize(Dest->mem2d->GetNx (), Dest->mem2d->GetNy (), numsets, ZD_FLOAT);
00332 Dest->mem2d->data->MkVLookup(0., (double)numsets);
00333 Dest->data.s.nvalues=numsets;
00334 Dest->data.s.ntimes=1;
00335 Dest->data.s.dz=1.;
00336
00337 if (Source1 < 0){
00338 UnitObj *NUnit = new UnitObj( " "," ",".0f", "#");
00339 Dest->data.SetVUnit (NUnit);
00340 delete NUnit;
00341 for (int n=0; n<numsets; n++) Dest->mem2d->data->SetVLookup(n, n);
00342 } else {
00343 UnitObj *NUnit = new UnitObj( defaultprobe->get_unit_symbol(iSource1), defaultprobe->get_unit_symbol(iSource1),".3f", defaultprobe->get_label (iSource1));
00344 Dest->data.SetVUnit (NUnit);
00345 delete NUnit;
00346 for (int n=0; n<numsets; n++) Dest->mem2d->data->SetVLookup(n, defaultprobe->get (n, iSource1));
00347 }
00348
00349 UnitObj *VoltUnit = new UnitObj( defaultprobe->get_unit_symbol (iSource2), defaultprobe->get_unit_symbol (iSource2),".3f", defaultprobe->get_label (iSource2));
00350 Dest->data.SetZUnit (VoltUnit);
00351 delete VoltUnit;
00352
00353
00354 double smoothness = pow(2., index-1.);
00355 radius = sqrt( (double)(Dest->mem2d->GetNx () * Dest->mem2d->GetNy () * avgvectors)/(double)(3*g_slist_length (Src->mem2d->scan_event_list)))+smoothness;
00356 PI_DEBUG (DBG_L2, "radius = " << radius << std::endl);
00357
00358 PI_DEBUG (DBG_L2, "Initialising lookup table for " << g_slist_length (Src->mem2d->scan_event_list) << " probe events." << std::endl);
00359
00360
00361 int* matrix = new int [Nx * Ny];
00362 for (int i=0; i < Nx * Ny; i++) matrix[i]=-1;
00363
00364 for (int n=0; n < g_slist_length (Src->mem2d->scan_event_list); n++){
00365 ScanEvent* se = (ScanEvent*) g_slist_nth_data (Src->mem2d->scan_event_list, n);
00366 if (!se) {
00367 PI_DEBUG (DBG_L2, "Empty Scan_Event found!");
00368 }
00369 else if (((EventEntry*) (se->event_list->data))->description_id () == 'P'){
00370 int xn,yn = 0;
00371 ProbeEntry* pe = (ProbeEntry*) se->event_list->data;
00372 se->get_position(xy[0], xy[1]);
00373 Dest->World2Pixel(xy[0],xy[1], xn , yn);
00374 if ( xn >= 0 && xn < Nx && yn >= 0 && yn < Ny ){
00375 matrix[yn*Nx+xn] = n;
00376
00377 }
00378 }}
00379
00380
00381
00382 double avgvalues[numsets], avgnorm;
00383 int dead_pixel = 0;
00384
00385 gapp->progress_info_new ("Converting Probe Data...", 1);
00386 gapp->progress_info_set_bar_fraction (0., 1);
00387 gapp->progress_info_set_bar_text (" ", 1);
00388
00389
00390
00391 for (int yi=0; yi < Dest->mem2d->GetNy (); yi++){
00392
00393 gapp->progress_info_set_bar_fraction ( (double) (yi+1)/Dest->mem2d->GetNy () , 1);
00394 gapp->progress_info_set_bar_text (g_strdup_printf("Line %i of %i", yi+1, Dest->mem2d->GetNy ()), 1);
00395
00396
00397
00398
00399
00400 int counter = 0;
00401 int pe_number = -1;
00402
00403 for (int xi=0; xi < Dest->mem2d->GetNx (); xi++){
00404
00405
00406
00407 int found_a_vector = 0;
00408 for (int i=0; i<numsets; i++) avgvalues[i] = avgnorm = 0.;
00409
00410 if ( (xmin = xi - (int)radius) < 0) xmin = 0;
00411 if ( (xmax = xi + (int)radius) > Nx) xmax = Nx;
00412 if ( (ymin = yi - (int)radius) < 0) ymin = 0;
00413 if ( (ymax = yi + (int)radius) > Ny) ymax = Ny;
00414
00415 for (int xpos=xmin; xpos < xmax; xpos++){
00416 for (int ypos=ymin; ypos < ymax; ypos++){
00417 if ( (pe_number = matrix[ypos*Nx+xpos]) >= 0){
00418 counter++;
00419
00420 ProbeEntry* pe = (ProbeEntry*) ((ScanEvent*) g_slist_nth_data (Src->mem2d->scan_event_list, pe_number))->event_list->data;
00421 jSource2 = check_probe(defaultprobe, pe, Source2);
00422 if ( jSource2 >= 0 ){
00423 double norm = exp(-sqrt((double)((xpos-xi)*(xpos-xi)+(ypos-yi)*(ypos-yi))/smoothness));
00424 avgnorm += norm;
00425 for (int zi=0; zi < numsets; zi++){
00426 avgvalues[zi] += norm * pe->get(zi, jSource2);
00427 }
00428 found_a_vector++;
00429 }
00430 }
00431
00432 }}
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462 for (int i=0; i<numsets; i++) {
00463 if (found_a_vector == 0){
00464 dead_pixel++;
00465 PI_DEBUG (DBG_L2, "dead_pixel at X" << xi << " Y" << yi << std::endl);
00466 }
00467 else {
00468 for (int zi=0; zi<numsets; zi++){
00469 Dest->mem2d->PutDataPkt ( avgvalues[zi]/avgnorm, xi, yi, zi);
00470 }
00471 }
00472
00473
00474 }
00475 }}
00476
00477 delete [] matrix;
00478
00479 gapp->progress_info_close ();
00480 PI_DEBUG (DBG_L2, "Total number of dead_pixel: " << dead_pixel << std::endl);
00481 return MATH_OK;
00482 }