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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines