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 jp.nyatla.nyartoolkit.NyARException;
\r
35 import jp.nyatla.nyartoolkit.core.raster.*;
\r
38 * 24ビットカラーのマーカーを保持するために使うクラスです。
\r
39 * このクラスは、ARToolkitのパターンと、ラスタから取得したパターンを保持します。
\r
42 public class NyARColorPatt
\r
44 public static final int AR_PATT_SAMPLE_NUM=64;//#define AR_PATT_SAMPLE_NUM 64
\r
45 private short extpat[][][];
\r
48 public NyARColorPatt(int i_width,int i_height)
\r
52 extpat=new short[i_height][i_width][3];
\r
54 public short[][][] getPatArray()
\r
58 public int getWidth()
\r
62 public int getHeight()
\r
66 private static void get_cpara( double world[][], double vertex[][],double para[][] ) throws NyARException
\r
68 NyARMat a = new NyARMat( 8, 8 );
\r
69 double[][] a_array=a.getArray();
\r
70 NyARMat b = new NyARMat( 8, 1 );
\r
71 double[][] b_array=b.getArray();
\r
72 NyARMat c = new NyARMat( 8, 1 );
\r
73 double[][] c_array=c.getArray();
\r
75 for(int i = 0; i < 4; i++ ) {
\r
76 a_array[i*2][0]=world[i][0];//a->m[i*16+0] = world[i][0];
\r
77 a_array[i*2][1]=world[i][1];//a->m[i*16+1] = world[i][1];
\r
78 a_array[i*2][2]=1.0;//a->m[i*16+2] = 1.0;
\r
79 a_array[i*2][3]=0.0;//a->m[i*16+3] = 0.0;
\r
80 a_array[i*2][4]=0.0;//a->m[i*16+4] = 0.0;
\r
81 a_array[i*2][5]=0.0;//a->m[i*16+5] = 0.0;
\r
82 a_array[i*2][6]=-world[i][0] * vertex[i][0];//a->m[i*16+6] = -world[i][0] * vertex[i][0];
\r
83 a_array[i*2][7]=-world[i][1] * vertex[i][0];//a->m[i*16+7] = -world[i][1] * vertex[i][0];
\r
84 a_array[i*2+1][0]=0.0;//a->m[i*16+8] = 0.0;
\r
85 a_array[i*2+1][1]=0.0;//a->m[i*16+9] = 0.0;
\r
86 a_array[i*2+1][2]=0.0;//a->m[i*16+10] = 0.0;
\r
87 a_array[i*2+1][3]=world[i][0];//a->m[i*16+11] = world[i][0];
\r
88 a_array[i*2+1][4]=world[i][1];//a->m[i*16+12] = world[i][1];
\r
89 a_array[i*2+1][5]=1.0;//a->m[i*16+13] = 1.0;
\r
90 a_array[i*2+1][6]=-world[i][0] * vertex[i][1];//a->m[i*16+14] = -world[i][0] * vertex[i][1];
\r
91 a_array[i*2+1][7]=-world[i][1] * vertex[i][1];//a->m[i*16+15] = -world[i][1] * vertex[i][1];
\r
92 b_array[i*2+0][0]=vertex[i][0];//b->m[i*2+0] = vertex[i][0];
\r
93 b_array[i*2+1][0]=vertex[i][1];//b->m[i*2+1] = vertex[i][1];
\r
95 // JartkException.trap("未チェックのパス");
\r
98 // JartkException.trap("未チェックのパス");
\r
99 NyARMat.matrixMul( c, a, b );
\r
100 for(int i = 0; i < 2; i++ ) {
\r
101 para[i][0] = c_array[i*3+0][0];//para[i][0] = c->m[i*3+0];
\r
102 para[i][1] = c_array[i*3+1][0];//para[i][1] = c->m[i*3+1];
\r
103 para[i][2] = c_array[i*3+2][0];//para[i][2] = c->m[i*3+2];
\r
105 para[2][0] = c_array[2*3+0][0];//para[2][0] = c->m[2*3+0];
\r
106 para[2][1] = c_array[2*3+1][0];//para[2][1] = c->m[2*3+1];
\r
107 para[2][2] = 1.0;//para[2][2] = 1.0;
\r
110 * imageから、i_markerの位置にあるパターンを切り出して、保持します。
\r
113 * @throws Exception
\r
115 public void pickFromRaster(NyARRaster image, NyARMarker i_marker) throws NyARException
\r
117 int[] x_coord=i_marker.x_coord;
\r
118 int[] y_coord=i_marker.y_coord;
\r
119 int[] vertex=i_marker.vertex;
\r
120 int[][][] ext_pat2=new int[height][width][3];//ARUint32 ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];
\r
121 double[][] world=new double[4][2];//double world[4][2];
\r
122 double[][] local=new double[4][2];//double local[4][2];
\r
123 double[][] para=new double[3][3]; //double para[3][3];
\r
128 int lx1, lx2, ly1, ly2;
\r
131 img_x=image.getWidth();
\r
132 img_y=image.getHeight();
\r
134 double xdiv2_reciprocal; // [tp]
\r
135 double ydiv2_reciprocal; // [tp]
\r
136 int ext_pat2_x_index;
\r
137 int ext_pat2_y_index;
\r
139 world[0][0] = 100.0;
\r
140 world[0][1] = 100.0;
\r
141 world[1][0] = 100.0 + 10.0;
\r
142 world[1][1] = 100.0;
\r
143 world[2][0] = 100.0 + 10.0;
\r
144 world[2][1] = 100.0 + 10.0;
\r
145 world[3][0] = 100.0;
\r
146 world[3][1] = 100.0 + 10.0;
\r
147 for(int i = 0; i < 4; i++ ) {
\r
148 local[i][0] = x_coord[vertex[i]];
\r
149 local[i][1] = y_coord[vertex[i]];
\r
151 get_cpara( world, local, para );
\r
153 lx1 = (int)((local[0][0] - local[1][0])*(local[0][0] - local[1][0])+ (local[0][1] - local[1][1])*(local[0][1] - local[1][1]));
\r
154 lx2 = (int)((local[2][0] - local[3][0])*(local[2][0] - local[3][0])+ (local[2][1] - local[3][1])*(local[2][1] - local[3][1]));
\r
155 ly1 = (int)((local[1][0] - local[2][0])*(local[1][0] - local[2][0])+ (local[1][1] - local[2][1])*(local[1][1] - local[2][1]));
\r
156 ly2 = (int)((local[3][0] - local[0][0])*(local[3][0] - local[0][0])+ (local[3][1] - local[0][1])*(local[3][1] - local[0][1]));
\r
166 while( xdiv2*xdiv2 < lx1/4 ){
\r
169 while( ydiv2*ydiv2 < ly1/4 ){
\r
173 if( xdiv2 > AR_PATT_SAMPLE_NUM)
\r
175 xdiv2 =AR_PATT_SAMPLE_NUM;
\r
177 if( ydiv2 >AR_PATT_SAMPLE_NUM)
\r
179 ydiv2 = AR_PATT_SAMPLE_NUM;
\r
182 xdiv = xdiv2/width;//xdiv = xdiv2/Config.AR_PATT_SIZE_X;
\r
183 ydiv = ydiv2/height;//ydiv = ydiv2/Config.AR_PATT_SIZE_Y;
\r
185 printf("%3d(%f), %3d(%f)\n", xdiv2, sqrt(lx1), ydiv2, sqrt(ly1));
\r
188 xdiv2_reciprocal = 1.0 / xdiv2;
\r
189 ydiv2_reciprocal = 1.0 / ydiv2;
\r
190 int[] rgb_tmp=new int[3];
\r
191 // arGetCode_put_zero(ext_pat2);//put_zero( (ARUint8 *)ext_pat2, AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3*sizeof(ARUint32) );
\r
192 for(int j = 0; j < ydiv2; j++ ) {
\r
193 yw = 102.5 + 5.0 * (j+0.5) * ydiv2_reciprocal;
\r
194 for(int i = 0; i < xdiv2; i++ ) {
\r
195 xw = 102.5 + 5.0 * (i+0.5) * xdiv2_reciprocal;
\r
196 d = para[2][0]*xw + para[2][1]*yw + para[2][2];
\r
198 throw new NyARException();
\r
200 xc = (int)((para[0][0]*xw + para[0][1]*yw + para[0][2])/d);
\r
201 yc = (int)((para[1][0]*xw + para[1][1]*yw + para[1][2])/d);
\r
204 if( xc >= 0 && xc < img_x && yc >= 0 && yc < img_y ) {
\r
205 ext_pat2_y_index = j/ydiv;
\r
206 ext_pat2_x_index = i/xdiv;
\r
207 // image_index = (yc*arUtil_c.arImXsize+xc)*Config.AR_PIX_SIZE_DEFAULT;
\r
208 image.pickRgbArray(xc, yc, rgb_tmp);
\r
210 ext_pat2[ext_pat2_y_index][ext_pat2_x_index][0] += rgb_tmp[0];//R
\r
211 ext_pat2[ext_pat2_y_index][ext_pat2_x_index][1] += rgb_tmp[1];//G
\r
212 ext_pat2[ext_pat2_y_index][ext_pat2_x_index][2] += rgb_tmp[2];//B
\r
213 // System.out.println(xc+":"+yc+":"+rgb_tmp[0]+":"+rgb_tmp[1]+":"+rgb_tmp[2]);
\r
217 // short[][][] ext_pat=new short[Config.AR_PATT_SIZE_Y][Config.AR_PATT_SIZE_X][3];//ARUint32 ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];
\r
219 for(int j = 0; j < height; j++ ) {
\r
220 for(int i = 0; i < width; i++ ) { // PRL 2006-06-08.
\r
221 extpat[j][i][0]=(short)(ext_pat2[j][i][0] / (xdiv*ydiv));//ext_pat[j][i][0] = (byte)(ext_pat2[j][i][0] / (xdiv*ydiv));
\r
222 extpat[j][i][1]=(short)(ext_pat2[j][i][1] / (xdiv*ydiv));//ext_pat[j][i][1] = (byte)(ext_pat2[j][i][1] / (xdiv*ydiv));
\r
223 extpat[j][i][2]=(short)(ext_pat2[j][i][2] / (xdiv*ydiv));//ext_pat[j][i][2] = (byte)(ext_pat2[j][i][2] / (xdiv*ydiv));
\r