1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/***************************************************
Author : Tanmay Chaudhari
**************************************************/
#include <bits/stdc++.h>
using namespace std;
extern "C"
{
#include "api_scilab.h"
#include "Scierror.h"
#include "BOOL.h"
#include <localization.h>
#include "sciprint.h"
int opencv_rotationVectorToMatrix(char *fname, unsigned long fname_len)
{
//Error management variable
SciErr sciErr;
//Variable declaration
int iComplex = 0;
int iType = 0;
int iRows = 0;
int iCols = 0;
int *piAddr = NULL;
double sinOfangle = 0;
double cosOfangle = 0;
double t, x, y, z;
double theta;
double *pdbl = NULL;
double *matrix;
double *identity;
double *A;
double *B;
//Check input output arguments
checkInputArgument(pvApiCtx, 1, 1);
checkOutputArgument(pvApiCtx, 1, 1);
//Get variable address of the first input argument
sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
//Check type
sciErr = getVarType(pvApiCtx, piAddr, &iType);
if(sciErr.iErr || iType != sci_matrix)
{
printError(&sciErr, 0);
return 0;
}
//Get complexity
iComplex = isVarComplex(pvApiCtx, piAddr);
//Check complexity
if(iComplex)
{
Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
return 0;
}
sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdbl);
if(sciErr.iErr || iCols != 3 || iRows != 1)
{
printError(&sciErr, 0);
return 0;
}
x = pdbl[0];
y = pdbl[1];
z = pdbl[2];
theta = sqrt(x * x + y * y + z * z);
sinOfangle = sin(theta);
cosOfangle = cos(theta);
t = 1 - cosOfangle;
x = pdbl[0] / theta;
y = pdbl[1] / theta;
z = pdbl[2] / theta;
matrix = (double*)malloc(sizeof(double) * 9);
A = (double*)malloc(sizeof(double) * 9);
B = (double*)malloc(sizeof(double) * 9);
identity = (double*)malloc(sizeof(double) * 9);
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
if(i == 0)
{
if(j == 0)
A[j * 3 + i] = x * x;
else if(j == 1)
A[j * 3 + i] = x * y;
else if(j == 2)
A[j * 3 + i] = x * z;
}
else if(i == 1)
{
if(j == 0)
A[j * 3 + i] = x * y;
else if(j == 1)
A[j * 3 + i] = y * y;
else if(j == 2)
A[j * 3 + i] = y * z;
}
else
{
if(j == 0)
A[j * 3 + i] = x * z;
else if(j == 1)
A[j * 3 + i] = y * z;
else if(j == 2)
A[j * 3 + i] = z * z;
}
}
}
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
if(i == 0)
{
if(j == 0)
B[j * 3 + i] = 0;
else if(j == 1)
B[j * 3 + i] = -z;
else if(j == 2)
B[j * 3 + i] = y;
}
else if(i == 1)
{
if(j == 0)
B[j * 3 + i] = z;
else if(j == 1)
B[j * 3 + i] = 0;
else if(j == 2)
B[j * 3 + i] = -x;
}
else
{
if(j == 0)
B[j * 3 + i] = -y;
else if(j == 1)
B[j * 3 + i] = x;
else if(j == 2)
B[j * 3 + i] = 0;
}
}
}
for(int i = 0; i < 3; i++)
{
for(int j = 0;j < 3; j++)
{
if(i == j)
identity[j * 3 + i] = 1;
else
identity[j * 3 + i] = 0;
}
}
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
matrix[i * 3 + j] = identity[j * 3 + i] * cosOfangle + t * A[j * 3 + i] + sinOfangle * B[j * 3 + i];
}
}
sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &piAddr);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, 3, 3, matrix);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
//Return output arguments
AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
ReturnArguments(pvApiCtx);
return 0;
}
}
|