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;
\r
34 import java.io.FileInputStream;
\r
35 import java.io.InputStream;
\r
36 import java.io.InputStreamReader;
\r
37 import java.io.StreamTokenizer;
\r
39 import jp.nyatla.nyartoolkit.NyARException;
\r
44 * ARToolKitのマーカーコードを1個保持します。
\r
47 public class NyARCode
\r
49 private int[][][][] pat;// static int
\r
50 // pat[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];
\r
52 private double[] patpow = new double[4];// static double patpow[AR_PATT_NUM_MAX][4];
\r
54 private short[][][] patBW;// static int patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];
\r
56 private double[] patpowBW = new double[4];// static double patpowBW[AR_PATT_NUM_MAX][4];
\r
58 private int width, height;
\r
60 public int[][][][] getPat()
\r
65 public double[] getPatPow()
\r
70 public short[][][] getPatBW()
\r
75 public double[] getPatPowBW()
\r
80 public int getWidth()
\r
85 public int getHeight()
\r
90 public NyARCode(int i_width, int i_height)
\r
94 pat = new int[4][height][width][3];// static int pat[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];
\r
95 patBW = new short[4][height][width];// static int patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];
\r
99 * int arLoadPatt( const char *filename ); ARToolKitのパターンファイルをロードする。
\r
100 * ファイル形式はBGR形式で記録されたパターンファイルであること。
\r
104 * @throws Exception
\r
106 public void loadARPattFromFile(String filename) throws NyARException
\r
109 loadARPatt(new FileInputStream(filename));
\r
111 } catch (Exception e) {
\r
112 throw new NyARException(e);
\r
119 * @throws NyARException
\r
121 public void loadARPatt(InputStream i_stream) throws NyARException
\r
124 StreamTokenizer st = new StreamTokenizer(new InputStreamReader(
\r
126 // パターンデータはGBRAで並んでる。
\r
127 for (int h = 0; h < 4; h++) {
\r
129 for (int i3 = 0; i3 < 3; i3++) {
\r
130 for (int i2 = 0; i2 < height; i2++) {
\r
131 for (int i1 = 0; i1 < width; i1++) {
\r
133 switch (st.nextToken()) {// if( fscanf(fp, "%d",&j) != 1 ) {
\r
134 case StreamTokenizer.TT_NUMBER:
\r
137 throw new NyARException();
\r
139 short j = (short) (255 - st.nval);// j = 255-j;
\r
140 // 標準ファイルのパターンはBGRでならんでるからRGBに並べなおす
\r
143 pat[h][i2][i1][2] = j;
\r
144 break;// pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+2]= j;break;
\r
146 pat[h][i2][i1][1] = j;
\r
147 break;// pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+1]= j;break;
\r
149 pat[h][i2][i1][0] = j;
\r
150 break;// pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+0]= j;break;
\r
152 // pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+i3]= j;
\r
154 patBW[h][i2][i1] = j;// patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1] = j;
\r
156 patBW[h][i2][i1] += j;// patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1] += j;
\r
159 patBW[h][i2][i1] /= 3;// patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1]/= 3;
\r
166 l /= (height * width * 3);
\r
169 for (int i = 0; i < height; i++) {// for( i = 0; i < AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3;i++ ) {
\r
170 for (int i2 = 0; i2 < width; i2++) {
\r
171 for (int i3 = 0; i3 < 3; i3++) {
\r
172 pat[h][i][i2][i3] -= l;
\r
173 m += (pat[h][i][i2][i3] * pat[h][i][i2][i3]);
\r
177 patpow[h] = Math.sqrt((double) m);
\r
178 if (patpow[h] == 0.0) {
\r
179 patpow[h] = 0.0000001;
\r
183 for (int i = 0; i < height; i++) {
\r
184 for (int i2 = 0; i2 < width; i2++) {
\r
185 patBW[h][i][i2] -= l;
\r
186 m += (patBW[h][i][i2] * patBW[h][i][i2]);
\r
189 patpowBW[h] = Math.sqrt((double) m);
\r
190 if (patpowBW[h] == 0.0) {
\r
191 patpowBW[h] = 0.0000001;
\r
194 } catch (Exception e) {
\r
195 throw new NyARException(e);
\r