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
33 package jp.nyatla.nyartoolkit.core;
\r
35 import java.io.FileInputStream;
\r
36 import java.io.InputStream;
\r
37 import java.io.InputStreamReader;
\r
38 import java.io.StreamTokenizer;
\r
40 import jp.nyatla.nyartoolkit.NyARException;
\r
47 * ARToolKitのマーカーコードを1個保持します。
\r
50 public class NyARCode{
\r
51 private int[][][][] pat;//static int 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
53 private short[][][] patBW;//static int patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];
\r
54 private double[] patpowBW=new double[4];//static double patpowBW[AR_PATT_NUM_MAX][4];
\r
55 private int width,height;
\r
56 public int[][][][] getPat()
\r
60 public double [] getPatPow()
\r
64 public short[][][] getPatBW()
\r
68 public double[] getPatPowBW()
\r
72 public int getWidth()
\r
76 public int getHeight()
\r
81 public NyARCode(int i_width,int i_height)
\r
85 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
86 patBW=new short[4][height][width];//static int patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];
\r
89 * int arLoadPatt( const char *filename );
\r
90 * ARToolKitのパターンファイルをロードする。
\r
91 * ファイル形式はBGR形式で記録されたパターンファイルであること。
\r
96 public void loadFromARFile(String filename) throws NyARException
\r
99 loadFromARFile(new FileInputStream(filename));
\r
101 } catch (Exception e) {
\r
102 throw new NyARException(e);
\r
108 * @throws NyARException
\r
110 public void loadFromARFile(InputStream i_stream) throws NyARException
\r
113 StreamTokenizer st=new StreamTokenizer(new InputStreamReader(i_stream));
\r
114 //パターンデータはGBRAで並んでる。
\r
115 for(int h=0; h<4; h++ ) {
\r
117 for(int i3 = 0; i3 < 3; i3++ ) {
\r
118 for(int i2 = 0; i2 < height; i2++ ) {
\r
119 for(int i1 = 0; i1 < width; i1++ ){
\r
121 switch(st.nextToken()){//if( fscanf(fp, "%d", &j) != 1 ) {
\r
122 case StreamTokenizer.TT_NUMBER:
\r
125 throw new NyARException();
\r
127 short j=(short)(255-st.nval);//j = 255-j;
\r
128 //標準ファイルのパターンはBGRでならんでるからRGBに並べなおす
\r
130 case 0:pat[h][i2][i1][2] = j;break;//pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+2] = j;break;
\r
131 case 1:pat[h][i2][i1][1] = j;break;//pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+1] = j;break;
\r
132 case 2:pat[h][i2][i1][0] = j;break;//pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+0] = j;break;
\r
134 //pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+i3] = j;
\r
136 patBW[h][i2][i1] = j;//patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1] = j;
\r
138 patBW[h][i2][i1] += j;//patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1] += j;
\r
141 patBW[h][i2][i1] /= 3;//patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1] /= 3;
\r
148 l /= (height*width*3);
\r
151 for(int i = 0; i < height; i++ ) {//for( i = 0; i < AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3; i++ ) {
\r
152 for(int i2 = 0; i2 < width; i2++ ) {
\r
153 for(int i3 = 0; i3 < 3; i3++ ) {
\r
154 pat[h][i][i2][i3] -= l;
\r
155 m += (pat[h][i][i2][i3]*pat[h][i][i2][i3]);
\r
159 patpow[h] = Math.sqrt((double)m);
\r
160 if( patpow[h] == 0.0 ){
\r
161 patpow[h] = 0.0000001;
\r
165 for(int i = 0; i < height; i++ ) {
\r
166 for(int i2 = 0; i2 < width; i2++ ) {
\r
167 patBW[h][i][i2] -= l;
\r
168 m += (patBW[h][i][i2]*patBW[h][i][i2]);
\r
171 patpowBW[h] = Math.sqrt((double)m);
\r
172 if(patpowBW[h] == 0.0 ){
\r
173 patpowBW[h] = 0.0000001;
\r
176 }catch(Exception e){
\r
177 throw new NyARException(e);
\r