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.types.*;
\r
40 public class NyARLabelingImage extends NyARRaster_BasicClass
\r
42 private final static int MAX_LABELS = 1024*32;
\r
44 protected int[] _ref_buf;
\r
45 protected NyARLabelingLabelStack _label_list;
\r
46 protected int[] _index_table;
\r
47 protected boolean _is_index_table_enable;
\r
48 public NyARLabelingImage(int i_width, int i_height) throws NyARException
\r
50 super(new NyARIntSize(i_width,i_height),NyARBufferType.INT1D);
\r
51 this._ref_buf =new int[i_height*i_width];
\r
52 this._label_list = new NyARLabelingLabelStack(MAX_LABELS);
\r
53 this._index_table=new int[MAX_LABELS];
\r
54 this._is_index_table_enable=false;
\r
59 public Object getBuffer()
\r
61 return this._ref_buf;
\r
63 public boolean hasBuffer()
\r
65 return this._ref_buf!=null;
\r
67 public void wrapBuffer(Object i_ref_buf) throws NyARException
\r
69 NyARException.notImplement();
\r
74 public void drawFrameEdge()
\r
78 // NyLabelingImageのイメージ初期化(枠書き)
\r
79 int[] img = (int[]) this._ref_buf;
\r
80 int bottom_ptr = (h - 1) * w;
\r
81 for (int i = 0; i < w; i++) {
\r
83 img[bottom_ptr + i] = 0;
\r
85 for (int i = 0; i < h; i++) {
\r
87 img[(i + 1) * w - 1] = 0;
\r
93 * ラベリング結果がインデックステーブルを持つ場合、その配列を返します。
\r
96 * 値がnullの時はラベル番号そのものがラスタに格納されていますが、
\r
97 * null以外の時はラスタに格納されているのはインデクス番号です。
\r
99 * インデクス番号とラベル番号の関係は、以下の式で表されます。
\r
100 * ラベル番号:=value[インデクス番号]
\r
103 public int[] getIndexArray()
\r
105 return this._is_index_table_enable?this._index_table:null;
\r
108 public NyARLabelingLabelStack getLabelStack()
\r
110 return this._label_list;
\r
112 public void reset(boolean i_label_index_enable)
\r
114 assert(i_label_index_enable==true);//非ラベルモードは未実装
\r
115 this._label_list.clear();
\r
116 this._is_index_table_enable=i_label_index_enable;
\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