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 * このクラスは、NyARToolkitの環境パラメータを格納します。
\r
42 * 環境パラメータは、ARToolKitのパラメータと同一です。
\r
43 * パラメータの要素には、以下のものがあります。
\r
45 * <li>樽型歪みパラメータ - 入力画像の樽型歪みパラメータです。
\r
46 * <li>スクリーンサイズ - 入力画像の解像度です。
\r
47 * <li>透視変換パラメータ - 4x4行列です。
\r
50 public class NyARParam
\r
53 protected NyARIntSize _screen_size=new NyARIntSize();
\r
54 private static final int SIZE_OF_PARAM_SET = 4 + 4 + (3 * 4 * 8) + (4 * 8);
\r
55 private NyARCameraDistortionFactor _dist=new NyARCameraDistortionFactor();
\r
56 private NyARPerspectiveProjectionMatrix _projection_matrix=new NyARPerspectiveProjectionMatrix();
\r
58 public NyARIntSize getScreenSize()
\r
60 return this._screen_size;
\r
64 * この関数は、ARToolKit形式の透視変換行列を返します。
\r
66 * [read only]透視変換行列を返します。
\r
68 public NyARPerspectiveProjectionMatrix getPerspectiveProjectionMatrix()
\r
70 return this._projection_matrix;
\r
73 * この関数は、ARToolKit形式の歪み補正パラメータを返します。
\r
75 * [read only]歪み補正パラメータオブジェクト
\r
77 public NyARCameraDistortionFactor getDistortionFactor()
\r
82 * この関数は、配列から値を設定します。
\r
84 * NyARCameraDistortionFactorにセットする配列を指定する。要素数は4であること。
\r
85 * @param i_projection
\r
86 * NyARPerspectiveProjectionMatrixセットする配列を指定する。要素数は12であること。
\r
88 public void setValue(double[] i_factor,double[] i_projection)
\r
90 this._dist.setValue(i_factor);
\r
91 this._projection_matrix.setValue(i_projection);
\r
95 * この関数は、現在のスクリーンサイズを変更します。
\r
96 * ARToolKitのarParamChangeSize関数に相当します。
\r
102 public void changeScreenSize(int i_xsize, int i_ysize)
\r
104 final double scale = (double) i_xsize / (double) (this._screen_size.w);// scale = (double)xsize / (double)(source->xsize);
\r
106 this._dist.changeScale(scale);
\r
107 this._projection_matrix.changeScale(scale);
\r
108 this._screen_size.w = i_xsize;// newparam->xsize = xsize;
\r
109 this._screen_size.h = i_ysize;// newparam->ysize = ysize;
\r
113 * この関数は、カメラパラメータから右手系の視錐台を作ります。
\r
115 * この処理は低速です。繰り返しの使用はできるだけ避けてください。
\r
117 * @param i_dist_min
\r
118 * 視錐台のnear point(mm指定)
\r
119 * @param i_dist_max
\r
120 * 視錐台のfar point(mm指定)
\r
123 * @see NyARPerspectiveProjectionMatrix#makeCameraFrustumRH
\r
125 public void makeCameraFrustumRH(double i_dist_min,double i_dist_max,NyARDoubleMatrix44 o_frustum)
\r
127 this._projection_matrix.makeCameraFrustumRH(this._screen_size.w, this._screen_size.h, i_dist_min, i_dist_max, o_frustum);
\r
132 * この関数は、ARToolKit形式のカメラパラメータファイルから、1個目の設定をロードします。
\r
133 * @param i_filename
\r
135 * @throws NyARException
\r
137 public void loadARParamFromFile(String i_filename) throws NyARException
\r
140 loadARParam(new FileInputStream(i_filename));
\r
141 } catch (Exception e) {
\r
142 throw new NyARException(e);
\r
150 * この関数は、ストリームからARToolKit形式のカメラパラメーを1個目の設定をロードします。
\r
153 * @throws Exception
\r
155 public void loadARParam(InputStream i_stream)throws NyARException
\r
158 byte[] buf = new byte[SIZE_OF_PARAM_SET];
\r
159 i_stream.read(buf);
\r
160 double[] tmp=new double[16];
\r
163 ByteBuffer bb = ByteBuffer.wrap(buf);
\r
164 bb.order(ByteOrder.BIG_ENDIAN);
\r
165 this._screen_size.w = bb.getInt();
\r
166 this._screen_size.h = bb.getInt();
\r
168 for(int i=0;i<12;i++){
\r
169 tmp[i]=bb.getDouble();
\r
172 tmp[12]=tmp[13]=tmp[14]=0;
\r
174 //Projectionオブジェクトにセット
\r
175 this._projection_matrix.setValue(tmp);
\r
177 for (int i = 0; i < 4; i++) {
\r
178 tmp[i]=bb.getDouble();
\r
181 this._dist.setValue(tmp);
\r
182 } catch (Exception e) {
\r
183 throw new NyARException(e);
\r
191 * @throws Exception
\r
193 public void saveARParam(OutputStream i_stream)throws Exception
\r
195 NyARException.trap("未チェックの関数");
\r
196 byte[] buf = new byte[SIZE_OF_PARAM_SET];
\r
198 ByteBuffer bb = ByteBuffer.wrap(buf);
\r
199 bb.order(ByteOrder.BIG_ENDIAN);
\r
202 bb.putInt(this._screen_size.w);
\r
203 bb.putInt(this._screen_size.h);
\r
204 double[] tmp=new double[12];
\r
206 this._projection_matrix.getValue(tmp);
\r
208 for(int i=0;i<12;i++){
\r
209 tmp[i]=bb.getDouble();
\r
212 this._dist.getValue(tmp);
\r
214 for (int i = 0; i < 4; i++) {
\r
215 tmp[i]=bb.getDouble();
\r
217 i_stream.write(buf);
\r