| ARX 1.0 The next-generation open source augmented reality toolkit.

Loading...
Searching...
No Matches
matrix.h
Go to the documentation of this file.
1/*
2 * matrix.h
3 * artoolkitX
4 *
5 * This file is part of artoolkitX.
6 *
7 * artoolkitX is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * artoolkitX is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with artoolkitX. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * As a special exception, the copyright holders of this library give you
21 * permission to link this library with independent modules to produce an
22 * executable, regardless of the license terms of these independent modules, and to
23 * copy and distribute the resulting executable under terms of your choice,
24 * provided that you also meet, for each linked independent module, the terms and
25 * conditions of the license of that module. An independent module is a module
26 * which is neither derived from nor based on this library. If you modify this
27 * library, you may extend this exception to your version of the library, but you
28 * are not obligated to do so. If you do not wish to do so, delete this exception
29 * statement from your version.
30 *
31 * Copyright 2018 Realmax, Inc.
32 * Copyright 2015 Daqri, LLC.
33 * Copyright 2002-2015 ARToolworks, Inc.
34 *
35 * Author(s): Hirokazu Kato, Philip Lamb
36 *
37 */
38
39#ifndef AR_MATRIX_H
40#define AR_MATRIX_H
41
42#include <math.h>
43
44
45#ifdef __cplusplus
46 extern "C" {
47#endif
48
49#ifdef _WIN32
50# ifdef AR_STATIC
51# define ARMATRIX_EXTERN
52# else
53# ifdef ARX_EXPORTS
54# define ARMATRIX_EXTERN __declspec(dllexport)
55# else
56# define ARMATRIX_EXTERN __declspec(dllimport)
57# endif
58# endif
59#else
60# define ARMATRIX_EXTERN
61#endif
62
63/* === matrix definition ===
64
65 <---- clm --->
66 [ 10 20 30 ] ^
67 [ 20 10 15 ] |
68 [ 12 23 13 ] row
69 [ 20 10 15 ] |
70 [ 13 14 15 ] v
71
72=========================== */
73
74 typedef struct {
75 ARdouble *m;
76 int row;
77 int clm;
78} ARMat;
79
80#ifdef ARDOUBLE_IS_FLOAT
81# define ARMatf ARMat
82#else
83 typedef struct {
84 float *m;
85 int row;
86 int clm;
87} ARMatf;
88#endif
89
90 typedef struct {
91 ARdouble *v;
92 int clm;
93} ARVec;
94
95
96/* 0 origin */
97#define ARELEM0(mat,r,c) ((mat)->m[(r)*((mat)->clm)+(c)])
98/* 1 origin */
99#define ARELEM1(mat,row,clm) ARELEM0(mat,row-1,clm-1)
100
101
102
103 ARMATRIX_EXTERN ARMat *arMatrixAlloc(int row, int clm);
104 ARMATRIX_EXTERN int arMatrixFree(ARMat *m);
105#ifdef ARDOUBLE_IS_FLOAT
106# define arMatrixAllocf arMatrixAlloc
107# define arMatrixFreef arMatrixFree
108#else
109 ARMATRIX_EXTERN ARMatf *arMatrixAllocf(int row, int clm);
110 int arMatrixFreef(ARMatf *m);
111#endif
112
113 ARMATRIX_EXTERN int arMatrixDup(ARMat *dest, ARMat *source);
114 ARMATRIX_EXTERN ARMat *arMatrixAllocDup(ARMat *source);
115
116 ARMATRIX_EXTERN int arMatrixUnit(ARMat *unit);
117 ARMATRIX_EXTERN ARMat *arMatrixAllocUnit(int dim);
118
119 ARMATRIX_EXTERN int arMatrixMul(ARMat *dest, ARMat *a, ARMat *b);
120 ARMATRIX_EXTERN ARMat *arMatrixAllocMul(ARMat *a, ARMat *b);
121
122#ifdef ARDOUBLE_IS_FLOAT
123# define arMatrixMulf arMatrixMul
124# define arMatrixAllocMulf arMatrixAllocMul
125#else
126 ARMATRIX_EXTERN int arMatrixMulf(ARMatf *dest, ARMatf *a, ARMatf *b);
127 ARMATRIX_EXTERN ARMatf *arMatrixAllocMulf(ARMatf *a, ARMatf *b);
128#endif
129
130 ARMATRIX_EXTERN int arMatrixTrans(ARMat *dest, ARMat *source); // Transpose source, place result in dest.
131 ARMATRIX_EXTERN ARMat *arMatrixAllocTrans(ARMat *source); // Transpose source, place result in newly allocated matrix.
132
133#ifdef ARDOUBLE_IS_FLOAT
134# define arMatrixTransf arMatrixTrans
135# define arMatrixAllocTransf arMatrixAllocTrans
136#else
137 ARMATRIX_EXTERN int arMatrixTransf(ARMatf *dest, ARMatf *source);
138 ARMATRIX_EXTERN ARMatf *arMatrixAllocTransf(ARMatf *source);
139#endif
140
141 ARMATRIX_EXTERN int arMatrixInv(ARMat *dest, ARMat *source);
142 ARMATRIX_EXTERN int arMatrixSelfInv(ARMat *m);
143 ARMATRIX_EXTERN ARMat *arMatrixAllocInv(ARMat *source);
144
145#ifdef ARDOUBLE_IS_FLOAT
146# define arMatrixSelfInvf arMatrixSelfInv
147#else
148 ARMATRIX_EXTERN int arMatrixSelfInvf(ARMatf *m);
149#endif
150
151 ARMATRIX_EXTERN ARdouble arMatrixDet(ARMat *m);
152
153 ARMATRIX_EXTERN int arMatrixPCA( ARMat *input, ARMat *evec, ARVec *ev, ARVec *mean );
154 ARMATRIX_EXTERN int arMatrixPCA2( ARMat *input, ARMat *evec, ARVec *ev );
155
156 ARMATRIX_EXTERN int arMatrixDisp(ARMat *m);
157
158
159 ARVec *arVecAlloc( int clm );
160 int arVecFree( ARVec *v );
161 int arVecDisp( ARVec *v );
162 ARdouble arVecHousehold( ARVec *x );
163 ARdouble arVecInnerproduct( ARVec *x, ARVec *y );
164 int arVecTridiagonalize( ARMat *a, ARVec *d, ARVec *e );
165
166
167#ifdef __cplusplus
168}
169#endif
170#endif
ARdouble
double ARdouble
Definition: ar.h:99
arVecTridiagonalize
int arVecTridiagonalize(ARMat *a, ARVec *d, ARVec *e)
Definition: vTridiag.c:54
arVecFree
int arVecFree(ARVec *v)
Definition: vFree.c:59
arMatrixAllocUnit
ARMATRIX_EXTERN ARMat * arMatrixAllocUnit(int dim)
Definition: mAllocUnit.c:59
arMatrixDisp
ARMATRIX_EXTERN int arMatrixDisp(ARMat *m)
Definition: mDisp.c:54
arMatrixAllocMulf
ARMATRIX_EXTERN ARMatf * arMatrixAllocMulf(ARMatf *a, ARMatf *b)
Definition: mAllocMul.c:75
arVecDisp
int arVecDisp(ARVec *v)
Definition: vDisp.c:54
arVecHousehold
ARdouble arVecHousehold(ARVec *x)
Definition: vHouse.c:60
arMatrixDet
ARMATRIX_EXTERN ARdouble arMatrixDet(ARMat *m)
Definition: mDet.c:58
arVecAlloc
ARVec * arVecAlloc(int clm)
Definition: vAlloc.c:59
arMatrixMul
ARMATRIX_EXTERN int arMatrixMul(ARMat *dest, ARMat *a, ARMat *b)
Definition: mMul.c:54
arMatrixInv
ARMATRIX_EXTERN int arMatrixInv(ARMat *dest, ARMat *source)
Definition: mInv.c:54
arMatrixAllocInv
ARMATRIX_EXTERN ARMat * arMatrixAllocInv(ARMat *source)
Definition: mAllocInv.c:59
arMatrixTransf
ARMATRIX_EXTERN int arMatrixTransf(ARMatf *dest, ARMatf *source)
Definition: mTrans.c:86
arMatrixPCA
ARMATRIX_EXTERN int arMatrixPCA(ARMat *input, ARMat *evec, ARVec *ev, ARVec *mean)
Definition: mPCA.c:91
arMatrixUnit
ARMATRIX_EXTERN int arMatrixUnit(ARMat *unit)
Definition: mUnit.c:54
arMatrixAllocf
ARMATRIX_EXTERN ARMatf * arMatrixAllocf(int row, int clm)
Definition: mAlloc.c:80
arMatrixAlloc
ARMATRIX_EXTERN ARMat * arMatrixAlloc(int row, int clm)
Definition: mAlloc.c:59
arMatrixMulf
ARMATRIX_EXTERN int arMatrixMulf(ARMatf *dest, ARMatf *a, ARMatf *b)
Definition: mMul.c:95
arMatrixAllocTrans
ARMATRIX_EXTERN ARMat * arMatrixAllocTrans(ARMat *source)
Definition: mAllocTrans.c:59
arMatrixSelfInvf
ARMATRIX_EXTERN int arMatrixSelfInvf(ARMatf *m)
Definition: mSelfInv.c:151
arMatrixFree
ARMATRIX_EXTERN int arMatrixFree(ARMat *m)
Definition: mFree.c:59
arMatrixAllocDup
ARMATRIX_EXTERN ARMat * arMatrixAllocDup(ARMat *source)
Definition: mAllocDup.c:59
arMatrixAllocTransf
ARMATRIX_EXTERN ARMatf * arMatrixAllocTransf(ARMatf *source)
Definition: mAllocTrans.c:75
arMatrixSelfInv
ARMATRIX_EXTERN int arMatrixSelfInv(ARMat *m)
Definition: mSelfInv.c:67
arMatrixPCA2
ARMATRIX_EXTERN int arMatrixPCA2(ARMat *input, ARMat *evec, ARVec *ev)
Definition: mPCA.c:131
arMatrixDup
ARMATRIX_EXTERN int arMatrixDup(ARMat *dest, ARMat *source)
Definition: mDup.c:54
ARMATRIX_EXTERN
#define ARMATRIX_EXTERN
Definition: matrix.h:60
arVecInnerproduct
ARdouble arVecInnerproduct(ARVec *x, ARVec *y)
Definition: vInnerP.c:55
arMatrixTrans
ARMATRIX_EXTERN int arMatrixTrans(ARMat *dest, ARMat *source)
Definition: mTrans.c:54
arMatrixAllocMul
ARMATRIX_EXTERN ARMat * arMatrixAllocMul(ARMat *a, ARMat *b)
Definition: mAllocMul.c:59
arMatrixFreef
int arMatrixFreef(ARMatf *m)
Definition: mFree.c:70
ARMat
Definition: matrix.h:74
ARMat::row
int row
Definition: matrix.h:76
ARMat::clm
int clm
Definition: matrix.h:77
ARMat::m
ARdouble * m
Definition: matrix.h:75
ARMatf
Definition: matrix.h:83
ARMatf::clm
int clm
Definition: matrix.h:86
ARMatf::m
float * m
Definition: matrix.h:84
ARMatf::row
int row
Definition: matrix.h:85
ARVec
Definition: matrix.h:90
ARVec::v
ARdouble * v
Definition: matrix.h:91
ARVec::clm
int clm
Definition: matrix.h:92