示例#1
0
文件: win_math.c 项目: timburrow/ovj3
/************************************************************************
*                                                                       *
*  Frame numbers are stripped out of the command string.
*  Each image vector is repllaced with just a "#".
*  
*  (STATIC)								*
*									*/
ParmList
Win_math::get_imagevector_list(char *name, char *cmd)
{
    int i;
    int j;
    int n;
    ParmList plp;		// List of parms (each one a framevector)
    ParmList plf;		// List of frame numbers (framevector)
    ParmList pli;		// List of images (imagevector)
    Imginfo *img;

    plp = allocParm(name, PL_PARM, 0);
    while (plf=get_framevector("framevec", &cmd)){ // "cmd" pointer gets updated
	// Convert framevector to imagevector
	n = countParm(plf);	// n will be positive
	pli = allocParm("imagevec", PL_PTR, n);
	for (i=0; i<n; i++){
	    getIntParm(plf, &j, i);
	    img = Gframe::get_frame_by_number(j)->imginfo;
	    if (!img){
		msgerr_print("Math: no image in input frame #%d.", j);
		freeParms(plp);
		freeParms(plf);
		return 0;
	    }
	    setPtrParm(pli, img->st, i);
	}
	plp = appendParmParm(plp, pli);
    }
    return plp;
}
示例#2
0
int
getIntParms(ParmList p, int *array, int nelems)
{
    int rtn = 0;
    int ok = 1;
    int i;

    for (i=0; ok && i<nelems; i++){
	if ( (ok=getIntParm(p, &array[i], i)) ) {
	    rtn++;
	}
    }
    return rtn;
}
示例#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");
    }
}
示例#4
0
文件: win_math.c 项目: timburrow/ovj3
/************************************************************************
*                                                                       *
*  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.");
}