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