4
4
#ifndef __FF_MATUTILS_H__
5
5
#define __FF_MATUTILS_H__
6
6
7
- #define FF_MAT_AT (mat, val, get ) \
8
- val = get(mat, info[0 ]->Int32Value (), info[1]->Int32Value());
7
+ #define FF_MAT_AT (mat, val, get ) \
8
+ if (mat.dims > 2 ) \
9
+ val = get(mat, info[0 ]->Int32Value (), info[1]->Int32Value(), info[2]->Int32Value()); \
10
+ else \
11
+ val = get(mat, info[0 ]->Int32Value (), info[1]->Int32Value());
9
12
10
- #define FF_MAT_SET (mat, val, put ) \
11
- put (mat, val, info[0 ]->Int32Value (), info[1]->Int32Value());
13
+ #define FF_MAT_SET (mat, val, put ) \
14
+ if (mat.dims > 2 ) \
15
+ put (mat, val, info[0 ]->Int32Value (), info[1]->Int32Value(), info[2]->Int32Value()); \
16
+ else \
17
+ put (mat, val, info[0 ]->Int32Value (), info[1]->Int32Value());
12
18
13
19
#define FF_MAT_FILL (mat, vec, put ) \
14
20
for (int r = 0 ; r < mat.rows; r++) { \
34
40
rowArray->Set (r, colArray); \
35
41
}
36
42
43
+ #define FF_JS_ARRAY_FROM_MAT_3D (mat, rowArray, get ) \
44
+ for (int r = 0 ; r < mat.size[0 ]; r++) { \
45
+ v8::Local<v8::Array> colArray = Nan::New<v8::Array>(mat.size [1 ]); \
46
+ for (int c = 0 ; c < mat.size [1 ]; c++) { \
47
+ v8::Local<v8::Array> depthArray = Nan::New<v8::Array>(mat.size [2 ]); \
48
+ for (int z = 0 ; z < mat.size [2 ]; z++) { \
49
+ depthArray->Set (z, get (mat, r, c, z)); \
50
+ } \
51
+ colArray->Set (c, depthArray); \
52
+ } \
53
+ rowArray->Set (r, colArray); \
54
+ }
55
+
37
56
#define FF_MAT_APPLY_TYPED_OPERATOR (mat, arg, type, ITERATOR, OPERATOR ) { \
38
57
switch (type) { \
39
58
case CV_8UC1: \
@@ -138,6 +157,11 @@ namespace FF {
138
157
mat.at <type>(r, c) = (type)value->NumberValue ();
139
158
}
140
159
160
+ template <typename type>
161
+ static inline void matPutVal (cv::Mat mat, v8::Local<v8::Value> value, int r, int c, int z) {
162
+ mat.at <type>(r, c, z) = (type)value->NumberValue ();
163
+ }
164
+
141
165
template <typename type>
142
166
static inline void matPutVec2 (cv::Mat mat, v8::Local<v8::Value> vector, int r, int c) {
143
167
v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast (vector);
@@ -147,6 +171,15 @@ namespace FF {
147
171
);
148
172
}
149
173
174
+ template <typename type>
175
+ static inline void matPutVec2 (cv::Mat mat, v8::Local<v8::Value> vector, int r, int c, int z) {
176
+ v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast (vector);
177
+ mat.at < cv::Vec<type, 2 > >(r, c, z) = cv::Vec<type, 2 >(
178
+ (type)vec->Get (0 )->NumberValue (),
179
+ (type)vec->Get (1 )->NumberValue ()
180
+ );
181
+ }
182
+
150
183
template <typename type>
151
184
static inline void matPutVec3 (cv::Mat mat, v8::Local<v8::Value> vector, int r, int c) {
152
185
v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast (vector);
@@ -157,6 +190,16 @@ namespace FF {
157
190
);
158
191
}
159
192
193
+ template <typename type>
194
+ static inline void matPutVec3 (cv::Mat mat, v8::Local<v8::Value> vector, int r, int c, int z) {
195
+ v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast (vector);
196
+ mat.at < cv::Vec<type, 3 > >(r, c, z) = cv::Vec<type, 3 >(
197
+ (type)vec->Get (0 )->NumberValue (),
198
+ (type)vec->Get (1 )->NumberValue (),
199
+ (type)vec->Get (2 )->NumberValue ()
200
+ );
201
+ }
202
+
160
203
template <typename type>
161
204
static inline void matPutVec4 (cv::Mat mat, v8::Local<v8::Value> vector, int r, int c) {
162
205
v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast (vector);
@@ -168,11 +211,27 @@ namespace FF {
168
211
);
169
212
}
170
213
214
+ template <typename type>
215
+ static inline void matPutVec4 (cv::Mat mat, v8::Local<v8::Value> vector, int r, int c, int z) {
216
+ v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast (vector);
217
+ mat.at < cv::Vec<type, 4 > >(r, c, z) = cv::Vec<type, 4 >(
218
+ (type)vec->Get (0 )->NumberValue (),
219
+ (type)vec->Get (1 )->NumberValue (),
220
+ (type)vec->Get (2 )->NumberValue (),
221
+ (type)vec->Get (3 )->NumberValue ()
222
+ );
223
+ }
224
+
171
225
template <typename type>
172
226
static inline v8::Local<v8::Value> matGetVal (cv::Mat mat, int r, int c) {
173
227
return Nan::New (mat.at <type>(r, c));
174
228
}
175
229
230
+ template <typename type>
231
+ static inline v8::Local<v8::Value> matGetVal (cv::Mat mat, int r, int c, int z) {
232
+ return Nan::New (mat.at <type>(r, c, z));
233
+ }
234
+
176
235
template <typename type>
177
236
static inline v8::Local<v8::Value> matGetVec2 (cv::Mat mat, int r, int c) {
178
237
v8::Local<v8::Array> vec = Nan::New<v8::Array>(2 );
@@ -181,6 +240,14 @@ namespace FF {
181
240
return vec;
182
241
}
183
242
243
+ template <typename type>
244
+ static inline v8::Local<v8::Value> matGetVec2 (cv::Mat mat, int r, int c, int z) {
245
+ v8::Local<v8::Array> vec = Nan::New<v8::Array>(2 );
246
+ vec->Set (0 , Nan::New (mat.at < cv::Vec<type, 2 > >(r, c, z)[0 ]));
247
+ vec->Set (1 , Nan::New (mat.at < cv::Vec<type, 2 > >(r, c, z)[1 ]));
248
+ return vec;
249
+ }
250
+
184
251
template <typename type>
185
252
static inline v8::Local<v8::Value> matGetVec3 (cv::Mat mat, int r, int c) {
186
253
v8::Local<v8::Array> vec = Nan::New<v8::Array>(3 );
@@ -190,6 +257,15 @@ namespace FF {
190
257
return vec;
191
258
}
192
259
260
+ template <typename type>
261
+ static inline v8::Local<v8::Value> matGetVec3 (cv::Mat mat, int r, int c, int z) {
262
+ v8::Local<v8::Array> vec = Nan::New<v8::Array>(3 );
263
+ vec->Set (0 , Nan::New (mat.at < cv::Vec<type, 3 > >(r, c, z)[0 ]));
264
+ vec->Set (1 , Nan::New (mat.at < cv::Vec<type, 3 > >(r, c, z)[1 ]));
265
+ vec->Set (2 , Nan::New (mat.at < cv::Vec<type, 3 > >(r, c, z)[2 ]));
266
+ return vec;
267
+ }
268
+
193
269
template <typename type>
194
270
static inline v8::Local<v8::Value> matGetVec4 (cv::Mat mat, int r, int c) {
195
271
v8::Local<v8::Array> vec = Nan::New<v8::Array>(4 );
@@ -199,6 +275,16 @@ namespace FF {
199
275
vec->Set (3 , Nan::New (mat.at < cv::Vec<type, 4 > >(r, c)[3 ]));
200
276
return vec;
201
277
}
278
+
279
+ template <typename type>
280
+ static inline v8::Local<v8::Value> matGetVec4 (cv::Mat mat, int r, int c, int z) {
281
+ v8::Local<v8::Array> vec = Nan::New<v8::Array>(4 );
282
+ vec->Set (0 , Nan::New (mat.at < cv::Vec<type, 4 > >(r, c, z)[0 ]));
283
+ vec->Set (1 , Nan::New (mat.at < cv::Vec<type, 4 > >(r, c, z)[1 ]));
284
+ vec->Set (2 , Nan::New (mat.at < cv::Vec<type, 4 > >(r, c, z)[2 ]));
285
+ vec->Set (3 , Nan::New (mat.at < cv::Vec<type, 4 > >(r, c, z)[3 ]));
286
+ return vec;
287
+ }
202
288
}
203
289
204
290
#endif
0 commit comments