/* Get the basis of a problem */ void __declspec(dllexport) WINAPI _get_basis(lprec *lp, long *bascolumn) { if (lp != NULL) { freebuferror(); get_basis(lp, bascolumn); } }
/* Output XML prologue to stdout */ static void xml_prologue(const SDData *sd) { const char *matn = (sd && sd->matn[0]) ? sd->matn : "Name"; const char *makr = (sd && sd->makr[0]) ? sd->makr : "Manufacturer"; ANGLE_BASIS *abp = get_basis(kbasis); int i; if (abp == NULL) { fprintf(stderr, "%s: unknown angle basis '%s'\n", progname, kbasis); exit(1); } puts("<WindowElementType>System</WindowElementType>"); puts("<FileType>BSDF</FileType>"); puts("<Optical>"); puts("<Layer>"); puts("\t<Material>"); printf("\t\t<Name>%s</Name>\n", matn); printf("\t\t<Manufacturer>%s</Manufacturer>\n", makr); if (sd && sd->dim[2] > .001) { printf("\t\t<Thickness unit=\"meter\">%.3f</Thickness>\n", sd->dim[2]); printf("\t\t<Width unit=\"meter\">%.3f</Width>\n", sd->dim[0]); printf("\t\t<Height unit=\"meter\">%.3f</Height>\n", sd->dim[1]); } puts("\t\t<DeviceType>Other</DeviceType>"); puts("\t</Material>"); if (sd && sd->mgf != NULL) { puts("\t<Geometry format=\"MGF\">"); puts("\t\t<MGFblock unit=\"meter\">"); fputs(sd->mgf, stdout); puts("</MGFblock>"); puts("\t</Geometry>"); } puts("\t<DataDefinition>"); puts("\t\t<IncidentDataStructure>Columns</IncidentDataStructure>"); puts("\t\t<AngleBasis>"); printf("\t\t\t<AngleBasisName>%s</AngleBasisName>\n", kbasis); for (i = 0; abp->lat[i].nphis; i++) { puts("\t\t\t<AngleBasisBlock>"); printf("\t\t\t<Theta>%g</Theta>\n", i ? .5*(abp->lat[i].tmin + abp->lat[i+1].tmin) : .0 ); printf("\t\t\t<nPhis>%d</nPhis>\n", abp->lat[i].nphis); puts("\t\t\t<ThetaBounds>"); printf("\t\t\t\t<LowerTheta>%g</LowerTheta>\n", abp->lat[i].tmin); printf("\t\t\t\t<UpperTheta>%g</UpperTheta>\n", abp->lat[i+1].tmin); puts("\t\t\t</ThetaBounds>"); puts("\t\t\t</AngleBasisBlock>"); } puts("\t\t</AngleBasis>"); puts("\t</DataDefinition>"); }
/* Interpolate and output a radial basis function BSDF representation */ static void eval_rbf(void) { ANGLE_BASIS *abp = get_basis(kbasis); float bsdfarr[MAXPATCHES*MAXPATCHES]; FVECT vin, vout; RBFNODE *rbf; double sum; int i, j, n; /* sanity check */ if (abp->nangles > MAXPATCHES) { fprintf(stderr, "%s: too many patches!\n", progname); exit(1); } data_prologue(); /* begin output */ for (i = 0; i < abp->nangles; i++) { if (input_orient > 0) /* use incident patch center */ fi_getvec(vin, i+.5*(i>0), abp); else bi_getvec(vin, i+.5*(i>0), abp); rbf = advect_rbf(vin); /* compute radial basis func */ for (j = 0; j < abp->nangles; j++) { sum = 0; /* sample over exiting patch */ for (n = npsamps; n--; ) { if (output_orient > 0) fo_getvec(vout, j+(n+frandom())/npsamps, abp); else bo_getvec(vout, j+(n+frandom())/npsamps, abp); sum += eval_rbfrep(rbf, vout) / vout[2]; } bsdfarr[j*abp->nangles + i] = sum*output_orient/npsamps; } if (rbf != NULL) free(rbf); } n = 0; /* write out our matrix */ for (j = 0; j < abp->nangles; j++) { for (i = 0; i < abp->nangles; i++) printf("\t%.3e\n", bsdfarr[n++]); putchar('\n'); } data_epilogue(); /* finish output */ }
/* Interpolate and output a BSDF function using Klems basis */ static void eval_function(char *funame) { ANGLE_BASIS *abp = get_basis(kbasis); int assignD = (fundefined(funame) < 6); FILE *ofp = open_component_file(CIE_Y); double iovec[6]; double sum; int i, j, n; initurand(npsamps); for (j = 0; j < abp->nangles; j++) { /* run through directions */ for (i = 0; i < abp->nangles; i++) { sum = 0; for (n = npsamps; n--; ) { /* average over patches */ if (output_orient > 0) fo_getvec(iovec+3, j+(n+frandom())/npsamps, abp); else bo_getvec(iovec+3, j+(n+frandom())/npsamps, abp); if (input_orient > 0) fi_getvec(iovec, i+urand(n), abp); else bi_getvec(iovec, i+urand(n), abp); if (assignD) { varset("Dx", '=', -iovec[3]); varset("Dy", '=', -iovec[4]); varset("Dz", '=', -iovec[5]); ++eclock; } sum += funvalue(funame, 6, iovec); } fprintf(ofp, "\t%.3e\n", sum/npsamps); } fputc('\n', ofp); prog_show((j+1.)/abp->nangles); } prog_done(); if (fclose(ofp)) { fprintf(stderr, "%s: error writing Y output\n", progname); exit(1); } }
/* Interpolate and output a BSDF function using Klems basis */ static void eval_function(char *funame) { ANGLE_BASIS *abp = get_basis(kbasis); int assignD = (fundefined(funame) < 6); double iovec[6]; double sum; int i, j, n; initurand(npsamps); data_prologue(); /* begin output */ for (j = 0; j < abp->nangles; j++) { /* run through directions */ for (i = 0; i < abp->nangles; i++) { sum = 0; for (n = npsamps; n--; ) { /* average over patches */ if (output_orient > 0) fo_getvec(iovec+3, j+(n+frandom())/npsamps, abp); else bo_getvec(iovec+3, j+(n+frandom())/npsamps, abp); if (input_orient > 0) fi_getvec(iovec, i+urand(n), abp); else bi_getvec(iovec, i+urand(n), abp); if (assignD) { varset("Dx", '=', -iovec[3]); varset("Dy", '=', -iovec[4]); varset("Dz", '=', -iovec[5]); ++eclock; } sum += funvalue(funame, 6, iovec); } printf("\t%.3e\n", sum/npsamps); } putchar('\n'); } data_epilogue(); /* finish output */ }
gint get_next_group(FILE *fp, struct model_pak *model, gint *have_basis) { gchar *line, *keyword; gint ret; GSList *keywords = NULL, *list; line = file_read_line(fp); if (!line) return(FALSE); /* TODO not a valid keyword so for the moment skip but could store */ if (g_ascii_strncasecmp(line, " $", 2) != 0) return(TRUE); if (g_ascii_strncasecmp(line, " $data", 6) == 0) { ret = get_data(fp, model, *have_basis); } else if (g_ascii_strncasecmp(line, " $basis", 7) == 0) { *have_basis = TRUE; keywords = get_gamess_keywords(fp, line+7, &ret); for (list=keywords ; list ; list=g_slist_next(list)) { keyword = (gchar *) list->data; ret = get_basis(keyword, model); } } else if (g_ascii_strncasecmp(line, " $contrl", 8) == 0) { keywords = get_gamess_keywords(fp, line+8, &ret); for (list=keywords; list ; list=g_slist_next(list)) { keyword = (gchar *) list->data; ret = get_control(keyword, model); } } else if (g_ascii_strncasecmp(line, " $system", 8) == 0) { keywords = get_gamess_keywords(fp, line+8, &ret); for (list=keywords; list ; list=g_slist_next(list)) { keyword = (gchar *) list->data; ret = get_system(keyword, model); } } else if (g_ascii_strncasecmp(line, " $statpt", 8) == 0) { keywords = get_gamess_keywords(fp, line+8, &ret); for (list=keywords; list ; list=g_slist_next(list)) { keyword = (gchar *) list->data; ret = get_statpt(keyword, model); } } else if (g_ascii_strncasecmp(line, " $dft", 5) == 0) { model->gamess.dft = TRUE; /* TODO - process functional */ } else { /* TODO - Unknown keyword, just pass through */ } free_slist(keywords); g_free(line); return(TRUE); }
node_desc *create_explicit_node_desc(lp_prob *p) { LPdata *lp_data = p->lp_data; int m = lp_data->m, n = lp_data->n; int bvarnum = p->base.varnum; var_desc **extravars = lp_data->vars + bvarnum; int extravarnum = n - bvarnum; int bcutnum = p->base.cutnum; row_data *rows = lp_data->rows; int extrarownum = m - bcutnum; int cutindsize; node_desc *desc = (node_desc *) calloc(1, sizeof(node_desc)); /* Will need these anyway for basis */ int *rstat = (int *) malloc(m * ISIZE); int *cstat = (int *) malloc(n * ISIZE); int *erstat = (extrarownum == 0) ? NULL : (int *) malloc(extrarownum*ISIZE); int *ecstat = (extravarnum == 0) ? NULL : (int *) malloc(extravarnum*ISIZE); int *ulist, *clist; /* this later uses tmp.i1 */ int cutcnt, i, j; #ifndef COMPILE_IN_LP int s_bufid, r_bufid; #endif get_basis(lp_data, cstat, rstat); if (extrarownum > 0) memcpy(erstat, rstat + bcutnum, extrarownum * ISIZE); if (extravarnum > 0) memcpy(ecstat, cstat + bvarnum, extravarnum * ISIZE); /* To start with, send the non-indexed cuts (only those which will be saved) to the treemanager and ask for names */ for (cutcnt = cutindsize = 0, i = bcutnum; i < m; i++){ if ((rows[i].cut->branch & CUT_BRANCHED_ON) || !rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC)){ cutindsize++; if (rows[i].cut->name < 0) cutcnt++; } } if (cutcnt > 0){ #ifdef COMPILE_IN_LP row_data *tmp_rows = (row_data *) malloc(cutcnt*sizeof(row_data)); for (j = 0, i = bcutnum; j < cutcnt; i++){ if (rows[i].cut->name < 0 && (!rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC))) tmp_rows[j++] = rows[i]; } unpack_cut_set(p->tm, 0, cutcnt, tmp_rows); FREE(tmp_rows); #else s_bufid = init_send(DataInPlace); send_int_array(&cutcnt, 1); for (i = bcutnum; i < m; i++){ if (rows[i].cut->name < 0 && (!rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC))) pack_cut(rows[i].cut); } send_msg(p->tree_manager, LP__CUT_NAMES_REQUESTED); freebuf(s_bufid); #endif } /* create the uind list and the extravars basis description */ desc->uind.type = EXPLICIT_LIST; desc->uind.added = 0; desc->uind.size = extravarnum; desc->basis.extravars.type = EXPLICIT_LIST; desc->basis.extravars.size = extravarnum; desc->basis.extravars.list = NULL; if (extravarnum > 0){ desc->uind.list = ulist = (int *) malloc(extravarnum * ISIZE); desc->basis.extravars.stat = ecstat; for (i = extravarnum - 1; i >= 0; i--) ulist[i] = extravars[i]->userind; if (lp_data->ordering == COLIND_ORDERED) qsortucb_ii(ulist, ecstat, extravarnum); }else{ desc->uind.list = NULL; desc->basis.extravars.stat = NULL; } /* create the basevars basis description */ desc->basis.basevars.type = EXPLICIT_LIST; desc->basis.basevars.size = bvarnum; desc->basis.basevars.list = NULL; if (bvarnum) desc->basis.basevars.stat = cstat; else FREE(cstat); /* create the not_fixed list */ desc->nf_status = lp_data->nf_status; if (desc->nf_status == NF_CHECK_AFTER_LAST || desc->nf_status == NF_CHECK_UNTIL_LAST){ desc->not_fixed.type = EXPLICIT_LIST; desc->not_fixed.added = 0; if ((desc->not_fixed.size = lp_data->not_fixed_num) > 0){ desc->not_fixed.list = (int *) malloc(desc->not_fixed.size * ISIZE); memcpy(desc->not_fixed.list, lp_data->not_fixed, lp_data->not_fixed_num * ISIZE); }else{ desc->not_fixed.list = NULL; } } #ifndef COMPILE_IN_LP /* At this point we will need the missing names */ if (cutcnt > 0){ static struct timeval tout = {15, 0}; int *names = lp_data->tmp.i1; /* m */ double start = wall_clock(NULL); do{ r_bufid = treceive_msg(p->tree_manager, LP__CUT_NAMES_SERVED, &tout); if (! r_bufid){ if (pstat(p->tree_manager) != PROCESS_OK){ printf("TM has died -- LP exiting\n\n"); exit(-301); } } }while (! r_bufid); p->comp_times.idle_names += wall_clock(NULL) - start; receive_int_array(names, cutcnt); for (j = 0, i = bcutnum; j < cutcnt; i++){ if (rows[i].cut->name < 0 && (!rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC))) rows[i].cut->name = names[j++]; } } #endif /* create the cutind list and the extrarows basis description */ desc->cutind.type = EXPLICIT_LIST; desc->cutind.added = 0; desc->cutind.size = cutindsize; desc->basis.extrarows.type = EXPLICIT_LIST; desc->basis.extrarows.list = NULL; desc->basis.extrarows.size = cutindsize; if (cutindsize > 0){ desc->cutind.list = clist = (int *) malloc(cutindsize * ISIZE); desc->basis.extrarows.stat = erstat; for (cutindsize = 0, i = bcutnum; i < m; i++){ if ((rows[i].cut->branch & CUT_BRANCHED_ON) || !rows[i].free || (rows[i].free && rstat[i] != SLACK_BASIC)){ clist[cutindsize] = rows[i].cut->name; erstat[cutindsize++] = rstat[i]; } } qsortucb_ii(clist, erstat, cutindsize); }else{ desc->cutind.list = NULL; desc->basis.extrarows.stat = NULL; } /* create the baserows basis description */ desc->basis.baserows.type = EXPLICIT_LIST; desc->basis.baserows.size = bcutnum; desc->basis.baserows.list = NULL; if (bcutnum) desc->basis.baserows.stat = rstat; else FREE(rstat); /* Mark that there is a basis */ desc->basis.basis_exists = TRUE; /* Add user description */ add_to_desc_u(p, desc); return(desc); }
/* Interpolate and output a radial basis function BSDF representation */ static void eval_rbf(void) { ANGLE_BASIS *abp = get_basis(kbasis); float (*XZarr)[2] = NULL; float bsdfarr[MAXPATCHES*MAXPATCHES]; FILE *cfp[3]; FVECT vin, vout; double sum, xsum, ysum; int i, j, n; /* sanity check */ if (abp->nangles > MAXPATCHES) { fprintf(stderr, "%s: too many patches!\n", progname); exit(1); } if (rbf_colorimetry == RBCtristimulus) XZarr = (float (*)[2])malloc(sizeof(float)*2*abp->nangles*abp->nangles); for (i = 0; i < abp->nangles; i++) { RBFNODE *rbf; if (input_orient > 0) /* use incident patch center */ fi_getvec(vin, i+.5*(i>0), abp); else bi_getvec(vin, i+.5*(i>0), abp); rbf = advect_rbf(vin, lobe_lim); /* compute radial basis func */ for (j = 0; j < abp->nangles; j++) { sum = 0; /* sample over exiting patch */ xsum = ysum = 0; for (n = npsamps; n--; ) { SDValue sdv; if (output_orient > 0) fo_getvec(vout, j+(n+frandom())/npsamps, abp); else bo_getvec(vout, j+(n+frandom())/npsamps, abp); eval_rbfcol(&sdv, rbf, vout); sum += sdv.cieY; if (rbf_colorimetry == RBCtristimulus) { xsum += sdv.cieY * sdv.spec.cx; ysum += sdv.cieY * sdv.spec.cy; } } n = j*abp->nangles + i; bsdfarr[n] = sum / npsamps; if (rbf_colorimetry == RBCtristimulus) { XZarr[n][0] = xsum*sum/(npsamps*ysum); XZarr[n][1] = (sum - xsum - ysum)*sum/(npsamps*ysum); } } if (rbf != NULL) free(rbf); prog_show((i+1.)/abp->nangles); } /* write out our matrix */ cfp[CIE_Y] = open_component_file(CIE_Y); n = 0; for (j = 0; j < abp->nangles; j++) { for (i = 0; i < abp->nangles; i++, n++) fprintf(cfp[CIE_Y], "\t%.3e\n", bsdfarr[n]); fputc('\n', cfp[CIE_Y]); } prog_done(); if (fclose(cfp[CIE_Y])) { fprintf(stderr, "%s: error writing Y output\n", progname); exit(1); } if (XZarr == NULL) /* no color? */ return; cfp[CIE_X] = open_component_file(CIE_X); cfp[CIE_Z] = open_component_file(CIE_Z); n = 0; for (j = 0; j < abp->nangles; j++) { for (i = 0; i < abp->nangles; i++, n++) { fprintf(cfp[CIE_X], "\t%.3e\n", XZarr[n][0]); fprintf(cfp[CIE_Z], "\t%.3e\n", XZarr[n][1]); } fputc('\n', cfp[CIE_X]); fputc('\n', cfp[CIE_Z]); } free(XZarr); if (fclose(cfp[CIE_X]) || fclose(cfp[CIE_Z])) { fprintf(stderr, "%s: error writing X/Z output\n", progname); exit(1); } }
/* Load and resample XML BSDF description using Klems basis */ static void eval_bsdf(const char *fname) { ANGLE_BASIS *abp = get_basis(kbasis); FILE *cfp[3]; SDData bsd; SDError ec; FVECT vin, vout; SDValue sdv; double sum, xsum, ysum; int i, j, n; initurand(npsamps); SDclearBSDF(&bsd, fname); /* load BSDF file */ if ((ec = SDloadFile(&bsd, fname)) != SDEnone) goto err; if (bsd.mgf != NULL) /* save geometry */ save_geom(bsd.mgf); if (bsd.matn[0]) /* save identifier(s) */ strcpy(bsdf_name, bsd.matn); if (bsd.makr[0]) strcpy(bsdf_manuf, bsd.makr); if (bsd.dim[2] > 0) { /* save dimension(s) */ char buf[64]; if ((bsd.dim[0] > 0) & (bsd.dim[1] > 0)) sprintf(buf, "w=%g;h=%g;t=%g", bsd.dim[0], bsd.dim[1], bsd.dim[2]); else sprintf(buf, "t=%g", bsd.dim[2]); add_wbsdf("-f", 1); add_wbsdf(buf, 0); } /* front reflection */ if (bsd.rf != NULL || bsd.rLambFront.cieY > .002) { input_orient = 1; output_orient = 1; cfp[CIE_Y] = open_component_file(CIE_Y); if (bsd.rf != NULL && bsd.rf->comp[0].cspec[2].flags) { rbf_colorimetry = RBCtristimulus; cfp[CIE_X] = open_component_file(CIE_X); cfp[CIE_Z] = open_component_file(CIE_Z); } else rbf_colorimetry = RBCphotopic; for (j = 0; j < abp->nangles; j++) { for (i = 0; i < abp->nangles; i++) { sum = 0; /* average over patches */ xsum = ysum = 0; for (n = npsamps; n-- > 0; ) { fo_getvec(vout, j+(n+frandom())/npsamps, abp); fi_getvec(vin, i+urand(n), abp); ec = SDevalBSDF(&sdv, vout, vin, &bsd); if (ec != SDEnone) goto err; sum += sdv.cieY; if (rbf_colorimetry == RBCtristimulus) { xsum += sdv.cieY * sdv.spec.cx; ysum += sdv.cieY * sdv.spec.cy; } } fprintf(cfp[CIE_Y], "\t%.3e\n", sum/npsamps); if (rbf_colorimetry == RBCtristimulus) { fprintf(cfp[CIE_X], "\t%.3e\n", xsum*sum/(npsamps*ysum)); fprintf(cfp[CIE_Z], "\t%.3e\n", (sum - xsum - ysum)*sum/(npsamps*ysum)); } } fputc('\n', cfp[CIE_Y]); /* extra space between rows */ if (rbf_colorimetry == RBCtristimulus) { fputc('\n', cfp[CIE_X]); fputc('\n', cfp[CIE_Z]); } } if (fclose(cfp[CIE_Y])) { fprintf(stderr, "%s: error writing Y output\n", progname); exit(1); } if (rbf_colorimetry == RBCtristimulus && (fclose(cfp[CIE_X]) || fclose(cfp[CIE_Z]))) { fprintf(stderr, "%s: error writing X/Z output\n", progname); exit(1); } } /* back reflection */ if (bsd.rb != NULL || bsd.rLambBack.cieY > .002) { input_orient = -1; output_orient = -1; cfp[CIE_Y] = open_component_file(CIE_Y); if (bsd.rb != NULL && bsd.rb->comp[0].cspec[2].flags) { rbf_colorimetry = RBCtristimulus; cfp[CIE_X] = open_component_file(CIE_X); cfp[CIE_Z] = open_component_file(CIE_Z); } else rbf_colorimetry = RBCphotopic; for (j = 0; j < abp->nangles; j++) { for (i = 0; i < abp->nangles; i++) { sum = 0; /* average over patches */ xsum = ysum = 0; for (n = npsamps; n-- > 0; ) { bo_getvec(vout, j+(n+frandom())/npsamps, abp); bi_getvec(vin, i+urand(n), abp); ec = SDevalBSDF(&sdv, vout, vin, &bsd); if (ec != SDEnone) goto err; sum += sdv.cieY; if (rbf_colorimetry == RBCtristimulus) { xsum += sdv.cieY * sdv.spec.cx; ysum += sdv.cieY * sdv.spec.cy; } } fprintf(cfp[CIE_Y], "\t%.3e\n", sum/npsamps); if (rbf_colorimetry == RBCtristimulus) { fprintf(cfp[CIE_X], "\t%.3e\n", xsum*sum/(npsamps*ysum)); fprintf(cfp[CIE_Z], "\t%.3e\n", (sum - xsum - ysum)*sum/(npsamps*ysum)); } } if (rbf_colorimetry == RBCtristimulus) { fputc('\n', cfp[CIE_X]); fputc('\n', cfp[CIE_Z]); } } if (fclose(cfp[CIE_Y])) { fprintf(stderr, "%s: error writing Y output\n", progname); exit(1); } if (rbf_colorimetry == RBCtristimulus && (fclose(cfp[CIE_X]) || fclose(cfp[CIE_Z]))) { fprintf(stderr, "%s: error writing X/Z output\n", progname); exit(1); } } /* front transmission */ if (bsd.tf != NULL || bsd.tLamb.cieY > .002) { input_orient = 1; output_orient = -1; cfp[CIE_Y] = open_component_file(CIE_Y); if (bsd.tf != NULL && bsd.tf->comp[0].cspec[2].flags) { rbf_colorimetry = RBCtristimulus; cfp[CIE_X] = open_component_file(CIE_X); cfp[CIE_Z] = open_component_file(CIE_Z); } else rbf_colorimetry = RBCphotopic; for (j = 0; j < abp->nangles; j++) { for (i = 0; i < abp->nangles; i++) { sum = 0; /* average over patches */ xsum = ysum = 0; for (n = npsamps; n-- > 0; ) { bo_getvec(vout, j+(n+frandom())/npsamps, abp); fi_getvec(vin, i+urand(n), abp); ec = SDevalBSDF(&sdv, vout, vin, &bsd); if (ec != SDEnone) goto err; sum += sdv.cieY; if (rbf_colorimetry == RBCtristimulus) { xsum += sdv.cieY * sdv.spec.cx; ysum += sdv.cieY * sdv.spec.cy; } } fprintf(cfp[CIE_Y], "\t%.3e\n", sum/npsamps); if (rbf_colorimetry == RBCtristimulus) { fprintf(cfp[CIE_X], "\t%.3e\n", xsum*sum/(npsamps*ysum)); fprintf(cfp[CIE_Z], "\t%.3e\n", (sum - xsum - ysum)*sum/(npsamps*ysum)); } } if (rbf_colorimetry == RBCtristimulus) { fputc('\n', cfp[CIE_X]); fputc('\n', cfp[CIE_Z]); } } if (fclose(cfp[CIE_Y])) { fprintf(stderr, "%s: error writing Y output\n", progname); exit(1); } if (rbf_colorimetry == RBCtristimulus && (fclose(cfp[CIE_X]) || fclose(cfp[CIE_Z]))) { fprintf(stderr, "%s: error writing X/Z output\n", progname); exit(1); } } /* back transmission */ if ((bsd.tb != NULL) | (bsd.tf != NULL)) { input_orient = -1; output_orient = 1; cfp[CIE_Y] = open_component_file(CIE_Y); if (bsd.tb != NULL) rbf_colorimetry = bsd.tb->comp[0].cspec[2].flags ? RBCtristimulus : RBCphotopic ; if (rbf_colorimetry == RBCtristimulus) { cfp[CIE_X] = open_component_file(CIE_X); cfp[CIE_Z] = open_component_file(CIE_Z); } for (j = 0; j < abp->nangles; j++) { for (i = 0; i < abp->nangles; i++) { sum = 0; /* average over patches */ xsum = ysum = 0; for (n = npsamps; n-- > 0; ) { fo_getvec(vout, j+(n+frandom())/npsamps, abp); bi_getvec(vin, i+urand(n), abp); ec = SDevalBSDF(&sdv, vout, vin, &bsd); if (ec != SDEnone) goto err; sum += sdv.cieY; if (rbf_colorimetry == RBCtristimulus) { xsum += sdv.cieY * sdv.spec.cx; ysum += sdv.cieY * sdv.spec.cy; } } fprintf(cfp[CIE_Y], "\t%.3e\n", sum/npsamps); if (rbf_colorimetry == RBCtristimulus) { fprintf(cfp[CIE_X], "\t%.3e\n", xsum*sum/(npsamps*ysum)); fprintf(cfp[CIE_Z], "\t%.3e\n", (sum - xsum - ysum)*sum/(npsamps*ysum)); } } if (rbf_colorimetry == RBCtristimulus) { fputc('\n', cfp[CIE_X]); fputc('\n', cfp[CIE_Z]); } } if (fclose(cfp[CIE_Y])) { fprintf(stderr, "%s: error writing Y output\n", progname); exit(1); } if (rbf_colorimetry == RBCtristimulus && (fclose(cfp[CIE_X]) || fclose(cfp[CIE_Z]))) { fprintf(stderr, "%s: error writing X/Z output\n", progname); exit(1); } } SDfreeBSDF(&bsd); /* all done */ return; err: SDreportError(ec, stderr); exit(1); }
/* Load and resample XML BSDF description using Klems basis */ static void eval_bsdf(const char *fname) { ANGLE_BASIS *abp = get_basis(kbasis); SDData bsd; SDError ec; FVECT vin, vout; SDValue sv; double sum; int i, j, n; SDclearBSDF(&bsd, fname); /* load BSDF file */ if ((ec = SDloadFile(&bsd, fname)) != SDEnone) goto err; xml_prologue(&bsd); /* pass geometry */ /* front reflection */ if (bsd.rf != NULL || bsd.rLambFront.cieY > .002) { input_orient = 1; output_orient = 1; data_prologue(); for (j = 0; j < abp->nangles; j++) { for (i = 0; i < abp->nangles; i++) { sum = 0; /* average over patches */ for (n = npsamps; n-- > 0; ) { fo_getvec(vout, j+(n+frandom())/npsamps, abp); fi_getvec(vin, i+urand(n), abp); ec = SDevalBSDF(&sv, vout, vin, &bsd); if (ec != SDEnone) goto err; sum += sv.cieY; } printf("\t%.3e\n", sum/npsamps); } putchar('\n'); /* extra space between rows */ } data_epilogue(); } /* back reflection */ if (bsd.rb != NULL || bsd.rLambBack.cieY > .002) { input_orient = -1; output_orient = -1; data_prologue(); for (j = 0; j < abp->nangles; j++) { for (i = 0; i < abp->nangles; i++) { sum = 0; /* average over patches */ for (n = npsamps; n-- > 0; ) { bo_getvec(vout, j+(n+frandom())/npsamps, abp); bi_getvec(vin, i+urand(n), abp); ec = SDevalBSDF(&sv, vout, vin, &bsd); if (ec != SDEnone) goto err; sum += sv.cieY; } printf("\t%.3e\n", sum/npsamps); } putchar('\n'); /* extra space between rows */ } data_epilogue(); } /* front transmission */ if (bsd.tf != NULL || bsd.tLamb.cieY > .002) { input_orient = 1; output_orient = -1; data_prologue(); for (j = 0; j < abp->nangles; j++) { for (i = 0; i < abp->nangles; i++) { sum = 0; /* average over patches */ for (n = npsamps; n-- > 0; ) { bo_getvec(vout, j+(n+frandom())/npsamps, abp); fi_getvec(vin, i+urand(n), abp); ec = SDevalBSDF(&sv, vout, vin, &bsd); if (ec != SDEnone) goto err; sum += sv.cieY; } printf("\t%.3e\n", sum/npsamps); } putchar('\n'); /* extra space between rows */ } data_epilogue(); } /* back transmission */ if ((bsd.tb != NULL) | (bsd.tf != NULL)) { input_orient = -1; output_orient = 1; data_prologue(); for (j = 0; j < abp->nangles; j++) { for (i = 0; i < abp->nangles; i++) { sum = 0; /* average over patches */ for (n = npsamps; n-- > 0; ) { fo_getvec(vout, j+(n+frandom())/npsamps, abp); bi_getvec(vin, i+urand(n), abp); ec = SDevalBSDF(&sv, vout, vin, &bsd); if (ec != SDEnone) goto err; sum += sv.cieY; } printf("\t%.3e\n", sum/npsamps); } putchar('\n'); /* extra space between rows */ } data_epilogue(); } SDfreeBSDF(&bsd); /* all done */ return; err: SDreportError(ec, stderr); exit(1); }