* HITLab, University of Washington, Seattle\r
* http://www.hitl.washington.edu/artoolkit/\r
*\r
- * The NyARToolkit is Java version ARToolkit class library.\r
- * Copyright (C)2008 R.Iizuka\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\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\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
+ *\r
* You should have received a copy of the GNU General Public License\r
- * along with this framework; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\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>\r
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
* \r
*/\r
package jp.nyatla.utils.j2se;\r
import jp.nyatla.nyartoolkit.core.rasterreader.*;\r
import jp.nyatla.nyartoolkit.core.raster.*;\r
import jp.nyatla.nyartoolkit.core.types.stack.*;\r
-\r
+import jp.nyatla.nyartoolkit.core.labeling.*;\r
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage;\r
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabel;\r
\r
/**\r
* bitmapとして利用可能なラベリングイメージです。\r
* \r
- * @author atla\r
* \r
*/\r
public class LabelingBufferdImage extends BufferedImage\r
\r
public final static int COLOR_8_MONO = 5;// 16階調モノクロモード\r
\r
- private int[] _rgb_table;\r
+ private int[] _rgb_table_125;\r
\r
- private int _number_of_color;\r
\r
/**\r
* i_width x i_heightの大きさのイメージを作成します。\r
* @param i_width\r
* @param i_height\r
*/\r
- public LabelingBufferdImage(int i_width, int i_height, int i_color_mode)\r
+ public LabelingBufferdImage(int i_width, int i_height)\r
{\r
super(i_width, i_height, ColorSpace.TYPE_RGB);\r
// RGBテーブルを作成\r
- switch (i_color_mode) {\r
- case COLOR_125_COLOR:\r
- this._rgb_table = new int[125];\r
- this._number_of_color = 125;\r
- for (int i = 0; i < 5; i++) {\r
- for (int i2 = 0; i2 < 5; i2++) {\r
- for (int i3 = 0; i3 < 5; i3++) {\r
- this._rgb_table[((i * 5) + i2) * 5 + i3] = ((((i * 63) << 8) | (i2 * 63)) << 8) | (i3 * 63);\r
- }\r
+ this._rgb_table_125 = new int[125];\r
+ for (int i = 0; i < 5; i++) {\r
+ for (int i2 = 0; i2 < 5; i2++) {\r
+ for (int i3 = 0; i3 < 5; i3++) {\r
+ this._rgb_table_125[((i * 5) + i2) * 5 + i3] = ((((i * 63) << 8) | (i2 * 63)) << 8) | (i3 * 63);\r
}\r
}\r
- break;\r
- case COLOR_256_MONO:\r
+ }\r
+/* case COLOR_256_MONO:\r
this._rgb_table = new int[256];\r
this._number_of_color = 256;\r
for (int i = 0; i < 256; i++) {\r
this._rgb_table[i] = (m << 16) | (m << 8) | m;\r
}\r
break;\r
- }\r
+ }*/\r
}\r
\r
\r
\r
- public void drawImage(NyARGlayscaleRaster i_raster) throws NyARException\r
+ public void drawImage(NyARGrayscaleRaster i_raster) throws NyARException\r
{\r
- assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8);\r
+ assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8);\r
\r
int w = this.getWidth();\r
int h = this.getHeight();\r
throw new NyARException();\r
}\r
\r
- int[][] limg;\r
+ int[] limg;\r
// イメージの描画\r
- limg = (int[][]) i_raster.getBufferReader().getBuffer();\r
+ limg = (int[]) i_raster.getBufferReader().getBuffer();\r
for (int i = 0; i < h; i++) {\r
for (int i2 = 0; i2 < w; i2++) {\r
- this.setRGB(i2, i, this._rgb_table[limg[i][i2] % this._number_of_color]);\r
+ this.setRGB(i2, i,limg[i*w+i2]);\r
}\r
}\r
return;\r
}\r
-\r
+ /**\r
+ * バイナリラスタ\r
+ * @param i_raster\r
+ * @throws NyARException\r
+ */\r
public void drawImage(NyARBinRaster i_raster) throws NyARException\r
{\r
- assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT2D_BIN_8);\r
+ assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8);\r
\r
int w = this.getWidth();\r
int h = this.getHeight();\r
throw new NyARException();\r
}\r
\r
- int[][] limg;\r
+ int[] limg;\r
// イメージの描画\r
- limg = (int[][]) i_raster.getBufferReader().getBuffer();\r
+ limg = (int[]) i_raster.getBufferReader().getBuffer();\r
for (int i = 0; i < h; i++) {\r
for (int i2 = 0; i2 < w; i2++) {\r
- this.setRGB(i2, i, limg[i][i2] > 0 ? 255 : 0);\r
+ this.setRGB(i2, i, limg[i*w+i2] > 0 ? 255 : 0);\r
}\r
}\r
return;\r
}\r
+ \r
+ /**\r
+ * ラベリングイメージを書く\r
+ * @param i_raster\r
+ * @throws NyARException\r
+ */\r
+ public void drawLabel(NyARLabelingImage i_image) throws NyARException\r
+ {\r
+ int w = this.getWidth();\r
+ int h = this.getHeight();\r
+ // サイズをチェック\r
+ NyARIntSize size = i_image.getSize();\r
+ if (size.h > h || size.w > w) {\r
+ throw new NyARException();\r
+ }\r
+ int[] index_array=i_image.getIndexArray();\r
+\r
+ int[] limg;\r
+ // イメージの描画\r
+ limg = (int[]) i_image.getBufferReader().getBuffer();\r
+ for (int i = 0; i < h; i++) {\r
+ for (int i2 = 0; i2 < w; i2++) {\r
+ int t=limg[i*w+i2]-1;\r
+ if(t<0){\r
+ t=0;\r
+ }else{\r
+ t=index_array[t];\r
+ }\r
+ this.setRGB(i2, i,_rgb_table_125[t% _rgb_table_125.length]);\r
+ }\r
+ }\r
+ return;\r
+ }\r
+ /**\r
+ * \r
+ * @param i_stack\r
+ */\r
+\r
+ public void overlayData(NyARLabelingLabel i_label)\r
+ {\r
+ Graphics g = this.getGraphics();\r
+ g.setColor(Color.red);\r
+ g.drawRect(i_label.clip_l,i_label.clip_t,i_label.clip_r-i_label.clip_l,i_label.clip_b-i_label.clip_t);\r
+ return;\r
+ } \r
+ /**\r
+ * \r
+ * @param i_stack\r
+ */\r
\r
public void overlayData(NyARIntPointStack i_stack)\r
{\r
int count = i_stack.getLength();\r
- NyARIntPoint[] items = i_stack.getArray();\r
+ NyARIntPoint2d[] items = i_stack.getArray();\r
Graphics g = this.getGraphics();\r
for (int i = 0; i < count; i++) {\r
int x = items[i].x;\r