OSDN Git Service

Merge branch 'git-svn'
[nyartoolkit-and/nyartoolkit-and.git] / tags / 2.4.2 / 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(double[] i_map_x,double[] i_map_y,NyARIntSize i_screen_size)\r
48         {\r
49                 \r
50         }\r
51         \r
52         public NyARFixedFloatObserv2IdealMap(NyARCameraDistortionFactor i_distfactor,NyARIntSize i_screen_size)\r
53         {\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
59                 //歪みマップを構築\r
60                 for(int i=i_screen_size.h-1;i>=0;i--)\r
61                 {\r
62                         for(int i2=i_screen_size.w-1;i2>=0;i2--)\r
63                         {\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
67                                 ptr--;\r
68                         }\r
69                 }\r
70                 i_distfactor.getValue(this._factor);\r
71                 return;\r
72         }       \r
73         /**\r
74          * 点集合のi_start~i_numまでの間から、最大i_sample_count個の頂点を取得して返します。\r
75          * i_sample_countは偶数である必要があります。\r
76          * @param i_x_coord\r
77          * @param i_y_coord\r
78          * @param i_start\r
79          * @param i_num\r
80          * @param o_x_coord\r
81          * @param o_y_coord\r
82          * @param i_sample_count\r
83          * @return\r
84          */\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
86         {\r
87                 assert(i_sample_count%2==0);\r
88         int idx;\r
89         if (i_num < i_sample_count)\r
90         {\r
91             for (int i = i_num - 1; i >= 0; i--)\r
92             {\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
96             }\r
97             return i_num;\r
98         }\r
99         else\r
100         {\r
101             //サンプリング個数分の点を、両端から半分づつ取ってくる。\r
102             int st = i_start;\r
103             int ed = i_start + i_num - 1;\r
104             for (int i = i_sample_count - 1; i >= 0; i -= 2)\r
105             {\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
112                 ed--;\r
113                 st++;\r
114             }\r
115             return i_sample_count;\r
116         }\r
117         }\r
118 }