OSDN Git Service

[tag]NyARToolkit/2.5.1
[nyartoolkit-and/nyartoolkit-and.git] / tags / 2.5.1 / src / jp / nyatla / nyartoolkit / core / pca2d / NyARPca2d_MatrixPCA.java
diff --git a/tags/2.5.1/src/jp/nyatla/nyartoolkit/core/pca2d/NyARPca2d_MatrixPCA.java b/tags/2.5.1/src/jp/nyatla/nyartoolkit/core/pca2d/NyARPca2d_MatrixPCA.java
new file mode 100644 (file)
index 0000000..ec47729
--- /dev/null
@@ -0,0 +1,73 @@
+/* \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.pca2d;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.NyARMat;\r
+import jp.nyatla.nyartoolkit.core.NyARVec;\r
+import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix22;\r
+/**\r
+ * NyARMatrixを利用した主成分分析\r
+ * ARToolKitと同じ処理をします。\r
+ */\r
+public class NyARPca2d_MatrixPCA implements INyARPca2d\r
+{\r
+       private final NyARMat __pca_input = new NyARMat(1, 2);\r
+       private final NyARMat __pca_evec = new NyARMat(2, 2);\r
+       private final NyARVec __pca_ev = new NyARVec(2);\r
+       private final NyARVec __pca_mean = new NyARVec(2);      \r
+       \r
+       public void pca(double[] i_v1,double[] i_v2,int i_number_of_point,NyARDoubleMatrix22 o_evec, double[] o_ev,double[] o_mean) throws NyARException\r
+       {\r
+               final NyARMat input = this.__pca_input;// 次処理で初期化される。             \r
+               // pcaの準備\r
+               input.realloc(i_number_of_point, 2);\r
+               final double[][] input_array=input.getArray();\r
+               for(int i=0;i<i_number_of_point;i++){\r
+                       input_array[i][0]=i_v1[i];\r
+                       input_array[i][1]=i_v2[i];\r
+               }\r
+               // 主成分分析\r
+               input.pca(this.__pca_evec, this.__pca_ev, this.__pca_mean);\r
+               final double[] mean_array = this.__pca_mean.getArray();\r
+               final double[][] evec_array = this.__pca_evec.getArray();\r
+               final double[] ev_array=this.__pca_ev.getArray();\r
+               o_evec.m00=evec_array[0][0];\r
+               o_evec.m01=evec_array[0][1];\r
+               o_evec.m10=evec_array[1][0];\r
+               o_evec.m11=evec_array[1][1];\r
+               o_ev[0]=ev_array[0];\r
+               o_ev[1]=ev_array[1];\r
+               o_mean[0]=mean_array[0];\r
+               o_mean[1]=mean_array[1];\r
+               return;\r
+       }\r
+}\r