ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rmatrix.h
(Generate patch)

Comparing ray/src/util/rmatrix.h (file contents):
Revision 2.5 by greg, Wed Aug 27 13:33:47 2014 UTC vs.
Revision 2.21 by greg, Sun May 19 15:32:24 2024 UTC

# Line 12 | Line 12
12   extern "C" {
13   #endif
14  
15 < /* General plane-ordered component matrix */
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 > /* General [row][col][cmp] component matrix */
25   typedef struct {
17        int     nrows, ncols, ncomp;
18        int     dtype;
26          char    *info;
27 <        double  mtx[1];                 /* extends struct */
27 >        void    *mapped;
28 >        double  *mtx;
29 >        COLOR   cexp;
30 >        float   wlpart[4];
31 >        int     nrows, ncols;
32 >        short   ncomp;
33 >        uby8    dtype;
34 >        uby8    pflags;
35   } RMATRIX;
36  
37 < #define rmx_lval(rm,r,c,i)      (rm)->mtx[(i)+(rm)->ncomp*((c)+(rm)->ncols*(r))]
37 > #define rmx_lval(rm,r,c)        ((rm)->mtx + (rm)->ncomp*((c)+(size_t)(rm)->ncols*(r)))
38 > #define rmx_val                 rmx_lval
39  
40 < /* Allocate a nr x nc matrix with n components */
40 > #define rmx_array_size(rm)      (sizeof(double)*(rm)->nrows*(rm)->ncols*(rm)->ncomp)
41 > #define rmx_mapped_size(rm)     ((char *)(rm)->mtx + rmx_array_size(rm) - (char *)(rm)->mapped)
42 >
43 > /* Initialize a RMATRIX struct but don't allocate array space */
44 > extern RMATRIX  *rmx_new(int nr, int nc, int n);
45 >
46 > /* Prepare a RMATRIX for writing (allocate array if needed) */
47 > extern int      rmx_prepare(RMATRIX *rm);
48 >
49 > /* Call rmx_new() and rmx_prepare() */
50   extern RMATRIX  *rmx_alloc(int nr, int nc, int n);
51  
52 < /* Free a RMATRIX array */
52 > /* Clear state by freeing info and matrix data */
53 > extern void     rmx_reset(RMATRIX *rm);
54 >
55 > /* Free an RMATRIX struct and data */
56   extern void     rmx_free(RMATRIX *rm);
57  
58   /* Resolve data type based on two input types (returns 0 for mismatch) */
59   extern int      rmx_newtype(int dtyp1, int dtyp2);
60  
61 < /* Load matrix from supported file type */
62 < extern RMATRIX  *rmx_load(const char *fname);
61 > /* Read matrix header from input stream (cannot be XML) */
62 > extern int      rmx_load_header(RMATRIX *rm, FILE *fp);
63  
64 + /* Load next row as double (cannot be XML) */
65 + extern int      rmx_load_row(double *drp, const RMATRIX *rm, FILE *fp);
66 +
67 + /* Allocate & load post-header data from stream given type set in rm->dtype */
68 + extern int      rmx_load_data(RMATRIX *rm, FILE *fp);
69 +
70 + /* Load matrix from supported file type (NULL for stdin, '!' with command) */
71 + extern RMATRIX  *rmx_load(const char *inspec, RMPref rmp);
72 +
73   /* Append header information associated with matrix data */
74   extern int      rmx_addinfo(RMATRIX *rm, const char *info);
75  
76 < /* Write matrix to file type indicated by dtype */
77 < extern long     rmx_write(const RMATRIX *rm, int dtype, FILE *fp);
76 > /* Finish writing header data with resolution and format, returning type used */
77 > extern int      rmx_write_header(const RMATRIX *rm, int dtype, FILE *fp);
78  
79 + /* Write out matrix data (usually by row) */
80 + extern int      rmx_write_data(const double *dp, int nc, int len,
81 +                                int dtype, FILE *fp);
82 +
83 + /* Write matrix using file format indicated by dtype */
84 + extern int      rmx_write(const RMATRIX *rm, int dtype, FILE *fp);
85 +
86   /* Allocate and assign square identity matrix with n components */
87   extern RMATRIX  *rmx_identity(int dim, int n);
88  
89   /* Duplicate the given matrix */
90   extern RMATRIX  *rmx_copy(const RMATRIX *rm);
91  
92 + /* Replace data in first matrix with data from second */
93 + extern int      rmx_transfer_data(RMATRIX *rdst, RMATRIX *rsrc, int dometa);
94 +
95   /* Allocate and assign transposed matrix */
96   extern RMATRIX  *rmx_transpose(const RMATRIX *rm);
97  
98   /* Multiply (concatenate) two matrices and allocate the result */
99   extern RMATRIX  *rmx_multiply(const RMATRIX *m1, const RMATRIX *m2);
100 +
101 + /* Element-wise multiplication (or division) of m2 into m1 */
102 + extern int      rmx_elemult(RMATRIX *m1, const RMATRIX *m2, int divide);
103  
104   /* Sum second matrix into first, applying scale factor beforehand */
105   extern int      rmx_sum(RMATRIX *msum, const RMATRIX *madd, const double sf[]);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines