Update of /cvsroot/teem/teem/src/limn In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8142 Modified Files: GNUmakefile io.c limn.h methodsLimn.c obj.c renderLimn.c shapes.c transform.c Log Message: sorry, beginning debugging of limnObject re-write Index: GNUmakefile =================================================================== RCS file: /cvsroot/teem/teem/src/limn/GNUmakefile,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** GNUmakefile 9 Feb 2004 07:02:05 -0000 1.16 --- GNUmakefile 9 Feb 2004 22:48:01 -0000 1.17 *************** *** 47,52 **** $(L).PUBLIC_HEADERS = limn.h $(L).PRIVATE_HEADERS = ! $(L).OBJS = defaultsLimn.o qn.o light.o env.o cam.o methodsLimn.o obj.o io.o \ ! hestLimn.o transform.o shapes.o renderLimn.o \ splineMisc.o splineMethods.o splineEval.o $(L).TESTS = test/map test/light test/tcam test/tps test/tspline test/tbc \ --- 47,52 ---- $(L).PUBLIC_HEADERS = limn.h $(L).PRIVATE_HEADERS = ! $(L).OBJS = defaultsLimn.o qn.o light.o env.o cam.o methodsLimn.o \ ! obj.o transform.o shapes.o renderLimn.o io.o hestLimn.o \ splineMisc.o splineMethods.o splineEval.o $(L).TESTS = test/map test/light test/tcam test/tps test/tspline test/tbc \ Index: io.c =================================================================== RCS file: /cvsroot/teem/teem/src/limn/io.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** io.c 9 Feb 2004 07:06:18 -0000 1.8 --- io.c 9 Feb 2004 22:48:01 -0000 1.9 *************** *** 22,60 **** int ! limnObjDescribe(FILE *file, limnObj *obj) { ! int j, i, vi; ! limnFace *f; ! limnEdge *e; ! limnPoint *p; ! limnPart *r; ! fprintf(file, "parts: %d\n", obj->rA->len); ! for (j=0; j<=obj->rA->len-1; j++) { ! r = &(obj->r[j]); ! fprintf(file, "%d | points: %d\n", j, r->pNum); ! for (i=0; i<=r->pNum-1; i++) { ! p = &(obj->p[r->pBase + i]); ! fprintf(file, "%d | %d(%d): w=(%g,%g,%g)\tv=(%g,%g,%g)\ts(%g,%g,%g)\n", ! j, i, r->pBase + i, ! p->w[0], p->w[1], p->w[2], ! p->v[0], p->v[1], p->v[2], ! p->s[0], p->s[1], p->s[2]); } ! fprintf(file, "%d | edges: %d\n", j, r->eNum); ! for (i=0; i<=r->eNum-1; i++) { ! e = &(obj->e[r->eBase + i]); ! fprintf(file, "%d | %d(%d): vert(%d,%d), face(%d,%d)\n", ! j, i, r->eBase + i, e->v0, e->v1, e->f0, e->f1); } ! fprintf(file, "%d | faces: %d\n", j, r->fNum); ! for (i=0; i<=r->fNum-1; i++) { ! f = &(obj->f[r->fBase + i]); ! fprintf(file, "%d | %d(%d): [", j, i, r->fBase + i); ! for (vi=0; vi<=f->vNum-1; vi++) { ! fprintf(file, "%d", obj->v[f->vBase + vi]); ! if (vi < f->vNum-1) fprintf(file, ","); } ! fprintf(file, "]; wn = (%g,%g,%g)\n", f->wn[0], f->wn[1], f->wn[2]); } } --- 22,64 ---- int ! limnObjectDescribe(FILE *file, limnObject *obj) { ! limnFace *face; int si, fii; ! limnEdge *edge; int eii; ! limnVertex *vert; int vii; ! limnPart *part; int partIdx; ! fprintf(file, "parts: %d\n", obj->partNum); ! for (partIdx=0; partIdx<obj->partNum; partIdx++) { ! part = obj->part + partIdx; ! fprintf(file, "part %d | verts: %d ========\n", partIdx, part->vertIdxNum); ! for (vii=0; vii<part->vertIdxNum; vii++) { ! vert = obj->vert + part->vertIdx[vii]; ! fprintf(file, "part %d | %d(%d): " ! "w=(%g,%g,%g)\tv=(%g,%g,%g)\ts(%g,%g,%g)\n", ! partIdx, vii, part->vertIdx[vii], ! vert->world[0], vert->world[1], vert->world[2], ! vert->view[0], vert->view[1], vert->view[2], ! vert->screen[0], vert->screen[1], vert->screen[2]); } ! fprintf(file, "part %d | edges: %d ========\n", partIdx, part->edgeIdxNum); ! for (eii=0; eii<part->edgeIdxNum; eii++) { ! edge = obj->edge + part->edgeIdx[eii]; ! fprintf(file, "part %d | %d(%d): " ! "vert(%d,%d), face(%d,%d)\n", ! partIdx, eii, part->edgeIdx[eii], ! edge->vertIdxIdx[0], edge->vertIdxIdx[1], ! edge->faceIdxIdx[0], edge->faceIdxIdx[1]); } ! fprintf(file, "part %d | faces: %d ========\n", partIdx, part->faceIdxNum); ! for (fii=0; fii<part->faceIdxNum; fii++) { ! face = obj->face + part->faceIdx[fii]; ! fprintf(file, "part %d | %d(%d): [", partIdx, fii, part->faceIdx[fii]); ! for (si=0; si<face->sideNum; si++) { ! fprintf(file, "%d", part->vertIdx[face->vertIdxIdx[si]]); ! if (si < face->sideNum-1) fprintf(file, ","); } ! fprintf(file, "]; wn = (%g,%g,%g)\n", face->worldNormal[0], ! face->worldNormal[1], face->worldNormal[2]); } } *************** *** 64,72 **** int ! limnObjOFFWrite(FILE *file, limnObj *obj) { ! char me[]="limnObjOFFWrite", err[AIR_STRLEN_MED]; ! int ii, vi; ! limnPoint *p; ! limnFace *f; if (!( obj && file )) { --- 68,77 ---- int ! limnObjectOFFWrite(FILE *file, limnObject *obj) { ! char me[]="limnObjectOFFWrite", err[AIR_STRLEN_MED]; ! int si; ! limnVertex *vert; int vii; ! limnFace *face; int fii; ! limnPart *part; int partIdx; if (!( obj && file )) { *************** *** 74,87 **** biffAdd(LIMN, err); return 1; } ! fprintf(file, "OFF\n"); ! fprintf(file, "%d %d -1\n", obj->pA->len, obj->fA->len); for (ii=0; ii<obj->pA->len; ii++) { p = obj->p + ii; fprintf(file, "%g %g %g", p->w[0]/p->w[3], p->w[1]/p->w[3], p->w[2]/p->w[3]); ! if (p->sp) { /* its a non-default color */ ! fprintf(file, " %g %g %g", obj->s[p->sp].rgba[0], ! obj->s[p->sp].rgba[1], obj->s[p->sp].rgba[2]); } fprintf(file, "\n"); --- 79,142 ---- biffAdd(LIMN, err); return 1; } ! fprintf(file, "OFF # created by teem/limn\n"); ! /* there will be (obj->partNum - 1) dummy vertices marking ! the boundary between different parts */ ! fprintf(file, "%d %d %d\n", obj->vertNum + obj->partNum - 1, ! obj->faceNum, obj->edgeNum); ! ! /* write vertices */ ! for (partIdx=0; partIdx<obj->partNum; partIdx++) { ! part = obj->part + partIdx; ! for (vii=0; vii<part->vertIdxNum; vii++) { ! vert = obj->vert + part->vertIdx[vii]; ! fprintf(file, "%g %g %g", ! vert->world[0]/vert->world[3], ! vert->world[1]/vert->world[3], ! vert->world[2]/vert->world[3]); ! if (vert->lookIdx) { ! /* its a non-default color */ ! fprintf(file, " %g %g %g", ! obj->look[vert->lookIdx].rgba[0], ! obj->look[vert->lookIdx].rgba[1], ! obj->look[vert->lookIdx].rgba[2]); ! } ! fprintf(file, "\n"); ! } ! /* dummy vertex, but not after last part */ ! if (partIdx<obj->partNum-1) { ! fprintf(file, "666 666 666 # end part %d\n", partIdx); ! } ! } ! ! /* write faces */ ! for (partIdx=0; partIdx<obj->partNum; partIdx++) { ! part = obj->part + partIdx; ! for (fii=0; fii<part->faceIdxNum; fii++) { ! face = obj->face + part->faceIdx[fii]; ! fprintf(file, "%d", face->sideNum); ! for (si=0; si<face->sideNum; si++) { ! fprintf(file, " %d", part->vertIdx[face->vertIdxIdx[si]] + partIdx); ! } ! if (face->lookIdx) { ! fprintf(file, " %g %g %g", ! obj->look[face->lookIdx].rgba[0], ! obj->look[face->lookIdx].rgba[1], ! obj->look[face->lookIdx].rgba[2]); ! } ! fprintf(file, "\n"); ! } ! } ! ! #if 0 /* before the OFF vertex hijack to delineate parts */ for (ii=0; ii<obj->pA->len; ii++) { p = obj->p + ii; fprintf(file, "%g %g %g", p->w[0]/p->w[3], p->w[1]/p->w[3], p->w[2]/p->w[3]); ! if (p->lookIdx) { /* its a non-default color */ ! fprintf(file, " %g %g %g", ! obj->look[p->lookIdx].rgba[0], ! obj->look[p->lookIdx].rgba[1], ! obj->look[p->lookIdx].rgba[2]); } fprintf(file, "\n"); *************** *** 94,112 **** } if (f->sp) { ! fprintf(file, " %g %g %g", obj->s[f->sp].rgba[0], ! obj->s[f->sp].rgba[1], obj->s[f->sp].rgba[2]); } fprintf(file, "\n"); } return 0; } int ! limnObjOFFRead(limnObj *obj, FILE *file) { ! char me[]="limnObjOFFRead", err[AIR_STRLEN_MED]; double vert[6]; ! char line[AIR_STRLEN_LARGE]; /* HEY: bad bad Gordon */ ! int si, lret, nvert, nface, ii, got, ibuff[512]; /* HEY: bad bad Gordon */ float fbuff[512]; /* HEY: bad bad Gordon */ if (!( obj && file )) { --- 149,174 ---- } if (f->sp) { ! fprintf(file, " %g %g %g", ! obj->look[f->lookIdx].rgba[0], ! obj->look[f->lookIdx].rgba[1], ! obj->look[f->lookIdx].rgba[2]); } fprintf(file, "\n"); } + #endif + return 0; } int ! limnObjectOFFRead(limnObject *obj, FILE *file) { ! char me[]="limnObjectOFFRead", err[AIR_STRLEN_MED]; double vert[6]; ! char line[AIR_STRLEN_LARGE]; /* HEY: bad Gordon */ ! int lookIdx, ri, lret, nvert, nface, ii, got; ! int ibuff[512]; /* HEY: bad Gordon */ float fbuff[512]; /* HEY: bad bad Gordon */ + int *rlut; + airArray *mop; if (!( obj && file )) { *************** *** 124,128 **** nvert = ibuff[0]; nface = ibuff[1]; ! limnObjPartStart(obj); for (ii=0; ii<nvert; ii++) { do { --- 186,194 ---- nvert = ibuff[0]; nface = ibuff[1]; ! ! mop = airMopNew(); ! rlut = (int*)calloc(nvert, sizeof(int)); ! airMopAdd(mop, rlut, airFree, airMopAlways); ! ri = -1; /* ssh */ for (ii=0; ii<nvert; ii++) { do { *************** *** 132,136 **** sprintf(err, "%s: hit EOF trying to read vert %d (of %d)", me, ii, nvert); ! biffAdd(LIMN, err); return 1; } if (3 != airParseStrD(vert, line, AIR_WHITESPACE, 3)) { --- 198,202 ---- sprintf(err, "%s: hit EOF trying to read vert %d (of %d)", me, ii, nvert); ! biffAdd(LIMN, err); airMopError(mop); return 1; } if (3 != airParseStrD(vert, line, AIR_WHITESPACE, 3)) { *************** *** 138,151 **** "for vert %d (of %d)", me, line, ii, nvert); ! biffAdd(LIMN, err); return 1; } if (6 == airParseStrD(vert, line, AIR_WHITESPACE, 6)) { /* we could also parse an RGB color */ ! si = limnObjSPAdd(obj); ! ELL_4V_SET(obj->s[si].rgba, vert[3], vert[4], vert[5], 1); } else { ! si = 0; } ! limnObjPointAdd(obj, si, vert[0], vert[1], vert[2]); } for (ii=0; ii<nface; ii++) { --- 204,221 ---- "for vert %d (of %d)", me, line, ii, nvert); ! biffAdd(LIMN, err); airMopError(mop); return 1; ! } ! if (!ii || (666 == vert[0] && 666 == vert[1] && 666 == vert[2])) { ! ri = limnObjectPartAdd(obj); } + rlut[ii] = ri; if (6 == airParseStrD(vert, line, AIR_WHITESPACE, 6)) { /* we could also parse an RGB color */ ! lookIdx = limnObjectLookAdd(obj); ! ELL_4V_SET(obj->look[lookIdx].rgba, vert[3], vert[4], vert[5], 1); } else { ! lookIdx = 0; } ! limnObjectVertexAdd(obj, ri, lookIdx, vert[0], vert[1], vert[2]); } for (ii=0; ii<nface; ii++) { *************** *** 156,160 **** sprintf(err, "%s: hit EOF trying to read face %d (of %d)", me, ii, nface); ! biffAdd(LIMN, err); return 1; } if (1 != sscanf(line, "%d", &nvert)) { --- 226,230 ---- sprintf(err, "%s: hit EOF trying to read face %d (of %d)", me, ii, nface); ! biffAdd(LIMN, err); airMopError(mop); return 1; } if (1 != sscanf(line, "%d", &nvert)) { *************** *** 162,166 **** "for face %d (of %d)", me, line, ii, nface); ! biffAdd(LIMN, err); return 1; } if (nvert+1 != airParseStrI(ibuff, line, AIR_WHITESPACE, nvert+1)) { --- 232,236 ---- "for face %d (of %d)", me, line, ii, nface); ! biffAdd(LIMN, err); airMopError(mop); return 1; } if (nvert+1 != airParseStrI(ibuff, line, AIR_WHITESPACE, nvert+1)) { *************** *** 168,185 **** "for face %d (of %d)", me, nvert+1, line, ii, nface); ! biffAdd(LIMN, err); return 1; } if (nvert+1+3 == airParseStrF(fbuff, line, AIR_WHITESPACE, nvert+1+3)) { /* could also parse color */ ! si = limnObjSPAdd(obj); ! ELL_4V_SET(obj->s[si].rgba, fbuff[nvert+1+0], fbuff[nvert+1+1], fbuff[nvert+1+2], 1); } else { ! si = 0; } ! limnObjFaceAdd(obj, si, nvert, ibuff+1); } - limnObjPartFinish(obj); return 0; } --- 238,255 ---- "for face %d (of %d)", me, nvert+1, line, ii, nface); ! biffAdd(LIMN, err); airMopError(mop); return 1; } if (nvert+1+3 == airParseStrF(fbuff, line, AIR_WHITESPACE, nvert+1+3)) { /* could also parse color */ ! lookIdx = limnObjectLookAdd(obj); ! ELL_4V_SET(obj->look[lookIdx].rgba, fbuff[nvert+1+0], fbuff[nvert+1+1], fbuff[nvert+1+2], 1); } else { ! lookIdx = 0; } ! limnObjectFaceAdd(obj, rlut[ibuff[1]], lookIdx, nvert, ibuff+1); } + airMopOkay(mop); return 0; } Index: limn.h =================================================================== RCS file: /cvsroot/teem/teem/src/limn/limn.h,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** limn.h 9 Feb 2004 07:06:18 -0000 1.45 --- limn.h 9 Feb 2004 22:48:01 -0000 1.46 *************** *** 140,144 **** typedef struct { float lineWidth[LIMN_EDGE_TYPE_MAX+1], - haloWidth[LIMN_EDGE_TYPE_MAX+1], creaseAngle, /* difference between crease and facet, in *degrees* */ bg[3]; /* background color */ --- 140,143 ---- *************** *** 147,151 **** } limnOptsPS; ! typedef struct limnWin_t { limnOptsPS ps; int device; --- 146,150 ---- } limnOptsPS; ! typedef struct { limnOptsPS ps; int device; *************** *** 153,157 **** int yFlip; FILE *file; ! } limnWin; enum { --- 152,156 ---- int yFlip; FILE *file; ! } limnWindow; enum { *************** *** 165,169 **** /* ! ******** struct limnPoint ** ** all the information you might want for a point --- 164,180 ---- /* ! ******** struct limnLook ! ** ! ** surface properties: pretty much anything having to do with ! ** appearance, for points, edges, faces, etc. ! */ ! typedef struct { ! float rgba[4]; ! float kads[3], /* phong: ka, kd, ks */ ! spow; /* specular power */ ! } limnLook; ! ! /* ! ******** struct limnVertex ** ** all the information you might want for a point *************** *** 171,182 **** ** Has no dynamically allocated information or pointers */ ! typedef struct limnPoint_t { ! float w[4], /* world coordinates (homogeneous) */ ! v[4], /* view coordinates */ ! s[3], /* screen coordinates (device independant) */ ! d[2], /* device coordinates */ ! n[3]; /* vertex normal (world coords only) */ ! int sp; /* index into parent's SP list */ ! } limnPoint; /* --- 182,194 ---- ** Has no dynamically allocated information or pointers */ ! typedef struct { ! float world[4], /* world coordinates (homogeneous) */ ! view[4], /* view coordinates */ ! screen[3], /* screen coordinates (device independant) */ ! device[2], /* device coordinates */ ! worldNormal[3]; /* vertex normal (world coords only) */ ! int lookIdx, /* index into parent's look array */ ! partIdx; ! } limnVertex; /* *************** *** 188,196 **** */ typedef struct limnEdge_t { ! int v0, v1, /* two point indices (in parent's point list) */ ! f0, f1, /* two face indices (in parent's face list) */ ! sp; /* index into parent's SP list */ ! ! int type; /* from the limnEdgeType enum */ } limnEdge; --- 200,208 ---- */ typedef struct limnEdge_t { ! int vertIdxIdx[2], faceIdxIdx[2], ! lookIdx, /* index into parent's look array */ ! partIdx; ! int type, /* from the limnEdgeType enum */ ! once; /* flag used for certain kinds of rendering */ } limnEdge; *************** *** 203,213 **** */ typedef struct limnFace_t { ! float wn[3], /* normal in world space */ ! sn[3]; /* normal in screen space (post-perspective-divide) */ ! int vBase, vNum, /* start and length in parent's vertex array, "v" */ ! sp; /* index into parent's SP list, "s" */ ! ! int visib; /* is face currently visible (AIR_TRUE or AIR_FALSE) */ ! float z; /* for depth ordering */ } limnFace; --- 215,228 ---- */ typedef struct limnFace_t { ! float worldNormal[3], ! screenNormal[3]; ! int *vertIdxIdx, /* normal array (not airArray) of indices (in part's ! vertIdx) vertex indices (in object's vert) */ ! *edgeIdxIdx, /* likewise for edges */ ! sideNum; /* number of sides (allocated length of {vert,edge}IdxIdx */ ! int lookIdx, ! partIdx; ! int visible; /* is face currently visible (AIR_TRUE or AIR_FALSE) */ ! float depth; } limnFace; *************** *** 218,246 **** */ typedef struct limnPart_t { ! int fBase, fNum, /* start and length in parent's limnFace array, "f" */ ! eBase, eNum, /* start and length in parent's limnEdge array, "e" */ ! pBase, pNum, /* start and length in parent's limnPoint array, "p" */ ! origIdx; /* initial part index of this part */ ! ! float z; /* assuming that the occlusion graph between ! whole parts is acyclic, one depth value is ! good enough for painter's algorithm ordering ! of drawing */ ! int sp; /* index into parent's SP list, "s" */ } limnPart; /* ! ******** struct limnSP ! ** ! ** "surface" properties: pretty much anything having to do with ! ** appearance, for points, edges, faces, etc. ! */ ! typedef struct limnSP_t { ! float rgba[4]; ! float k[3], spec; ! } limnSP; ! ! /* ! ******** struct limnObj ** ** the beast used to represent polygonal objects --- 233,246 ---- */ typedef struct limnPart_t { ! int *vertIdx, vertIdxNum, ! *edgeIdx, edgeIdxNum, ! *faceIdx, faceIdxNum; ! airArray *vertIdxArr, *edgeIdxArr, *faceIdxArr; ! int lookIdx; ! float depth; } limnPart; /* ! ******** struct limnObject ** ** the beast used to represent polygonal objects *************** *** 248,275 **** ** Relies on many dynamically allocated arrays */ ! typedef struct limnObj_t { ! limnPoint *p; /* array of point structs */ ! airArray *pA; /* airArray around "p" */ ! ! int *v; /* array of vertex indices for all faces */ ! airArray *vA; /* airArray around "v" */ ! limnEdge *e; /* array of edge structs */ ! airArray *eA; /* airArray around "e" */ ! limnFace *f; /* array of face structs */ ! airArray *fA; /* airArray around "f" */ ! int *fSort; /* indices into "f", sorted by depth */ ! limnPart *r; /* array of part structs */ ! airArray *rA; /* arrArray around "r" */ ! limnSP *s; /* array of surface properties */ ! airArray *sA; /* airArray around "s" */ ! ! limnPart *rCurr; /* pointer to part under construction */ ! int edges; /* if non-zero, build edges as faces are added */ ! } limnObj; /* --- 248,271 ---- ** Relies on many dynamically allocated arrays */ ! typedef struct { ! limnVertex *vert; int vertNum; ! airArray *vertArr; ! limnEdge *edge; int edgeNum; ! airArray *edgeArr; ! limnFace *face; int faceNum; ! airArray *faceArr; ! int *faceSort; /* indices into "face", sorted by depth */ ! limnPart *part; int partNum; ! airArray *partArr; ! limnLook *look; int lookNum; ! airArray *lookArr; ! int doEdges, /* if non-zero, build edges as faces are added */ ! incr; /* increment to use with airArrays */ ! } limnObject; /* *************** *** 390,395 **** extern limnCamera *limnCameraNew(void); extern limnCamera *limnCameraNix(limnCamera *cam); ! extern limnWin *limnWinNew(int device); ! extern limnWin *limnWinNix(limnWin *win); /* hestLimn.c */ --- 386,391 ---- extern limnCamera *limnCameraNew(void); extern limnCamera *limnCameraNix(limnCamera *cam); ! extern limnWindow *limnWindowNew(int device); ! extern limnWindow *limnWindowNix(limnWindow *win); /* hestLimn.c */ *************** *** 410,454 **** /* obj.c */ ! extern limnObj *limnObjNew(int incr, int edges); ! extern limnObj *limnObjNix(limnObj *obj); ! extern int limnObjPointAdd(limnObj *obj, int sp, float x, float y, float z); ! extern int limnObjEdgeAdd(limnObj *obj, int sp, int face, int v0, int v1); ! extern int limnObjFaceAdd(limnObj *obj, int sp, int numVert, int *vert); ! extern int limnObjSPAdd(limnObj *obj); ! extern int limnObjPartStart(limnObj *obj); ! extern int limnObjPartFinish(limnObj *obj); /* io.c */ ! extern int limnObjDescribe(FILE *file, limnObj *obj); ! extern int limnObjOFFRead(limnObj *obj, FILE *file); ! extern int limnObjOFFWrite(FILE *file, limnObj *obj); /* shapes.c */ ! extern int limnObjCubeAdd(limnObj *obj, int sp); ! extern int limnObjSquareAdd(limnObj *obj, int sp); ! extern int limnObjLoneEdgeAdd(limnObj *obj, int sp); ! extern int limnObjCylinderAdd(limnObj *obj, int sp, int axis,int res); ! extern int limnObjPolarSphereAdd(limnObj *obj, int sp, int axis, ! int thetaRes, int phiRes); ! extern int limnObjConeAdd(limnObj *obj, int sp, int axis, int res); ! extern int limnObjPolarSuperquadAdd(limnObj *obj, int sp, int axis, ! float A, float B, int thetaRes, int phiRes); /* transform.c */ ! extern int limnObjHomog(limnObj *obj, int space); ! extern int limnObjNormals(limnObj *obj, int space); ! extern int limnObjSpaceTransform(limnObj *obj, limnCamera *cam, limnWin *win, ! int space); ! extern int limnObjPartTransform(limnObj *obj, int ri, float tx[16]); ! extern int limnObjDepthSortParts(limnObj *obj); ! extern int limnObjDepthSortFaces(limnObj *obj); /* renderLimn.c */ ! extern int limnObjRender(limnObj *obj, limnCamera *cam, limnWin *win); ! extern int limnObjPSDrawOld(limnObj *obj, limnCamera *cam, ! Nrrd *envMap, limnWin *win); ! extern int limnObjPSDraw(limnObj *obj, limnCamera *cam, ! Nrrd *envMap, limnWin *win); /* splineMethods.c */ --- 406,453 ---- /* obj.c */ ! extern int limnObjectLookAdd(limnObject *obj); ! extern limnObject *limnObjectNew(int incr, int doEdges); ! extern limnObject *limnObjectNix(limnObject *obj); ! extern int limnObjectPartAdd(limnObject *obj); ! extern int limnObjectVertexAdd(limnObject *obj, int partIdx, int lookIdx, ! float x, float y, float z); ! extern int limnObjectEdgeAdd(limnObject *obj, int partIdx, int lookIdx, ! int faceIdxIdx, int vertIdxIdx0, int vertIdxIdx1); ! extern int limnObjectFaceAdd(limnObject *obj, int partIdx, ! int lookIdx, int sideNum, int *vertIdxIdx); /* io.c */ ! extern int limnObjectDescribe(FILE *file, limnObject *obj); ! extern int limnObjectOFFRead(limnObject *obj, FILE *file); ! extern int limnObjectOFFWrite(FILE *file, limnObject *obj); /* shapes.c */ ! extern int limnObjectCubeAdd(limnObject *obj, int lookIdx); ! extern int limnObjectSquareAdd(limnObject *obj, int lookIdx); ! extern int limnObjectLoneEdgeAdd(limnObject *obj, int lookIdx); ! extern int limnObjectCylinderAdd(limnObject *obj, int lookIdx, ! int axis,int res); ! extern int limnObjectPolarSphereAdd(limnObject *obj, int lookIdx, int axis, int thetaRes, int phiRes); + extern int limnObjectConeAdd(limnObject *obj, int lookIdx, int axis, int res); + extern int limnObjectPolarSuperquadAdd(limnObject *obj, int lookIdx, int axis, + float A, float B, + int thetaRes, int phiRes); /* transform.c */ ! extern int limnObjectHomog(limnObject *obj, int space); ! extern int limnObjectNormals(limnObject *obj, int space); ! extern int limnObjectSpaceTransform(limnObject *obj, limnCamera *cam, ! limnWindow *win, int space); ! extern int limnObjectPartTransform(limnObject *obj, int ri, float tx[16]); ! extern int limnObjectDepthSortParts(limnObject *obj); ! extern int limnObjectDepthSortFaces(limnObject *obj); /* renderLimn.c */ ! extern int limnObjectRender(limnObject *obj, limnCamera *cam, limnWindow *win); ! extern int limnObjectPSDraw(limnObject *obj, limnCamera *cam, ! Nrrd *envMap, limnWindow *win); ! extern int limnObjectPSDrawConcave(limnObject *obj, limnCamera *cam, ! Nrrd *envMap, limnWindow *win); /* splineMethods.c */ Index: methodsLimn.c =================================================================== RCS file: /cvsroot/teem/teem/src/limn/methodsLimn.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** methodsLimn.c 9 Feb 2004 07:06:18 -0000 1.10 --- methodsLimn.c 9 Feb 2004 22:48:01 -0000 1.11 *************** *** 79,90 **** ps->lineWidth[limnEdgeTypeBorder] = 1.0; ps->lineWidth[limnEdgeTypeLone] = 1.0; - ps->haloWidth[limnEdgeTypeUnknown] = AIR_NAN; - ps->haloWidth[limnEdgeTypeBackFacet] = 0.0; - ps->haloWidth[limnEdgeTypeBackCrease] = 0.0; - ps->haloWidth[limnEdgeTypeContour] = 0.0; - ps->haloWidth[limnEdgeTypeFrontCrease] = 0.0; - ps->haloWidth[limnEdgeTypeFrontFacet] = 0.0; - ps->haloWidth[limnEdgeTypeBorder] = 0.0; - ps->haloWidth[limnEdgeTypeLone] = 0.0; ps->creaseAngle = 46; ps->showpage = AIR_FALSE; --- 79,82 ---- *************** *** 93,101 **** } ! limnWin * ! limnWinNew(int device) { ! limnWin *win; ! win = (limnWin *)calloc(1, sizeof(limnWin)); if (win) { win->device = device; --- 85,93 ---- } ! limnWindow * ! limnWindowNew(int device) { ! limnWindow *win; ! win = (limnWindow *)calloc(1, sizeof(limnWindow)); if (win) { win->device = device; *************** *** 112,117 **** } ! limnWin * ! limnWinNix(limnWin *win) { if (win) { --- 104,109 ---- } ! limnWindow * ! limnWindowNix(limnWindow *win) { if (win) { Index: obj.c =================================================================== RCS file: /cvsroot/teem/teem/src/limn/obj.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** obj.c 9 Feb 2004 07:06:18 -0000 1.15 --- obj.c 9 Feb 2004 22:48:01 -0000 1.16 *************** *** 21,67 **** #include "limn.h" ! limnObj * ! limnObjNew(int incr, int edges) { ! limnObj *obj; ! obj = (limnObj *)calloc(1, sizeof(limnObj)); ! obj->p = NULL; ! obj->v = NULL; ! obj->e = NULL; ! obj->f = NULL; ! obj->fSort = NULL; ! obj->r = NULL; ! obj->s = NULL; /* create all various airArrays */ ! obj->pA = airArrayNew((void**)&(obj->p), NULL, ! sizeof(limnPoint), incr); ! obj->vA = airArrayNew((void**)&(obj->v), NULL, ! sizeof(int), incr); ! obj->eA = airArrayNew((void**)&(obj->e), NULL, ! sizeof(limnEdge), incr); ! obj->fA = airArrayNew((void**)&(obj->f), NULL, ! sizeof(limnFace), incr); ! obj->rA = airArrayNew((void**)&(obj->r), NULL, ! sizeof(limnPart), incr); ! obj->sA = airArrayNew((void**)&(obj->s), NULL, ! sizeof(limnSP), incr); ! obj->rCurr = NULL; ! obj->edges = edges; return obj; } ! limnObj * ! limnObjNix(limnObj *obj) { ! airArrayNuke(obj->pA); ! airArrayNuke(obj->vA); ! airArrayNuke(obj->eA); ! airArrayNuke(obj->fA); ! airFree(obj->fSort); ! airArrayNuke(obj->rA); ! airArrayNuke(obj->sA); free(obj); return NULL; --- 21,80 ---- #include "limn.h" ! int ! limnObjectLookAdd(limnObject *obj) { ! int lookIdx; ! limnLook *look; ! lookIdx = airArrayIncrLen(obj->lookArr, 1); ! look = &(obj->look[lookIdx]); ! ELL_4V_SET(look->rgba, 1, 1, 1, 1); ! ELL_3V_SET(look->kads, 0.5, 0.5, 0.0); ! look->spow = 50; ! return lookIdx; ! } ! ! ! limnObject * ! limnObjectNew(int incr, int doEdges) { ! limnObject *obj; ! ! obj = (limnObject *)calloc(1, sizeof(limnObject)); ! obj->vert = NULL; ! obj->edge = NULL; ! obj->face = NULL; ! obj->faceSort = NULL; ! obj->part = NULL; ! obj->look = NULL; /* create all various airArrays */ ! obj->vertArr = airArrayNew((void**)&(obj->vert), &(obj->vertNum), ! sizeof(limnVertex), incr); ! obj->edgeArr = airArrayNew((void**)&(obj->edge), &(obj->edgeNum), ! sizeof(limnEdge), incr); ! obj->faceArr = airArrayNew((void**)&(obj->face), &(obj->faceNum), ! sizeof(limnFace), incr); ! obj->partArr = airArrayNew((void**)&(obj->part), &(obj->partNum), ! sizeof(limnPart), incr); ! obj->lookArr = airArrayNew((void**)&(obj->look), &(obj->lookNum), ! sizeof(limnLook), incr); ! /* create (default) look 0 */ ! limnObjectLookAdd(obj); ! ! obj->doEdges = doEdges; ! obj->incr = incr; return obj; } ! limnObject * ! limnObjectNix(limnObject *obj) { ! airArrayNuke(obj->vertArr); ! airArrayNuke(obj->edgeArr); ! airArrayNuke(obj->faceArr); ! airFree(obj->faceSort); ! airArrayNuke(obj->partArr); ! airArrayNuke(obj->lookArr); free(obj); return NULL; *************** *** 69,197 **** int ! limnObjPartStart(limnObj *obj) { ! int rBase; ! limnPart *r; ! rBase = airArrayIncrLen(obj->rA, 1); ! r = &(obj->r[rBase]); ! r->fBase = obj->fA->len; r->fNum = 0; ! r->eBase = obj->eA->len; r->eNum = 0; ! r->pBase = obj->pA->len; r->pNum = 0; ! r->origIdx = rBase; ! r->sp = 0; ! obj->rCurr = r; ! return rBase; } int ! limnObjPointAdd(limnObj *obj, int sp, float x, float y, float z) { ! limnPoint *p; ! int pBase; ! ! pBase = airArrayIncrLen(obj->pA, 1); ! p = &(obj->p[pBase]); ! ELL_4V_SET(p->w, x, y, z, 1); ! ELL_3V_SET(p->v, AIR_NAN, AIR_NAN, AIR_NAN); ! ELL_3V_SET(p->s, AIR_NAN, AIR_NAN, AIR_NAN); ! ELL_3V_SET(p->n, AIR_NAN, AIR_NAN, AIR_NAN); ! p->d[0] = p->d[1] = AIR_NAN; ! p->sp = sp; ! obj->rCurr->pNum++; ! return pBase; ! } ! void ! _limnEdgeInit(limnEdge *e, int sp, int face, int v0, int v1) { ! ! e->v0 = v0; ! e->v1 = v1; ! e->f0 = face; ! e->f1 = -1; ! e->sp = sp; ! e->type = limnEdgeTypeUnknown; } int ! limnObjEdgeAdd(limnObj *obj, int sp, int face, int v0, int v1) { ! int ret, t, i, eNum, eBase; ! limnEdge *e=NULL; ! ! eBase = obj->rCurr->eBase; ! eNum = obj->rCurr->eNum; ! if (v0 > v1) { ! ELL_SWAP2(v0, v1, t); } ! ! /* do a linear search through this part's edges */ ! for (i=0; i<=eNum-1; i++) { ! e = &(obj->e[eBase+i]); ! if (e->v0 == v0 && e->v1 == v1) { break; } } ! if (i == eNum) { ! /* edge not found */ ! eBase = airArrayIncrLen(obj->eA, 1); ! e = &(obj->e[eBase]); ! _limnEdgeInit(e, sp, face, v0, v1); ! ret = eBase; ! obj->rCurr->eNum++; ! } ! else { ! /* edge already exists */ ! e->f1 = face; ! ret = eBase+i; } ! return ret; } int ! limnObjFaceAdd(limnObj *obj, int sp, int numVert, int *vert) { ! int i, vBase, fBase; ! limnFace *f; ! fBase = airArrayIncrLen(obj->fA, 1); ! vBase = airArrayIncrLen(obj->vA, numVert); ! f = &(obj->f[fBase]); ! ELL_3V_SET(f->wn, AIR_NAN, AIR_NAN, AIR_NAN); ! ELL_3V_SET(f->sn, AIR_NAN, AIR_NAN, AIR_NAN); ! f->vBase = vBase; ! f->vNum = numVert; ! for (i=0; i<=numVert-1; i++) { ! obj->v[vBase + i] = vert[i]; ! if (obj->edges) { ! limnObjEdgeAdd(obj, 1, fBase, vert[i], vert[AIR_MOD(i+1, numVert)]); } } ! f->sp = sp; ! f->visib = AIR_FALSE; ! obj->rCurr->fNum++; ! ! return fBase; ! } ! ! int ! limnObjPartFinish(limnObj *obj) { ! ! obj->rCurr = NULL; ! return 0; } - int - limnObjSPAdd(limnObj *obj) { - int sBase; - limnSP *s; - - sBase = airArrayIncrLen(obj->sA, 1); - s = &(obj->s[sBase]); - ELL_4V_SET(s->rgba, 1, 1, 1, 1); - ELL_3V_SET(s->k, 0.5, 0.5, 0.0); - s->spec = 50; - return sBase; - } --- 82,208 ---- int ! limnObjectPartAdd(limnObject *obj) { ! int partIdx; ! limnPart *part; ! partIdx = airArrayIncrLen(obj->partArr, 1); ! part = obj->part + partIdx; ! part->vertIdx = NULL; ! part->edgeIdx = NULL; ! part->faceIdx = NULL; ! part->vertIdxArr = airArrayNew((void**)&(part->vertIdx), &(part->vertIdxNum), ! sizeof(int), obj->incr); ! part->edgeIdxArr = airArrayNew((void**)&(part->edgeIdx), &(part->edgeIdxNum), ! sizeof(int), obj->incr); ! part->faceIdxArr = airArrayNew((void**)&(part->faceIdx), &(part->faceIdxNum), ! sizeof(int), obj->incr); ! part->lookIdx = 0; ! part->depth = AIR_NAN; ! ! return partIdx; } int ! limnObjectVertexAdd(limnObject *obj, int partIdx, int lookIdx, ! float x, float y, float z) { ! limnPart *part; ! limnVertex *vert; ! int vertIdx, vertIdxIdx; ! part = obj->part + partIdx; ! vertIdx = airArrayIncrLen(obj->vertArr, 1); ! vert = obj->vert + vertIdx; ! vertIdxIdx = airArrayIncrLen(part->vertIdxArr, 1); ! part->vertIdx[vertIdxIdx] = vertIdx; ! ELL_4V_SET(vert->world, x, y, z, 1); ! ELL_3V_SET(vert->view, AIR_NAN, AIR_NAN, AIR_NAN); ! ELL_3V_SET(vert->screen, AIR_NAN, AIR_NAN, AIR_NAN); ! ELL_3V_SET(vert->worldNormal, AIR_NAN, AIR_NAN, AIR_NAN); ! vert->device[0] = vert->device[1] = AIR_NAN; ! vert->partIdx = partIdx; ! vert->lookIdx = lookIdx; ! return vertIdxIdx; } int ! limnObjectEdgeAdd(limnObject *obj, int partIdx, int lookIdx, ! int faceIdxIdx, int vertIdxIdx0, int vertIdxIdx1) { ! int tmp, edgeIdx, edgeIdxIdx; ! limnEdge *edge=NULL; ! limnPart *part; ! part = obj->part + partIdx; ! if (vertIdxIdx0 > vertIdxIdx1) { ! ELL_SWAP2(vertIdxIdx0, vertIdxIdx1, tmp); } ! ! /* do a linear search through this part's existing edges */ ! for (edgeIdxIdx=0; edgeIdxIdx<part->edgeIdxNum; edgeIdxIdx++) { ! edgeIdx = part->edgeIdx[edgeIdxIdx]; ! edge = &(obj->edge[edgeIdx]); ! if (edge->vertIdxIdx[0] == vertIdxIdx0 ! && edge->vertIdxIdx[1] == vertIdxIdx1) { break; } } ! if (edgeIdxIdx == part->edgeIdxNum) { ! /* edge not found, add it */ ! edgeIdx = airArrayIncrLen(obj->edgeArr, 1); ! edge = &(obj->edge[edgeIdx]); ! edgeIdxIdx = airArrayIncrLen(part->edgeIdxArr, 1); ! part->edgeIdx[edgeIdxIdx] = edgeIdx; ! edge->vertIdxIdx[0] = vertIdxIdx0; ! edge->vertIdxIdx[1] = vertIdxIdx1; ! edge->faceIdxIdx[0] = faceIdxIdx; ! edge->faceIdxIdx[1] = -1; ! edge->lookIdx = lookIdx; ! edge->partIdx = partIdx; ! edge->type = limnEdgeTypeUnknown; ! edge->once = AIR_FALSE; ! } else { ! /* edge already exists; "edge", "edgeIdx", and "edgeIdxIdx" are all set */ ! edge->faceIdxIdx[1] = faceIdxIdx; } ! return edgeIdxIdx; } int ! limnObjectFaceAdd(limnObject *obj, int partIdx, ! int lookIdx, int sideNum, int *vertIdxIdx) { ! limnFace *face; ! limnPart *part; ! int faceIdx, faceIdxIdx, sideIdx; ! part = obj->part + partIdx; ! faceIdx = airArrayIncrLen(obj->faceArr, 1); ! face = &(obj->face[faceIdx]); ! faceIdxIdx = airArrayIncrLen(part->faceIdxArr, 1); ! part->faceIdx[faceIdxIdx] = faceIdx; ! face->vertIdxIdx = (int*)calloc(sideNum, sizeof(int)); ! if (obj->doEdges) { ! face->edgeIdxIdx = (int*)calloc(sideNum, sizeof(int)); ! } ! face->sideNum = sideNum; ! for (sideIdx=0; sideIdx<sideNum; sideIdx++) { ! face->vertIdxIdx[sideIdx] = vertIdxIdx[sideIdx]; ! if (obj->doEdges) { ! face->edgeIdxIdx[sideIdx] = ! limnObjectEdgeAdd(obj, partIdx, 0, faceIdxIdx, ! vertIdxIdx[sideIdx], ! vertIdxIdx[AIR_MOD(sideIdx+1, sideNum)]); } } ! ELL_3V_SET(face->worldNormal, AIR_NAN, AIR_NAN, AIR_NAN); ! ELL_3V_SET(face->screenNormal, AIR_NAN, AIR_NAN, AIR_NAN); ! face->lookIdx = lookIdx; ! face->partIdx = partIdx; ! face->visible = AIR_FALSE; ! face->depth = AIR_NAN; ! return faceIdx; } Index: renderLimn.c =================================================================== RCS file: /cvsroot/teem/teem/src/limn/renderLimn.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** renderLimn.c 9 Feb 2004 07:06:18 -0000 1.16 --- renderLimn.c 9 Feb 2004 22:48:01 -0000 1.17 *************** *** 22,27 **** int ! limnObjRender(limnObj *obj, limnCamera *cam, limnWin *win) { ! char me[]="limnObjRender", err[AIR_STRLEN_MED]; int E; --- 22,27 ---- int ! limnObjectRender(limnObject *obj, limnCamera *cam, limnWindow *win) { ! char me[]="limnObjectRender", err[AIR_STRLEN_MED]; int E; *************** *** 32,41 **** fprintf(stderr, "%s: true right = %g %g %g\n", me, cam->U[0], cam->U[1], cam->U[2]); ! if (!E) E |= limnObjHomog(obj, limnSpaceWorld); ! if (!E) E |= limnObjNormals(obj, limnSpaceWorld); ! if (!E) E |= limnObjSpaceTransform(obj, cam, win, limnSpaceView); ! if (!E) E |= limnObjSpaceTransform(obj, cam, win, limnSpaceScreen); ! if (!E) E |= limnObjSpaceTransform(obj, cam, win, limnSpaceDevice); ! if (!E) E |= limnObjNormals(obj, limnSpaceScreen); if (E) { sprintf(err, "%s: trouble", me); --- 32,41 ---- fprintf(stderr, "%s: true right = %g %g %g\n", me, cam->U[0], cam->U[1], cam->U[2]); ! if (!E) E |= limnObjectHomog(obj, limnSpaceWorld); ! if (!E) E |= limnObjectNormals(obj, limnSpaceWorld); ! if (!E) E |= limnObjectSpaceTransform(obj, cam, win, limnSpaceView); ! if (!E) E |= limnObjectSpaceTransform(obj, cam, win, limnSpaceScreen); ! if (!E) E |= limnObjectSpaceTransform(obj, cam, win, limnSpaceDevice); ! if (!E) E |= limnObjectNormals(obj, limnSpaceScreen); if (E) { sprintf(err, "%s: trouble", me); *************** *** 46,50 **** void ! _limnPSPreamble(limnObj *obj, limnCamera *cam, limnWin *win) { fprintf(win->file, "%%!PS-Adobe-2.0 EPSF-2.0\n"); --- 46,50 ---- void ! _limnPSPreamble(limnObject *obj, limnCamera *cam, limnWindow *win) { fprintf(win->file, "%%!PS-Adobe-2.0 EPSF-2.0\n"); *************** *** 83,87 **** void ! _limnPSEpilogue(limnObj *obj, limnCamera *cam, limnWin *win) { fprintf(win->file, "grestore\n"); --- 83,87 ---- void ! _limnPSEpilogue(limnObject *obj, limnCamera *cam, limnWindow *win) { fprintf(win->file, "grestore\n"); *************** *** 94,141 **** void ! _limnPSDrawFace(limnObj *obj, limnPart *r, limnFace *f, ! limnCamera *cam, Nrrd *nmap, limnWin *win) { ! int vi; ! limnPoint *p; ! limnSP *sp; int qn; float *map, R, G, B; ! for (vi=0; vi<f->vNum; vi++) { ! p = obj->p + obj->v[vi + f->vBase]; fprintf(win->file, "%g %g %s\n", ! p->d[0], p->d[1], vi ? "L" : "M"); } ! sp = obj->s + f->sp; ! /* ! fprintf(stderr, "RGB = %g %g %g ->", r->rgba[0], r->rgba[1], r->rgba[2]); ! */ ! R = sp->k[0]*sp->rgba[0]; ! G = sp->k[0]*sp->rgba[1]; ! B = sp->k[0]*sp->rgba[2]; ! /* ! fprintf(stderr, "RGB = %g %g %g ->", R, G, B); ! */ if (nmap) { ! qn = limnVtoQN_f[limnQN16checker](f->wn); map = nmap->data; ! R += sp->k[1]*sp->rgba[0]*map[0 + 3*qn]; ! G += sp->k[1]*sp->rgba[1]*map[1 + 3*qn]; ! B += sp->k[1]*sp->rgba[2]*map[2 + 3*qn]; } else { ! R += sp->k[1]*sp->rgba[0]; ! G += sp->k[1]*sp->rgba[1]; ! B += sp->k[1]*sp->rgba[2]; } /* HEY: not evaluating phong specular for now */ - /* - fprintf(stderr, "%g %g %g ->", R, G, B); - */ R = AIR_CLAMP(0, R, 1); G = AIR_CLAMP(0, G, 1); B = AIR_CLAMP(0, B, 1); - /* - fprintf(stderr, "%g %g %g\n", R, G, B); - */ if (R == G && G == B) { fprintf(win->file, "CP %g Gr F\n", R); --- 94,131 ---- void ! _limnPSDrawFace(limnObject *obj, limnFace *face, ! limnCamera *cam, Nrrd *nmap, limnWindow *win) { ! int vii; ! limnVertex *vert; ! limnLook *look; ! limnPart *part; int qn; float *map, R, G, B; ! look = obj->look + face->lookIdx; ! part = obj->part + face->partIdx; ! for (vii=0; vii<face->sideNum; vii++) { ! vert = obj->vert + part->vertIdx[vii]; fprintf(win->file, "%g %g %s\n", ! vert->device[0], vert->device[1], vii ? "L" : "M"); } ! R = look->kads[0]*look->rgba[0]; ! G = look->kads[0]*look->rgba[1]; ! B = look->kads[0]*look->rgba[2]; if (nmap) { ! qn = limnVtoQN_f[limnQN16checker](face->worldNormal); map = nmap->data; ! R += look->kads[1]*look->rgba[0]*map[0 + 3*qn]; ! G += look->kads[1]*look->rgba[1]*map[1 + 3*qn]; ! B += look->kads[1]*look->rgba[2]*map[2 + 3*qn]; } else { ! R += look->kads[1]*look->rgba[0]; ! G += look->kads[1]*look->rgba[1]; ! B += look->kads[1]*look->rgba[2]; } /* HEY: not evaluating phong specular for now */ R = AIR_CLAMP(0, R, 1); G = AIR_CLAMP(0, G, 1); B = AIR_CLAMP(0, B, 1); if (R == G && G == B) { fprintf(win->file, "CP %g Gr F\n", R); *************** *** 147,160 **** void ! _limnPSDrawEdge(limnObj *obj, limnPart *r, limnEdge *e, ! limnCamera *cam, limnWin *win) { ! limnPoint *p0, *p1; ! if (win->ps.lineWidth[e->type]) { ! p0 = obj->p + e->v0; ! p1 = obj->p + e->v1; ! fprintf(win->file, "%g %g M ", p0->d[0], p0->d[1]); ! fprintf(win->file, "%g %g L ", p1->d[0], p1->d[1]); ! fprintf(win->file, "%g W ", win->ps.lineWidth[e->type]); fprintf(win->file, "S\n"); } --- 137,152 ---- void ! _limnPSDrawEdge(limnObject *obj, limnEdge *edge, ! limnCamera *cam, limnWindow *win) { ! limnVertex *vert0, *vert1; ! limnPart *part; ! part = obj->part + edge->partIdx; ! if (win->ps.lineWidth[edge->type]) { ! vert0 = obj->vert + part->vertIdx[edge->vertIdxIdx[0]]; ! vert1 = obj->vert + part->vertIdx[edge->vertIdxIdx[1]]; ! fprintf(win->file, "%g %g M ", vert0->device[0], vert0->device[1]); ! fprintf(win->file, "%g %g L ", vert1->device[0], vert1->device[1]); ! fprintf(win->file, "%g W ", win->ps.lineWidth[edge->type]); fprintf(win->file, "S\n"); } *************** *** 162,169 **** /* ! ******** limnObjPSDrawOld ** ** draws a "rendered" limn object to postscript. ! ** limnObjRender MUST be called first. ** ** The current (feeble) justification for using an environment map is --- 154,161 ---- /* ! ******** limnObjectPSDraw ** ** draws a "rendered" limn object to postscript. ! ** limnObjectRender MUST be called first. ** ** The current (feeble) justification for using an environment map is *************** *** 173,184 **** */ int ! limnObjPSDrawOld(limnObj *obj, limnCamera *cam, Nrrd *nmap, limnWin *win) { ! char me[]="limnObjPSDraw", err[AIR_STRLEN_MED]; int inside; float angle; ! limnFace *f, *f0, *f1; int fi; ! limnEdge *e; int ei; ! limnPart *r; int ri; ! limnPoint *p; int pi; if (nmap) { --- 165,177 ---- */ int ! limnObjectPSDraw(limnObject *obj, limnCamera *cam, ! Nrrd *nmap, limnWindow *win) { ! char me[]="limnObjectPSDraw", err[AIR_STRLEN_MED]; int inside; float angle; ! limnFace *face, *face0, *face1; int fii; ! limnEdge *edge; int eii; ! limnPart *part; int partIdx; ! limnVertex *vert; int vii; if (nmap) { *************** *** 189,216 **** } ! limnObjDepthSortParts(obj); _limnPSPreamble(obj, cam, win); ! for (ri=0; ri<obj->rA->len; ri++) { ! r = &(obj->r[ri]); /* only draw the parts that are inside the field of view */ inside = 0; ! for (pi=0; pi<r->pNum; pi++) { ! p = &(obj->p[r->pBase + pi]); ! /* ! printf("p[%d] = %g %g\n", pi, p->d[0], p->d[1]); ! */ ! inside |= (AIR_IN_CL(win->bbox[0], p->d[0], win->bbox[2]) && ! AIR_IN_CL(win->bbox[1], p->d[1], win->bbox[3])); ! if (inside) break; } ! if (!inside) continue; /* draw the part */ ! if (1 == r->eNum) { /* this part is just one lone edge */ /* HEY: this is a mess */ --- 182,210 ---- } ! limnObjectDepthSortParts(obj); _limnPSPreamble(obj, cam, win); ! for (partIdx=0; partIdx<obj->partNum; partIdx++) { ! part = obj->part + partIdx; /* only draw the parts that are inside the field of view */ inside = 0; ! for (vii=0; vii<part->vertIdxNum; vii++) { ! vert = obj->vert + part->vertIdx[vii]; ! inside |= (AIR_IN_CL(win->bbox[0], vert->device[0], win->bbox[2]) && ! AIR_IN_CL(win->bbox[1], vert->device[1], win->bbox[3])); ! if (inside) { ! /* at least vertex is in, we know we can't skip this part */ break; + } } ! if (!inside) { ! /* none of the vertices were in, we can skip this part */ continue; + } /* draw the part */ ! if (1 == part->edgeIdxNum) { /* this part is just one lone edge */ /* HEY: this is a mess */ *************** *** 223,229 **** fprintf(win->file, "%g %g %g RGB\n", r->rgba[0], r->rgba[1], r->rgba[2]); ! win->ps.edgeWidth[e->visib] = 4; _limnPSDrawEdge(obj, r, e, cam, win); ! win->ps.edgeWidth[e->visib] = widthTmp; */ } else { --- 217,223 ---- fprintf(win->file, "%g %g %g RGB\n", r->rgba[0], r->rgba[1], r->rgba[2]); ! win->ps.edgeWidth[e->visible] = 4; _limnPSDrawEdge(obj, r, e, cam, win); ! win->ps.edgeWidth[e->visible] = widthTmp; */ } else { *************** *** 231,251 **** /* draw the front-facing, shaded faces */ ! for (fi=0; fi<r->fNum; fi++) { ! f = &(obj->f[r->fBase + fi]); ! /* ! printf("f[%d]->sn = %g %g %g\n", fi, f->sn[0], f->sn[1], f->sn[2]); ! */ /* The consequence of having a left-handed frame is that world-space CC-wise vertex traversal becomes C-wise screen-space traversal, so all the normals are backwards of what we want */ ! f->visib = (cam->rightHanded ! ? f->sn[2] < 0 ! : f->sn[2] > 0); ! if (f->vNum == r->pNum && !f->visib) { ! f->visib = AIR_TRUE; ! ELL_3V_SCALE(f->wn, -1, f->wn); } ! if (!win->ps.wireFrame && f->visib) { ! _limnPSDrawFace(obj, r, f, cam, nmap, win); } } --- 225,243 ---- /* draw the front-facing, shaded faces */ ! for (fii=0; fii<part->faceIdxNum; fii++) { ! face = obj->face + part->faceIdx[fii]; /* The consequence of having a left-handed frame is that world-space CC-wise vertex traversal becomes C-wise screen-space traversal, so all the normals are backwards of what we want */ ! face->visible = (cam->rightHanded ! ? face->screenNormal[2] < 0 ! : face->screenNormal[2] > 0); ! if (face->sideNum == part->vertIdxNum && !face->visible) { ! /* lone faces are always visible */ ! face->visible = AIR_TRUE; ! ELL_3V_SCALE(face->worldNormal, -1, face->worldNormal); } ! if (!win->ps.wireFrame && face->visible) { ! _limnPSDrawFace(obj, face, cam, nmap, win); } } *************** *** 253,277 **** /* draw ALL edges */ fprintf(win->file, "0 setgray\n"); ! for (ei=0; ei<r->eNum; ei++) { ! e = &(obj->e[r->eBase + ei]); ! f0 = &(obj->f[e->f0]); ! f1 = e->f1 != -1 ? &(obj->f[e->f1]) : NULL; ! if (!f1) { ! e->type = limnEdgeTypeBorder; } else { ! angle = 180/M_PI*acos(ELL_3V_DOT(f0->wn, f1->wn)); ! if (f0->visib && f1->visib) { ! e->type = (angle > win->ps.creaseAngle ! ? limnEdgeTypeFrontCrease ! : limnEdgeTypeFrontFacet); ! } else if (f0->visib ^ f1->visib) { ! e->type = limnEdgeTypeContour; } else { ! e->type = (angle > win->ps.creaseAngle ! ? limnEdgeTypeBackCrease ! : limnEdgeTypeBackFacet); } } ! _limnPSDrawEdge(obj, r, e, cam, win); } } --- 245,272 ---- /* draw ALL edges */ fprintf(win->file, "0 setgray\n"); ! for (eii=0; eii<part->edgeIdxNum; eii++) { ! edge = obj->edge + part->edgeIdx[eii]; ! face0 = obj->face + part->faceIdx[edge->faceIdxIdx[0]]; ! face1 = (-1 == edge->faceIdxIdx[0] ! ? NULL ! : obj->face + part->faceIdx[edge->faceIdxIdx[1]]); ! if (!face1) { ! edge->type = limnEdgeTypeBorder; } else { ! angle = 180/M_PI*acos(ELL_3V_DOT(face0->worldNormal, ! face1->worldNormal)); ! if (face0->visible && face1->visible) { ! edge->type = (angle > win->ps.creaseAngle ! ? limnEdgeTypeFrontCrease ! : limnEdgeTypeFrontFacet); ! } else if (face0->visible ^ face1->visible) { ! edge->type = limnEdgeTypeContour; } else { ! edge->type = (angle > win->ps.creaseAngle ! ? limnEdgeTypeBackCrease ! : limnEdgeTypeBackFacet); } } ! _limnPSDrawEdge(obj, edge, cam, win); } } *************** *** 283,323 **** } - void - _limnPSDrawPointPair(limnObj *obj, limnPart *r, - int v0, int v1, int type, - limnCamera *cam, limnWin *win) { - - if (win->ps.lineWidth[type]) { - fprintf(win->file, "%g %g M ", obj->p[v0].d[0], obj->p[v0].d[1]); - fprintf(win->file, "%g %g L ", obj->p[v1].d[0], obj->p[v1].d[1]); - fprintf(win->file, "%g W ", win->ps.lineWidth[type]); - fprintf(win->file, "S\n"); - } - } - /* ! ** HEY: drawing non-convex objects has to be done one face at a time, ! ** and faces are responsible for drawing their edges. The STUPID ! ** thing about limn right now is that faces do not have a list of ! ** their edges; only a list of their vertex indices... ! */ ! ! /* ! ******** limnObjPSDraw ** ! ** new version of the above, which works per-face instead of per-part */ int ! limnObjPSDraw(limnObj *obj, limnCamera *cam, Nrrd *nmap, limnWin *win) { ! char me[]="limnObjPSDraw", err[AIR_STRLEN_MED]; ! int inside, vi, psize, v0, v1; float angle; ! limnFace *f, *f0, *f1; int fi; ! limnEdge *e; int ei; ! limnPart *r; int ri; ! limnPoint *p; int pi; ! Nrrd *neinfo; ! unsigned char *einfo; ! airArray *mop; if (nmap) { --- 278,296 ---- } /* ! ******** limnObjectPSDrawConcave ** ! ** new version of the above, which works per-face instead of per-part, ! ** thus better handling self-occlusions, but at the cost of not getting ! ** contours near oblique faces correct... */ int ! limnObjectPSDrawConcave(limnObject *obj, limnCamera *cam, ! Nrrd *nmap, limnWindow *win) { ! char me[]="limnObjectPSDrawConcave", err[AIR_STRLEN_MED]; float angle; ! limnPart *part; ! limnFace *face, *face0, *face1; int faceIdx; ! limnEdge *edge; int edgeIdx, eii; if (nmap) { *************** *** 328,397 **** } ! mop = airMopNew(); ! neinfo = nrrdNew(); ! airMopAdd(mop, neinfo, (airMopper)nrrdNuke, airMopAlways); ! psize = obj->pA->len; ! if (nrrdMaybeAlloc(neinfo, nrrdTypeUChar, 2, psize, psize)) { ! sprintf(err, "%s: couldn't allocate %d x %d array of point pairs", ! me, obj->pA->len, obj->pA->len); ! biffMove(LIMN, err, NRRD); return 1; ! } ! einfo = (unsigned char*)(neinfo->data); ! ! limnObjDepthSortFaces(obj); _limnPSPreamble(obj, cam, win); ! ! /* categorize all edges by traversing edge array, and storing ! edge type information in einfo[] */ ! for (ei=0; ei<obj->eA->len; ei++) { ! e = obj->e + ei; ! if (e->v0 < e->v1) { ! v0 = e->v0; ! v1 = e->v1; ! } else { ! v0 = e->v1; ! v1 = e->v0; } ! f0 = &(obj->f[e->f0]); ! f1 = e->f1 != -1 ? &(obj->f[e->f1]) : NULL; ! if (!f1) { ! einfo[v0 + psize*v1] = limnEdgeTypeBorder; } else { ! angle = 180/M_PI*acos(ELL_3V_DOT(f0->wn, f1->wn)); ! if (f0->visib && f1->visib) { ! einfo[v0 + psize*v1] = (angle > win->ps.creaseAngle ! ? limnEdgeTypeFrontCrease ! : limnEdgeTypeFrontFacet); ! } else if (f0->visib ^ f1->visib) { ! einfo[v0 + psize*v1] = limnEdgeTypeContour; } else { ! einfo[v0 + psize*v1] = (angle > win->ps.creaseAngle ! ? limnEdgeTypeBackCrease ! : limnEdgeTypeBackFacet); } } } ! /* draw front-faces and non-back edges */ ! for (fi=0; fi<obj->fA->len; fi++) { ! f = obj->f + obj->fSort[fi]; ! f->visib = (cam->rightHanded ! ? f->sn[2] < 0 ! : f->sn[2] > 0); ! if (f->vNum == r->pNum && !f->visib) { ! f->visib = AIR_TRUE; ! ELL_3V_SCALE(f->wn, -1, f->wn); } ! if (!win->ps.wireFrame && f->visib) { ! _limnPSDrawFace(obj, r, f, cam, nmap, win); } ! /* ! for (vi=0; vi<f->vNum; vi++) { ! p = obj->p + obj->v[vi + f->vBase]; ! fprintf(win->file, "%g %g %s\n", ! p->d[0], p->d[1], vi ? "L" : "M"); } - */ } --- 301,379 ---- } ! limnObjectDepthSortFaces(obj); _limnPSPreamble(obj, cam, win); ! ! /* set every face's visibility */ ! for (faceIdx=0; faceIdx<obj->faceNum; faceIdx++) { ! face = obj->face + faceIdx; ! part = obj->part + face->partIdx; ! face->visible = (cam->rightHanded ! ? face->screenNormal[2] < 0 ! : face->screenNormal[2] > 0); ! if (face->sideNum == part->vertIdxNum && !face->visible) { ! /* lone faces are always visible */ ! face->visible = AIR_TRUE; ! ELL_3V_SCALE(face->worldNormal, -1, face->worldNormal); } ! } ! ! /* categorize all edges by traversing edge array, and looking ! at each of their two faces */ ! for (edgeIdx=0; edgeIdx<obj->edgeNum; edgeIdx++) { ! edge = obj->edge + edgeIdx; ! part = obj->part + edge->partIdx; ! face0 = obj->face + part->faceIdx[edge->faceIdxIdx[0]]; ! face1 = (-1 == edge->faceIdxIdx[1] ! ? NULL ! : obj->face + part->faceIdx[edge->faceIdxIdx[1]]); ! if (!face1) { ! edge->type = limnEdgeTypeBorder; } else { ! angle = 180/M_PI*acos(ELL_3V_DOT(face0->worldNormal, ! face1->worldNormal)); ! if (face0->visible && face1->visible) { ! edge->type = (angle > win->ps.creaseAngle ! ? limnEdgeTypeFrontCrease ! : limnEdgeTypeFrontFacet); ! } else if (face0->visible ^ face1->visible) { ! edge->type = limnEdgeTypeContour; } else { ! edge->type = (angle > win->ps.creaseAngle ! ? limnEdgeTypeBackCrease ! : limnEdgeTypeBackFacet); } } } ! /* draw front-faces and their edges ! (contours, front crease, front non-crease) */ ! for (faceIdx=0; faceIdx<obj->faceNum; faceIdx++) { ! face = obj->face + obj->faceSort[faceIdx]; ! part = obj->part + face->partIdx; ! if (!face->visible) { ! continue; } ! if (!win->ps.wireFrame) { ! _limnPSDrawFace(obj, face, cam, nmap, win); } ! /* draw those edges around the face that won't be seen again by ! future faces in the depth-first traversal */ ! for (eii=0; eii<face->sideNum; eii++) { ! edge = obj->edge + part->edgeIdx[face->edgeIdxIdx[eii]]; ! if (limnEdgeTypeContour == edge->type) { ! _limnPSDrawEdge(obj, edge, cam, win); ! } else if (limnEdgeTypeFrontCrease == edge->type ! || limnEdgeTypeFrontFacet == edge->type) { ! if (edge->once) { ! /* its been seen once already, okay to draw */ ! _limnPSDrawEdge(obj, edge, cam, win); ! edge->once = AIR_FALSE; ! } else { ! /* we're the first to see it, and we're not the last, don't draw */ ! edge->once = AIR_TRUE; ! } ! } } } Index: shapes.c =================================================================== RCS file: /cvsroot/teem/teem/src/limn/shapes.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** shapes.c 7 Jan 2004 15:34:30 -0000 1.15 --- shapes.c 9 Feb 2004 22:48:01 -0000 1.16 *************** *** 22,29 **** int ! limnObjCubeAdd(limnObj *obj, int sp) { ! int pb, v[4], ret; ! ret = limnObjPartStart(obj); /* 7 6 --- 22,29 ---- int ! limnObjectCubeAdd(limnObject *obj, int lookIdx) { ! int vII[4], vII0, partIdx; ! partIdx = limnObjectPartAdd(obj); /* 7 6 *************** *** 36,90 **** ------ x */ ! pb = limnObjPointAdd(obj, 0, -1, -1, -1); ! limnObjPointAdd(obj, 0, 1, -1, -1); ! limnObjPointAdd(obj, 0, 1, 1, -1); ! limnObjPointAdd(obj, 0, -1, 1, -1); ! limnObjPointAdd(obj, 0, -1, -1, 1); ! limnObjPointAdd(obj, 0, 1, -1, 1); ! limnObjPointAdd(obj, 0, 1, 1, 1); ! limnObjPointAdd(obj, 0, -1, 1, 1); ! ELL_4V_SET(v, pb+3, pb+2, pb+1, pb+0); limnObjFaceAdd(obj, sp, 4, v); ! ELL_4V_SET(v, pb+1, pb+5, pb+4, pb+0); limnObjFaceAdd(obj, sp, 4, v); ! ELL_4V_SET(v, pb+2, pb+6, pb+5, pb+1); limnObjFaceAdd(obj, sp, 4, v); ! ELL_4V_SET(v, pb+3, pb+7, pb+6, pb+2); limnObjFaceAdd(obj, sp, 4, v); ! ELL_4V_SET(v, pb+0, pb+4, pb+7, pb+3); limnObjFaceAdd(obj, sp, 4, v); ! ELL_4V_SET(v, pb+5, pb+6, pb+7, pb+4); limnObjFaceAdd(obj, sp, 4, v); ! limnObjPartFinish(obj); ! ! return ret; ! } ! ! int ! limnObjSquareAdd(limnObj *obj, int sp) { ! int pb, v[4], ret; ! ! ret = limnObjPartStart(obj); ! pb = limnObjPointAdd(obj, 0, 0, 0, 0); ! limnObjPointAdd(obj, 0, 1, 0, 0); ! limnObjPointAdd(obj, 0, 1, 1, 0); ! limnObjPointAdd(obj, 0, 0, 1, 0); ! ELL_4V_SET(v, pb+0, pb+1, pb+2, pb+3); limnObjFaceAdd(obj, sp, 4, v); ! limnObjPartFinish(obj); ! return ret; } int ! limnObjLoneEdgeAdd(limnObj *obj, int sp) { ! int pb, ret; ! float x; ! x = 0.5; ! ret = limnObjPartStart(obj); ! pb = limnObjPointAdd(obj, 0, -x, 0, 0); ! limnObjPointAdd(obj, 0, x, 0, 0); ! limnObjEdgeAdd(obj, 1, -1, pb+0, pb+1); ! limnObjPartFinish(obj); ! return ret; } /* ! ******** limnObjCylinderAdd ** ** adds a cylinder that fills up the bi-unit cube [-1,1]^3, --- 36,80 ---- ------ x */ ! vII0 = limnObjectVertexAdd(obj, partIdx, 0, -1, -1, -1); ! limnObjectVertexAdd(obj, partIdx, lookIdx, 1, -1, -1); ! limnObjectVertexAdd(obj, partIdx, lookIdx, 1, 1, -1); ! limnObjectVertexAdd(obj, partIdx, lookIdx, -1, 1, -1); ! limnObjectVertexAdd(obj, partIdx, lookIdx, -1, -1, 1); ! limnObjectVertexAdd(obj, partIdx, lookIdx, 1, -1, 1); ! limnObjectVertexAdd(obj, partIdx, lookIdx, 1, 1, 1); ! limnObjectVertexAdd(obj, partIdx, lookIdx, -1, 1, 1); ! ELL_4V_SET(vII, vII0+3, vII0+2, vII0+1, vII0+0); ! limnObjectFaceAdd(obj, partIdx, lookIdx, 4, vII); ! ELL_4V_SET(vII, vII0+1, vII0+5, vII0+4, vII0+0); ! limnObjectFaceAdd(obj, partIdx, lookIdx, 4, vII); ! ELL_4V_SET(vII, vII0+2, vII0+6, vII0+5, vII0+1); ! limnObjectFaceAdd(obj, partIdx, lookIdx, 4, vII); ! ELL_4V_SET(vII, vII0+3, vII0+7, vII0+6, vII0+2); ! limnObjectFaceAdd(obj, partIdx, lookIdx, 4, vII); ! ELL_4V_SET(vII, vII0+0, vII0+4, vII0+7, vII0+3); ! limnObjectFaceAdd(obj, partIdx, lookIdx, 4, vII); ! ELL_4V_SET(vII, vII0+5, vII0+6, vII0+7, vII0+4); ! limnObjectFaceAdd(obj, partIdx, lookIdx, 4, vII); ! return partIdx; } int ! limnObjectSquareAdd(limnObject *obj, int lookIdx) { ! int vII0, vII[4], partIdx; ! partIdx = limnObjectPartAdd(obj); ! vII0 = limnObjectVertexAdd(obj, partIdx, lookIdx, 0, 0, 0); ! limnObjectVertexAdd(obj, partIdx, lookIdx, 1, 0, 0); ! limnObjectVertexAdd(obj, partIdx, lookIdx, 1, 1, 0); ! limnObjectVertexAdd(obj, partIdx, lookIdx, 0, 1, 0); ! ELL_4V_SET(vII, vII0+0, vII0+1, vII0+2, vII0+3); ! limnObjectFaceAdd(obj, partIdx, lookIdx, 4, vII); ! return partIdx; } /* ! ******** limnObjectCylinderAdd ** ** adds a cylinder that fills up the bi-unit cube [-1,1]^3, *************** *** 92,142 **** */ int ! limnObjCylinderAdd(limnObj *obj, int sp, int axis, int res) { ! float th; ! int i, j, t, pb=-1, ret, *v; ! ret = limnObjPartStart(obj); ! v = (int *)calloc(res, sizeof(int)); ! for (i=0; i<=res-1; i++) { ! th = AIR_AFFINE(0, i, res, 0, 2*M_PI); switch(axis) { case 0: ! t = limnObjPointAdd(obj, 0, 1, -sin(th), cos(th)); if (!i) pb = t; ! limnObjPointAdd(obj, 0, -1, -sin(th), cos(th)); break; case 1: ! t = limnObjPointAdd(obj, 0, sin(th), 1, cos(th)); if (!i) pb = t; ! limnObjPointAdd(obj, 0, sin(th), -1, cos(th)); break; case 2: default: ! t = limnObjPointAdd(obj, 0, cos(th), sin(th), 1); if (!i) pb = t; ! limnObjPointAdd(obj, 0, cos(th), sin(th), -1); break; } } ! for (i=0; i<=res-1; i++) { ! j = (i+1) % res; ! ELL_4V_SET(v, pb + 2*i, pb + 2*i + 1, pb + 2*j + 1, pb + 2*j); ! limnObjFaceAdd(obj,... [truncated message content] |