예제 #1
0
void
FilterROIDraw::apply()
{
  if ( dst_roi ) {
    draw_roi(dst_roi);
  }
  if ( __rois ) {
    for (std::list<ROI>::const_iterator r = __rois->begin(); r != __rois->end(); ++r) {
      draw_roi(&(*r));
    }
  }
}
예제 #2
0
파일: handler.c 프로젝트: BIC-MNI/xdisp
/*---------------------------- HandleEvent --------------------------*/
int HandleEvent(XEvent *event)
{
  int	i;
    
  if(theEvent.xany.window==mainW) {

    switch (event->type) {
    case Expose: {
      XExposeEvent *exp_event = (XExposeEvent *) event;
 
      if (exp_event->window==mainW) {
	DrawWindow(exp_event->x,exp_event->y,
		   exp_event->width, exp_event->height);
      }
    }
    break;

    case EnterNotify: {
      if (Selected_Visual_Class==DirectColor)
	XStoreColors(theDisp,NewCmap,newC,ColorMapSize);
      if (Selected_Visual_Class!=TrueColor)
	XInstallColormap(theDisp,NewCmap);
    }
    break;
    
    case LeaveNotify: {
      if (Selected_Visual_Class==DirectColor)
	XStoreColors(theDisp,NewCmap,rootC,ColorMapSize); 
    }
    break;

    case KeyPress: {	/* allow a quit from the image window */
      Handle_KeyPress(event);
    }
    break;

    case MotionNotify: {
      Handle_Motion(event);
    }
    break;

    case ConfigureNotify: {
      XConfigureEvent *conf_event = (XConfigureEvent *) event;

      if (conf_event->window == cmdW && 
	  (conf_event->width != cmd_width ||
	   conf_event->height != cmd_height))
	XResizeWindow(theDisp,cmdW,cmd_width,cmd_height);
      if (conf_event->window == mainW && 
	  (conf_event->width != zWidth+(color_bar?color_bar_width:0) ||
	   conf_event->height != zHeight+info_height))
	Resize(conf_event->width-(color_bar?color_bar_width:0),
	       conf_event->height-info_height);
    }
    break;

    case ButtonPress: {
      if (theEvent.xbutton.button==Button1) {
	if (selzoom_active) {
	  Selective_Zoom((caddr_t)&one);
	  break;
	}
	XDefineCursor(theDisp,mainW,roiCursor);
	XFlush(theDisp);
	if (roi_present) draw_roi(roi_x1, roi_y1, roi_x2, roi_y2);
	roi_active = 1;
	roi_x1 = theEvent.xmotion.x < zWidth ?
	  (theEvent.xmotion.x>0 ?
	   theEvent.xmotion.x : 0) : zWidth-1;
	roi_y1 = theEvent.xmotion.y < zHeight ?
	  (theEvent.xmotion.y>0 ?
	   theEvent.xmotion.y : 0) : zHeight-1;
	roi_x2 = roi_x1;
	roi_y2 = roi_y1;
	draw_roi(roi_x1, roi_y1, roi_x2, roi_y2);
	break;
      } 
      if (theEvent.xbutton.button==Button2) {
	XDefineCursor(theDisp,mainW,wlCursor);
	XClearArea(theDisp,mainW,0,zHeight,
		   zWidth,zHeight+info_height,False);
	XDrawImageString(theDisp,mainW,theMGC,
			 zWidth-XTextWidth(ol_text_finfo,
					   wl_msg,strlen(wl_msg))-4,
			 zHeight+info_height-4,wl_msg,strlen(wl_msg));
	XDrawImageString(theDisp,mainW,theMGC,4,
			 zHeight+info_height-4,loc_msg,strlen(loc_msg));
	XFlush(theDisp);
	break;
      } 
      if (theEvent.xbutton.button==Button3) {
	/* note: not really 'iconic' anymore, simply map or unmap */
	if (cmdW_State==NormalState) {
	  XUnmapWindow(theDisp,cmdW);
	  cmdW_State = IconicState;
	}
	else {
	  XMapWindow(theDisp,cmdW);
	  cmdW_State = NormalState;
	}
	break;
      } 
    }
    break;

    case ButtonRelease: {
      int xa, xb, ya, yb;
      if (theEvent.xbutton.button==Button1 && roi_active) {
	roi_active = 0;
	xa = roi_x1*(Width-1)/(zWidth-1);
	xb = roi_x2*(Width-1)/(zWidth-1);
	ya = roi_y1*(Height-1)/(zHeight-1);
	yb = roi_y2*(Height-1)/(zHeight-1);
	roi_stats(xa, ya, xb, yb, 0);
	XDefineCursor(theDisp,mainW,mainCursor);
	XFlush(theDisp);
      }
      if (theEvent.xbutton.button==Button2) {
	XDefineCursor(theDisp,mainW,mainCursor);
	XFlush(theDisp);               
	if (Scale_Data && (oUpper != Upper || oLower != Lower)) {
	  Rescale();
	  Window_Level(Lower,Upper); 
	  oLower=Lower; oUpper=Upper; 
	}
	XClearArea(theDisp,mainW,0,zHeight,
		   zWidth,zHeight+info_height,False);
	if (wl_display) 
	  XDrawImageString(theDisp,mainW,theMGC,
			   zWidth-XTextWidth(ol_text_finfo,wl_msg,strlen(wl_msg))-4,
			   zHeight+info_height-4,wl_msg,strlen(wl_msg));
	XDrawImageString(theDisp,mainW,theMGC,4,
			 zHeight+info_height-4,loc_msg,strlen(loc_msg));
	update_sliders();
	update_msgs();
      }
    }
    break;

    case UnmapNotify: {
      if (bitmap_pad==8) {
	if (Interpolation_Type==BILINEAR) {
	  bilinear_byte_to_byte(byte_Image, Width, Height,
				icon_byte_image, ICON_WIDTH, ICON_HEIGHT);
	}
	else {
	  nneighbour_byte_to_byte(byte_Image, Width, Height,
				  icon_byte_image, ICON_WIDTH, ICON_HEIGHT);
	}
      }
      else {
	if (Interpolation_Type==BILINEAR) {
	  bilinear_rgbp_to_rgbp(byte_Image, Width, Height,
				icon_byte_image, ICON_WIDTH, ICON_HEIGHT);
	}
	else {
	  nneighbour_rgbp_to_rgbp(byte_Image, Width, Height,
				  icon_byte_image, ICON_WIDTH, ICON_HEIGHT);
	}
      }
      XPutImage(theDisp,iconW,theMGC,iconImage,0,0,0,0,
		ICON_WIDTH, ICON_HEIGHT);
    }
    break;
                
    case CirculateNotify:
    case MapNotify:
    case DestroyNotify:
    case GravityNotify:
    case ReparentNotify:
    default: 
    break;
    }  /* end of switch */
  }

  /* other command Window events */
  if(theEvent.xany.window==cmdW) {

    switch (event->type) {
    case Expose: {
      update_msgs();
    }
    break;

    case EnterNotify: {
      if (Selected_Visual_Class==DirectColor)
	XStoreColors(theDisp,NewCmap,newC,ColorMapSize); 
      if (Selected_Visual_Class!=TrueColor)
	XInstallColormap(theDisp,NewCmap);
    }
    break;

    case LeaveNotify: {
      if (Selected_Visual_Class==DirectColor)
	XStoreColors(theDisp,NewCmap,rootC,ColorMapSize); 
    }
    break;

    case UnmapNotify: {
      cmdW_State = IconicState;
    }
    break;
            
    case MapNotify: {
      cmdW_State = NormalState;
    }
    break;

    case ConfigureNotify: {
      XConfigureEvent *conf_event = (XConfigureEvent *) event;

      if (conf_event->window == cmdW && 
	  (conf_event->width != cmd_width ||
	   conf_event->height != cmd_height))
	XResizeWindow(theDisp,cmdW,cmd_width,cmd_height);
    }
    break;

    default: break;
    }
  }

  /* button press events */
  if (XFindContext(theDisp, theEvent.xany.window, xwin_context,
		   (caddr_t *) &which_xwin)==0) {
    if(*(which_xwin->event_handler)!=NULL)
      (*(which_xwin->event_handler))(which_xwin);
    if (Scale_Data && (oUpper != Upper || oLower != Lower)) {
      Rescale();
      oLower=Lower; oUpper=Upper;
    }
  }
}
예제 #3
0
파일: tic.c 프로젝트: BIC-MNI/xdisp
/*-------------------------- TIC ---------------------------------*/
int TIC()
{
  int 	i, j, im, org_image; 
  char  tmp_name[40], tmp_cmd[80];
  float rw_loc;
  FILE	*out;    
    
  /* check that an roi is defined */
  if (roi_present != 1) {
    fprintf(stderr,"An ROI must be drawn before calculating its time course.\n");
    return;
  }

  /* open output file */
  tmpnam(tmp_name);
  if(!(out = fopen(tmp_name,"w"))){ 
    fprintf(stderr,"Unable to open temporary file\n");
    return;
  }

  /* define new cursors */
  XDefineCursor(theDisp,mainW,waitCursor);
  XDefineCursor(theDisp,cmdW,waitCursor);
  XFlush(theDisp);

  /* save current image position */
  org_image = image_number;
    
  /* cycle through images and dump results to file */
  for (im=0; im<slider_length[current_dim]; im++) {
    fprintf(stderr,"Processing image %d\r",im+1);
    image_increment = im - slider_image[current_dim];
    New_Image();
    draw_roi(roi_x1,roi_y1,roi_x2,roi_y2);
    roi_stats(roi_x1*(Width-1)/(zWidth-1),
	      roi_y1*(Height-1)/(zHeight-1),
	      roi_x2*(Width-1)/(zWidth-1),
	      roi_y2*(Height-1)/(zHeight-1),1);
    if (file_format==MINC_FORMAT && 
	RW_valid &&
	minc_volume_info.step[current_dim]!=0 ) {
      rw_loc = minc_volume_info.start[current_dim] + 
	(float) slider_image[current_dim] * 
	minc_volume_info.step[current_dim];
      fprintf(out,"%f %f %f \n",rw_loc,tic_mean,tic_std);
    }
    else {
      fprintf(out,"%d  %f %f\n",im+1,tic_mean,tic_std);
    }
  }

  /* display original image */
  image_increment = org_image - image_number;
  New_Image();
  draw_roi(roi_x1,roi_y1,roi_x2,roi_y2);
    
  /* print plot commands */
  fprintf(out,"@s0 type xy \n");
  fprintf(out,"@s0 symbol 2 \n");
  fprintf(out,"@s0 symbol fill 1 \n");
  if (file_format==MINC_FORMAT && 
      RW_valid &&
      minc_volume_info.step[current_dim]!=0 ) {
    fprintf(out,"@xaxis label \"%s (%s)\"\n", 
	    minc_volume_info.dimension_names[current_dim],
	    minc_volume_info.dimension_units[current_dim]);
  }
  else if (file_format==MINC_FORMAT) {
    fprintf(out,"@xaxis label \"Frame (%s)\"\n", 
	    minc_volume_info.dimension_names[current_dim]);
  }
  else {
    fprintf(out,"@xaxis label \"Image Number\"\n");
  }
  fprintf(out,"@yaxis label \"ROI Mean\"\n");
  fprintf(out,"@title \"%s\"\n",basfname);
  fprintf(out,"@frame fill on\n");
  fprintf(out,"@frame background color 7\n");

  /* close file */
  fclose(out);
  fprintf(stderr,"                                              \r");

  /* issue shell commands */
  if (GRACE) {
    sprintf(tmp_cmd,"cat %s | xmgrace -pipe &\n",tmp_name); 
  }
  else {
    sprintf(tmp_cmd,"cat %s | xmgr -xy -source stdin &\n",tmp_name); 
  }
  system (tmp_cmd); 
  sprintf(tmp_cmd,"rm %s &\n",tmp_name); 
  system (tmp_cmd); 
    
  /* define new cursors */
  XDefineCursor(theDisp,mainW,mainCursor);
  XDefineCursor(theDisp,cmdW,cmdCursor);
  XFlush(theDisp);
}