ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rmatrix.h
Revision: 2.11
Committed: Tue Sep 3 23:43:07 2019 UTC (4 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.10: +5 -4 lines
Log Message:
Minor changes should not affect behavior

File Contents

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