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;
\r
34 import java.lang.reflect.Array;
\r
35 import jp.nyatla.nyartoolkit.core.labeling.*;
\r
38 * ラベル同士の重なり(内包関係)を調べるクラスです。
\r
39 * ラベルリストに内包するラベルを蓄積し、それにターゲットのラベルが内包されているか を確認します。
\r
41 public class LabelOverlapChecker<T extends NyARLabelInfo>
\r
43 private T[] _labels;
\r
44 private int _length;
\r
45 private Class<T> _element_type;
\r
48 @SuppressWarnings("unchecked")
\r
49 public LabelOverlapChecker(int i_max_label,Class<T> i_element_type)
\r
51 this._element_type=i_element_type;
\r
52 this._labels = (T[])Array.newInstance(i_element_type, 32);
\r
58 * @param i_label_ref
\r
60 public void push(T i_label_ref)
\r
62 this._labels[this._length] = i_label_ref;
\r
67 * 現在リストにあるラベルと重なっているかを返す。
\r
70 * @return 何れかのラベルの内側にあるならばfalse,独立したラベルである可能性が高ければtrueです.
\r
72 public boolean check(T i_label)
\r
75 final T[] label_pt = this._labels;
\r
76 final int px1 = (int) i_label.pos_x;
\r
77 final int py1 = (int) i_label.pos_y;
\r
78 for (int i = this._length - 1; i >= 0; i--) {
\r
79 final int px2 = (int) label_pt[i].pos_x;
\r
80 final int py2 = (int) label_pt[i].pos_y;
\r
81 final int d = (px1 - px2) * (px1 - px2) + (py1 - py2) * (py1 - py2);
\r
82 if (d < label_pt[i].area / 4) {
\r
91 * 最大i_max_label個のラベルを蓄積できるようにオブジェクトをリセットする
\r
93 * @param i_max_label
\r
95 @SuppressWarnings("unchecked")
\r
96 public void setMaxLabels(int i_max_label)
\r
98 if (i_max_label > this._labels.length) {
\r
99 this._labels = (T[])Array.newInstance(this._element_type, i_max_label);
\r