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
46extern "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
74typedef struct {
76 int row;
77 int clm;
78} ARMat;
79
80#ifdef ARDOUBLE_IS_FLOAT
81# define ARMatf ARMat
82#else
83typedef struct {
84 float *m;
85 int row;
86 int clm;
87} ARMatf;
88#endif
89
90typedef struct {
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
103ARMATRIX_EXTERN ARMat *arMatrixAlloc(int row, int clm);
105#ifdef ARDOUBLE_IS_FLOAT
106# define arMatrixAllocf arMatrixAlloc
107# define arMatrixFreef arMatrixFree
108#else
109ARMATRIX_EXTERN ARMatf *arMatrixAllocf(int row, int clm);
110int arMatrixFreef(ARMatf *m);
111#endif
112
113ARMATRIX_EXTERN int arMatrixDup(ARMat *dest, ARMat *source);
115
118
119ARMATRIX_EXTERN int arMatrixMul(ARMat *dest, ARMat *a, ARMat *b);
121
122#ifdef ARDOUBLE_IS_FLOAT
123# define arMatrixMulf arMatrixMul
124# define arMatrixAllocMulf arMatrixAllocMul
125#else
128#endif
129
130ARMATRIX_EXTERN int arMatrixTrans(ARMat *dest, ARMat *source); // Transpose source, place result in dest.
131ARMATRIX_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
137ARMATRIX_EXTERN int arMatrixTransf(ARMatf *dest, ARMatf *source);
139#endif
140
141ARMATRIX_EXTERN int arMatrixInv(ARMat *dest, ARMat *source);
144
145#ifdef ARDOUBLE_IS_FLOAT
146# define arMatrixSelfInvf arMatrixSelfInv
147#else
149#endif
150
152
153ARMATRIX_EXTERN int arMatrixPCA( ARMat *input, ARMat *evec, ARVec *ev, ARVec *mean );
154ARMATRIX_EXTERN int arMatrixPCA2( ARMat *input, ARMat *evec, ARVec *ev );
155
157
158
159ARVec *arVecAlloc( int clm );
160int arVecFree( ARVec *v );
161int arVecDisp( ARVec *v );
164int arVecTridiagonalize( ARMat *a, ARVec *d, ARVec *e );
165
166
167#ifdef __cplusplus
168}
169#endif
170#endif
double ARdouble
Definition: ar.h:99
int arVecTridiagonalize(ARMat *a, ARVec *d, ARVec *e)
Definition: vTridiag.c:54
int arVecFree(ARVec *v)
Definition: vFree.c:59
ARMATRIX_EXTERN ARMat * arMatrixAllocUnit(int dim)
Definition: mAllocUnit.c:59
ARMATRIX_EXTERN int arMatrixDisp(ARMat *m)
Definition: mDisp.c:54
ARMATRIX_EXTERN ARMatf * arMatrixAllocMulf(ARMatf *a, ARMatf *b)
Definition: mAllocMul.c:75
int arVecDisp(ARVec *v)
Definition: vDisp.c:54
ARdouble arVecHousehold(ARVec *x)
Definition: vHouse.c:60
ARMATRIX_EXTERN ARdouble arMatrixDet(ARMat *m)
Definition: mDet.c:58
ARVec * arVecAlloc(int clm)
Definition: vAlloc.c:59
ARMATRIX_EXTERN int arMatrixMul(ARMat *dest, ARMat *a, ARMat *b)
Definition: mMul.c:54
ARMATRIX_EXTERN int arMatrixInv(ARMat *dest, ARMat *source)
Definition: mInv.c:54
ARMATRIX_EXTERN ARMat * arMatrixAllocInv(ARMat *source)
Definition: mAllocInv.c:59
ARMATRIX_EXTERN int arMatrixTransf(ARMatf *dest, ARMatf *source)
Definition: mTrans.c:86
ARMATRIX_EXTERN int arMatrixPCA(ARMat *input, ARMat *evec, ARVec *ev, ARVec *mean)
Definition: mPCA.c:91
ARMATRIX_EXTERN int arMatrixUnit(ARMat *unit)
Definition: mUnit.c:54
ARMATRIX_EXTERN ARMatf * arMatrixAllocf(int row, int clm)
Definition: mAlloc.c:80
ARMATRIX_EXTERN ARMat * arMatrixAlloc(int row, int clm)
Definition: mAlloc.c:59
ARMATRIX_EXTERN int arMatrixMulf(ARMatf *dest, ARMatf *a, ARMatf *b)
Definition: mMul.c:95
ARMATRIX_EXTERN ARMat * arMatrixAllocTrans(ARMat *source)
Definition: mAllocTrans.c:59
ARMATRIX_EXTERN int arMatrixSelfInvf(ARMatf *m)
Definition: mSelfInv.c:151
ARMATRIX_EXTERN int arMatrixFree(ARMat *m)
Definition: mFree.c:59
ARMATRIX_EXTERN ARMat * arMatrixAllocDup(ARMat *source)
Definition: mAllocDup.c:59
ARMATRIX_EXTERN ARMatf * arMatrixAllocTransf(ARMatf *source)
Definition: mAllocTrans.c:75
ARMATRIX_EXTERN int arMatrixSelfInv(ARMat *m)
Definition: mSelfInv.c:67
ARMATRIX_EXTERN int arMatrixPCA2(ARMat *input, ARMat *evec, ARVec *ev)
Definition: mPCA.c:131
ARMATRIX_EXTERN int arMatrixDup(ARMat *dest, ARMat *source)
Definition: mDup.c:54
#define ARMATRIX_EXTERN
Definition: matrix.h:60
ARdouble arVecInnerproduct(ARVec *x, ARVec *y)
Definition: vInnerP.c:55
ARMATRIX_EXTERN int arMatrixTrans(ARMat *dest, ARMat *source)
Definition: mTrans.c:54
ARMATRIX_EXTERN ARMat * arMatrixAllocMul(ARMat *a, ARMat *b)
Definition: mAllocMul.c:59
int arMatrixFreef(ARMatf *m)
Definition: mFree.c:70
Definition: matrix.h:74
int row
Definition: matrix.h:76
int clm
Definition: matrix.h:77
ARdouble * m
Definition: matrix.h:75
Definition: matrix.h:83
int clm
Definition: matrix.h:86
float * m
Definition: matrix.h:84
int row
Definition: matrix.h:85
Definition: matrix.h:90
ARdouble * v
Definition: matrix.h:91
int clm
Definition: matrix.h:92