Esempio n. 1
0
static int
picheadline(		/* process picture header line */
	char	*s,
	void	*vph
)
{
	char	fmt[32];
	struct phead *ph = vph;

	if (formatval(fmt, s)) {
		ph->badfmt = strcmp(fmt, COLRFMT);
		return(0);
	}
	if (isprims(s)) {
		ph->altprims++;		/* don't want to deal with this */
		return(0);
	}
	if (isexpos(s)) {
		ph->expos *= exposval(s);
		return(0);
	}
	if (isview(s)) {
		ph->gotview += sscanview(&ph->vw, s);
		return(0);
	}
	return(0);
}
Esempio n. 2
0
static int
headline(				/* process header line */
	char	*s,
	void	*p
)
{
	static RGBPRIMS	inprimS;
	char	fmt[32];

	if (formatval(fmt, s)) {	/* check if format string */
		if (!strcmp(fmt,COLRFMT)) lumf = rgblum;
		else if (!strcmp(fmt,CIEFMT)) lumf = cielum;
		else lumf = NULL;
		return(0);		/* don't echo */
	}
	if (isprims(s)) {		/* get input primaries */
		primsval(inprimS, s);
		inprims= inprimS;
		return(0);		/* don't echo */
	}
	if (isexpos(s)) {		/* picture exposure */
		inpexp *= exposval(s);
		return(0);		/* don't echo */
	}
	if (isaspect(s))		/* pixel aspect ratio */
		pixaspect *= aspectval(s);
	if (isview(s))			/* image view */
		gotview += sscanview(&ourview, s);
	return(fputs(s, stdout));
}
Esempio n. 3
0
static int
gethview(				/* get view from header */
	char  *s,
	void  *v
)
{
	if (isview(s) && sscanview(((struct myview*)v)->hv, s) > 0)
		((struct myview*)v)->ok++;
	return(0);
}
Esempio n. 4
0
File: rv2.c Progetto: NREL/Radiance
void
loadview(				/* load view from rad file */
	char  *s
)
{
	char  buf[512];
	char  *fname;
	FILE  *fp;
	VIEW  nv;

	strcpy(buf, "rad -n -s -V -v ");
	if (sscanf(s, "%s", buf+strlen(buf)) == 1)
		s = sskip(s);
	else
		strcat(buf, "1");
	if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) {
		error(COMMAND, "no previous rad file");
		return;
	}
	if ((fname = getpath(rifname, "", R_OK)) == NULL) {
		sprintf(errmsg, "cannot access \"%s\"", rifname);
		error(COMMAND, errmsg);
		return;
	}
	sprintf(buf+strlen(buf), " %s", fname);
	if ((fp = popen(buf, "r")) == NULL) {
		error(COMMAND, "cannot run rad");
		return;
	}
	buf[0] = '\0';
	fgets(buf, sizeof(buf), fp);
	pclose(fp);
	nv = stdview;
	if (!sscanview(&nv, buf)) {
		error(COMMAND, "rad error -- no such view?");
		return;
	}
	newview(&nv);
}
Esempio n. 5
0
static int
headline(			/* check header line & echo if requested */
	char	*s,
	void	*p
)
{
	char	fmt[32];
	double	d;
	COLOR	ctmp;

	if (isheadid(s))			/* header id */
		return(0);	/* don't echo */
	if (formatval(fmt, s)) {		/* check format */
		if (globmatch(ourfmt, fmt)) {
			wrongformat = 0;
			strcpy(ourfmt, fmt);
		} else
			wrongformat = globmatch(PICFMT, fmt) ? 1 : -1;
		return(0);	/* don't echo */
	}
	if (isexpos(s)) {			/* exposure */
		d = exposval(s);
		scalecolor(input[nfiles].expos, d);
	} else if (iscolcor(s)) {		/* color correction */
		colcorval(ctmp, s);
		multcolor(input[nfiles].expos, ctmp);
	} else if (isaspect(s))
		input[nfiles].pa *= aspectval(s);
	else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0)
		gotview++;

	if (echoheader) {			/* echo line */
		putchar('\t');
		return(fputs(s, stdout));
	}
	return(0);
}
Esempio n. 6
0
File: rv2.c Progetto: NREL/Radiance
void
getview(				/* get/show/save view parameters */
	char  *s
)
{
	FILE  *fp;
	char  buf[128];
	char  *fname;
	int  change = 0;
	VIEW  nv = ourview;

	while (isspace(*s))
		s++;
	if (*s == '-') {			/* command line parameters */
		if (sscanview(&nv, s))
			newview(&nv);
		else
			error(COMMAND, "bad view option(s)");
		return;
	}
	if (nextword(buf, sizeof(buf), s) != NULL) {	/* write to a file */
		if ((fname = getpath(buf, NULL, 0)) == NULL ||
				(fp = fopen(fname, "a")) == NULL) {
			sprintf(errmsg, "cannot open \"%s\"", buf);
			error(COMMAND, errmsg);
			return;
		}
		fputs(progname, fp);
		fprintview(&ourview, fp);
		fputs(sskip(s), fp);
		putc('\n', fp);
		fclose(fp);
		return;
	}
	sprintf(buf, "view type (%c): ", ourview.type);
	(*dev->comout)(buf);
	(*dev->comin)(buf, NULL);
	if (buf[0] == CTRL('C')) return;
	if (buf[0] && buf[0] != ourview.type) {
		nv.type = buf[0];
		change++;
	}
	sprintf(buf, "view point (%.6g %.6g %.6g): ",
			ourview.vp[0], ourview.vp[1], ourview.vp[2]);
	(*dev->comout)(buf);
	(*dev->comin)(buf, NULL);
	if (buf[0] == CTRL('C')) return;
	if (sscanvec(buf, nv.vp))
		change++;
	sprintf(buf, "view direction (%.6g %.6g %.6g): ",
			ourview.vdir[0]*ourview.vdist,
			ourview.vdir[1]*ourview.vdist,
			ourview.vdir[2]*ourview.vdist);
	(*dev->comout)(buf);
	(*dev->comin)(buf, NULL);
	if (buf[0] == CTRL('C')) return;
	if (sscanvec(buf, nv.vdir)) {
		nv.vdist = 1.;
		change++;
	}
	sprintf(buf, "view up (%.6g %.6g %.6g): ",
			ourview.vup[0], ourview.vup[1], ourview.vup[2]);
	(*dev->comout)(buf);
	(*dev->comin)(buf, NULL);
	if (buf[0] == CTRL('C')) return;
	if (sscanvec(buf, nv.vup))
		change++;
	sprintf(buf, "view horiz and vert size (%.6g %.6g): ",
			ourview.horiz, ourview.vert);
	(*dev->comout)(buf);
	(*dev->comin)(buf, NULL);
	if (buf[0] == CTRL('C')) return;
	if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
		change++;
	sprintf(buf, "fore and aft clipping plane (%.6g %.6g): ",
			ourview.vfore, ourview.vaft);
	(*dev->comout)(buf);
	(*dev->comin)(buf, NULL);
	if (buf[0] == CTRL('C')) return;
	if (sscanf(buf, "%lf %lf", &nv.vfore, &nv.vaft) == 2)
		change++;
	sprintf(buf, "view shift and lift (%.6g %.6g): ",
			ourview.hoff, ourview.voff);
	(*dev->comout)(buf);
	(*dev->comin)(buf, NULL);
	if (buf[0] == CTRL('C')) return;
	if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
		change++;
	if (change)
		newview(&nv);
}
Esempio n. 7
0
static void
runrad(				/* run rad and load variables */
	int	ac,
	char	**av
)
{
	static char	optfile[] = TEMPLATE;
	int	nvn = 0, nvv = 0;
	FILE	*fp;
	register char	*cp;
	char	radcomm[256], buf[128], nam[32];
					/* set rad commmand */
	strcpy(radcomm, "rad -w -v 0        ");	/* look out below! */
	cp = radcomm + 19;
	if (silent) {
		strcpy(cp, "-s ");
		cp += 3;
	}
	while (ac--) {
		strcpy(cp, *av++);
		while (*cp) cp++;
		*cp++ = ' ';
	}
	strcpy(cp, "OPTFILE=");		/* create temporary options file */
	strcpy(cp+8, mktemp(optfile));
	if (system(radcomm))		/* update octree */
		error(USER, "error executing rad command");
					/* replace "-v 0" with "-n -e -s -V" */
	strcpy(radcomm+7, "-n -e -s -V");
	radcomm[18] = ' ';
	if ((fp = popen(radcomm, "r")) == NULL)
		error(SYSTEM, "cannot start rad command");
	buf[0] = '\0';			/* read variables alphabetically */
						/* get exposure */
	if ((cp = scan4var(buf, sizeof(buf), "EXPOSURE", fp)) != NULL) {
		expval = atof(cp);
		if ((*cp == '-') | (*cp == '+'))
			expval = pow(2., expval);
		expval *= 0.5;		/* compensate for local shading */
	}
						/* look for eye separation */
	if ((cp = scan4var(buf, sizeof(buf), "EYESEP", fp)) != NULL)
		eyedist = atof(cp);
						/* look for materials */
	while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) {
		nscenef += wordstring(scene+nscenef, cp);
		buf[0] = '\0';
	}
						/* look for octree */
	if ((cp = scan4var(buf, sizeof(buf), "OCTREE", fp)) != NULL)
		octree = savqstr(cp);
						/* look for scene files */
	while ((cp = scan4var(buf, sizeof(buf), "scene", fp)) != NULL) {
		nscenef += wordstring(scene+nscenef, cp);
		buf[0] = '\0';
	}
						/* load view names */
	while ((cp = scan4var(buf, sizeof(buf), "view", fp)) != NULL) {
		if (nvn >= MAXVIEW)
			error(INTERNAL, "too many views in rad file");
		vwl[nvn++].nam = *cp == '-' ? (char *)NULL :
				savqstr(atos(nam, sizeof(nam), cp));
		buf[0] = '\0';
	}
						/* load actual views */
	do
		if (isview(buf)) {
			vwl[nvv].v = (VIEW *)bmalloc(sizeof(VIEW));
			*(vwl[nvv].v) = stdview;
			sscanview(vwl[nvv].v, buf);
			if ((cp = setview(vwl[nvv++].v)) != NULL) {
				fprintf(stderr, "%s: bad view %d - %s\n",
						progname, nvv, cp);
				quit(1);
			}
		}
	while (fgets(buf, sizeof(buf), fp) != NULL);
	if (nvv != nvn)
		error(INTERNAL, "view miscount in runrad");
	pclose(fp);
						/* open options file */
	if ((fp = fopen(optfile, "r")) == NULL)
		error(SYSTEM, "cannot open options file");
						/* get relevant options */
	while (fgets(buf, sizeof(buf), fp) != NULL)
		if (!strncmp(buf, "-av ", 4))
			setcolor(ambval, atof(buf+4),
					atof(sskip2(buf+4,1)),
					atof(sskip2(buf+4,2)));
		else if (backvis && !strncmp(buf, "-bv", 3) &&
				(!buf[3] || strchr("0-FfNn \n",buf[3])!=NULL))
			backvis = 0;
	fclose(fp);
	unlink(optfile);			/* delete options file */
}
Esempio n. 8
0
int
main(
	int	argc,
	char	*argv[]
)
{
	char	*viewsel = NULL;
	long	vwintvl = 0;
	int	i;

	progname = argv[0];
	for (i = 1; i < argc && argv[i][0] == '-'; i++)
		switch (argv[i][1]) {
		case 'v':
			viewsel = argv[++i];
			break;
		case 'w':
			nowarn = !nowarn;
			break;
		case 's':
			silent = !silent;
			break;
		case 'S':
			stereo = !stereo;
			break;
		case 'c':
			vwintvl = atoi(argv[++i]);
			break;
		case 'b':
			backvis = !backvis;
			break;
		default:
			goto userr;
		}
	if (i >= argc)
		goto userr;
#ifdef NOSTEREO
	if (stereo)
		error(INTERNAL, "stereo not supported in this version");
#endif
					/* run rad and get views */
	runrad(argc-i, argv+i);
					/* check view */
	if (viewsel != NULL) {
		if (viewsel[0] == '-') {
			char	*ve = viewsel;
			if (!sscanview(&thisview, viewsel) ||
					(ve = setview(&thisview)) != NULL) {
				fprintf(stderr, "%s: bad view: %s\n",
						progname, ve);
				quit(1);
			}
			currentview = -1;
		} else if ((currentview = findvw(viewsel)) < 0) {
			fprintf(stderr, "%s: no such view: %s\n",
						progname, viewsel);
			quit(1);
		}
	}
					/* open GL */
	dev_open(radfile = argv[i]);
					/* load octree or scene files */
	if (octree != NULL) {
		displist = rgl_octlist(octree, NULL, NULL, NULL);
		startrtrace(octree);
	} else
		displist = rgl_filelist(nscenef, scene, NULL);
					/* set initial view */
	dev_view(currentview < 0 ? &thisview : vwl[currentview].v);
					/* input/render loop */
	while (dev_input(vwintvl))
		;
					/* all done */
	quit(0);
userr:
	fprintf(stderr,
		"Usage: %s [-w][-s][-b][-S][-v view] rfile [VAR=value]..\n",
			argv[0]);
	quit(1);
	return 1; /* pro forma return */
}
Esempio n. 9
0
static int
usr_input(void)			/* get user input and process it */
{
	VIEW	vparams;
	char	cmd[256];
	register char	*args;
	register int	i;

	if (fgets(cmd, sizeof(cmd), sstdin) == NULL) {
		fclose(sstdin);
		sstdin = NULL;
		return(-1);
	}
	if (*cmd == '\n')
		return(DC_RESUME);
	for (args = cmd; *args && !isspace(*args); args++)
		;
	while (isspace(*args))
		*args++ = '\0';
	if (*args && args[i=strlen(args)-1] == '\n')
		args[i] = '\0';
	for (i = 0; i < DC_NCMDS; i++)
		if (!strcmp(cmd, cmdlist[i]))
			break;
	if (i >= DC_NCMDS) {
		dev_auxcom(cmd, args);
		return(-1);
	}
	switch (i) {
	case DC_SETVIEW:		/* set the view */
		vparams = odev.v;
		if (!sscanview(&vparams, args))
			error(COMMAND, "missing view options");
		else
			new_view(&vparams);
		break;
	case DC_GETVIEW:		/* print the current view */
		printview();
		break;
	case DC_LASTVIEW:		/* restore previous view */
		new_view(NULL);
		break;
	case DC_FOCUS:			/* set focus frame */
		set_focus(args);
		break;
	case DC_PAUSE:			/* pause the current calculation */
	case DC_RESUME:			/* resume the calculation */
		/* handled in main() */
		break;
	case DC_REDRAW:			/* redraw from server */
		imm_mode = beam_sync(1) > 0;
		dev_clear();
		break;
	case DC_KILL:			/* kill rtrace process(es) */
		serv_request(DR_KILL, 0, NULL);
		break;
	case DC_CLOBBER:		/* clobber holodeck */
		serv_request(DR_CLOBBER, 0, NULL);
		break;
	case DC_RESTART:		/* restart rtrace */
		serv_request(DR_RESTART, 0, NULL);
		break;
	case DC_QUIT:			/* quit request */
		serv_request(DR_SHUTDOWN, 0, NULL);
		break;
	default:
		error(CONSISTENCY, "bad command id in usr_input");
	}
	return(i);
}