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
|
/***************************************************
Author : Tanmay Chaudhari
**************************************************/
#include <numeric>
#include <iostream>
using namespace std;
extern "C"
{
#include "api_scilab.h"
#include "Scierror.h"
#include "BOOL.h"
#include <localization.h>
#include "sciprint.h"
int opencv_genCheckerboardPoints(char *fname, unsigned long fname_len)
{
//Error management variable
SciErr sciErr;
//Variable declaration
int iType = 0;
int iComplex = 0;
int rowsOfBoardSize = 0;
int rowsOfSquareSize = 0;
int colsOfBoardSize = 0;
int colsOfSquareSize = 0;
int iterator1 = 0;
int iterator2 = 0;
int *piAddr = NULL;
double *boardSize = NULL;
double *squareSize = NULL;
double *worldPoints = NULL;
//Check input output arguments
checkInputArgument(pvApiCtx, 2, 2);
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, &rowsOfBoardSize, &colsOfBoardSize, &boardSize);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
if(((rowsOfBoardSize != 1) || (colsOfBoardSize != 2)) || (boardSize[0] <= 0) || (boardSize[1] <= 0))
{
printError(&sciErr, 0);
return 0;
}
//Get variable address of the second input argument
sciErr = getVarAddressFromPosition(pvApiCtx, 2, &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, &rowsOfSquareSize, &colsOfSquareSize, &squareSize);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
if(((rowsOfSquareSize != 1) || (colsOfSquareSize != 1)) || (squareSize[0] <= 0))
{
printError(&sciErr, 0);
return 0;
}
boardSize[0] -= 1;
boardSize[1] -= 1;
worldPoints = (double*)malloc(sizeof(double) * 2 * (int(boardSize[0])) * (int(boardSize[1])));
iterator1 = 0;
iterator2 = (int(boardSize[0])) * (int(boardSize[1]));
for(int j = 0; j <= int(boardSize[1]) - 1; j++)
{
for(int i = 0; i <= int(boardSize[0]) - 1; i++)
{
worldPoints[iterator1] = j * squareSize[0];
worldPoints[iterator2] = i * squareSize[0];
iterator1++;
iterator2++;
}
}
sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &piAddr);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, (int(boardSize[0])) * (int(boardSize[1])), 2, worldPoints);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
//Return Output Argument
AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
ReturnArguments(pvApiCtx);
return 0;
}
}
|