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
\r
14 * modify it under the terms of the GNU Lesser General Public License
\r
15 * as published by the Free Software Foundation; either version 3
\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 Lesser General Public License for more details
\r
23 * You should have received a copy of the GNU Lesser General Public
\r
24 * License 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;
\r
33 import java.lang.reflect.Array;
\r
37 * ラベル同士の重なり(内包関係)を調べるクラスです。
\r
38 * ラベルリストに内包するラベルを蓄積し、それにターゲットのラベルが内包されているか を確認します。
\r
40 public class LabelOverlapChecker<T extends NyARLabelInfo>
\r
42 private T[] _labels;
\r
43 private int _length;
\r
44 private Class<T> _element_type;
\r
47 @SuppressWarnings("unchecked")
\r
48 public LabelOverlapChecker(int i_max_label,Class<T> i_element_type)
\r
50 this._element_type=i_element_type;
\r
51 this._labels = (T[])Array.newInstance(i_element_type, i_max_label);
\r
57 * @param i_label_ref
\r
59 public void push(T i_label_ref)
\r
61 this._labels[this._length] = i_label_ref;
\r
66 * 現在リストにあるラベルと重なっているかを返す。
\r
69 * @return 何れかのラベルの内側にあるならばfalse,独立したラベルである可能性が高ければtrueです.
\r
71 public boolean check(T i_label)
\r
74 final T[] label_pt = this._labels;
\r
75 final int px1 = (int) i_label.pos_x;
\r
76 final int py1 = (int) i_label.pos_y;
\r
77 for (int i = this._length - 1; i >= 0; i--) {
\r
78 final int px2 = (int) label_pt[i].pos_x;
\r
79 final int py2 = (int) label_pt[i].pos_y;
\r
80 final int d = (px1 - px2) * (px1 - px2) + (py1 - py2) * (py1 - py2);
\r
81 if (d < label_pt[i].area / 4) {
\r
90 * 最大i_max_label個のラベルを蓄積できるようにオブジェクトをリセットする
\r
92 * @param i_max_label
\r
94 @SuppressWarnings("unchecked")
\r
95 public void setMaxLabels(int i_max_label)
\r
97 if (i_max_label > this._labels.length) {
\r
98 this._labels = (T[])Array.newInstance(this._element_type, i_max_label);
\r