Example #1
0
/************************************************************************
*                                                                       *
*  Parse the RHS of math expression "cmd".
*  Returns number of source images
*  (STATIC)								*
*									*/
int
Win_math::parse_rhs(char *cmd,
		    ParmList *ddls,
		    ParmList *ddlvecs,
		    ParmList *strings,
		    ParmList *constants)
{
    int i;
    int j;
    int m;
    int n;
    char *pc;
    char *tbuf;
    ParmList frames;
    ParmList pl;
    void *pv;
    Imginfo *img;

    pc = strchr(cmd, '=');
    if (!pc){
	return 0;
    }

    tbuf = strdup(++pc);	// tbuf contains the RHS
    if (!tbuf) return 0;

    *ddlvecs = get_imagevector_list("src_ddlvecs", tbuf); // frame nbrs stripped

    *ddls = allocParm("src_ddls", PL_PTR, 0);
    n = countParm(*ddlvecs);
    for (i=0; i<n; i++){
	getParmParm(*ddlvecs, &pl, i);
	m = countParm(pl);
	for (j=0; j<m; j++){
	    getPtrParm(pl, &pv, j);
	    *ddls = appendPtrParm(*ddls, pv);
	}
    }
    /*fprintf(stderr,"cmd w/o frames = \"%s\"\n", tbuf);/*CMP*/

    *strings = get_stringlist("src_strings", tbuf); // strings stripped off
    /*fprintf(stderr,"cmd w/o strings = \"%s\"\n", tbuf);/*CMP*/

    *constants = get_constlist("src_constants", tbuf); // tbuf unchanged
    /*fprintf(stderr,"cmd w/ constants = \"%s\"\n", tbuf);/*CMP*/

    n = countParm(*ddls);
    if (!n){
	msgerr_print("Math: no input image(s) specified");
	freeParms(*ddls);
	*ddls = NULL;
	return 0;
    }
    free(tbuf);
    return n;
}
Example #2
0
int
getPtrParms(ParmList p, void **array, int nelems)
{
    int rtn = 0;
    int ok = 1;
    int i;

    for (i=0; ok && i<nelems; i++){
	if ( (ok=getPtrParm(p, &array[i], i)) ) {
	    rtn++;
	}
    }
    return rtn;
}
Example #3
0
void
printParm(ParmList p)
{
    int i;
    int n;
    int type;
    int pi;
    float pf;
    void *pp;
    char *ps;
    ParmList parm;

    if (p){
	fprintf(stderr,"%s = [", p[PL_NAMEOFFSET].sval);
	n = countParm(p);
	type = typeofParm(p);
	for (i=0; i<n; i++){
	    switch (type){
	      case PL_INT:
		getIntParm(p, &pi, i);
		fprintf(stderr,"%d ", pi);
		break;
	      case PL_FLOAT:
		getFloatParm(p, &pf, i);
		fprintf(stderr,"%g ", pf);
		break;
	      case PL_STRING:
		getStrParm(p, &ps, i);
		if (ps){
		    fprintf(stderr,"\"%s\" ", ps);
		}else{
		    fprintf(stderr,"NULL ");
		}
		break;
	      case PL_PTR:
		getPtrParm(p, &pp, i);
		fprintf(stderr,"%p ", pp);
		break;
	      case PL_PARM:
		getParmParm(p, &parm, i);
		fprintf(stderr,"%p ", parm);
		break;
	    }
	}
	fprintf(stderr,"]\n");
    }
}
Example #4
0
/************************************************************************
*                                                                       *
*  Process the Image Math string "cmd".
*  (STATIC)								*
*									*/
void
Win_math::exec_string(char *cmd)
{
    int i;
    int n;
    int err = FALSE;
    char *pc;

    // The following get pointed to mallocated memory
    ParmList dst_frames = NULL;
    ParmList dst_ddls = NULL;
    ParmList src_ddls = NULL;
    ParmList src_ddl_vecs = NULL;
    ParmList src_strings = NULL;
    ParmList src_constants = NULL;
    ParmList parmtree = NULL;
    char *exec_path = NULL;

    win_print_msg("Math: Parsing...");

    /* Change New-Lines to Spaces */
    while (pc=strchr(cmd, '\n')){
	*pc = ' ';
    }

    /* Parse the left hand side */
    int nout = parse_lhs(cmd, &dst_frames);
    if (!nout){
	err = TRUE;
    }
    /*printParm(dst_frames);/*CMP*/

    /* Parse images on right hand side */
    int nin = parse_rhs(cmd, &src_ddls, &src_ddl_vecs,
			&src_strings, &src_constants);
    if (!nin){
	err = TRUE;
    }
    /*printParm(src_ddls);/*CMP*/
    /*printParm(src_strings);/*CMP*/

    /* Get the executable, compiling if necessary */
    if (!err){
	win_print_msg("Math: Compiling program...");
	if (!(exec_path = get_program(cmd))){
	    err = TRUE;
	}
    }
    /*fprintf(stderr,"exec_path=%s\n", exec_path);/*CMP*/

    /* Execute the program */
    parmtree = allocParm("parmtree", PL_PARM, 5);
    setParmParm(parmtree, src_ddls, 0);
    setParmParm(parmtree, dst_frames, 1);
    setParmParm(parmtree, src_strings, 2);
    setParmParm(parmtree, src_constants, 3);
    setParmParm(parmtree, src_ddl_vecs, 4);
    /*printParm(parmtree);/*CMP*/
    if (!err){
	win_print_msg("Math: Executing program...");
	if (!exec_program(exec_path, parmtree, &dst_ddls)){
	    err = TRUE;
	}
    }

    /* Display the results */
    /*printParm(dst_ddls);/*CMP*/
    void *vst;
    int frame;
    Gframe *gf;
    n = countParm(dst_ddls);
    for (i=0; i<n; i++){
	getPtrParm(dst_ddls, &vst, i);
	DDLSymbolTable *st = (DDLSymbolTable *)vst;
	getIntParm(dst_frames, &frame, i);
	/*fprintf(stderr,"st=0x%x, frame=%d\n", st, frame);/*CMP*/
	if (st && frame){
	    char *fname;
	    st->GetValue("filename", fname);
	    char *newname = (char *)malloc(strlen(fname) + 20);
	    sprintf(newname,"%s-mathout#%d", fname, i+1);
	    st->SetValue("filename", newname);
	    free(newname);
	    gf = Gframe::get_frame_by_number(frame);
	    int display_data = TRUE;
	    int math_result = TRUE;
	    Frame_data::load_ddl_data(gf, NULL, NULL, &display_data, TRUE,
				      (DDLSymbolTable *)st, math_result);
	}
    }

    /* Free memory */
    free(parmtree);		// Also frees params under it
    free(dst_ddls);

    win_print_msg("Math: Done.");
}
Example #5
0
int
mathexpr(ParmList inparms, ParmList *outparms)
{
    float x, y, z;		/* User variables */
    float r[100];		/* Many user variables */
    int ii, jj, kk;		/* Integer user variables */
    int n[100];			/* Many integer user variables */

    int i, j, k;		/* Pixel position in row, column, depth */
    int width, height, depth;	/* Size of all images */
    int indx;			/* Running pixel number */

    char msg[128];
    DDLSymbolTable *st;
    DDLSymbolTable *out;
    float **img;		/* Vector of pointers to input data */
    float *iout;		/* Pointer to output data */
    int nsrcs;			/* Number of input images */
    ParmList src_ddls;
    ParmList dst_ddls;

    /*fprintf(stderr,"mathexpr(0x%x, 0x%x)\n", inparms, outparms);/*CMP*/
    /*printParm(inparms);/*CMP*/
    /* Grab the input args */
    src_ddls = findParm(inparms, "src_ddls");
    if (!src_ddls){
	ib_errmsg("MATH: \"src_ddls\" not passed");
	return FALSE;
    }
    nsrcs = countParm(src_ddls);
    img = (float **)malloc(nsrcs * sizeof(float *));
    fdfhandle = (DDLSymbolTable **)malloc(nsrcs * sizeof(DDLSymbolTable *));
    if (!img || !fdfhandle){
	ib_errmsg("MATH: out of memory");
	return FALSE;
    }

    /* Check image sizes */
    width = height = depth = 0;
    for (indx=0; indx<nsrcs; indx++){
	getPtrParm(src_ddls, &st, indx);
	i = get_image_width(st);
	j = get_image_height(st);
	k = get_image_depth(st);
	if (!i || !j){
	    sprintf(msg,"MATH: image size is %dx%d\n", i, j);
	    ib_errmsg(msg);
	    return FALSE;
	}
	if ((width && i != width)
	    || (height && j != height)
	    || (depth && k != depth))
	{
	    ib_errmsg("MATH: images are different sizes\n");
	    return FALSE;
	}
	width = i;
	height = j;
	depth = k;

	/* Point the working source image pointers to the appropriate data */
	img[indx] = get_ddl_data(st);
	fdfhandle[indx] = st;
    }
    /*fprintf(stderr,"MATH: width=%d, height=%d, depth=%d\n",
	    width, height, depth);/*DBG*/

    /* Copy the first input object (for storing the output image) */
    getPtrParm(src_ddls, &st, 0);
    out = clone_ddl(st, 1);
    /*fprintf(stderr,"MATH: out width=%d, data=0x%x, *data=%g\n",
	    get_image_width(out),
	    get_ddl_data(out), *get_ddl_data(out));/*CMP*/
    /*fprintf(stderr,"indata=0x%x, *indata=%g\n", img[0], img[0][0]);/*CMP*/
    iout = get_ddl_data(out);

    /*
     * NOTE: IB_EXPRESSION will be expanded into something like
     *		img[0][indx]+img[1][indx]
     */
    interrupt_begin();
    for (indx=k=0; k<depth; k++){
	for (j=0; j<height; j++){
	    for (i=0; i<width && !interrupt(); i++, indx++){
		iout[indx] = IB_EXPRESSION;
	    }
	}
    }
    interrupt_end();
    /*fprintf(stderr,"MATH: out width=%d, data=0x%x, *data=%g\n",
	    get_image_width(out),
	    get_ddl_data(out), *get_ddl_data(out));/*CMP*/

    /* Pass back the output image */
    *outparms = allocParm("dst_ddls", PL_PTR, 1);
    setPtrParm(*outparms, out, 0);

    return TRUE;
}