bantic-ruby-opencv 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/License.txt +30 -0
- data/README.rdoc +90 -0
- data/Rakefile +15 -0
- data/examples/convexhull.rb +47 -0
- data/examples/face_detect.rb +24 -0
- data/examples/houghcircle.rb +23 -0
- data/examples/inpaint.png +0 -0
- data/examples/inpaint.rb +42 -0
- data/examples/paint.rb +71 -0
- data/examples/snake.rb +42 -0
- data/examples/stuff.jpg +0 -0
- data/ext/curve.cpp +103 -0
- data/ext/curve.h +34 -0
- data/ext/cvavgcomp.cpp +67 -0
- data/ext/cvavgcomp.h +39 -0
- data/ext/cvbox2d.cpp +114 -0
- data/ext/cvbox2d.h +53 -0
- data/ext/cvcapture.cpp +276 -0
- data/ext/cvcapture.h +54 -0
- data/ext/cvchain.cpp +184 -0
- data/ext/cvchain.h +43 -0
- data/ext/cvchaincode.cpp +49 -0
- data/ext/cvchaincode.h +43 -0
- data/ext/cvcircle32f.cpp +90 -0
- data/ext/cvcircle32f.h +53 -0
- data/ext/cvcondensation.cpp +230 -0
- data/ext/cvcondensation.h +49 -0
- data/ext/cvconnectedcomp.cpp +115 -0
- data/ext/cvconnectedcomp.h +46 -0
- data/ext/cvcontour.cpp +217 -0
- data/ext/cvcontour.h +47 -0
- data/ext/cvcontourtree.cpp +86 -0
- data/ext/cvcontourtree.h +41 -0
- data/ext/cvconvexitydefect.cpp +103 -0
- data/ext/cvconvexitydefect.h +42 -0
- data/ext/cverror.cpp +140 -0
- data/ext/cverror.h +79 -0
- data/ext/cvfont.cpp +173 -0
- data/ext/cvfont.h +56 -0
- data/ext/cvhaarclassifiercascade.cpp +159 -0
- data/ext/cvhaarclassifiercascade.h +41 -0
- data/ext/cvhistogram.cpp +200 -0
- data/ext/cvhistogram.h +51 -0
- data/ext/cvindex.cpp +73 -0
- data/ext/cvindex.h +40 -0
- data/ext/cvline.cpp +106 -0
- data/ext/cvline.h +52 -0
- data/ext/cvmat.cpp +4809 -0
- data/ext/cvmat.h +286 -0
- data/ext/cvmatnd.cpp +44 -0
- data/ext/cvmatnd.h +28 -0
- data/ext/cvmemstorage.cpp +64 -0
- data/ext/cvmemstorage.h +53 -0
- data/ext/cvmoments.cpp +204 -0
- data/ext/cvmoments.h +48 -0
- data/ext/cvpoint.cpp +229 -0
- data/ext/cvpoint.h +59 -0
- data/ext/cvpoint2d32f.cpp +213 -0
- data/ext/cvpoint2d32f.h +61 -0
- data/ext/cvpoint3d32f.cpp +245 -0
- data/ext/cvpoint3d32f.h +64 -0
- data/ext/cvrect.cpp +340 -0
- data/ext/cvrect.h +79 -0
- data/ext/cvscalar.cpp +227 -0
- data/ext/cvscalar.h +63 -0
- data/ext/cvseq.cpp +583 -0
- data/ext/cvseq.h +71 -0
- data/ext/cvset.cpp +63 -0
- data/ext/cvset.h +39 -0
- data/ext/cvsize.cpp +223 -0
- data/ext/cvsize.h +63 -0
- data/ext/cvsize2d32f.cpp +180 -0
- data/ext/cvsize2d32f.h +59 -0
- data/ext/cvslice.cpp +82 -0
- data/ext/cvslice.h +53 -0
- data/ext/cvsparsemat.cpp +44 -0
- data/ext/cvsparsemat.h +28 -0
- data/ext/cvtermcriteria.cpp +183 -0
- data/ext/cvtermcriteria.h +71 -0
- data/ext/cvtwopoints.cpp +98 -0
- data/ext/cvtwopoints.h +50 -0
- data/ext/cvvector.cpp +206 -0
- data/ext/cvvector.h +54 -0
- data/ext/cvvideowriter.cpp +116 -0
- data/ext/cvvideowriter.h +41 -0
- data/ext/extconf.rb +58 -0
- data/ext/gui.cpp +65 -0
- data/ext/gui.h +33 -0
- data/ext/iplconvkernel.cpp +177 -0
- data/ext/iplconvkernel.h +52 -0
- data/ext/iplimage.cpp +238 -0
- data/ext/iplimage.h +54 -0
- data/ext/mouseevent.cpp +184 -0
- data/ext/mouseevent.h +59 -0
- data/ext/opencv.cpp +481 -0
- data/ext/opencv.h +356 -0
- data/ext/point3dset.cpp +41 -0
- data/ext/point3dset.h +31 -0
- data/ext/pointset.cpp +238 -0
- data/ext/pointset.h +69 -0
- data/ext/trackbar.cpp +122 -0
- data/ext/trackbar.h +65 -0
- data/ext/window.cpp +368 -0
- data/ext/window.h +56 -0
- data/images/CvMat_sobel.png +0 -0
- data/images/CvMat_sub_rect.png +0 -0
- data/images/CvSeq_relationmap.png +0 -0
- data/images/face_detect_from_lena.jpg +0 -0
- data/lib/opencv.rb +3 -0
- data/lib/version.rb +3 -0
- data/metadata +191 -0
- data/ruby-opencv.gemspec +33 -0
- data/setup/setup.cygwin.rb +120 -0
- data/setup/setup.mingw.rb +99 -0
- data/setup/setup.mswin32.rb +103 -0
- data/test/test_opencv.rb +6 -0
- metadata +272 -0
data/ext/cvpoint.h
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvpoint.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVPOINT_H
|
11
|
+
#define RUBY_OPENCV_CVPOINT_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_CVPOINT namespace cCvPoint{
|
16
|
+
#define __NAMESPACE_END_CVPOINT }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVPOINT
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
|
23
|
+
void define_ruby_class();
|
24
|
+
|
25
|
+
VALUE rb_compatible_q(VALUE klass, VALUE object);
|
26
|
+
|
27
|
+
VALUE rb_allocate(VALUE klass);
|
28
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
29
|
+
VALUE rb_x(VALUE self);
|
30
|
+
VALUE rb_set_x(VALUE self, VALUE x);
|
31
|
+
VALUE rb_y(VALUE self);
|
32
|
+
VALUE rb_set_y(VALUE self, VALUE y);
|
33
|
+
|
34
|
+
VALUE rb_to_s(VALUE self);
|
35
|
+
VALUE rb_to_ary(VALUE self);
|
36
|
+
|
37
|
+
VALUE new_object();
|
38
|
+
VALUE new_object(CvPoint point);
|
39
|
+
|
40
|
+
__NAMESPACE_END_CVPOINT
|
41
|
+
|
42
|
+
inline CvPoint *CVPOINT(VALUE object){
|
43
|
+
CvPoint *ptr;
|
44
|
+
Data_Get_Struct(object, CvPoint, ptr);
|
45
|
+
return ptr;
|
46
|
+
}
|
47
|
+
|
48
|
+
inline CvPoint VALUE_TO_CVPOINT(VALUE object){
|
49
|
+
if(cCvPoint::rb_compatible_q(cCvPoint::rb_class(), object)){
|
50
|
+
return cvPoint(NUM2INT(rb_funcall(object, rb_intern("x"), 0)),
|
51
|
+
NUM2INT(rb_funcall(object, rb_intern("y"), 0)));
|
52
|
+
}else{
|
53
|
+
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvPoint::rb_class()));
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
__NAMESPACE_END_OPENCV
|
58
|
+
|
59
|
+
#endif // RUBY_OPENCV_CVPOINT_H
|
@@ -0,0 +1,213 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvpoint2d32f.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include"cvpoint2d32f.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvPoint2D32f
|
13
|
+
*
|
14
|
+
* This class means one point on X axis Y axis.
|
15
|
+
* X and Y takes the value of the Float. see also CvPoint
|
16
|
+
*
|
17
|
+
* C structure is here, very simple.
|
18
|
+
* typdef struct CvPoint2D32f{
|
19
|
+
* float x;
|
20
|
+
* float y;
|
21
|
+
* }
|
22
|
+
*/
|
23
|
+
__NAMESPACE_BEGIN_OPENCV
|
24
|
+
__NAMESPACE_BEGIN_CVPOINT2D32F
|
25
|
+
|
26
|
+
VALUE rb_klass;
|
27
|
+
|
28
|
+
VALUE
|
29
|
+
rb_class()
|
30
|
+
{
|
31
|
+
return rb_klass;
|
32
|
+
}
|
33
|
+
|
34
|
+
void
|
35
|
+
define_ruby_class()
|
36
|
+
{
|
37
|
+
if(rb_klass)
|
38
|
+
return;
|
39
|
+
/*
|
40
|
+
* opencv = rb_define_module("OpenCV");
|
41
|
+
*
|
42
|
+
* note: this comment is used by rdoc.
|
43
|
+
*/
|
44
|
+
VALUE opencv = rb_module_opencv();
|
45
|
+
|
46
|
+
rb_klass = rb_define_class_under(opencv, "CvPoint2D32f", rb_cObject);
|
47
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
48
|
+
rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
|
49
|
+
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
50
|
+
rb_define_method(rb_klass, "x", RUBY_METHOD_FUNC(rb_x), 0);
|
51
|
+
rb_define_method(rb_klass, "x=", RUBY_METHOD_FUNC(rb_set_x), 1);
|
52
|
+
rb_define_method(rb_klass, "y", RUBY_METHOD_FUNC(rb_y), 0);
|
53
|
+
rb_define_method(rb_klass, "y=", RUBY_METHOD_FUNC(rb_set_y), 1);
|
54
|
+
|
55
|
+
rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
|
56
|
+
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
57
|
+
}
|
58
|
+
|
59
|
+
/*
|
60
|
+
* call-seq:
|
61
|
+
* combatible?(obj)
|
62
|
+
*
|
63
|
+
* Return compatibility to CvPoint2D32f. Return true if object have method #x and #y.
|
64
|
+
*
|
65
|
+
* For example.
|
66
|
+
* class MyPoint2D32f
|
67
|
+
* def x
|
68
|
+
* 95.7
|
69
|
+
* end
|
70
|
+
* def y
|
71
|
+
* 70.2
|
72
|
+
* end
|
73
|
+
* end
|
74
|
+
* mp = MyPoint2D32f.new
|
75
|
+
* CvPoint2D32f.compatible?(mp) #=> true
|
76
|
+
* CvPoint2D32f.new(mp) #=> same as CvPoint2D32f(95.7, 70.2)
|
77
|
+
*/
|
78
|
+
VALUE
|
79
|
+
rb_compatible_q(VALUE klass, VALUE object)
|
80
|
+
{
|
81
|
+
return (rb_respond_to(object, rb_intern("x")) && rb_respond_to(object, rb_intern("y"))) ? Qtrue : Qfalse;
|
82
|
+
}
|
83
|
+
|
84
|
+
VALUE
|
85
|
+
rb_allocate(VALUE klass)
|
86
|
+
{
|
87
|
+
CvPoint2D32f *ptr;
|
88
|
+
return Data_Make_Struct(klass, CvPoint2D32f, 0, -1, ptr);
|
89
|
+
}
|
90
|
+
|
91
|
+
/*
|
92
|
+
* call-seq:
|
93
|
+
* new
|
94
|
+
* new(obj)
|
95
|
+
* new(x, y)
|
96
|
+
*
|
97
|
+
* Create new 2D-coordinate, (x, y).
|
98
|
+
*
|
99
|
+
* new() is same as new(0.0, 0.0)
|
100
|
+
*
|
101
|
+
* new(obj) is same as new(obj.x.to_f, obj.y.to_f)
|
102
|
+
*/
|
103
|
+
VALUE
|
104
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
105
|
+
{
|
106
|
+
VALUE obj, x, y;
|
107
|
+
switch (argc) {
|
108
|
+
case 0:
|
109
|
+
break;
|
110
|
+
case 1:
|
111
|
+
obj = argv[0];
|
112
|
+
if(rb_compatible_q(rb_klass, obj)) {
|
113
|
+
CVPOINT2D32F(self)->x = NUM2DBL(rb_funcall(rb_funcall(obj, rb_intern("x"), 0), rb_intern("to_f"), 0));
|
114
|
+
CVPOINT2D32F(self)->y = NUM2DBL(rb_funcall(rb_funcall(obj, rb_intern("y"), 0), rb_intern("to_f"), 0));
|
115
|
+
}else{
|
116
|
+
rb_raise(rb_eArgError, "object is not compatible %s.", rb_class2name(rb_klass));
|
117
|
+
}
|
118
|
+
break;
|
119
|
+
case 2:
|
120
|
+
x = argv[0], y = argv[1];
|
121
|
+
CVPOINT2D32F(self)->x = NUM2DBL(x);
|
122
|
+
CVPOINT2D32F(self)->y = NUM2DBL(y);
|
123
|
+
break;
|
124
|
+
default:
|
125
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
126
|
+
}
|
127
|
+
return Qnil;
|
128
|
+
}
|
129
|
+
|
130
|
+
/*
|
131
|
+
* Return parameter on x-axis.
|
132
|
+
*/
|
133
|
+
VALUE
|
134
|
+
rb_x(VALUE self)
|
135
|
+
{
|
136
|
+
return rb_float_new(CVPOINT2D32F(self)->x);
|
137
|
+
}
|
138
|
+
|
139
|
+
/*
|
140
|
+
* call-seq:
|
141
|
+
* x = val
|
142
|
+
*
|
143
|
+
* Set x-axis parameter, return self.
|
144
|
+
*/
|
145
|
+
VALUE
|
146
|
+
rb_set_x(VALUE self, VALUE x)
|
147
|
+
{
|
148
|
+
CVPOINT2D32F(self)->x = NUM2DBL(x);
|
149
|
+
return self;
|
150
|
+
}
|
151
|
+
|
152
|
+
/*
|
153
|
+
* Return parameter on y-axis.
|
154
|
+
*/
|
155
|
+
VALUE
|
156
|
+
rb_y(VALUE self)
|
157
|
+
{
|
158
|
+
return rb_float_new(CVPOINT2D32F(self)->y);
|
159
|
+
}
|
160
|
+
|
161
|
+
/*
|
162
|
+
* call-seq:
|
163
|
+
* y = val
|
164
|
+
*
|
165
|
+
* Set y-axis parameter, return self.
|
166
|
+
*/
|
167
|
+
VALUE
|
168
|
+
rb_set_y(VALUE self, VALUE y)
|
169
|
+
{
|
170
|
+
CVPOINT2D32F(self)->y = NUM2DBL(y);
|
171
|
+
return self;
|
172
|
+
}
|
173
|
+
|
174
|
+
/*
|
175
|
+
* call-seq:
|
176
|
+
* to_s -> "<OpenCV::CvSize2D32f:(self.x,self.y)>"
|
177
|
+
*
|
178
|
+
* Return x and y by String.
|
179
|
+
*/
|
180
|
+
VALUE
|
181
|
+
rb_to_s(VALUE self)
|
182
|
+
{
|
183
|
+
const int i = 4;
|
184
|
+
VALUE str[i];
|
185
|
+
str[0] = rb_str_new2("<%s:(%f,%f)>");
|
186
|
+
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
|
187
|
+
str[2] = rb_x(self);
|
188
|
+
str[3] = rb_y(self);
|
189
|
+
return rb_f_sprintf(i, str);
|
190
|
+
}
|
191
|
+
|
192
|
+
/*
|
193
|
+
* call-seq:
|
194
|
+
* to_ary -> [x, y]
|
195
|
+
*
|
196
|
+
* Return x and y by Array.
|
197
|
+
*/
|
198
|
+
VALUE
|
199
|
+
rb_to_ary(VALUE self)
|
200
|
+
{
|
201
|
+
return rb_ary_new3(2, rb_x(self), rb_y(self));
|
202
|
+
}
|
203
|
+
|
204
|
+
VALUE
|
205
|
+
new_object(CvPoint2D32f point)
|
206
|
+
{
|
207
|
+
VALUE object = rb_allocate(rb_klass);
|
208
|
+
*CVPOINT2D32F(object) = point;
|
209
|
+
return object;
|
210
|
+
}
|
211
|
+
|
212
|
+
__NAMESPACE_END_CVPOINT2D32F
|
213
|
+
__NAMESPACE_END_OPENCV
|
data/ext/cvpoint2d32f.h
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvpoint2d32f.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVPOINT2D32F_H
|
11
|
+
#define RUBY_OPENCV_CVPOINT2D32F_H
|
12
|
+
|
13
|
+
#define __NAMESPACE_BEGIN_CVPOINT2D32F namespace cCvPoint2D32f{
|
14
|
+
#define __NAMESPACE_END_CVPOINT2D32F }
|
15
|
+
|
16
|
+
#include"opencv.h"
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVPOINT2D32F
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
|
23
|
+
void define_ruby_class();
|
24
|
+
|
25
|
+
VALUE rb_compatible_q(VALUE klass, VALUE object);
|
26
|
+
|
27
|
+
VALUE rb_allocate(VALUE klass);
|
28
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
29
|
+
VALUE rb_x(VALUE self);
|
30
|
+
VALUE rb_set_x(VALUE self, VALUE x);
|
31
|
+
VALUE rb_y(VALUE self);
|
32
|
+
VALUE rb_set_y(VALUE self, VALUE y);
|
33
|
+
|
34
|
+
VALUE rb_to_s(VALUE self);
|
35
|
+
VALUE rb_to_ary(VALUE self);
|
36
|
+
|
37
|
+
VALUE new_object(CvPoint2D32f point);
|
38
|
+
|
39
|
+
__NAMESPACE_END_CVPOINT2D32F
|
40
|
+
|
41
|
+
inline CvPoint2D32f*
|
42
|
+
CVPOINT2D32F(VALUE object)
|
43
|
+
{
|
44
|
+
CvPoint2D32f *ptr;
|
45
|
+
Data_Get_Struct(object, CvPoint2D32f, ptr);
|
46
|
+
return ptr;
|
47
|
+
}
|
48
|
+
|
49
|
+
inline CvPoint2D32f
|
50
|
+
VALUE_TO_CVPOINT2D32F(VALUE object)
|
51
|
+
{
|
52
|
+
if(cCvPoint2D32f::rb_compatible_q(cCvPoint2D32f::rb_class(), object)){
|
53
|
+
return cvPoint2D32f(NUM2DBL(rb_funcall(object, rb_intern("x"), 0)),
|
54
|
+
NUM2DBL(rb_funcall(object, rb_intern("y"), 0)));
|
55
|
+
}else{
|
56
|
+
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvPoint2D32f::rb_class()));
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
__NAMESPACE_END_OPENCV
|
61
|
+
#endif // RUBY_OPENCV_CVPOINT2D32F_H
|
@@ -0,0 +1,245 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvpoint3d32f.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2008 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include"cvpoint3d32f.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvPoint3D32f
|
13
|
+
*
|
14
|
+
* This class means one point on X axis Y axis.
|
15
|
+
* X and Y takes the value of the Float. see also CvPoint
|
16
|
+
*
|
17
|
+
* C structure is here, very simple.
|
18
|
+
* typdef struct CvPoint3D32f{
|
19
|
+
* float x;
|
20
|
+
* float y;
|
21
|
+
* float z;
|
22
|
+
* }
|
23
|
+
*/
|
24
|
+
__NAMESPACE_BEGIN_OPENCV
|
25
|
+
__NAMESPACE_BEGIN_CVPOINT3D32F
|
26
|
+
|
27
|
+
VALUE rb_klass;
|
28
|
+
|
29
|
+
VALUE
|
30
|
+
rb_class()
|
31
|
+
{
|
32
|
+
return rb_klass;
|
33
|
+
}
|
34
|
+
|
35
|
+
void
|
36
|
+
define_ruby_class()
|
37
|
+
{
|
38
|
+
if(rb_klass)
|
39
|
+
return;
|
40
|
+
/*
|
41
|
+
* opencv = rb_define_module("OpenCV");
|
42
|
+
* cvpoint2d32f = rb_define_class_under(opencv, "CvPoint2D32f", rb_cObject);
|
43
|
+
*
|
44
|
+
* note: this comment is used by rdoc.
|
45
|
+
*/
|
46
|
+
VALUE opencv = rb_module_opencv();
|
47
|
+
VALUE cvpoint2d32f = cCvPoint2D32f::rb_class();
|
48
|
+
rb_klass = rb_define_class_under(opencv, "CvPoint3D32f", cvpoint2d32f);
|
49
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
50
|
+
rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
|
51
|
+
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
52
|
+
rb_define_method(rb_klass, "x", RUBY_METHOD_FUNC(rb_x), 0);
|
53
|
+
rb_define_method(rb_klass, "x=", RUBY_METHOD_FUNC(rb_set_x), 1);
|
54
|
+
rb_define_method(rb_klass, "y", RUBY_METHOD_FUNC(rb_y), 0);
|
55
|
+
rb_define_method(rb_klass, "y=", RUBY_METHOD_FUNC(rb_set_y), 1);
|
56
|
+
rb_define_method(rb_klass, "z", RUBY_METHOD_FUNC(rb_z), 0);
|
57
|
+
rb_define_method(rb_klass, "z=", RUBY_METHOD_FUNC(rb_set_z), 1);
|
58
|
+
|
59
|
+
rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
|
60
|
+
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
61
|
+
}
|
62
|
+
|
63
|
+
/*
|
64
|
+
* call-seq:
|
65
|
+
* combatible?(obj)
|
66
|
+
*
|
67
|
+
* Return compatibility to CvPoint3D32f. Return true if object have method #x and #y and #z.
|
68
|
+
*
|
69
|
+
* For example.
|
70
|
+
* class MyPoint3D32f
|
71
|
+
* def x
|
72
|
+
* 95.7
|
73
|
+
* end
|
74
|
+
* def y
|
75
|
+
* 70.2
|
76
|
+
* end
|
77
|
+
* def z
|
78
|
+
* 10.0
|
79
|
+
* end
|
80
|
+
* end
|
81
|
+
* mp = MyPoint3D32f.new
|
82
|
+
* CvPoint3D32f.compatible?(mp) #=> true
|
83
|
+
* CvPoint3D32f.new(mp) #=> same as CvPoint3D32f(95.7, 70.2)
|
84
|
+
*/
|
85
|
+
VALUE
|
86
|
+
rb_compatible_q(VALUE klass, VALUE object)
|
87
|
+
{
|
88
|
+
return (rb_respond_to(object, rb_intern("x")) && rb_respond_to(object, rb_intern("y"))) ? Qtrue : Qfalse;
|
89
|
+
}
|
90
|
+
|
91
|
+
VALUE
|
92
|
+
rb_allocate(VALUE klass)
|
93
|
+
{
|
94
|
+
CvPoint3D32f *ptr;
|
95
|
+
return Data_Make_Struct(klass, CvPoint3D32f, 0, -1, ptr);
|
96
|
+
}
|
97
|
+
|
98
|
+
/*
|
99
|
+
* call-seq:
|
100
|
+
* new
|
101
|
+
* new(obj)
|
102
|
+
* new(x, y, z)
|
103
|
+
*
|
104
|
+
* Create new 3D-coordinate, (x, y, z).
|
105
|
+
*
|
106
|
+
* new() is same as new(0.0, 0.0, 0.0)
|
107
|
+
*
|
108
|
+
* new(obj) is same as new(obj.x.to_f, obj.y.to_f, obj.z.to_f)
|
109
|
+
*/
|
110
|
+
VALUE
|
111
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
112
|
+
{
|
113
|
+
VALUE obj, x, y, z;
|
114
|
+
switch (argc) {
|
115
|
+
case 0:
|
116
|
+
break;
|
117
|
+
case 1:
|
118
|
+
obj = argv[0];
|
119
|
+
if(rb_compatible_q(rb_klass, obj)) {
|
120
|
+
CVPOINT3D32F(self)->x = NUM2DBL(rb_funcall(rb_funcall(obj, rb_intern("x"), 0), rb_intern("to_f"), 0));
|
121
|
+
CVPOINT3D32F(self)->y = NUM2DBL(rb_funcall(rb_funcall(obj, rb_intern("y"), 0), rb_intern("to_f"), 0));
|
122
|
+
CVPOINT3D32F(self)->z = NUM2DBL(rb_funcall(rb_funcall(obj, rb_intern("z"), 0), rb_intern("to_f"), 0));
|
123
|
+
}else{
|
124
|
+
rb_raise(rb_eArgError, "object is not compatible %s.", rb_class2name(rb_klass));
|
125
|
+
}
|
126
|
+
break;
|
127
|
+
case 3:
|
128
|
+
x = argv[0], y = argv[1], z = argv[2];
|
129
|
+
CVPOINT3D32F(self)->x = NUM2DBL(x);
|
130
|
+
CVPOINT3D32F(self)->y = NUM2DBL(y);
|
131
|
+
CVPOINT3D32F(self)->z = NUM2DBL(z);
|
132
|
+
break;
|
133
|
+
default:
|
134
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
135
|
+
}
|
136
|
+
return Qnil;
|
137
|
+
}
|
138
|
+
|
139
|
+
/*
|
140
|
+
* Return parameter on x-axis.
|
141
|
+
*/
|
142
|
+
VALUE
|
143
|
+
rb_x(VALUE self)
|
144
|
+
{
|
145
|
+
return rb_float_new(CVPOINT2D32F(self)->x);
|
146
|
+
}
|
147
|
+
|
148
|
+
/*
|
149
|
+
* call-seq:
|
150
|
+
* x = val
|
151
|
+
*
|
152
|
+
* Set x-axis parameter, return self.
|
153
|
+
*/
|
154
|
+
VALUE
|
155
|
+
rb_set_x(VALUE self, VALUE x)
|
156
|
+
{
|
157
|
+
CVPOINT2D32F(self)->x = NUM2DBL(x);
|
158
|
+
return self;
|
159
|
+
}
|
160
|
+
|
161
|
+
/*
|
162
|
+
* Return parameter on y-axis.
|
163
|
+
*/
|
164
|
+
VALUE
|
165
|
+
rb_y(VALUE self)
|
166
|
+
{
|
167
|
+
return rb_float_new(CVPOINT2D32F(self)->y);
|
168
|
+
}
|
169
|
+
|
170
|
+
/*
|
171
|
+
* call-seq:
|
172
|
+
* y = val
|
173
|
+
*
|
174
|
+
* Set y-axis parameter, return self.
|
175
|
+
*/
|
176
|
+
VALUE
|
177
|
+
rb_set_y(VALUE self, VALUE y)
|
178
|
+
{
|
179
|
+
CVPOINT2D32F(self)->y = NUM2DBL(y);
|
180
|
+
return self;
|
181
|
+
}
|
182
|
+
|
183
|
+
/*
|
184
|
+
* Return parameter on z-axis.
|
185
|
+
*/
|
186
|
+
VALUE
|
187
|
+
rb_z(VALUE self)
|
188
|
+
{
|
189
|
+
return rb_float_new(CVPOINT3D32F(self)->z);
|
190
|
+
}
|
191
|
+
|
192
|
+
/*
|
193
|
+
* call-seq:
|
194
|
+
* z = val
|
195
|
+
*
|
196
|
+
* Set z-axis parameter, return self.
|
197
|
+
*/
|
198
|
+
VALUE
|
199
|
+
rb_set_z(VALUE self, VALUE z)
|
200
|
+
{
|
201
|
+
CVPOINT3D32F(self)->z = NUM2DBL(z);
|
202
|
+
return self;
|
203
|
+
}
|
204
|
+
|
205
|
+
/*
|
206
|
+
* call-seq:
|
207
|
+
* to_s -> "<OpenCV::CvSize3D32f:(self.x,self.y,self.z)>"
|
208
|
+
*
|
209
|
+
* Return x and y by String.
|
210
|
+
*/
|
211
|
+
VALUE
|
212
|
+
rb_to_s(VALUE self)
|
213
|
+
{
|
214
|
+
const int i = 5;
|
215
|
+
VALUE str[i];
|
216
|
+
str[0] = rb_str_new2("<%s:(%f,%f,%f)>");
|
217
|
+
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
|
218
|
+
str[2] = rb_x(self);
|
219
|
+
str[3] = rb_y(self);
|
220
|
+
str[4] = rb_z(self);
|
221
|
+
return rb_f_sprintf(i, str);
|
222
|
+
}
|
223
|
+
|
224
|
+
/*
|
225
|
+
* call-seq:
|
226
|
+
* to_ary -> [x, y, z]
|
227
|
+
*
|
228
|
+
* Return x and y by Array.
|
229
|
+
*/
|
230
|
+
VALUE
|
231
|
+
rb_to_ary(VALUE self)
|
232
|
+
{
|
233
|
+
return rb_ary_new3(3, rb_x(self), rb_y(self), rb_z(self));
|
234
|
+
}
|
235
|
+
|
236
|
+
VALUE
|
237
|
+
new_object(CvPoint3D32f point)
|
238
|
+
{
|
239
|
+
VALUE object = rb_allocate(rb_klass);
|
240
|
+
*CVPOINT3D32F(object) = point;
|
241
|
+
return object;
|
242
|
+
}
|
243
|
+
|
244
|
+
__NAMESPACE_END_CVPOINT3D32F
|
245
|
+
__NAMESPACE_END_OPENCV
|