--- ray/src/util/rmatrix.h 2014/08/27 13:33:47 2.5 +++ ray/src/util/rmatrix.h 2023/11/21 01:30:20 2.16 @@ -1,4 +1,4 @@ -/* RCSid $Id: rmatrix.h,v 2.5 2014/08/27 13:33:47 greg Exp $ */ +/* RCSid $Id: rmatrix.h,v 2.16 2023/11/21 01:30:20 greg Exp $ */ /* * Header file for general matrix routines. */ @@ -12,17 +12,32 @@ 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 { - int nrows, ncols, ncomp; - int dtype; char *info; - double mtx[1]; /* extends struct */ + void *mapped; + double *mtx; + COLOR cexp; + float wlpart[4]; + int nrows, ncols; + short ncomp; + uby8 dtype; + uby8 swapin; } RMATRIX; -#define rmx_lval(rm,r,c,i) (rm)->mtx[(i)+(rm)->ncomp*((c)+(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 */ @@ -31,14 +46,14 @@ extern void rmx_free(RMATRIX *rm); /* Resolve data type based on two input types (returns 0 for mismatch) */ extern int rmx_newtype(int dtyp1, int dtyp2); -/* Load matrix from supported file type */ -extern RMATRIX *rmx_load(const char *fname); +/* Load matrix from supported file type (NULL for stdin, '!' with command) */ +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); /* Write matrix to file type indicated by dtype */ -extern long rmx_write(const RMATRIX *rm, int dtype, FILE *fp); +extern int rmx_write(const RMATRIX *rm, int dtype, FILE *fp); /* Allocate and assign square identity matrix with n components */ extern RMATRIX *rmx_identity(int dim, int n); @@ -51,6 +66,9 @@ extern RMATRIX *rmx_transpose(const RMATRIX *rm); /* Multiply (concatenate) two matrices and allocate the result */ extern RMATRIX *rmx_multiply(const RMATRIX *m1, const RMATRIX *m2); + +/* Element-wise multiplication (or division) of m2 into m1 */ +extern int rmx_elemult(RMATRIX *m1, const RMATRIX *m2, int divide); /* Sum second matrix into first, applying scale factor beforehand */ extern int rmx_sum(RMATRIX *msum, const RMATRIX *madd, const double sf[]);