OSDN Git Service

85586d9a176be104688caa15ba2793540b0ee0be
[nyartoolkit-and/nyartoolkit-and.git] / branches / nyatla / src / jp / nyatla / nyartoolkit / core / NyARSquare.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;\r
33 \r
34 \r
35 \r
36 /**\r
37  * ARMarkerInfoに相当するクラス。\r
38  * スクエア情報を保持します。\r
39  *\r
40  */\r
41 public class NyARSquare{\r
42 //    private NyARMarker marker;\r
43 //    public int area;\r
44 //    public double[] pos;\r
45     public double[][] line=new double[4][3];\r
46     public double[][] sqvertex=new double[4][2];\r
47     public int[][] imvertex=new int[4][2];\r
48 /*    public NyARSquare()\r
49     {\r
50         super();\r
51     }\r
52     private final NyARMat wk_getLine_input=new NyARMat(1,2);\r
53     private final NyARMat wk_getLine_evec=new NyARMat(2,2);\r
54     private final NyARVec wk_getLine_ev=new NyARVec(2);\r
55     private final NyARVec wk_getLine_mean=new NyARVec(2);\r
56 \r
57     public boolean getLine(NyARParam i_cparam) throws NyARException\r
58     {\r
59         double   w1;\r
60         int      st, ed, n;\r
61         int      i;\r
62 \r
63         final double[][] l_sqvertex=this.sqvertex;\r
64         final double[][] l_line=this.line;\r
65         final int[] l_mkvertex=this.mkvertex;\r
66         final int[] l_x_coord=this.x_coord;\r
67         final int[] l_y_coord=this.y_coord;     \r
68         final NyARVec ev     = this.wk_getLine_ev;  //matrixPCAの戻り値を受け取る\r
69         final NyARVec mean   = this.wk_getLine_mean;//matrixPCAの戻り値を受け取る\r
70         final double[] mean_array=mean.getArray();\r
71         double[] l_line_i,l_line_2;\r
72 \r
73         NyARMat input=this.wk_getLine_input;//次処理で初期化される。\r
74         NyARMat evec =this.wk_getLine_evec;//アウトパラメータを受け取るから初期化不要//new NyARMat(2,2);\r
75         double[][] evec_array=evec.getArray();\r
76         for( i = 0; i < 4; i++ ) {\r
77             w1 = (double)(l_mkvertex[i+1]-l_mkvertex[i]+1) * 0.05 + 0.5;\r
78             st = (int)(l_mkvertex[i]   + w1);\r
79             ed = (int)(l_mkvertex[i+1] - w1);\r
80             n = ed - st + 1;\r
81             if(n<2){\r
82                 //nが2以下でmatrix.PCAを計算することはできないので、エラーにしておく。\r
83                 return false;//throw new NyARException();\r
84             }\r
85             input.realloc(n,2);\r
86             //バッチ取得\r
87             i_cparam.observ2IdealBatch(l_x_coord,l_y_coord,st,n,input.getArray());\r
88 //          for( j = 0; j < n; j++ ) {\r
89 //              i_cparam.observ2Ideal(l_x_coord[st+j], l_y_coord[st+j],dv1,dv2);//arParamObserv2Ideal( dist_factor, x_coord[st+j], y_coord[st+j],&(input->m[j*2+0]), &(input->m[j*2+1]) );\r
90 //              in_array[j][0]=dv1.value;\r
91 //              in_array[j][1]=dv2.value;\r
92 //          }\r
93             input.matrixPCA(evec, ev, mean);\r
94             l_line_i=l_line[i];\r
95             l_line_i[0] =  evec_array[0][1];//line[i][0] =  evec->m[1];\r
96             l_line_i[1] = -evec_array[0][0];//line[i][1] = -evec->m[0];\r
97             l_line_i[2] = -(l_line_i[0]*mean_array[0] + l_line_i[1]*mean_array[1]);//line[i][2] = -(line[i][0]*mean->v[0] + line[i][1]*mean->v[1]);\r
98         }\r
99 \r
100         for( i = 0; i < 4; i++ )\r
101         {\r
102             l_line_i=l_line[i];\r
103             l_line_2=l_line[(i+3)%4];\r
104             w1 = l_line_2[0] * l_line_i[1] - l_line_i[0] * l_line_2[1];\r
105             if( w1 == 0.0 ){\r
106                 return false;\r
107             }\r
108             l_sqvertex[i][0] = (  l_line_2[1] * l_line_i[2]- l_line_i[1] * l_line_2[2] ) / w1;\r
109             l_sqvertex[i][1] = (  l_line_i[0] * l_line_2[2]- l_line_2[0] * l_line_i[2] ) / w1;\r
110         }\r
111         return true;\r
112     }*/\r
113 }\r