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
33 import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
\r
36 * カメラの歪み成分を格納するクラスと、補正関数群
\r
37 * http://www.hitl.washington.edu/artoolkit/Papers/ART02-Tutorial.pdf
\r
40 * x=x(xi-x0),y=s(yi-y0)
\r
45 public class NyARCameraDistortionFactor implements INyARCameraDistortionFactor
\r
47 private static final int PD_LOOP = 3;
\r
48 private double _f0;//x0
\r
49 private double _f1;//y0
\r
50 private double _f2;//100000000.0*f
\r
51 private double _f3;//s
\r
52 public void copyFrom(NyARCameraDistortionFactor i_ref)
\r
61 * 配列の値をファクタ値としてセットする。
\r
65 public void setValue(double[] i_factor)
\r
67 this._f0=i_factor[0];
\r
68 this._f1=i_factor[1];
\r
69 this._f2=i_factor[2];
\r
70 this._f3=i_factor[3];
\r
73 public void getValue(double[] o_factor)
\r
75 o_factor[0]=this._f0;
\r
76 o_factor[1]=this._f1;
\r
77 o_factor[2]=this._f2;
\r
78 o_factor[3]=this._f3;
\r
81 public void changeScale(double i_scale)
\r
83 this._f0=this._f0*i_scale;// newparam->dist_factor[0] =source->dist_factor[0] *scale;
\r
84 this._f1=this._f1*i_scale;// newparam->dist_factor[1] =source->dist_factor[1] *scale;
\r
85 this._f2=this._f2/ (i_scale * i_scale);// newparam->dist_factor[2]=source->dist_factor[2]/ (scale*scale);
\r
86 //this.f3=this.f3;// newparam->dist_factor[3] =source->dist_factor[3];
\r
90 * int arParamIdeal2Observ( const double dist_factor[4], const double ix,const double iy,double *ox, double *oy ) 関数の代替関数
\r
95 public void ideal2Observ(final NyARDoublePoint2d i_in, NyARDoublePoint2d o_out)
\r
97 final double x = (i_in.x - this._f0) * this._f3;
\r
98 final double y = (i_in.y - this._f1) * this._f3;
\r
99 if (x == 0.0 && y == 0.0) {
\r
100 o_out.x = this._f0;
\r
101 o_out.y = this._f1;
\r
103 final double d = 1.0 - this._f2 / 100000000.0 * (x * x + y * y);
\r
104 o_out.x = x * d + this._f0;
\r
105 o_out.y = y * d + this._f1;
\r
111 * ideal2Observをまとめて実行します。
\r
115 public void ideal2ObservBatch(final NyARDoublePoint2d[] i_in, NyARDoublePoint2d[] o_out, int i_size)
\r
118 final double d0 = this._f0;
\r
119 final double d1 = this._f1;
\r
120 final double d3 = this._f3;
\r
121 final double d2_w = this._f2 / 100000000.0;
\r
122 for (int i = 0; i < i_size; i++) {
\r
123 x = (i_in[i].x - d0) * d3;
\r
124 y = (i_in[i].y - d1) * d3;
\r
125 if (x == 0.0 && y == 0.0) {
\r
129 final double d = 1.0 - d2_w * (x * x + y * y);
\r
130 o_out[i].x = x * d + d0;
\r
131 o_out[i].y = y * d + d1;
\r
138 * int arParamObserv2Ideal( const double dist_factor[4], const double ox,const double oy,double *ix, double *iy );
\r
146 public void observ2Ideal(double ix, double iy, NyARDoublePoint2d o_point)
\r
148 double z02, z0, p, q, z, px, py, opttmp_1;
\r
149 final double d0 = this._f0;
\r
150 final double d1 = this._f1;
\r
154 p = this._f2 / 100000000.0;
\r
155 z02 = px * px + py * py;
\r
156 q = z0 = Math.sqrt(z02);// Optimize//q = z0 = Math.sqrt(px*px+ py*py);
\r
158 for (int i = 1;; i++) {
\r
160 // Optimize opttmp_1
\r
161 opttmp_1 = p * z02;
\r
162 z = z0 - ((1.0 - opttmp_1) * z0 - q) / (1.0 - 3.0 * opttmp_1);
\r
170 if (i == PD_LOOP) {
\r
173 z02 = px * px + py * py;
\r
174 z0 = Math.sqrt(z02);// Optimize//z0 = Math.sqrt(px*px+ py*py);
\r
176 o_point.x = px / this._f3 + d0;
\r
177 o_point.y = py / this._f3 + d1;
\r
182 * 指定範囲のobserv2Idealをまとめて実行して、結果をo_idealに格納します。
\r
190 * 出力バッファ[i_num][2]であること。
\r
192 public void observ2IdealBatch(int[] i_x_coord, int[] i_y_coord,int i_start, int i_num, double[] o_x_coord,double[] o_y_coord)
\r
194 double z02, z0, q, z, px, py, opttmp_1;
\r
195 final double d0 = this._f0;
\r
196 final double d1 = this._f1;
\r
197 final double d3 = this._f3;
\r
198 final double p = this._f2 / 100000000.0;
\r
199 for (int j = 0; j < i_num; j++) {
\r
201 px = i_x_coord[i_start + j] - d0;
\r
202 py = i_y_coord[i_start + j] - d1;
\r
204 z02 = px * px + py * py;
\r
205 q = z0 = Math.sqrt(z02);// Optimize//q = z0 = Math.sqrt(px*px+py*py);
\r
207 for (int i = 1;; i++) {
\r
209 // Optimize opttmp_1
\r
210 opttmp_1 = p * z02;
\r
211 z = z0 - ((1.0 - opttmp_1) * z0 - q)/ (1.0 - 3.0 * opttmp_1);
\r
219 if (i == PD_LOOP) {
\r
222 z02 = px * px + py * py;
\r
223 z0 = Math.sqrt(z02);// Optimize//z0 = Math.sqrt(px*px+ py*py);
\r
225 o_x_coord[j] = px / d3 + d0;
\r
226 o_y_coord[j] = py / d3 + d1;
\r