--- ray/src/util/rmatrix.h 2019/09/03 23:43:07 2.11 +++ ray/src/util/rmatrix.h 2022/03/05 01:45:21 2.15 @@ -1,4 +1,4 @@ -/* RCSid $Id: rmatrix.h,v 2.11 2019/09/03 23:43:07 greg Exp $ */ +/* RCSid $Id: rmatrix.h,v 2.15 2022/03/05 01:45:21 greg Exp $ */ /* * Header file for general matrix routines. */ @@ -12,19 +12,31 @@ extern "C" { #endif -/* General plane-ordered component matrix */ +/* Preferred BSDF component: + transmission, reflection front (normal side), reflection back */ +typedef enum {RMPtrans=0, RMPreflF, RMPreflB} RMPref; + +/* General [row][col][cmp] component matrix */ typedef struct { + char *info; + void *mapped; + double *mtx; + COLOR cexp; int nrows, ncols; short ncomp; uby8 dtype; uby8 swapin; - char *info; - double mtx[1]; /* extends struct */ } RMATRIX; -#define rmx_lval(rm,r,c,i) (rm)->mtx[(i)+(rm)->ncomp*((c)+(size_t)(rm)->ncols*(r))] +#define rmx_lval(rm,r,c) ((rm)->mtx + (rm)->ncomp*((c)+(size_t)(rm)->ncols*(r))) -/* Allocate a nr x nc matrix with n components */ +/* Initialize a RMATRIX struct but don't allocate array space */ +extern RMATRIX *rmx_new(int nr, int nc, int n); + +/* Prepare a RMATRIX for writing (allocate array if needed) */ +extern int rmx_prepare(RMATRIX *rm); + +/* Call rmx_new() and rmx_prepare() */ extern RMATRIX *rmx_alloc(int nr, int nc, int n); /* Free a RMATRIX array */ @@ -34,7 +46,7 @@ extern void rmx_free(RMATRIX *rm); extern int rmx_newtype(int dtyp1, int dtyp2); /* Load matrix from supported file type (NULL for stdin, '!' with command) */ -extern RMATRIX *rmx_load(const char *inspec); +extern RMATRIX *rmx_load(const char *inspec, RMPref rmp); /* Append header information associated with matrix data */ extern int rmx_addinfo(RMATRIX *rm, const char *info);