# The following is a shar archive. Extract using 'sh filename' not 'csh'. # The rest of this file will extract: # dist/poly2obj.README include/topology.h src/cmds/make.poly2obj src/cmds/mkdefs.IRIS_3000 src/cmds/mkdefs.I_3000_DEBUG src/cmds/mkdefs.IRIS_4D src/cmds/mkdefs.I_4D_DEBUG src/cmds/mkdefs.SUN src/cmds/mkdefs.SUN_DEBUG src/cmds/poly2obj.c src/obj_lib/alloc_ obj.c src/obj_lib/app_obj.c src/obj_lib/rd_poly.c src/obj_lib/wt_obj.c man/man1/poly2obj.sl man/man1/Make.poly2obj man/man3/alloc_obj.sl man/man3/app_obj.sl man/man3/rd_poly.sl man/man3/wt_obj.sl man/man3/Make.poly2obj man/man5/objects.sl man/man5/poly.ma n man/man5/Make.poly2obj echo extracting dist/poly2obj.README echo mkdir ./dist mkdir ./dist sed 's/^X//' > dist/poly2obj.README << '!EOR!' X X X X poly2obj - a program written in C to convert objects of the form X used by Andrew Hume's catalogue of polyhedra to the ASCII X object description form used by Wavefront Technologies' X CAD, animation and rendering package. X X Author: Stewart Dickson X celia!tpg!dickson@tis.llnl.gov X !EOR! echo extracting include/topology.h echo mkdir ./include mkdir ./include sed 's/^X//' > include/topology.h << '!EOR!' X/* file: topology.h X X description: Data structure for linking topological aspects of a 3-D X graphical object. Objects are described via the ASCII X object description language as being composed of vertices X and topological elements of several types with material X attributes. This system provides sufficient information X for determining the complete geometry, topology and material X properties of the object. This data structure provides the X framework for a complete linkage of these object attributes. X X Additionally is supported the recursive definition of X 'graphical meta-elements' which enable the efficient X specification of object hierarchical morphology (detail). X X author: Stewart Dickson X*/ X X/* define a 32-bit Magic Number for portability */ X#define SPD_MAGIC 0xff5500aa X X/* define values of object-to-polygon mapping directives */ X#define MAP 1 X#define NOMAP 0 X X/* define several types of parametric surfaces */ X#define BSPLINE 0 X#define BEZIER 1 X#define CARDINAL 2 X Xstruct sizes { X char notraces; X char noshados; X char nocalls; X char nolibs; X char nomaps; X char valence; X char nosgrps; X short nolverts; X short nofverts; X short nopverts; X short nogroups; X int nolines; X int nofaces; X int nopoints; X int noverts; X int notverts; X int noedges; X int nomtls; X int nocircs; X int nosphrs; X int noptchs; X int nogverts; X int nogfaces; X int nogpoints; X int noglines; X int nogsphrs; X int nogcircs; X int nogptchs; X int nomdefs; X int nomrefs; X int nomops; X X char objname[128]; X }; X Xstruct topology { X X struct sizes size; X X struct sizes alloc; X X struct bounding_box { X float minx; X float maxx; X float miny; X float maxy; X float minz; X float maxz; X } b_box; X X struct tracobj { X char objname[128]; X } **trace_obj; X X struct shadobj { X char objname[128]; X } **shad_obj; X X struct caldfile { X char filnam[128]; X } **call; X X struct library { X char libnam[128]; X } **lib; X X struct material { X char mtlnam[128]; X int illum; X struct RGB { X float red, green, blue; X } Ka, Kd, Ks, Ni, Tf; X float Ns, dissolve; X float mass_dens, surf_elast, surf_stiff; X float damping, visc_drag, visc_damp; X } **mtl; X X struct mapping { X char mapnam[128]; X } **map; X X struct objgrps { X int noverts; X int nopoints; X int nolines; X int nofaces; X int nocircs; X int nosphrs; X int noptchs; X X char grpnam[128]; X X int *vertno; X int *pointno; X int *lineno; X int *faceno; X int *circno; X int *sphrno; X int *ptchno; X } **group; X X struct vertex { X char facec; X char edgec; X short group; X int mtl; X float x; X float y; X float z; X struct Vector_struct { X float x; X float y; X float z; X } normal; X int *faceno; X int *edgeno; X } **vertex; X X struct faces { X char bevel; X char mapflg; X short map; X short smooth; X short group; X short vertc; X short edgec; X int mtl; X int *vertno; X int *tvertno; X int *edgeno; X struct Vector_struct normal; X } **face; X X struct textur { X float u; X float v; X float w; X } **texver; X X struct lines { X short vertc; X short group; X int mtl; X int *vertno; X } **line; X X struct edges { X int vertno[2]; X int faceno[2]; X float length; X float theta; X } **edge; X X struct points { X short vertc; X short group; X int *vertno; X } **point; X X struct circles { X short group; X short res; X int vertno; X float beg_ang; X float end_ang; X float rad; X struct Vector_struct x, y; X } **circl; X X struct spheres { X short map; X short smooth; X short group; X short res; X int vertno; X int mtl; X float rad; X } **spher; X X struct bicubes { X char type; X char u_res; X char v_res; X short map; X short smooth; X short group; X int mtl; X int vertno[4][4]; X int tvertno[4][4]; X } **bicub; X X struct topology **metadef; X X struct meta_reference { X float orient[4][4][4]; X struct topology *meta; X } **metaref; X X struct meta_oper { X char opname[128]; X struct topology *(*function)(); X struct param_iface *objarg; X } **metaop; X X }; !EOR! echo extracting src/cmds/make.poly2obj echo mkdir ./src mkdir ./src echo mkdir ./src/cmds mkdir ./src/cmds sed 's/^X//' > src/cmds/make.poly2obj << '!EOR!' X# file: makefile X# X# contents: compilation instructions for the Stewart Dickson 3-D Graphical X# modelling package. X# X# author: Stewart Dickson X# X X X# ******* Build for various machines ******* X#include mkdefs.IRIS_3000 X#include mkdefs.I_3000_DEBUG X#include mkdefs.IRIS_4D X#include mkdefs.I_4D_DEBUG X#include mkdefs.SUN Xinclude mkdefs.SUN_DEBUG X XWAVE_INCL= $(WF_DIR)/include X XWAVE_LIB= $(WF_DIR)/lib X XSRC_DIR= $(SPD_DIR)/src X XINCL_DIR= $(SPD_DIR)/include X X#BIN= $(SPD_DIR)/bin X XBIN= /usr/local/tools X XCMD_DIR= $(SRC_DIR)/cmds X XOBJ_SRC= $(SRC_DIR)/obj_lib X XSCMP_SRC= $(SRC_DIR)/scmp_lib X XIMF_SRC= $(SRC_DIR)/imf_lib X XUTIL_SRC= $(SRC_DIR)/util_lib X X# X# commands X# XALL: poly2obj X Xclean: X rm -f *.o $(OBJ_SRC)/*.o $(SCMP_SRC)/*.o $(IMF_SRC)/*.o \ X $(UTIL_SRC)/*.o X X# X Xpoly2obj: $(BIN)/poly2obj X$(BIN)/poly2obj: poly2obj.o alloc_obj.o app_obj.o rd_poly.o wt_obj.o \ X $(INCL_DIR)/topology.h X $(LD) poly2obj.o $(OBJ_SRC)/alloc_obj.o $(OBJ_SRC)/app_obj.o \ X $(OBJ_SRC)/rd_poly.o $(OBJ_SRC)/wt_obj.o \ X -o $(BIN)/poly2obj $(LDFLAGS); chmod 755 $@ X Xpoly2obj.o: poly2obj.c $(INCL_DIR)/topology.h X $(CC) $(CFLAGS) -I$(INCL_DIR) poly2obj.c X X# X# graphical utility functions X# X Xalloc_obj.o: $(OBJ_SRC)/alloc_obj.o X$(OBJ_SRC)/alloc_obj.o: $(OBJ_SRC)/alloc_obj.c $(INCL_DIR)/topology.h X $(CC) $(CFLAGS) -I$(INCL_DIR) $(OBJ_SRC)/alloc_obj.c; \ X mv alloc_obj.o $(OBJ_SRC) X Xapp_obj.o: $(OBJ_SRC)/app_obj.o X$(OBJ_SRC)/app_obj.o: $(OBJ_SRC)/app_obj.c $(INCL_DIR)/topology.h X $(CC) $(CFLAGS) -I$(INCL_DIR) $(OBJ_SRC)/app_obj.c ; \ X mv app_obj.o $(OBJ_SRC) X Xrd_poly.o: $(OBJ_SRC)/rd_poly.o X$(OBJ_SRC)/rd_poly.o: $(OBJ_SRC)/rd_poly.c $(INCL_DIR)/topology.h X $(CC) $(CFLAGS) -I$(INCL_DIR) $(OBJ_SRC)/rd_poly.c ; \ X mv rd_poly.o $(OBJ_SRC) X X Xwt_obj.o: $(OBJ_SRC)/wt_obj.o X$(OBJ_SRC)/wt_obj.o: $(OBJ_SRC)/wt_obj.c $(INCL_DIR)/topology.h X $(CC) $(CFLAGS) -I$(INCL_DIR) $(OBJ_SRC)/wt_obj.c ; \ X mv wt_obj.o $(OBJ_SRC) X !EOR! echo extracting src/cmds/mkdefs.IRIS_3000 echo mkdir ./src mkdir ./src echo mkdir ./src/cmds mkdir ./src/cmds sed 's/^X//' > src/cmds/mkdefs.IRIS_3000 << '!EOR!' X# ****** Build for IRIS 3000 ****** X XCFLAGS= -O -DIRIS -DWAVE X# non-Wavefront make X# CFLAGS= -O -DIRIS X XLDFLAGS= -Zf -Zg -lbsd -lm X !EOR! echo extracting src/cmds/mkdefs.I_3000_DEBUG echo mkdir ./src mkdir ./src echo mkdir ./src/cmds mkdir ./src/cmds sed 's/^X//' > src/cmds/mkdefs.I_3000_DEBUG << '!EOR!' X# ****** Build for IRIS 3000, debug using dbx ****** X XCC= cc -c X XCFLAGS= -g -DIRIS -DWAVE X# non-Wavefront make X# CFLAGS= -g -DIRIS X XLD= cc --x X XLDFLAGS= -Zf -Zg -lbsd -lm X !EOR! echo extracting src/cmds/mkdefs.IRIS_4D echo mkdir ./src mkdir ./src echo mkdir ./src/cmds mkdir ./src/cmds sed 's/^X//' > src/cmds/mkdefs.IRIS_4D << '!EOR!' X# ****** Build for IRIS 4D ****** X XCFLAGS= -G 0 -Olimit 850 -DIRIS -DWAVE X# non-Wavefront make X# CFLAGS= -G 0 -Olimit 850 -DIRIS X XLDFLAGS= -G 0 -lbsd -lm X !EOR! echo extracting src/cmds/mkdefs.I_4D_DEBUG echo mkdir ./src mkdir ./src echo mkdir ./src/cmds mkdir ./src/cmds sed 's/^X//' > src/cmds/mkdefs.I_4D_DEBUG << '!EOR!' X# ****** Build for IRIS 4D, debug using dbx ****** XCC= cc -c -g2 X XCFLAGS= -G 0 -DWAVE X# non-Wavefront make X# CFLAGS= -G 0 X XLD= cc -g2 X XLDFLAGS= -G 0 -lbsd -lm X !EOR! echo extracting src/cmds/mkdefs.SUN echo mkdir ./src mkdir ./src echo mkdir ./src/cmds mkdir ./src/cmds sed 's/^X//' > src/cmds/mkdefs.SUN << '!EOR!' X# ****** Build for Sun ******* X XCC= cc -c X XCFLAGS= -O -DSUN -DWAVE X# non-Wavefront make X# CFLAGS= -O -DSUN X XLD= cc X XLDFLAGS= -s -ffpa -lm X X !EOR! echo extracting src/cmds/mkdefs.SUN_DEBUG echo mkdir ./src mkdir ./src echo mkdir ./src/cmds mkdir ./src/cmds sed 's/^X//' > src/cmds/mkdefs.SUN_DEBUG << '!EOR!' X# ****** Build for Sun, Debug using DBX ****** XCC= cc -c X X# *** debug make **** X#CFLAGS= -v -g -DSUN -DWAVE -ffpa X XCFLAGS= -g -DSUN -DWAVE -ffpa X# non-Wavefront make X# CFLAGS= -g -DSUN -ffpa X X# *** debug make **** X#LD= cc -v -g X XLD= cc -g X XLDFLAGS= -lg -lm X !EOR! echo extracting src/cmds/poly2obj.c echo mkdir ./src mkdir ./src echo mkdir ./src/cmds mkdir ./src/cmds sed 's/^X//' > src/cmds/poly2obj.c << '!EOR!' X/* file: poly2obj.c X X description: C source code for a program to convert files from X Andrew Hume's catalogue of 142 regular polyhedra to X the Wavefront Technologies ASCII object description X format. X X author: Stewart Dickson X*/ X X#include X#include X Xint verbflg = 0; X Xmain(argc,argv) Xint argc; Xchar **argv; X{ XFILE *in_file; Xstruct topology *polyhedron = NULL, *rd_poly(); Xint argindx = 1; Xchar file_name[128]; X Xfile_name[0] = '\0'; X Xwhile(argindx < argc) { /* parse command line arguments if any */ X if(!strncmp(argv[argindx],"-h",2)) { /* help */ X fprintf(stderr,"usage: poly2obj [options] [file_name]\n"); X fprintf(stderr,"options:\n"); X fprintf(stderr,"\t-h[elp] - this message\n"); X fprintf(stderr,"\t-v [level] - verbose\n"); X exit(0); X } X else if(!strcmp(argv[argindx],"-v")) { /* verbose */ X if(++argindx < argc) { X if((verbflg = atoi(argv[argindx])) < 1) { /* non-numeric */ X verbflg = 1; X } X else { X argindx++; X } X } X } X else if(argindx < argc - 1) { /* option not found (not file name) */ X fprintf(stderr,"poly2obj: option '%s' not found\n",argv[argindx]); X fprintf(stderr,"usage: poly2obj [options] [file_name]\n"); X fprintf(stderr,"options:\n"); X fprintf(stderr,"\t-h[elp] - this message\n"); X fprintf(stderr,"\t-v [level] - verbose\n"); X exit(-1); X } X else { /* we have not matched an option -- argindx == argc - 1 X - must be a file name */ X strcpy(file_name, argv[argc - 1]); X argindx++; X } X } X Xif(strlen(file_name) > 0) { /* if a file name has been read from command line */ X if((in_file = fopen(file_name,"r")) == NULL) { X fprintf(stderr,"poly2obj: cannot open file '%s'\n",file_name); X exit(-1); X } X } Xelse { /* take input from stdin */ X in_file = stdin; X } X Xpolyhedron = rd_poly(polyhedron,in_file); X Xwt_obj(stdout,polyhedron); X} !EOR! echo extracting src/obj_lib/alloc_obj.c echo mkdir ./src mkdir ./src echo mkdir ./src/obj_lib mkdir ./src/obj_lib sed 's/^X//' > src/obj_lib/alloc_obj.c << '!EOR!' X/* file alloc_obj.c X X description: C modules for allocating storage for geometrical/topological X object description structures. X X contents: alloc_obj() X def_parms() X copy_alc() X copy_siz() X realc_obj() X free_obj() X X author: Stewart Dickson X*/ X X#include X#include X X/* function: alloc_obj X X description: allocates storage for a geometrical object description X structure. X X parameters: alcalc - pointer to structure containing allocation size X parameters. X X returns: alcobj - pointer to structure allocated for object description. X X author: Stewart Dickson X*/ X Xunsigned cumsize; X Xstruct topology *alloc_obj(alcalc) Xstruct sizes *alcalc; X{ Xextern int verbflg; Xstruct sizes *def_parms(); Xstruct topology *alcobj,*alloc_hdr(),*alloc_verts(),*alloc_tverts(); Xstruct topology *alloc_faces(),*alloc_lines(),*alloc_edges(),*alloc_circs(); Xstruct topology *alloc_points(),*alloc_sphrs(),*alloc_ptchs(),*alloc_mdefs(); Xstruct topology *alloc_mrefs(),*alloc_moprs(); Xunsigned objsize; Xchar *malloc(); X X/* struct sizes should have requested size parameters for object */ X Xif(alcalc==NULL) { /* if not, check for environment variables set */ X alcalc=def_parms(alcalc); X } X X/* allocate object structure and header info */ Xalcobj = alloc_hdr(alcalc); X X/* allocate vertex structures */ Xalcobj = alloc_verts(alcobj,alcalc); X X/* allocate face structures */ Xalcobj = alloc_faces(alcobj,alcalc); X X/* allocate texture vertex structures */ Xalcobj = alloc_tverts(alcobj,alcalc); X X/* allocate line structures */ Xalcobj = alloc_lines(alcobj,alcalc); X X/* allocate edge structures */ Xalcobj = alloc_edges(alcobj,alcalc); X X/* allocate point structures */ Xalcobj = alloc_points(alcobj,alcalc); X X/* allocate circle structures */ Xalcobj = alloc_circs(alcobj,alcalc); X X/* allocate sphere structures */ Xalcobj = alloc_sphrs(alcobj,alcalc); X X/* allocate bicubic patch structures */ Xalcobj = alloc_ptchs(alcobj,alcalc); X X/* allocate object meta-element definitions */ Xalcobj = alloc_mdefs(alcobj,alcalc); X X/* allocate object meta-element references */ Xalcobj = alloc_mrefs(alcobj,alcalc); X X/* allocate object meta-element operations */ Xalcobj = alloc_moprs(alcobj,alcalc); X Xif(verbflg>0) { X fprintf(stderr,"alloc_obj: object size %u : done\n",cumsize); X } X Xreturn(alcobj); X} X X X X X X X/* function: alloc_hdr X X description: allocates storage for an object and its header information. X*/ X X Xstruct topology *alloc_hdr(hdralc) Xstruct sizes *hdralc; X{ Xstruct topology *hdrobj; Xunsigned objsize; Xint tracindx,shadindx,calindx,mtlindx,mapindx,libindx,gindx; X Xif(hdralc == NULL) { X fprintf(stderr, X "alloc_hdr: ERROR - NULL allocation parameter struct received\n"); X exit(-1); X } X X/* make sure we are allocating at least one of everything */ Xif(hdralc->nomtls<=0) hdralc->nomtls=1; Xif(hdralc->nomaps<=0) hdralc->nomaps=1; Xif(hdralc->nocalls<=0) hdralc->nocalls=1; Xif(hdralc->notraces<=0) hdralc->notraces=1; Xif(hdralc->noshados<=0) hdralc->noshados=1; Xif(hdralc->nolibs<=0) hdralc->nolibs=1; Xif(hdralc->nogroups<=0) hdralc->nogroups=1; Xif(hdralc->nogverts<=0) hdralc->nogverts=1; Xif(hdralc->noglines<=0) hdralc->noglines=1; Xif(hdralc->nogfaces<=0) hdralc->nogfaces=1; Xif(hdralc->nogcircs<=0) hdralc->nogcircs=1; Xif(hdralc->nogsphrs<=0) hdralc->nogsphrs=1; Xif(hdralc->nogptchs<=0) hdralc->nogptchs=1; Xif(hdralc->nogpoints<=0) hdralc->nogpoints=1; X X/* allocate space for object structure */ Xif((hdrobj=(struct topology *)malloc(sizeof(struct topology)))==NULL) { X fprintf(stderr,"alloc_hdr: cannot allocate object structure size %d\n", X sizeof(struct topology)); X exit(-1); X } X Xcumsize=sizeof(struct topology); X X/* set object name */ Xstrcpy(hdrobj->size.objname,hdralc->objname); Xstrcpy(hdrobj->alloc.objname,hdralc->objname); X Xif(verbflg>0) { X fprintf(stderr,"alloc_hdr: object '%s'\n",hdrobj->size.objname); X } Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: hdrobj = 0x%x, size %d\n", X hdrobj, X sizeof(struct topology)); X } X X/* allocate space for 'trace_obj' structure pointers */ Xobjsize=hdralc->notraces*sizeof(struct tracobj *); Xif((hdrobj->trace_obj=(struct tracobj **)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->trace_obj' size %u\n", X objsize); X exit(-1); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: %d traced objects\n",hdralc->notraces); X fprintf(stderr,"alloc_hdr: hdrobj->trace_obj = 0x%x, size = %d\n", X hdrobj->trace_obj,objsize); X } X/* allocate space for 'trace_obj' structures */ Xobjsize=sizeof(struct tracobj); Xfor(tracindx=0;tracindxnotraces;tracindx++) { X if((hdrobj->trace_obj[tracindx] = X (struct tracobj *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->trace_obj[%d]'", X tracindx); X fprintf(stderr, X " size %u\n", objsize); X exit(-1); X } X if(verbflg>20) { X fprintf(stderr, X "alloc_hdr: hdrobj->trace_obj[%d] = 0x%x, size = %d\n", X tracindx,hdrobj->trace_obj[tracindx],objsize); X } X cumsize+=objsize; X } X/* initialize 'trace_obj' string to a default */ Xstrcpy(hdrobj->trace_obj[0]->objname,"# no objects traced"); Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: %s\n",hdrobj->trace_obj[0]->objname); X } X X/* allocate space for 'shad_obj' structure pointers */ Xobjsize=hdralc->noshados*sizeof(struct shadobj *); Xif((hdrobj->shad_obj=(struct shadobj **)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->shad_obj' size %u\n", X objsize); X exit(-1); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: %d shadowed objects\n",hdralc->noshados); X fprintf(stderr,"alloc_hdr: hdrobj->shad_obj = 0x%x, size = %d\n", X hdrobj->shad_obj,objsize); X } X/* allocate space for 'shad_obj' structures */ Xobjsize=sizeof(struct shadobj); Xfor(shadindx=0;shadindxnoshados;shadindx++) { X if((hdrobj->shad_obj[shadindx] = X (struct shadobj *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->shad_obj[%d]'", X shadindx); X fprintf(stderr," size %u\n", objsize); X exit(-1); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr,"alloc_hdr: hdrobj->shad_obj[%d] = 0x%x,", X shadindx, hdrobj->shad_obj[shadindx]); X fprintf(stderr," size = %d\n",objsize); X } X } X/* initialize 'shad_obj' string to a default */ Xstrcpy(hdrobj->shad_obj[0]->objname,"# no objects shadowed"); Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: %s\n",hdrobj->shad_obj[0]->objname); X } X X/* allocate space for 'call' structure pointers */ Xobjsize=hdralc->nocalls*sizeof(struct caldfile *); Xif((hdrobj->call=(struct caldfile **)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_hdr: cannot allocate 'hdrobj->call' size %u\n", X objsize); X exit(-1); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: %d file calls\n",hdralc->nocalls); X fprintf(stderr,"alloc_hdr: hdrobj->call = 0x%x, size = %d\n", X hdrobj->call,objsize); X } X/* allocate space for 'call' structures */ Xobjsize=sizeof(struct caldfile); Xfor(calindx=0;calindxnocalls;calindx++) { X if((hdrobj->call[calindx]=(struct caldfile *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->call[%d]'", X calindx); X fprintf(stderr," size %u\n", objsize); X exit(-1); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr, X "alloc_hdr: hdrobj->call[%d] = 0x%x, size = %d\n", X calindx,hdrobj->call[calindx],objsize); X } X } X/* initialize 'call' string to a default */ Xstrcpy(hdrobj->call[0]->filnam,"# no files called"); Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: %s\n",hdrobj->call[0]->filnam); X } X X/* allocate space for 'lib' structure pointers */ Xobjsize=hdralc->nolibs*sizeof(struct library *); Xif((hdrobj->lib=(struct library **)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_hdr: cannot allocate 'hdrobj->lib' size %u\n", X objsize); X exit(-1); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: %d libraries\n",hdralc->nolibs); X fprintf(stderr,"alloc_hdr: hdrobj->lib = 0x%x, size = %d\n", X hdrobj->lib,objsize); X } X/* allocate space for 'lib' structures */ Xobjsize=sizeof(struct library); Xfor(libindx=0;libindxnolibs;libindx++) { X if((hdrobj->lib[libindx]=(struct library *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->lib[%d]'", X libindx); X fprintf(stderr," size %u\n", objsize); X exit(-1); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr,"alloc_hdr: hdrobj->lib[%d] = 0x%x, size = %d\n", X libindx,hdrobj->lib[libindx],objsize); X } X } X/* initialize 'lib' string to a default */ Xstrcpy(hdrobj->lib[0]->libnam,"# no libraries used"); Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: %s\n",hdrobj->lib[0]->libnam); X } X X/* allocate space for 'mtl' structure pointers */ Xobjsize = hdralc->nomtls*sizeof(struct material *); Xif((hdrobj->mtl = (struct material **)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_hdr: cannot allocate 'hdrobj->mtl' size %u\n", X objsize); X exit(-1); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: %d materials\n",hdralc->nomtls); X fprintf(stderr,"alloc_hdr: hdrobj->mtl = 0x%x, size = %d\n", X hdrobj->mtl,objsize); X } X/* allocate space for 'mtl' structures */ Xobjsize = sizeof(struct material); Xfor(mtlindx=0; mtlindxnomtls; mtlindx++) { X if((hdrobj->mtl[mtlindx] = (struct material *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->mtl[%d]'", X mtlindx); X fprintf(stderr," size %u\n", objsize); X exit(-1); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr, X "alloc_hdr: hdrobj->mtl[%d] = 0x%x, size = %d\n", X mtlindx,hdrobj->mtl[mtlindx],objsize); X } X /* initialize material attributes to defaults */ X hdrobj->mtl[mtlindx]->Ka.red = 0.1; X hdrobj->mtl[mtlindx]->Ka.green = 0.1; X hdrobj->mtl[mtlindx]->Ka.blue = 0.1; X hdrobj->mtl[mtlindx]->Kd.red = 1.0; X hdrobj->mtl[mtlindx]->Kd.green = 1.0; X hdrobj->mtl[mtlindx]->Kd.blue = 1.0; X hdrobj->mtl[mtlindx]->Ks.red = 0.5; X hdrobj->mtl[mtlindx]->Ks.green = 0.5; X hdrobj->mtl[mtlindx]->Ks.blue = 0.5; X hdrobj->mtl[mtlindx]->Ni.red = 1.25; X hdrobj->mtl[mtlindx]->Ni.green = 1.375; X hdrobj->mtl[mtlindx]->Ni.blue = 1.5; X hdrobj->mtl[mtlindx]->Tf.red = 1.0; X hdrobj->mtl[mtlindx]->Tf.green = 1.0; X hdrobj->mtl[mtlindx]->Tf.blue = 1.0; X hdrobj->mtl[mtlindx]->Ns = 100; X hdrobj->mtl[mtlindx]->mass_dens = 0.0; X hdrobj->mtl[mtlindx]->surf_elast = 0.0; X hdrobj->mtl[mtlindx]->surf_stiff = 0.0; X } X/* initialize 'mtl' string to a default */ Xstrcpy(hdrobj->mtl[0]->mtlnam,"# no materials used"); Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: %s\n",hdrobj->mtl[0]->mtlnam); X } X X/* allocate space for 'map' structure pointers */ Xobjsize=(unsigned)hdralc->nomaps*sizeof(struct mapping *); Xif((hdrobj->map = (struct mapping **)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_hdr: cannot allocate 'hdrobj->map' size %u\n", X objsize); X exit(); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: %d texture maps\n",hdralc->nomaps); X fprintf(stderr,"alloc_hdr: hdrobj->map = 0x%x, size = %d\n", X hdrobj->map,objsize); X } X/* allocate space for 'map' structures */ Xobjsize=sizeof(struct mapping); Xfor(mapindx=0;mapindxnomaps;mapindx++) { X if((hdrobj->map[mapindx]=(struct mapping *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->map[%d]'", X mapindx); X fprintf(stderr," size %u\n", objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr, X "alloc_hdr: hdrobj->map[%d] = 0x%x, size = %d\n", X mapindx,hdrobj->map[mapindx],objsize); X } X } X/* initialize 'map' string to a default */ Xstrcpy(hdrobj->map[0]->mapnam,"# no mappings used"); Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: %s\n",hdrobj->map[0]->mapnam); X } X X/* allocate space for pointers to 'group' structures */ Xobjsize=(unsigned)hdralc->nogroups*sizeof(struct objgrps *); Xif((hdrobj->group=(struct objgrps **)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_hdr: cannot allocate 'hdrobj->group' size %u\n", X objsize); X exit(); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: %d groups\n",hdralc->nogroups); X fprintf(stderr,"alloc_hdr: hdrobj->group = 0x%x, size = %d\n", X hdrobj->group,objsize); X } X X/* allocate space for 'group->*' arrays */ Xfor(gindx=0;gindxnogroups;gindx++) { X objsize=sizeof(struct objgrps); X if((hdrobj->group[gindx]=(struct objgrps *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->group[%d]'", X gindx); X fprintf(stderr," size %u\n",objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr,"alloc_hdr: group[%d] ",gindx); X fprintf(stderr,"= 0x%lx\n", hdrobj->group[gindx]); X } X objsize=hdralc->nogverts*sizeof(int); X if((hdrobj->group[gindx]->vertno=(int *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->group[%d]", X gindx); X fprintf(stderr,"->vertno' size %u\n", X objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr,"alloc_hdr: group[%d]->vertno ",gindx); X fprintf(stderr,"= 0x%lx, size %u\n", X hdrobj->group[gindx]->vertno,objsize); X } X objsize=hdralc->nogpoints*sizeof(int); X if((hdrobj->group[gindx]->pointno=(int *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->group[%d]", X gindx); X fprintf(stderr,"->pointno' size %u\n", X objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr,"alloc_hdr: group[%d]->pointno ",gindx); X fprintf(stderr,"= 0x%lx, size %u\n", X hdrobj->group[gindx]->pointno,objsize); X } X objsize=hdralc->noglines*sizeof(int); X if((hdrobj->group[gindx]->lineno=(int *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->group[%d]", X gindx); X fprintf(stderr,"->lineno' size %u\n", X objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr,"alloc_hdr: group[%d]->lineno ",gindx); X fprintf(stderr,"= 0x%lx\n", hdrobj->group[gindx]->lineno); X } X objsize=hdralc->nogfaces*sizeof(int); X if((hdrobj->group[gindx]->faceno=(int *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->group[%d]", X gindx); X fprintf(stderr,"->faceno' size %u\n", X objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr,"alloc_hdr: group[%d]->faceno ",gindx); X fprintf(stderr,"= 0x%lx\n", hdrobj->group[gindx]->faceno); X } X objsize=hdralc->nogcircs*sizeof(int); X if((hdrobj->group[gindx]->circno=(int *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->group[%d]", X gindx); X fprintf(stderr,"->circno' size %u\n", X objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr,"alloc_hdr: group[%d]->circno ",gindx); X fprintf(stderr,"= 0x%lx\n", hdrobj->group[gindx]->circno); X } X objsize=hdralc->nogsphrs*sizeof(int); X if((hdrobj->group[gindx]->sphrno=(int *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->group[%d]", X gindx); X fprintf(stderr,"->sphrno' size %u\n", X objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr,"alloc_hdr: group[%d]->sphrno ",gindx); X fprintf(stderr,"= 0x%lx\n", hdrobj->group[gindx]->sphrno); X } X objsize=hdralc->nogptchs*sizeof(int); X if((hdrobj->group[gindx]->ptchno=(int *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_hdr: cannot allocate 'hdrobj->group[%d]", X gindx); X fprintf(stderr,"->ptchno' size %u\n", X objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr,"alloc_hdr: group[%d]->ptchno ",gindx); X fprintf(stderr,"= 0x%lx\n", hdrobj->group[gindx]->ptchno); X } X /* initialize group element pointer counts to 0 */ X hdrobj->group[gindx]->noverts=0; X hdrobj->group[gindx]->nofaces=0; X hdrobj->group[gindx]->nolines=0; X hdrobj->group[gindx]->nopoints=0; X hdrobj->group[gindx]->nocircs=0; X hdrobj->group[gindx]->nosphrs=0; X hdrobj->group[gindx]->noptchs=0; X } X X/* initialize 'group' name to a default */ Xstrcpy(hdrobj->group[0]->grpnam,"d"); Xif(verbflg>10) { X fprintf(stderr,"alloc_hdr: %s\n",hdrobj->group[0]->grpnam); X } X X/* initialize structure pointers to NULL, indicating no allocation */ Xhdrobj->vertex = NULL; Xhdrobj->texver = NULL; Xhdrobj->face = NULL; Xhdrobj->edge = NULL; Xhdrobj->line = NULL; Xhdrobj->point = NULL; Xhdrobj->circl = NULL; Xhdrobj->spher = NULL; Xhdrobj->bicub = NULL; Xhdrobj->metadef = NULL; X X/* initialize allocation sizes in output object */ Xhdrobj->alloc.nomtls=hdralc->nomtls; Xhdrobj->alloc.nomaps=hdralc->nomaps; Xhdrobj->alloc.notraces=hdralc->notraces; Xhdrobj->alloc.noshados=hdralc->noshados; Xhdrobj->alloc.nocalls=hdralc->nocalls; Xhdrobj->alloc.nolibs=hdralc->nolibs; Xhdrobj->alloc.nogroups=hdralc->nogroups; Xhdrobj->alloc.nogverts=hdralc->nogverts; Xhdrobj->alloc.noglines=hdralc->noglines; Xhdrobj->alloc.nogfaces=hdralc->nogfaces; Xhdrobj->alloc.nogcircs=hdralc->nogcircs; Xhdrobj->alloc.nogsphrs=hdralc->nogsphrs; Xhdrobj->alloc.nogptchs=hdralc->nogptchs; Xhdrobj->alloc.nogpoints=hdralc->nogpoints; X X/* initialize population size parameters in output object */ Xhdrobj->size.nomtls=1; Xhdrobj->size.nomaps=1; Xhdrobj->size.notraces=1; Xhdrobj->size.noshados=1; Xhdrobj->size.nocalls=1; Xhdrobj->size.nolibs=1; Xhdrobj->size.nogroups=1; Xfor(gindx=0;gindxalloc.nogroups;gindx++) { X hdrobj->group[gindx]->noverts = 0; X hdrobj->group[gindx]->nolines = 0; X hdrobj->group[gindx]->nofaces = 0; X hdrobj->group[gindx]->nopoints = 0; X hdrobj->group[gindx]->nocircs = 0; X hdrobj->group[gindx]->nosphrs = 0; X hdrobj->group[gindx]->noptchs = 0; X } Xhdrobj->size.nogverts=0; Xhdrobj->size.noglines=0; Xhdrobj->size.nogfaces=0; Xhdrobj->size.nogcircs=0; Xhdrobj->size.nogsphrs=0; Xhdrobj->size.nogptchs=0; Xhdrobj->size.nogpoints=0; X Xreturn(hdrobj); X} X X X X X X X X/* function: alloc_verts X X description: allocates space for vertices in an object X*/ X X Xstruct topology *alloc_verts(vertobj,vertalc) Xstruct topology *vertobj; Xstruct sizes *vertalc; X{ Xunsigned objsize; Xint vindx; X Xif(verbflg > 10) { X fprintf(stderr,"entering alloc_verts\n"); X } X X/* make sure we are allocating at least one vertex */ Xif(vertalc->noverts<=0) vertalc->noverts=1; Xif(vertalc->valence<=0) vertalc->valence=1; X X/* allocate space for 'vertex' structure pointers */ Xobjsize=vertalc->noverts*sizeof(struct vertex *); Xif((vertobj->vertex=(struct vertex **)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_verts: cannot allocate 'vertobj->vertex' size %u\n", X objsize); X exit(); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_verts: %d vertices\n",vertalc->noverts); X fprintf(stderr,"alloc_verts: vertobj->vertex = 0x%x, size = %d\n", X vertobj->vertex,objsize); X } X X/* allocate space for 'vertex[]' structures, 'vertex->faceno' X and 'vertex->edgeno' arrays */ Xfor(vindx=0;vindxnoverts;vindx++) { X objsize=sizeof(struct vertex); X if((vertobj->vertex[vindx]=(struct vertex *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_verts: cannot allocate 'vertobj->vertex[%d]'", X vindx); X fprintf(stderr," size %u\n", objsize); X exit(-1); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr, X "alloc_verts: vertobj->vertex[%d] = 0x%x, size = %d\n", X vindx,vertobj->vertex[vindx],objsize); X } X objsize=vertalc->valence*sizeof(int); X if((vertobj->vertex[vindx]->faceno=(int *)malloc(objsize))==NULL) { X fprintf(stderr, "alloc_verts: cannot allocate"); X fprintf(stderr," 'vertobj->vertex[%d]->faceno' size %u\n", X vindx,objsize); X exit(-1); X } X if((vertobj->vertex[vindx]->edgeno=(int *)malloc(objsize))==NULL) { X fprintf(stderr, "alloc_verts: cannot allocate"); X fprintf(stderr," 'vertobj->vertex[%d]->edgeno' size %u\n", X vindx,objsize); X exit(-1); X } X X /* initialize vertex attributes */ X vertobj->vertex[vindx]->normal.x = 0; X vertobj->vertex[vindx]->normal.y = 0; X vertobj->vertex[vindx]->normal.z = 0; X vertobj->vertex[vindx]->group = 0; X vertobj->vertex[vindx]->mtl = 0; X X cumsize+=objsize*2; X } X X/* update allocation size parameters in output object */ Xvertobj->alloc.noverts=vertalc->noverts; Xvertobj->alloc.valence=vertalc->valence; X X/* update population size parameters in output object */ Xvertobj->size.noverts=1; Xvertobj->size.valence=0; X Xreturn(vertobj); X} X X X X X X/* function: alloc_faces X X description: allocates face structures for an object. X*/ X X Xstruct topology *alloc_faces(facobj,facalc) Xstruct topology *facobj; Xstruct sizes *facalc; X{ Xunsigned objsize; Xint findx; X X/* make sure we allocate at least one of each entity */ Xif(facalc->nofaces<=0) facalc->nofaces=1; X/* make sure we allocate at least three vertices per face */ Xif(facalc->nofverts<3) facalc->nofverts=3; X X/* allocate space for 'face' structure pointers */ Xobjsize=facalc->nofaces*sizeof(struct faces *); Xif((facobj->face=(struct faces **)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_faces: cannot allocate 'facobj->face' size %u\n", X objsize); X exit(); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_faces: %d faces\n",facalc->nofaces); X fprintf(stderr,"alloc_faces: facobj->face = 0x%x, size = %d\n", X facobj->face,objsize); X } X X/* allocate space for 'face[]' structures, 'face->vertno', 'face->tvertno' X and 'face->edgeno' arrays */ Xfor(findx=0;findxnofaces;findx++) { X objsize=sizeof(struct faces); X if((facobj->face[findx]=(struct faces *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_faces: cannot allocate 'facobj->face[%d]'", X findx); X fprintf(stderr," size %u\n", objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr, X "alloc_faces: facobj->face[%d] = 0x%x, size = %d\n", X findx,facobj->face[findx],objsize); X } X objsize=facalc->nofverts*sizeof(int); X if((facobj->face[findx]->vertno=(int *)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_faces: cannot allocate"); X fprintf(stderr," 'facobj->face[%d]->vertno' size %u\n", X findx,objsize); X exit(); X } X if((facobj->face[findx]->tvertno=(int *)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_faces: cannot allocate"); X fprintf(stderr," 'facobj->face[%d]->tvertno' size %u\n", X findx,objsize); X exit(); X } X if((facobj->face[findx]->edgeno=(int *)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_faces: cannot allocate"); X fprintf(stderr," 'facobj->face[%d]->edgeno' size %u\n", X findx,objsize); X exit(); X } X cumsize+=objsize*3; X } X X/* update allocation sizes in output object */ Xfacobj->alloc.nofaces=facalc->nofaces; Xfacobj->alloc.nofverts=facalc->nofverts; X X/* initialize population sizes in output object */ Xfacobj->size.nofaces=0; Xfacobj->size.nofverts=0; X Xreturn(facobj); X} X X X X X X/* function: alloc_tverts X X description: allocates texture vertices for an object. X*/ X X Xstruct topology *alloc_tverts(tvrtobj,tvrtalc) Xstruct topology *tvrtobj; Xstruct sizes *tvrtalc; X{ Xunsigned objsize; Xint tvindx; X X/* make sure we allocate at least one */ Xif(tvrtalc->notverts<=0) tvrtalc->notverts=1; X X/* allocate space for 'texver' structure pointers */ Xobjsize=tvrtalc->notverts*sizeof(struct textur *); Xif((tvrtobj->texver=(struct textur **)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_tverts: cannot allocate"); X fprintf(stderr," 'tvrtobj->texver' size %u\n",objsize); X exit(); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_tverts: %d texture vertices\n",tvrtalc->notverts); X fprintf(stderr,"alloc_tverts: tvrtobj->texver = 0x%x, size = %d\n", X tvrtobj->texver,objsize); X } X X/* allocate space for 'texver' structures */ Xobjsize=sizeof(struct textur); Xfor(tvindx=0;tvindxnotverts;tvindx++) { X if((tvrtobj->texver[tvindx]=(struct textur *)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_tverts: cannot allocate"); X fprintf(stderr, X " 'tvrtobj->texver[%d]' size %u\n",tvindx,objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr, X "alloc_tverts: tvrtobj->texver[%d] = 0x%x, size = %d\n", X tvindx,tvrtobj->texver[tvindx],objsize); X } X } X X/* update allocation sizes in output object */ Xtvrtobj->alloc.notverts=tvrtalc->notverts; X X/* initialize population sizes in output object */ Xtvrtobj->size.notverts=1; X Xreturn(tvrtobj); X} X X X X X X/* function: alloc_lines X X description: allocates lines for an object. X*/ X X Xstruct topology *alloc_lines(linobj,linalc) Xstruct topology *linobj; Xstruct sizes *linalc; X{ Xunsigned objsize; Xint lindx; X X/* make sure we allocate at least one */ Xif(linalc->nolverts<=0) linalc->nolverts=1; Xif(linalc->nolines<=0) linalc->nolines=1; X X/* allocate space for 'line' structure pointers */ Xobjsize=linalc->nolines*sizeof(struct lines *); Xif((linobj->line=(struct lines **)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_lines: cannot allocate 'linobj->line' size %u\n", X objsize); X exit(); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_lines: %d lines, %d verts/line\n", X linalc->nolines,linalc->nolverts); X fprintf(stderr,"alloc_lines: linobj->line = 0x%x, size = %d\n", X linobj->line,objsize); X } X X/* allocate space for 'line->vertno' arrays */ Xfor(lindx=0;lindxnolines;lindx++) { X objsize=sizeof(struct lines); X if((linobj->line[lindx]=(struct lines *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_lines: cannot allocate 'linobj->line[%d]'", X lindx); X fprintf(stderr," size %u\n", objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr, X "alloc_lines: linobj->line[%d] = 0x%x, size = %d\n", X lindx,linobj->line[lindx],objsize); X } X objsize=linalc->nolverts*sizeof(int); X if((linobj->line[lindx]->vertno=(int *)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_lines: cannot allocate"); X fprintf(stderr," 'linobj->line[%d]->vertno' size %u\n", X lindx,objsize); X exit(); X } X cumsize+=objsize; X } X X/* update allocation sizes in output object */ Xlinobj->alloc.nolverts=linalc->nolverts; Xlinobj->alloc.nolines=linalc->nolines; X X/* initialize population sizes in output object */ Xlinobj->size.nolverts=0; Xlinobj->size.nolines=0; X Xreturn(linobj); X} X X X X X X/* function: alloc_edges X X description: allocates edges for an object. X*/ X X Xstruct topology *alloc_edges(edgobj,edgalc) Xstruct topology *edgobj; Xstruct sizes *edgalc; X{ Xunsigned objsize; Xint eindx; X X/* make sure we allocate at least one */ Xif(edgalc->noedges <= 0) edgalc->noedges = 1; X X/* allocate space for 'edge' structure pointers */ Xobjsize=edgalc->noedges*sizeof(struct edges *); Xif((edgobj->edge=(struct edges **)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_edges: cannot allocate 'edgobj->edge' size %u\n", X objsize); X exit(); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_edges: %d edges\n",edgalc->noedges); X fprintf(stderr,"alloc_edges: edgobj->edge = 0x%x, size = %d\n", X edgobj->edge,objsize); X } X/* allocate space for 'edge' structures */ Xobjsize=sizeof(struct edges); Xfor(eindx=0;eindxnoedges;eindx++) { X if((edgobj->edge[eindx]=(struct edges *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_edges: cannot allocate 'edgobj->edge[%d]'", X eindx); X fprintf(stderr," size %u\n", objsize); X exit(); X } X cumsize+=objsize; X X /* initialize edge face indices to recognized undefined values */ X edgobj->edge[eindx]->faceno[0] = -1; X edgobj->edge[eindx]->faceno[1] = -1; X X if(verbflg>20) { X fprintf(stderr, X "alloc_edges: edgobj->edge[%d] = 0x%x, size = %d\n", X eindx,edgobj->edge[eindx],objsize); X } X } X X/* update allocation sizes in output object */ Xedgobj->alloc.noedges = edgalc->noedges; X X/* initialize population sizes in output object */ Xedgobj->size.noedges = 0; X Xreturn(edgobj); X} X X X X X X/* function: alloc_points X X description: allocates points for an object X*/ X X Xstruct topology *alloc_points(pntobj,pontalc) Xstruct topology *pntobj; Xstruct sizes *pontalc; X{ Xunsigned objsize; Xint pindx; X X/* make sure we allocate at least one */ Xif(pontalc->nopverts<=0) pontalc->nopverts=1; Xif(pontalc->nopoints<=0) pontalc->nopoints=1; X X/* allocate space for 'point' structure pointers */ Xobjsize=pontalc->nopoints*sizeof(struct points *); Xif((pntobj->point=(struct points **)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_points: cannot allocate 'pntobj->point' size %u\n", X objsize); X exit(); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_points: %d points\n",pontalc->nopoints); X fprintf(stderr,"alloc_points: pntobj->point = 0x%x, size = %d\n", X pntobj->point,objsize); X } X X/* allocate space for 'point' structures and 'point->vertno' arrays */ Xfor(pindx=0;pindxnopoints;pindx++) { X objsize=sizeof(struct points); X if((pntobj->point[pindx]=(struct points *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_points: cannot allocate 'pntobj->point[%d]'", X pindx); X fprintf(stderr," size %u\n", objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr, X "alloc_points: pntobj->point[%d] = 0x%x, size = %d\n", X pindx,pntobj->point[pindx],objsize); X } X objsize=pontalc->nopverts*sizeof(int); X if((pntobj->point[pindx]->vertno=(int *)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_points: cannot allocate"); X fprintf(stderr," 'pntobj->point[%d]->vertno' size %u\n", X pindx,objsize); X exit(); X } X cumsize+=objsize; X } X X X/* update allocation sizes in output object */ Xpntobj->alloc.nopverts=pontalc->nopverts; Xpntobj->alloc.nopoints=pontalc->nopoints; X X/* initialize population sizes in output object */ Xpntobj->size.nopverts=0; Xpntobj->size.nopoints=0; X Xreturn(pntobj); X} X X X X X X/* function: alloc_circs(circobj,circalc) X X description: allocates circles for an object. X*/ X X Xstruct topology *alloc_circs(circobj,circalc) Xstruct topology *circobj; Xstruct sizes *circalc; X{ Xunsigned objsize; Xint cindx; X X/* make sure we allocate at least one */ Xif(circalc->nocircs<=0) circalc->nocircs=1; X X/* allocate space for 'circl' structure pointers */ Xobjsize=circalc->nocircs*sizeof(struct circles *); Xif((circobj->circl=(struct circles **)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_circs: cannot allocate"); X fprintf(stderr," 'circobj->circl' size %u\n",objsize); X exit(); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_circs: %d circles\n",circalc->nocircs); X fprintf(stderr,"alloc_circs: circobj->circl = 0x%x, size = %d\n", X circobj->circl,objsize); X } X/* allocate space for 'circl' structures */ Xobjsize=sizeof(struct circles); Xfor(cindx=0;cindxnocircs;cindx++) { X if((circobj->circl[cindx]=(struct circles *)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_circs: cannot allocate"); X fprintf(stderr, X " 'circobj->circl[%d]' size %u\n",cindx,objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr, X "alloc_circs: circobj->circl[%d] = 0x%x, size = %d\n", X cindx,circobj->circl[cindx],objsize); X } X } X X/* update allocation sizes in output object */ Xcircobj->alloc.nocircs=circalc->nocircs; X X/* initialize population sizes in output object */ Xcircobj->size.nocircs=0; X Xreturn(circobj); X} X X X X X X/* function: alloc_sphrs() X X description: allocates spheres for an object. X*/ X X Xstruct topology *alloc_sphrs(sphobj,sphalc) Xstruct topology *sphobj; Xstruct sizes *sphalc; X{ Xunsigned objsize; Xint sindx; X X/* make sure we allocate at least one */ Xif(sphalc->nosphrs<=0) sphalc->nosphrs = 1; X X/* allocate space for 'spher' structure pointers */ Xobjsize=sphalc->nosphrs*sizeof(struct spheres *); Xif((sphobj->spher=(struct spheres **)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_sphrs: cannot allocate 'sphobj->spher' size %u\n", X objsize); X exit(); X } Xcumsize+=objsize; Xif(verbflg>10) { X fprintf(stderr,"alloc_sphrs: %d spheres\n",sphalc->nosphrs); X fprintf(stderr,"alloc_sphrs: sphobj->spher = 0x%x, size = %d\n", X sphobj->spher,objsize); X } X/* allocate space for 'spher' structures */ Xobjsize=sizeof(struct spheres); Xfor(sindx=0;sindxnosphrs;sindx++) { X if((sphobj->spher[sindx]=(struct spheres *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_sphrs: cannot allocate 'sphobj->spher[%d]'", X sindx); X fprintf(stderr," size %u\n",objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr, X "alloc_sphrs: sphobj->spher[%d] = 0x%x, size = %d\n", X sindx,sphobj->spher[sindx],objsize); X } X } X X/* update allocation sizes in output object */ Xsphobj->alloc.nosphrs=sphalc->nosphrs; X X/*initialize population sizes in output object */ Xsphobj->size.nosphrs = 0; X Xreturn(sphobj); X} X X X X X X/* function: alloc_ptchs X X description: allocates bicubic patches for an object X*/ X X Xstruct topology *alloc_ptchs(ptchobj,ptchalc) Xstruct topology *ptchobj; Xstruct sizes *ptchalc; X{ Xunsigned objsize; Xint bindx; X X/* make sure allocation sizes in object struct are non-zero */ Xif(ptchalc->noptchs<=0) ptchalc->noptchs=1; X X/* allocate space for 'bicub' structure pointers */ Xobjsize=ptchalc->noptchs*sizeof(struct bicubes *); Xcumsize+=objsize; Xif((ptchobj->bicub=(struct bicubes **)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_ptchs: cannot allocate 'ptchobj->bicub' size %u\n", X objsize); X exit(); X } Xif(verbflg>10) { X fprintf(stderr,"alloc_ptchs: %d bicubic patches\n",ptchalc->noptchs); X fprintf(stderr,"alloc_ptchs: ptchobj->bicub = 0x%x, size = %d\n", X ptchobj->bicub,objsize); X } X/* allocate space for 'bicub' structures */ Xobjsize=sizeof(struct bicubes); Xfor(bindx=0;bindxnoptchs;bindx++) { X if((ptchobj->bicub[bindx]=(struct bicubes *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_ptchs: cannot allocate 'ptchobj->bicub[%d]'", X bindx); X fprintf(stderr," size %u\n", objsize); X exit(); X } X cumsize+=objsize; X if(verbflg>20) { X fprintf(stderr, X "alloc_ptchs: ptchobj->bicub[%d] = 0x%x, size = %d\n", X bindx,ptchobj->bicub[bindx],objsize); X } X } X X/* set allocation sizes in object struct */ Xptchobj->alloc.noptchs=ptchalc->noptchs; X X/* initialize object sizes in object struct */ Xptchobj->size.noptchs=0; X Xreturn(ptchobj); X} X X X X X X/* function: alloc_mdefs X X description: allocates object meta-element definitions for an object X*/ X X Xstruct topology *alloc_mdefs(mdefobj,mdefalc) Xstruct topology *mdefobj; Xstruct sizes *mdefalc; X{ X Xreturn(mdefobj); X} X X X X X X/* function: alloc_mrefs X X description: allocates object meta-element references for an object X*/ X X Xstruct topology *alloc_mrefs(mrefobj,mrefalc) Xstruct topology *mrefobj; Xstruct sizes *mrefalc; X{ X Xreturn(mrefobj); X} X X X X X X/* function: alloc_moprs X X description: allocates object meta-element operations for an object X*/ X X Xstruct topology *alloc_moprs(moprobj,mopralc) Xstruct topology *moprobj; Xstruct sizes *mopralc; X{ X Xreturn(moprobj); X} X X X X X X/* function: def_parms X X description: reads environment for object size parameter variables or X uses internal defaults for object allocation parameters. X X author: Stewart Dickson X*/ X X X Xstruct sizes *def_parms(defalc) Xstruct sizes *defalc; X{ Xchar *getenv(),*c_vert,*c_tvert,*c_nomtl,*c_novpe,*c_notex,*c_nolib; Xchar *c_nolines,*c_nopoints,*c_nofaces,*c_nocircs,*c_nosphrs; Xchar *c_noptchs,*c_noedges,*c_novpl,*c_novpf,*c_valence; X Xif(verbflg>0) { X fprintf(stderr,"entering def_parms()\n"); X } X Xif(defalc==NULL) { X /* allocate space for object size parameter structure */ X if((defalc=(struct sizes *)malloc(sizeof(struct sizes)))==NULL) { X fprintf(stderr, X "def_parms: cannot allocate 'defalc' struct size %d\n", X sizeof(struct sizes)); X exit(); X } X } X X/* check for Wavefront environment variables then SPD variables */ X X/* check environment */ Xif((c_vert=getenv("WF_MVRT"))==NULL) { /* if not set, use default */ X defalc->noverts=5000; X defalc->nolines=100; X defalc->nopoints=100; X defalc->nofaces=5000; X defalc->noedges=100; X defalc->nocircs=100; X defalc->nosphrs=100; X defalc->noptchs=10; X defalc->noglines=100; X defalc->nogverts=5000; X defalc->nogpoints=100; X defalc->nogfaces=5000; X defalc->nogcircs=100; X defalc->nogsphrs=100; X defalc->nogptchs=10; X } Xelse { X fprintf(stderr,"WF_MVRT = %s\n",c_vert); X defalc->noverts=atoi(c_vert); X defalc->nolines=100; X defalc->nopoints=100; X defalc->nofaces=5000; X defalc->noedges=100; X defalc->nocircs=100; X defalc->nosphrs=100; X defalc->noptchs=10; X defalc->noglines=100; X defalc->nogverts=100; X defalc->nogpoints=100; X defalc->nogfaces=5000; X defalc->nogcircs=100; X defalc->nogsphrs=100; X defalc->nogptchs=10; X } X Xif((c_tvert=getenv("WF_MTVS"))==NULL) { /* if not set, use default */ X defalc->notverts=5000; X } Xelse { X fprintf(stderr,"WF_MTVS = %s\n",c_tvert); X defalc->notverts=atoi(c_tvert); X } X Xif((c_nomtl=getenv("WF_MMTL"))==NULL) { /* if not set, use default */ X defalc->nomtls=100; X } Xelse { X fprintf(stderr,"WF_MMTL = %s\n",c_nomtl); X defalc->nomtls=atoi(c_nomtl); X } X Xif((c_novpe=getenv("WF_MVPE"))==NULL) { /* if not set, use default */ X defalc->nolverts=500; X defalc->nofverts=10; X defalc->valence=10; X defalc->nopverts=500; X } Xelse { X fprintf(stderr,"WF_MVPE = %s\n",c_novpe); X defalc->nolverts=atoi(c_novpe); X if((defalc->nofverts=atoi(c_novpe)/10)<3) { X defalc->nofverts=4; X } X defalc->nopverts=atoi(c_novpe); X if((defalc->valence=atoi(c_novpe)/20)<3) { X defalc->valence=6; X } X } X Xif((c_notex=getenv("WF_MTEX"))==NULL) { /* if not set, use default */ X defalc->nomaps=10; X defalc->nocalls=10; X defalc->nolibs=10; X } Xelse { X fprintf(stderr,"WF_MTEX = %s\n",c_notex); X defalc->nomaps=atoi(c_notex); X defalc->nocalls=atoi(c_notex); X defalc->nolibs=atoi(c_notex); X } X Xdefalc->notraces=1; Xdefalc->noshados=1; Xdefalc->nogroups=10; X X/* check for SPD environment variables */ X Xif((c_vert=getenv("SPD_VERTS"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_VERTS = %s\n",c_vert); X defalc->noverts=atoi(c_vert); X } X Xif((c_vert=getenv("SPD_GROUPS"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_GROUPS = %s\n",c_vert); X defalc->nogroups=atoi(c_vert); X } X Xif((c_tvert=getenv("SPD_TVERTS"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_TVERTS = %s\n",c_tvert); X defalc->notverts=atoi(c_tvert); X } X Xif((c_nomtl=getenv("SPD_MTLS"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_MTLS = %s\n",c_nomtl); X defalc->nomtls=atoi(c_nomtl); X } X Xif((c_notex=getenv("SPD_TEX"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_TEX = %s\n",c_notex); X defalc->nomaps=atoi(c_notex); X } X Xif((c_nolib=getenv("SPD_LIBS"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_LIBS = %s\n",c_nolib); X defalc->nolibs=atoi(c_nolib); X defalc->nocalls=atoi(c_nolib); X } X Xif((c_nolines=getenv("SPD_LINES"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_LINES = %s\n",c_nolines); X defalc->nolines=atoi(c_nolines); X defalc->noglines=atoi(c_nolines); X } X Xif((c_nopoints=getenv("SPD_POINTS"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_POINTS = %s\n",c_nopoints); X defalc->nopoints=atoi(c_nopoints); X defalc->nogpoints=atoi(c_nopoints); X } X Xif((c_nofaces=getenv("SPD_FACES"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_FACES = %s\n",c_nofaces); X defalc->nofaces=atoi(c_nofaces); X defalc->nogfaces=atoi(c_nofaces); X } X Xif((c_nocircs=getenv("SPD_CIRCS"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_CIRCS = %s\n",c_nocircs); X defalc->nocircs=atoi(c_nocircs); X defalc->nogcircs=atoi(c_nocircs); X } X Xif((c_nosphrs=getenv("SPD_SPHRS"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_SPHRS = %s\n",c_nosphrs); X defalc->nosphrs=atoi(c_nosphrs); X defalc->nogsphrs=atoi(c_nosphrs); X } X Xif((c_noptchs=getenv("SPD_PTCHS"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_PTCHS = %s\n",c_noptchs); X defalc->noptchs=atoi(c_noptchs); X defalc->nogptchs=atoi(c_noptchs); X } X Xif((c_noedges=getenv("SPD_EDGES"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_EDGES = %s\n",c_noedges); X defalc->noedges=atoi(c_noedges); X } X Xif((c_novpl=getenv("SPD_VPLIN"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_VPLIN = %s\n",c_novpl); X defalc->nolverts=atoi(c_novpl); X defalc->nopverts=atoi(c_novpl); X } X Xif((c_novpf=getenv("SPD_VPFAC"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_VPFAC = %s\n",c_novpf); X defalc->nofverts=atoi(c_novpf); X } X Xif((c_valence=getenv("SPD_VALEN"))!=NULL) { /* if set, use it */ X fprintf(stderr,"SPD_VALEN = %s\n",c_valence); X defalc->valence=atoi(c_valence); X } X X/* set object name to a default */ Xstrcpy(defalc->objname,"default object"); X Xif(verbflg>0) { X fprintf(stderr,"def_parms: done\n"); X } X Xreturn(defalc); X} X X X X X X X X/* function: null_parms X X description: Allocates object allocation parameters, but populates with X zeroes. X X author: Stewart Dickson X*/ X X X Xstruct sizes *null_parms(nulalc) Xstruct sizes *nulalc; X{ X Xif(verbflg>0) { X fprintf(stderr,"entering null_parms()\n"); X } X Xif(nulalc==NULL) { X /* allocate space for object size parameter structure */ X if((nulalc=(struct sizes *)malloc(sizeof(struct sizes)))==NULL) { X fprintf(stderr, X "def_parms: cannot allocate 'nulalc' struct size %d\n", X sizeof(struct sizes)); X exit(-1); X } X } X Xnulalc->noverts=0; Xnulalc->notverts=0; Xnulalc->valence=0; Xnulalc->nolines=0; Xnulalc->nolverts=0; Xnulalc->nopoints=0; Xnulalc->nopverts=0; Xnulalc->nofaces=0; Xnulalc->nofverts=0; Xnulalc->noedges=0; Xnulalc->nocircs=0; Xnulalc->nosphrs=0; Xnulalc->noptchs=0; Xnulalc->noglines=0; Xnulalc->nogverts=0; Xnulalc->nogpoints=0; Xnulalc->nogfaces=0; Xnulalc->nogcircs=0; Xnulalc->nogsphrs=0; Xnulalc->nogptchs=0; Xnulalc->nomtls=0; Xnulalc->nomaps=0; Xnulalc->nocalls=0; Xnulalc->nolibs=0; Xnulalc->notraces=0; Xnulalc->noshados=0; Xnulalc->nogroups=0; X X/* set object name to a null string */ Xstrcpy(nulalc->objname,""); X Xif(verbflg>0) { X fprintf(stderr,"null_parms: done\n"); X } X Xreturn(nulalc); X} X X X X X X X X/* function: copy_alc X X description: copies allocation parameters from an object structure X to an allocation structure. X X*/ X X Xstruct sizes *copy_alc(cpyobj,cpalloc) Xstruct topology *cpyobj; Xstruct sizes *cpalloc; X{ X Xif(cpyobj==NULL) { /* NULL source pointer received */ X fprintf(stderr,"copy_alc: ERROR - NULL object pointer received\n"); X exit(); X } X Xif(verbflg>2) { X fprintf(stderr,"entering copy_alc('%s',%d)\n",cpyobj->size.objname, X cpalloc); X } X Xif(cpalloc==NULL) { /* if memory has not been allocated for this */ X if(verbflg>2) { X fprintf(stderr, X "copy_alc: allocating duplicate alloc struct...\n "); X } X /* allocate structure for internal use */ X if((cpalloc=(struct sizes *)malloc(sizeof(struct sizes)))==NULL) { X fprintf(stderr,"copy_alc: cannot allocate 'cpalloc' size %d\n", X sizeof(struct sizes)); X exit(); X } X if(verbflg>2) { X fprintf(stderr,"copy_alc: done\n"); X } X } X X/* set object name */ Xstrcpy(cpalloc->objname,cpyobj->size.objname); X X/* copy allocations from cpyobj returned from alloc_obj() */ X/* (prevent ourselves from passing along garbage */ Xif((cpalloc->noverts=cpyobj->alloc.noverts)<=0) cpalloc->noverts = 1; Xif((cpalloc->notverts=cpyobj->alloc.notverts)<=0) cpalloc->notverts = 1; Xif((cpalloc->nomtls=cpyobj->alloc.nomtls)<=0) cpalloc->nomtls = 1; Xif((cpalloc->nomaps=cpyobj->alloc.nomaps)<=0) cpalloc->nomaps = 1; Xif((cpalloc->notraces=cpyobj->alloc.notraces)<=0) cpalloc->notraces = 1; Xif((cpalloc->noshados=cpyobj->alloc.noshados)<=0) cpalloc->noshados = 1; Xif((cpalloc->nocalls=cpyobj->alloc.nocalls)<=0) cpalloc->nocalls = 1; Xif((cpalloc->nolibs=cpyobj->alloc.nolibs)<=0) cpalloc->nolibs = 1; Xif((cpalloc->nogroups=cpyobj->alloc.nogroups)<=0) cpalloc->nogroups = 1; Xif((cpalloc->nogverts=cpyobj->alloc.nogverts)<=0) cpalloc->nogverts = 1; Xif((cpalloc->noglines=cpyobj->alloc.noglines)<=0) cpalloc->noglines = 1; Xif((cpalloc->nogfaces=cpyobj->alloc.nogfaces)<=0) cpalloc->nogfaces = 1; Xif((cpalloc->nogsphrs=cpyobj->alloc.nogsphrs)<=0) cpalloc->nogsphrs = 1; Xif((cpalloc->nogcircs=cpyobj->alloc.nogcircs)<=0) cpalloc->nogcircs = 1; Xif((cpalloc->nogptchs=cpyobj->alloc.nogptchs)<=0) cpalloc->nogptchs = 1; Xif((cpalloc->nogpoints=cpyobj->alloc.nogpoints)<=0) cpalloc->nogpoints = 1; Xif((cpalloc->nolverts=cpyobj->alloc.nolverts)<=0) cpalloc->nolverts = 1; Xif((cpalloc->nofverts=cpyobj->alloc.nofverts)<=0) cpalloc->nofverts = 1; Xif((cpalloc->nopverts=cpyobj->alloc.nopverts)<=0) cpalloc->nopverts = 1; Xif((cpalloc->valence=cpyobj->alloc.valence)<=0) cpalloc->valence = 1; Xif((cpalloc->nolines=cpyobj->alloc.nolines)<=0) cpalloc->nolines = 1; Xif((cpalloc->nofaces=cpyobj->alloc.nofaces)<=0) cpalloc->nofaces = 1; Xif((cpalloc->nopoints=cpyobj->alloc.nopoints)<=0) cpalloc->nopoints = 1; Xif((cpalloc->nocircs=cpyobj->alloc.nocircs)<=0) cpalloc->nocircs = 1; Xif((cpalloc->nosphrs=cpyobj->alloc.nosphrs)<=0) cpalloc->nosphrs = 1; Xif((cpalloc->noptchs=cpyobj->alloc.noptchs)<=0) cpalloc->noptchs = 1; Xif((cpalloc->noedges=cpyobj->alloc.noedges)<=0) cpalloc->noedges = 1; X Xreturn(cpalloc); X} X X X X X X X X X/* function: copy_siz X X description: copies population size parameters from an object structure X to an allocation structure. X X*/ X X Xstruct sizes *copy_siz(cpyobj,cpalloc) Xstruct topology *cpyobj; Xstruct sizes *cpalloc; X{ Xint gindx; X Xif(cpyobj==NULL) { /* NULL source pointer received */ X fprintf(stderr,"copy_siz: ERROR - NULL object pointer received\n"); X exit(); X } X Xif(verbflg>2) { X fprintf(stderr,"entering copy_siz('%s',%d)\n",cpyobj->size.objname, X cpalloc); X } X Xif(cpalloc==NULL) { /* if memory has not been allocated for this */ X if(verbflg>2) { X fprintf(stderr, X "copy_siz: allocating duplicate alloc struct...\n "); X } X /* allocate structure for internal use */ X if((cpalloc=(struct sizes *)malloc(sizeof(struct sizes)))==NULL) { X fprintf(stderr,"copy_siz: cannot allocate 'cpalloc' size %d\n", X sizeof(struct sizes)); X exit(); X } X if(verbflg>2) { X fprintf(stderr,"copy_siz: done\n"); X } X } X X/* set object name */ Xstrcpy(cpalloc->objname,cpyobj->size.objname); X X/* copy sizes from cpyobj */ Xif((cpalloc->noverts = cpyobj->size.noverts + 1)<=0) cpalloc->noverts = 1; Xif((cpalloc->notverts = cpyobj->size.notverts + 1)<=0) cpalloc->notverts = 1; Xif((cpalloc->nomtls = cpyobj->size.nomtls + 1)<=0) cpalloc->nomtls = 1; Xif((cpalloc->nomaps = cpyobj->size.nomaps + 1)<=0) cpalloc->nomaps = 1; Xif((cpalloc->notraces = cpyobj->size.notraces + 1)<=0) cpalloc->notraces = 1; Xif((cpalloc->noshados = cpyobj->size.noshados + 1)<=0) cpalloc->noshados = 1; Xif((cpalloc->nocalls = cpyobj->size.nocalls + 1)<=0) cpalloc->nocalls = 1; Xif((cpalloc->nolibs = cpyobj->size.nolibs + 1)<=0) cpalloc->nolibs = 1; Xif((cpalloc->nogroups = cpyobj->size.nogroups + 1)<=0) cpalloc->nogroups = 1; Xcpalloc->nogverts = 1; Xcpalloc->noglines = 1; Xcpalloc->nogfaces = 1; Xcpalloc->nogsphrs = 1; Xcpalloc->nogcircs = 1; Xcpalloc->nogptchs = 1; Xcpalloc->nogpoints = 1; Xfor(gindx=0;gindxsize.nogroups;gindx++) { X if(cpyobj->group[gindx]->noverts > cpalloc->nogverts) { X cpalloc->nogverts = cpyobj->group[gindx]->noverts + 1; X } X if(cpyobj->group[gindx]->nolines > cpalloc->noglines) { X cpalloc->noglines = cpyobj->group[gindx]->nolines + 1; X } X if(cpyobj->group[gindx]->nofaces > cpalloc->nogfaces) { X cpalloc->nogfaces = cpyobj->group[gindx]->nofaces + 1; X } X if(cpyobj->group[gindx]->nosphrs > cpalloc->nogsphrs) { X cpalloc->nogsphrs = cpyobj->group[gindx]->nosphrs + 1; X } X if(cpyobj->group[gindx]->nocircs > cpalloc->nogcircs) { X cpalloc->nogcircs = cpyobj->group[gindx]->nocircs + 1; X } X if(cpyobj->group[gindx]->noptchs > cpalloc->nogptchs) { X cpalloc->nogptchs = cpyobj->group[gindx]->noptchs + 1; X } X if(cpyobj->group[gindx]->nopoints > cpalloc->nogpoints) { X cpalloc->nogpoints = cpyobj->group[gindx]->nopoints + 1; X } X } Xif((cpalloc->nolverts = cpyobj->size.nolverts + 1)<=0) cpalloc->nolverts = 1; Xif((cpalloc->nofverts = cpyobj->size.nofverts + 1)<=0) cpalloc->nofverts = 1; Xif((cpalloc->nopverts = cpyobj->size.nopverts + 1)<=0) cpalloc->nopverts = 1; Xif((cpalloc->valence = cpyobj->size.valence + 1)<=0) cpalloc->valence = 1; Xif((cpalloc->nolines = cpyobj->size.nolines + 1)<=0) cpalloc->nolines = 1; Xif((cpalloc->nofaces = cpyobj->size.nofaces + 1)<=0) cpalloc->nofaces = 1; Xif((cpalloc->nopoints = cpyobj->size.nopoints + 1)<=0) cpalloc->nopoints = 1; Xif((cpalloc->nocircs = cpyobj->size.nocircs + 1)<=0) cpalloc->nocircs = 1; Xif((cpalloc->nosphrs = cpyobj->size.nosphrs + 1)<=0) cpalloc->nosphrs = 1; Xif((cpalloc->noptchs = cpyobj->size.noptchs + 1)<=0) cpalloc->noptchs = 1; Xif((cpalloc->noedges = cpyobj->size.noedges + 1)<=0) cpalloc->noedges = 1; X Xreturn(cpalloc); X} X X X X X X X/* function: realc_obj() X X description: increases allocation for selected parts of an object X topology structure. X X author: Stewart Dickson X*/ X Xstruct topology *realc_obj(rlcobj,rlcalc) Xstruct topology *rlcobj; Xstruct sizes *rlcalc; X{ Xextern int verbflg; Xint libindx,calindx,mtlindx,mapindx,tracindx,shadindx; Xint gindx,vindx,tvindx,lindx,findx,eindx,pindx,cindx,sindx,bindx; Xunsigned objsize; X Xif(rlcobj==NULL) { X fprintf(stderr,"realc_obj: NULL pointer to structure 'rlcobj',"); X fprintf(stderr," no can do\n"); X exit(); X } X X/* struct sizes must have requested size parameters for object */ Xif(rlcalc==NULL) { /* if not, print error and return */ X fprintf(stderr, X "realc_obj: NULL pointer to structure 'alloc', no can do\n"); X exit(); X } X Xif(verbflg>0) { X fprintf(stderr,"entering realc_obj(%s)\n",rlcobj->size.objname); X } X Xif(rlcalc->notraces>rlcobj->alloc.notraces) { X if(verbflg>0) { X fprintf(stderr,"reallocating traced objects\n"); X } X if(rlcobj->trace_obj == NULL) { X fprintf(stderr, X "realc_obj: ERROR - NULL pointer 'trace_obj' cannot reallocate\n"); X exit(); X } X /* reallocate trace object pointers */ X objsize=rlcalc->notraces*sizeof(struct tracobj *); X if((rlcobj->trace_obj = X (struct tracobj **)realloc(rlcobj->trace_obj,objsize)) X == NULL) { X fprintf(stderr, X "realc_obj: can't reallocate"); X fprintf(stderr," 'rlcobj->trace_obj' size %u\n", X objsize); X exit(); X } X /* allocate new trace object structures */ X objsize=sizeof(struct tracobj *); X for(tracindx=rlcobj->alloc.notraces; X tracindxnotraces;tracindx++) { X if((rlcobj->trace_obj[tracindx] = X (struct tracobj *)malloc(objsize))==NULL) { X fprintf(stderr, "realc_obj: cannot allocate"); X fprintf(stderr, X " 'rlcobj->trace_obj[%d]' size %u\n", X tracindx,objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.notraces=rlcalc->notraces; X } X Xif(rlcalc->noshados>rlcobj->alloc.noshados) { X if(verbflg>0) { X fprintf(stderr,"reallocating shadowed objects\n"); X } X if(rlcobj->shad_obj == NULL) { X fprintf(stderr, X "realc_obj: ERROR - NULL pointer 'shad_obj' cannot reallocate\n"); X exit(); X } X /* reallocate space for 'shad_obj' structure pointers */ X objsize=rlcalc->noshados*sizeof(struct shadobj *); X if((rlcobj->shad_obj = X (struct shadobj **)realloc(rlcobj->shad_obj,objsize)) X ==NULL) { X fprintf(stderr, X "realc_obj: cannot reallocate 'rlcobj->shad_obj'"); X fprintf(stderr," size %u\n", objsize); X exit(); X } X /* allocate space for new 'shad_obj' structures */ X objsize=sizeof(struct shadobj); X for(shadindx=rlcobj->alloc.noshados; X shadindxnoshados;shadindx++) { X if((rlcobj->shad_obj[shadindx] = X (struct shadobj *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate "); X fprintf(stderr,"'rlcobj->shad_obj[%d]' size %u\n", X shadindx,objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.noshados=rlcalc->noshados; X } X Xif(rlcalc->nocalls>rlcobj->alloc.nocalls) { X if(verbflg>0) { X fprintf(stderr,"reallocating calls\n"); X } X if(rlcobj->call == NULL) { X fprintf(stderr, X "realc_obj: ERROR - NULL pointer 'call' cannot reallocate\n"); X exit(); X } X /* reallocate space for 'call' structure pointers */ X objsize=rlcalc->nocalls*sizeof(struct caldfile *); X if((rlcobj->call = (struct caldfile **) X realloc(rlcobj->call,objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot reallocate 'rlcobj->call' size %u\n", X objsize); X exit(); X } X /* allocate space for new 'call' structures */ X objsize=sizeof(struct caldfile); X for(calindx=rlcobj->alloc.nocalls; X calindxnocalls;calindx++) { X if((rlcobj->call[calindx] = X (struct caldfile *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate "); X fprintf(stderr,"'rlcobj->call[%d]' size %u\n", X calindx,objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nocalls=rlcalc->nocalls; X } X Xif(rlcalc->nolibs>rlcobj->alloc.nolibs) { X if(verbflg>0) { X fprintf(stderr,"reallocating libs\n"); X } X if(rlcobj->lib == NULL) { X fprintf(stderr, X "realc_obj: ERROR - NULL pointer 'lib' cannot reallocate\n"); X exit(); X } X /* reallocate space for 'lib' structure pointers */ X objsize=rlcalc->nolibs*sizeof(struct library *); X if((rlcobj->lib = (struct library **)realloc(rlcobj->lib,objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot reallocate 'rlcobj->lib' size %u\n", X objsize); X exit(); X } X /* allocate space for new 'lib' structures */ X objsize=sizeof(struct library); X for(libindx=rlcobj->alloc.nolibs; X libindxnolibs;libindx++) { X if((rlcobj->lib[libindx] = X (struct library *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate "); X fprintf(stderr,"'rlcobj->lib[%d]' size %u\n", X libindx,objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nolibs=rlcalc->nolibs; X } X Xif(rlcalc->nomtls>rlcobj->alloc.nomtls) { X if(verbflg>0) { X fprintf(stderr,"reallocating mtls\n"); X } X if(rlcobj->mtl == NULL) { X fprintf(stderr, X "realc_obj: ERROR - NULL pointer 'mtl' cannot reallocate\n"); X exit(); X } X /* reallocate space for 'mtl' structure pointers */ X objsize=rlcalc->nomtls*sizeof(struct material *); X if((rlcobj->mtl = (struct material **)realloc(rlcobj->mtl,objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot reallocate 'rlcobj->mtl' size %u\n", X objsize); X exit(); X } X /* allocate space for new 'mtl' structures */ X objsize=sizeof(struct material); X for(mtlindx=rlcobj->alloc.nomtls; X mtlindxnomtls;mtlindx++) { X if((rlcobj->mtl[mtlindx] = X (struct material *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate 'rlcobj->mtl[%d]'"); X fprintf(stderr," size %u\n", objsize); X exit(); X } X /* initialize material attributes to defaults */ X rlcobj->mtl[mtlindx]->Ka.red = 0.1; X rlcobj->mtl[mtlindx]->Ka.green = 0.1; X rlcobj->mtl[mtlindx]->Ka.blue = 0.1; X rlcobj->mtl[mtlindx]->Kd.red = 1.0; X rlcobj->mtl[mtlindx]->Kd.green = 1.0; X rlcobj->mtl[mtlindx]->Kd.blue = 1.0; X rlcobj->mtl[mtlindx]->Ks.red = 0.5; X rlcobj->mtl[mtlindx]->Ks.green = 0.5; X rlcobj->mtl[mtlindx]->Ks.blue = 0.5; X rlcobj->mtl[mtlindx]->Ni.red = 1.25; X rlcobj->mtl[mtlindx]->Ni.green = 1.375; X rlcobj->mtl[mtlindx]->Ni.blue = 1.5; X rlcobj->mtl[mtlindx]->Tf.red = 1.0; X rlcobj->mtl[mtlindx]->Tf.green = 1.0; X rlcobj->mtl[mtlindx]->Tf.blue = 1.0; X rlcobj->mtl[mtlindx]->Ns = 100; X rlcobj->mtl[mtlindx]->mass_dens = 1.0; X rlcobj->mtl[mtlindx]->surf_elast = 100; X rlcobj->mtl[mtlindx]->surf_stiff = 100; X } X /* reset allocation size in object struct */ X rlcobj->alloc.nomtls=rlcalc->nomtls; X } X Xif(rlcalc->nomaps>rlcobj->alloc.nomaps) { X if(verbflg>0) { X fprintf(stderr,"reallocating maps\n"); X } X if(rlcobj->map == NULL) { X fprintf(stderr, X "realc_obj: ERROR - NULL pointer 'map' cannot reallocate\n"); X exit(); X } X /* reallocate space for 'map' structure poointers */ X objsize=rlcalc->nomaps*sizeof(struct mapping *); X if((rlcobj->map = (struct mapping **)realloc(rlcobj->map,objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot reallocate 'rlcobj->map' size %u\n", X objsize); X exit(); X } X /* allocate space for new 'map' structures */ X objsize=sizeof(struct mapping); X for(mapindx=rlcobj->alloc.nomaps; X mapindxnomaps;mapindx++) { X if((rlcobj->map[mapindx] = X (struct mapping *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate "); X fprintf(stderr,"'rlcobj->map[%d]' size %u\n", X mapindx,objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nomaps=rlcalc->nomaps; X } X Xif(rlcalc->nogroups>rlcobj->alloc.nogroups) { X if(verbflg>0) { X fprintf(stderr,"reallocating groups\n"); X } X if(rlcobj->group == NULL) { X fprintf(stderr, X "realc_obj: ERROR - NULL pointer 'group' cannot reallocate\n"); X exit(); X } X /* reallocate space for 'group' structure pointers */ X objsize=rlcalc->nogroups*sizeof(struct objgrps *); X if((rlcobj->group = (struct objgrps **) X realloc(rlcobj->group,objsize))==NULL) { X fprintf(stderr,"realc_obj: cannot reallocate 'rlcobj->group'"); X fprintf(stderr," size %u\n", X objsize); X exit(); X } X if(verbflg>10) { X fprintf(stderr,"realc_obj: rlcobj->group = 0x%x",rlcobj->group); X fprintf(stderr," size %u\n", X objsize); X } X X /* allocate space for new 'group' structures and 'group->*' arrays */ X for(gindx=rlcobj->alloc.nogroups;gindxnogroups;gindx++) { X /* allocate space for new 'group' structures */ X objsize=sizeof(struct objgrps); X if((rlcobj->group[gindx] = X (struct objgrps *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate 'rlcobj->group"); X fprintf(stderr,"[%d]' size %u\n", X gindx,objsize); X exit(); X } X /* allocate integer arrays of previous size */ X objsize=rlcobj->alloc.nogverts*sizeof(int); X if((rlcobj->group[gindx]->vertno = X (int *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate 'rlcobj->group[%d]", X gindx); X fprintf(stderr,"->vertno' size %u\n", X objsize); X exit(); X } X objsize=rlcobj->alloc.nogpoints*sizeof(int); X if((rlcobj->group[gindx]->pointno = X (int *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate 'rlcobj->group[%d]", X gindx); X fprintf(stderr,"->pointno' size %u\n", X objsize); X exit(); X } X objsize=rlcobj->alloc.noglines*sizeof(int); X if((rlcobj->group[gindx]->lineno = X (int *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate 'rlcobj->group[%d]", X gindx); X fprintf(stderr,"->lineno' size %u\n", X objsize); X exit(); X } X objsize=rlcobj->alloc.nogfaces*sizeof(int); X if((rlcobj->group[gindx]->faceno = X (int *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate 'rlcobj->group[%d]", X gindx); X fprintf(stderr,"->faceno' size %u\n", X objsize); X exit(); X } X objsize=rlcobj->alloc.nogcircs*sizeof(int); X if((rlcobj->group[gindx]->circno = X (int *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate 'rlcobj->group[%d]", X gindx); X fprintf(stderr,"->circno' size %u\n", X objsize); X exit(); X } X objsize=rlcobj->alloc.nogsphrs*sizeof(int); X if((rlcobj->group[gindx]->sphrno = X (int *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate 'rlcobj->group[%d]", X gindx); X fprintf(stderr,"->sphrno' size %u\n", X objsize); X exit(); X } X objsize=rlcobj->alloc.nogptchs*sizeof(int); X if((rlcobj->group[gindx]->ptchno = X (int *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate 'rlcobj->group[%d]", X gindx); X fprintf(stderr,"->ptchno' size %u\n", X objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nogroups=rlcalc->nogroups; X } X Xif(rlcalc->nogverts>rlcobj->alloc.nogverts) { X /* reallocate space for 'group->vertno' arrays */ X objsize=rlcalc->nogverts*sizeof(int); X for(gindx=0;gindxalloc.nogroups;gindx++) { X if((rlcobj->group[gindx]->vertno = (int *) X realloc(rlcobj->group[gindx]->vertno, X objsize))==NULL) { X fprintf(stderr, X "realc_obj: can't reallocate 'rlcobj->group[%d]", X gindx); X fprintf(stderr,"->vertno' size %u\n", X objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nogverts=rlcalc->nogverts; X } X Xif(rlcalc->nogpoints>rlcobj->alloc.nogpoints) { X /* reallocate space for 'group->pointno' arrays */ X objsize=rlcalc->nogpoints*sizeof(int); X for(gindx=0;gindxalloc.nogroups;gindx++) { X if((rlcobj->group[gindx]->pointno = (int *) X realloc(rlcobj->group[gindx]->pointno, X objsize))==NULL) { X fprintf(stderr, X "realc_obj: can't reallocate 'rlcobj->group[%d]", X gindx); X fprintf(stderr,"->pointno' size %u\n", X objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nogpoints=rlcalc->nogpoints; X } X Xif(rlcalc->noglines>rlcobj->alloc.noglines) { X /* reallocate space for 'group->lineno' arrays */ X objsize=rlcalc->noglines*sizeof(int); X for(gindx=0;gindxalloc.nogroups;gindx++) { X if((rlcobj->group[gindx]->lineno = (int *) X realloc(rlcobj->group[gindx]->lineno, X objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot reallocate 'rlcobj->group[%d]", X gindx); X fprintf(stderr,"->lineno' size %u\n", X objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.noglines=rlcalc->noglines; X } X Xif(rlcalc->nogfaces>rlcobj->alloc.nogfaces) { X /* reallocate space for 'group->faceno' arrays */ X if(verbflg>0) { X fprintf(stderr, X "reallocating space for 'group->faceno' arrays"); X fprintf(stderr, X " from %d to %d\n", X rlcobj->alloc.nogfaces*sizeof(int), X rlcalc->nogfaces*sizeof(int)); X } X objsize=rlcalc->nogfaces*sizeof(int); X for(gindx=0;gindxalloc.nogroups;gindx++) { X if(verbflg>0) { X fprintf(stderr, X "rlcobj->group[%d]->faceno = 0x%x ->", X gindx,rlcobj->group[gindx]->faceno); X } X if((rlcobj->group[gindx]->faceno= X (int *)realloc(rlcobj->group[gindx]->faceno, X objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot reallocate 'rlcobj->group[%d]", X gindx); X fprintf(stderr,"->faceno' size %u\n", X objsize); X exit(); X } X if(verbflg>0) { X fprintf(stderr, X " 0x%x\n", X rlcobj->group[gindx]->faceno); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nogfaces=rlcalc->nogfaces; X if(verbflg>0) { X fprintf(stderr,"faces done\n"); X } X } X Xif(rlcalc->nogcircs>rlcobj->alloc.nogcircs) { X /* reallocate space for 'group->circno' arrays */ X objsize=rlcalc->nogcircs*sizeof(int); X for(gindx=0;gindxalloc.nogroups;gindx++) { X if((rlcobj->group[gindx]->circno = (int *) X realloc(rlcobj->group[gindx]->circno, X objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot reallocate 'rlcobj->group[%d]", X gindx); X fprintf(stderr,"->circno' size %u\n", X objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nogcircs=rlcalc->nogcircs; X } X Xif(rlcalc->nogsphrs>rlcobj->alloc.nogsphrs) { X /* reallocate space for 'group->sphrno' arrays */ X objsize=rlcalc->nogsphrs*sizeof(int); X for(gindx=0;gindxalloc.nogroups;gindx++) { X if((rlcobj->group[gindx]->sphrno = (int *) X realloc(rlcobj->group[gindx]->sphrno, X objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot reallocate 'rlcobj->group[%d]", X gindx); X fprintf(stderr,"->sphrno' size %u\n", X objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nogsphrs=rlcalc->nogsphrs; X } X Xif(rlcalc->nogptchs>rlcobj->alloc.nogptchs) { X /* reallocate space for 'group->ptchno' arrays */ X objsize=rlcalc->nogptchs*sizeof(int); X for(gindx=0;gindxalloc.nogroups;gindx++) { X if((rlcobj->group[gindx]->ptchno = (int *) X realloc(rlcobj->group[gindx]->ptchno, X objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot reallocate 'rlcobj->group[%d]", X gindx); X fprintf(stderr,"->ptchno' size %u\n", X objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nogptchs=rlcalc->nogptchs; X } X Xif(rlcalc->noverts>rlcobj->alloc.noverts) { X /* reallocate space for 'vertex' structures */ X objsize=rlcalc->noverts*sizeof(struct vertex *); X if(verbflg>0) { X fprintf(stderr, X "reallocating rlcobj->vertex = 0x%x to size %u\n", X rlcobj->vertex,objsize); X } X if(rlcobj->vertex == NULL) { /* NULL structure - must allocate */ X rlcobj = alloc_verts(rlcobj,rlcalc); X } X else { /* reallocate */ X if((rlcobj->vertex = X (struct vertex **)realloc(rlcobj->vertex,objsize)) == X NULL) { X fprintf(stderr, X "realc_obj: cannot reallocate 'rlcobj->vertex' size %u\n", X objsize); X exit(); X } X if(verbflg>0) { X fprintf(stderr,"OK\n"); X } X X /* allocate space for new 'vertex' structures, 'vertex->faceno' X and 'vertex->edgeno' arrays */ X for(vindx=rlcobj->alloc.noverts;vindxnoverts;vindx++) { X /* allocate space for more 'vertex' structures */ X objsize=sizeof(struct vertex); X if((rlcobj->vertex[vindx] = X (struct vertex *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate "); X fprintf(stderr,"'rlcobj->vertex[%d]' size %u\n", X vindx,objsize); X exit(); X } X objsize=rlcobj->alloc.valence*sizeof(int); X if(verbflg>10) { X fprintf(stderr, X "allocated rlcobj->vertex[%d] = 0x%x ", X vindx,rlcobj->vertex[vindx]); X fprintf(stderr,"size %u\n", X objsize); X } X if((rlcobj->vertex[vindx]->faceno = X (int *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_obj: cannot allocate"); X fprintf(stderr, X " 'rlcobj->vertex[%d]->faceno' size %u\n", X vindx,objsize); X exit(); X } X if((rlcobj->vertex[vindx]->edgeno = X (int *)malloc(objsize))==NULL) { X fprintf(stderr, X "alloc_obj: cannot allocate"); X fprintf(stderr, X " 'rlcobj->vertex[%d]->edgeno' size %u\n", X vindx,objsize); X exit(); X } X /* initialize new vertices to defaults */ X rlcobj->vertex[vindx]->facec = 0; X rlcobj->vertex[vindx]->edgec = 0; X rlcobj->vertex[vindx]->group = 0; X rlcobj->vertex[vindx]->mtl = 0; X } X /* reset allocation size in object struct */ X rlcobj->alloc.noverts = rlcalc->noverts; X } X } X Xif(rlcalc->valence>rlcobj->alloc.valence) { X if(verbflg>0) { X fprintf(stderr,"reallocating valences\n"); X } X /* reallocate space for 'vertex->faceno' and 'vertex->edgeno' arrays */ X for(vindx=0;vindxnoverts;vindx++) { X objsize=rlcalc->valence*sizeof(int); X if((rlcobj->vertex[vindx]->faceno = (int *) X realloc(rlcobj->vertex[vindx]->faceno,objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot reallocate"); X fprintf(stderr, X " 'rlcobj->vertex[%d]->faceno' size %u\n", X vindx,objsize); X exit(); X } X if((rlcobj->vertex[vindx]->edgeno = (int *) X realloc(rlcobj->vertex[vindx]->edgeno,objsize))==NULL) { X fprintf(stderr,"realc_obj: cannot reallocate"); X fprintf(stderr, X " 'rlcobj->vertex[%d]->edgeno' size %u\n", X vindx,objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.valence=rlcalc->valence; X } X Xif(rlcalc->nofaces>rlcobj->alloc.nofaces) { X /* reallocate space for 'face' structure pointers */ X objsize=rlcalc->nofaces*sizeof(struct faces *); X if(verbflg>0) { X fprintf(stderr, X "reallocating rlcobj->face = 0x%x to size %u\n", X rlcobj->face,objsize); X } X if(rlcobj->face == NULL) { /* NULL pointer - must allocate */ X rlcobj = alloc_faces(rlcobj,rlcalc); X } X else { /* reallocate */ X if((rlcobj->face = X (struct faces **)realloc(rlcobj->face,objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot reallocate 'rlcobj->face' size %u\n", X objsize); X exit(); X } X if(verbflg>0) { X fprintf(stderr,"OK\n"); X } X X /* allocate space for new 'face' structures, 'face->vertno', X 'face->tvertno' and 'face->edgeno' arrays */ X for(findx=rlcobj->alloc.nofaces;findxnofaces;findx++) { X objsize=sizeof(struct faces); X if((rlcobj->face[findx] = X (struct faces *)malloc(objsize))==NULL) { X fprintf(stderr, X "realc_obj: cannot allocate "); X fprintf(stderr,"'rlcobj->face[%d]' size %u\n", X findx,objsize); X exit(); X } X if(verbflg>20) { X fprintf(stderr, X "allocated rlcobj->face[%d] = 0x%x size %u\n", X findx,rlcobj->face[findx],objsize); X } X objsize=rlcobj->alloc.nofverts*sizeof(int); X rlcobj->face[findx]->vertno = (int *)malloc(objsize); X if(rlcobj->face[findx]->vertno == NULL) { X fprintf(stderr, X "realc_obj: cannot allocate"); X fprintf(stderr," 'rlcobj->face[%d]->vertno' size %u\n", X findx,objsize); X exit(); X } X rlcobj->face[findx]->tvertno = (int *)malloc(objsize); X if(rlcobj->face[findx]->tvertno == NULL) { X fprintf(stderr,"realc_obj: cannot allocate"); X fprintf(stderr," 'rlcobj->face[%d]->tvertno' size %u\n", X findx,objsize); X exit(); X } X rlcobj->face[findx]->edgeno = (int *)malloc(objsize); X if(rlcobj->face[findx]->edgeno == NULL) { X fprintf(stderr,"realc_obj: cannot allocate"); X fprintf(stderr," 'rlcobj->face[%d]->edgeno' size %u\n", X findx,objsize); X exit(); X } X /* initialize new faces to defaults */ X rlcobj->face[findx]->bevel = 0; X rlcobj->face[findx]->mapflg = NOMAP; X rlcobj->face[findx]->map = -1; X rlcobj->face[findx]->mtl = 0; X rlcobj->face[findx]->smooth = -1; X rlcobj->face[findx]->group = 0; X } X /* reset allocation size in object struct */ X rlcobj->alloc.nofaces=rlcalc->nofaces; X } X } X Xif(rlcalc->nofverts>rlcobj->alloc.nofverts) { X if(verbflg>0) { X fprintf(stderr,"reallocating face vertices\n"); X } X /* reallocate space for 'face->vertno', X 'face->tvertno' and 'face->edgeno' arrays */ X for(findx=0;findxnofaces;findx++) { X objsize=rlcalc->nofverts*sizeof(int); X if((rlcobj->face[findx]->vertno = (int *) X realloc(rlcobj->face[findx]->vertno,objsize))==NULL) { X fprintf(stderr,"realc_obj: cannot reallocate"); X fprintf(stderr," 'rlcobj->face[%d]->vertno' size %u\n", X findx,objsize); X exit(); X } X if((rlcobj->face[findx]->tvertno = (int *) X realloc(rlcobj->face[findx]->tvertno,objsize))==NULL) { X fprintf(stderr,"realc_obj: cannot reallocate"); X fprintf(stderr," 'rlcobj->face[%d]->tvertno' size %u\n", X findx,objsize); X exit(); X } X if((rlcobj->face[findx]->edgeno = (int *) X realloc(rlcobj->face[findx]->edgeno,objsize))==NULL) { X fprintf(stderr,"realc_obj: cannot reallocate"); X fprintf(stderr," 'rlcobj->face[%d]->edgeno' size %u\n", X findx,objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nofverts=rlcalc->nofverts; X } X Xif(rlcalc->notverts>rlcobj->alloc.notverts) { X /* reallocate space for 'texver' structure pointers */ X objsize=rlcalc->notverts*sizeof(struct textur *); X if(verbflg>0) { X fprintf(stderr,"reallocating rlcobj->texver = 0x%x to size %u\n", X rlcobj->texver,objsize); X } X if(rlcobj->texver == NULL) { /* NULL pointer - must allocate */ X rlcobj = alloc_tverts(rlcobj,rlcalc); X } X else { /* reallocate */ X if((rlcobj->texver = X (struct textur **)realloc(rlcobj->texver,objsize)) == X NULL) { X fprintf(stderr,"realc_obj: cannot reallocate"); X fprintf(stderr," 'rlcobj->texver' size %u\n",objsize); X exit(); X } X if(verbflg>0) { X fprintf(stderr,"OK\n"); X } X /* allocate space for new 'texver' structures */ X objsize=sizeof(struct textur); X for(tvindx=rlcobj->alloc.notverts; X tvindxnotverts;tvindx++) { X if(verbflg>10) { X fprintf(stderr, X "allocating rlcobj->texver[%d] = 0x%x size %u", X tvindx,rlcobj->texver[tvindx],objsize); X } X if((rlcobj->texver[tvindx] = X (struct textur *)malloc(objsize))==NULL) { X fprintf(stderr,"realc_obj: cannot allocate"); X fprintf(stderr," 'rlcobj->texver[%d]' size %u\n", X tvindx,objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.notverts=rlcalc->notverts; X } X } X Xif(rlcalc->nolines>rlcobj->alloc.nolines) { X /* reallocate space for 'line' structure pointers */ X objsize=rlcalc->nolines*sizeof(struct lines *); X if(verbflg>0) { X fprintf(stderr,"reallocating rlcobj->line = 0x%x to size %u\n", X rlcobj->line,objsize); X } X if(rlcobj->line == NULL) { /* NULL pointer - must allocate */ X rlcobj = alloc_lines(rlcobj,rlcalc); X } X else { /* reallocate */ X if((rlcobj->line = X (struct lines **)realloc(rlcobj->line,objsize)) == X NULL) { X fprintf(stderr,"realc_obj: cannot reallocate"); X fprintf(stderr," 'rlcobj->line' size %u\n",objsize); X exit(); X } X X /* allocate space for 'line' structures and 'line->vertno' arrays */ X for(lindx=rlcobj->alloc.nolines;lindxnolines;lindx++) { X objsize=sizeof(struct lines); X if(verbflg>10) { X fprintf(stderr, X "allocating rlcobj->line[%d] = 0x%x size %u\n", X lindx,rlcobj->line[lindx],objsize); X } X if((rlcobj->line[lindx] = X (struct lines *)malloc(objsize))==NULL) { X fprintf(stderr,"realc_obj: cannot allocate"); X fprintf(stderr," 'rlcobj->line[%d]' size %u\n", X lindx,objsize); X exit(); X } X objsize=rlcobj->alloc.nolverts*sizeof(int); X if((rlcobj->line[lindx]->vertno = X (int *)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_obj: cannot allocate"); X fprintf(stderr," 'rlcobj->line[%d]->vertno' size %u\n", X lindx,objsize); X exit(); X } X /* initialize new lines to defaults */ X rlcobj->line[lindx]->group = 0; X rlcobj->line[lindx]->mtl = 0; X } X /* reset allocation size in object struct */ X rlcobj->alloc.nolines=rlcalc->nolines; X } X } X Xif(rlcalc->nolverts>rlcobj->alloc.nolverts) { X objsize=rlcalc->nolverts*sizeof(int); X /* reallocate space for 'line->vertno' arrays */ X for(lindx=0;lindxnolines;lindx++) { X if(verbflg>0) { X fprintf(stderr, X "reallocating rlcobj->line[%d]->vertno = 0x%x to size %u\n", X lindx,rlcobj->line[lindx]->vertno,objsize); X } X if((rlcobj->line[lindx]->vertno= X (int *)realloc(rlcobj->line[lindx]->vertno,objsize)) == X NULL) { X fprintf(stderr,"realc_obj: cannot reallocate"); X fprintf(stderr," 'rlcobj->line[%d]->vertno' size %u\n", X lindx,objsize); X exit(); X } X if(verbflg>0) { X fprintf(stderr,"OK\n"); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nolverts=rlcalc->nolverts; X } X Xif(rlcalc->noedges>rlcobj->alloc.noedges) { X /* reallocate space for 'edge' structure pointers */ X objsize=rlcalc->noedges*sizeof(struct edges *); X if(verbflg>0) { X fprintf(stderr,"reallocating rlcobj->edge = 0x%x to size %u\n", X rlcobj->edge,objsize); X } X if(rlcobj->edge == NULL) { /* NULL pointer - must allocate */ X rlcobj = alloc_edges(rlcobj,rlcalc); X } X else { /* reallocate */ X if((rlcobj->edge = X (struct edges **)realloc(rlcobj->edge,objsize)) == X NULL) { X fprintf(stderr,"realc_obj: cannot reallocate"); X fprintf(stderr," 'rlcobj->edge' size %u\n",objsize); X exit(); X } X /* allocate space for new 'edge' structures */ X objsize=sizeof(struct edges); X for(eindx=rlcobj->alloc.noedges; X eindxnoedges;eindx++) { X if(verbflg>10) { X fprintf(stderr, X "allocating rlcobj->edge[%d] = 0x%x size %u\n", X eindx,rlcobj->edge[eindx],objsize); X } X if((rlcobj->edge[eindx] = X (struct edges *)malloc(objsize))==NULL) { X fprintf(stderr,"realc_obj: cannot allocate"); X fprintf(stderr," 'rlcobj->edge[%d]' size %u\n", X eindx,objsize); X exit(); X } X } X if(verbflg>0) { X fprintf(stderr,"OK\n"); X } X /* reset allocation size in object struct */ X rlcobj->alloc.noedges=rlcalc->noedges; X } X } X Xif(rlcalc->nopoints>rlcobj->alloc.nopoints) { X /* reallocate space for 'point' structure pointers */ X objsize=rlcalc->nopoints*sizeof(struct points *); X if(verbflg>0) { X fprintf(stderr,"reallocating rlcobj->point = 0x%x to size %u\n", X rlcobj->point,objsize); X } X if(rlcobj->point == NULL) { /* NULL pointer - must allocate */ X rlcobj = alloc_points(rlcobj,rlcalc); X } X else { /* reallocate */ X if((rlcobj->point = X (struct points **)realloc(rlcobj->point,objsize)) == X NULL) { X fprintf(stderr,"realc_obj: cannot reallocate"); X fprintf(stderr," 'rlcobj->point' size %u\n",objsize); X exit(); X } X X /* allocate space for 'point' structures and 'point->vertno' arrays */ X for(pindx=rlcobj->alloc.nopoints;pindxnopoints;pindx++) { X objsize=sizeof(struct points); X if(verbflg>10) { X fprintf(stderr, X "allocating rlcobj->point[%d] = 0x%x size %u\n", X pindx,rlcobj->point[pindx],objsize); X } X if((rlcobj->point[pindx] = X (struct points *)malloc(objsize))==NULL) { X fprintf(stderr,"realc_obj: cannot allocate"); X fprintf(stderr, X " 'rlcobj->point[%d]' size %u\n", X pindx,objsize); X exit(); X } X objsize=rlcobj->alloc.nopverts*sizeof(int); X if((rlcobj->point[pindx]->vertno = X (int *)malloc(objsize))==NULL) { X fprintf(stderr,"alloc_obj: cannot allocate"); X fprintf(stderr," 'rlcobj->point[%d]->vertno' size %u\n", X pindx,objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nopoints=rlcalc->nopoints; X } X } X Xif(rlcalc->nopverts>rlcobj->alloc.nopverts) { X if(verbflg>0) { X fprintf(stderr,"reallocating point vertices\n"); X } X /* reallocate space for 'point->vertno' arrays */ X objsize=rlcalc->nopverts*sizeof(int); X for(pindx=0;pindxnopoints;pindx++) { X if((rlcobj->point[pindx]->vertno= X (int *)realloc(rlcobj->point[pindx]->vertno,objsize)) X ==NULL) { X fprintf(stderr,"realc_obj: cannot reallocate"); X fprintf(stderr," 'rlcobj->point[%d]->vertno' size %u\n", X pindx,objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nopverts=rlcalc->nopverts; X } X Xif(rlcalc->nocircs>rlcobj->alloc.nocircs) { X /* reallocate space for 'circl' structure pointers */ X objsize=rlcalc->nocircs*sizeof(struct circles *); X if(verbflg>0) { X fprintf(stderr, X "reallocating rlcobj->circle = 0x%x to size %u\n", X rlcobj->circl,objsize); X } X if(rlcobj->circl == NULL) { /* NULL pointer - must allocate */ X rlcobj = alloc_circs(rlcobj,rlcalc); X } X else { /* reallocate */ X if((rlcobj->circl = X (struct circles **)realloc(rlcobj->circl,objsize)) == X NULL) { X fprintf(stderr,"realc_obj: cannot reallocate"); X fprintf(stderr," 'rlcobj->circl' size %u\n",objsize); X exit(); X } X /* allocate space for new 'circl' structures */ X objsize=sizeof(struct circles); X for(cindx=rlcobj->alloc.nocircs; X cindxnocircs;cindx++) { X if(verbflg>10) { X fprintf(stderr, X "allocating rlcobj->circle[%d] = 0x%x size %u\n", X cindx,rlcobj->circl[cindx],objsize); X } X if((rlcobj->circl[cindx] = X (struct circles *)malloc(objsize))==NULL) { X fprintf(stderr,"realc_obj: cannot allocate"); X fprintf(stderr, X " 'rlcobj->circl[%d]' size %u\n", X cindx,objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nocircs=rlcalc->nocircs; X } X } X Xif(rlcalc->nosphrs>rlcobj->alloc.nosphrs) { X /* reallocate space for 'spher' structure pointers */ X objsize=rlcalc->nosphrs*sizeof(struct spheres *); X if(verbflg>0) { X fprintf(stderr,"reallocating rlcobj->spher = 0x%x to size %u\n", X rlcobj->spher,objsize); X } X if(rlcobj->spher == NULL) { /* NULL pointer - must allocate */ X rlcobj = alloc_sphrs(rlcobj,rlcalc); X } X else { /* reallocate */ X if((rlcobj->spher = X (struct spheres **)realloc(rlcobj->spher,objsize)) == X NULL) { X fprintf(stderr,"realc_obj: cannot reallocate"); X fprintf(stderr," 'rlcobj->spher' size %u\n",objsize); X exit(); X } X /* allocate space for new 'spher' structures */ X objsize=sizeof(struct spheres); X for(sindx=rlcobj->alloc.nosphrs; X sindxnosphrs;sindx++) { X if(verbflg>10) { X fprintf(stderr, X "allocating rlcobj->spher[%d] = 0x%x size %u\n", X sindx,rlcobj->spher[sindx],objsize); X } X if((rlcobj->spher[sindx] = X (struct spheres *)malloc(objsize))==NULL) { X fprintf(stderr,"realc_obj: cannot allocate"); X fprintf(stderr, X " 'rlcobj->spher[%d]' size %u\n", X sindx,objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.nosphrs=rlcalc->nosphrs; X } X } X Xif(rlcalc->noptchs>rlcobj->alloc.noptchs) { X /* reallocate space for 'bicub' structure pointers */ X objsize=rlcalc->noptchs*sizeof(struct bicubes *); X if(verbflg>0) { X fprintf(stderr,"reallocating rlcobj->bicub = 0x%x to size %u\n", X rlcobj->bicub,objsize); X } X if(rlcobj->bicub == NULL) { /* NULL pointer - must allocate */ X rlcobj = alloc_ptchs(rlcobj,rlcalc); X } X else { /* reallocate */ X if((rlcobj->bicub = X (struct bicubes **)realloc(rlcobj->bicub,objsize)) == X NULL) { X fprintf(stderr,"realc_obj: cannot reallocate"); X fprintf(stderr," 'rlcobj->bicub' size %u\n",objsize); X exit(); X } X /* allocate space for new 'bicub' structures */ X objsize=sizeof(struct bicubes); X for(bindx=rlcobj->alloc.noptchs; X bindxnoptchs;bindx++) { X if(verbflg>10) { X fprintf(stderr, X "allocating rlcobj->bicub[%d] = 0x%x size %u\n", X bindx,rlcobj->bicub[bindx],objsize); X } X if((rlcobj->bicub[bindx] = X (struct bicubes *)malloc(objsize))==NULL) { X fprintf(stderr,"realc_obj: cannot allocate"); X fprintf(stderr, X " 'rlcobj->bicub[%d]' size %u\n", X bindx,objsize); X exit(); X } X } X /* reset allocation size in object struct */ X rlcobj->alloc.noptchs=rlcalc->noptchs; X } X } X Xif(verbflg>0) { X fprintf(stderr,"realc_obj: rlcobj = 0x%x, done\n",rlcobj); X } X Xreturn(rlcobj); X} X X X X X X X X X/* function: free_obj() X X description: frees allocation for an object topology structure. X X author: Stewart Dickson X*/ X Xvoid free_obj(freobj) Xstruct topology *freobj; X{ Xint tracindx,shadindx,calindx,libindx,mtlindx,mapindx,gindx; Xint vindx,tvindx,lindx,findx,pindx,eindx,cindx,sindx,bindx; Xint notraces,noshados,nocalls,nolibs,nomtls,nomaps,nogroups; Xint noverts,notverts,nolines,nofaces,nopoints,noedges,nocircs,nosphrs,noptchs; X Xnotraces=freobj->alloc.notraces; Xnoshados=freobj->alloc.noshados; Xnocalls=freobj->alloc.nocalls; Xnolibs=freobj->alloc.nolibs; Xnomtls=freobj->alloc.nomtls; Xnomaps=freobj->alloc.nomaps; Xnogroups=freobj->alloc.nogroups; Xnoverts=freobj->alloc.noverts; Xnotverts=freobj->alloc.notverts; Xnolines=freobj->alloc.nolines; Xnofaces=freobj->alloc.nofaces; Xnopoints=freobj->alloc.nopoints; Xnoedges=freobj->alloc.noedges; Xnocircs=freobj->alloc.nocircs; Xnosphrs=freobj->alloc.nosphrs; Xnoptchs=freobj->alloc.noptchs; X X/* free space for 'trace_obj' structures */ Xfor(tracindx=0;tracindxtrace_obj[tracindx]); X freobj->trace_obj[tracindx] = NULL; X } X X/* free space for 'trace_obj' structure pointers */ Xfree(freobj->trace_obj); Xfreobj->trace_obj = NULL; X X/* free space for 'shad_obj' structures */ Xfor(shadindx=0;shadindxshad_obj[shadindx]); X freobj->shad_obj[shadindx] = NULL; X } X X/* free space for 'shad_obj' structure pointers */ Xfree(freobj->shad_obj); Xfreobj->shad_obj = NULL; X X/* free space for 'call' structures */ Xfor(calindx=0;calindxcall[calindx]); X freobj->call[calindx] = NULL; X } X X/* free space for 'call' structure pointers */ Xfree(freobj->call); Xfreobj->call = NULL; X X/* free space for 'lib' structures */ Xfor(libindx=0;libindxlib[libindx]); X freobj->lib[libindx] = NULL; X } X X/* free space for 'lib' structure pointers */ Xfree(freobj->lib); Xfreobj->lib = NULL; X X/* free space for 'mtl' structures */ Xfor(mtlindx=0;mtlindxmtl[mtlindx]); X freobj->mtl[mtlindx] = NULL; X } X X/* free space for 'mtl' structure pointers */ Xfree(freobj->mtl); Xfreobj->mtl = NULL; X X/* free space for 'map' structures */ Xfor(mapindx=0;mapindxmap[mapindx]); X freobj->map[mapindx] = NULL; X } X X/* free space for 'map' structure pointers */ Xfree(freobj->map); Xfreobj->map =NULL; X X/* free space for 'group' structures */ Xfor(gindx=0;gindxgroup[gindx]->faceno); X freobj->group[gindx]->faceno = NULL; X free(freobj->group[gindx]->lineno); X freobj->group[gindx]->lineno = NULL; X free(freobj->group[gindx]->pointno); X freobj->group[gindx]->pointno = NULL; X free(freobj->group[gindx]->circno); X freobj->group[gindx]->circno = NULL; X free(freobj->group[gindx]->sphrno); X freobj->group[gindx]->sphrno = NULL; X free(freobj->group[gindx]->ptchno); X freobj->group[gindx]->ptchno = NULL; X free(freobj->group[gindx]); X freobj->group[gindx] = NULL; X } X X/* free space for 'group' structure pointers */ Xfree(freobj->group); Xfreobj->group = NULL; X X/* free space for 'vertex->faceno', 'vertex->edgeno' arrays X and 'vertex' structures */ Xfor(vindx=0;vindxvertex[vindx]->faceno != NULL) { X free(freobj->vertex[vindx]->faceno); X freobj->vertex[vindx]->faceno = NULL; X } X if(freobj->vertex[vindx]->edgeno != NULL) { X free(freobj->vertex[vindx]->edgeno); X freobj->vertex[vindx]->edgeno = NULL; X } X if(freobj->vertex[vindx] != NULL) { X free(freobj->vertex[vindx]); X freobj->vertex[vindx] = NULL; X } X } X X/* free space for 'vertex' structure pointers */ Xfree(freobj->vertex); Xfreobj->vertex = NULL; X X/* free space for 'face->vertno', 'face->tvertno', 'face->edgeno' arrays X and 'face' structures */ Xfor(findx=0;findxface[findx]->vertno != NULL) { X free(freobj->face[findx]->vertno); X freobj->face[findx]->vertno = NULL; X } X if(freobj->face[findx]->tvertno != NULL) { X free(freobj->face[findx]->tvertno); X freobj->face[findx]->tvertno = NULL; X } X if(freobj->face[findx]->edgeno != NULL) { X free(freobj->face[findx]->edgeno); X freobj->face[findx]->edgeno = NULL; X } X if(freobj->face[findx] != NULL) { X free(freobj->face[findx]); X freobj->face[findx] = NULL; X } X } X X/* free space for 'face' structure pointers */ Xif(freobj->face != NULL) { X free(freobj->face); X freobj->face = NULL; X } X X X/* free space for 'texver' structures */ Xfor(tvindx=0;tvindxtexver[tvindx] != NULL) { X free(freobj->texver[tvindx]); X freobj->texver[tvindx] = NULL; X } X } X X/* free space for 'texver' structure pointers */ Xif(freobj->texver != NULL) { X free(freobj->texver); X freobj->texver = NULL; X } X X/* free space for 'line->vertno' arrays and 'line' structures */ Xfor(lindx=0;lindxline[lindx]->vertno != NULL) { X free(freobj->line[lindx]->vertno); X freobj->line[lindx]->vertno = NULL; X free(freobj->line[lindx]); X freobj->line[lindx] = NULL; X } X } X X/* free space for 'line' structure pointers */ Xif(freobj->line != NULL) { X free(freobj->line); X freobj->line = NULL; X } X X X/* free space for 'edge' structures */ Xfor(eindx=0;eindxedge[eindx] != NULL) { X free(freobj->edge[eindx]); X freobj->edge[eindx] = NULL; X } X } X X/* free space for 'edge' structure pointers */ Xif(freobj->edge != NULL) { X free(freobj->edge); X freobj->edge = NULL; X } X X/* free space for 'point->vertno' arrays and 'point' structures */ Xfor(pindx=0;pindxpoint[pindx]->vertno != NULL) { X free(freobj->point[pindx]->vertno); X freobj->point[pindx]->vertno = NULL; X } X if(freobj->point[pindx] != NULL) { X free(freobj->point[pindx]); X freobj->point[pindx] = NULL; X } X } X X/* free space for 'point' structure pointers */ Xif(freobj->point != NULL) { X free(freobj->point); X freobj->point = NULL; X } X X/* free space for 'circl' structures */ Xfor(cindx=0;cindxcircl[cindx] != NULL) { X free(freobj->circl[cindx]); X freobj->circl[cindx] = NULL; X } X } X X/* free space for 'circl' structure pointers */ Xif(freobj->circl != NULL) { X free(freobj->circl); X freobj->circl = NULL; X } X X/* free space for 'spher' structures */ Xfor(sindx=0;sindxspher[sindx] != NULL) { X free(freobj->spher[sindx]); X freobj->spher[sindx] = NULL; X } X } X X/* free space for 'spher' structure pointers */ Xif(freobj->spher != NULL) { X free(freobj->spher); X freobj->spher = NULL; X } X X/* free space for 'bicub' structures */ Xfor(bindx=0;bindxbicub[bindx] != NULL) { X free(freobj->bicub[bindx]); X freobj->bicub[bindx] = NULL; X } X } X X/* free space for 'bicub' structure pointers */ Xif(freobj->bicub != NULL) { X free(freobj->bicub); X freobj->bicub = NULL; X } X X/* free allocation for object struct */ Xif(freobj != NULL) { X free(freobj); X freobj = NULL; X } X X} !EOR! echo extracting src/obj_lib/app_obj.c echo mkdir ./src mkdir ./src echo mkdir ./src/obj_lib mkdir ./src/obj_lib sed 's/^X//' > src/obj_lib/app_obj.c << '!EOR!' X/* file: app_obj.c X X contents: X app_obj(), X add_group(), X add_lib(), X add_mtl(), X add_map(), X copy_obj() X X description: C functions to copy and append object descriptions to data X data structures in core. X X author: Stewart Dickson X*/ X X#include X#include X X/* X Xfunction: app_obj() X Xdescription: appends the object in the source data structure to the destination X data structure in core. X Xinputs: srcobj -- pointer to object structure to append to dstobj. X dstobj -- pointer to object structure to receive appended object. X appgrp -- index of group to receive appended object. X metaflg - designation of type of information to copy, X recognized types are: X 'e' - copy simple elements only X 'm' - copy meta elements and simple elements X Xreturns: dstobj X X*/ X X X X Xstruct topology *app_obj(dstobj,srcobj,appgrp,metaflg) Xstruct topology *dstobj; Xstruct topology *srcobj; Xchar appgrp,metaflg; X{ X/* external data declaration */ Xextern int verbflg; X/* internal data declaration */ Xstruct sizes *apalloc=NULL,*copy_alc(); Xstruct topology *alloc_obj(),*realc_obj(); Xint lcount,lvcnt; Xint fcount,fvcnt; Xint circnt,sphcnt,bicuct; Xint row,col; Xint tvcount,vcount,pcount,pvcnt; Xint sindx; Xint mtlindx=0,mtlptr[200],add_mtl(); Xint mapindx=0,mapptr[200],add_map(); Xint gindx=0,grpptr[200], add_group(); Xint libindx=0, add_lib(); Xint calindx=0,calcount; Xint vindx,tvindx; X Xint ovoffset; Xint otvofset; Xint ovindx; Xint otvindx; Xint olindx; Xint ofindx; Xint opindx; Xint ocalindx; Xint ocindx; Xint ospndx; Xint obpndx; Xint gfindx,gpindx,glindx,gcindx,gsindx,gbindx; X Xif(srcobj==NULL) { /* if we have been given a NULL pointer */ X fprintf(stderr, X "app_obj: ERROR - received NULL source struct pointer\n"); X exit(-1); X } X Xif(dstobj==NULL) { /* if we have been given a NULL pointer */ X /* allocate dstobj */ X dstobj=alloc_obj(NULL); X } X X/* allocate storage for object size parameter struct */ Xapalloc=copy_alc(dstobj,apalloc); X Xif(verbflg>1) { X fprintf(stderr,"app_obj: copying object '%s' to '%s'", X srcobj->size.objname,dstobj->size.objname); X if(appgrp > -1) { X fprintf(stderr, X " group '%s'(%d)\n",dstobj->group[appgrp]->grpnam,appgrp); X } X else { X fprintf(stderr," group 'append ...'(%d)\n", appgrp); X } X } X X/* initialize vertex, element indices to sizes in destination object */ Xovoffset=dstobj->size.noverts-1; Xotvofset=dstobj->size.notverts-1; Xovindx=dstobj->size.noverts; Xotvindx=dstobj->size.notverts; Xolindx=dstobj->size.nolines; Xofindx=dstobj->size.nofaces; Xopindx=dstobj->size.nopoints; Xocalindx=dstobj->size.nocalls; Xocindx=dstobj->size.nocircs; Xospndx=dstobj->size.nosphrs; Xobpndx=dstobj->size.noptchs; X X/* check allocation of destination object and reallocate if necessary */ Xif(ovindx+srcobj->size.noverts > apalloc->noverts) { X apalloc->noverts = ovindx+srcobj->size.noverts; X } Xif(otvindx+srcobj->size.notverts > apalloc->notverts) { X apalloc->notverts = otvindx+srcobj->size.notverts; X } Xif(olindx+srcobj->size.nolines > apalloc->nolines) { X apalloc->nolines = olindx+srcobj->size.nolines; X } Xif(srcobj->alloc.nolverts > apalloc->nolverts) { X apalloc->nolverts = srcobj->alloc.nolverts; X } Xif(ofindx+srcobj->size.nofaces > apalloc->nofaces) { X apalloc->nofaces = ofindx + srcobj->size.nofaces; X } Xif(opindx+srcobj->size.nopoints > apalloc->nopoints) { X apalloc->nopoints = opindx + srcobj->size.nopoints; X } Xif(srcobj->alloc.nopverts > apalloc->nopverts) { X apalloc->nopverts = srcobj->alloc.nopverts; X } Xif(ocindx+srcobj->size.nocircs > apalloc->nocircs) { X apalloc->nocircs = ocindx + srcobj->size.nocircs; X } Xif(ospndx+srcobj->size.nosphrs > apalloc->nosphrs) { X apalloc->nosphrs = ospndx + srcobj->size.nosphrs; X } Xif(obpndx + srcobj->size.noptchs > apalloc->noptchs) { X apalloc->noptchs = obpndx + srcobj->size.noptchs; X } X/* reallocate if necessary */ Xdstobj = realc_obj(dstobj,apalloc); X X/* copy 'call' directives */ X Xif(strcmp(srcobj->call[0]->filnam,"# no files called")!=0) { X X if(verbflg>4) { X fprintf(stderr,"app_obj: copying %d file calls\n", X srcobj->size.nocalls); X } X X for(calindx=0;calindxsize.nocalls;calindx++) { X for(calcount=0;calcountsize.nocalls;calcount++) { X /* determine if copied call is unique */ X if(strcmp(srcobj->call[calindx]->filnam, X dstobj->call[calcount]->filnam)==0) { X break; X } X } X if(strcmp(srcobj->call[calindx]->filnam, X dstobj->call[calcount]->filnam)!=0) { X /* if it is unique */ X X if(verbflg>9) { X fprintf(stderr,"%s\n", X srcobj->call[calindx]->filnam); X } X X strcpy(dstobj->call[ocalindx]->filnam, X srcobj->call[calindx]->filnam); X if((++ocalindx)>=dstobj->alloc.nocalls) { X fprintf(stderr, X "app_obj: too many file calls %d", X ocalindx); X fprintf(stderr, X " in object '%s' -- reallocating\n", X dstobj->size.objname); X /* double allocation for library calls */ X apalloc->nocalls=apalloc->nocalls*2; X dstobj=realc_obj(dstobj,apalloc); X } X } X } X } X X/* copy 'mtllib/maplib' directives */ X Xif(strcmp(srcobj->lib[0]->libnam,"# no libraries used")!=0) { X X if(verbflg>9) { X fprintf(stderr,"app_obj: copying %d library calls\n", X srcobj->size.nolibs); X } X X for(libindx=0;libindxsize.nolibs;libindx++) { X add_lib(dstobj,srcobj->lib[libindx]->libnam); X } X } X X/* copy materials */ X Xif(verbflg > 4) { X fprintf(stderr,"app_obj: copying %d materials\n", X srcobj->size.nomtls); X } X Xfor(mtlindx=0;mtlindxsize.nomtls;mtlindx++) { X mtlptr[mtlindx] = add_mtl(dstobj,srcobj->mtl[mtlindx]->mtlnam); X X if(verbflg>9) { X fprintf(stderr, X "app_obj: mtl '%s', mtlptr(%d)=%d\n", X srcobj->mtl[mtlindx]->mtlnam,mtlindx,mtlptr[mtlindx]); X } X } X X/* copy texture maps */ X Xif(verbflg > 4) { X fprintf(stderr,"app_obj: copying %d mappings\n", X srcobj->size.nomaps); X } X Xfor(mapindx=0;mapindxsize.nomaps;mapindx++) { X mapptr[mapindx] = add_map(dstobj,srcobj->map[mapindx]->mapnam); X X if(verbflg>9) { X fprintf(stderr, X "app_obj: map '%s', mapptr(%d)=%d\n", X srcobj->map[mapindx]->mapnam,mapindx,mapptr[mapindx]); X } X } X X/* copy groups */ X Xif(verbflg>4) { X fprintf(stderr,"app_obj: copying %d groups\n", X srcobj->size.nogroups); X } X Xfor(gindx = 0; gindx < srcobj->size.nogroups; gindx++) { X /* if not, set a pointer to old group */ X grpptr[gindx] = add_group(dstobj,srcobj->group[gindx]->grpnam); X X if(verbflg>9) { X fprintf(stderr, X "app_obj: group '%s', grpptr(%d)=%d\n", X srcobj->group[gindx]->grpnam,gindx,grpptr[gindx]); X } X } X X/* copy vertices */ X Xif(verbflg>4) { X fprintf(stderr,"app_obj: copy %d vertices\n",srcobj->size.noverts); X } X Xfor(vcount=1;vcountsize.noverts;vcount++) { X if(verbflg>9) { X fprintf(stderr,"app_obj: vcount=%d, ovindx=%d\n",vcount,ovindx); X } X mtlindx=srcobj->vertex[vcount]->mtl; X if(verbflg>9) { X fprintf(stderr,"app_obj: copied mtlptr[%d]=%d\n", X mtlindx,(int)mtlptr[mtlindx]); X } X dstobj->vertex[ovindx]->mtl=mtlptr[mtlindx]; X dstobj->vertex[ovindx]->x=srcobj->vertex[vcount]->x; X dstobj->vertex[ovindx]->y=srcobj->vertex[vcount]->y; X dstobj->vertex[ovindx]->z=srcobj->vertex[vcount]->z; X if((++ovindx)>=dstobj->alloc.noverts) { X fprintf(stderr, X "app_obj: too many vertices %d in object '%s'", X ovindx,dstobj->size.objname); X fprintf(stderr," -- reallocating\n"); X /* double allocation for vertices */ X apalloc->noverts=apalloc->noverts*2; X dstobj=realc_obj(dstobj,apalloc); X } X } X X/* copy texture vertices */ X Xif(verbflg>4) { X fprintf(stderr,"app_obj: copy %d texture vertices\n", X srcobj->size.notverts); X } X Xfor(tvcount=1;tvcountsize.notverts;tvcount++) { X if(verbflg>9) { X fprintf(stderr,"app_obj: otvindx=%d\n",otvindx); X } X dstobj->texver[otvindx]->u=srcobj->texver[tvcount]->u; X dstobj->texver[otvindx]->v=srcobj->texver[tvcount]->v; X dstobj->texver[otvindx]->w=srcobj->texver[tvcount]->w; X if((++otvindx)>=dstobj->alloc.notverts) { X fprintf(stderr, X "app_obj: too many texture vertices %d in object '%s'", X otvindx,dstobj->size.objname); X fprintf(stderr," -- reallocating\n"); X /* double allocation for texture vertices */ X apalloc->notverts=apalloc->notverts*2; X dstobj=realc_obj(dstobj,apalloc); X } X } X X/* copy lines */ X Xif(verbflg>4) { X fprintf(stderr,"app_obj: copying %d lines\n",srcobj->size.nolines); X } X Xfor(lcount=0;lcountsize.nolines;lcount++) { X if(verbflg>10) { X fprintf(stderr,"app_obj: line %d: %d vertices\n",lcount, X srcobj->line[lcount]->vertc); X } X for(lvcnt=0;lvcntline[lcount]->vertc;lvcnt++) { X vindx=srcobj->line[lcount]->vertno[lvcnt]; X dstobj->line[olindx]->vertno[lvcnt]=vindx+ovoffset; X } X dstobj->line[olindx]->vertc=srcobj->line[lcount]->vertc; X if(lvcnt > dstobj->size.nolverts) { X dstobj->size.nolverts = lvcnt + 1; X } X /* copy material pointers */ X mtlindx=srcobj->line[lcount]->mtl; X if(verbflg>10) { X fprintf(stderr, X "app_obj: old mtl = %d, mtlptr[%d] = %d\n", X mtlindx,mtlindx,mtlptr[mtlindx]); X } X dstobj->line[olindx]->mtl=mtlptr[mtlindx]; X /* copy and re-index group pointers */ X if(appgrp > -1) { X gindx=appgrp; X glindx=dstobj->group[appgrp]->nolines; X } X else { X gindx=srcobj->line[lcount]->group; X if(verbflg>10) { X fprintf(stderr, X "app_obj: old group = %d, grpptr[%d] = %d\n", X gindx,gindx,grpptr[mtlindx]); X } X gindx=grpptr[gindx]; X glindx=dstobj->group[gindx]->nolines; X } X if(verbflg>10) { X fprintf(stderr,"app_obj: group %d, glindx = %d\n",gindx,glindx); X } X dstobj->line[olindx]->group=gindx; X dstobj->group[gindx]->lineno[glindx]=olindx; X if((++glindx)>=dstobj->alloc.noglines) { X fprintf(stderr, X "app_obj: too many lines %d, group '%s', object '%s'", X olindx,dstobj->group[gindx]->grpnam, X dstobj->size.objname); X fprintf(stderr," -- reallocating\n"); X /* double allocation for group lines */ X apalloc->noglines=apalloc->noglines*2; X dstobj=realc_obj(dstobj,apalloc); X } X dstobj->group[gindx]->nolines=glindx; X if((++olindx)>=dstobj->alloc.nolines) { X fprintf(stderr, X "app_obj: too many lines %d in object '%s'", X olindx,dstobj->size.objname); X fprintf(stderr," -- reallocating\n"); X /* double allocation for lines */ X apalloc->nolines=apalloc->nolines*2; X dstobj=realc_obj(dstobj,apalloc); X } X } X X X X X/* copy points */ X Xif(verbflg>4) { X fprintf(stderr,"app_obj: copying %d points\n",srcobj->size.nopoints); X } X Xfor(pcount=0;pcountsize.nopoints;pcount++) { X for(pvcnt=0;pvcntpoint[pcount]->vertc;pvcnt++) { X vindx=srcobj->point[pcount]->vertno[pvcnt]; X dstobj->point[opindx]->vertno[pvcnt]=vindx+ovoffset; X } X dstobj->point[opindx]->vertc=srcobj->point[pcount]->vertc; X if(pvcnt > dstobj->size.nopverts) { X dstobj->size.nopverts = pvcnt + 1; X } X /* copy group pointers */ X if(appgrp > -1) { X gindx=appgrp; X gpindx=dstobj->group[appgrp]->nopoints; X } X else { X gindx=srcobj->point[pcount]->group; X gindx=grpptr[gindx]; X gpindx=dstobj->group[gindx]->nopoints; X } X dstobj->point[opindx]->group=gindx; X dstobj->group[gindx]->pointno[gpindx]=opindx; X if((++gpindx)>=dstobj->alloc.nogpoints) { X fprintf(stderr, X "app_obj: too many points %d, group '%s', object '%s'", X opindx,dstobj->group[gindx]->grpnam, X dstobj->size.objname); X fprintf(stderr," -- reallocating\n"); X /* double allocation for group pointses */ X apalloc->nogpoints=apalloc->nogpoints*2; X dstobj=realc_obj(dstobj,apalloc); X } X dstobj->group[gindx]->nopoints=gpindx; X if((++opindx)>=dstobj->alloc.nopoints) { X fprintf(stderr, X "app_obj: too many pointses %d in object '%s'", X opindx,dstobj->size.objname); X fprintf(stderr," -- reallocating\n"); X /* double allocation for pointses */ X apalloc->nopoints=apalloc->nopoints*2; X dstobj=realc_obj(dstobj,apalloc); X } X } X X X/* copy faces */ X Xif(verbflg>9) { X fprintf(stderr,"app_obj: copy faces\n"); X } X Xfor(fcount=0;fcountsize.nofaces;fcount++) { X dstobj->face[ofindx]->smooth=srcobj->face[fcount]->smooth; X dstobj->face[ofindx]->bevel=srcobj->face[fcount]->bevel; X dstobj->face[ofindx]->mapflg=srcobj->face[fcount]->mapflg; X mapindx=srcobj->face[fcount]->map; X for(fvcnt=0;fvcntface[fcount]->vertc;fvcnt++) { X /* copy geometrical vertex pointers */ X vindx=srcobj->face[fcount]->vertno[fvcnt]; X dstobj->face[ofindx]->vertno[fvcnt]=vindx+ovoffset; X if(mapindx>(-1)) { X /* copy texture vertex pointers */ X tvindx=srcobj->face[fcount]->tvertno[fvcnt]; X dstobj->face[ofindx]->tvertno[fvcnt]=tvindx+otvofset; X } X } X dstobj->face[ofindx]->vertc=srcobj->face[fcount]->vertc; X if(fvcnt > dstobj->size.nofverts) { X dstobj->size.nofverts = fvcnt + 1; X } X /* copy material pointers */ X mtlindx=srcobj->face[fcount]->mtl; X dstobj->face[ofindx]->mtl=mtlptr[mtlindx]; X /* copy texture map pointers */ X if(mapindx>(-1)) { X dstobj->face[ofindx]->map=mapptr[mapindx]; X } X else { X dstobj->face[ofindx]->map=(-1); X } X /* copy group pointers */ X if(appgrp > -1) { X gindx=appgrp; X gfindx=dstobj->group[appgrp]->nofaces; X } X else { X gindx=srcobj->face[fcount]->group; X gindx=grpptr[gindx]; X gfindx=dstobj->group[gindx]->nofaces; X } X dstobj->face[ofindx]->group=gindx; X dstobj->group[gindx]->faceno[gfindx]=ofindx; X if((++gfindx)>=dstobj->alloc.nogfaces) { X fprintf(stderr, X "app_obj: too many faces %d, group '%s', object '%s'", X gfindx,dstobj->group[grpptr[gindx]]->grpnam, X dstobj->size.objname); X fprintf(stderr," -- reallocating\n"); X /* double allocation for group faces */ X apalloc->nogfaces=apalloc->nogfaces*2; X dstobj=realc_obj(dstobj,apalloc); X } X dstobj->group[gindx]->nofaces=gfindx; X if((++ofindx)>=dstobj->alloc.nofaces) { X fprintf(stderr, X "app_obj: too many faces %d, object '%s'", X ofindx, dstobj->size.objname); X fprintf(stderr," -- reallocating\n"); X /* double allocation for faces */ X apalloc->nofaces=apalloc->nofaces*2; X dstobj=realc_obj(dstobj,apalloc); X } X } X X/* copy bicubic patches */ Xfor(bicuct = 0; bicuct < srcobj->size.noptchs; bicuct++) { X X mapindx=srcobj->bicub[bicuct]->map; X /* copy vertex pointers */ X for(row = 0; row < 4; row++) { X for(col = 0; col < 4; col++) { X vindx = srcobj->bicub[bicuct]->vertno[row][col]; X dstobj->bicub[obpndx]->vertno[row][col] = vindx + ovoffset; X if(mapindx>(-1)) { X tvindx = srcobj->bicub[bicuct]->tvertno[row][col]; X dstobj->bicub[obpndx]->tvertno[row][col] = tvindx + otvofset; X } X } X } X /* copy element attributes */ X dstobj->bicub[obpndx]->type=srcobj->bicub[bicuct]->type; X dstobj->bicub[obpndx]->u_res=srcobj->bicub[bicuct]->u_res; X dstobj->bicub[obpndx]->v_res=srcobj->bicub[bicuct]->v_res; X dstobj->bicub[obpndx]->smooth=srcobj->bicub[bicuct]->smooth; X /* copy material pointers */ X mtlindx=srcobj->bicub[bicuct]->mtl; X dstobj->bicub[obpndx]->mtl=mtlptr[mtlindx]; X /* copy texture map pointers */ X if(mapindx>(-1)) { X dstobj->bicub[obpndx]->map=mapptr[mapindx]; X } X else { X dstobj->bicub[obpndx]->map=(-1); X } X /* copy group pointers */ X if(appgrp > -1) { X gindx=appgrp; X gbindx=dstobj->group[appgrp]->noptchs; X } X else { X gindx=srcobj->bicub[bicuct]->group; X gindx=grpptr[gindx]; X gbindx=dstobj->group[gindx]->noptchs; X } X dstobj->bicub[obpndx]->group=gindx; X dstobj->group[gindx]->ptchno[gbindx]=obpndx; X if((++gbindx) >= dstobj->alloc.nogptchs) { X fprintf(stderr, X "app_obj: too many patches %d, group '%s', object '%s'", X gbindx,dstobj->group[grpptr[gindx]]->grpnam, X dstobj->size.objname); X fprintf(stderr," -- reallocating\n"); X /* double allocation for group patches */ X apalloc->nogptchs = apalloc->nogptchs * 2; X dstobj=realc_obj(dstobj,apalloc); X } X dstobj->group[gindx]->noptchs=gbindx; X if(++obpndx >= dstobj->alloc.noptchs) { X fprintf(stderr, X "app_obj: too many bicubic patches %d", X obpndx); X fprintf(stderr," in object '%s' - reallocating\n", X dstobj->size.objname); X /* double allocation for bicubic patches */ X apalloc->noptchs = apalloc->noptchs * 2; X dstobj=realc_obj(dstobj,apalloc); X } X } X X/* if flag is set, copy meta elements */ Xif(metaflg=='m') { X /* copy circles */ X for(circnt=0;circntsize.nocircs;circnt++) { X vindx = srcobj->circl[circnt]->vertno; X dstobj->circl[ocindx]->vertno = vindx + ovoffset; X dstobj->circl[ocindx]->rad=srcobj->circl[circnt]->rad; X dstobj->circl[ocindx]->res=srcobj->circl[circnt]->res; X if(++ocindx>=dstobj->alloc.nocircs) { X fprintf(stderr, X "app_obj: too many circles %d in object '%s'", X ocindx,dstobj->size.objname); X fprintf(stderr," -- reallocating\n"); X /* double allocation for circles */ X apalloc->nocircs=apalloc->nocircs*2; X dstobj=realc_obj(dstobj,apalloc); X } X } X /* copy spheres */ X for(sphcnt=0;sphcntsize.nosphrs;sphcnt++) { X vindx = srcobj->spher[sphcnt]->vertno; X dstobj->spher[ospndx]->vertno = vindx + ovoffset; X dstobj->spher[ospndx]->rad=srcobj->spher[sphcnt]->rad; X dstobj->spher[ospndx]->res=srcobj->spher[sphcnt]->res; X dstobj->spher[ospndx]->smooth=srcobj->spher[sphcnt]->smooth; X /* copy material pointers */ X mtlindx=srcobj->spher[sphcnt]->mtl; X dstobj->spher[ospndx]->mtl=mtlptr[mtlindx]; X /* copy texture map pointers if defined */ X mapindx=srcobj->spher[sphcnt]->map; X if(mapindx>(-1)) { X dstobj->spher[ospndx]->map=mapptr[mapindx]; X } X else { X dstobj->spher[ospndx]->map=(-1); X } X if(++ospndx>=dstobj->alloc.nosphrs) { X fprintf(stderr, X "app_obj: too many spheres %d in object '%s'", X ospndx,dstobj->size.objname); X fprintf(stderr," -- reallocating\n"); X /* double allocation for spheres */ X apalloc->nosphrs=apalloc->nosphrs*2; X dstobj=realc_obj(dstobj,apalloc); X } X } X dstobj->size.nocircs=ocindx; X dstobj->size.nosphrs=ospndx; X } Xdstobj->size.noptchs=obpndx; Xdstobj->size.noverts=ovindx; Xdstobj->size.notverts=otvindx; Xdstobj->size.nosgrps=dstobj->size.nosgrps + srcobj->size.nosgrps; Xdstobj->size.nofaces=ofindx; Xdstobj->size.nopoints=opindx; Xdstobj->size.nolines=olindx; Xdstobj->size.nocalls=ocalindx; X X/* free memory allocated in this function */ Xfree(apalloc); Xapalloc = NULL; X Xif(verbflg>1) { X fprintf(stderr, X "app_obj: '%s', %d verts %d tverts %d lines %d faces %d patches\n", X dstobj->size.objname,ovindx,otvindx,olindx,ofindx,obpndx); X } X Xreturn(dstobj); X} X X X X X X X X X X/* function: add_group X X description: adds a group name to an object. Returns the index of the X group. If the group name already exists, the index of that X group is returned. X X author: Stewart Dickson X*/ X X Xint add_group(AG_dstobj,group_name) Xstruct topology *AG_dstobj; Xchar *group_name; X{ Xextern int verbflg; Xstruct topology *realc_obj(); Xstruct sizes *dstalloc; Xint gcount; Xdstalloc = NULL; X Xif(AG_dstobj == NULL) { X fprintf(stderr,"add_group: ERROR - NULL object pointer received\n"); X exit(-1); X } X Xif(group_name == NULL) { X fprintf(stderr,"add_group: ERROR - NULL group name string received\n"); X exit(-1); X } X Xif(verbflg > 1) { X fprintf(stderr,"entering add_group(%s,%s)\n", X AG_dstobj->size.objname,group_name); X } X Xfor(gcount = 0; gcount < AG_dstobj->size.nogroups; gcount++) { X /* determine if copied group is unique */ X if(!strcmp(group_name, AG_dstobj->group[gcount]->grpnam)) { X break; X } X } Xif(gcount >= AG_dstobj->size.nogroups) { X /* if it is unique */ X X if(verbflg>9) { X fprintf(stderr, X "add_group: adding group %d, '%s'\n", gcount, group_name); X } X X /* check allocation */ X if(gcount >= AG_dstobj->alloc.nogroups) { X /* allocate storage for object size parameter struct */ X dstalloc = copy_alc(AG_dstobj,dstalloc); X X fprintf(stderr, X "add_group: too many groups %d", gcount); X fprintf(stderr, X " in object '%s' -- reallocating\n", AG_dstobj->size.objname); X X /* double allocation for groups */ X dstalloc->nogroups = dstalloc->nogroups * 2; X AG_dstobj = realc_obj(AG_dstobj,dstalloc); X X /* free storage allocated in this module */ X free(dstalloc); X dstalloc = NULL; X } X /* add a new group name */ X strcpy(AG_dstobj->group[gcount]->grpnam, group_name); X AG_dstobj->size.nogroups = gcount + 1; X X } X X Xif(verbflg > 1) { X fprintf(stderr,"add_group: done\n"); X } X Xreturn(gcount); X} X X X X X X X X/* function: add_lib() X X description: Add a library name to the object. Returns the index to the X new library. If the library name already exists, that indes X is returned. X X author: Stewart Dickson X*/ X X Xint add_lib(AL_dstobj,lib_name) Xstruct topology *AL_dstobj; Xchar *lib_name; X{ Xextern int verbflg; Xstruct sizes *dstalloc = NULL, *copy_alc(); Xint libcount; X Xif(AL_dstobj == NULL) { X fprintf(stderr,"add_lib: ERROR - NULL object pointer received\n"); X exit(-1); X } X Xif(lib_name == NULL) { X fprintf(stderr,"add_lib: ERROR - NULL library name string received\n"); X exit(-1); X } X Xif(verbflg > 1) { X fprintf(stderr, X "entering add_lib(%s,%s)\n",AL_dstobj->size.objname,lib_name); X } X X/* there is always 1 library, if library 0 is set to a default */ Xif(!strcmp(AL_dstobj->lib[0]->libnam,"# no libraries used")) { X /* record new library name in dest object */ X strcpy(AL_dstobj->lib[0]->libnam,lib_name); X AL_dstobj->size.nolibs = 1; X return(0); X } X Xfor(libcount = 0; libcount < AL_dstobj->size.nolibs; libcount++) { X /* determine if copied library is unique */ X if(!strcmp(AL_dstobj->lib[libcount]->libnam,lib_name)) { X break; X } X } X Xif(libcount >= AL_dstobj->size.nolibs) { X /* if it is unique */ X X if(verbflg>9) { X fprintf(stderr, X "add_lib: adding library %d, '%s'\n", libcount, lib_name); X } X X /* check allocation and re-allocate if necessary */ X if(libcount >= AL_dstobj->alloc.nolibs) { X X /* allocate storage for object size parameter struct */ X dstalloc = copy_alc(AL_dstobj,dstalloc); X X fprintf(stderr, "add_lib: too many libraries %d", libcount); X fprintf(stderr, " in object '%s' -- reallocating\n", X AL_dstobj->size.objname); X X /* double allocation for libraries */ X dstalloc->nolibs = dstalloc->nolibs * 2; X AL_dstobj=realc_obj(AL_dstobj,dstalloc); X X /* free memory allocated in this module */ X free(dstalloc); X dstalloc = NULL; X } X /* record new library name in dest object */ X strcpy(AL_dstobj->lib[libcount]->libnam,lib_name); X AL_dstobj->size.nolibs = libcount + 1; X X } X Xif(verbflg > 1) { X fprintf(stderr,"add_lib: done\n"); X } X Xreturn(libcount); X} X X X X X X X X/* function: add_map X X description: Adds a texture map name to an object. Returns the index to X the new texture map. If the map name already exists, the X index to the existing map is returned. X X author: Stewart Dickson X*/ X Xint add_map(AM_dstobj,map_name) Xstruct topology *AM_dstobj; Xchar *map_name; X{ Xint mapcount; Xstruct sizes *dstalloc, *copy_alc(); X Xif(AM_dstobj == NULL) { X fprintf(stderr,"add_map: ERROR - NULL object pointer received\n"); X exit(-1); X } X Xif(map_name == NULL) { X fprintf(stderr,"add_map: ERROR - NULL texture map name string received\n"); X exit(-1); X } X Xif(verbflg > 1) { X fprintf(stderr, X "entering add_map(%s,%s)\n",AM_dstobj->size.objname,map_name); X } X X/* if map 0 is set to a default */ Xif(!strcmp(AM_dstobj->map[0]->mapnam,"# no mappings used")) { X strcpy(AM_dstobj->map[mapcount]->mapnam,map_name); X AM_dstobj->size.nomaps = 1; X return(0); X } X Xfor(mapcount=0; mapcount < AM_dstobj->size.nomaps; mapcount++) { X /* determine if copied mapping is unique */ X if(strcmp(AM_dstobj->map[mapcount]->mapnam,map_name)) { X break; X } X } X Xif(mapcount >= AM_dstobj->size.nomaps) { X /* if it is unique */ X X if(verbflg>9) { X fprintf(stderr,"add_map: adding texture map %d, %s\n",mapcount, X map_name); X } X X /* check allocation */ X if(mapcount >= AM_dstobj->alloc.nomaps) { X X /* allocate storage for object size parameter struct */ X dstalloc = copy_alc(AM_dstobj,dstalloc); X X fprintf(stderr, "add_map: too many mappings %d", mapcount); X fprintf(stderr, " in object '%s' -- reallocating\n", X AM_dstobj->size.objname); X X /* double allocation for texture names */ X dstalloc->nomaps = dstalloc->nomaps * 2; X AM_dstobj = realc_obj(AM_dstobj,dstalloc); X X /* free memory allocated in this module */ X free(dstalloc); X dstalloc = NULL; X } X X /* record new material in object */ X strcpy(AM_dstobj->map[mapcount]->mapnam,map_name); X AM_dstobj->size.nomaps = mapcount; X X } X Xif(verbflg > 1) { X fprintf(stderr,"add_map: done\n"); X } X Xreturn(mapcount); X} X X X X X X X X/* function: add_mtl X X description: Adds a material name to an object. Returns the index to X the new material. If the material name already exists, the X index to the existing material is returned. X X author: Stewart Dickson X*/ X Xint add_mtl(AM_dstobj,mtl_name) Xstruct topology *AM_dstobj; Xchar *mtl_name; X{ Xextern int verbflg; Xstruct sizes *dstalloc = NULL, *copy_alc(); Xint mtlcount; X Xif(AM_dstobj == NULL) { X fprintf(stderr,"add_mtl: ERROR - NULL object pointer received\n"); X exit(-1); X } X Xif(mtl_name == NULL) { X fprintf(stderr,"add_mtl: ERROR - NULL material name string received\n"); X exit(-1); X } X Xif(verbflg > 1) { X fprintf(stderr, X "entering add_mtl(%s,%s)\n",AM_dstobj->size.objname,mtl_name); X } X X/* there is always 1 material, if material 0 is set to a default */ Xif(!strcmp(AM_dstobj->mtl[0]->mtlnam,"# no materials used")) { X /* record new material name in dest object */ X strcpy(AM_dstobj->mtl[0]->mtlnam,mtl_name); X AM_dstobj->size.nomtls = 1; X return(0); X } X Xfor(mtlcount = 0; mtlcount < AM_dstobj->size.nomtls; mtlcount++) { X /* determine if copied material is unique */ X if(!strcmp(AM_dstobj->mtl[mtlcount]->mtlnam,mtl_name)) { X break; X } X } Xif(mtlcount >= AM_dstobj->size.nomtls) { X /* if it is unique */ X X if(verbflg>9) { X fprintf(stderr, X "add_mtl: adding material %d, '%s'\n",mtlcount, mtl_name); X } X X /* check allocation and re-allocate if necessary */ X if(mtlcount >= AM_dstobj->alloc.nomtls) { X /* allocate storage for object size parameter struct */ X dstalloc = copy_alc(AM_dstobj,dstalloc); X X fprintf(stderr, "add_mtl: too many materials %d", mtlcount); X fprintf(stderr, "in object '%s' -- reallocating\n", X AM_dstobj->size.objname); X X /* double allocation for materials */ X dstalloc->nomtls = dstalloc->nomtls * 2; X AM_dstobj = realc_obj(AM_dstobj,dstalloc); X X /* free memory allocated in this module */ X free(dstalloc); X dstalloc = NULL; X } X /* record new material name */ X strcpy(AM_dstobj->mtl[mtlcount]->mtlnam,mtl_name); X AM_dstobj->size.nomtls = mtlcount + 1; X X } X Xif(verbflg > 1) { X fprintf(stderr,"add_mtl: done\n"); X } X Xreturn(mtlcount); X} X X X X X X X X X/* function: copy_obj X X description: copies an object structure, destroying original contents X of destination structure. X X parameters: srcobj - object structure containing copy X elemflg - designation of type of information to copy X valid values are: X 'e' - copy simple elements only X 'm' - copy meta elements and simple elements X 'h' - copy material header information only X X return: dstobj - object structure to receive copy X X author: Stewart Dickson X*/ X X Xstruct topology *copy_obj(dstobj,srcobj,elemflg) Xstruct topology *dstobj, *srcobj; Xchar elemflg; X{ Xextern int verbflg; Xstruct topology *alloc_obj(),*realc_obj(); Xstruct sizes *CPalloc=NULL,*copy_alc(),*copy_siz(); Xint lcount=0,lvcnt=0; Xint fcount=0,fvcnt=0; Xint circnt=0,sphcnt=0,bicuct=0; Xint row,col; Xint tvcount=1,vcount=1,pcount=0,pvcnt=0; Xint sindx=(-1),mtlindx,mapindx,calindx,libindx,gindx,geindx; Xint vindx,tvindx; Xlcount=0;lvcnt=0; Xfcount=0;fvcnt=0; Xtvcount=1;vcount=1;pcount=0; X Xif(srcobj==NULL) { X fprintf(stderr,"copy_obj: ERROR - NULL source object received\n"); X exit(-1); X } X Xif(verbflg>1) { X fprintf(stderr,"entering copy_obj('%c')\n",elemflg); X } X Xif(dstobj==NULL) { X fprintf(stderr, X "copy_obj: NULL destination object received -- allocating\n"); X /* copy allocation parameters from source object */ X CPalloc=copy_alc(srcobj,CPalloc); X /* allocate an object of identical size to input object */ X dstobj=alloc_obj(CPalloc); X } Xelse { X /* copy size parameters from source object for internal use */ X if(elemflg == 'h') { /* only use header params form srcobj */ X CPalloc=copy_alc(dstobj,CPalloc); X /* copy header params if we're ony copying header */ X CPalloc->nocalls = srcobj->size.nocalls; X CPalloc->nolibs = srcobj->size.nolibs; X CPalloc->nomaps = srcobj->size.nomaps; X CPalloc->nomtls = srcobj->size.nomtls; X } X else { /* copy everything */ X CPalloc=copy_alc(srcobj,CPalloc); X } X /* reallocate to ensure we have at least the sizes of input object */ X dstobj=realc_obj(dstobj,CPalloc); X } X Xif(verbflg>0) { X fprintf(stderr,"copy_obj: copying object '%s' to '%s'\n", X srcobj->size.objname,dstobj->size.objname); X } X X/* copy 'call' directives */ Xfor(calindx=0;calindxsize.nocalls;calindx++) { X if(verbflg>9) { X fprintf(stderr,"%s\n",srcobj->call[calindx]->filnam); X } X strcpy(dstobj->call[calindx]->filnam,srcobj->call[calindx]->filnam); X } X X/* copy 'mtllib/maplib' directives */ Xfor(libindx=0;libindxsize.nolibs;libindx++) { X if(verbflg>9) { X fprintf(stderr,"%s\n",srcobj->lib[libindx]->libnam); X } X strcpy(dstobj->lib[libindx]->libnam,srcobj->lib[libindx]->libnam); X } X X/* copy materials */ Xif(verbflg>4) { X fprintf(stderr,"copy_obj: copying %d materials\n",srcobj->size.nomtls); X } Xfor(mtlindx=0;mtlindxsize.nomtls;mtlindx++) { X if(verbflg>9) { X fprintf(stderr,"%s\n",srcobj->mtl[mtlindx]->mtlnam); X } X strcpy(dstobj->mtl[mtlindx]->mtlnam,srcobj->mtl[mtlindx]->mtlnam); X } X X/* copy texture maps */ Xif(verbflg>4) { X fprintf(stderr,"copy_obj: copying %d texture maps\n", X srcobj->size.nomaps); X } X Xfor(mapindx=0;mapindxsize.nomaps;mapindx++) { X if(verbflg>9) { X fprintf(stderr,"%s\n",srcobj->map[mapindx]->mapnam); X } X strcpy(dstobj->map[mapindx]->mapnam,srcobj->map[mapindx]->mapnam); X } X X/* copy groups */ Xif(verbflg>4) { X fprintf(stderr,"copy_obj: copying %d groups\n", X srcobj->size.nogroups); X } Xfor(gindx=0;gindxsize.nogroups;gindx++) { X if(verbflg>9) { X fprintf(stderr,"copy_obj: %s ",srcobj->group[gindx]->grpnam); X } X /* copy group name */ X strcpy(dstobj->group[gindx]->grpnam,srcobj->group[gindx]->grpnam); X /* copy group vertices */ X for(geindx=0;geindxgroup[gindx]->noverts;geindx++) { X dstobj->group[gindx]->vertno[geindx] = X srcobj->group[gindx]->vertno[geindx]; X } X dstobj->group[gindx]->noverts = X srcobj->group[gindx]->noverts; X /* copy group elements */ X if(verbflg > 9) { X fprintf(stderr,"%d pointses ",srcobj->group[gindx]->nopoints); X } X for(geindx=0;geindxgroup[gindx]->nopoints;geindx++) { X dstobj->group[gindx]->pointno[geindx] = X srcobj->group[gindx]->pointno[geindx]; X } X dstobj->group[gindx]->nopoints = X srcobj->group[gindx]->nopoints; X if(verbflg > 9) { X fprintf(stderr,"%d lines ",srcobj->group[gindx]->nolines); X } X for(geindx=0;geindxgroup[gindx]->nolines;geindx++) { X dstobj->group[gindx]->lineno[geindx] = X srcobj->group[gindx]->lineno[geindx]; X } X dstobj->group[gindx]->nolines = X srcobj->group[gindx]->nolines; X if(verbflg > 9) { X fprintf(stderr,"%d faces ",srcobj->group[gindx]->nofaces); X } X for(geindx=0;geindxgroup[gindx]->nofaces;geindx++) { X dstobj->group[gindx]->faceno[geindx] = X srcobj->group[gindx]->faceno[geindx]; X } X dstobj->group[gindx]->nofaces = X srcobj->group[gindx]->nofaces; X if(verbflg > 9) { X fprintf(stderr,"%d circles ",srcobj->group[gindx]->nocircs); X } X for(geindx=0;geindxgroup[gindx]->nocircs;geindx++) { X dstobj->group[gindx]->circno[geindx] = X srcobj->group[gindx]->circno[geindx]; X } X dstobj->group[gindx]->nocircs = X srcobj->group[gindx]->nocircs; X if(verbflg > 9) { X fprintf(stderr,"%d spheres ",srcobj->group[gindx]->nosphrs); X } X for(geindx=0;geindxgroup[gindx]->nosphrs;geindx++) { X dstobj->group[gindx]->sphrno[geindx] = X srcobj->group[gindx]->sphrno[geindx]; X } X dstobj->group[gindx]->nosphrs = X srcobj->group[gindx]->nosphrs; X if(verbflg > 9) { X fprintf(stderr,"%d patches\n",srcobj->group[gindx]->noptchs); X } X for(geindx=0;geindxgroup[gindx]->noptchs;geindx++) { X dstobj->group[gindx]->ptchno[geindx] = X srcobj->group[gindx]->ptchno[geindx]; X } X dstobj->group[gindx]->noptchs = X srcobj->group[gindx]->noptchs; X } X Xif(elemflg=='e' || elemflg=='m') { X if(verbflg > 9) { X fprintf(stderr,"copy_obj: %d vertices ", X srcobj->size.noverts); X } X /* copy vertices */ X for(vcount=1;vcountsize.noverts;vcount++) { X dstobj->vertex[vcount]->mtl=srcobj->vertex[vcount]->mtl; X dstobj->vertex[vcount]->x=srcobj->vertex[vcount]->x; X dstobj->vertex[vcount]->y=srcobj->vertex[vcount]->y; X dstobj->vertex[vcount]->z=srcobj->vertex[vcount]->z; X } X X if(verbflg > 9) { X fprintf(stderr,"%d texture vertices ",srcobj->size.notverts); X } X /* copy texture vertices */ X for(tvcount=1;tvcountsize.notverts;tvcount++) { X dstobj->texver[tvcount]->u=srcobj->texver[tvcount]->u; X dstobj->texver[tvcount]->v=srcobj->texver[tvcount]->v; X dstobj->texver[tvcount]->w=srcobj->texver[tvcount]->w; X } X X if(verbflg > 9) { X fprintf(stderr,"%d lines ",srcobj->size.nolines); X } X /* copy lines */ X for(lcount=0;lcountsize.nolines;lcount++) { X for(lvcnt=0;lvcntline[lcount]->vertc;lvcnt++) { X vindx=srcobj->line[lcount]->vertno[lvcnt]; X dstobj->line[lcount]->vertno[lvcnt]=vindx; X } X if(lvcnt > dstobj->size.nolverts) { X dstobj->size.nolverts = lvcnt + 1; X } X dstobj->line[lcount]->vertc=srcobj->line[lcount]->vertc; X dstobj->line[lcount]->mtl=srcobj->line[lcount]->mtl; X dstobj->line[lcount]->group=srcobj->line[lcount]->group; X } X X if(verbflg > 9) { X fprintf(stderr,"%d pointses ",srcobj->size.nopoints); X } X /* copy points */ X for(pcount=0;pcountsize.nopoints;pcount++) { X for(pvcnt=0;pvcntpoint[pcount]->vertc;pvcnt++) { X vindx=srcobj->point[pcount]->vertno[pvcnt]; X dstobj->point[pcount]->vertno[pvcnt]=vindx; X } X if(pvcnt > dstobj->size.nopverts) { X dstobj->size.nopverts = pvcnt + 1; X } X dstobj->point[pcount]->vertc=srcobj->point[pcount]->vertc; X dstobj->point[pcount]->group=srcobj->point[pcount]->group; X } X X if(verbflg > 9) { X fprintf(stderr,"%d faces\n",srcobj->size.nofaces); X } X /* copy faces */ X for(fcount=0;fcountsize.nofaces;fcount++) { X dstobj->face[fcount]->smooth=srcobj->face[fcount]->smooth; X dstobj->face[fcount]->bevel=srcobj->face[fcount]->bevel; X dstobj->face[fcount]->mapflg=srcobj->face[fcount]->mapflg; X for(fvcnt=0;fvcntface[fcount]->vertc;fvcnt++) { X vindx=srcobj->face[fcount]->vertno[fvcnt]; X dstobj->face[fcount]->vertno[fvcnt]=vindx; X if(srcobj->face[fcount]->map>(-1)) { X tvindx=srcobj->face[fcount]->tvertno[fvcnt]; X dstobj->face[fcount]->vertno[fvcnt]=tvindx; X } X } X if(fvcnt > dstobj->size.nofverts) { X dstobj->size.nofverts = fvcnt + 1; X } X dstobj->face[fcount]->vertc=srcobj->face[fcount]->vertc; X dstobj->face[fcount]->mtl=srcobj->face[fcount]->mtl; X dstobj->face[fcount]->map=srcobj->face[fcount]->map; X dstobj->face[fcount]->group=srcobj->face[fcount]->group; X } X X if(verbflg > 9) { X fprintf(stderr,"%d patches\n",srcobj->size.noptchs); X } X /* copy bicubic patches */ X for(bicuct=0;bicuctsize.noptchs;bicuct++) { X for(row=0;row<4;row++) { X for(col=0;col<4;col++) { X dstobj->bicub[bicuct]->vertno[row][col] = X srcobj->bicub[bicuct]->vertno[row][col]; X dstobj->bicub[bicuct]->tvertno[row][col] = X srcobj->bicub[bicuct]->tvertno[row][col]; X } X } X dstobj->bicub[bicuct]->type=srcobj->bicub[bicuct]->type; X dstobj->bicub[bicuct]->v_res=srcobj->bicub[bicuct]->v_res; X dstobj->bicub[bicuct]->u_res=srcobj->bicub[bicuct]->u_res; X dstobj->bicub[bicuct]->mtl=srcobj->bicub[bicuct]->mtl; X dstobj->bicub[bicuct]->map=srcobj->bicub[bicuct]->map; X dstobj->bicub[bicuct]->smooth=srcobj->bicub[bicuct]->smooth; X dstobj->bicub[bicuct]->group=srcobj->bicub[bicuct]->group; X } X X dstobj->size.noverts=vcount; X dstobj->size.notverts=tvcount; X dstobj->size.nosgrps=srcobj->size.nosgrps; X dstobj->size.nofaces=fcount; X dstobj->size.nopoints=pcount; X dstobj->size.nolines=lcount; X dstobj->size.noptchs=bicuct; X } X X/* if flag is set, copy meta elements */ Xif(elemflg=='m') { X if(verbflg > 9) { X fprintf(stderr,"copy_obj: %d circles ", X srcobj->size.nocircs); X } X /* copy circles */ X for(circnt=0;circntsize.nocircs;circnt++) { X dstobj->circl[circnt]->vertno=srcobj->circl[circnt]->vertno; X dstobj->circl[circnt]->rad=srcobj->circl[circnt]->rad; X dstobj->circl[circnt]->res=srcobj->circl[circnt]->res; X dstobj->circl[circnt]->group=srcobj->circl[circnt]->group; X } X if(verbflg > 9) { X fprintf(stderr,"%d spheres ",srcobj->size.nosphrs); X } X /* copy spheres */ X for(sphcnt=0;sphcntsize.nosphrs;sphcnt++) { X dstobj->spher[sphcnt]->vertno=srcobj->spher[sphcnt]->vertno; X dstobj->spher[sphcnt]->rad=srcobj->spher[sphcnt]->rad; X dstobj->spher[sphcnt]->res=srcobj->spher[sphcnt]->res; X dstobj->spher[sphcnt]->mtl=srcobj->spher[sphcnt]->mtl; X dstobj->spher[sphcnt]->map=srcobj->spher[sphcnt]->map; X dstobj->spher[sphcnt]->smooth=srcobj->spher[sphcnt]->smooth; X dstobj->spher[sphcnt]->group=srcobj->spher[sphcnt]->group; X } X X dstobj->size.nocircs=circnt; X dstobj->size.nosphrs=sphcnt; X } Xdstobj->size.nomtls=mtlindx; Xdstobj->size.nomaps=mapindx; Xdstobj->size.nolibs=libindx; Xdstobj->size.nocalls=calindx; Xdstobj->size.nogroups=gindx; X X/* free memory allocated in this function */ Xfree(CPalloc); XCPalloc = NULL; X Xif(verbflg > 1) { X fprintf(stderr,"copy_obj: done\n"); X } X Xreturn(dstobj); X} !EOR! echo extracting src/obj_lib/rd_poly.c echo mkdir ./src mkdir ./src echo mkdir ./src/obj_lib mkdir ./src/obj_lib sed 's/^X//' > src/obj_lib/rd_poly.c << '!EOR!' X/* file: rd_poly.c X X description: Reads an ASCII geometrical object description of the type X used in Andrew Humes database of regular polyhedra. X See poly(5). X X author: Stewart Dickson X*/ X X#include X#include X X#define NUMBER 0 X#define NAME 1 X#define SYMBOL 2 X#define DUAL 3 X#define VERTICES 4 X#define SVERTICES 5 X#define NET 6 X#define SFACES 7 X#define HINGES 8 X#define SOLID 9 X#define DIHEDRAL 10 X#define END_OF_FILE 11 X#define NO_LABELS 12 X Xchar header[NO_LABELS][80] = { X "number", "name", "symbol", "dual", "vertices", "svertices", "net", X "sfaces", "hinges", "solid", "dihedral", "EOF" X }; X Xstruct topology *rd_poly(dst_obj, src_file) Xstruct topology *dst_obj; XFILE *src_file; X{ Xextern int verbflg; Xstruct sizes *alloc = NULL, *null_parms(); Xstruct topology *alloc_hdr(), *alloc_verts(), *alloc_faces(), *alloc_edges(); Xstruct topology *realc_obj(); Xint lchar, lcount, lindx, nolines; Xint add_group(), grp_index, net_group, solid_group; Xint tot_verts, net_verts, net_faces, solid_faces; Xint vindx, eindx, findx, fvindx, ofindx, noverts, nofverts, noedges; Xfloat vert_x, vert_y, vert_z, dihedral; Xchar key_word[128], line[128], new_string[128]; X Xif(verbflg > 0) { X fprintf(stderr,"entering rd_poly\n"); X } X X/* allocate local object parameter struct - set to all zeroes */ Xalloc = null_parms(alloc); Xalloc->nomtls = 1; Xalloc->nomaps = 1; Xalloc->nogroups = 3; X Xofindx = 0; Xlcount = 1; Xwhile(fscanf(src_file,":%s",key_word) != EOF) { X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X switch(parse(key_word)) { X case NUMBER: { /* plug into object name */ X fscanf(src_file,"%[^\n]",line); X sprintf(new_string,"Hume's number: %s, ",line); X if(strlen(alloc->objname) + strlen(new_string) < 128) { X strcat(alloc->objname,new_string); X } X if(verbflg > 0) { X fprintf(stderr, X "rd_poly: line %d, NUMBER '%s'\n",lcount,line); X } X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X break; X } X case NAME: { /* plug into object name */ X fscanf(src_file,"%[^\n]",line); X sprintf(new_string,"Polyhedron name: %s, ",line); X if(strlen(alloc->objname) + strlen(new_string) < 128) { X strcat(alloc->objname,new_string); X } X if(verbflg > 0) { X fprintf(stderr, X "rd_poly: line %d, NAME '%s'\n",lcount,line); X } X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X break; X } X case SYMBOL: { /* plug into object name */ X fscanf(src_file,"%[^\n]",line); X sprintf(new_string,"Symbol: %s, ",line); X if(strlen(alloc->objname) + strlen(new_string) < 128) { X strcat(alloc->objname,new_string); X } X if(verbflg > 0) { X fprintf(stderr, X "rd_poly: line %d, SYMBOL '%s'\n",lcount,line); X } X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X break; X } X case DUAL: { /* plug into object name */ X fscanf(src_file,"%[^\n]",line); X sprintf(new_string,"Dual: %s, ",line); X if(strlen(alloc->objname) + strlen(new_string) < 128) { X strcat(alloc->objname,new_string); X } X if(verbflg > 0) { X fprintf(stderr, X "rd_poly: line %d, DUAL '%s'\n",lcount, line); X } X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X break; X } X case VERTICES: { X /* first line following header is number of vertices */ X fscanf(src_file,"%d", &tot_verts); X /* there is an optional number of vertices X depicting the planar net */ X if((lchar = fgetc(src_file)) == ' ') { X fscanf(src_file,"%d", &net_verts); X } X else { /* newline */ X net_verts = 0; X ungetc(lchar,src_file); X } X if(tot_verts < 5) { /* bad # vertices */ X fprintf(stderr, X "rd_poly: line %d: bad number of vertices: %d\n", X lcount, tot_verts); X exit(-1); X } X if(verbflg > 1) { X fprintf(stderr, X "rd_poly: line %d, reading %d vertices\n", X lcount, tot_verts); X } X alloc->noverts = tot_verts + 1; X alloc->nogverts = alloc->noverts; X if(dst_obj == NULL) { /* We're going to allocate as we go */ X dst_obj = alloc_hdr(alloc); X } X else if(dst_obj->vertex == NULL) { /* allocate vertices */ X dst_obj = alloc_verts(dst_obj,alloc); X } X else { /* we already have an object and vertices, reallocate */ X dst_obj = realc_obj(dst_obj,alloc); X } X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X /* read vertices */ X for(vindx = 1; vindx < alloc->noverts; vindx++) { X if(verbflg > 1) { X fprintf(stderr, X "rd_poly: line %d, reading vertex %d\n", X lcount, vindx); X } X if(vindx <= net_verts) { X grp_index = add_group(dst_obj,"net"); X } X else { X grp_index = add_group(dst_obj,"solid"); X } X fscanf(src_file,"%f",&vert_x); X /* if next char is '[', expect expression form of vertex X coordinate */ X if((lchar = fgetc(src_file)) == '[') { X /* skip this for now */ X while((lchar = fgetc(src_file)) != ']'); X } X else if(lchar != ' ') { X ungetc(lchar,src_file); X } X /* assign value to vertex coordinate */ X dst_obj->vertex[vindx]->x = vert_x; X /* read next coordinate */ X fscanf(src_file,"%f",&vert_y); X /* if next char is '[', expect expression form of vertex X coordinate */ X if((lchar = fgetc(src_file)) == '[') { X /* skip this for now */ X while((lchar = fgetc(src_file)) != ']'); X } X else if(lchar != ' ') { X ungetc(lchar,src_file); X } X /* assign value to vertex coordinate */ X dst_obj->vertex[vindx]->y = vert_y; X /* read next coordinate */ X fscanf(src_file,"%f",&vert_z); X /* if next char is '[', expect expression form of vertex X coordinate */ X if((lchar = fgetc(src_file)) == '[') { X /* skip this for now */ X while((lchar = fgetc(src_file)) != ']'); X } X else if(lchar != ' ') { X ungetc(lchar,src_file); X } X /* assign value to vertex coordinate */ X dst_obj->vertex[vindx]->z = vert_z; X /* set material */ X dst_obj->vertex[vindx]->mtl = 0; X dst_obj->vertex[vindx]->group = grp_index; X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X } X /* set vertex population of object */ X dst_obj->size.noverts = alloc->noverts; X break; X } X case SVERTICES: { /* ??? */ X /* don't know what this is - throw away */ X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X /* read up to next newline */ X while((lchar = fgetc(src_file)) != '\n'); X ungetc(lchar,src_file); X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X break; X } X case NET: { /* planar net - stereographic projection */ X /* first line is number of faces and max. vertices in a face */ X if(fscanf(src_file,"%d ",&net_faces) < 1) { /* missing # faces */ X fprintf(stderr, "rd_poly: line %d: missing number of faces\n", X lcount); X exit(-1); X } X if(fscanf(src_file,"%d",&nofverts) < 1) { X /* missing # vertices/face */ X fprintf(stderr, X "rd_poly: line %d: missing number of vertices per face\n", X lcount); X exit(-1); X } X if(alloc->nofaces == 0) { /* no faces have been read */ X alloc->nofaces = net_faces; X alloc->nofverts = nofverts; X if(dst_obj == NULL) { /* We're going to allocate as we go */ X dst_obj = alloc_hdr(alloc); X } X if(dst_obj->face == NULL) { /* allocate faces */ X dst_obj = alloc_faces(dst_obj,alloc); X } X } X else { /* some faces have been read, reallocate */ X alloc->nofaces = alloc->nofaces + net_faces; X if(alloc->nofverts < nofverts) { X alloc->nofverts = nofverts; X } X dst_obj = realc_obj(dst_obj,alloc); X } X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X /* add an object element group 'net' */ X grp_index = add_group(dst_obj,"net"); X net_group = grp_index; X /* remaining lines consist of vertex count and vertex indices */ X for(findx = 0; findx < net_faces; findx++) { X if(verbflg > 1) { X fprintf(stderr, X "rd_poly: line %d, reading net face %d, abs. face %d\n", X lcount, findx, ofindx); X } X /* first field is number of vertices */ X if(fscanf(src_file,"%d",&noverts) < 1) { /* missing # verts */ X fprintf(stderr, X "rd_poly: line %d: polygon %d, missing # of verts\n", X lcount, findx); X exit(-1); X } X dst_obj->face[ofindx]->vertc = noverts; X dst_obj->face[ofindx]->mtl = 0; X dst_obj->face[ofindx]->map = -1; X dst_obj->face[ofindx]->mapflg = 0; X dst_obj->face[ofindx]->group = grp_index; X dst_obj->face[ofindx]->bevel = 0; X dst_obj->face[ofindx]->smooth = -1; X for(fvindx = 0; fvindx < noverts; fvindx++) { X /* remaining fields are vertex indices */ X if(fscanf(src_file, " %d", &vindx) < 1) { X fprintf(stderr, X "rd_poly: line %d: polygon %d, missing vertex %d\n", X lcount, ofindx, fvindx); X exit(-1); X } X dst_obj->face[ofindx]->vertno[fvindx] = vindx + 1; X } X ofindx++; X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X } X dst_obj->size.nofaces = alloc->nofaces; X dst_obj->size.nofverts = alloc->nofverts; X break; X } X case SFACES: { X /* know what this is, but don't know what to do with it - X throw away */ X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X /* read up to next newline */ X while((lchar = fgetc(src_file)) != '\n'); X ungetc(lchar,src_file); X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X break; X } X case HINGES: { X /* first line is number of edges */ X if(fscanf(src_file,"%d",&noedges) < 1) { /* missing # edges */ X fprintf(stderr, "rd_poly: line %d: missing number of edges\n", X lcount); X exit(-1); X } X alloc->noedges = noedges; X X if(dst_obj == NULL) { /* We're going to allocate as we go */ X dst_obj = alloc_hdr(alloc); X } X else if(dst_obj->edge == NULL) { /* allocate edges */ X dst_obj = alloc_edges(dst_obj,alloc); X } X else { /* reallocate */ X dst_obj = realc_obj(dst_obj,alloc); X } X X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X X /* remaining lines consist of face-edge pairs */ X for(eindx = 0; eindx < noedges; eindx++) { X if(verbflg > 1) { X fprintf(stderr,"rd_poly: line %d, reading edge %d\n", X lcount, eindx); X } X /* first field is face 0 */ X if(fscanf(src_file,"%d ",&findx) < 1) { /* missing face # */ X fprintf(stderr, X "rd_poly: line %d: edge %d, missing face #\n", X lcount, eindx); X exit(-1); X } X dst_obj->edge[eindx]->faceno[0] = findx; X X /* second field is side of face 0 */ X if(fscanf(src_file,"%d ",&fvindx) < 1) { X /* missing face side */ X fprintf(stderr, X "rd_poly: line %d: edge %d, missing face side #\n", X lcount, eindx); X exit(-1); X } X X /* assign vertices to edge from face vertex list */ X vindx = dst_obj->face[findx]->vertno[fvindx]; X dst_obj->edge[eindx]->vertno[0] = vindx; X vindx = dst_obj->face[findx]->vertno[fvindx + 1]; X dst_obj->edge[eindx]->vertno[1] = vindx; X X /* third field is face 1 */ X if(fscanf(src_file,"%d ",&findx) < 1) { /* missing face # */ X fprintf(stderr, X "rd_poly: line %d: edge %d, missing face #\n", X lcount, eindx); X exit(-1); X } X dst_obj->edge[eindx]->faceno[1] = findx; X X /* fourth field is side of face 1 */ X if(fscanf(src_file,"%d ",&fvindx) < 1) { /* missing face side */ X fprintf(stderr, X "rd_poly: line %d: edge %d, missing face side #\n", X lcount, eindx); X exit(-1); X } X X /* verify vertices from face vertex list with edge */ X vindx = dst_obj->face[findx]->vertno[fvindx]; X if(dst_obj->edge[eindx]->vertno[1] != vindx) { X /* flag inconsistencies */ X fprintf(stderr, X "rd_poly: WARNING: edge %d vertex mismatch\n",eindx); X fprintf(stderr, X "\tedge vertex %d, face vertex %d\n", X dst_obj->edge[eindx]->vertno[1], vindx); X } X vindx = dst_obj->face[findx]->vertno[fvindx + 1]; X if(dst_obj->edge[eindx]->vertno[0] != vindx) { X /* flag inconsistencies */ X fprintf(stderr, X "rd_poly: WARNING: edge %d vertex mismatch\n",eindx); X fprintf(stderr, X "\tedge vertex %d, face vertex %d\n", X dst_obj->edge[eindx]->vertno[0], vindx); X } X X /* fifth field is angle */ X fscanf(src_file,"%f",&dihedral); X /* if next char is '[', expect expression form of vertex X coordinate */ X if((lchar = fgetc(src_file)) == '[') { X /* skip this for now */ X while((lchar = fgetc(src_file)) != ']'); X } X else if(lchar != ' ') { X ungetc(lchar,src_file); X } X /* assign angle to object */ X dst_obj->edge[eindx]->theta = dihedral; X X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X } X dst_obj->size.noedges = alloc->noedges; X break; X } X case SOLID: { /* polyhedron */ X /* first line is number of faces and max. vertices in a face */ X if(fscanf(src_file,"%d ",&solid_faces) < 1) { /* missing # faces */ X fprintf(stderr, "rd_poly: line %d: missing number of faces\n", X lcount); X exit(-1); X } X if(fscanf(src_file,"%d",&nofverts) < 1) { X /* missing # vertices/face */ X fprintf(stderr, X "rd_poly: line %d: missing number of vertices per face\n", X lcount); X exit(-1); X } X if(alloc->nofaces == 0) { /* no faces have been read */ X alloc->nofaces = solid_faces; X alloc->nofverts = nofverts; X if(dst_obj == NULL) { /* We're going to allocate as we go */ X dst_obj = alloc_hdr(alloc); X } X if(dst_obj->face == NULL) { /* allocate faces */ X dst_obj = alloc_faces(dst_obj,alloc); X } X } X else { /* faces have been read - reallocate */ X alloc->nofaces = alloc->nofaces + solid_faces; X if(alloc->nofverts < nofverts) { X alloc->nofverts = nofverts; X } X dst_obj = realc_obj(dst_obj,alloc); X } X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X /* add an object element group 'net' */ X grp_index = add_group(dst_obj,"solid"); X solid_group = grp_index; X /* remaining lines consist of vertex count and vertex indices */ X for(findx = 0; findx < solid_faces; findx++) { X if(verbflg > 1) { X fprintf(stderr, X "rd_poly: line %d, reading solid face %d abs. face %d\n", X lcount, findx, ofindx); X } X /* first field is number of vertices */ X if(fscanf(src_file,"%d",&noverts) < 1) { /* missing # verts */ X fprintf(stderr, X "rd_poly: line %d: polygon %d, missing # of verts\n", X lcount, findx); X exit(-1); X } X dst_obj->face[ofindx]->vertc = noverts; X dst_obj->face[ofindx]->mtl = 0; X dst_obj->face[ofindx]->map = -1; X dst_obj->face[ofindx]->mapflg = 0; X dst_obj->face[ofindx]->group = grp_index; X dst_obj->face[ofindx]->bevel = 0; X dst_obj->face[ofindx]->smooth = -1; X for(fvindx = 0; fvindx < noverts; fvindx++) { X /* remaining fields are vertex indices */ X if(fscanf(src_file, " %d", &vindx) < 1) { X fprintf(stderr, X "rd_poly: line %d: polygon %d, missing vertex %d\n", X lcount, ofindx, fvindx); X exit(-1); X } X dst_obj->face[ofindx]->vertno[fvindx] = vindx + 1; X } X ofindx++; X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X } X dst_obj->size.nofaces = alloc->nofaces; X dst_obj->size.nofverts = alloc->nofverts; X break; X } X case DIHEDRAL: { X /* know what this is, but don't know what to do with it - X throw away */ X /* first line contains number of distinct dihedrals */ X fscanf(src_file,"%[^\n]",line); X lcount++; X if((nolines = atoi(line)) < 0) { /* bad # dihedrals */ X fprintf(stderr, X "rd_poly: line %d, bad number of dihedral angles '%s'\n", X lcount, line); X exit(-1); X } X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X /* remaining lines contain dihedral angles */ X for(lindx = 0; lindx < nolines; lindx++) { X /* read lines */ X fscanf(src_file,"%[^\n]",line); X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X } X break; X } X case END_OF_FILE: { X /* read newline(s) */ X while((lchar = fgetc(src_file)) == '\n') lcount++; X ungetc(lchar,src_file); X break; X } X X } X } X X/* free memory allocated in this module */ Xfree(alloc); X Xif(verbflg > 0) { X fprintf(stderr,"rd_poly: done\n"); X } X Xreturn(dst_obj); X X} X X X X X/* function: parse X X description: Returns the index to a #define'd label matching the input X string. X X author: Stewart Dickson X*/ X Xint parse(string) Xchar *string; X{ Xextern int verbflg; Xint index; X Xfor(index = 0; index < NO_LABELS; index++) { X if(!strncmp(string,header[index],3)) { X break; X } X } X Xif(verbflg > 1) { X fprintf(stderr,"parse: reading '%s'\n",header[index]); X } X X/* re-set string to a NULL */ Xstrcat(string,"\0"); X Xreturn(index); X} !EOR! echo extracting src/obj_lib/wt_obj.c echo mkdir ./src mkdir ./src echo mkdir ./src/obj_lib mkdir ./src/obj_lib sed 's/^X//' > src/obj_lib/wt_obj.c << '!EOR!' X/* X Xfunction: wt_obj() X Xdescription: writes a Wavefront ".obj" ASCII object description file from X a data structure in core. X Has been modified to include graphical 'meta-elements' circle, X sphere and user-defined object meta-elements. X Xinputs: outfildes -- file descriptor of file opened for writing. X wtobj -- pointer to structure containing object description. X Xreturns: none X Xauthor: Stewart Dickson X*/ X X#include X#include X#include X X X Xvoid wt_obj(outfildes,wtobj) XFILE *outfildes; Xstruct topology *wtobj; X{ Xextern int verbflg; X Xchar date[30]; Xint lcount=0; Xshort lvcnt=0; Xint fcount=0; Xshort fvcnt=0; Xint vcount=1,tvcount=1,pcount=0; Xshort pvcnt=0; Xint circnt=0,sphcnt=0,bicuct=0; Xshort libcnt,calcnt; Xint row,col,u_res = 4,v_res = 4; Xshort grpindx=0,bindx=0,sindx=(-1),mtlindx=(-1),mapindx=(-1); Xlong secs,time(); X Xif(outfildes==NULL) { X fprintf(stderr,"wt_obj: ERROR - NULL file pointer received\n"); X exit(); X } X Xif(wtobj==NULL) { X fprintf(stderr,"wt_obj: ERROR - NULL object pointer received\n"); X exit(); X } X Xfprintf(stderr,"wt_obj: writing object '%s'\n",wtobj->size.objname); X Xif(verbflg>1) { X fprintf(stderr,"wt_obj: writing identification message\n"); X } X X/* output object identification message */ X Xsecs=time((long *)0); Xstrcpy(date,asctime(localtime(&secs))); X Xfprintf(outfildes, X "\# %s %s\n",wtobj->size.objname,date); Xfprintf(outfildes, X "\# This is a Stewart Dickson object description file\n"); Xfprintf(outfildes, X "\# made from a Stewart Dickson object-generating program.\n"); Xfprintf(outfildes, X "\# It may contain 'meta-elements' which must be expanded\n"); Xfprintf(outfildes, X "\# to be compatible with Wavefront Technologies software.\n\#\n\#\n"); X X/* output "mtllib/maplib" directives */ X Xif(verbflg>1) { X fprintf(stderr,"wt_obj: writing %d 'mtllib/maplib' directives\n", X wtobj->size.nolibs); X } X Xfor(libcnt=0;libcntsize.nolibs;libcnt++) { X if(verbflg>10) { X fprintf(stderr,"%s\n",wtobj->lib[libcnt]->libnam); X } X X fprintf(outfildes,"%s\n",wtobj->lib[libcnt]->libnam); X } X X/* output "call" directives */ X Xif(verbflg>1) { X fprintf(stderr,"wt_obj: writing %d 'call' directives\n", X wtobj->size.nocalls); X } X Xfor(calcnt=0;calcntsize.nocalls;calcnt++) { X if(verbflg>10) { X fprintf(stderr,"%s\n",wtobj->call[calcnt]->filnam); X } X X fprintf(outfildes,"%s\n\n",wtobj->call[calcnt]->filnam); X } X X/* output vertices */ X Xif(verbflg>1) { X fprintf(stderr,"wt_obj: writing %d vertices\n",wtobj->size.noverts - 1); X } X Xfprintf(outfildes,"\n! vertices %d\n",wtobj->size.noverts); Xfor(vcount=1;vcountsize.noverts;vcount++) { X if(verbflg>10) { X fprintf(stderr,"wt_obj: vertex mtl = %d, current mtl = %d\n", X wtobj->vertex[vcount]->mtl,mtlindx); X fprintf(stderr,"v %3.6f %3.6f %3.6f # vertex %d\n", X wtobj->vertex[vcount]->x, X wtobj->vertex[vcount]->y, X wtobj->vertex[vcount]->z,vcount); X } X /* see if vertex material is current material */ X if(wtobj->vertex[vcount]->mtl!=mtlindx) { X /* if not, change current mtl and ouput new "usemtl" */ X mtlindx=wtobj->vertex[vcount]->mtl; X if(!strcmp(wtobj->mtl[mtlindx]->mtlnam,"# no materials used")) { X if(verbflg>10) { X fprintf(stderr,"%s\n",wtobj->mtl[mtlindx]->mtlnam); X } X fprintf(outfildes,"%s\n",wtobj->mtl[mtlindx]->mtlnam); X } X else { X if(verbflg>10) { X fprintf(stderr,"usemtl %s\n",wtobj->mtl[mtlindx]->mtlnam); X } X fprintf(outfildes,"usemtl %s\n",wtobj->mtl[mtlindx]->mtlnam); X } X } X fprintf(outfildes,"v %3.6f %3.6f %3.6f\n", X wtobj->vertex[vcount]->x, X wtobj->vertex[vcount]->y, X wtobj->vertex[vcount]->z); X } Xfprintf(outfildes,"\n\# %d vertices\n\n",wtobj->size.noverts - 1); X X/* output texture vertices */ X Xif(verbflg>1) { X fprintf(stderr,"wt_obj: writing %d texture vertices\n", X wtobj->size.notverts - 1); X } X Xfprintf(outfildes,"\n! tverts %d\n",wtobj->size.notverts); Xfor(tvcount=1;tvcountsize.notverts;tvcount++) { X fprintf(outfildes,"vt %3.6f %3.6f %3.6f\n", X wtobj->texver[tvcount]->u, X wtobj->texver[tvcount]->v, X wtobj->texver[tvcount]->w); X } Xfprintf(outfildes,"\n\# %d texture vertices\n\n",wtobj->size.notverts - 1); X X X X/* output lines */ X Xif(verbflg>1) { X fprintf(stderr,"wt_obj: writing %d lines\n",wtobj->size.nolines); X } X Xfprintf(outfildes,"\n! lverts %d\n",wtobj->size.nolverts); Xfprintf(outfildes,"\n! lines %d\n",wtobj->size.nolines); Xfor(lcount=0;lcountsize.nolines;lcount++) { X /* don't output a line with less than two vertices */ X if(wtobj->line[lcount]->vertc>1) { X /* see if line group is current group */ X if(wtobj->line[lcount]->group!=grpindx) { X /* if not, change current group and ouput new group */ X grpindx=wtobj->line[lcount]->group; X if(verbflg>9) { X fprintf(stderr, "g %s\n",wtobj->group[grpindx]->grpnam); X } X fprintf(outfildes, "g %s\n",wtobj->group[grpindx]->grpnam); X } X /* see if line material is current material */ X if(wtobj->line[lcount]->mtl!=mtlindx) { X /* if not, change current mtl and ouput new "usemtl" */ X mtlindx=wtobj->line[lcount]->mtl; X if(!strcmp(wtobj->mtl[mtlindx]->mtlnam,"# no materials used")) { X if(verbflg>9) { X fprintf(stderr, "%s\n",wtobj->mtl[mtlindx]->mtlnam); X } X fprintf(outfildes,"%s\n",wtobj->mtl[mtlindx]->mtlnam); X } X else { X if(verbflg>9) { X fprintf(stderr, X "usemtl %s\n",wtobj->mtl[mtlindx]->mtlnam); X } X fprintf(outfildes,"usemtl %s\n",wtobj->mtl[mtlindx]->mtlnam); X } X } X fprintf(outfildes,"l"); X for(lvcnt=0;lvcntline[lcount]->vertc;lvcnt++) { X fprintf(outfildes," %d", wtobj->line[lcount]->vertno[lvcnt]); X } X fprintf(outfildes,"\n"); X } X } X X/* output meta-elements of type 'circle' */ X Xif(verbflg>1) { X fprintf(stderr,"wt_obj: writing %d meta-elements of type 'circle'\n", X wtobj->size.nocircs); X } X Xfprintf(outfildes,"\n! circles %d\n",wtobj->size.nocircs); Xfor(circnt=0;circntsize.nocircs;circnt++) { X /* see if circle group is current group */ X if(wtobj->circl[circnt]->group!=grpindx) { X /* if not, change current group and ouput new group */ X grpindx=wtobj->circl[circnt]->group; X if(verbflg>9) { X fprintf(stderr, X "g %s\n",wtobj->group[grpindx]->grpnam); X } X fprintf(outfildes, X "g %s\n",wtobj->group[grpindx]->grpnam); X } X fprintf(outfildes,"*c %d %3.6f %d\n", X wtobj->circl[circnt]->vertno, X wtobj->circl[circnt]->rad, X wtobj->circl[circnt]->res); X } X Xfprintf(outfildes,"\n\# %d circles\n",wtobj->size.nocircs); X X/* output points */ X Xif(verbflg>1) { X fprintf(stderr,"wt_obj: writing %d points\n",wtobj->size.nopoints); X } X Xfprintf(outfildes,"\n! pverts %d\n",wtobj->size.nopverts); Xfprintf(outfildes,"\n! points %d\n",wtobj->size.nopoints); Xfor(pcount=0;pcountsize.nopoints;pcount++) { X /* don't output a point with less than one vertex */ X if(wtobj->point[pcount]->vertc>0) { X /* see if point group is current group */ X if(wtobj->point[pcount]->group!=grpindx) { X /* if not, change current group and ouput new group */ X grpindx=wtobj->point[pcount]->group; X if(verbflg>9) { X fprintf(stderr, "g %s\n",wtobj->group[grpindx]->grpnam); X } X fprintf(outfildes, "g %s\n",wtobj->group[grpindx]->grpnam); X } X if(verbflg>9) { X fprintf(stderr,"point %d: p",pcount); X } X fprintf(outfildes,"p"); X for(pvcnt=0;pvcntpoint[pcount]->vertc;pvcnt++) { X if(verbflg>9) { X fprintf(stderr," %d", X wtobj->point[pcount]->vertno[pvcnt]); X } X fprintf(outfildes," %d", X wtobj->point[pcount]->vertno[pvcnt]); X } X if(verbflg>9) { X fprintf(stderr,"\n"); X } X fprintf(outfildes,"\n"); X } X } X Xfprintf(outfildes,"\n\# %d points\n",wtobj->size.nopoints); X X/* output faces */ X Xif(verbflg>1) { X fprintf(stderr,"wt_obj: writing %d faces\n",wtobj->size.nofaces); X } X Xfprintf(outfildes,"\n! fverts %d\n",wtobj->size.nofverts); Xfprintf(outfildes,"\n! faces %d\n",wtobj->size.nofaces); Xfor(fcount=0;fcountsize.nofaces;fcount++) { X if(verbflg>9) { X fprintf(stderr, X "wt_obj: face %d, %d vertices\n", X fcount,wtobj->face[fcount]->vertc); X } X /* don't output a face with less than three vertices */ X if(wtobj->face[fcount]->vertc>2) { X /* see if face group is current group */ X if(wtobj->face[fcount]->group!=grpindx) { X /* if not, change current group and ouput new group */ X grpindx=wtobj->face[fcount]->group; X if(verbflg>9) { X fprintf(stderr, "g %s\n",wtobj->group[grpindx]->grpnam); X } X fprintf(outfildes, "g %s\n",wtobj->group[grpindx]->grpnam); X } X /* see if face smoothing group is current smoothing group */ X if(wtobj->face[fcount]->smooth!=sindx) { X /* if not, change current smoothing group */ X sindx=wtobj->face[fcount]->smooth; X /* and output smoothing directive */ X if(sindx<=(-1)) { X if(verbflg>9) { X fprintf(stderr,"s off\n"); X } X fprintf(outfildes,"s off\n"); X } X else { X if(verbflg>9) { X fprintf(stderr,"s %d\n", X wtobj->face[fcount]->smooth); X } X fprintf(outfildes,"s %d\n", X wtobj->face[fcount]->smooth); X } X } X /* see if face bevel interp state is same as current state */ X if(wtobj->face[fcount]->bevel!=bindx) { X /* if not, change current bevel flag */ X bindx=wtobj->face[fcount]->bevel; X /* and output bevel directive */ X if(bindx==0) { X fprintf(outfildes,"bevel off\n"); X } X else { X fprintf(outfildes,"bevel on\n"); X } X } X /* see if face material is current material */ X if(wtobj->face[fcount]->mtl!=mtlindx) { X /* if not, change current mtl and ouput new "usemtl" */ X mtlindx=wtobj->face[fcount]->mtl; X if(!strcmp(wtobj->mtl[mtlindx]->mtlnam,"# no materials used")) { X if(verbflg>9) { X fprintf(stderr, "%s\n",wtobj->mtl[mtlindx]->mtlnam); X } X fprintf(outfildes,"%s\n",wtobj->mtl[mtlindx]->mtlnam); X } X else { X if(verbflg>9) { X fprintf(stderr, "usemtl %s\n",wtobj->mtl[mtlindx]->mtlnam); X } X fprintf(outfildes,"usemtl %s\n",wtobj->mtl[mtlindx]->mtlnam); X } X } X /* see if face mapping is current mapping */ X if(wtobj->face[fcount]->map!=mapindx) { X /* if not, change current map and ouput new "usemap" */ X mapindx=wtobj->face[fcount]->map; X if(mapindx==(-1)) { X if(verbflg>9) { X fprintf(outfildes,"usemap off\n"); X } X fprintf(outfildes,"usemap off\n"); X } X else { X if(!strcmp(wtobj->map[mapindx]->mapnam,"# no mappings used")) { X if(verbflg>9) { X fprintf(stderr, "%s\n", wtobj->map[mapindx]->mapnam); X } X fprintf(outfildes,"%s\n", wtobj->map[mapindx]->mapnam); X } X else { X if(verbflg>9) { X fprintf(stderr, "usemap %s\n", X wtobj->map[mapindx]->mapnam); X } X fprintf(outfildes,"usemap %s\n", X wtobj->map[mapindx]->mapnam); X } X } X } X if(wtobj->face[fcount]->mapflg==MAP) { X if(verbflg>9) { X fprintf(stderr,"f"); X } X fprintf(outfildes,"f"); X } X else { X if(verbflg>9) { X fprintf(stderr,"fo"); X } X fprintf(outfildes,"fo"); X } X for(fvcnt=0;fvcntface[fcount]->vertc;fvcnt++) { X if(wtobj->face[fcount]->map>(-1)) { X if(verbflg>9) { X fprintf(stderr," %d/%d", X wtobj->face[fcount]->vertno[fvcnt], X wtobj->face[fcount]->tvertno[fvcnt]); X } X fprintf(outfildes," %d/%d", X wtobj->face[fcount]->vertno[fvcnt], X wtobj->face[fcount]->tvertno[fvcnt]); X } X else { X if(verbflg>9) { X fprintf(stderr," %d", X wtobj->face[fcount]->vertno[fvcnt]); X } X fprintf(outfildes," %d", X wtobj->face[fcount]->vertno[fvcnt]); X } X } X if(verbflg>9) { X fprintf(stderr,"\n"); X } X fprintf(outfildes,"\n"); X } X } X Xfprintf(outfildes,"\n\# %d faces\n\n",wtobj->size.nofaces); X X/* output meta-elements of type 'sphere' */ X Xif(verbflg>1) { X fprintf(stderr,"wt_obj: writing %d meta-elements of type 'sphere'\n", X wtobj->size.nosphrs); X } X Xfprintf(outfildes,"\n! spheres %d\n",wtobj->size.nosphrs); Xfor(sphcnt=0;sphcntsize.nosphrs;sphcnt++) { X /* see if sphere group is current group */ X if(wtobj->spher[sphcnt]->group!=grpindx) { X /* if not, change current group and ouput new group */ X grpindx=wtobj->spher[sphcnt]->group; X if(verbflg>9) { X fprintf(stderr, "g %s\n",wtobj->group[grpindx]->grpnam); X } X fprintf(outfildes, "g %s\n",wtobj->group[grpindx]->grpnam); X } X /* see if sphere smoothing group is current smoothing group */ X if(wtobj->spher[sphcnt]->smooth!=sindx) { X /* if not, change current smoothing group */ X sindx=wtobj->spher[sphcnt]->smooth; X /* and output smoothing directive */ X if(sindx<=(-1)) { X fprintf(outfildes,"s off\n"); X } X else { X fprintf(outfildes, X "s %d\n",wtobj->spher[sphcnt]->smooth); X } X } X /* see if sphere material is current material */ X if(wtobj->spher[sphcnt]->mtl!=mtlindx) { X /* if not, change current mtl and ouput new "usemtl" */ X mtlindx=wtobj->spher[sphcnt]->mtl; X if(!strcmp(wtobj->mtl[mtlindx]->mtlnam,"# no materials used")) { X if(verbflg>9) { X fprintf(stderr,"%s\n",wtobj->mtl[mtlindx]->mtlnam); X } X fprintf(outfildes,"%s\n",wtobj->mtl[mtlindx]->mtlnam); X } X else { X if(verbflg>9) { X fprintf(stderr,"usemtl %s\n",wtobj->mtl[mtlindx]->mtlnam); X } X fprintf(outfildes,"usemtl %s\n",wtobj->mtl[mtlindx]->mtlnam); X } X } X /* see if sphere mapping is current mapping */ X if(wtobj->spher[sphcnt]->map!=mapindx) { X /* if not, change current map and ouput new "usemap" */ X mapindx=wtobj->spher[sphcnt]->map; X if(mapindx==(-1)) { X if(verbflg>9) { X fprintf(outfildes,"usemap off\n"); X } X fprintf(outfildes,"usemap off\n"); X } X else { X if(!strcmp(wtobj->map[mapindx]->mapnam,"# no mappings used")) { X if(verbflg>9) { X fprintf(stderr, X "%s\n",wtobj->map[mapindx]->mapnam); X } X fprintf(outfildes,"%s\n",wtobj->map[mapindx]->mapnam); X } X else { X if(verbflg>9) { X fprintf(stderr, "usemap %s\n",wtobj->map[mapindx]->mapnam); X } X fprintf(outfildes,"usemap %s\n",wtobj->map[mapindx]->mapnam); X } X } X } X /* meta-element directive for sphere: '*s center radius resolution' */ X fprintf(outfildes,"*s %d %3.6f %d\n", X wtobj->spher[sphcnt]->vertno, X wtobj->spher[sphcnt]->rad, X wtobj->spher[sphcnt]->res); X } Xfprintf(outfildes,"\n\# %d spheres\n\n",wtobj->size.nosphrs); X X/* output elements of type 'bicubic patch' */ X Xif(verbflg>1) { X fprintf(stderr, X "wt_obj: writing %d bicubic patches\n", wtobj->size.noptchs); X } X Xfprintf(outfildes,"\n! bicubes %d\n",wtobj->size.noptchs); Xfor(bicuct=0;bicuctsize.noptchs;bicuct++) { X /* see if patch group is current group */ X if(wtobj->bicub[bicuct]->group!=grpindx) { X /* if not, change current group and ouput new group */ X grpindx=wtobj->bicub[bicuct]->group; X if(verbflg>9) { X fprintf(stderr, X "g %s\n",wtobj->group[grpindx]->grpnam); X } X fprintf(outfildes, X "g %s\n",wtobj->group[grpindx]->grpnam); X } X /* see if patch smoothing group is current smoothing group */ X if(wtobj->bicub[bicuct]->smooth!=sindx) { X /* if not, change current smoothing group */ X sindx=wtobj->bicub[bicuct]->smooth; X /* and output smoothing directive */ X if(sindx<=(-1)) { X fprintf(outfildes,"s off\n"); X } X else { X fprintf(outfildes, X "s %d\n",wtobj->bicub[bicuct]->smooth); X } X } X /* see if patch material is current material */ X if(wtobj->bicub[bicuct]->mtl!=mtlindx) { X /* if not, change current mtl and ouput new "usemtl" */ X mtlindx=wtobj->bicub[bicuct]->mtl; X if(!strcmp(wtobj->mtl[mtlindx]->mtlnam,"# no materials used")) { X if(verbflg>9) { X fprintf(stderr,"%s\n",wtobj->mtl[mtlindx]->mtlnam); X } X fprintf(outfildes,"%s\n",wtobj->mtl[mtlindx]->mtlnam); X } X else { X if(verbflg>9) { X fprintf(stderr,"usemtl %s\n",wtobj->mtl[mtlindx]->mtlnam); X } X fprintf(outfildes,"usemtl %s\n",wtobj->mtl[mtlindx]->mtlnam); X } X } X /* see if patch mapping is current mapping */ X if(wtobj->bicub[bicuct]->map!=mapindx) { X /* if not, change current map and ouput new "usemap" */ X mapindx=wtobj->bicub[bicuct]->map; X if(mapindx==(-1)) { X if(verbflg>9) { X fprintf(outfildes,"usemap off\n"); X } X fprintf(outfildes,"usemap off\n"); X } X else { X if(!strcmp(wtobj->map[mapindx]->mapnam,"# no mappings used")) { X if(verbflg>9) { X fprintf(stderr,"%s\n", wtobj->map[mapindx]->mapnam); X } X fprintf(outfildes,"%s\n",wtobj->map[mapindx]->mapnam); X } X else { X if(verbflg>9) { X fprintf(stderr,"usemap %s\n", wtobj->map[mapindx]->mapnam); X } X fprintf(outfildes,"usemap %s\n",wtobj->map[mapindx]->mapnam); X } X } X } X /* see if patch resolution is current resolution */ X if(wtobj->bicub[bicuct]->u_res!=u_res || X wtobj->bicub[bicuct]->v_res!=v_res) { X /* if not, change current res and ouput new "res" */ X u_res=wtobj->bicub[bicuct]->u_res; X v_res=wtobj->bicub[bicuct]->v_res; X if(verbflg>9) { X fprintf(stderr,"wt_obj: res %d %d\n",u_res,v_res); X } X fprintf(outfildes,"res %d %d\n",u_res,v_res); X } X /* meta-element directive for bicubic patch: X '[bsp | bzp | bcp] [vertex matrix]' */ X switch(wtobj->bicub[bicuct]->type) { X case BSPLINE: { X fprintf(outfildes,"bsp"); X break; X } X case BEZIER: { X fprintf(outfildes,"bzp"); X break; X } X case CARDINAL: { X fprintf(outfildes,"bcp"); X break; X } X } X for(row=0;row<4;row++) { X for(col=0;col<4;col++) { X if(wtobj->bicub[bicuct]->map>(-1)) { X /* output vertex indices with texture */ X fprintf(outfildes," %d/%d", X wtobj->bicub[bicuct]->vertno[row][col], X wtobj->bicub[bicuct]->tvertno[row][col]); X } X else { X fprintf(outfildes," %d", X wtobj->bicub[bicuct]->vertno[row][col]); X } X } X } X fprintf(outfildes,"\n"); X } X Xfprintf(outfildes,"\n\# %d bicubic patches\n",wtobj->size.noptchs); X Xfprintf(stderr,"wt_obj: done\n"); X} !EOR! echo extracting man/man1/poly2obj.sl echo mkdir ./man mkdir ./man echo mkdir ./man/man1 mkdir ./man/man1 sed 's/^X//' > man/man1/poly2obj.sl << '!EOR!' X.TH POLY2OBJ 1 "25 Jan 1989" X.UC 4 X.SH NAME X.B poly2obj X\- converts Hume's '.poly' object files to Wavefront '.obj' object files. X.SH SYNOPSIS X.B poly2obj \[options\] X.B \[input_file.poly\] X XASCII object description is delivered to X.B standard output. X.in -4 X.SH OPTIONS X.B -h\[elp\] X\- prints command usage. X X.B -v \[level\] X\- runs the command verbosely. Levels begin at 1 (default). Levels higher Xthan 5 print out more information than is necessary for all but very intensive Xprogram debugging. X X.in -4 X.SH DESCRIPTION X.ad n X.fi X.B poly2obj X\- converts '.poly' ASCII object files of the type used by Andrew Hume's Xcatalogue of polyhedra to Wavefront '.obj' object files. X X.SH AUTHOR X.nf XStewart Dickson Xcelia!tpg!dickson@tis.llnl.gov X.SH FILES X.nf X$SPD_DIR/src/cmds/poly2obj.c X$SPD_DIR/src/obj_lib/alloc_obj.c X$SPD_DIR/src/obj_lib/app_obj.c X$SPD_DIR/src/obj_lib/rd_poly.c X$SPD_DIR/src/obj_lib/wt_obj.c X X.SH SEE ALSO X.nf Xobjects(5 local) Xpoly(5 local) X !EOR! echo extracting man/man1/Make.poly2obj echo mkdir ./man mkdir ./man echo mkdir ./man/man1 mkdir ./man/man1 sed 's/^X//' > man/man1/Make.poly2obj << '!EOR!' X# file: $SPD_DIR/man/man1/Make.poly2obj X# X# description: instructions for printing manual section 1 of the Stewart X# Dickson computer modeling package. X# X Xpoly2obj: poly2obj.sl X troff -man -t poly2obj.sl |lpr -t !EOR! echo extracting man/man3/alloc_obj.sl echo mkdir ./man mkdir ./man echo mkdir ./man/man3 mkdir ./man/man3 sed 's/^X//' > man/man3/alloc_obj.sl << '!EOR!' X.TH ALLOC_OBJ 3 "9 Oct 1988" X.UC 4 X.SH NAME X.nf Xalloc_obj, Xdef_parms, Xcopy_alc, Xcopy_siz, Xfree_obj, Xrealc_obj X.fi X\- functions for allocating, freeing and Xreallocating memory for geometrical object description structures. X.SH SYNOPSIS X#include X X.nf Xstruct topology *alloc_obj(alloc) Xstruct sizes *alloc; X Xstruct topology *alloc_hdr(hdrobj,hdralc) Xstruct topology *hdrobj; Xstruct sizes *hdralc; X Xstruct topology *alloc_verts(vertobj,vertalc) Xstruct topology *hdrobj; Xstruct sizes *hdralc; X Xstruct topology *alloc_tverts(tvertobj,tvertalc) Xstruct topology tvertobj; Xstruct sizes *tvertalc; X Xstruct topology *alloc_faces(facobj,facalc) Xstruct topology *facobj; Xstruct sizes *facalc; X Xstruct topology *alloc_lines(linobj,linalc) Xstruct topology *linobj; Xstruct sizes *linalc; X Xstruct topology *alloc_edges(edgobj,edgalc) Xstruct topology *edgobj; Xstruct sizes *edgalc; X Xstruct topology *alloc_circs(crcobj,crcalc) Xstruct topology *crcobj; Xstruct sizes *crcalc; X Xstruct topology *alloc_points(pntobj,pntalc) Xstruct topology *pntobj; Xstruct sizes *pntalc; X Xstruct topology *alloc_sphrs(sphobj,sphalc) Xstruct topology *sphobj; Xstruct sizes *sphalc; X Xstruct topology *alloc_ptchs(pchobj,pchalc) Xstruct topology *pchobj; Xstruct sizes *pchalc; X Xstruct topology *alloc_mdefs(mdfobj,mdfalc) Xstruct topology *mdfobj; Xstruct sizes *mdfalc; X Xstruct topology *alloc_mrefs(mrfobj,mrfalc) Xstruct topology *mrfobj; Xstruct sizes *mrfalc; X Xstruct topology *alloc_moprs(mopobj,mopalc) Xstruct topology *mopobj; Xstruct sizes *mopalc; X Xstruct sizes *copy_alc(object,alloc) Xstruct topology *object; Xstruct sizes *alloc; X Xstruct sizes *copy_siz(object,alloc) Xstruct topology *object; Xstruct sizes *alloc; X Xstruct sizes *def_parms(alloc) Xstruct sizes *alloc; X Xvoid free_obj(object) Xstruct topology *object; X Xstruct topology *realc_obj(object,alloc) Xstruct topology *object; Xstruct sizes *alloc; X.fi X X.SH DESCRIPTION X.ad n X.fi X.B alloc_obj Xdynamically allocates memory for geometrical object description structures. XAllocation parameters are passed in the structure 'alloc'. If 'alloc' is XNULL, default parameters are used. X X.B def_parms Xsets default allocation size parameters for an object. X.B def_parms Xreads the environment for object size specification variables. If these Xvariables are not set, internal defaults are used. X X.in 4 XThe following environment variables used by Wavefront Technologies are Xrecognized: X X.B WF_MVRT X\- sets the number of vertices to allocate - default 5000 X X.B WF_MTVS X\- sets the number of texture vertices to allocate - default 100 X X.B WF_MVPE X\- sets the number of vertices per element to allocate - default 200 XNote: since Wavefront Technologies does not distinguish between element types Xwhen allocating objects, all elements are allocated the same number of vertices. X X.B WF_MMTL X\- sets the number of materials to allocate - default 100 X X.B WF_MTEX X\- sets the number of textures to allocate - default 100 X X XThe following local environment variables are recognized and if set override Xthe WF_* variables: X X.B SPD_VERTS X\- sets the number of vertices to allocate - default 5000 X X.B SPD_TVERTS X\- sets the number of texture vertices to allocate - default 100 X X.B SPD_MTLS X\- sets the number of materials to allocate - default 100 X X.B SPD_TEX X\- sets the number of textures to allocate - default 100 X X.B SPD_LIBS X\- sets the number of material/mapping libraries to allocate - default 100 X X.B SPD_GROUPS X\- sets the number of element grouping lists to allocate - default 10 X X.B SPD_LINES X\- sets the number of elements of type 'line' to allocate - default 100 X X.B SPD_POINTS X\- sets the number of elements of type 'point' to allocate - default 100 X X.B SPD_FACES X\- sets the number of elements of type 'face' to allocate - default 5000 X X.B SPD_CIRCS X\- sets the number of 'meta-elements' of type 'circle' to allocate - default 100 X X.B SPD_SPHRS X\- sets the number of 'meta-elements' of type 'sphere' to allocate - default 100 X X.B SPD_PTCHS X\- sets the number of 'meta-elements' of type 'bicubic patch' to allocate - default 10 X X.B SPD_EDGES X\- sets the number of connections between vertices to allocate default - 100 X X.B SPD_GROUPS X\- sets the number of element groups to allocate - default 1 X X.B SPD_VPLIN X\- sets the number of vertices per line to allocate - default 100 X X.B SPD_VPFAC X\- sets the number of vertices per face to allocate - default 20 X X.B SPD_VALEN X\- sets the number of edges-per-vertex and faces-per-vertex to allocate - default 10 X.in -4 X X.B copy_alc Xreturns a pointer to a structure containing the allocation parameters for the Xstructure 'object'. X X.B copy_siz Xreturns a pointer to a structure containing the current population parameters Xfor the structure 'object'. X X.B free_obj Xfrees memory previously allocated for geometrical object description Xstructures. X X.B realc_obj Xdynamically reallocates memory for any part of a geometrical object description Xstructure. Allocation parameters are passed in structure 'alloc'. Any Xparameter in 'alloc' exceeding the current value of the corresponding Xparameter in 'object->alloc' will cause the memory to be reallocated for that Xparameter. A NULL value for 'alloc' will cause the process to exit(2). X X X.SH AUTHOR XStewart Dickson X.SH FILES X.nf X$SPD_DIR/include/topology.h X$SPD_DIR/src/obj_lib/alloc_obj.c X$SPD_DIR/src/obj_lib/rd_obj.c X$SPD_DIR/src/obj_lib/app_obj.c X X.SH SEE ALSO X.nf Xrd_obj(3 local) Xobjects(5 local) !EOR! echo extracting man/man3/app_obj.sl echo mkdir ./man mkdir ./man echo mkdir ./man/man3 mkdir ./man/man3 sed 's/^X//' > man/man3/app_obj.sl << '!EOR!' X.TH APP_OBJ 3 "27 Nov 1988" X.UC 4 X.SH NAME X.Bapp_obj X.br X.B copy_obj X XTopological object concatenate and copy. X.SH SYNOPSIS X.nf X\#include X X.B struct topology *app_obj(dstobj,srcobj,actgrp,flag) Xstruct topology *dstobj,*srcobj; Xint actgrp; Xchar flag; X X.B int add_group(object,grp_name) Xstruct topology *object; Xchar *grp_name; X X.B int add_lib(object,lib_name) Xstruct topology *object; Xchar *lib_name; X X.B int add_map(object,map_name) Xstruct topology *object; Xchar *map_name; X X.B int add_mtl(object,mtl_name) Xstruct topology *object; Xchar *mtl_name; X X.B struct topology *copy_obj(dstobj,srcobj,flag) Xstruct topology *dstobj,*srcobj; Xchar flag; X.fi X X.in -4 X.SH DESCRIPTION X.ad n X.fi X.B app_obj Xreturns the destination object which has had the contents of the source object Xappended to it. Elements in the X.B srcobj Xare placed in the group indicated by X.B actgrp. XIf X.B actgrp Xis \-1, the groups defined in X.B srcobj Xare transferred intact to X.B dstobj. XObjec attributes such as material, texture mapping, geometrical smoothing, etc. Xare preserved and, if necessary, re-indexed to retain the uniqueness indicated Xin the X.B srcobj. X X.B flag Xis a character 'e', 'm' or 'h', indicating whether only simple elements, Xgraphical meta-elements and simple elements or only object header information Xare to be copied to the destination object. X X.B add_group, add_lib, add_map Xand X.B add_mtl Xrespectively add group, library, texture map and material names to the Xcorresponding list of such items in the X.B object. XIf the X.B grp_, lib_, map_ Xor X.B mtl_name Xalready exists in the corresponding list, the index to the existing named Xitem is returned. If the name does not already exist, allocation is checked, Xincreased if necessary, the named item is added to the list and its index is Xreturned. X X.B copy_obj Xreturns the source object verbatim, copied to a new structure in core. XThe previous contents of X.B dstobj, Xif any, are destroyed. X X.SH AUTHOR XStewart Dickson X.SH FILES X.nf X$SPD_DIR/src/obj_lib/app_obj.c X$SPD_DIR/include/topology.h X X X !EOR! echo extracting man/man3/rd_poly.sl echo mkdir ./man mkdir ./man echo mkdir ./man/man3 mkdir ./man/man3 sed 's/^X//' > man/man3/rd_poly.sl << '!EOR!' X.TH RD_POLY 3 "25 Jan 1989" X.UC 4 X.SH NAME Xrd_poly() - Hume's ASCII object description input. X.SH SYNOPSIS X#include X X.nf Xstruct topology *rd_poly(object,fildes) Xstruct topology *object; XFILE *fildes; X.fi X.in -4 X.SH DESCRIPTION X.ad n X.fi X.B rd_poly Xreads an input ASCII object description into a data structure in core. XIf 'object' is a NULL pointer, X.B rd_poly Xcalls X.B alloc_obj(3 local) Xto allocate space for this structure. X X.B rd_poly Xunderstands ASCII object description conventions used by XAndrew Hume's catalogue of polyhedra. (See also X.B POLY(5 local)). X X.fi X.SH EXAMPLES X.nf X#include X#include X XFILE *file; Xchar *filename; Xstruct topology *object,*rd_poly(); X Xif((file=fopen(filename,"r"))==NULL) { X fprintf(stderr,"cannot open %s\\n",filename); X exit(-1); X } X/* read 'filename' into structure 'object' of default size */ Xobject=rd_poly(object,file); Xfclose(file); X X.fi X.SH AUTHOR XStewart Dickson X.SH FILES X.nf X$SPD_DIR/src/alloc_obj.c X$SPD_DIR/src/app_obj.c X$SPD_DIR/src/rd_poly.c X$SPD_DIR/include/topology.h X X.SH SEE ALSO X.nf Xalloc_obj(3 local) Xapp_obj(3 local) Xwt_obj(3 local) Xobjects (5 local) Xpoly(5 local) !EOR! echo extracting man/man3/wt_obj.sl echo mkdir ./man mkdir ./man echo mkdir ./man/man3 mkdir ./man/man3 sed 's/^X//' > man/man3/wt_obj.sl << '!EOR!' X.TH WT_OBJ 3 "8 Mar 1988" X.UC 4 X.SH NAME Xwt_obj() - ASCII object description output. X.SH SYNOPSIS X#include X.nf X Xvoid wt_obj(fildes,object) XFILE *fildes; Xstruct topology *object; X.in -4 X.SH DESCRIPTION X.ad n X.fi X.B wt_obj Xwrites an input ASCII object description from a data structure in core. X X.B wt_obj Xuses ASCII object description conventions used by XWavefront Technologies, 'model', 'pv' and 'image', plus a few Xenhancements. Object description directives include the following: X X.nf X# comment X X# object description file inclusion Xcall filename.obj X# material description file inclusion Xmtllib filename.mtl X# texture map description file inclusion Xmaplib filename.map X X# material application directive Xusemtl mtl_name X# texture map application directive Xusemap map_name Xusemap off X X# element grouping directive Xg name X X# allocation specification for vertices (comment to Wavefront) X! vertices 5000 X X# 3D geometrical vertex specification (without topology) Xv 1.000 2.000 3.000 X X# allocation specification for texture vertices (comment to Wavefront) X! tverts 5000 X X# texture map index specification Xvt 0.0 [0.05] [1.0] X X# allocation specification for vertices per point element and points X# (comment to Wavefront) X! pverts 500 X! points 100 X X# topological element type 'point' Xp [single-space separated integer vertex indeces] X X# allocation specification for vertices per line element and lines X# (comment to Wavefront) X! lverts 500 X! lines 100 X X# topological element type 'line' Xl [single-space separated integer vertex indeces] X X# allocation specification for vertices per face element and faces X# (comment to Wavefront) X! fverts 500 X! faces 100 X X# topological element type 'filled face' Xf 7 8 9 10 X X# topological element type 'face outline' with texture indeces Xfo 11/1 12/4 13/5 14/2 X X# geometrical smoothing directive Xs 1 Xs off X X# parametric surface patch resolution specifier Xres u_res v_res X X# allocation directive for bicubic patches X! patches 500 X X# parametric surface element type 'B-Spline Patch' Xbsp [set of 16 control vertex indices] X X# parametric surface element type 'Bezier Patch' Xbzp [set of 16 control vertex indices] X X# graphical meta-element type circle X*c [center vertex index] [radius] [resolution] X X# graphical meta-element type sphere X*s [center vertex index] [radius] [resolution] X X# graphical meta-element type 'bicubic patch' X*b [set of 16 control vertex indeces] [resolution] X X# begin the definition of a user-defined object meta-element X*defmeta name X X# lines of object description language follow X# NOTE: defmeta is recursive and may be nested X X# terminate the definition of a user-defined object meta-element X*enddef name X X# reference to (instance of) a user-defined object meta-element X*refmeta name vec1.x vec1.y vec1.z X vec2.x vec2.y vec2.z X base2.x base2.y base2.z X scale2.x scale2.y scale2.z X X.fi Xuse alloc_obj(3 local), rd_obj(3 local), etc. to allocate and fill object Xdescription structures. X X.SH EXAMPLES X.nf X#include X#include X XFILE *file; Xchar *filename; Xstruct topology *object; X Xif((file=fopen(filename,"w"))==NULL) { X fprintf(stderr,"cannot open %s\n",filename); X exit; X } X/* write 'object' to 'filename' */ Xwt_obj(file,object); Xfclose(file); X X.fi X.SH AUTHOR XStewart Dickson X.SH FILES X$SPD_DIR/src/wt_obj.c X$SPD_DIR/include/objects.h X X.SH SEE ALSO Xobjects (5 local) Xrd_obj() (3 local) !EOR! echo extracting man/man3/Make.poly2obj echo mkdir ./man mkdir ./man echo mkdir ./man/man3 mkdir ./man/man3 sed 's/^X//' > man/man3/Make.poly2obj << '!EOR!' X# file: $(SPD_DIR)/man/man3/Make.poly2obj X X# description: Instructions for printing manual section 3 of the Stewart X# Dickson computer modeling package. X Xalloc_obj: alloc_obj.sl X troff -man -t alloc_obj.sl |rsh tpg lpr -t X Xapp_obj: app_obj.sl X troff -man -t app_obj.sl |rsh tpg lpr -t X Xrd_poly: rd_poly.sl X troff -man -t rd_poly.sl |lpr -t X Xwt_obj: wt_obj.sl X troff -man -t wt_obj.sl |rsh tpg lpr -t !EOR! echo extracting man/man5/objects.sl echo mkdir ./man mkdir ./man echo mkdir ./man/man5 mkdir ./man/man5 sed 's/^X//' > man/man5/objects.sl << '!EOR!' X.TH OBJECTS 5 "27 Jul 1988" X.UC 4 X.SH NAME Xobjects - ASCII object description formats and data structure. X.SH SYNOPSIS X#include X.in -4 X.SH DESCRIPTION X.ad n X.fi X X.B WAVEFRONT ASCII OBJECT DESCRIPTION X XThis system adheres to ASCII object description conventions used by XWavefront Technologies, 'model', 'pv' and 'image' and the Stewart Dickson Xenhancements. Files using this convention should be named using the '.obj' Xsuffix. Object description directives include the following: X X# comment X X# object description file inclusion X.br Xcall filename.obj X X.br X# material description file inclusion X.br Xmtllib filename.mtl X X.br X# texture map description file inclusion X.br Xmaplib filename.map X X# material application directive X.br Xusemtl mtl_name X X.br X# texture map application directive X.br Xusemap map_name X.br Xusemap off X X.br X# element grouping directive X.br Xg name X X.br X# allocation specification for vertices (comment to Wavefront) X.br X! vertices 5000 X X.br X# 3D geometrical vertex specification (without topology) X.br Xv 1.000 2.000 3.000 X X.br X# allocation specification for texture vertices (comment to Wavefront) X.br X! tverts 5000 X X.br X# texture map index specification X.br Xvt 0.0 [0.05] [1.0] X X.br X# allocation specification for vertices per point element and point elements X.br X# (comment to Wavefront) X.br X! pverts 200 X.br X! points 100 X X# topological element type 'point' X.br Xp 11 12 13 14 15 X X.br X# allocation specification for vertices per line element and line elements X.br X# (comment to Wavefront) X.br X! lverts 200 X.br X! lines 100 X X# topological element type 'line' X.br Xl 2 3 4 5 6 X X.br X# allocation specification for vertices per face element and face elements X.br X# (comment to Wavefront) X.br X! fverts 4 X.br X! faces 10000 X X# topological element type 'filled face' X.br Xf 7 8 9 10 X X# topological element type 'face outline' with texture indices X.br Xfo 11/1 12/4 13/5 14/2 X X# allocation specification for parametric surface patches X.br X# (comment to Wavefront) X! patches 500 X X# parametric surface patch resolution (default is 4 X 4) X.br Xres u_res v_res X X# parametric surface element type 'B-Spline Patch' X.br Xbsp [set of 16 control vertex indices] X X# parametric surface element type 'Bezier Patch' X.br Xbzp [set of 16 control vertex indices] X X# geometrical smoothing directive X.br Xs 0 X.br Xs off X X# ray tracing directive X.br Xtrace_object object_name X X# shadow casting directive X.br Xshadow_object object_name X X.nf X# The following graphical 'meta-elements' are not implemented in X# Wavefront Technologies software. They must be expanded using X# 'expmeta(1 local)'. Files containing 'meta-elements' should be named X# using the file suffix ".meta". X X# allocation directive for circles (comment to Wavefront) X! circles 1000 X X# graphical meta-element type circle X.br X*c [center vertex index] [radius] [resolution] X X# allocation directive for spheres (comment to Wavefront) X! spheres 1000 X X# graphical meta-element type sphere X.br X*s [center vertex index] [radius] [resolution] X X# graphical meta-element type 'Cardinal Spline Patch' X.br Xbcp [set of 16 control vertex indices] X X.fi X X XObject files adhering to the '.obj' format are supported by all of the Xprograms in the locally-developed graphics tool package via the functions X.B rd_obj(3) Xand X.B wt_obj(3). X X X.B IGES X XThe IGES (Initial Graphics Exchange Standard) Version 2.0 graphical object Xdescription format is supported through object file conversion programs X\(see X.B wf2IGES(1) IGES2wf(1) rd_IGES(3) Xand X.B wt_IGES(3) X\). This is the ANSI graphics format defined by the National Bureau of XStandards. More information about IGES can be found in U.S. Department of XCommerce document number PB83-137884, available from the National Technical XInformation Service, Springfield, VA 22161. X XThe IGES entity types supported are: connected line segments organized as X.B copious data Xentities; 'node' entities; and 'finite element' entities of type 'linear Xtriangle' and 'linear quadrilateral'. Files using IGES conventions Xshould be named using the '.igs' extension. X X.B MOVIE.BYU X XObject files of the type used by MOVIE.BYU are supported through object file Xconversion programs (see X.B byu2obj(1) obj2byu(1) rd_byu(3) Xand X.B wt_byu(3) X\). X X.B GRASS X XObject files of the type used by Tom DeFanti's GRASS system are supported Xthrough object file conversion programs (see X.B vg2sg(1) X\). This object description is a simple vector list composed of lines of Xinteger vertices ordered X Y Z separated by spaces followed by a carriage Xreturn. Vertices are connected unless separated by a line consisting of 'J'. X X.B SKIDMORE, OWINGS AND MERRILL X XBinary object files of the type used by Skidmore, Owings and Merrill drafting Xprograms are supported through object conversion programs (see X.B gr2obj(1) X\). Files using this format are named using the file extension '.gr'. XThe binary file is of the following form: X X.nf X.B HEADER X(data type char *) the string "GRAPHICS\\0": 9 bytes X(data type short) header length : 2 bytes X(data type short) header type : 2 bytes Xvariable length header Xif header type = 1: id name X short length ; char *string X 2: time X short length ; long time X 3: comment X short length ; char *comment X -1: end of header X X.fi XGraphical Entity Type X.B NODE X(vertex) X.nf X(data type char) entity type = 8 : 1 byte X(data type short) length of entry to follow = 25 : 2 bytes X(data type double float) X coordinate : 8 bytes X(data type double float) Y coordinate : 8 bytes X(data type double float) Z coordinate : 8 bytes X(data type char) group number : 1 byte X X.fi XGraphical Entity Type X.B LINE SEGMENT X.nf X(data type char) entity type = 16 : 1 byte X(data type short) length of entry to follow = 15 : 2 bytes X(data type long) color : 4 bytes X(data type long) node (endpoint) 1 index : 4 bytes X(data type long) node (endpoint) 2 index : 4 bytes X(data type short) plot data (compressed pen/vector type) : 2 bytes X(data type char) group number : 1 byte X X.fi XGraphical Entity Type X.B POLYGON X.nf X(data type char) entity type = 24 : 1 byte X(data type short) length of entry to follow = 42 + strlen(key) + 4*nodes : 2 bytes X(data type double float) X coordinate of centroid of polygon : 8 bytes X(data type double float) Y coordinate of centroid of polygon : 8 bytes X(data type double float) Z coordinate of centroid of polygon : 8 bytes X(data type long) color : 4 bytes X(data type long) compressed polygon fill indicators : 4 bytes X(data type long) binary time stamp : 4 bytes X(data type short) plot data (compressed pen/vector type) : 2 bytes X(data type short) number of nodes in polygon : 2 bytes X(data type char) group number : 1 byte X(data type char) string length : 1 byte X(data type char) key : variable Xa number of node references: X (data type long) node (endpoint) 1 index : 4 bytes X X.fi XGraphical Entity Type X.B TEXT X.nf X(data type char) entity type = 32 : 1 byte X(data type short) length of entry to follow = 67 + strlen(font) + strlen(text) : 2 bytes X(data type double float) X coordinate of start of text : 8 bytes X(data type double float) Y coordinate of start of text : 8 bytes X(data type double float) Z coordinate of start of text : 8 bytes X(data type double float) height of text : 8 bytes X(data type double float) angle of text : 8 bytes X(data type double float) spacing of text : 8 bytes X(data type long) color : 4 bytes X(data type long) compressed text fill indicators : 4 bytes X(data type long) binary time stamp : 4 bytes X(data type short) plot data (compressed pen/vector type) : 2 bytes X(data type short) justification (right/left) : 2 bytes X(data type char) group number : 1 byte X(data type short) string length : 2 bytes X(data type char*) font : variable X(data type short) string length : 2 bytes X(data type char*) text : variable X X.fi XGraphical Entity Type X.B SYMBOL X.nf X(data type char) entity type = 40 : 1 byte X(data type short) length of entry to follow = 79 + strlen(name) + strlen(key) : 2 bytes X(data type double float) X translation of symbol : 8 bytes X(data type double float) Y translation of symbol : 8 bytes X(data type double float) Z translation of symbol : 8 bytes X(data type double float) X scale of symbol : 8 bytes X(data type double float) Y scale of symbol : 8 bytes X(data type double float) Z scale of symbol : 8 bytes X(data type double float) X rotation of symbol : 8 bytes X(data type double float) Y rotation of symbol : 8 bytes X(data type double float) Z rotation of symbol : 8 bytes X(data type long) binary time stamp : 4 bytes X(data type char) group number : 1 byte X(data type short) string length : 2 bytes X(data type char*) name : variable X(data type short) string length : 2 bytes X(data type char*) key : variable X.fi X XFunctions for reading and writing geometrical object description files are Xinterfaced to graphical programs through the data structure X.B $SPD_DIR/include/topology.h. XCompilation instructions should include 'cc -I$(SPD_DIR)/include ...' X X.SH DATA STRUCTURE X X.nf X/* file: topology.h X X description: Data structure for linking topological aspects of a 3-D X graphical object. Objects are described via the ASCII X object description language as being composed of vertices X and topological elements of several types with material X attributes. This system provides sufficient information X for determining the complete geometry, topology and material X properties of the object. This data structure provides the X framework for a complete linkage of these object attributes. X X Additionally is supported the recursive definition of X 'graphical meta-elements' which enable the efficient X specification of object hierarchical morphology (detail). X X author: Stewart Dickson X*/ X X/* define a 32-bit Magic Number for portability */ X#define SPD_MAGIC 0xff5500aa X X/* define values of object-to-polygon mapping directives */ X#define MAP 1 X#define NOMAP 0 X X/* define several types of parametric surfaces */ X#define BSPLINE 0 X#define BEZIER 1 X#define CARDINAL 2 X Xstruct sizes { X char notraces; X char noshados; X char nocalls; X char nolibs; X char nomaps; X char valence; X char nosgrps; X short nolverts; X short nofverts; X short nopverts; X short nogroups; X int nolines; X int nofaces; X int nopoints; X int noverts; X int notverts; X int noedges; X int nomtls; X int nocircs; X int nosphrs; X int noptchs; X int nogverts; X int nogfaces; X int nogpoints; X int noglines; X int nogsphrs; X int nogcircs; X int nogptchs; X int nomdefs; X int nomrefs; X int nomops; X X char objname[128]; X }; X Xstruct topology { X X struct sizes size; X X struct sizes alloc; X X struct bounding_box { X float minx; X float maxx; X float miny; X float maxy; X float minz; X float maxz; X } b_box; X X struct tracobj { X char objname[128]; X } **trace_obj; X X struct shadobj { X char objname[128]; X } **shad_obj; X X struct caldfile { X char filnam[128]; X } **call; X X struct library { X char libnam[128]; X } **lib; X X struct material { X char mtlnam[128]; X int illum; X struct RGB { X float red, green, blue; X } Ka, Kd, Ks, Ni, Tf; X float Ns, dissolve; X float mass_dens, surf_elast, surf_stiff; X float damping, visc_drag; X } **mtl; X X struct mapping { X char mapnam[128]; X } **map; X X struct objgrps { X int noverts; X int nopoints; X int nolines; X int nofaces; X int nocircs; X int nosphrs; X int noptchs; X X char grpnam[128]; X X int *vertno; X int *pointno; X int *lineno; X int *faceno; X int *circno; X int *sphrno; X int *ptchno; X } **group; X X struct vertex { X char facec; X char edgec; X short group; X int mtl; X float x; X float y; X float z; X struct Vector_struct { X float x; X float y; X float z; X } normal; X int *faceno; X int *edgeno; X } **vertex; X X struct faces { X char bevel; X char mapflg; X short map; X short smooth; X short group; X short vertc; X short edgec; X int mtl; X int *vertno; X int *tvertno; X int *edgeno; X struct Vector_struct normal; X } **face; X X struct textur { X float u; X float v; X float w; X } **texver; X X struct lines { X short vertc; X short group; X int mtl; X int *vertno; X } **line; X X struct edges { X int vertno[2]; X int faceno[2]; X float length; X float theta; X } **edge; X X struct points { X short vertc; X short group; X int *vertno; X } **point; X X struct circles { X short group; X short res; X int vertno; X float beg_ang; X float end_ang; X float rad; X struct Vector_struct x, y; X } **circl; X X struct spheres { X short map; X short smooth; X short group; X short res; X int vertno; X int mtl; X float rad; X } **spher; X X struct bicubes { X char type; X char u_res; X char v_res; X short map; X short smooth; X short group; X int mtl; X int vertno[4][4]; X int tvertno[4][4]; X } **bicub; X X struct topology **metadef; X X struct meta_reference { X float orient[4][4][4]; X struct topology *meta; X } **metaref; X X struct meta_oper { X char opname[128]; X struct topology *(*function)(); X struct param_iface *objarg; X } **metaop; X X }; X.fi X XThe motivation behind the design of this data structure is to make available Xto an application program an explicit description of the entire topology of Xan object. The following description of the elements of this structure will Xfurther elucidate its utility. X XDesigning the object as single structure enables programs to deal with Xobjects as named entities, with no prior assumptions about their contents. XThe contents are expressed in an explicit enough fashion that all information Xabout the object is completely contained. X X.B object->alloc Xis the structure containing the current allocation for the object. X.B alloc_obj(3 local), X.B rd_obj(3 local) Xand X.B realc_obj(3 local) Xpopulate the X.B alloc Xstructure upon completion. X X.B object->size Xis the structure containing the the current population of the structure. XThe value of each population element must be less than its corresponding Xallocation parameter. X.B rd_obj(3 local) Xand all other functions which create object structures populate the X.B size Xstructure upon completion. X X.B object->b_box Xcontains the positive and negative extrema of the object along each of the XX, Y and Z Cartesian axes. Thus, the extrema are reduced to six values. XThe object always is completely contained by its bounding cube, therefore Xprograms which scan many objects may first test whether the scan falls Xwithin each object's bounding cube before processing the object. X X.B object->trace_obj Xspecifies the (possibly alternate) object file to use in ray tracing Xillumination calculations. X X.B object->shad_obj Xspecifies the (possibly alternate) object file to use in shadow casting Xillumination calculations. X X.B object->call Xis a list of files called by this object. X X.B object->lib Xis a list of material and texture-mapping libraries used by this object. X.B rd_mtl(3 local) Xmay be used to read the material libraries. X X.Bobject->mtl Xis a list of materials used by the object. X X.B object->mtl->mtlnam Xis a string containing the name of the material as specified in the Xmaterial library and referenced in the object. X X.B object->mtl->Ka, X.B object->mtl->Kd, X.B object->mtl->Ks, X.B object->mtl->Ni X.B object->mtl->Ns Xand X.B object->mtl->Tf Xspecify the X.B ambient illumination, X.B diffuse scattering, X.B specular reflection, X.B index of refraction, X.B directional exponent of specular reflection Xand X.B transmission filter Xoptical properties of the material being used by the object. Note that X.B index of refraction Xis defined as a spectral curve, as occurs naturally, which permits glass to Xhave prismatic properties. Wavefront does not support this. X X.B object->mtl->mass_dens, X.B object->mtl->surf_elast Xand X.B object->mtl->surf_stiff Xspecify the mechanical properties of the material. These parameters permit Xthe treatment of objects as physical surfaces or, if constructed suitably, Xphysical volumes. This permits the modeling of surfaces which deform and Xanimate under the influence of 'real' Newtonian forces. X X.B object->map Xis a list of texture or other maps used by the object. X X.B object->group Xis a list of the vertex and element groups defined in the object and their Xmembership. X X.B object->vertex Xis the geometric vertex or node database for the object. X X.B object->vertex->x, X.B object->vertex->y Xand X.B object->vertex->z Xspecify the coordinate in Cartesian three-space for the vertex. X X.B object->vertex->mtl Xis the index of the material (as listed in the X.B object->mtl Xarray of structures) to be used at this vertex. X X.B object->vertex->facec, X.B object->vertex->edgec, X.B object->vertex->faceno Xand X.B object->vertex->edgeno Xlist the number of faces and edges containing this vertex and the indices to Xthese faces and edges as listed in the X.B object->face Xand X.B object->edge Xarrays of structures. The faces and edges are listed in a counter-clockwise Xorder about the vertex (according to the right-hand rule) relative to the Xeffective surface normal at the vertex. This ordering assures a topologically Xhomogeneous surface. This is one-third of the specification of the Xtopological connectivity of the object. X X.B object->normal Xcontains the effective normal to the surface located at the vertex. This is Xdefined as the sum of normal vectors to the polygons intersecting at this Xvertex. As this is redundant, this structure is also used in mechanical Xsimulations to store the X.B directed velocity Xof the vertex. This plus the X.B mass density Xof the vertex gives the X.B momentum Xfor the calculation of physical interactions of the object. X X.B object->face Xis the polygon or connected topological two-cell database for the object. XThis specifies the connectivity of the vertices in forming surfaces and Xvolumes. X X.B object->face->map Xand X.B object->face->mtl Xspecify the indices to texture or other mapping and material to be applied Xto this polygon, as listed in the X.B object->map Xand X.B object->mtl Xarrays of structures. X X.B object->face->smooth Xand X.B object->face->bevel Xspecify the membership in an illumination modeling geometric smoothing group Xand the specification of bevel geometric interpolation of the surface across Xthis polygon. This technique is an interpolation of the normal vector to the Xsurface across the polygon in two different flavors, used by rendering Xprograms to eliminate the polygonal 'faceting' artifice caused by the Xapproximation of a continuous curved surface by a finite number of polygons. X X.B object->face->group Xspecify the membership in a modeling element group of the polygon. X X.B object->face->mapflg Xis used to distinguish between a 'face outline' and a 'filled face' in Xinteractive display programs. This is also used by X.B objmap(1 local) Xto determine which elements to use as specification of the orientation of Xinstances of other objects. X X.B object->face->vertc, X.B object->face->edgec, X.B object->face->vertno, X.B object->face->tvertno Xand X.B object->face->edgeno Xspecify the number of X.B vertices Xand X.B edges Xand the list of indices to X.B vertices, X.B texture vertices Xand X.B edges Xin the object as listed in the X.B object->vertex, X.B object->texver Xand X.B object->edge Xarrays of structures. Faces close themselves. The first vertex is listed Xonly once and the last vertex is assumed to close the polygon. The ordering Xof the polygon specifies the direction of the normal vector to the surface at Xthe polygon, X.B object->face->normal. X XThe normal is constructed as the vector cross-product of the Xsecond edge of the polygon into the first. The sense of ordering of the Xvertices is counter-clockwise about the centroid of the polygon when the Xpositive sense of the normal indicates the 'outward' direction from a closed Xsurface. X XThe above convention is used by rendering/shading algorithms to economize on Xcalculations assuming polygons whose normal vectors are directed away from Xthe viewpoint will not be seen. This leads to 'directionally invisible' Xsurfaces when the inside of surfaces is exposed. The option of not culling Xbackward-facing polygons is useful in these situations, because the user is Xnot then obligated to create a double surface, one half of whose polygons are Xsimply ordered in reverse from the other half. X XErroneously backward-facing polygons are often difficult to detect in Xmodeling programs. The specification of connectivity to vertices and edges Xof polygons is the second one-third of the complete specification of the Xtopological connectivity of the object. The complete connectivity may be used Xto detect and correct polygons which deviate from the homogeneity of the Xsurface. X X.B object->texver Xis the list of texture vertices used by the object. A texture vertex is an Xindex into a texture map which may be a rectangular or cubic binary array or Xa stochastic or algorithmic texture generation scheme. X X.B object->line Xis the list of connected line segment elements in the object. The elements Xin this structure are similar in meaning to those in X.B object->face. XConnected line segment elements are not assumed to connect themselves. X X.B object->edge Xis the list of edges or intersections between pairs of adjacent polygons in Xthe object. X X.B object->edge->vertno Xand X.B object->edge->faceno Xspecify the indices of the two vertices in this edge and the polygons which Xintersect at this edge, as listed in the X.B object->vertex Xand X.B object->face Xarrays of structures. This is the last one-third which completes the Xspecification of the topological connectivity of the object. X X.B object->edge->length Xand X.B object->edge->theta Xare the length of the edge and the dihedral angle between the two polygons Xintersecting at this edge. These two values are used to simulate Xelasticity of the surface, calculated as a force proportional to the Xelongation of an edge from an at-rest length, and stiffness, calculated as a Xtorque about the edge proportional to the change in angle (moment of Xbending) between the two polygons at this edge, compared to an at-rest Xvalue. X XThe sense (sign) of the dihedral angle is defined as positive if the vector Xcross-product of the normal vector to polygon 0 into the normal vector to Xpolygon 1 has the same direction as the vector from vertex 0 to vertex 1 of Xthe edge and negative otherwise. X X.B object->point Xis the list of point elements in the object. X X.B object->circl Xis the list of circular arc elements in the object. These specify continuous Xcircular curves in three-space. The curves are assumed drawn in the Y-Z XCartesian plane then rotated using nested gimbals such that the X and Y Xaxes of the original frame of reference are aligned with the vectors X.B object->circl->x Xand X.B object->circl->y. X X.B object->circl->res Xis the specification of the drawing resolution to use by interactive Xdisplay programs or when expanding the arcs into connected line segments. X X.B object->spher Xis the list of sphere elements in the object. These specify continuous Xspherical surfaces in three-space. X X.B object->bicub Xis the list of bi-parametric cubic spline surface patch elements used by Xthe object. The supported basis types describe continuous surfaces Xthrough the positioning of a four-by-four grid of control vertices in XCartesian three-space. X X.B object->bicub->type Xspecifies one of the three supported basis matrices used in drawing Xparametric cubic spline surfaces. The supported types are X.B BSPLINE, X.B BEZIER Xand X.B CARDINAL. XSee X.B REFERENCES Xfor further information. X X.B object->bicub->u_res Xand X.B object->bicub->v_res Xspecify the rectangular mesh resolution to use in interactive drawing Xprograms and in expanding the parametric surfaces to finite polygon Xapproximations. X X.B object->metadef Xsupplies the capability for the recursive definition of an object 'meta Xelement', or the description of a morphological type which is to be Xrepeated throughout the object. This feature allows a compact representation Xfor object instances as well as a language for high-level specification Xof object structure. The recursion implies that the morphological Xspecification can be hierarchical. X X.B object->metaref Xis a reference to or instance of an object meta-element. The orientation Xstructure specifies the orientation of the element in three-space, while the X.B object->metaref->meta Xpointer-to-structure allows elements defined in one level of recursion to Xbe references in another. X X.B object->metaop Xis an operation on object meta-elements. This is required in a descriptive Xmodeling system which performs Combinational Solid Geometry or other Xoperations as a means for defining form. X X.B object->metaop->function Xis the pointer to the function called to perform this operation. X X.B object->metaop->objarg Xis the standardized formal parameter interface used by object operator Xfunctions in this object modeling system. X X X.SH AUTHOR XStewart Dickson X.SH FILES X.nf X$SPD_DIR/include/topology.h X$SPD_DIR/src/obj_lib/alloc_obj.c X$SPD_DIR/src/obj_lib/rd_IGES.c X$SPD_DIR/src/obj_lib/rd_byu.c X$SPD_DIR/src/obj_lib/rd_gr.c X$SPD_DIR/src/obj_lib/rd_obj.c X$SPD_DIR/src/obj_lib/wt_IGES.c X$SPD_DIR/src/obj_lib/wt_byu.c X$SPD_DIR/src/obj_lib/wt_obj.c X X.SH SEE ALSO X.nf Xbyu2obj(1 local) Xgr2obj(1 local) Xsg2ds(1 local) Xvg2sg(1 local) Xwf2IGES(1 local) X Xalloc_obj(3 local) Xrd_IGES(3 local) Xrd_byu(3 local) Xrd_gr(3 local) Xrd_mtl(3 local) Xrd_obj(3 local) Xwt_IGES(3 local) Xwt_byu(3 local) Xwt_obj(3 local) X Xmaterials(5 local) X X.SH REFERENCES X XSilicon Graphics IRIS Graphics Library Programming Guide X XFoley and Dan Dam, X.ul XFundamentals of Interactive Computer Graphics, X1982, Addison-Wesley, (Chapter 13.5-6, Parametric Cubic Curves and Surfaces) !EOR! echo extracting man/man5/poly.man echo mkdir ./man mkdir ./man echo mkdir ./man/man5 mkdir ./man/man5 sed 's/^X//' > man/man5/poly.man << '!EOR!' X.TH POLY 5 X.SH NAME Xpoly \- polyhedron database X.SH DESCRIPTION XThe directory X.B /usr/lib/polyhedra Xcontains an index file and many polyhedron description files. XThe index file consists of lines composed of the polyhedron number followed Xby a horizontal tab and the polyhedron's name. XThe polyhedron's number is also the name of its description file. XThe routines of X.IR poly (3) Xread such description files. X.PP XThe description file consists of a number of fields. XA field header is a line with an initial X.B : . XThe remainder of the line is the field name. XFields start with a field header line and are terminated by the next field header line Xor by end of file. XA polyhedron's description is terminated by the field X.B EOF . XThe fields include, Xbut are not limited to, X.TP 12n X.B number Xthe polyhedron's number (written and read with the X.B %d Xprintf/scanf format). X.TP X.B name Xthe polyhedron's name is less than 128 characters long and is not capitalized. X.TP X.B symbol Xthe X.IR eqn (1) Xinput for two symbols separated by a tab; Xthe Johnson symbol, and the Schla\*:fli symbol. X.TP X.B dual Xthe name of the dual polyhedron optionally followed by a horizontal tab Xand the number of the dual. X.TP X.B vertices Xthe first line contains the total number of vertices in the database entry and Xan optional second number indicating the number of vertices in the solid Xseparate from the planar net. The vertices are arranged one per line as an X.RI ( x ,\fIy\fR, z ) Xcoordinate of white-space Xseparated values (described below). XThe vertices are implicitly numbered starting at zero. X.TP X.B svertices Xthe following line contains the total number of vertices, and an itemized list Xof vertices with various valences. X.TP X.B net Xthe first line contains the number of faces and the maximum number of Xvertices in a face. XThe remaining lines are the faces in the planar net. XEach face has a vertex count followed by the vertex numbers. XThe vertices are listed in counter-clockwise order Xas viewed from outside the polyhedron. X.TP X.B sfaces Xthe following line contains the total number of faces followed by an itemized Xlist of the number of faces having various numbers of sides in the form: Xnumber_of_faces{number_of_sides} number_of_faces{number_of_sides}... X.TP X.B hinges Xthe first line contains the number of hinges in the planar net. XThe remaining lines are hinge connections. XThe format is X.IR "face1 side1 face2 side2 value" . XSides are numbered from zero. XIf the dihedral X.RI ( value ) Xis greater than \(*p, it is a reflex or re-entrant hinge. X.TP X.B solid Xthe first line contains the number of faces and the maximum number of Xvertices in a face. XThe remaining lines are the faces in the 3D polyhedron. XEach face has a vertex count followed by the vertex numbers. XThe vertices are listed in counter-clockwise order Xas viewed from outside the polyhedron. X.TP X.B dihedral Xthe first line contains the number of distinct dihedrals. XEach dihedral starts on a new line and has a count and a value. XIf the count is non-zero, Xthen that many X.I "face edge" Xpairs (one per line) follow the dihedral value. X.TP X.B EOF Xthe end of the polyhedron's description. X.PP XA value consists of a floating point number Xoptionally followed by a expression enclosed by X.B [] . XThe expression is the exact value represented in X.IR bc (1) Xcode with the following function meanings: X.EQ Xa(x) ~=~ {tan sup -1 {( x )}}, X.EN X.EQ Xb(x) ~=~ { ( x ) } sup { 1/3 }, X.EN X.EQ Xc(x) ~=~ {cos ( {x} ) }, X.EN X.EQ Xd(x) ~=~ {tan {( x )}}, X.EN X.EQ Xp ~=~ {pi}, X.EN X.EQ Xq(x) ~=~ {{x} sup 2}, X.EN X.EQ Xr(x) ~=~ {cos sup -1 {( x )}}, X.EN X.EQ Xs(x) ~=~ {sin ( {x} )}, X.EN X.EQ Xt ~=~ {phi}. X.EN XThe code may include assignments but does not include white space. X.SH FILES X.ta 31n X.F "/usr/lib/polyhedra/index " Xindex file X.br X.F "/usr/lib/polyhedra/[0-9]* " Xdescription files X.SH "SEE ALSO" Xpoly(3), Xpoly(7) X !EOR! echo extracting man/man5/Make.poly2obj echo mkdir ./man mkdir ./man echo mkdir ./man/man5 mkdir ./man/man5 sed 's/^X//' > man/man5/Make.poly2obj << '!EOR!' X# file: $SPD_DIR/man/man5/Make.poly2obj X X# description: instructions for printing section 5 of the Stewart Dickson X# 3D graphical modeling package X X# author: Stewart Dickson X Xobjects: objects.sl X troff -man -t objects.sl | rsh tpg lpr -t X Xpoly: poly.man X eqn poly.man |troff -man -t |rsh tpg lpr -t !EOR!