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.param;
\r
37 import jp.nyatla.nyartoolkit.NyARException;
\r
38 import jp.nyatla.nyartoolkit.core.types.*;
\r
41 * typedef struct { int xsize, ysize; double mat[3][4]; double dist_factor[4]; } ARParam;
\r
42 * NyARの動作パラメータを格納するクラス
\r
45 public class NyARParam
\r
47 protected NyARIntSize _screen_size=new NyARIntSize();
\r
48 private static final int SIZE_OF_PARAM_SET = 4 + 4 + (3 * 4 * 8) + (4 * 8);
\r
49 private NyARCameraDistortionFactor _dist=new NyARCameraDistortionFactor();
\r
50 private NyARPerspectiveProjectionMatrix _projection_matrix=new NyARPerspectiveProjectionMatrix();
\r
52 public NyARIntSize getScreenSize()
\r
54 return this._screen_size;
\r
57 public NyARPerspectiveProjectionMatrix getPerspectiveProjectionMatrix()
\r
59 return this._projection_matrix;
\r
61 public NyARCameraDistortionFactor getDistortionFactor()
\r
67 * ARToolKit標準ファイルから1個目の設定をロードする。
\r
70 * @throws NyARException
\r
72 public void loadARParamFromFile(String i_filename) throws NyARException
\r
75 loadARParam(new FileInputStream(i_filename));
\r
76 } catch (Exception e) {
\r
77 throw new NyARException(e);
\r
82 * int arParamChangeSize( ARParam *source, int xsize, int ysize, ARParam *newparam );
\r
83 * 関数の代替関数 サイズプロパティをi_xsize,i_ysizeに変更します。
\r
90 public void changeScreenSize(int i_xsize, int i_ysize)
\r
92 final double scale = (double) i_xsize / (double) (this._screen_size.w);// scale = (double)xsize / (double)(source->xsize);
\r
94 this._dist.changeScale(scale);
\r
95 this._projection_matrix.changeScale(scale);
\r
96 //for (int i = 0; i < 4; i++) {
\r
97 // array34[0 * 4 + i] = array34[0 * 4 + i] * scale;// newparam->mat[0][i]=source->mat[0][i]* scale;
\r
98 // array34[1 * 4 + i] = array34[1 * 4 + i] * scale;// newparam->mat[1][i]=source->mat[1][i]* scale;
\r
99 // array34[2 * 4 + i] = array34[2 * 4 + i];// newparam->mat[2][i] = source->mat[2][i];
\r
103 this._screen_size.w = i_xsize;// newparam->xsize = xsize;
\r
104 this._screen_size.h = i_ysize;// newparam->ysize = ysize;
\r
110 * int arParamLoad( const char *filename, int num, ARParam *param, ...);
\r
111 * i_streamの入力ストリームからi_num個の設定を読み込み、パラメタを配列にして返します。
\r
114 * @throws Exception
\r
116 public void loadARParam(InputStream i_stream)throws NyARException
\r
119 byte[] buf = new byte[SIZE_OF_PARAM_SET];
\r
120 i_stream.read(buf);
\r
121 double[] tmp=new double[12];
\r
124 ByteBuffer bb = ByteBuffer.wrap(buf);
\r
125 bb.order(ByteOrder.BIG_ENDIAN);
\r
126 this._screen_size.w = bb.getInt();
\r
127 this._screen_size.h = bb.getInt();
\r
129 for(int i=0;i<12;i++){
\r
130 tmp[i]=bb.getDouble();
\r
132 //Projectionオブジェクトにセット
\r
133 this._projection_matrix.setValue(tmp);
\r
135 for (int i = 0; i < 4; i++) {
\r
136 tmp[i]=bb.getDouble();
\r
139 this._dist.setValue(tmp);
\r
140 } catch (Exception e) {
\r
141 throw new NyARException(e);
\r
146 public void saveARParam(OutputStream i_stream)throws Exception
\r
148 NyARException.trap("未チェックの関数");
\r
149 byte[] buf = new byte[SIZE_OF_PARAM_SET];
\r
151 ByteBuffer bb = ByteBuffer.wrap(buf);
\r
152 bb.order(ByteOrder.BIG_ENDIAN);
\r
155 bb.putInt(this._screen_size.w);
\r
156 bb.putInt(this._screen_size.h);
\r
157 double[] tmp=new double[12];
\r
159 this._projection_matrix.getValue(tmp);
\r
161 for(int i=0;i<12;i++){
\r
162 tmp[i]=bb.getDouble();
\r
165 this._dist.getValue(tmp);
\r
167 for (int i = 0; i < 4; i++) {
\r
168 tmp[i]=bb.getDouble();
\r
170 i_stream.write(buf);
\r