ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/cmatrix.h
Revision: 2.5
Committed: Fri May 30 00:00:54 2014 UTC (9 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad4R2
Changes since 2.4: +12 -12 lines
Log Message:
Added NROWS, NCOLS and NCOMP to matrix headers

File Contents

# User Rev Content
1 greg 2.5 /* RCSid $Id: cmatrix.h,v 2.4 2014/02/08 01:28:06 greg Exp $ */
2 greg 2.1 /*
3     * Color matrix routine declarations.
4     *
5     * G. Ward
6     */
7    
8     #ifndef _RAD_CMATRIX_H_
9     #define _RAD_CMATRIX_H_
10    
11     #include "color.h"
12    
13     #ifdef __cplusplus
14     extern "C" {
15     #endif
16    
17     /* Data types for file loading */
18 greg 2.5 enum {DTfromHeader=0, DTascii, DTfloat, DTdouble, DTrgbe, DTxyze, DTend};
19 greg 2.4
20     extern const char *cm_fmt_id[];
21     extern const int cm_elem_size[];
22 greg 2.1
23     /* A color coefficient matrix -- vectors have ncols==1 */
24     typedef struct {
25     int nrows, ncols;
26     COLORV cmem[3]; /* extends struct */
27     } CMATRIX;
28    
29     #define COLSPEC (sizeof(COLORV)==sizeof(float) ? "%f %f %f" : "%lf %lf %lf")
30    
31     #define cm_lval(cm,r,c) ((cm)->cmem + 3*((r)*(cm)->ncols + (c)))
32    
33     #define cv_lval(cm,i) ((cm)->cmem + 3*(i))
34    
35     /* Allocate a color coefficient matrix */
36 greg 2.5 extern CMATRIX *cm_alloc(int nrows, int ncols);
37 greg 2.1
38     /* Resize color coefficient matrix */
39 greg 2.5 extern CMATRIX *cm_resize(CMATRIX *cm, int nrows);
40 greg 2.1
41     #define cm_free(cm) free(cm)
42    
43 greg 2.5 /* Load header to obtain/check data type and matrix dimensions */
44     extern char *cm_getheader(int *dt, int *nr, int *nc, FILE *fp);
45 greg 2.1
46     /* Allocate and load a matrix from the given file (or stdin if NULL) */
47 greg 2.5 extern CMATRIX *cm_load(const char *fname, int nrows, int ncols, int dtype);
48 greg 2.1
49     /* Extract a column vector from a matrix */
50 greg 2.5 extern CMATRIX *cm_column(const CMATRIX *cm, int c);
51 greg 2.1
52     /* Scale a matrix by a single value */
53 greg 2.5 extern CMATRIX *cm_scale(const CMATRIX *cm1, const COLOR sca);
54 greg 2.1
55     /* Multiply two matrices (or a matrix and a vector) and allocate the result */
56 greg 2.5 extern CMATRIX *cm_multiply(const CMATRIX *cm1, const CMATRIX *cm2);
57 greg 2.1
58 greg 2.4 /* write out matrix to file (precede by resolution string if picture) */
59 greg 2.5 extern int cm_write(const CMATRIX *cm, int dtype, FILE *fp);
60 greg 2.1
61 greg 2.3 /* Load and convert a matrix BTDF from the given XML file */
62 greg 2.5 extern CMATRIX *cm_loadBTDF(char *fname);
63 greg 2.1
64     #ifdef __cplusplus
65     }
66     #endif
67     #endif /* _RAD_CMATRIX_H_ */