12 |
|
extern "C" { |
13 |
|
#endif |
14 |
|
|
15 |
< |
/* General plane-ordered component matrix */ |
15 |
> |
/* Preferred BSDF component: |
16 |
> |
transmission, reflection front (normal side), reflection back */ |
17 |
> |
typedef enum {RMPtrans=0, RMPreflF, RMPreflB} RMPref; |
18 |
> |
|
19 |
> |
/* General [row][col][cmp] component matrix */ |
20 |
|
typedef struct { |
17 |
– |
int nrows, ncols, ncomp; |
21 |
|
char *info; |
22 |
< |
double mtx[1]; /* extends struct */ |
22 |
> |
void *mapped; |
23 |
> |
double *mtx; |
24 |
> |
COLOR cexp; |
25 |
> |
float wlpart[4]; |
26 |
> |
int nrows, ncols; |
27 |
> |
short ncomp; |
28 |
> |
uby8 dtype; |
29 |
> |
uby8 swapin; |
30 |
|
} RMATRIX; |
31 |
|
|
32 |
< |
#define rmx_lval(rm,r,c,i) (rm)->mtx[((i)*(rm)->nrows+(r))*(rm)->ncols+(c)] |
32 |
> |
#define rmx_lval(rm,r,c) ((rm)->mtx + (rm)->ncomp*((c)+(size_t)(rm)->ncols*(r))) |
33 |
> |
#define rmx_val rmx_lval |
34 |
|
|
35 |
< |
#define rmx_free(rm) free(rm) |
35 |
> |
/* Initialize a RMATRIX struct but don't allocate array space */ |
36 |
> |
extern RMATRIX *rmx_new(int nr, int nc, int n); |
37 |
|
|
38 |
< |
/* Allocate a nr x nc matrix with n components */ |
38 |
> |
/* Prepare a RMATRIX for writing (allocate array if needed) */ |
39 |
> |
extern int rmx_prepare(RMATRIX *rm); |
40 |
> |
|
41 |
> |
/* Call rmx_new() and rmx_prepare() */ |
42 |
|
extern RMATRIX *rmx_alloc(int nr, int nc, int n); |
43 |
|
|
44 |
< |
/* Load matrix from supported file type */ |
45 |
< |
extern RMATRIX *rmx_load(const char *fname); |
44 |
> |
/* Free a RMATRIX array */ |
45 |
> |
extern void rmx_free(RMATRIX *rm); |
46 |
|
|
47 |
+ |
/* Resolve data type based on two input types (returns 0 for mismatch) */ |
48 |
+ |
extern int rmx_newtype(int dtyp1, int dtyp2); |
49 |
+ |
|
50 |
+ |
/* Read matrix header from input stream (cannot be XML) */ |
51 |
+ |
extern int rmx_load_header(RMATRIX *rm, FILE *fp); |
52 |
+ |
|
53 |
+ |
/* Load next row as double (cannot be XML) */ |
54 |
+ |
extern int rmx_load_row(double *drp, const RMATRIX *rm, FILE *fp); |
55 |
+ |
|
56 |
+ |
/* Allocate & load post-header data from stream given type set in rm->dtype */ |
57 |
+ |
extern int rmx_load_data(RMATRIX *rm, FILE *fp); |
58 |
+ |
|
59 |
+ |
/* Load matrix from supported file type (NULL for stdin, '!' with command) */ |
60 |
+ |
extern RMATRIX *rmx_load(const char *inspec, RMPref rmp); |
61 |
+ |
|
62 |
|
/* Append header information associated with matrix data */ |
63 |
|
extern int rmx_addinfo(RMATRIX *rm, const char *info); |
64 |
|
|
65 |
< |
/* Write matrix to file type indicated by dt */ |
66 |
< |
extern long rmx_write(const RMATRIX *rm, int dtype, FILE *fp); |
65 |
> |
/* Write matrix to file type indicated by dtype */ |
66 |
> |
extern int rmx_write(const RMATRIX *rm, int dtype, FILE *fp); |
67 |
|
|
68 |
|
/* Allocate and assign square identity matrix with n components */ |
69 |
|
extern RMATRIX *rmx_identity(int dim, int n); |
76 |
|
|
77 |
|
/* Multiply (concatenate) two matrices and allocate the result */ |
78 |
|
extern RMATRIX *rmx_multiply(const RMATRIX *m1, const RMATRIX *m2); |
79 |
+ |
|
80 |
+ |
/* Element-wise multiplication (or division) of m2 into m1 */ |
81 |
+ |
extern int rmx_elemult(RMATRIX *m1, const RMATRIX *m2, int divide); |
82 |
|
|
83 |
|
/* Sum second matrix into first, applying scale factor beforehand */ |
84 |
|
extern int rmx_sum(RMATRIX *msum, const RMATRIX *madd, const double sf[]); |