Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
203 chris 1
/*
2
 * PROJECT: NyARToolkit
3
 * --------------------------------------------------------------------------------
4
 * This work is based on the original ARToolKit developed by
5
 *   Hirokazu Kato
6
 *   Mark Billinghurst
7
 *   HITLab, University of Washington, Seattle
8
 * http://www.hitl.washington.edu/artoolkit/
9
 *
10
 * The NyARToolkit is Java version ARToolkit class library.
11
 * Copyright (C)2008 R.Iizuka
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version 2
16
 * of the License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this framework; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 *
27
 * For further information please contact.
28
 *      http://nyatla.jp/nyatoolkit/
29
 *      <airmail(at)ebony.plala.or.jp>
30
 *
31
 */
32
package jp.nyatla.nyartoolkit.core;
33
 
34
import jp.nyatla.nyartoolkit.NyARException;
35
 
36
/**
37
 * ARMarkerInfoに相当するクラス。 スクエア情報を保持します。
38
 *
39
 */
40
public class NyARSquare extends NyARMarker {
41
        // private NyARMarker marker;
42
        // public int area;
43
        // public double[] pos;
44
        public double[][] line = new double[4][3]; // double[4][3]
45
        public double[][] sqvertex = new double[4][2];// double[4][2];
46
 
47
        public NyARSquare() {
48
                super();
49
        }
50
 
51
        private final NyARMat wk_getLine_input = new NyARMat(1, 2);
52
        private final NyARMat wk_getLine_evec = new NyARMat(2, 2);
53
        private final NyARVec wk_getLine_ev = new NyARVec(2);
54
        private final NyARVec wk_getLine_mean = new NyARVec(2);
55
 
56
        /**
57
         * arGetLine(int x_coord[], int y_coord[], int coord_num,int vertex[],
58
         * double line[4][3], double v[4][2]) arGetLine2(int x_coord[], int
59
         * y_coord[], int coord_num,int vertex[], double line[4][3], double v[4][2],
60
         * double *dist_factor) の2関数の合成品です。 格納しているマーカー情報に対して、GetLineの計算を行い、結果を返します。
61
         * Optimize:STEP[424->391]
62
         *
63
         * @param i_cparam
64
         * @return
65
         * @throws NyARException
66
         */
67
        public boolean getLine(NyARParam i_cparam) throws NyARException {
68
                double w1;
69
                int st, ed, n;
70
                int i;
71
 
72
                final double[][] l_sqvertex = this.sqvertex;
73
                final double[][] l_line = this.line;
74
                final int[] l_mkvertex = this.mkvertex;
75
                final int[] l_x_coord = this.x_coord;
76
                final int[] l_y_coord = this.y_coord;
77
                final NyARVec ev = this.wk_getLine_ev; // matrixPCAの戻り値を受け取る
78
                final NyARVec mean = this.wk_getLine_mean;// matrixPCAの戻り値を受け取る
79
                final double[] mean_array = mean.getArray();
80
                double[] l_line_i, l_line_2;
81
 
82
                NyARMat input = this.wk_getLine_input;// 次処理で初期化される。
83
                NyARMat evec = this.wk_getLine_evec;// アウトパラメータを受け取るから初期化不要//new
84
                                                                                        // NyARMat(2,2);
85
                double[][] evec_array = evec.getArray();
86
                for (i = 0; i < 4; i++) {
87
                        w1 = (double) (l_mkvertex[i + 1] - l_mkvertex[i] + 1) * 0.05 + 0.5;
88
                        st = (int) (l_mkvertex[i] + w1);
89
                        ed = (int) (l_mkvertex[i + 1] - w1);
90
                        n = ed - st + 1;
91
                        if (n < 2) {
92
                                // nが2以下でmatrix.PCAを計算することはできないので、エラーにしておく。
93
                                return false;// throw new NyARException();
94
                        }
95
                        input.realloc(n, 2);
96
                        // バッチ取得
97
                        i_cparam.observ2IdealBatch(l_x_coord, l_y_coord, st, n, input
98
                                        .getArray());
99
                        // for( j = 0; j < n; j++ ) {
100
                        // i_cparam.observ2Ideal(l_x_coord[st+j],
101
                        // l_y_coord[st+j],dv1,dv2);//arParamObserv2Ideal( dist_factor,
102
                        // x_coord[st+j], y_coord[st+j],&(input->m[j*2+0]),
103
                        // &(input->m[j*2+1]) );
104
                        // in_array[j][0]=dv1.value;
105
                        // in_array[j][1]=dv2.value;
106
                        // }
107
                        input.matrixPCA(evec, ev, mean);
108
                        l_line_i = l_line[i];
109
                        l_line_i[0] = evec_array[0][1];// line[i][0] = evec->m[1];
110
                        l_line_i[1] = -evec_array[0][0];// line[i][1] = -evec->m[0];
111
                        l_line_i[2] = -(l_line_i[0] * mean_array[0] + l_line_i[1]
112
                                        * mean_array[1]);// line[i][2] = -(line[i][0]*mean->v[0]
113
                                                                                // + line[i][1]*mean->v[1]);
114
                }
115
 
116
                for (i = 0; i < 4; i++) {
117
                        l_line_i = l_line[i];
118
                        l_line_2 = l_line[(i + 3) % 4];
119
                        w1 = l_line_2[0] * l_line_i[1] - l_line_i[0] * l_line_2[1];
120
                        if (w1 == 0.0) {
121
                                return false;
122
                        }
123
                        l_sqvertex[i][0] = (l_line_2[1] * l_line_i[2] - l_line_i[1]
124
                                        * l_line_2[2])
125
                                        / w1;
126
                        l_sqvertex[i][1] = (l_line_i[0] * l_line_2[2] - l_line_2[0]
127
                                        * l_line_i[2])
128
                                        / w1;
129
                }
130
                return true;
131
        }
132
}