--- ray/src/gen/replmarks.c 2003/02/22 02:07:24 2.5 +++ ray/src/gen/replmarks.c 2004/01/29 22:20:31 2.11 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: replmarks.c,v 2.5 2003/02/22 02:07:24 greg Exp $"; +static const char RCSid[] = "$Id"; #endif /* * Replace markers in Radiance scene description with objects or instances. @@ -7,11 +7,14 @@ static const char RCSid[] = "$Id: replmarks.c,v 2.5 20 * Created: 17 Feb 1991 Greg Ward */ -#include #include #include #include +#include +#include "platform.h" +#include "rtio.h" +#include "rtprocess.h" #include "fvect.h" #ifdef M_PI @@ -25,6 +28,10 @@ static const char RCSid[] = "$Id: replmarks.c,v 2.5 20 #define MAXVERT 6 /* maximum number of vertices for markers */ #define MAXMARK 32 /* maximum number of markers */ +#define USE_XFORM 1 /* use !xform inline command */ +#define USE_INSTANCE 2 /* use instance primitive */ +#define USE_MESH 3 /* use mesh primitive */ + typedef struct { short beg, end; /* beginning and ending vertex */ float len2; /* length squared */ @@ -35,7 +42,7 @@ struct mrkr { double mscale; /* scale by this to get unit */ char *modin; /* input modifier indicating marker */ char *objname; /* output object file or octree */ - int doxform; /* true if xform, false if instance */ + int usetype; /* one of USE_* above */ } marker[MAXMARK]; /* array of markers */ int nmarkers = 0; /* number of markers */ @@ -43,10 +50,20 @@ int expand; /* expand commands? */ char *progname; +static void convert(char *name, FILE *fin); +static void cvcomm(char *fname, FILE *fin); +static void cvobject(char *fname, FILE *fin); +static void replace(char *fname, struct mrkr *m, char *mark, FILE *fin); +static int edgecmp(const void *e1, const void *e2); +static int buildxf(char *xf, double markscale, FILE *fin); +static int addrot(char *xf, FVECT xp, FVECT yp, FVECT zp); -main(argc, argv) -int argc; -char *argv[]; + +int +main( + int argc, + char *argv[] +) { FILE *fp; int i, j; @@ -57,11 +74,15 @@ char *argv[]; do { switch (argv[i][1]) { case 'i': - marker[nmarkers].doxform = 0; + marker[nmarkers].usetype = USE_INSTANCE; marker[nmarkers].objname = argv[++i]; break; + case 'I': + marker[nmarkers].usetype = USE_MESH; + marker[nmarkers].objname = argv[++i]; + break; case 'x': - marker[nmarkers].doxform = 1; + marker[nmarkers].usetype = USE_XFORM; marker[nmarkers].objname = argv[++i]; break; case 'e': @@ -106,18 +127,20 @@ char *argv[]; convert(argv[i], fp); fclose(fp); } - exit(0); + return 0; userr: fprintf(stderr, -"Usage: %s [-e][-s size][-m modout] {-x objfile|-i octree} modname .. [file ..]\n", +"Usage: %s [-e][-s size][-m modout] {-x objfile|-i octree|-I mesh} modname .. [file ..]\n", progname); - exit(1); + return 1; } -convert(name, fin) /* replace marks in a stream */ -char *name; -register FILE *fin; +void +convert( /* replace marks in a stream */ + char *name, + register FILE *fin +) { register int c; @@ -142,11 +165,13 @@ register FILE *fin; } -cvcomm(fname, fin) /* convert a command */ -char *fname; -FILE *fin; +void +cvcomm( /* convert a command */ + char *fname, + FILE *fin +) { - FILE *pin, *popen(); + FILE *pin; char buf[512], *fgetline(); fgetline(buf, sizeof(buf), fin); @@ -164,10 +189,13 @@ FILE *fin; } -cvobject(fname, fin) /* convert an object */ -char *fname; -FILE *fin; +void +cvobject( /* convert an object */ + char *fname, + FILE *fin +) { + extern char *fgetword(); char buf[128], typ[16], nam[128]; int i, n; register int j; @@ -208,18 +236,20 @@ readerr: } -replace(fname, m, mark, fin) /* replace marker */ -char *fname; -register struct mrkr *m; -char *mark; -FILE *fin; +void +replace( /* replace marker */ + char *fname, + register struct mrkr *m, + char *mark, + FILE *fin +) { int n; char buf[256]; buf[0] = '\0'; /* bug fix thanks to schorsch */ - if (m->doxform) { - sprintf(buf, "xform -e -n %s", mark); + if (m->usetype == USE_XFORM) { + sprintf(buf, "xform -n %s", mark); if (m->modout != NULL) sprintf(buf+strlen(buf), " -m %s", m->modout); if (buildxf(buf+strlen(buf), m->mscale, fin) < 0) @@ -233,8 +263,10 @@ FILE *fin; } else { if ((n = buildxf(buf, m->mscale, fin)) < 0) goto badxf; - printf("\n%s instance %s\n", - m->modout==NULL?"void":m->modout, mark); + printf("\n%s %s %s\n", + m->modout==NULL?"void":m->modout, + m->usetype==USE_INSTANCE?"instance":"mesh", + mark); printf("%d %s%s\n0\n0\n", n+1, m->objname, buf); } return; @@ -245,22 +277,26 @@ badxf: } -edgecmp(e1, e2) /* compare two edges, descending order */ -EDGE *e1, *e2; +int +edgecmp( /* compare two edges, descending order */ + const void *e1, + const void *e2 +) { - if (e1->len2 > e2->len2) + if (((EDGE*)e1)->len2 > ((EDGE*)e2)->len2) return(-1); - if (e1->len2 < e2->len2) + if (((EDGE*)e1)->len2 < ((EDGE*)e2)->len2) return(1); return(0); } int -buildxf(xf, markscale, fin) /* build transform for marker */ -register char *xf; -double markscale; -FILE *fin; +buildxf( /* build transform for marker */ + register char *xf, + double markscale, + FILE *fin +) { static FVECT vlist[MAXVERT]; static EDGE elist[MAXVERT]; @@ -338,9 +374,13 @@ FILE *fin; } -addrot(xf, xp, yp, zp) /* compute rotation (x,y,z) => (xp,yp,zp) */ -register char *xf; -FVECT xp, yp, zp; +int +addrot( /* compute rotation (x,y,z) => (xp,yp,zp) */ + register char *xf, + FVECT xp, + FVECT yp, + FVECT zp +) { int n; double theta;