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
68 * NyARCameraDistortionFactorにセットする配列を指定する。要素数は4であること。
\r
69 * @param i_projection
\r
70 * NyARPerspectiveProjectionMatrixセットする配列を指定する。要素数は12であること。
\r
72 public void setValue(double[] i_factor,double[] i_projection)
\r
74 this._dist.setValue(i_factor);
\r
75 this._projection_matrix.setValue(i_projection);
\r
80 * ARToolKit標準ファイルから1個目の設定をロードする。
\r
83 * @throws NyARException
\r
85 public void loadARParamFromFile(String i_filename) throws NyARException
\r
88 loadARParam(new FileInputStream(i_filename));
\r
89 } catch (Exception e) {
\r
90 throw new NyARException(e);
\r
95 * int arParamChangeSize( ARParam *source, int xsize, int ysize, ARParam *newparam );
\r
96 * 関数の代替関数 サイズプロパティをi_xsize,i_ysizeに変更します。
\r
103 public void changeScreenSize(int i_xsize, int i_ysize)
\r
105 final double scale = (double) i_xsize / (double) (this._screen_size.w);// scale = (double)xsize / (double)(source->xsize);
\r
107 this._dist.changeScale(scale);
\r
108 this._projection_matrix.changeScale(scale);
\r
109 this._screen_size.w = i_xsize;// newparam->xsize = xsize;
\r
110 this._screen_size.h = i_ysize;// newparam->ysize = ysize;
\r
116 * int arParamLoad( const char *filename, int num, ARParam *param, ...);
\r
117 * i_streamの入力ストリームからi_num個の設定を読み込み、パラメタを配列にして返します。
\r
120 * @throws Exception
\r
122 public void loadARParam(InputStream i_stream)throws NyARException
\r
125 byte[] buf = new byte[SIZE_OF_PARAM_SET];
\r
126 i_stream.read(buf);
\r
127 double[] tmp=new double[12];
\r
130 ByteBuffer bb = ByteBuffer.wrap(buf);
\r
131 bb.order(ByteOrder.BIG_ENDIAN);
\r
132 this._screen_size.w = bb.getInt();
\r
133 this._screen_size.h = bb.getInt();
\r
135 for(int i=0;i<12;i++){
\r
136 tmp[i]=bb.getDouble();
\r
138 //Projectionオブジェクトにセット
\r
139 this._projection_matrix.setValue(tmp);
\r
141 for (int i = 0; i < 4; i++) {
\r
142 tmp[i]=bb.getDouble();
\r
145 this._dist.setValue(tmp);
\r
146 } catch (Exception e) {
\r
147 throw new NyARException(e);
\r
152 public void saveARParam(OutputStream i_stream)throws Exception
\r
154 NyARException.trap("未チェックの関数");
\r
155 byte[] buf = new byte[SIZE_OF_PARAM_SET];
\r
157 ByteBuffer bb = ByteBuffer.wrap(buf);
\r
158 bb.order(ByteOrder.BIG_ENDIAN);
\r
161 bb.putInt(this._screen_size.w);
\r
162 bb.putInt(this._screen_size.h);
\r
163 double[] tmp=new double[12];
\r
165 this._projection_matrix.getValue(tmp);
\r
167 for(int i=0;i<12;i++){
\r
168 tmp[i]=bb.getDouble();
\r
171 this._dist.getValue(tmp);
\r
173 for (int i = 0; i < 4; i++) {
\r
174 tmp[i]=bb.getDouble();
\r
176 i_stream.write(buf);
\r