2008-08-19 11:01:28 -04:00
|
|
|
/************************************************************
|
|
|
|
|
|
|
|
curve.cpp -
|
|
|
|
|
|
|
|
$Author: lsxi $
|
|
|
|
|
|
|
|
Copyright (C) 2005 Masakazu Yonekura
|
|
|
|
|
|
|
|
************************************************************/
|
2011-08-11 13:26:54 -04:00
|
|
|
#include "curve.h"
|
2012-04-30 07:39:38 -04:00
|
|
|
/*
|
|
|
|
* Document-class: OpenCV::Curve
|
|
|
|
*
|
|
|
|
* Curve sequence
|
|
|
|
*/
|
2008-08-19 11:01:28 -04:00
|
|
|
__NAMESPACE_BEGIN_OPENCV
|
|
|
|
__NAMESPACE_BEGIN_CURVE
|
|
|
|
|
|
|
|
VALUE module;
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_module()
|
|
|
|
{
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-04-30 07:14:49 -04:00
|
|
|
* If the curve is closed, return true. Otherwise return false.
|
|
|
|
* @overload closed?
|
|
|
|
* @return [Boolean] Closed or not
|
|
|
|
* @opencv_func CV_IS_SEQ_CLOSED
|
2008-08-19 11:01:28 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
|
|
|
rb_closed_q(VALUE self)
|
|
|
|
{
|
|
|
|
return CV_IS_SEQ_CLOSED(CVSEQ(self)) ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-04-30 07:14:49 -04:00
|
|
|
* If the curve is convex, return true. Otherwise return false.
|
|
|
|
* @overload convex?
|
|
|
|
* @return [Boolean] Convex or not
|
|
|
|
* @opencv_func CV_IS_SEQ_CONVEX
|
2008-08-19 11:01:28 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
|
|
|
rb_convex_q(VALUE self)
|
|
|
|
{
|
|
|
|
return CV_IS_SEQ_CONVEX(CVSEQ(self)) ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-04-30 07:14:49 -04:00
|
|
|
* If the curve is hole(inner contour), return true. Otherwise return false.
|
|
|
|
* @overload hole?
|
|
|
|
* @return [Boolean] Hole or not
|
|
|
|
* @opencv_func CV_IS_SEQ_HOLE
|
2008-08-19 11:01:28 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
|
|
|
rb_hole_q(VALUE self)
|
|
|
|
{
|
|
|
|
return CV_IS_SEQ_HOLE(CVSEQ(self)) ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-04-30 07:14:49 -04:00
|
|
|
* If the curve is simple, return true. Otherwise return false.
|
|
|
|
* @overload simple?
|
|
|
|
* @return [Boolean] Simple or not
|
|
|
|
* @opencv_func CV_IS_SEQ_SIMPLE
|
2008-08-19 11:01:28 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
|
|
|
rb_simple_q(VALUE self)
|
|
|
|
{
|
|
|
|
return CV_IS_SEQ_SIMPLE(CVSEQ(self)) ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-04-30 07:14:49 -04:00
|
|
|
* Calculates length of a curve
|
|
|
|
* @overload arc_length(slice = nil, is_closed = nil)
|
|
|
|
* @param slice [Range,CvSlice,nil] Starting and ending points of the curve.
|
|
|
|
* By default, the whole curve length is calculated.
|
|
|
|
* @param is_closed [Boolean,nil] Indicates whether the curve is closed or not.
|
|
|
|
* There are 3 cases:
|
|
|
|
* * is_closed = true - the curve is assumed to be unclosed.
|
|
|
|
* * is_closed = false - the curve is assumed to be closed.
|
|
|
|
* * is_closed = nil (default) use self#closed?
|
|
|
|
* @return [Number] Length of the curve
|
|
|
|
* @opencv_func cvArcLength
|
2008-08-19 11:01:28 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
|
|
|
rb_arc_length(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
VALUE slice, is_closed;
|
|
|
|
rb_scan_args(argc, argv, "02", &slice, &is_closed);
|
2011-07-21 10:14:12 -04:00
|
|
|
double length = 0;
|
|
|
|
try {
|
|
|
|
length = cvArcLength(CVARR(self),
|
|
|
|
NIL_P(slice) ? CV_WHOLE_SEQ : VALUE_TO_CVSLICE(slice),
|
|
|
|
TRUE_OR_FALSE(is_closed, -1));
|
|
|
|
}
|
|
|
|
catch (cv::Exception& e) {
|
|
|
|
raise_cverror(e);
|
|
|
|
}
|
|
|
|
return rb_float_new(length);
|
2008-08-19 11:01:28 -04:00
|
|
|
}
|
|
|
|
|
2012-05-30 13:38:41 -04:00
|
|
|
void
|
|
|
|
init_ruby_module()
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
// For documentation using YARD
|
|
|
|
VALUE opencv = rb_define_module("OpenCV");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (module)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VALUE opencv = rb_module_opencv();
|
|
|
|
module = rb_define_module_under(opencv, "Curve");
|
|
|
|
rb_define_method(module, "closed?", RUBY_METHOD_FUNC(rb_closed_q), 0);
|
|
|
|
rb_define_method(module, "convex?", RUBY_METHOD_FUNC(rb_convex_q), 0);
|
|
|
|
rb_define_method(module, "hole?", RUBY_METHOD_FUNC(rb_hole_q), 0);
|
|
|
|
rb_define_method(module, "simple?", RUBY_METHOD_FUNC(rb_simple_q), 0);
|
|
|
|
rb_define_method(module, "arc_length", RUBY_METHOD_FUNC(rb_arc_length), -1);
|
|
|
|
}
|
|
|
|
|
2008-08-19 11:01:28 -04:00
|
|
|
__NAMESPACE_END_CURVE
|
|
|
|
__NAMESPACE_END_OPENCV
|
|
|
|
|