ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rmatrix.h
Revision: 2.16
Committed: Tue Nov 21 01:30:20 2023 UTC (5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.15: +2 -1 lines
Log Message:
feat(rmtxop): Added handling of Radiance spectral pictures as matrices

File Contents

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