示例#1
0
int compose_compound(F_compound *c)
{
    c->ellipses = NULL;
    c->lines = NULL;
    c->texts = NULL;
    c->splines = NULL;
    c->arcs = NULL;
    c->comments = NULL;
    c->compounds = NULL;
    /* defer updating of layer buttons until we've composed the entire compound */
    defer_update_layers = True;
    get_ellipse(&c->ellipses);
    get_line(&c->lines);
    get_spline(&c->splines);
    get_text(&c->texts);
    get_arc(&c->arcs);
    get_compound(&c->compounds);
    /* now update the layer buttons */
    defer_update_layers = False;
    update_layers();
    if (c->ellipses != NULL)
	return (1);
    if (c->splines != NULL)
	return (1);
    if (c->lines != NULL)
	return (1);
    if (c->texts != NULL)
	return (1);
    if (c->arcs != NULL)
	return (1);
    if (c->compounds != NULL)
	return (1);
    return (0);
}
/* ==========================================================================
   get_score 
   ========================================================================== */
float get_score(int w_x[],int w_y[],int nwhisker_points,TMatrix2D I_Conv)
{
  float **conv_dat;
  float score = 0;
  int min_x,max_x;
  int *yy, x;
  int ncols, nrows;

  conv_dat = Mat2D_getDataFloat(I_Conv);
  ncols = Mat2D_getnCols(I_Conv);
  nrows = Mat2D_getnRows(I_Conv);
  
  min_x = IMAX(w_x[0],0);
  max_x = IMIN(w_x[nwhisker_points-1],nrows-1);

  get_spline(w_x,w_y,nwhisker_points,min_x, max_x, &yy);
  
  for (x=min_x;x<=max_x;x++)
    if (yy[x]>=0 && yy[x]<ncols)
      score += conv_dat[x][yy[x]];
  
  free_ivector(yy,min_x,max_x);

  return(score);
}
/* ==========================================================================
   get_I_Conv

   Convulve I_Conv with oriented filter according to the whisker angle
   ========================================================================== */
void get_I_Conv(int *w0_x,int *w0_y,int nwhisker_points, 
		TMatrix2D image, int min_y, int max_y,
		TMatrix2D filters[], TMatrix2D *I_Conv_p)
{
  int i,x_val;
  int *yy;
  int *angle_vec;
  int spline_len;  
  int filt_size;
  int min_x, max_x;
  int nrows;

  nrows = Mat2D_getnRows(image);

  /* calculate spline of w0 */

  min_x = IMAX(w0_x[0],0);
  max_x = IMIN(w0_x[nwhisker_points-1],nrows-1);

  filt_size = (Mat2D_getnRows(filters[0])-1)/2;

  get_spline(w0_x,w0_y,nwhisker_points,min_x-COL_WIDTH, max_x+COL_WIDTH, &yy);
  get_angle_vec(yy,min_x,max_x,COL_WIDTH,&angle_vec);

    /* for (i=0;i<nwhisker_points;i++) */
    /*    mexPrintf("w0[%d]: %d %d\n",i,w0_x[i],w0_y[i]); */
    /* mexPrintf("\n"); */
    /* for (x_val=min_x;x_val<=max_x;x_val++) */
    /*     mexPrintf("spline[%d]: %d angle = %d\n",x_val,yy[x_val],angle_vec[x_val]); */
    /*   mexPrintf("\n"); */

  /* convolve each column of I_Conv with correct filter (according to angle) */

  convolve_image_by_angle(image,filters,filt_size,angle_vec,
			  min_x,max_x,min_y,max_y,I_Conv_p);

  free_ivector(yy,min_x-COL_WIDTH, max_x+COL_WIDTH);
  free_ivector(angle_vec,min_x,max_x);

 /*  Mat2D_display(*I_Conv_p); */
}