--- ray/src/util/rmatrix.h 2021/01/19 23:32:00 2.13 +++ ray/src/util/rmatrix.h 2023/11/28 21:07:20 2.18 @@ -1,4 +1,4 @@ -/* RCSid $Id: rmatrix.h,v 2.13 2021/01/19 23:32:00 greg Exp $ */ +/* RCSid $Id: rmatrix.h,v 2.18 2023/11/28 21:07:20 greg Exp $ */ /* * Header file for general matrix routines. */ @@ -16,19 +16,29 @@ extern "C" { transmission, reflection front (normal side), reflection back */ typedef enum {RMPtrans=0, RMPreflF, RMPreflB} RMPref; -/* General plane-ordered component matrix */ +/* General [row][col][cmp] component matrix */ typedef struct { + char *info; + void *mapped; + double *mtx; + COLOR cexp; + float wlpart[4]; int nrows, ncols; short ncomp; uby8 dtype; uby8 swapin; - char *info; - double mtx[3]; /* 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))) +#define rmx_val rmx_lval -/* 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 */ @@ -36,6 +46,15 @@ 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); + +/* Read matrix header from input stream (cannot be XML) */ +extern int rmx_load_header(RMATRIX *rm, FILE *fp); + +/* Load next row as double (cannot be XML) */ +extern int rmx_load_row(double *drp, const RMATRIX *rm, FILE *fp); + +/* Allocate & load post-header data from stream given type set in rm->dtype */ +extern int rmx_load_data(RMATRIX *rm, FILE *fp); /* Load matrix from supported file type (NULL for stdin, '!' with command) */ extern RMATRIX *rmx_load(const char *inspec, RMPref rmp);