ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rmatrix.h
Revision: 2.13
Committed: Tue Jan 19 23:32:00 2021 UTC (3 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.12: +6 -2 lines
Log Message:
feat: Added -rf and -rb options to rmtxop to load XML reflectance matrices

File Contents

# Content
1 /* RCSid $Id: rmatrix.h,v 2.12 2020/03/25 01:51:09 greg Exp $ */
2 /*
3 * Header file for general matrix routines.
4 */
5
6 #ifndef _RAD_RMATRIX_H_
7 #define _RAD_RMATRIX_H_
8
9 #include "cmatrix.h"
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 /* Preferred BSDF component:
16 transmission, reflection front (normal side), reflection back */
17 typedef enum {RMPtrans=0, RMPreflF, RMPreflB} RMPref;
18
19 /* General plane-ordered component matrix */
20 typedef struct {
21 int nrows, ncols;
22 short ncomp;
23 uby8 dtype;
24 uby8 swapin;
25 char *info;
26 double mtx[3]; /* extends struct */
27 } RMATRIX;
28
29 #define rmx_lval(rm,r,c,i) (rm)->mtx[(i)+(rm)->ncomp*((c)+(size_t)(rm)->ncols*(r))]
30
31 /* Allocate a nr x nc matrix with n components */
32 extern RMATRIX *rmx_alloc(int nr, int nc, int n);
33
34 /* Free a RMATRIX array */
35 extern void rmx_free(RMATRIX *rm);
36
37 /* Resolve data type based on two input types (returns 0 for mismatch) */
38 extern int rmx_newtype(int dtyp1, int dtyp2);
39
40 /* Load matrix from supported file type (NULL for stdin, '!' with command) */
41 extern RMATRIX *rmx_load(const char *inspec, RMPref rmp);
42
43 /* Append header information associated with matrix data */
44 extern int rmx_addinfo(RMATRIX *rm, const char *info);
45
46 /* Write matrix to file type indicated by dtype */
47 extern int rmx_write(const RMATRIX *rm, int dtype, FILE *fp);
48
49 /* Allocate and assign square identity matrix with n components */
50 extern RMATRIX *rmx_identity(int dim, int n);
51
52 /* Duplicate the given matrix */
53 extern RMATRIX *rmx_copy(const RMATRIX *rm);
54
55 /* Allocate and assign transposed matrix */
56 extern RMATRIX *rmx_transpose(const RMATRIX *rm);
57
58 /* Multiply (concatenate) two matrices and allocate the result */
59 extern RMATRIX *rmx_multiply(const RMATRIX *m1, const RMATRIX *m2);
60
61 /* Element-wise multiplication (or division) of m2 into m1 */
62 extern int rmx_elemult(RMATRIX *m1, const RMATRIX *m2, int divide);
63
64 /* Sum second matrix into first, applying scale factor beforehand */
65 extern int rmx_sum(RMATRIX *msum, const RMATRIX *madd, const double sf[]);
66
67 /* Scale the given matrix by the indicated scalar component vector */
68 extern int rmx_scale(RMATRIX *rm, const double sf[]);
69
70 /* Allocate new matrix and apply component transformation */
71 extern RMATRIX *rmx_transform(const RMATRIX *msrc, int n, const double cmat[]);
72
73 /* Convert a color matrix to newly allocated RMATRIX buffer */
74 extern RMATRIX *rmx_from_cmatrix(const CMATRIX *cm);
75
76 /* Convert general matrix to newly allocated CMATRIX buffer */
77 extern CMATRIX *cm_from_rmatrix(const RMATRIX *rm);
78
79 #ifdef __cplusplus
80 }
81 #endif
82 #endif /* _RAD_RMATRIX_H_ */