Home Overview FAQ Documentation Download Mailing List Geomview For Windows? Support Users Development Bug Reporting Contributing Contact Us Sponsors
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Closed REQ 5922]: Geomview question
Also-Cc: Glad you like it! As for internal manipulations on PolyList or other objects, there isn't much, aside from the pointlist(3) routines in include/pointlist.h. To deal with connectivity information, you'd have to write your own code that looked into the polylist data structure; see include/polylistP.h. We don't have much internal documentation; generally you just need to read the include-files. Here's a program that does something like what you'd need. It gives examples of using the PolyList data structure, and of some other OOGL library routines. #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: Makefile adjacent.c # Wrapped by slevy at euclid on Sun Jul 28 14:48:15 1996 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(347 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' X# Set up for your site & machine type XGEOM = /u/gcg/ngrap XMACHTYPE = sgi X X# -DTEST => Compile the test program, too XCFLAGS = -I${GEOM}/include -g -DTEST X XLIBS = -L${GEOM}/lib/${MACHTYPE} \ X -lstubdraw -lgeom -lpolylist -lbbox \ X -lstub -lgeom -lbbox -lshade -l3d -lcolor -loogl -lm X Xadjacent: adjacent.o X ${CC} -o $@ ${CFLAGS} adjacent.o ${LIBS} END_OF_FILE if test 347 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'adjacent.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'adjacent.c'\" else echo shar: Extracting \"'adjacent.c'\" \(3855 characters\) sed "s/^X//" >'adjacent.c' <<'END_OF_FILE' X/* This could go in a header file... */ X#include "geom.h" X X/* X * Construct table of adjacencies for a PolyList object X * (loaded from an OFF file). Returns NULL if given a non-PolyList. X */ Xextern struct adjs *PLadjacencies(Geom *polylist); X X/* X * Return 1 if v0 is adjacent to v1, otherwise 0. X */ Xextern int is_adj(struct adjs *, int v0, int v1); X/* X * Define v0 as being adjacent to v1. X * Return 1 if we already knew that, otherwise 0. X */ Xextern int add_adj(struct adjs *, int v0, int v1); X X X/* And here's the source, which reads the internals of PolyList objects */ X#include "polylistP.h" X/* #include "adjacent.h" if you put the above in something like that */ X X/* X * We represent adjacencies with an array of "vvec"s -- variable-length X * vectors, as described in ooglutil.h. We have an array of vvecs; X * the array is indexed by vertex number, and the i'th vvec contains a list X * of vertex-numbers of other vertices adjacent (along some polylist edge) X * to vertex i. X */ Xstruct adjs { X Geom *pl; /* The PolyList object, loaded via e.g. GeomFLoad() */ X int nverts; /* number of vertices */ X vvec *adj; /* array of variable-length vectors, each holding int's */ X}; X X X/* We assume adjacencies are symmetrical; to save space we only store X * adjacencies(i,j) where i < j. X */ X X/* X * Return 1 if v0 is adjacent to v1, otherwise 0. X */ Xint Xis_adj(struct adjs *adj, int v0, int v1) X{ X int *vp, nadj, i; X X if(adj == NULL || v0 < 0 || v0 > adj->nverts || v1 < 0 || v1 > adj->nverts) X return 0; X if(v0 > v1) { X i = v1; X v1 = v0; X v0 = i; X } X vp = VVEC(adj->adj[v0], int); X nadj = VVCOUNT(adj->adj[v0]); X for(i = 0; i < nadj; i++) X if(vp[i] == v1) X return 1; X return 0; X} X X/* X * Define v0 as being adjacent to v1. X * Return 1 if we already knew that, otherwise 0. X */ Xint Xadd_adj(struct adjs *adj, int v0, int v1) X{ X int *vp, nadj, i; X X if(adj == NULL || v0 < 0 || v0 > adj->nverts || v1 < 0 || v1 > adj->nverts) X return 0; X if(v0 > v1) { X i = v1; X v1 = v0; X v0 = i; X } X vp = VVEC(adj->adj[v0], int); X nadj = VVCOUNT(adj->adj[v0]); X for(i = 0; i < nadj; i++) X if(vp[i] == v1) X return 1; X *VVAPPEND(adj->adj[v0], int) = v1; X return 0; X} X Xstruct adjs * XPLadjacencies(Geom *g) X{ X struct adjs *adj; X Poly *p; X int i, j; X /* Is this really a PolyList? */ X if(g == NULL || strcmp(GeomName(g), "polylist") != 0) X return NULL; X X#define gpl ((PolyList *)g) X X adj = OOGLNewE(struct adjs, "PL adjacencies"); X adj->pl = g; X adj->nverts = gpl->n_verts; X adj->adj = OOGLNewNE(vvec, adj->nverts, "PL adjacencies vvecs"); X X /* Initialize each vvec as an array of int's, initial length 10 */ X for(i = 0; i < gpl->n_verts; i++) X VVINIT(adj->adj[i], int, 10); X X /* Loop over all polylist faces */ X for(j = 0; j < gpl->n_polys; j++) { X Poly *p = &gpl->p[j]; X X /* Vertices in each face are saved as pointers into the "vl" array of X * all vertices of the polyhedron; subtract to get vertex number. X */ X int prevvno = (p->v[p->n_vertices-1] - gpl->vl); X for(i = 0; i < p->n_vertices; i++) { X int vno = (p->v[i] - gpl->vl); X add_adj(adj, prevvno, vno); X prevvno = vno; X } X } X return adj; X} X X#ifdef TEST X X/* test program: loads an OFF file, accepts pairs of vertex numbers */ Xmain(int argc, char *argv[]) X{ X Geom *g = GeomLoad(argv[1]); X struct adjs *adj = PLadjacencies(g); X int v0, v1; X X if(g == NULL) { X fprintf(stderr, "%s: %s: Couldn't load\n", argv[0], argv[1]); X exit(1); X } X if(adj == NULL) { X fprintf(stderr, "%s: %s isn't an OFF file\n", argv[0], argv[1]); X exit(1); X } X printf("Enter pairs of vertex numbers (in the range 0..%d)\n", X adj->verts - 1); X for(;;) { X printf("v0 v1 : "); X if(scanf("%d %d", &v0, &v1) < 2) X break; X printf("vertices %d and %d are%s adjacent\n", v0, v1, X is_adj(adj, v0, v1) ? "" : " not"); X } X exit(0); X} X#endif END_OF_FILE if test 3855 -ne `wc -c <'adjacent.c'`; then echo shar: \"'adjacent.c'\" unpacked with wrong size! fi # end of 'adjacent.c' fi echo shar: End of shell archive. exit 0
|
||
Home | Overview | FAQ | Documentation | Support | Download | Mailing List Windows? | Development | Bug Reporting | Contributing | Contact Us | Sponsors |
|||
site hosted by |