static void show_color(MBLOCK *mblk, int col_id) { int save_win_id; char *label; int colornamecount; char **arraydata; int win_id = mblk->info->colorwin_id; int block_id = mblk->info->colorblock_id; int array_id = mblk->info->colorarray_id; g_push_gc(); save_win_id=g_get_windownr(); g_select_window(win_id); g_delete_object(mblk->spar[S_COLORMAP].obj_id+1); g_open_object(mblk->spar[S_COLORMAP].obj_id+1); g_select_viewport(mblk->spar[S_COLORMAP].vp_id); g_set_foreground(col_id); g_fillrectangle(0,MAXROW,MAXCOLUMN,MAXROW+1); g_moveto(0.2,MAXROW+0.2); if (col_id == G_WHITE ) g_set_foreground(G_BLACK); else g_set_foreground(G_WHITE); g_set_font(G_FONT_HELVETICA_BOLD,G_RELATIVE_FONTSCALING); g_set_charsize(1.0); arraydata = psnd_get_colornames(&colornamecount); label = psnd_sprintf_temp("Block%d:%s:Color=%d", block_id+1, arraydata[array_id], col_id); g_label(label); g_close_object(mblk->spar[S_COLORMAP].obj_id+1); g_call_object(mblk->spar[S_COLORMAP].obj_id+1); g_flush(); g_pop_gc(); g_select_window(save_win_id); }
/* * Integrate peaks */ void psnd_integrate1d(MBLOCK *mblk, float x1, float x2) { int i; int i1 = round(x1); int i2 = round(x2); int lim1 = min(i1, i2); int lim2 = max(i1, i2); int xmin, xmax; float sum0, sum1, sum, ymin, ymax, yrange,xx; char *label; POPUP_INFO *popinf = mblk->popinf + POP_INT1D; lim1 = max(1, lim1); lim2 = max(1, lim2); lim1 = min(DAT->isize, lim1); lim2 = min(DAT->isize, lim2); mblk->int1dinf->left = min(lim1,lim2); mblk->int1dinf->right = max(lim1,lim2); update_labels(mblk); lim1 = mblk->int1dinf->left; lim2 = mblk->int1dinf->right; /* * ... determine integral over visible area (and min and max) */ for (i=0,sum0=0;i<DAT->isize;i++) sum0 += DAT->xreal[i]; if (sum0 == 0) sum0 = 1; /* * * ... determine integral over selected area (and min and max) * ... and draw the intensity lines * */ g_append_object(mblk->spar[S_REAL].obj_id); g_set_foreground(mblk->spar[S_REAL].color); for (i=lim1,sum=0,xmin=lim1,xmax=lim1;i<=lim2;i++) { sum += DAT->xreal[i-1]; g_moveto((float) i, DAT->xreal[i-1]); g_lineto((float) i, 0.0); } /* * * ... calc integral * */ g_set_foreground(mblk->spar[S_REAL].color3); minmax(DAT->xreal,DAT->isize,&(DAT->ylimit[0]),&(DAT->ylimit[1])); sum1=0; yrange = (DAT->ylimit[1] - DAT->ylimit[0])/ sum0; for (i=lim1;i<lim2;i++) { sum1 += yrange * DAT->xreal[i-1]; DAT->work1[i-1] = sum1; } /* * Try to move integral on top of peak */ xx=DAT->ylimit[0]; for (i=lim1;i<lim2;i++) { if (xx < (DAT->xreal[i-1]-DAT->work1[i-1])) xx = DAT->xreal[i-1]-DAT->work1[i-1]; } /* * But not outside window */ if (DAT->work1[lim2-2]+xx>DAT->ylimit[1]) xx -= -DAT->ylimit[1] + (DAT->work1[lim2-2] + xx); xx += (DAT->ylimit[1] - DAT->ylimit[0])/100; for (i=lim1;i<lim2;i++) { DAT->work1[i-1] += xx; } /* * Draw integral */ g_moveto((float) lim1, DAT->work1[lim1-1]); for (i=lim1;i<lim2;i++) { g_lineto((float)i, DAT->work1[i-1]); } /* * Print label */ g_moveto((float) lim1, DAT->work1[lim1-1]+(DAT->work1[lim2-2]-DAT->work1[lim1-1])/2); label = psnd_sprintf_temp("%.2e", sum); /* g_set_motif_realtextrotation(1); g_set_textdirection(90);*/ g_label(label); /* g_set_textdirection(0);*/ g_set_foreground(mblk->spar[S_REAL].color); g_close_object(mblk->spar[S_REAL].obj_id); g_plotall(); /* g_set_motif_realtext rotation(0);*/ mblk->int1dinf->sum = sum; if (popinf->visible) add_integral(mblk); psnd_printf(mblk," Range: %6d%6d Area: %g\n", lim1, lim2, sum); }
/* * Display the color map in a window */ void psnd_show_colormap(MBLOCK *mblk, int numcol) { float x0,y0,dx,dy,box_height,box_width; int nx,ny,win_id, save_win_id,bar_id; char string[5]; int i,ix,iy,color=0; int colornamecount; char **arraydata; if (mblk->info->colorwin_id) { g_raise_window(mblk->info->colorwin_id); return; } arraydata = psnd_get_colornames(&colornamecount); box_width = 60.0; box_height = 30.0; nx = sqrt(numcol); if (nx>MAXCOLUMN) nx=MAXCOLUMN; ny = numcol/nx; if (nx*ny < numcol) ny++; x0 = 0.0; y0 = 0.0; dx = box_width*(nx); dy = box_height*(ny); g_push_gc(); save_win_id=g_get_windownr(); mblk->info->colorwin_id = g_open_window(G_SCREEN, x0, y0, dx, dy, "Colormap", G_WIN_BUFFER| G_WIN_BUTTONBAR2); /* g_popup_follow_cursor(TRUE); */ g_delete_object(mblk->spar[S_COLORMAP].obj_id); g_open_object(mblk->spar[S_COLORMAP].obj_id); g_set_viewport(mblk->spar[S_COLORMAP].vp_id, 0, 0, 1, 1); g_set_world(mblk->spar[S_COLORMAP].vp_id, 0, 0, nx+0.01, 1+ny+0.01); g_select_viewport(mblk->spar[S_COLORMAP].vp_id); g_set_clipping(FALSE); g_set_font(G_FONT_HELVETICA_BOLD,G_RELATIVE_FONTSCALING); g_set_charsize(1.0); for (iy=0;iy<ny;iy++) { for(ix=0;ix<nx;ix++) { g_set_foreground(color); g_fillrectangle(ix,ny-iy-1,ix+1,ny-iy); g_moveto((float)ix+0.25,(float)(ny-iy-1)+0.25); if ((color%(numcol)) == G_WHITE ) g_set_foreground(G_BLACK); else g_set_foreground(G_WHITE); sprintf(string,"%d",color); g_label(string); color++; } } g_close_object(mblk->spar[S_COLORMAP].obj_id); g_call_object(mblk->spar[S_COLORMAP].obj_id); bar_id = g_menu_create_buttonbox2(mblk->info->colorwin_id, 1); mblk->info->colorbar_id = bar_id; g_menu_append_button(bar_id, "Quit", COL_QUIT); g_menu_append_button(bar_id, "Reset", COL_DEF); g_menu_append_button(bar_id, "Save", COL_WRITE); g_menu_append_button(bar_id, "Retrieve", COL_READ); #ifdef _WIN32 g_menu_append_button(bar_id, "Item", COL_ITEM); #else { char *data[MAX_BLOCK] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }; assert(mblk->info->colorblock_id <= 12); g_menu_append_optionmenu(bar_id, "Block", COL_BLOCK, MAXBLK, mblk->info->colorblock_id, data); } g_menu_append_optionmenu(bar_id, "Item", COL_ARRAY, colornamecount, mblk->info->colorarray_id, arraydata); #endif g_menu_create_buttonbox2(mblk->info->colorwin_id, -1); g_flush(); g_pop_gc(); g_select_window(save_win_id); color = psnd_get_colorvalue(mblk,mblk->info->colorarray_id, mblk->info->colorblock_id); show_color(mblk, color); }