--- /dev/null
+/* \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.match;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.*;\r
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;\r
+\r
+/**\r
+ * AR_TEMPLATE_MATCHING_BWと同等のルールで マーカを評価します。\r
+ * \r
+ */\r
+public class NyARMatchPatt_BlackWhite implements INyARMatchPatt\r
+{\r
+ protected NyARCode _code_patt; \r
+ protected int _pixels;\r
+ \r
+ public NyARMatchPatt_BlackWhite(int i_width, int i_height)\r
+ {\r
+ //最適化定数の計算\r
+ this._pixels=i_height*i_width;\r
+ return;\r
+ }\r
+ public NyARMatchPatt_BlackWhite(NyARCode i_code_ref)\r
+ {\r
+ //最適化定数の計算\r
+ this._pixels=i_code_ref.getWidth()*i_code_ref.getHeight();\r
+ this._code_patt=i_code_ref;\r
+ return;\r
+ } \r
+ /**\r
+ * 比較対象のARCodeをセットします。\r
+ * @throws NyARException\r
+ */\r
+ public void setARCode(NyARCode i_code_ref)\r
+ {\r
+ this._code_patt=i_code_ref;\r
+ return;\r
+ }\r
+ /**\r
+ * 現在セットされているコードとパターンを比較して、結果値o_resultを更新します。\r
+ * 比較部分はFor文を16倍展開してあります。\r
+ */\r
+ public boolean evaluate(NyARMatchPattDeviationBlackWhiteData i_patt,NyARMatchPattResult o_result) throws NyARException\r
+ {\r
+ assert this._code_patt!=null;\r
+\r
+ final int[] linput = i_patt.refData();\r
+ int sum;\r
+ double max = 0.0;\r
+ int res = NyARMatchPattResult.DIRECTION_UNKNOWN;\r
+ \r
+\r
+ for (int j = 0; j < 4; j++) {\r
+ //合計値初期化\r
+ sum=0;\r
+ final NyARMatchPattDeviationBlackWhiteData code_patt=this._code_patt.getBlackWhiteData(j);\r
+ final int[] pat_j = code_patt.refData();\r
+ //<全画素について、比較(FORの1/16展開)/>\r
+ int i;\r
+ for(i=this._pixels-1;i>=0;i--){\r
+ sum += linput[i] * pat_j[i];\r
+ }\r
+ //0.7776737688877927がでればOK\r
+ final double sum2 = sum / code_patt.getPow() / i_patt.getPow();// sum2 = sum / patpow[k][j]/ datapow;\r
+ if (sum2 > max) {\r
+ max = sum2;\r
+ res = j;\r
+ }\r
+ }\r
+ o_result.direction = res;\r
+ o_result.confidence= max;\r
+ return true;\r
+ }\r
+}\r