OSDN Git Service

7c43f02656e01878cf5d0872b796049b5d3fed47
[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 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 import jp.nyatla.nyartoolkit.NyARException;\r
35 \r
36 \r
37 \r
38 public class NyARVec\r
39 {\r
40         private int clm;\r
41 \r
42         public NyARVec(int i_clm)\r
43         {\r
44                 v = new double[i_clm];\r
45                 clm = i_clm;\r
46         }\r
47 \r
48         private double[] v;\r
49 \r
50         /**\r
51          * i_clmサイズの列を格納できるように列サイズを変更します。 実行後、列の各値は不定になります。\r
52          * \r
53          * @param i_clm\r
54          */\r
55         public void realloc(int i_clm)\r
56         {\r
57                 if (i_clm <= this.v.length) {\r
58                         // 十分な配列があれば何もしない。\r
59                 } else {\r
60                         // 不十分なら取り直す。\r
61                         v = new double[i_clm];\r
62                 }\r
63                 this.clm = i_clm;\r
64         }\r
65 \r
66         public int getClm()\r
67         {\r
68                 return clm;\r
69         }\r
70 \r
71         public double[] getArray()\r
72         {\r
73                 return v;\r
74         }\r
75 \r
76         /**\r
77          * arVecDispの代替品\r
78          * \r
79          * @param value\r
80          * @return\r
81          */\r
82         public int arVecDisp() throws NyARException\r
83         {\r
84                 NyARException.trap("未チェックのパス");\r
85                 System.out.println(" === vector (" + clm + ") ===\n");// printf(" ===\r
86                                                                                                                                 // vector (%d)\r
87                                                                                                                                 // ===\n",\r
88                                                                                                                                 // v->clm);\r
89                 System.out.print(" |");// printf(" |");\r
90                 for (int c = 0; c < clm; c++) {// for( c = 0; c < v->clm; c++ ){\r
91                         System.out.print(" " + v[c]);// printf( " %10g", v->v[c] );\r
92                 }\r
93                 System.out.println(" |");// printf(" |\n");\r
94                 System.out.println(" ===================");// printf("\r
95                                                                                                         // ===================\n");\r
96                 return 0;\r
97         }\r
98 \r
99         /**\r
100          * arVecInnerproduct関数の代替品\r
101          * \r
102          * @param x\r
103          * @param y\r
104          * @param i_start\r
105          *            演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる)\r
106          * @return\r
107          * @throws NyARException\r
108          */\r
109         public double vecInnerproduct(NyARVec y, int i_start) throws NyARException\r
110         {\r
111                 NyARException.trap("この関数は動作確認できていません。");\r
112                 double result = 0.0;\r
113                 // double[] x_array=x.v;.getArray();\r
114                 // double[] y_array=y.getArray();\r
115 \r
116                 if (this.clm != y.clm) {\r
117                         throw new NyARException();// exit();\r
118                 }\r
119                 for (int i = i_start; i < this.clm; i++) {\r
120                         NyARException.trap("未チェックのパス");\r
121                         result += this.v[i] * y.v[i];// result += x->v[i] * y->v[i];\r
122                 }\r
123                 return result;\r
124         }\r
125 \r
126         /**\r
127          * double arVecHousehold関数の代替品\r
128          * \r
129          * @param x\r
130          * @param i_start\r
131          *            演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる)\r
132          * @return\r
133          * @throws NyARException\r
134          */\r
135         public double vecHousehold(int i_start) throws NyARException\r
136         {\r
137                 NyARException.trap("この関数は動作確認できていません。");\r
138                 double s, t;\r
139                 s = Math.sqrt(this.vecInnerproduct(this, i_start));\r
140                 // double[] x_array=x.getArray();\r
141                 if (s != 0.0) {\r
142                         NyARException.trap("未チェックのパス");\r
143                         if (this.v[i_start] < 0) {\r
144                                 s = -s;\r
145                         }\r
146                         NyARException.trap("未チェックのパス");\r
147                         {\r
148                                 this.v[i_start] += s;// x->v[0] += s;\r
149                                 t = 1 / Math.sqrt(this.v[i_start] * s);// t = 1 / sqrt(x->v[0] * s);\r
150                         }\r
151                         for (int i = i_start; i < this.clm; i++) {\r
152                                 NyARException.trap("未チェックのパス");\r
153                                 this.v[i] *= t;// x->v[i] *= t;\r
154                         }\r
155                 }\r
156                 return -s;\r
157         }\r
158 \r
159         /**\r
160          * 現在ラップしている配列を取り外して、新しい配列をラップします。\r
161          * \r
162          * @param i_v\r
163          * @param i_clm\r
164          */\r
165         public void setNewArray(double[] i_array, int i_clm)\r
166         {\r
167                 this.v = i_array;\r
168                 this.clm = i_clm;\r
169         }\r
170 }\r