OSDN Git Service

db8b04b652409fbe872a03c51dedf9c0548a6062
[nyartoolkit-and/nyartoolkit-and.git] / src / jp / nyatla / nyartoolkit / core / NyARVec.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 edition ARToolKit class library.\r
11  * Copyright (C)2008-2009 Ryo 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 Lesser General Public License\r
15  * as published by the Free Software Foundation; either version 3\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 Lesser General Public License for more details\r
22  * \r
23  * You should have received a copy of the GNU Lesser General Public\r
24  * License along with this program. If not, see <http://www.gnu.org/licenses/>.\r
25  * \r
26  * For further information please contact.\r
27  *      http://nyatla.jp/nyatoolkit/\r
28  *      <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
29  * \r
30  */\r
31 package jp.nyatla.nyartoolkit.core;\r
32 \r
33 import jp.nyatla.nyartoolkit.NyARException;\r
34 \r
35 \r
36 \r
37 public class NyARVec\r
38 {\r
39         private int clm;\r
40 \r
41         public NyARVec(int i_clm)\r
42         {\r
43                 v = new double[i_clm];\r
44                 clm = i_clm;\r
45         }\r
46 \r
47         private double[] v;\r
48 \r
49         /**\r
50          * i_clmサイズの列を格納できるように列サイズを変更します。 実行後、列の各値は不定になります。\r
51          * \r
52          * @param i_clm\r
53          */\r
54         public void realloc(int i_clm)\r
55         {\r
56                 if (i_clm <= this.v.length) {\r
57                         // 十分な配列があれば何もしない。\r
58                 } else {\r
59                         // 不十分なら取り直す。\r
60                         v = new double[i_clm];\r
61                 }\r
62                 this.clm = i_clm;\r
63         }\r
64 \r
65         public int getClm()\r
66         {\r
67                 return clm;\r
68         }\r
69 \r
70         public double[] getArray()\r
71         {\r
72                 return v;\r
73         }\r
74 \r
75         /**\r
76          * arVecDispの代替品\r
77          * \r
78          * @param value\r
79          * @return\r
80          */\r
81         public int arVecDisp() throws NyARException\r
82         {\r
83                 NyARException.trap("未チェックのパス");\r
84                 System.out.println(" === vector (" + clm + ") ===\n");// printf(" ===\r
85                                                                                                                                 // vector (%d)\r
86                                                                                                                                 // ===\n",\r
87                                                                                                                                 // v->clm);\r
88                 System.out.print(" |");// printf(" |");\r
89                 for (int c = 0; c < clm; c++) {// for( c = 0; c < v->clm; c++ ){\r
90                         System.out.print(" " + v[c]);// printf( " %10g", v->v[c] );\r
91                 }\r
92                 System.out.println(" |");// printf(" |\n");\r
93                 System.out.println(" ===================");// printf("\r
94                                                                                                         // ===================\n");\r
95                 return 0;\r
96         }\r
97 \r
98         /**\r
99          * arVecInnerproduct関数の代替品\r
100          * \r
101          * @param x\r
102          * @param y\r
103          * @param i_start\r
104          *            演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる)\r
105          * @return\r
106          * @throws NyARException\r
107          */\r
108         public double vecInnerproduct(NyARVec y, int i_start) throws NyARException\r
109         {\r
110                 NyARException.trap("この関数は動作確認できていません。");\r
111                 double result = 0.0;\r
112                 // double[] x_array=x.v;.getArray();\r
113                 // double[] y_array=y.getArray();\r
114 \r
115                 if (this.clm != y.clm) {\r
116                         throw new NyARException();// exit();\r
117                 }\r
118                 for (int i = i_start; i < this.clm; i++) {\r
119                         NyARException.trap("未チェックのパス");\r
120                         result += this.v[i] * y.v[i];// result += x->v[i] * y->v[i];\r
121                 }\r
122                 return result;\r
123         }\r
124 \r
125         /**\r
126          * double arVecHousehold関数の代替品\r
127          * \r
128          * @param x\r
129          * @param i_start\r
130          *            演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる)\r
131          * @return\r
132          * @throws NyARException\r
133          */\r
134         public double vecHousehold(int i_start) throws NyARException\r
135         {\r
136                 NyARException.trap("この関数は動作確認できていません。");\r
137                 double s, t;\r
138                 s = Math.sqrt(this.vecInnerproduct(this, i_start));\r
139                 // double[] x_array=x.getArray();\r
140                 if (s != 0.0) {\r
141                         NyARException.trap("未チェックのパス");\r
142                         if (this.v[i_start] < 0) {\r
143                                 s = -s;\r
144                         }\r
145                         NyARException.trap("未チェックのパス");\r
146                         {\r
147                                 this.v[i_start] += s;// x->v[0] += s;\r
148                                 t = 1 / Math.sqrt(this.v[i_start] * s);// t = 1 / sqrt(x->v[0] * s);\r
149                         }\r
150                         for (int i = i_start; i < this.clm; i++) {\r
151                                 NyARException.trap("未チェックのパス");\r
152                                 this.v[i] *= t;// x->v[i] *= t;\r
153                         }\r
154                 }\r
155                 return -s;\r
156         }\r
157 \r
158         /**\r
159          * 現在ラップしている配列を取り外して、新しい配列をラップします。\r
160          * \r
161          * @param i_v\r
162          * @param i_clm\r
163          */\r
164         public void setNewArray(double[] i_array, int i_clm)\r
165         {\r
166                 this.v = i_array;\r
167                 this.clm = i_clm;\r
168         }\r
169 }\r