1 |
/* RCSid $Id$ */ |
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, ncomp; |
18 |
double mtx[1]; /* extends struct */ |
19 |
} RMATRIX; |
20 |
|
21 |
#define rmx_indx(rm,r,c,i) (((i)*(rm)->nrows+(r))*(rm)->ncols+(c)) |
22 |
|
23 |
#define rmx_lval(rm,r,c,i) (rm)->mtx[rmx_indx(rm,r,c,i)] |
24 |
|
25 |
#define rmx_free(rm) free(rm) |
26 |
|
27 |
/* Allocate a nr x nc matrix with n components */ |
28 |
extern RMATRIX *rmx_alloc(int nr, int nc, int n); |
29 |
|
30 |
/* Load matrix from supported file type */ |
31 |
extern RMATRIX *rmx_load(const char *fname); |
32 |
|
33 |
/* Write matrix to file type indicated by dt */ |
34 |
extern long rmx_write(const RMATRIX *rm, int dtype, FILE *fp); |
35 |
|
36 |
/* Allocate and assign square identity matrix with n components */ |
37 |
extern RMATRIX *rmx_identity(int dim, int n); |
38 |
|
39 |
/* Duplicate the given matrix */ |
40 |
extern RMATRIX *rmx_copy(const RMATRIX *rm); |
41 |
|
42 |
/* Swap rows and columns in the given matrix in situ */ |
43 |
extern int rmx_transpose(RMATRIX *rm); |
44 |
|
45 |
/* Multiply (concatenate) two matrices and allocate the result */ |
46 |
extern RMATRIX *rmx_multiply(const RMATRIX *m1, const RMATRIX *m2); |
47 |
|
48 |
/* Sum second matrix into first, applying scale factor beforehand */ |
49 |
extern int rmx_sum(RMATRIX *msum, const RMATRIX *madd, const double sf[]); |
50 |
|
51 |
/* Scale the given matrix by the indicated scalar component vector */ |
52 |
extern int rmx_scale(RMATRIX *rm, const double sf[]); |
53 |
|
54 |
/* Allocate new matrix and apply component transformation */ |
55 |
extern RMATRIX *rmx_transform(const RMATRIX *msrc, int n, const double cmat[]); |
56 |
|
57 |
/* Convert a color matrix to newly allocated RMATRIX buffer */ |
58 |
extern RMATRIX *rmx_from_cmatrix(const CMATRIX *cm); |
59 |
|
60 |
/* Convert general matrix to newly allocated CMATRIX buffer */ |
61 |
extern CMATRIX *cm_from_rmatrix(const RMATRIX *rm); |
62 |
|
63 |
#ifdef __cplusplus |
64 |
} |
65 |
#endif |
66 |
#endif /* _RAD_RMATRIX_H_ */ |