OSDN Git Service

[TAG]2.4.1
[nyartoolkit-and/nyartoolkit-and.git] / tags / 2.4.1 / sample / sandbox / jp / nyatla / nyartoolkit / sandbox / x2 / NyARFixedFloat16Mat.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.sandbox.x2;\r
33 \r
34 import jp.nyatla.nyartoolkit.NyARException;\r
35 \r
36 \r
37 \r
38 /**\r
39  * ARMat構造体に対応するクラス typedef struct { double *m; int row; int clm; }ARMat;\r
40  * \r
41  */\r
42 public class NyARFixedFloat16Mat\r
43 {\r
44         /**\r
45          * 配列サイズと行列サイズは必ずしも一致しないことに注意 返された配列のサイズを行列の大きさとして使わないこと!\r
46          * \r
47          */\r
48         protected long[][] m;\r
49         private int clm, row;\r
50 \r
51         /**\r
52          * デフォルトコンストラクタは機能しません。\r
53          * \r
54          * @throws NyARException\r
55          */\r
56         protected NyARFixedFloat16Mat() throws NyARException\r
57         {\r
58                 throw new NyARException();\r
59         }\r
60 \r
61         public NyARFixedFloat16Mat(int i_row, int i_clm)\r
62         {\r
63                 this.m = new long[i_row][i_clm];\r
64                 clm = i_clm;\r
65                 row = i_row;\r
66                 return;\r
67         }\r
68         public int getClm()\r
69         {\r
70                 return clm;\r
71         }\r
72         public int getRow()\r
73         {\r
74                 return row;\r
75         }\r
76         /**\r
77          * 行列をゼロクリアする。\r
78          */\r
79         public void zeroClear()\r
80         {\r
81                 int i, i2;\r
82                 // For順変更OK\r
83                 for (i = row - 1; i >= 0; i--) {\r
84                         for (i2 = clm - 1; i2 >= 0; i2--) {\r
85                                 m[i][i2] = 0;\r
86                         }\r
87                 }\r
88         }\r
89         public long[][] getArray()\r
90         {\r
91                 return this.m;\r
92         }\r
93         // public void getRowVec(int i_row,NyARVec o_vec)\r
94         // {\r
95         // o_vec.set(this.m[i_row],this.clm);\r
96         // }\r
97         /**\r
98          * aとbの積を自分自身に格納する。arMatrixMul()の代替品\r
99          * \r
100          * @param a\r
101          * @param b\r
102          * @throws NyARException\r
103          */\r
104         public void matrixMul(NyARFixedFloat16Mat a, NyARFixedFloat16Mat b) throws NyARException\r
105         {\r
106                 if (a.clm != b.row || this.row != a.row || this.clm != b.clm) {\r
107                         throw new NyARException();\r
108                 }\r
109                 long w;\r
110                 int r, c, i;\r
111                 long[][] am = a.m, bm = b.m, dm = this.m;\r
112                 // For順変更禁止\r
113                 for (r = 0; r < this.row; r++) {\r
114                         for (c = 0; c < this.clm; c++) {\r
115                                 w = 0L;// dest.setARELEM0(r, c,0.0);\r
116                                 for (i = 0; i < a.clm; i++) {\r
117                                         w += (am[r][i] * bm[i][c])>>16;// ARELEM0(dest, r, c) +=ARELEM0(a, r, i) * ARELEM0(b,i, c);\r
118                                 }\r
119                                 dm[r][c] = w;\r
120                         }\r
121                 }\r
122         }\r
123 }