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 final public class NyARCameraDistortionFactor
\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
54 * 配列の値をファクタ値としてセットする。
\r
58 public void setValue(double[] i_factor)
\r
60 this._f0=i_factor[0];
\r
61 this._f1=i_factor[1];
\r
62 this._f2=i_factor[2];
\r
63 this._f3=i_factor[3];
\r
66 public void getValue(double[] o_factor)
\r
68 o_factor[0]=this._f0;
\r
69 o_factor[1]=this._f1;
\r
70 o_factor[2]=this._f2;
\r
71 o_factor[3]=this._f3;
\r
74 public void changeScale(double i_scale)
\r
76 this._f0=this._f0*i_scale;// newparam->dist_factor[0] =source->dist_factor[0] *scale;
\r
77 this._f1=this._f1*i_scale;// newparam->dist_factor[1] =source->dist_factor[1] *scale;
\r
78 this._f2=this._f2/ (i_scale * i_scale);// newparam->dist_factor[2]=source->dist_factor[2]/ (scale*scale);
\r
79 //this.f3=this.f3;// newparam->dist_factor[3] =source->dist_factor[3];
\r
83 * int arParamIdeal2Observ( const double dist_factor[4], const double ix,const double iy,double *ox, double *oy ) 関数の代替関数
\r
88 public void ideal2Observ(final NyARDoublePoint2d i_in, NyARDoublePoint2d o_out)
\r
90 final double x = (i_in.x - this._f0) * this._f3;
\r
91 final double y = (i_in.y - this._f1) * this._f3;
\r
92 if (x == 0.0 && y == 0.0) {
\r
96 final double d = 1.0 - this._f2 / 100000000.0 * (x * x + y * y);
\r
97 o_out.x = x * d + this._f0;
\r
98 o_out.y = y * d + this._f1;
\r
104 * ideal2Observをまとめて実行します。
\r
108 public void ideal2ObservBatch(final NyARDoublePoint2d[] i_in, NyARDoublePoint2d[] o_out, int i_size)
\r
111 final double d0 = this._f0;
\r
112 final double d1 = this._f1;
\r
113 final double d3 = this._f3;
\r
114 final double d2_w = this._f2 / 100000000.0;
\r
115 for (int i = 0; i < i_size; i++) {
\r
116 x = (i_in[i].x - d0) * d3;
\r
117 y = (i_in[i].y - d1) * d3;
\r
118 if (x == 0.0 && y == 0.0) {
\r
122 final double d = 1.0 - d2_w * (x * x + y * y);
\r
123 o_out[i].x = x * d + d0;
\r
124 o_out[i].y = y * d + d1;
\r
131 * int arParamObserv2Ideal( const double dist_factor[4], const double ox,const double oy,double *ix, double *iy );
\r
139 public void observ2Ideal(double ix, double iy, NyARDoublePoint2d o_point)
\r
141 double z02, z0, p, q, z, px, py, opttmp_1;
\r
142 final double d0 = this._f0;
\r
143 final double d1 = this._f1;
\r
147 p = this._f2 / 100000000.0;
\r
148 z02 = px * px + py * py;
\r
149 q = z0 = Math.sqrt(z02);// Optimize//q = z0 = Math.sqrt(px*px+ py*py);
\r
151 for (int i = 1;; i++) {
\r
153 // Optimize opttmp_1
\r
154 opttmp_1 = p * z02;
\r
155 z = z0 - ((1.0 - opttmp_1) * z0 - q) / (1.0 - 3.0 * opttmp_1);
\r
163 if (i == PD_LOOP) {
\r
166 z02 = px * px + py * py;
\r
167 z0 = Math.sqrt(z02);// Optimize//z0 = Math.sqrt(px*px+ py*py);
\r
169 o_point.x = px / this._f3 + d0;
\r
170 o_point.y = py / this._f3 + d1;
\r
175 * 指定範囲のobserv2Idealをまとめて実行して、結果をo_idealに格納します。
\r
184 * 出力バッファ[i_num][2]であること。
\r
186 public void observ2IdealBatch(int[] i_x_coord, int[] i_y_coord,int i_start, int i_num, double[][] o_ideal)
\r
188 double z02, z0, q, z, px, py, opttmp_1;
\r
189 final double d0 = this._f0;
\r
190 final double d1 = this._f1;
\r
191 final double d3 = this._f3;
\r
192 final double p = this._f2 / 100000000.0;
\r
193 for (int j = 0; j < i_num; j++) {
\r
195 px = i_x_coord[i_start + j] - d0;
\r
196 py = i_y_coord[i_start + j] - d1;
\r
198 z02 = px * px + py * py;
\r
199 q = z0 = Math.sqrt(z02);// Optimize//q = z0 = Math.sqrt(px*px+py*py);
\r
201 for (int i = 1;; i++) {
\r
203 // Optimize opttmp_1
\r
204 opttmp_1 = p * z02;
\r
205 z = z0 - ((1.0 - opttmp_1) * z0 - q)/ (1.0 - 3.0 * opttmp_1);
\r
213 if (i == PD_LOOP) {
\r
216 z02 = px * px + py * py;
\r
217 z0 = Math.sqrt(z02);// Optimize//z0 = Math.sqrt(px*px+ py*py);
\r
219 o_ideal[j][0] = px / d3 + d0;
\r
220 o_ideal[j][1] = py / d3 + d1;
\r
224 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
226 double z02, z0, q, z, px, py, opttmp_1;
\r
227 final double d0 = this._f0;
\r
228 final double d1 = this._f1;
\r
229 final double d3 = this._f3;
\r
230 final double p = this._f2 / 100000000.0;
\r
231 for (int j = 0; j < i_num; j++) {
\r
233 px = i_x_coord[i_start + j] - d0;
\r
234 py = i_y_coord[i_start + j] - d1;
\r
236 z02 = px * px + py * py;
\r
237 q = z0 = Math.sqrt(z02);// Optimize//q = z0 = Math.sqrt(px*px+py*py);
\r
239 for (int i = 1;; i++) {
\r
241 // Optimize opttmp_1
\r
242 opttmp_1 = p * z02;
\r
243 z = z0 - ((1.0 - opttmp_1) * z0 - q)/ (1.0 - 3.0 * opttmp_1);
\r
251 if (i == PD_LOOP) {
\r
254 z02 = px * px + py * py;
\r
255 z0 = Math.sqrt(z02);// Optimize//z0 = Math.sqrt(px*px+ py*py);
\r
257 o_x_coord[j] = px / d3 + d0;
\r
258 o_y_coord[j] = py / d3 + d1;
\r