--- ray/src/util/rmatrix.h 2022/03/05 01:45:21 2.15 +++ ray/src/util/rmatrix.h 2023/12/06 17:57:34 2.20 @@ -1,4 +1,4 @@ -/* RCSid $Id: rmatrix.h,v 2.15 2022/03/05 01:45:21 greg Exp $ */ +/* RCSid $Id: rmatrix.h,v 2.20 2023/12/06 17:57:34 greg Exp $ */ /* * Header file for general matrix routines. */ @@ -13,8 +13,8 @@ extern "C" { #endif /* Preferred BSDF component: - transmission, reflection front (normal side), reflection back */ -typedef enum {RMPtrans=0, RMPreflF, RMPreflB} RMPref; + none, transmission, reflection front (normal side), reflection back */ +typedef enum {RMPnone=-1, RMPtrans=0, RMPreflF, RMPreflB} RMPref; /* General [row][col][cmp] component matrix */ typedef struct { @@ -22,6 +22,7 @@ typedef struct { void *mapped; double *mtx; COLOR cexp; + float wlpart[4]; int nrows, ncols; short ncomp; uby8 dtype; @@ -29,6 +30,7 @@ typedef struct { } RMATRIX; #define rmx_lval(rm,r,c) ((rm)->mtx + (rm)->ncomp*((c)+(size_t)(rm)->ncols*(r))) +#define rmx_val rmx_lval /* Initialize a RMATRIX struct but don't allocate array space */ extern RMATRIX *rmx_new(int nr, int nc, int n); @@ -39,19 +41,38 @@ 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 */ +/* Clear state by freeing info and matrix data */ +extern void rmx_reset(RMATRIX *rm); + +/* Free an RMATRIX struct and data */ 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); /* Append header information associated with matrix data */ extern int rmx_addinfo(RMATRIX *rm, const char *info); -/* Write matrix to file type indicated by dtype */ +/* Finish writing header data with resolution and format, returning type used */ +extern int rmx_write_header(const RMATRIX *rm, int dtype, FILE *fp); + +/* Write out matrix data (usually by row) */ +extern int rmx_write_data(const double *dp, int nc, int len, + int dtype, FILE *fp); + +/* Write matrix using file format indicated by dtype */ extern int rmx_write(const RMATRIX *rm, int dtype, FILE *fp); /* Allocate and assign square identity matrix with n components */ @@ -59,6 +80,9 @@ extern RMATRIX *rmx_identity(int dim, int n); /* Duplicate the given matrix */ extern RMATRIX *rmx_copy(const RMATRIX *rm); + +/* Replace data in first matrix with data from second */ +extern int rmx_transfer_data(RMATRIX *rdst, RMATRIX *rsrc, int dometa); /* Allocate and assign transposed matrix */ extern RMATRIX *rmx_transpose(const RMATRIX *rm);