2 * PROJECT: NyARToolkit
\r
3 * --------------------------------------------------------------------------------
\r
4 * This work is based on the original ARToolKit developed by
\r
7 * HITLab, University of Washington, Seattle
\r
8 * http://www.hitl.washington.edu/artoolkit/
\r
10 * The NyARToolkit is Java edition ARToolKit class library.
\r
11 * Copyright (C)2008-2009 Ryo Iizuka
\r
13 * This program is free software: you can redistribute it and/or modify
\r
14 * it under the terms of the GNU General Public License as published by
\r
15 * the Free Software Foundation, either version 3 of the License, or
\r
16 * (at your option) any later version.
\r
18 * This program is distributed in the hope that it will be useful,
\r
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 * GNU General Public License for more details.
\r
23 * You should have received a copy of the GNU General Public License
\r
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
26 * For further information please contact.
\r
27 * http://nyatla.jp/nyatoolkit/
\r
28 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
31 package jp.nyatla.nyartoolkit.core.labeling.artoolkit;
\r
33 import jp.nyatla.nyartoolkit.NyARException;
\r
34 import jp.nyatla.nyartoolkit.core.raster.*;
\r
35 import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;
\r
36 import jp.nyatla.nyartoolkit.core.rasterreader.NyARBufferReader;
\r
37 import jp.nyatla.nyartoolkit.core.types.*;
\r
42 public class NyARLabelingImage extends NyARRaster_BasicClass
\r
44 private final static int MAX_LABELS = 1024*32;
\r
45 protected int[] _ref_buf;
\r
46 private INyARBufferReader _buffer_reader;
\r
47 protected NyARLabelingLabelStack _label_list;
\r
48 protected int[] _index_table;
\r
49 protected boolean _is_index_table_enable;
\r
50 public NyARLabelingImage(int i_width, int i_height)
\r
52 super(new NyARIntSize(i_width,i_height));
\r
53 this._ref_buf =new int[i_height*i_width];
\r
54 this._label_list = new NyARLabelingLabelStack(MAX_LABELS);
\r
55 this._index_table=new int[MAX_LABELS];
\r
56 this._is_index_table_enable=false;
\r
57 this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D);
\r
62 public INyARBufferReader getBufferReader()
\r
64 return this._buffer_reader;
\r
69 public void drawFrameEdge()
\r
73 // NyLabelingImageのイメージ初期化(枠書き)
\r
74 int[] img = (int[]) this._ref_buf;
\r
75 int bottom_ptr = (h - 1) * w;
\r
76 for (int i = 0; i < w; i++) {
\r
78 img[bottom_ptr + i] = 0;
\r
80 for (int i = 0; i < h; i++) {
\r
82 img[(i + 1) * w - 1] = 0;
\r
88 * ラベリング結果がインデックステーブルを持つ場合、その配列を返します。
\r
91 * 値がnullの時はラベル番号そのものがラスタに格納されていますが、
\r
92 * null以外の時はラスタに格納されているのはインデクス番号です。
\r
94 * インデクス番号とラベル番号の関係は、以下の式で表されます。
\r
95 * ラベル番号:=value[インデクス番号]
\r
98 public int[] getIndexArray()
\r
100 return this._is_index_table_enable?this._index_table:null;
\r
103 public NyARLabelingLabelStack getLabelStack()
\r
105 return this._label_list;
\r
107 public void reset(boolean i_label_index_enable)
\r
109 assert(i_label_index_enable==true);//非ラベルモードは未実装
\r
110 this._label_list.clear();
\r
111 this._is_index_table_enable=i_label_index_enable;
\r
114 //巡回参照できるように、テーブルを二重化
\r
115 // 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
\r
116 protected final static int[] _getContour_xdir = { 0, 1, 1, 1, 0,-1,-1,-1 , 0, 1, 1, 1, 0,-1,-1};
\r
117 protected final static int[] _getContour_ydir = {-1,-1, 0, 1, 1, 1, 0,-1 ,-1,-1, 0, 1, 1, 1, 0};
\r
119 * i_labelのラベルの、クリップ領域が上辺に接しているx座標を返します。
\r
123 public int getTopClipTangentX(NyARLabelingLabel i_label) throws NyARException
\r
126 int i_label_id=i_label.id;
\r
127 int[] index_table=this._index_table;
\r
128 int[] limage=this._ref_buf;
\r
129 int limage_ptr=i_label.clip_t*this._size.w;
\r
130 final int clip1 = i_label.clip_r;
\r
131 // p1=ShortPointer.wrap(limage,j*xsize+clip.get());//p1 =&(limage[j*xsize+clip[0]]);
\r
132 for (int i = i_label.clip_l; i <= clip1; i++) {// for( i = clip[0]; i <=clip[1]; i++, p1++ ) {
\r
133 pix = limage[limage_ptr+i];
\r
134 if (pix > 0 && index_table[pix-1] == i_label_id){
\r
139 throw new NyARException();
\r