OSDN Git Service

git-svn-id: http://svn.sourceforge.jp/svnroot/nyartoolkit/NyARToolkit/trunk@768 7cac0...
[nyartoolkit-and/nyartoolkit-and.git] / lib / src / jp / nyatla / nyartoolkit / core / NyARVec.java
diff --git a/lib/src/jp/nyatla/nyartoolkit/core/NyARVec.java b/lib/src/jp/nyatla/nyartoolkit/core/NyARVec.java
new file mode 100644 (file)
index 0000000..a38a0a6
--- /dev/null
@@ -0,0 +1,148 @@
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ *   Hirokazu Kato\r
+ *   Mark Billinghurst\r
+ *   HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java edition ARToolKit class library.\r
+ * Copyright (C)2008-2009 Ryo Iizuka\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+ * \r
+ * For further information please contact.\r
+ *     http://nyatla.jp/nyatoolkit/\r
+ *     <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+\r
+\r
+\r
+public class NyARVec\r
+{\r
+       private int clm;\r
+\r
+       public NyARVec(int i_clm)\r
+       {\r
+               v = new double[i_clm];\r
+               clm = i_clm;\r
+       }\r
+\r
+       private double[] v;\r
+\r
+       /**\r
+        * i_clmサイズの列を格納できるように列サイズを変更します。 実行後、列の各値は不定になります。\r
+        * \r
+        * @param i_clm\r
+        */\r
+       public void realloc(int i_clm)\r
+       {\r
+               if (i_clm <= this.v.length) {\r
+                       // 十分な配列があれば何もしない。\r
+               } else {\r
+                       // 不十分なら取り直す。\r
+                       v = new double[i_clm];\r
+               }\r
+               this.clm = i_clm;\r
+       }\r
+\r
+       public int getClm()\r
+       {\r
+               return clm;\r
+       }\r
+\r
+       public double[] getArray()\r
+       {\r
+               return v;\r
+       }\r
+\r
+\r
+\r
+       /**\r
+        * arVecInnerproduct関数の代替品\r
+        * \r
+        * @param x\r
+        * @param y\r
+        * @param i_start\r
+        *            演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる)\r
+        * @return\r
+        * @throws NyARException\r
+        */\r
+       public double vecInnerproduct(NyARVec y, int i_start) throws NyARException\r
+       {\r
+               NyARException.trap("この関数は動作確認できていません。");\r
+               double result = 0.0;\r
+               // double[] x_array=x.v;.getArray();\r
+               // double[] y_array=y.getArray();\r
+\r
+               if (this.clm != y.clm) {\r
+                       throw new NyARException();// exit();\r
+               }\r
+               for (int i = i_start; i < this.clm; i++) {\r
+                       NyARException.trap("未チェックのパス");\r
+                       result += this.v[i] * y.v[i];// result += x->v[i] * y->v[i];\r
+               }\r
+               return result;\r
+       }\r
+\r
+       /**\r
+        * double arVecHousehold関数の代替品\r
+        * \r
+        * @param x\r
+        * @param i_start\r
+        *            演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる)\r
+        * @return\r
+        * @throws NyARException\r
+        */\r
+       public double vecHousehold(int i_start) throws NyARException\r
+       {\r
+               NyARException.trap("この関数は動作確認できていません。");\r
+               double s, t;\r
+               s = Math.sqrt(this.vecInnerproduct(this, i_start));\r
+               // double[] x_array=x.getArray();\r
+               if (s != 0.0) {\r
+                       NyARException.trap("未チェックのパス");\r
+                       if (this.v[i_start] < 0) {\r
+                               s = -s;\r
+                       }\r
+                       NyARException.trap("未チェックのパス");\r
+                       {\r
+                               this.v[i_start] += s;// x->v[0] += s;\r
+                               t = 1 / Math.sqrt(this.v[i_start] * s);// t = 1 / sqrt(x->v[0] * s);\r
+                       }\r
+                       for (int i = i_start; i < this.clm; i++) {\r
+                               NyARException.trap("未チェックのパス");\r
+                               this.v[i] *= t;// x->v[i] *= t;\r
+                       }\r
+               }\r
+               return -s;\r
+       }\r
+\r
+       /**\r
+        * 現在ラップしている配列を取り外して、新しい配列をラップします。\r
+        * \r
+        * @param i_v\r
+        * @param i_clm\r
+        */\r
+       public void setNewArray(double[] i_array, int i_clm)\r
+       {\r
+               this.v = i_array;\r
+               this.clm = i_clm;\r
+       }\r
+}\r