ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rmatrix.h
Revision: 2.19
Committed: Fri Dec 1 02:05:00 2023 UTC (4 months, 3 weeks ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.18: +15 -5 lines
Log Message:
refactor(rmtxop): Changed rmatrix library interface for by row matrix output

File Contents

# Content
1 /* RCSid $Id: rmatrix.h,v 2.18 2023/11/28 21:07:20 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 none, transmission, reflection front (normal side), reflection back */
17 typedef enum {RMPnone=-1, 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 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) ((rm)->mtx + (rm)->ncomp*((c)+(size_t)(rm)->ncols*(r)))
33 #define rmx_val rmx_lval
34
35 /* Initialize a RMATRIX struct but don't allocate array space */
36 extern RMATRIX *rmx_new(int nr, int nc, int n);
37
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 /* Clear state by freeing info and matrix data */
45 extern void rmx_reset(RMATRIX *rm);
46
47 /* Free an RMATRIX struct and data */
48 extern void rmx_free(RMATRIX *rm);
49
50 /* Resolve data type based on two input types (returns 0 for mismatch) */
51 extern int rmx_newtype(int dtyp1, int dtyp2);
52
53 /* Read matrix header from input stream (cannot be XML) */
54 extern int rmx_load_header(RMATRIX *rm, FILE *fp);
55
56 /* Load next row as double (cannot be XML) */
57 extern int rmx_load_row(double *drp, const RMATRIX *rm, FILE *fp);
58
59 /* Allocate & load post-header data from stream given type set in rm->dtype */
60 extern int rmx_load_data(RMATRIX *rm, FILE *fp);
61
62 /* Load matrix from supported file type (NULL for stdin, '!' with command) */
63 extern RMATRIX *rmx_load(const char *inspec, RMPref rmp);
64
65 /* Append header information associated with matrix data */
66 extern int rmx_addinfo(RMATRIX *rm, const char *info);
67
68 /* Finish writing header data with resolution and format, returning type used */
69 extern int rmx_write_header(const RMATRIX *rm, int dtype, FILE *fp);
70
71 /* Write out matrix data (usually by row) */
72 extern int rmx_write_data(const double *dp, int nc, int len,
73 int dtype, FILE *fp);
74
75 /* Write matrix using file format indicated by dtype */
76 extern int rmx_write(const RMATRIX *rm, int dtype, FILE *fp);
77
78 /* Allocate and assign square identity matrix with n components */
79 extern RMATRIX *rmx_identity(int dim, int n);
80
81 /* Duplicate the given matrix */
82 extern RMATRIX *rmx_copy(const RMATRIX *rm);
83
84 /* Allocate and assign transposed matrix */
85 extern RMATRIX *rmx_transpose(const RMATRIX *rm);
86
87 /* Multiply (concatenate) two matrices and allocate the result */
88 extern RMATRIX *rmx_multiply(const RMATRIX *m1, const RMATRIX *m2);
89
90 /* Element-wise multiplication (or division) of m2 into m1 */
91 extern int rmx_elemult(RMATRIX *m1, const RMATRIX *m2, int divide);
92
93 /* Sum second matrix into first, applying scale factor beforehand */
94 extern int rmx_sum(RMATRIX *msum, const RMATRIX *madd, const double sf[]);
95
96 /* Scale the given matrix by the indicated scalar component vector */
97 extern int rmx_scale(RMATRIX *rm, const double sf[]);
98
99 /* Allocate new matrix and apply component transformation */
100 extern RMATRIX *rmx_transform(const RMATRIX *msrc, int n, const double cmat[]);
101
102 /* Convert a color matrix to newly allocated RMATRIX buffer */
103 extern RMATRIX *rmx_from_cmatrix(const CMATRIX *cm);
104
105 /* Convert general matrix to newly allocated CMATRIX buffer */
106 extern CMATRIX *cm_from_rmatrix(const RMATRIX *rm);
107
108 #ifdef __cplusplus
109 }
110 #endif
111 #endif /* _RAD_RMATRIX_H_ */