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 modify
\r
14 * it under the terms of the GNU General Public License as published by
\r
15 * the Free Software Foundation, either version 3 of the License, or
\r
16 * (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 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.param;
\r
36 import jp.nyatla.nyartoolkit.NyARException;
\r
37 import jp.nyatla.nyartoolkit.core.types.*;
\r
38 import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix44;
\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
58 * ARToolKit形式の透視変換行列を返します。
\r
61 public NyARPerspectiveProjectionMatrix getPerspectiveProjectionMatrix()
\r
63 return this._projection_matrix;
\r
66 * ARToolKit形式の歪み補正パラメータを返します。
\r
69 public NyARCameraDistortionFactor getDistortionFactor()
\r
76 * NyARCameraDistortionFactorにセットする配列を指定する。要素数は4であること。
\r
77 * @param i_projection
\r
78 * NyARPerspectiveProjectionMatrixセットする配列を指定する。要素数は12であること。
\r
80 public void setValue(double[] i_factor,double[] i_projection)
\r
82 this._dist.setValue(i_factor);
\r
83 this._projection_matrix.setValue(i_projection);
\r
88 * ARToolKit標準ファイルから1個目の設定をロードする。
\r
91 * @throws NyARException
\r
93 public void loadARParamFromFile(String i_filename) throws NyARException
\r
96 loadARParam(new FileInputStream(i_filename));
\r
97 } catch (Exception e) {
\r
98 throw new NyARException(e);
\r
103 * int arParamChangeSize( ARParam *source, int xsize, int ysize, ARParam *newparam );
\r
104 * 関数の代替関数 サイズプロパティをi_xsize,i_ysizeに変更します。
\r
111 public void changeScreenSize(int i_xsize, int i_ysize)
\r
113 final double scale = (double) i_xsize / (double) (this._screen_size.w);// scale = (double)xsize / (double)(source->xsize);
\r
115 this._dist.changeScale(scale);
\r
116 this._projection_matrix.changeScale(scale);
\r
117 this._screen_size.w = i_xsize;// newparam->xsize = xsize;
\r
118 this._screen_size.h = i_ysize;// newparam->ysize = ysize;
\r
123 * 計算結果を多用するときは、キャッシュするようにして下さい。
\r
124 * @param i_dist_min
\r
125 * @param i_dist_max
\r
128 public void makeCameraFrustumRH(double i_dist_min,double i_dist_max,NyARDoubleMatrix44 o_frustum)
\r
130 this._projection_matrix.makeCameraFrustumRH(this._screen_size.w, this._screen_size.h, i_dist_min, i_dist_max, o_frustum);
\r
136 * int arParamLoad( const char *filename, int num, ARParam *param, ...);
\r
137 * i_streamの入力ストリームからi_num個の設定を読み込み、パラメタを配列にして返します。
\r
140 * @throws Exception
\r
142 public void loadARParam(InputStream i_stream)throws NyARException
\r
145 byte[] buf = new byte[SIZE_OF_PARAM_SET];
\r
146 i_stream.read(buf);
\r
147 double[] tmp=new double[16];
\r
150 ByteBuffer bb = ByteBuffer.wrap(buf);
\r
151 bb.order(ByteOrder.BIG_ENDIAN);
\r
152 this._screen_size.w = bb.getInt();
\r
153 this._screen_size.h = bb.getInt();
\r
155 for(int i=0;i<12;i++){
\r
156 tmp[i]=bb.getDouble();
\r
159 tmp[12]=tmp[13]=tmp[14]=0;
\r
161 //Projectionオブジェクトにセット
\r
162 this._projection_matrix.setValue(tmp);
\r
164 for (int i = 0; i < 4; i++) {
\r
165 tmp[i]=bb.getDouble();
\r
168 this._dist.setValue(tmp);
\r
169 } catch (Exception e) {
\r
170 throw new NyARException(e);
\r
175 public void saveARParam(OutputStream i_stream)throws Exception
\r
177 NyARException.trap("未チェックの関数");
\r
178 byte[] buf = new byte[SIZE_OF_PARAM_SET];
\r
180 ByteBuffer bb = ByteBuffer.wrap(buf);
\r
181 bb.order(ByteOrder.BIG_ENDIAN);
\r
184 bb.putInt(this._screen_size.w);
\r
185 bb.putInt(this._screen_size.h);
\r
186 double[] tmp=new double[12];
\r
188 this._projection_matrix.getValue(tmp);
\r
190 for(int i=0;i<12;i++){
\r
191 tmp[i]=bb.getDouble();
\r
194 this._dist.getValue(tmp);
\r
196 for (int i = 0; i < 4; i++) {
\r
197 tmp[i]=bb.getDouble();
\r
199 i_stream.write(buf);
\r