|
From: Gordon K. <kin...@us...> - 2004-05-12 04:03:43
|
Update of /cvsroot/teem/teem/src/echo In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21805 Modified Files: GNUmakefile echo.h list.c methodsEcho.c objmethods.c renderEcho.c Log Message: debuggin Index: renderEcho.c =================================================================== RCS file: /cvsroot/teem/teem/src/echo/renderEcho.c,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** renderEcho.c 13 Mar 2004 20:03:09 -0000 1.25 --- renderEcho.c 12 May 2004 04:03:31 -0000 1.26 *************** *** 22,26 **** int ! echoThreadStateInit(echoThreadState *tstate, echoRTParm *parm, echoGlobalState *gstate) { char me[]="echoThreadStateInit", err[AIR_STRLEN_MED]; --- 22,26 ---- int ! echoThreadStateInit(int threadIdx, echoThreadState *tstate, echoRTParm *parm, echoGlobalState *gstate) { char me[]="echoThreadStateInit", err[AIR_STRLEN_MED]; *************** *** 30,37 **** biffAdd(ECHO, err); return 1; } ! /* this will probably be over-written */ tstate->verbose = gstate->verbose; ! if (nrrdMaybeAlloc(tstate->nperm, nrrdTypeInt, 2, ECHO_JITTABLE_NUM, parm->numSamples)) { --- 30,38 ---- biffAdd(ECHO, err); return 1; } ! /* tstate->thread set by echoThreadStateNew() */ ! tstate->gstate = gstate; /* this will probably be over-written */ tstate->verbose = gstate->verbose; ! tstate->threadIdx = threadIdx; if (nrrdMaybeAlloc(tstate->nperm, nrrdTypeInt, 2, ECHO_JITTABLE_NUM, parm->numSamples)) { *************** *** 55,59 **** biffAdd(ECHO, err); return 1; } - tstate->chanBuff = airFree(tstate->chanBuff); if (!( tstate->chanBuff = --- 56,59 ---- *************** *** 63,66 **** --- 63,68 ---- biffAdd(ECHO, err); return 1; } + + tstate->returnPtr = NULL; return 0; *************** *** 264,324 **** } ! /* ! ******** echoRTRender ! ** ! ** top-level call to accomplish all (ray-tracing) rendering. As much ! ** error checking as possible should be done here and not in the ! ** lower-level functions. ! */ ! int ! echoRTRender(Nrrd *nraw, limnCamera *cam, echoScene *scene, ! echoRTParm *parm, echoGlobalState *gstate) { ! char me[]="echoRTRender", err[AIR_STRLEN_MED], done[20]; int imgUi, imgVi, /* integral pixel indices */ samp; /* which sample are we doing */ echoPos_t tmp0, tmp1, ! eye[3], /* eye center before jittering */ ! at[3], /* ray destination (pixel center post-jittering) */ ! U[4], V[4], N[4], /* view space basis (only first 3 elements used) */ pixUsz, pixVsz, /* U and V dimensions of a pixel */ imgU, imgV, /* floating point pixel center locations */ imgOrig[3]; /* image origin */ - echoThreadState *tstate; /* only one thread for now */ - echoCol_t *img, *chan; /* current scanline of channel buffer array */ - echoRay ray; /* (not a pointer) */ double time0; ! if (echoRTRenderCheck(nraw, cam, scene, parm, gstate)) { ! sprintf(err, "%s: problem with input", me); ! biffAdd(ECHO, err); return 1; ! } ! if (nrrdMaybeAlloc(nraw, echoCol_nt, 3, ! ECHO_IMG_CHANNELS, parm->imgResU, parm->imgResV)) { ! sprintf(err, "%s: couldn't allocate output image", me); ! biffMove(ECHO, err, NRRD); return 1; ! } ! nrrdAxisInfoSet(nraw, nrrdAxisInfoLabel, ! "r,g,b,a,t", "x", "y"); ! nrrdAxisInfoSet(nraw, nrrdAxisInfoMin, ! AIR_NAN, cam->uRange[0], cam->vRange[0]); ! nrrdAxisInfoSet(nraw, nrrdAxisInfoMax, ! AIR_NAN, cam->uRange[1], cam->vRange[1]); ! tstate = echoThreadStateNew(); ! if (echoThreadStateInit(tstate, parm, gstate)) { ! sprintf(err, "%s:", me); ! biffAdd(ECHO, err); return 1; ! } ! ! gstate->time = airTime(); ! if (parm->seedRand) { ! airSrand(); ! } ! echoJitterCompute(parm, tstate); ! if (gstate->verbose > 2) { ! nrrdSave("jitt.nrrd", tstate->njitt, NULL); } /* set eye, U, V, N, imgOrig */ ! ELL_3V_COPY(eye, cam->from); ELL_4MV_ROW0_GET(U, cam->W2V); ELL_4MV_ROW1_GET(V, cam->W2V); --- 266,304 ---- } ! void * ! _echoRTRenderThreadBody(void *_arg) { ! char done[20]; int imgUi, imgVi, /* integral pixel indices */ samp; /* which sample are we doing */ echoPos_t tmp0, tmp1, ! *jitt, pixUsz, pixVsz, /* U and V dimensions of a pixel */ + U[4], V[4], N[4], /* view space basis (only first 3 elements used) */ imgU, imgV, /* floating point pixel center locations */ + eye[3], /* eye center before jittering */ + at[3], /* ray destination (pixel center post-jittering) */ imgOrig[3]; /* image origin */ double time0; + echoRay ray; /* (not a pointer) */ + echoThreadState *arg; + echoCol_t *img, *chan; /* current scanline of channel buffer array */ + Nrrd *nraw; /* copies of arguments to echoRTRender ... */ + limnCamera *cam; + echoScene *scene; + echoRTParm *parm; ! arg = (echoThreadState *)_arg; ! nraw = arg->gstate->nraw; ! cam = arg->gstate->cam; ! scene = arg->gstate->scene; ! parm = arg->gstate->parm; ! ! echoJitterCompute(arg->gstate->parm, arg); ! if (arg->gstate->verbose > 2) { ! nrrdSave("jitt.nrrd", arg->njitt, NULL); } /* set eye, U, V, N, imgOrig */ ! ELL_3V_COPY(eye, arg->gstate->cam->from); ELL_4MV_ROW0_GET(U, cam->W2V); ELL_4MV_ROW1_GET(V, cam->W2V); *************** *** 330,356 **** pixVsz = (cam->vRange[1] - cam->vRange[0])/(parm->imgResV); ! tstate->depth = 0; ray.shadow = AIR_FALSE; ! img = (echoCol_t *)nraw->data; ! fprintf(stderr, "%s: ", me); /* prep for printing airDoneStr */ ! tstate->verbose = AIR_FALSE; ! for (imgVi=0; imgVi<parm->imgResV; imgVi++) { ! imgV = NRRD_POS(nrrdCenterCell, cam->vRange[0], cam->vRange[1], ! parm->imgResV, imgVi); if (!(imgVi % 5)) { fprintf(stderr, "%s", airDoneStr(0, imgVi, parm->imgResV-1, done)); fflush(stderr); } for (imgUi=0; imgUi<parm->imgResU; imgUi++) { imgU = NRRD_POS(nrrdCenterCell, cam->uRange[0], cam->uRange[1], parm->imgResU, imgUi); ! /* initialize things on first "scanline" */ ! tstate->jitt = (echoPos_t *)tstate->njitt->data; ! chan = tstate->chanBuff; ! /* tstate->verbose = ( (160 == imgUi && 160 == imgVi) ); */ ! if (tstate->verbose) { fprintf(stderr, "\n"); fprintf(stderr, "-----------------------------------------------\n"); --- 310,354 ---- pixVsz = (cam->vRange[1] - cam->vRange[0])/(parm->imgResV); ! arg->depth = 0; ray.shadow = AIR_FALSE; ! arg->verbose = AIR_FALSE; ! while (1) { ! if (arg->gstate->workMutex) { ! airThreadMutexLock(arg->gstate->workMutex); ! } ! imgVi = arg->gstate->workIdx; ! if (arg->gstate->workIdx < parm->imgResV) { ! arg->gstate->workIdx += 1; ! } ! /* if (!(imgVi % 5)) { fprintf(stderr, "%s", airDoneStr(0, imgVi, parm->imgResV-1, done)); fflush(stderr); } + */ + fprintf(stderr, "%d : %d\n", arg->threadIdx, imgVi); + if (arg->gstate->workMutex) { + airThreadMutexUnlock(arg->gstate->workMutex); + } + if (imgVi == parm->imgResV) { + /* we're done! */ + break; + } + + imgV = NRRD_POS(nrrdCenterCell, cam->vRange[0], cam->vRange[1], + parm->imgResV, imgVi); for (imgUi=0; imgUi<parm->imgResU; imgUi++) { imgU = NRRD_POS(nrrdCenterCell, cam->uRange[0], cam->uRange[1], parm->imgResU, imgUi); ! img = ((echoCol_t *)nraw->data ! + ECHO_IMG_CHANNELS*(imgUi + parm->imgResU*imgVi)); ! /* initialize things on first "scanline" */ ! jitt = (echoPos_t *)arg->njitt->data; ! chan = arg->chanBuff; ! /* arg->verbose = ( (160 == imgUi && 160 == imgVi) ); */ ! if (arg->verbose) { fprintf(stderr, "\n"); fprintf(stderr, "-----------------------------------------------\n"); *************** *** 365,376 **** ELL_3V_COPY(ray.from, eye); if (parm->aperture) { ! tmp0 = parm->aperture*(tstate->jitt[0 + 2*echoJittableLens]); ! tmp1 = parm->aperture*(tstate->jitt[1 + 2*echoJittableLens]); ELL_3V_SCALE_ADD3(ray.from, 1, ray.from, tmp0, U, tmp1, V); } /* set at[] */ ! tmp0 = imgU + pixUsz*(tstate->jitt[0 + 2*echoJittablePixel]); ! tmp1 = imgV + pixVsz*(tstate->jitt[1 + 2*echoJittablePixel]); ELL_3V_SCALE_ADD3(at, 1, imgOrig, tmp0, U, tmp1, V); --- 363,374 ---- ELL_3V_COPY(ray.from, eye); if (parm->aperture) { ! tmp0 = parm->aperture*(jitt[0 + 2*echoJittableLens]); ! tmp1 = parm->aperture*(jitt[1 + 2*echoJittableLens]); ELL_3V_SCALE_ADD3(ray.from, 1, ray.from, tmp0, U, tmp1, V); } /* set at[] */ ! tmp0 = imgU + pixUsz*(jitt[0 + 2*echoJittablePixel]); ! tmp1 = imgV + pixVsz*(jitt[1 + 2*echoJittablePixel]); ELL_3V_SCALE_ADD3(at, 1, imgOrig, tmp0, U, tmp1, V); *************** *** 384,407 **** memset(chan, 0, ECHO_IMG_CHANNELS*sizeof(echoCol_t)); } else { ! echoRayColor(chan, &ray, scene, parm, tstate); } chan[4] = airTime() - time0; ! /* move to next "scanlines" */ ! tstate->jitt += 2*ECHO_JITTABLE_NUM; chan += ECHO_IMG_CHANNELS; } ! echoChannelAverage(img, parm, tstate); img += ECHO_IMG_CHANNELS; if (!parm->reuseJitter) { ! echoJitterCompute(parm, tstate); } } } gstate->time = airTime() - gstate->time; fprintf(stderr, "\n%s: time = %g\n", me, gstate->time); ! tstate = echoThreadStateNix(tstate); ! return 0; } --- 382,486 ---- memset(chan, 0, ECHO_IMG_CHANNELS*sizeof(echoCol_t)); } else { ! echoRayColor(chan, &ray, scene, parm, arg); } chan[4] = airTime() - time0; ! /* move to next "scanline" */ ! jitt += 2*ECHO_JITTABLE_NUM; chan += ECHO_IMG_CHANNELS; } ! echoChannelAverage(img, parm, arg); ! img[0] = arg->threadIdx; img += ECHO_IMG_CHANNELS; if (!parm->reuseJitter) { ! echoJitterCompute(parm, arg); } } } + + return _arg; + } + + + /* + ******** echoRTRender + ** + ** top-level call to accomplish all (ray-tracing) rendering. As much + ** error checking as possible should be done here and not in the + ** lower-level functions. + */ + int + echoRTRender(Nrrd *nraw, limnCamera *cam, echoScene *scene, + echoRTParm *parm, echoGlobalState *gstate) { + char me[]="echoRTRender", err[AIR_STRLEN_MED]; + int tid, ret; + airArray *mop; + echoThreadState *tstate[ECHO_THREAD_MAX]; + + if (echoRTRenderCheck(nraw, cam, scene, parm, gstate)) { + sprintf(err, "%s: problem with input", me); + biffAdd(ECHO, err); return 1; + } + gstate->nraw = nraw; + gstate->cam = cam; + gstate->scene = scene; + gstate->parm = parm; + mop = airMopNew(); + if (nrrdMaybeAlloc(nraw, echoCol_nt, 3, + ECHO_IMG_CHANNELS, parm->imgResU, parm->imgResV)) { + sprintf(err, "%s: couldn't allocate output image", me); + biffMove(ECHO, err, NRRD); airMopError(mop); return 1; + } + airMopAdd(mop, nraw, (airMopper)nrrdNix, airMopOnError); + nrrdAxisInfoSet(nraw, nrrdAxisInfoLabel, + "r,g,b,a,t", "x", "y"); + nrrdAxisInfoSet(nraw, nrrdAxisInfoMin, + AIR_NAN, cam->uRange[0], cam->vRange[0]); + nrrdAxisInfoSet(nraw, nrrdAxisInfoMax, + AIR_NAN, cam->uRange[1], cam->vRange[1]); + gstate->time = airTime(); + if (parm->seedRand) { + airSrand(); + } + + if (parm->numThreads > 1) { + gstate->workMutex = airThreadMutexNew(); + airMopAdd(mop, gstate->workMutex, + (airMopper)airThreadMutexNix, airMopAlways); + } else { + gstate->workMutex = NULL; + } + for (tid=0; tid<parm->numThreads; tid++) { + if (!( tstate[tid] = echoThreadStateNew() )) { + sprintf(err, "%s: failed to create thread state %d", me, tid); + biffAdd(ECHO, err); airMopError(mop); return 1; + } + if (echoThreadStateInit(tid, tstate[tid], parm, gstate)) { + sprintf(err, "%s: failed to initialized thread state %d", me, tid); + biffAdd(ECHO, err); airMopError(mop); return 1; + } + airMopAdd(mop, tstate[tid], (airMopper)echoThreadStateNix, airMopAlways); + } + fprintf(stderr, "%s: ", me); /* prep for printing airDoneStr */ + gstate->workIdx = 0; + for (tid=0; tid<parm->numThreads; tid++) { + if (( ret = airThreadStart(tstate[tid]->thread, _echoRTRenderThreadBody, + (void *)(tstate[tid])) )) { + sprintf(err, "%s: thread[%d] failed to start: %d", me, tid, ret); + biffAdd(ECHO, err); airMopError(mop); return 1; + } + } + for (tid=0; tid<parm->numThreads; tid++) { + if (( ret = airThreadJoin(tstate[tid]->thread, + (void **)(&(tstate[tid]->returnPtr))) )) { + sprintf(err, "%s: thread[%d] failed to join: %d", me, tid, ret); + biffAdd(ECHO, err); airMopError(mop); return 1; + } + } + gstate->time = airTime() - gstate->time; fprintf(stderr, "\n%s: time = %g\n", me, gstate->time); ! airMopOkay(mop); return 0; } Index: echo.h =================================================================== RCS file: /cvsroot/teem/teem/src/echo/echo.h,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** echo.h 19 Feb 2004 03:44:07 -0000 1.61 --- echo.h 12 May 2004 04:03:31 -0000 1.62 *************** *** 67,70 **** --- 67,72 ---- #define ECHO_LEN_SMALL_ENOUGH 5 /* to control splitting for split objects */ + #define ECHO_THREAD_MAX 512 /* max number of threads */ + typedef struct { int jitterType, /* from echoJitter* enum below */ *************** *** 80,85 **** renderBoxes, /* faintly render bounding boxes */ seedRand, /* call airSrand() (don't if repeatability wanted) */ ! sqNRI; /* how many iterations of newton-raphson we allow for finding superquadric root (within tolorance sqTol) */ echoPos_t sqTol; /* how close newtwon-raphson must get to zero */ --- 82,88 ---- renderBoxes, /* faintly render bounding boxes */ seedRand, /* call airSrand() (don't if repeatability wanted) */ ! sqNRI, /* how many iterations of newton-raphson we allow for finding superquadric root (within tolorance sqTol) */ + numThreads; /* number of threads to spawn per rendering */ echoPos_t sqTol; /* how close newtwon-raphson must get to zero */ *************** *** 94,104 **** } echoRTParm; typedef struct { int verbose; double time; /* time it took to render image */ } echoGlobalState; typedef struct { ! int verbose, depth; /* how many recursion levels are we at */ Nrrd *nperm, /* ECHO_JITTABLE_NUM x parm->numSamples array --- 97,118 ---- } echoRTParm; + struct echoScene_t; + typedef struct { int verbose; double time; /* time it took to render image */ + Nrrd *nraw; /* copies of arguments to echoRTRender */ + limnCamera *cam; + struct echoScene_t *scene; + echoRTParm *parm; + int workIdx; /* next work assignment (such as a scanline) */ + airThreadMutex *workMutex; /* mutex around work assignment */ } echoGlobalState; typedef struct { ! airThread *thread; /* my thread */ ! echoGlobalState *gstate; ! int verbose, /* blah blah blah */ ! threadIdx, /* my thread index */ depth; /* how many recursion levels are we at */ Nrrd *nperm, /* ECHO_JITTABLE_NUM x parm->numSamples array *************** *** 115,118 **** --- 129,133 ---- echoCol_t *chanBuff; /* for storing ray color and other parameters for each of the parm->numSamples rays in current pixel */ + void *returnPtr; /* for airThreadJoin */ } echoThreadState; *************** *** 338,342 **** ** and nrrds to be nixed and nuked, respectively. */ ! typedef struct { echoObject **cat; /* array of ALL objects and all lights */ airArray *catArr; --- 353,357 ---- ** and nrrds to be nixed and nuked, respectively. */ ! typedef struct echoScene_t { echoObject **cat; /* array of ALL objects and all lights */ airArray *catArr; *************** *** 489,493 **** /* renderEcho.c ---------------------------------------- */ ! TEEM_API int echoThreadStateInit(echoThreadState *tstate, echoRTParm *parm, echoGlobalState *gstate); TEEM_API void echoJitterCompute(echoRTParm *parm, echoThreadState *state); --- 504,508 ---- /* renderEcho.c ---------------------------------------- */ ! TEEM_API int echoThreadStateInit(int threadIdx, echoThreadState *tstate, echoRTParm *parm, echoGlobalState *gstate); TEEM_API void echoJitterCompute(echoRTParm *parm, echoThreadState *state); Index: methodsEcho.c =================================================================== RCS file: /cvsroot/teem/teem/src/echo/methodsEcho.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** methodsEcho.c 13 Mar 2004 20:03:09 -0000 1.14 --- methodsEcho.c 12 May 2004 04:03:31 -0000 1.15 *************** *** 41,44 **** --- 41,45 ---- parm->seedRand = AIR_TRUE; parm->sqNRI = 15; + parm->numThreads = 1; parm->sqTol = 0.0001; parm->aperture = 0.0; /* pinhole camera by default */ *************** *** 67,70 **** --- 68,77 ---- state->verbose = 0; state->time = 0; + state->nraw = NULL; + state->cam = NULL; + state->scene = NULL; + state->parm = NULL; + state->workIdx = 0; + state->workMutex = NULL; } return state; *************** *** 75,78 **** --- 82,86 ---- state = airFree(state); + /* mutex freed at end of echoRTRender() */ return NULL; } *************** *** 84,88 **** --- 92,99 ---- state = (echoThreadState *)calloc(1, sizeof(echoThreadState)); if (state) { + state->thread = airThreadNew(); state->verbose = 0; + state->threadIdx = -1; + state->depth = -1; state->njitt = nrrdNew(); state->nperm = nrrdNew(); *************** *** 90,93 **** --- 101,105 ---- state->jitt = NULL; state->chanBuff = NULL; + state->returnPtr = NULL; } return state; *************** *** 98,101 **** --- 110,114 ---- if (state) { + state->thread = airThreadNix(state->thread); nrrdNuke(state->njitt); nrrdNuke(state->nperm); Index: list.c =================================================================== RCS file: /cvsroot/teem/teem/src/echo/list.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** list.c 7 Jan 2004 15:34:28 -0000 1.3 --- list.c 12 May 2004 04:03:31 -0000 1.4 *************** *** 136,140 **** that there's nothing substantial left of it */ airArraySetLen(LIST(list)->objArr, 0); ! free(mids); return split; } --- 136,140 ---- that there's nothing substantial left of it */ airArraySetLen(LIST(list)->objArr, 0); ! mids = airFree(mids); return split; } Index: objmethods.c =================================================================== RCS file: /cvsroot/teem/teem/src/echo/objmethods.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** objmethods.c 13 Mar 2004 20:03:09 -0000 1.9 --- objmethods.c 12 May 2004 04:03:31 -0000 1.10 *************** *** 39,43 **** if (obj) { \ do { BODY dummy=dummy;} while (0); \ ! free(obj); \ } \ return NULL; \ --- 39,43 ---- if (obj) { \ do { BODY dummy=dummy;} while (0); \ ! airFree(obj); \ } \ return NULL; \ Index: GNUmakefile =================================================================== RCS file: /cvsroot/teem/teem/src/echo/GNUmakefile,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** GNUmakefile 7 Jan 2004 15:34:28 -0000 1.18 --- GNUmakefile 12 May 2004 04:03:30 -0000 1.19 *************** *** 48,52 **** $(L).PRIVATE_HEADERS = privateEcho.h $(L).OBJS = enumsEcho.o methodsEcho.o objmethods.o bounds.o set.o model.o \ ! matter.o renderEcho.o intx.o sqd.o list.o color.o lightEcho.o $(L).TESTS = test/test test/trend #### --- 48,52 ---- $(L).PRIVATE_HEADERS = privateEcho.h $(L).OBJS = enumsEcho.o methodsEcho.o objmethods.o bounds.o set.o model.o \ ! matter.o intx.o sqd.o list.o color.o lightEcho.o renderEcho.o $(L).TESTS = test/test test/trend #### |