ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rmatrix.h
Revision: 2.15
Committed: Sat Mar 5 01:45:21 2022 UTC (2 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4
Changes since 2.14: +2 -2 lines
Log Message:
refactor(rmtxop): Changed matrix array access macros

File Contents

# Content
1 /* RCSid $Id: rmatrix.h,v 2.14 2022/03/04 01:27:12 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 [row][col][cmp] component matrix */
20 typedef struct {
21 char *info;
22 void *mapped;
23 double *mtx;
24 COLOR cexp;
25 int nrows, ncols;
26 short ncomp;
27 uby8 dtype;
28 uby8 swapin;
29 } RMATRIX;
30
31 #define rmx_lval(rm,r,c) ((rm)->mtx + (rm)->ncomp*((c)+(size_t)(rm)->ncols*(r)))
32
33 /* Initialize a RMATRIX struct but don't allocate array space */
34 extern RMATRIX *rmx_new(int nr, int nc, int n);
35
36 /* Prepare a RMATRIX for writing (allocate array if needed) */
37 extern int rmx_prepare(RMATRIX *rm);
38
39 /* Call rmx_new() and rmx_prepare() */
40 extern RMATRIX *rmx_alloc(int nr, int nc, int n);
41
42 /* Free a RMATRIX array */
43 extern void rmx_free(RMATRIX *rm);
44
45 /* Resolve data type based on two input types (returns 0 for mismatch) */
46 extern int rmx_newtype(int dtyp1, int dtyp2);
47
48 /* Load matrix from supported file type (NULL for stdin, '!' with command) */
49 extern RMATRIX *rmx_load(const char *inspec, RMPref rmp);
50
51 /* Append header information associated with matrix data */
52 extern int rmx_addinfo(RMATRIX *rm, const char *info);
53
54 /* Write matrix to file type indicated by dtype */
55 extern int rmx_write(const RMATRIX *rm, int dtype, FILE *fp);
56
57 /* Allocate and assign square identity matrix with n components */
58 extern RMATRIX *rmx_identity(int dim, int n);
59
60 /* Duplicate the given matrix */
61 extern RMATRIX *rmx_copy(const RMATRIX *rm);
62
63 /* Allocate and assign transposed matrix */
64 extern RMATRIX *rmx_transpose(const RMATRIX *rm);
65
66 /* Multiply (concatenate) two matrices and allocate the result */
67 extern RMATRIX *rmx_multiply(const RMATRIX *m1, const RMATRIX *m2);
68
69 /* Element-wise multiplication (or division) of m2 into m1 */
70 extern int rmx_elemult(RMATRIX *m1, const RMATRIX *m2, int divide);
71
72 /* Sum second matrix into first, applying scale factor beforehand */
73 extern int rmx_sum(RMATRIX *msum, const RMATRIX *madd, const double sf[]);
74
75 /* Scale the given matrix by the indicated scalar component vector */
76 extern int rmx_scale(RMATRIX *rm, const double sf[]);
77
78 /* Allocate new matrix and apply component transformation */
79 extern RMATRIX *rmx_transform(const RMATRIX *msrc, int n, const double cmat[]);
80
81 /* Convert a color matrix to newly allocated RMATRIX buffer */
82 extern RMATRIX *rmx_from_cmatrix(const CMATRIX *cm);
83
84 /* Convert general matrix to newly allocated CMATRIX buffer */
85 extern CMATRIX *cm_from_rmatrix(const RMATRIX *rm);
86
87 #ifdef __cplusplus
88 }
89 #endif
90 #endif /* _RAD_RMATRIX_H_ */