--- /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-2010 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.types;\r
+\r
+/**\r
+ * ヒストグラムを格納するクラスです。\r
+ */\r
+public class NyARHistogram\r
+{\r
+ /**\r
+ * サンプリング値の格納変数\r
+ */\r
+ public final int[] data;\r
+ /**\r
+ * 有効なサンプリング値の範囲。[0-data.length-1]\r
+ */\r
+ public int length;\r
+ /**\r
+ * 有効なサンプルの総数 data[i]\r
+ */\r
+ public int total_of_data;\r
+ \r
+ \r
+ \r
+ public NyARHistogram(int i_length)\r
+ {\r
+ this.data=new int[i_length];\r
+ this.length=i_length;\r
+ this.total_of_data=0;\r
+ }\r
+ /**\r
+ * 区間i_stからi_edまでの総データ数を返します。\r
+ * @param i_st\r
+ * @param i_ed\r
+ * @return\r
+ */\r
+ public final int getTotal(int i_st,int i_ed)\r
+ {\r
+ assert(i_st<i_ed && i_ed<this.length);\r
+ int result=0;\r
+ int[] s=this.data;\r
+ for(int i=i_st;i<=i_ed;i++){\r
+ result+=s[i];\r
+ }\r
+ return result;\r
+ }\r
+ /**\r
+ * 指定したi_pos未満サンプルを0にします。\r
+ * @param i_pos\r
+ */\r
+ public void lowCut(int i_pos)\r
+ {\r
+ int s=0;\r
+ for(int i=0;i<i_pos;i++){\r
+ s+=this.data[i];\r
+ this.data[i]=0;\r
+ }\r
+ this.total_of_data-=s;\r
+ }\r
+ /**\r
+ * 指定したi_pos以上のサンプルを0にします。\r
+ * @param i_pos\r
+ */\r
+ public void highCut(int i_pos)\r
+ {\r
+ int s=0;\r
+ for(int i=this.length-1;i>=i_pos;i--){\r
+ s+=this.data[i];\r
+ this.data[i]=0;\r
+ }\r
+ this.total_of_data-=s;\r
+ }\r
+ /**\r
+ * 最小の値が格納されているサンプル番号を返します。\r
+ */\r
+ public int getMinSample()\r
+ {\r
+ int[] data=this.data;\r
+ int ret=this.length-1;\r
+ int min=data[ret];\r
+ for(int i=this.length-2;i>=0;i--)\r
+ {\r
+ if(data[i]<min){\r
+ min=data[i];\r
+ ret=i;\r
+ }\r
+ }\r
+ return ret;\r
+ }\r
+ /**\r
+ * サンプルの中で最小の値を返します。\r
+ * @return\r
+ */\r
+ public int getMinData()\r
+ {\r
+ return this.data[this.getMinSample()];\r
+ }\r
+ /**\r
+ * 平均値を計算します。\r
+ * @return\r
+ */\r
+ public int getAverage()\r
+ {\r
+ long sum=0;\r
+ for(int i=this.length-1;i>=0;i--)\r
+ {\r
+ sum+=this.data[i]*i;\r
+ }\r
+ return (int)(sum/this.total_of_data);\r
+ }\r
+ \r
+}\r