/*
* PROJECT: NyARToolkitAS3
* --------------------------------------------------------------------------------
* This work is based on the original ARToolKit developed by
* Hirokazu Kato
* Mark Billinghurst
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
* The NyARToolkitAS3 is AS3 edition ARToolKit class library.
* Copyright (C)2010 Ryo Iizuka
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
* or
*
*/
package jp.nyatla.nyartoolkit.as3.core.squaredetect
{
import jp.nyatla.nyartoolkit.as3.core.raster.*;
import jp.nyatla.nyartoolkit.as3.core.labeling.*;
import jp.nyatla.nyartoolkit.as3.*;
public class NyARContourPickup
{
//巡回参照できるように、テーブルを二重化
// 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
protected static const _getContour_xdir:Vector. = Vector.([0, 1, 1, 1, 0, -1, -1, -1 , 0, 1, 1, 1, 0, -1, -1]);
protected static const _getContour_ydir:Vector. = Vector.([-1,-1, 0, 1, 1, 1, 0,-1 ,-1,-1, 0, 1, 1, 1, 0]);
public function getContour_NyARBinRaster(i_raster:NyARBinRaster,i_entry_x:int,i_entry_y:int,i_array_size:int,o_coord_x:Vector.,o_coord_y:Vector.):int
{
return impl_getContour(i_raster,0,i_entry_x,i_entry_y,i_array_size,o_coord_x,o_coord_y);
}
/**
*
* @param i_raster
* @param i_th
* 画像を2値化するための閾値。暗点<=i_th<明点となります。
* @param i_entry_x
* 輪郭の追跡開始点を指定します。
* @param i_entry_y
* @param i_array_size
* @param o_coord_x
* @param o_coord_y
* @return
* @throws NyARException
*/
public function getContour_NyARGrayscaleRaster(i_raster:NyARGrayscaleRaster,i_th:int,i_entry_x:int,i_entry_y:int,i_array_size:int,o_coord_x:Vector.,o_coord_y:Vector.):int
{
return impl_getContour(i_raster,i_th,i_entry_x,i_entry_y,i_array_size,o_coord_x,o_coord_y);
}
/**
* ラスタのエントリポイントから辿れる輪郭線を配列に返します。
* @param i_raster
* @param i_th
* 暗点<=th<明点
* @param i_entry_x
* @param i_entry_y
* @param i_array_size
* @param o_coord_x
* @param o_coord_y
* @return
* 輪郭線の長さを返します。
* @throws NyARException
*/
private function impl_getContour(i_raster:INyARRaster,i_th:int,i_entry_x:int,i_entry_y:int,i_array_size:int,o_coord_x:Vector.,o_coord_y:Vector.):int
{
var xdir:Vector. = _getContour_xdir;// static int xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1};
var ydir:Vector. = _getContour_ydir;// static int ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1};
var i_buf:Vector.=Vector.(i_raster.getBuffer());
var width:int=i_raster.getWidth();
var height:int=i_raster.getHeight();
//クリップ領域の上端に接しているポイントを得る。
var coord_num:int = 1;
o_coord_x[0] = i_entry_x;
o_coord_y[0] = i_entry_y;
var dir:int = 5;
var c:int = i_entry_x;
var r:int = i_entry_y;
for (;;) {
dir = (dir + 5) % 8;//dirの正規化
//ここは頑張ればもっと最適化できると思うよ。
//4隅以外の境界接地の場合に、境界チェックを省略するとかね。
if(c>=1 && c=1 && r=0 && x=0 && y