ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rmatrix.h
Revision: 2.18
Committed: Tue Nov 28 21:07:20 2023 UTC (4 months, 4 weeks ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.17: +4 -1 lines
Log Message:
refactor: Added ability to read matrix data a row at a time

File Contents

# User Rev Content
1 greg 2.18 /* RCSid $Id: rmatrix.h,v 2.17 2023/11/28 00:39:56 greg Exp $ */
2 greg 2.1 /*
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 greg 2.13 /* Preferred BSDF component:
16     transmission, reflection front (normal side), reflection back */
17     typedef enum {RMPtrans=0, RMPreflF, RMPreflB} RMPref;
18    
19 greg 2.14 /* General [row][col][cmp] component matrix */
20 greg 2.1 typedef struct {
21 greg 2.14 char *info;
22     void *mapped;
23     double *mtx;
24     COLOR cexp;
25 greg 2.16 float wlpart[4];
26 greg 2.11 int nrows, ncols;
27     short ncomp;
28     uby8 dtype;
29     uby8 swapin;
30 greg 2.1 } RMATRIX;
31    
32 greg 2.15 #define rmx_lval(rm,r,c) ((rm)->mtx + (rm)->ncomp*((c)+(size_t)(rm)->ncols*(r)))
33 greg 2.17 #define rmx_val rmx_lval
34 greg 2.1
35 greg 2.14 /* 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 greg 2.1 extern RMATRIX *rmx_alloc(int nr, int nc, int n);
43    
44 greg 2.4 /* 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 greg 2.17 /* Read matrix header from input stream (cannot be XML) */
51     extern int rmx_load_header(RMATRIX *rm, FILE *fp);
52    
53 greg 2.18 /* Load next row as double (cannot be XML) */
54     extern int rmx_load_row(double *drp, const RMATRIX *rm, FILE *fp);
55    
56 greg 2.17 /* 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 greg 2.7 /* Load matrix from supported file type (NULL for stdin, '!' with command) */
60 greg 2.13 extern RMATRIX *rmx_load(const char *inspec, RMPref rmp);
61 greg 2.1
62 greg 2.3 /* Append header information associated with matrix data */
63     extern int rmx_addinfo(RMATRIX *rm, const char *info);
64    
65 greg 2.4 /* Write matrix to file type indicated by dtype */
66 greg 2.6 extern int rmx_write(const RMATRIX *rm, int dtype, FILE *fp);
67 greg 2.1
68     /* Allocate and assign square identity matrix with n components */
69     extern RMATRIX *rmx_identity(int dim, int n);
70    
71     /* Duplicate the given matrix */
72     extern RMATRIX *rmx_copy(const RMATRIX *rm);
73    
74 greg 2.2 /* Allocate and assign transposed matrix */
75     extern RMATRIX *rmx_transpose(const RMATRIX *rm);
76 greg 2.1
77     /* Multiply (concatenate) two matrices and allocate the result */
78     extern RMATRIX *rmx_multiply(const RMATRIX *m1, const RMATRIX *m2);
79    
80 greg 2.8 /* Element-wise multiplication (or division) of m2 into m1 */
81     extern int rmx_elemult(RMATRIX *m1, const RMATRIX *m2, int divide);
82    
83 greg 2.1 /* Sum second matrix into first, applying scale factor beforehand */
84     extern int rmx_sum(RMATRIX *msum, const RMATRIX *madd, const double sf[]);
85    
86     /* Scale the given matrix by the indicated scalar component vector */
87     extern int rmx_scale(RMATRIX *rm, const double sf[]);
88    
89     /* Allocate new matrix and apply component transformation */
90     extern RMATRIX *rmx_transform(const RMATRIX *msrc, int n, const double cmat[]);
91    
92     /* Convert a color matrix to newly allocated RMATRIX buffer */
93     extern RMATRIX *rmx_from_cmatrix(const CMATRIX *cm);
94    
95     /* Convert general matrix to newly allocated CMATRIX buffer */
96     extern CMATRIX *cm_from_rmatrix(const RMATRIX *rm);
97    
98     #ifdef __cplusplus
99     }
100     #endif
101     #endif /* _RAD_RMATRIX_H_ */