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.sandbox.x2;
\r
34 import jp.nyatla.nyartoolkit.core.types.*;
\r
35 import jp.nyatla.nyartoolkit.core.param.*;
\r
37 * 歪み成分マップを使用するINyARCameraDistortionFactor
\r
38 * 内部マップをint(1:15:16)フォーマットの固定小数点で保持する。
\r
39 * 固定小数点で値を提供するインタフェイスを持ちます。
\r
41 final public class NyARFixedFloatObserv2IdealMap
\r
43 private double[] _factor=new double[4];
\r
44 private int _stride;
\r
45 private int[] _mapx;
\r
46 private int[] _mapy;
\r
47 public NyARFixedFloatObserv2IdealMap(double[] i_map_x,double[] i_map_y,NyARIntSize i_screen_size)
\r
52 public NyARFixedFloatObserv2IdealMap(NyARCameraDistortionFactor i_distfactor,NyARIntSize i_screen_size)
\r
54 NyARDoublePoint2d opoint=new NyARDoublePoint2d();
\r
55 this._mapx=new int[i_screen_size.w*i_screen_size.h];
\r
56 this._mapy=new int[i_screen_size.w*i_screen_size.h];
\r
57 this._stride=i_screen_size.w;
\r
58 int ptr=i_screen_size.h*i_screen_size.w-1;
\r
60 for(int i=i_screen_size.h-1;i>=0;i--)
\r
62 for(int i2=i_screen_size.w-1;i2>=0;i2--)
\r
64 i_distfactor.observ2Ideal(i2,i,opoint);
\r
65 this._mapx[ptr]=(int)(opoint.x*65536);
\r
66 this._mapy[ptr]=(int)(opoint.y*65536);
\r
70 i_distfactor.getValue(this._factor);
\r
74 * 点集合のi_start~i_numまでの間から、最大i_sample_count個の頂点を取得して返します。
\r
75 * i_sample_countは偶数である必要があります。
\r
82 * @param i_sample_count
\r
85 public int observ2IdealSampling(int[] i_x_coord, int[] i_y_coord,int i_start, int i_num, int[] o_x_coord,int[] o_y_coord,int i_sample_count)
\r
87 assert(i_sample_count%2==0);
\r
89 if (i_num < i_sample_count)
\r
91 for (int i = i_num - 1; i >= 0; i--)
\r
93 idx = i_x_coord[i_start + i] + i_y_coord[i_start + i] * this._stride;
\r
94 o_x_coord[i] = this._mapx[idx];
\r
95 o_y_coord[i] = this._mapy[idx];
\r
101 //サンプリング個数分の点を、両端から半分づつ取ってくる。
\r
103 int ed = i_start + i_num - 1;
\r
104 for (int i = i_sample_count - 1; i >= 0; i -= 2)
\r
106 idx = i_x_coord[st] + i_y_coord[st] * this._stride;
\r
107 o_x_coord[i] = this._mapx[idx];
\r
108 o_y_coord[i] = this._mapy[idx];
\r
109 idx = i_x_coord[ed] + i_y_coord[ed] * this._stride;
\r
110 o_x_coord[i - 1] = this._mapx[idx];
\r
111 o_y_coord[i - 1] = this._mapy[idx];
\r
115 return i_sample_count;
\r