OSDN Git Service

c4c06e8bbf2a70a074e26e2008fc4f3b6e04930c
[nyartoolkit-and/nyartoolkit-and.git] / trunk / src / jp / nyatla / nyartoolkit / core / param / NyARObserv2IdealMap.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.core.param;\r
33 \r
34 import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;\r
35 import jp.nyatla.nyartoolkit.core.types.*;\r
36 /**\r
37  * 歪み成分マップを使用するINyARCameraDistortionFactor\r
38  */\r
39 final public class NyARObserv2IdealMap\r
40 {\r
41         private int _stride;\r
42         private double[] _mapx;\r
43         private double[] _mapy;\r
44         public NyARObserv2IdealMap(NyARCameraDistortionFactor i_distfactor,NyARIntSize i_screen_size)\r
45         {\r
46                 NyARDoublePoint2d opoint=new NyARDoublePoint2d();\r
47                 this._mapx=new double[i_screen_size.w*i_screen_size.h];\r
48                 this._mapy=new double[i_screen_size.w*i_screen_size.h];\r
49                 this._stride=i_screen_size.w;\r
50                 int ptr=i_screen_size.h*i_screen_size.w-1;\r
51                 //歪みマップを構築\r
52                 for(int i=i_screen_size.h-1;i>=0;i--)\r
53                 {\r
54                         for(int i2=i_screen_size.w-1;i2>=0;i2--)\r
55                         {\r
56                                 i_distfactor.observ2Ideal(i2,i, opoint);\r
57                                 this._mapx[ptr]=opoint.x;\r
58                                 this._mapy[ptr]=opoint.y;\r
59                                 ptr--;\r
60                         }\r
61                 }\r
62                 return;\r
63         }\r
64         public void observ2Ideal(double ix, double iy, NyARDoublePoint2d o_point)\r
65         {\r
66                 int idx=(int)ix+(int)iy*this._stride;\r
67                 o_point.x=this._mapx[idx];\r
68                 o_point.y=this._mapy[idx];\r
69                 return;\r
70         }\r
71         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
72         {\r
73                 int idx;\r
74                 int ptr=0;\r
75                 for (int j = 0; j < i_num; j++) {\r
76                         idx=i_x_coord[i_start + j]+i_y_coord[i_start + j]*this._stride;\r
77                         o_x_coord[ptr]=this._mapx[idx];\r
78                         o_y_coord[ptr]=this._mapy[idx];\r
79                         ptr++;\r
80                 }\r
81                 return;\r
82         }       \r
83 }\r