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 version ARToolkit class library.
\r
11 * Copyright (C)2008 R.Iizuka
\r
13 * This program is free software; you can redistribute it and/or
\r
14 * modify it under the terms of the GNU General Public License
\r
15 * as published by the Free Software Foundation; either version 2
\r
16 * of the License, or (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 framework; if not, write to the Free Software
\r
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
27 * For further information please contact.
\r
28 * http://nyatla.jp/nyatoolkit/
\r
29 * <airmail(at)ebony.plala.or.jp>
\r
32 package jp.nyatla.nyartoolkit.core.labeling.artoolkit;
\r
34 import jp.nyatla.nyartoolkit.NyARException;
\r
35 import jp.nyatla.nyartoolkit.core.raster.*;
\r
36 import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;
\r
37 import jp.nyatla.nyartoolkit.core.rasterreader.NyARBufferReader;
\r
38 import jp.nyatla.nyartoolkit.core.types.*;
\r
43 public class NyARLabelingImage extends NyARRaster_BasicClass
\r
45 private final static int MAX_LABELS = 1024*32;
\r
46 protected int[] _ref_buf;
\r
47 private INyARBufferReader _buffer_reader;
\r
48 protected NyARLabelingLabelStack _label_list;
\r
49 protected int[] _index_table;
\r
50 protected boolean _is_index_table_enable;
\r
51 public NyARLabelingImage(int i_width, int i_height)
\r
53 super(new NyARIntSize(i_width,i_height));
\r
54 this._ref_buf =new int[i_height*i_width];
\r
55 this._label_list = new NyARLabelingLabelStack(MAX_LABELS);
\r
56 this._index_table=new int[MAX_LABELS];
\r
57 this._is_index_table_enable=false;
\r
58 this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D);
\r
63 public INyARBufferReader getBufferReader()
\r
65 return this._buffer_reader;
\r
70 public void drawFrameEdge()
\r
74 // NyLabelingImageのイメージ初期化(枠書き)
\r
75 int[] img = (int[]) this._ref_buf;
\r
76 int bottom_ptr = (h - 1) * w;
\r
77 for (int i = 0; i < w; i++) {
\r
79 img[bottom_ptr + i] = 0;
\r
81 for (int i = 0; i < h; i++) {
\r
83 img[(i + 1) * w - 1] = 0;
\r
89 * ラベリング結果がインデックステーブルを持つ場合、その配列を返します。
\r
92 * 値がnullの時はラベル番号そのものがラスタに格納されていますが、
\r
93 * null以外の時はラスタに格納されているのはインデクス番号です。
\r
95 * インデクス番号とラベル番号の関係は、以下の式で表されます。
\r
96 * ラベル番号:=value[インデクス番号]
\r
99 public int[] getIndexArray()
\r
101 return this._is_index_table_enable?this._index_table:null;
\r
104 public NyARLabelingLabelStack getLabelStack()
\r
106 return this._label_list;
\r
108 public void reset(boolean i_label_index_enable)
\r
110 assert(i_label_index_enable==true);//非ラベルモードは未実装
\r
111 this._label_list.clear();
\r
112 this._is_index_table_enable=i_label_index_enable;
\r
115 //巡回参照できるように、テーブルを二重化
\r
116 // 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
\r
117 protected final static int[] _getContour_xdir = { 0, 1, 1, 1, 0,-1,-1,-1 , 0, 1, 1, 1, 0,-1,-1};
\r
118 protected final static int[] _getContour_ydir = {-1,-1, 0, 1, 1, 1, 0,-1 ,-1,-1, 0, 1, 1, 1, 0};
\r
120 * i_labelのラベルの、クリップ領域が上辺に接しているx座標を返します。
\r
124 public int getTopClipTangentX(NyARLabelingLabel i_label) throws NyARException
\r
127 int i_label_id=i_label.id;
\r
128 int[] index_table=this._index_table;
\r
129 int[] limage=this._ref_buf;
\r
130 int limage_ptr=i_label.clip_t*this._size.w;
\r
131 final int clip1 = i_label.clip_r;
\r
132 // p1=ShortPointer.wrap(limage,j*xsize+clip.get());//p1 =&(limage[j*xsize+clip[0]]);
\r
133 for (int i = i_label.clip_l; i <= clip1; i++) {// for( i = clip[0]; i <=clip[1]; i++, p1++ ) {
\r
134 pix = limage[limage_ptr+i];
\r
135 if (pix > 0 && index_table[pix-1] == i_label_id){
\r
140 throw new NyARException();
\r