OSDN Git Service

195f318170c7edf82eca9bb3ae6bac779784436c
[nyartoolkit-and/nyartoolkit-and.git] / trunk / sample / sandbox / jp / nyatla / nyartoolkit / sandbox / x2 / NyARFixedFloatObserv2IdealMap.java
1 /* \r
2  * PROJECT: NyARToolkit\r
3  * --------------------------------------------------------------------------------\r
4  * This work is based on the original ARToolKit developed by\r
5  *   Hirokazu Kato\r
6  *   Mark Billinghurst\r
7  *   HITLab, University of Washington, Seattle\r
8  * http://www.hitl.washington.edu/artoolkit/\r
9  *\r
10  * The NyARToolkit is Java version ARToolkit class library.\r
11  * Copyright (C)2008 R.Iizuka\r
12  *\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
17  * \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
22  * \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
26  * \r
27  * For further information please contact.\r
28  *      http://nyatla.jp/nyatoolkit/\r
29  *      <airmail(at)ebony.plala.or.jp>\r
30  * \r
31  */\r
32 package jp.nyatla.nyartoolkit.sandbox.x2;\r
33 \r
34 import jp.nyatla.nyartoolkit.core.types.*;\r
35 import jp.nyatla.nyartoolkit.core.param.*;\r
36 /**\r
37  * 歪み成分マップを使用するINyARCameraDistortionFactor\r
38  * 内部マップをint(1:15:16)フォーマットの固定小数点で保持する。\r
39  * 固定小数点で値を提供するインタフェイスを持ちます。\r
40  */\r
41 final public class NyARFixedFloatObserv2IdealMap\r
42 {\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(NyARCameraDistortionFactor i_distfactor,NyARIntSize i_screen_size)\r
48         {\r
49                 NyARDoublePoint2d opoint=new NyARDoublePoint2d();\r
50                 this._mapx=new int[i_screen_size.w*i_screen_size.h];\r
51                 this._mapy=new int[i_screen_size.w*i_screen_size.h];\r
52                 this._stride=i_screen_size.w;\r
53                 int ptr=i_screen_size.h*i_screen_size.w-1;\r
54                 //歪みマップを構築\r
55                 for(int i=i_screen_size.h-1;i>=0;i--)\r
56                 {\r
57                         for(int i2=i_screen_size.w-1;i2>=0;i2--)\r
58                         {\r
59                                 i_distfactor.observ2Ideal(i2,i,opoint);\r
60                                 this._mapx[ptr]=(int)(opoint.x*65536);\r
61                                 this._mapy[ptr]=(int)(opoint.y*65536);\r
62                                 ptr--;\r
63                         }\r
64                 }\r
65                 i_distfactor.getValue(this._factor);\r
66                 return;\r
67         }       \r
68         /**\r
69          * 点集合のi_start~i_numまでの間から、最大i_sample_count個の頂点を取得して返します。\r
70          * i_sample_countは偶数である必要があります。\r
71          * @param i_x_coord\r
72          * @param i_y_coord\r
73          * @param i_start\r
74          * @param i_num\r
75          * @param o_x_coord\r
76          * @param o_y_coord\r
77          * @param i_sample_count\r
78          * @return\r
79          */\r
80         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
81         {\r
82                 assert(i_sample_count%2==0);\r
83         int idx;\r
84         if (i_num < i_sample_count)\r
85         {\r
86             for (int i = i_num - 1; i >= 0; i--)\r
87             {\r
88                 idx = i_x_coord[i_start + i] + i_y_coord[i_start + i] * this._stride;\r
89                 o_x_coord[i] = this._mapx[idx];\r
90                 o_y_coord[i] = this._mapy[idx];\r
91             }\r
92             return i_num;\r
93         }\r
94         else\r
95         {\r
96             //サンプリング個数分の点を、両端から半分づつ取ってくる。\r
97             int st = i_start;\r
98             int ed = i_start + i_num - 1;\r
99             for (int i = i_sample_count - 1; i >= 0; i -= 2)\r
100             {\r
101                 idx = i_x_coord[st] + i_y_coord[st] * this._stride;\r
102                 o_x_coord[i] = this._mapx[idx];\r
103                 o_y_coord[i] = this._mapy[idx];\r
104                 idx = i_x_coord[ed] + i_y_coord[ed] * this._stride;\r
105                 o_x_coord[i - 1] = this._mapx[idx];\r
106                 o_y_coord[i - 1] = this._mapy[idx];\r
107                 ed--;\r
108                 st++;\r
109             }\r
110             return i_sample_count;\r
111         }\r
112         }\r
113 }