ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rmatrix.h
Revision: 2.10
Committed: Wed Aug 14 18:20:02 2019 UTC (4 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.9: +3 -2 lines
Log Message:
Added explicit byte-swap checks in headers using BigEndian= line

File Contents

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