ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rmatrix.h
Revision: 2.22
Committed: Tue Jun 4 21:23:11 2024 UTC (8 hours, 15 minutes ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 2.21: +3 -1 lines
Log Message:
fix(rcomb): Added child process to sequence output; seems to finally work

File Contents

# Content
1 /* RCSid $Id: rmatrix.h,v 2.21 2024/05/19 15:32:24 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 /* Private flags:
20 need to swap input, need to free/unmap memory */
21 #define RMF_SWAPIN 1
22 #define RMF_OURMEM 2
23
24 #define DTrmx_native DTdouble /* in-core data type */
25
26 /* General [row][col][cmp] component matrix */
27 typedef struct {
28 char *info;
29 void *mapped;
30 double *mtx;
31 COLOR cexp;
32 float wlpart[4];
33 int nrows, ncols;
34 short ncomp;
35 uby8 dtype;
36 uby8 pflags;
37 } RMATRIX;
38
39 #define rmx_lval(rm,r,c) ((rm)->mtx + (rm)->ncomp*((c)+(size_t)(rm)->ncols*(r)))
40 #define rmx_val rmx_lval
41
42 #define rmx_array_size(rm) (sizeof(double)*(rm)->nrows*(rm)->ncols*(rm)->ncomp)
43 #define rmx_mapped_size(rm) ((char *)(rm)->mtx + rmx_array_size(rm) - (char *)(rm)->mapped)
44
45 /* Initialize a RMATRIX struct but don't allocate array space */
46 extern RMATRIX *rmx_new(int nr, int nc, int n);
47
48 /* Prepare a RMATRIX for writing (allocate array if needed) */
49 extern int rmx_prepare(RMATRIX *rm);
50
51 /* Call rmx_new() and rmx_prepare() */
52 extern RMATRIX *rmx_alloc(int nr, int nc, int n);
53
54 /* Clear state by freeing info and matrix data */
55 extern void rmx_reset(RMATRIX *rm);
56
57 /* Free an RMATRIX struct and data */
58 extern void rmx_free(RMATRIX *rm);
59
60 /* Resolve data type based on two input types (returns 0 for mismatch) */
61 extern int rmx_newtype(int dtyp1, int dtyp2);
62
63 /* Read matrix header from input stream (cannot be XML) */
64 extern int rmx_load_header(RMATRIX *rm, FILE *fp);
65
66 /* Load next row as double (cannot be XML) */
67 extern int rmx_load_row(double *drp, const RMATRIX *rm, FILE *fp);
68
69 /* Allocate & load post-header data from stream given type set in rm->dtype */
70 extern int rmx_load_data(RMATRIX *rm, FILE *fp);
71
72 /* Load matrix from supported file type (NULL for stdin, '!' with command) */
73 extern RMATRIX *rmx_load(const char *inspec, RMPref rmp);
74
75 /* Append header information associated with matrix data */
76 extern int rmx_addinfo(RMATRIX *rm, const char *info);
77
78 /* Finish writing header data with resolution and format, returning type used */
79 extern int rmx_write_header(const RMATRIX *rm, int dtype, FILE *fp);
80
81 /* Write out matrix data (usually by row) */
82 extern int rmx_write_data(const double *dp, int nc, int len,
83 int dtype, FILE *fp);
84
85 /* Write matrix using file format indicated by dtype */
86 extern int rmx_write(const RMATRIX *rm, int dtype, FILE *fp);
87
88 /* Allocate and assign square identity matrix with n components */
89 extern RMATRIX *rmx_identity(int dim, int n);
90
91 /* Duplicate the given matrix */
92 extern RMATRIX *rmx_copy(const RMATRIX *rm);
93
94 /* Replace data in first matrix with data from second */
95 extern int rmx_transfer_data(RMATRIX *rdst, RMATRIX *rsrc, int dometa);
96
97 /* Allocate and assign transposed matrix */
98 extern RMATRIX *rmx_transpose(const RMATRIX *rm);
99
100 /* Multiply (concatenate) two matrices and allocate the result */
101 extern RMATRIX *rmx_multiply(const RMATRIX *m1, const RMATRIX *m2);
102
103 /* Element-wise multiplication (or division) of m2 into m1 */
104 extern int rmx_elemult(RMATRIX *m1, const RMATRIX *m2, int divide);
105
106 /* Sum second matrix into first, applying scale factor beforehand */
107 extern int rmx_sum(RMATRIX *msum, const RMATRIX *madd, const double sf[]);
108
109 /* Scale the given matrix by the indicated scalar component vector */
110 extern int rmx_scale(RMATRIX *rm, const double sf[]);
111
112 /* Allocate new matrix and apply component transformation */
113 extern RMATRIX *rmx_transform(const RMATRIX *msrc, int n, const double cmat[]);
114
115 /* Convert a color matrix to newly allocated RMATRIX buffer */
116 extern RMATRIX *rmx_from_cmatrix(const CMATRIX *cm);
117
118 /* Convert general matrix to newly allocated CMATRIX buffer */
119 extern CMATRIX *cm_from_rmatrix(const RMATRIX *rm);
120
121 #ifdef __cplusplus
122 }
123 #endif
124 #endif /* _RAD_RMATRIX_H_ */