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
34 import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
\r
37 * カメラの歪み成分を格納するクラスと、補正関数群
\r
38 * http://www.hitl.washington.edu/artoolkit/Papers/ART02-Tutorial.pdf
\r
41 * x=x(xi-x0),y=s(yi-y0)
\r
46 public class NyARCameraDistortionFactor implements INyARCameraDistortionFactor
\r
48 private static final int PD_LOOP = 3;
\r
49 private double _f0;//x0
\r
50 private double _f1;//y0
\r
51 private double _f2;//100000000.0*f
\r
52 private double _f3;//s
\r
53 public void copyFrom(NyARCameraDistortionFactor i_ref)
\r
62 * 配列の値をファクタ値としてセットする。
\r
66 public void setValue(double[] i_factor)
\r
68 this._f0=i_factor[0];
\r
69 this._f1=i_factor[1];
\r
70 this._f2=i_factor[2];
\r
71 this._f3=i_factor[3];
\r
74 public void getValue(double[] o_factor)
\r
76 o_factor[0]=this._f0;
\r
77 o_factor[1]=this._f1;
\r
78 o_factor[2]=this._f2;
\r
79 o_factor[3]=this._f3;
\r
82 public void changeScale(double i_scale)
\r
84 this._f0=this._f0*i_scale;// newparam->dist_factor[0] =source->dist_factor[0] *scale;
\r
85 this._f1=this._f1*i_scale;// newparam->dist_factor[1] =source->dist_factor[1] *scale;
\r
86 this._f2=this._f2/ (i_scale * i_scale);// newparam->dist_factor[2]=source->dist_factor[2]/ (scale*scale);
\r
87 //this.f3=this.f3;// newparam->dist_factor[3] =source->dist_factor[3];
\r
91 * int arParamIdeal2Observ( const double dist_factor[4], const double ix,const double iy,double *ox, double *oy ) 関数の代替関数
\r
96 public void ideal2Observ(final NyARDoublePoint2d i_in, NyARDoublePoint2d o_out)
\r
98 final double x = (i_in.x - this._f0) * this._f3;
\r
99 final double y = (i_in.y - this._f1) * this._f3;
\r
100 if (x == 0.0 && y == 0.0) {
\r
101 o_out.x = this._f0;
\r
102 o_out.y = this._f1;
\r
104 final double d = 1.0 - this._f2 / 100000000.0 * (x * x + y * y);
\r
105 o_out.x = x * d + this._f0;
\r
106 o_out.y = y * d + this._f1;
\r
112 * ideal2Observをまとめて実行します。
\r
116 public void ideal2ObservBatch(final NyARDoublePoint2d[] i_in, NyARDoublePoint2d[] o_out, int i_size)
\r
119 final double d0 = this._f0;
\r
120 final double d1 = this._f1;
\r
121 final double d3 = this._f3;
\r
122 final double d2_w = this._f2 / 100000000.0;
\r
123 for (int i = 0; i < i_size; i++) {
\r
124 x = (i_in[i].x - d0) * d3;
\r
125 y = (i_in[i].y - d1) * d3;
\r
126 if (x == 0.0 && y == 0.0) {
\r
130 final double d = 1.0 - d2_w * (x * x + y * y);
\r
131 o_out[i].x = x * d + d0;
\r
132 o_out[i].y = y * d + d1;
\r
139 * int arParamObserv2Ideal( const double dist_factor[4], const double ox,const double oy,double *ix, double *iy );
\r
147 public void observ2Ideal(double ix, double iy, NyARDoublePoint2d o_point)
\r
149 double z02, z0, p, q, z, px, py, opttmp_1;
\r
150 final double d0 = this._f0;
\r
151 final double d1 = this._f1;
\r
155 p = this._f2 / 100000000.0;
\r
156 z02 = px * px + py * py;
\r
157 q = z0 = Math.sqrt(z02);// Optimize//q = z0 = Math.sqrt(px*px+ py*py);
\r
159 for (int i = 1;; i++) {
\r
161 // Optimize opttmp_1
\r
162 opttmp_1 = p * z02;
\r
163 z = z0 - ((1.0 - opttmp_1) * z0 - q) / (1.0 - 3.0 * opttmp_1);
\r
171 if (i == PD_LOOP) {
\r
174 z02 = px * px + py * py;
\r
175 z0 = Math.sqrt(z02);// Optimize//z0 = Math.sqrt(px*px+ py*py);
\r
177 o_point.x = px / this._f3 + d0;
\r
178 o_point.y = py / this._f3 + d1;
\r
183 * 指定範囲のobserv2Idealをまとめて実行して、結果をo_idealに格納します。
\r
191 * 出力バッファ[i_num][2]であること。
\r
193 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
195 double z02, z0, q, z, px, py, opttmp_1;
\r
196 final double d0 = this._f0;
\r
197 final double d1 = this._f1;
\r
198 final double d3 = this._f3;
\r
199 final double p = this._f2 / 100000000.0;
\r
200 for (int j = 0; j < i_num; j++) {
\r
202 px = i_x_coord[i_start + j] - d0;
\r
203 py = i_y_coord[i_start + j] - d1;
\r
205 z02 = px * px + py * py;
\r
206 q = z0 = Math.sqrt(z02);// Optimize//q = z0 = Math.sqrt(px*px+py*py);
\r
208 for (int i = 1;; i++) {
\r
210 // Optimize opttmp_1
\r
211 opttmp_1 = p * z02;
\r
212 z = z0 - ((1.0 - opttmp_1) * z0 - q)/ (1.0 - 3.0 * opttmp_1);
\r
220 if (i == PD_LOOP) {
\r
223 z02 = px * px + py * py;
\r
224 z0 = Math.sqrt(z02);// Optimize//z0 = Math.sqrt(px*px+ py*py);
\r
226 o_x_coord[j] = px / d3 + d0;
\r
227 o_y_coord[j] = py / d3 + d1;
\r