コード例 #1
0
ファイル: win_math.c プロジェクト: timburrow/ovj3
/************************************************************************
*                                                                       *
*  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;
}
コード例 #2
0
ファイル: aipParmList.C プロジェクト: DanIverson/OpenVnmrJ
void
freeParms(ParmList p)
{
    int n;
    int i;
    int type;
    char *s;
    ParmList p2;

    if (p){
	n = countParm(p);
	if ((type=typeofParm(p)) == PL_PARM) {
	    for (i=0; i<n; i++){
		getParmParm(p, &p2, i);
		freeParms(p2);
	    }
	}else if (type == PL_STRING){
	    for (i=0; i<n; i++){
		getStrParm(p, &s, i);
		if (s){
		    free(s);
		}
	    }
	}
	free(p);
    }
}
コード例 #3
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;
}
コード例 #4
0
ファイル: aipParmList.C プロジェクト: DanIverson/OpenVnmrJ
ParmList
appendPtrParm(ParmList p, void *value)
{
    ParmList rtn = NULL;
    int n;

    if (p[PL_TYPEOFFSET].ival == PL_PTR){
	n = countParm(p);
	rtn = (ParmList)realloc(p, (n+1+PL_DATAOFFSET)*sizeof(ParmItem));
	if (rtn){
	    rtn[PL_SIZEOFFSET].ival = n+1;
	    setPtrParm(rtn, value, n);
	}
    }
    return rtn;
}
コード例 #5
0
ファイル: aipParmList.C プロジェクト: DanIverson/OpenVnmrJ
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");
    }
}
コード例 #6
0
ファイル: aipParmList.C プロジェクト: DanIverson/OpenVnmrJ
ParmList
findParm(ParmList p, const char *name)
{
    int i;
    int n;
    ParmList q;
    ParmList rtn = 0;
    if (p[PL_TYPEOFFSET].ival == PL_PARM){
	n = countParm(p);
	for (i=PL_DATAOFFSET; i<PL_DATAOFFSET+n; i++){
	    q = (ParmList)p[i].pval;
	    if (strcmp(q[PL_NAMEOFFSET].sval, name) == 0){
		rtn = q;
		break;
	    }
	}
    }
    return rtn;
}
コード例 #7
0
ファイル: win_math.c プロジェクト: timburrow/ovj3
/************************************************************************
*                                                                       *
*  Parse the LHS of math expression "cmd".
*  Returns number of frames in list.
*  (STATIC)								*
*									*/
int
Win_math::parse_lhs(char *cmd, ParmList *framelist)
{
    int nframes = 0;
    char *tbuf;
    int pid = getpid();

    tbuf = strdup(cmd);
    if (!tbuf) return 0;

    char *token = strtok(tbuf, "=");
    if (token){
	// Where to put the results
	*framelist = get_framevector("dst_frames", &token);
	nframes = countParm(*framelist);
	if (nframes < 1){
	    msgerr_print("Math: Illegal expression: no output frames.");
	    return 0;
	}
    }
    free(tbuf);
    return nframes;
}
コード例 #8
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.");
}
コード例 #9
0
ファイル: win_math.c プロジェクト: timburrow/ovj3
/************************************************************************
*                                                                       *
*  The "cmd" pointer is moved past the stuff that gets parsed.
*  The string itself is not changed.
*  Parses stuff like #1 or ##1-10 or #(1,2,4-6,10) or #(1-)
*  
*  (STATIC)								*
*									*/
ParmList
Win_math::get_framevector(char *name, char **cmd)
{
    int i;
    int j;
    int n;
    int brange;
    int erange;
    char *p;
    char *pp;
    char *ppp;
    ParmList pl;

    /* Load up the list of frames */
    pl = 0;
    if (p=strchr(*cmd, '#')){	// p --> first #
	pl = allocParm(name, PL_INT, 0);
	pp = ++p;		// Mark spot to delete frame numbers
	if (*p == '#'){
	    /* Specified a range of frames, like ##20-30 */
	    p++;
	    sscanf(p,"%u", &brange);
	    erange = brange;
	    p += strspn(p, "0123456789");
	    switch (*p){
	      case '-':
		p++;
		sscanf(p,"%u", &erange);
		p += strspn(p, "0123456789");
		break;
	    }
	    for (j=brange; j<=erange; j++){
		if (!Gframe::get_frame_by_number(j)){
		    msgerr_print("Math: frame #%d does not exist", j);
		    return NULL;
		}
		pl = appendIntParm(pl, j);
	    }
	}else if (*p == '('){
	    pl = parse_frame_spec(p, pl);
	    if (ppp=strchr(p, ')')){
		p = ppp;
	    }else{
		p += strlen(p);
	    }
	}else if (sscanf(p,"%d",&j) == 1){
	    p += strspn(p, "0123456789");
	    if (!Gframe::get_frame_by_number(j)){
		msgerr_print("Math: frame #%d does not exist", j);
		return NULL;
	    }
	    pl = appendIntParm(pl, j);
	}
	/* Consolidate string--replacing image spec with "#" */
	ppp = pp;
	while (*pp++ = *p++);
	*cmd = ppp;

	if (countParm(pl) == 0){
	    freeParms(pl);
	    pl = 0;
	}
	/*printParm(pl);/*CMP*/
    }
    return pl;
}
コード例 #10
0
ファイル: mathproto.c プロジェクト: timburrow/ovj3
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;
}