OSDN Git Service

[リリース]NyARToolkit 1.0.0
authornyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Sat, 7 Jun 2008 02:37:50 +0000 (02:37 +0000)
committernyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Sat, 7 Jun 2008 02:37:50 +0000 (02:37 +0000)
36 files changed:
changelog/0.6.20080330.0.txt [deleted file]
changelog/0.7.20080406.0.txt [deleted file]
changelog/0.8.20080412.0.txt [deleted file]
readme.ja.txt
sample/java3d/.classpath
sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java
sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java
sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java
sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java
src/jp/nyatla/nyartoolkit/base/Param.java
src/jp/nyatla/nyartoolkit/core/NyARColorPatt.java
src/jp/nyatla/nyartoolkit/core/NyARColorPatt_O1.java [new file with mode: 0644]
src/jp/nyatla/nyartoolkit/core/NyARColorPatt_O2.java [new file with mode: 0644]
src/jp/nyatla/nyartoolkit/core/NyARColorPatt_O3.java [new file with mode: 0644]
src/jp/nyatla/nyartoolkit/core/NyARDetectMarker.java
src/jp/nyatla/nyartoolkit/core/NyARDetectSquare.java
src/jp/nyatla/nyartoolkit/core/NyARLabeling.java
src/jp/nyatla/nyartoolkit/core/NyARMarker.java
src/jp/nyatla/nyartoolkit/core/NyARMarkerList.java [new file with mode: 0644]
src/jp/nyatla/nyartoolkit/core/NyARMat.java
src/jp/nyatla/nyartoolkit/core/NyARParam.java
src/jp/nyatla/nyartoolkit/core/NyARSquare.java
src/jp/nyatla/nyartoolkit/core/NyARSquareList.java [new file with mode: 0644]
src/jp/nyatla/nyartoolkit/core/NyARTransMat.java
src/jp/nyatla/nyartoolkit/core/NyARTransRot.java [new file with mode: 0644]
src/jp/nyatla/nyartoolkit/core/NyARVec.java
src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java
src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java
src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java
src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java
src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_BGRA.java
src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_Blank.java
src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_RGB.java
src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java
src/jp/nyatla/nyartoolkit/sample/RawFileTest.java
src/jp/nyatla/util/IntValue.java

diff --git a/changelog/0.6.20080330.0.txt b/changelog/0.6.20080330.0.txt
deleted file mode 100644 (file)
index 0dba4ee..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-2008.03.30 version 0.6.20080330.0\r
-\r
-*Title\r
--メモリ管理の見直し\r
--速度向上(84%up)\r
--サンプルの15fps化\r
-\r
-*PublicAPI\r
-\r
--NyARCode.java\r
-[改名--rename]\r
- NyARCode::LoadFromARFileをNyARCode::loadFromARFile\r
-\r
--NyARDetectMarker.java\r
-[廃止--delete]\r
-NyARDetectMarker::getMarkerArray\r
-[追加--add]\r
-NyARDetectMarker::getMarker\r
-\r
-\r
--NyARMat.java\r
-[更新--update]\r
-NyARMat::matrixSelfInv \r
-NyARMat::matrixDup\r
-\r
--DoubleValue.java\r
-[廃止--delete]\r
-DoubleValue::set\r
-DoubleValue::get\r
-DoubleValue::add\r
diff --git a/changelog/0.7.20080406.0.txt b/changelog/0.7.20080406.0.txt
deleted file mode 100644 (file)
index 705f134..0000000
+++ /dev/null
@@ -1,595 +0,0 @@
-2008.04.06 version 0.7.20080406.0\r
-\r
-*Title\r
--バグフィクス\r
---キャプチャ画像のBGRをRGBとして評価していたのを修正\r
---JMFキャプチャ画像ピクセルフォーマット認識の自動化\r
---サンプルバグ修正\r
---スペルミス修正\r
-\r
-\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java      (revision 172)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java      (revision 173)\r
-@@ -121,9 +121,8 @@\r
-         //NyARToolkitの準備\r
-         try{\r
-             //キャプチャの準備\r
--            capture=new JmfCameraCapture(320,240,15f,JmfCameraCapture.PIXCEL_FORMAT_RGB);\r
-+            capture=new JmfCameraCapture(320,240,15f,JmfCameraCapture.PIXEL_FORMAT_RGB);\r
-             capture.setCaptureListener(this);\r
--            capture.start();\r
-             //NyARToolkitの準備\r
-             ar_param=new GLNyARParam();\r
-             NyARCode ar_code  =new NyARCode(16,16);\r
-@@ -132,8 +131,9 @@\r
-             nya=new GLNyARSingleDetectMarker(ar_param,ar_code,80.0);\r
-             ar_code.loadFromARFile(CARCODE_FILE);\r
-             //GL対応のRGBラスタオブジェクト\r
--            cap_image=new GLNyARRaster_RGB(gl,ar_param,320,240);\r
--\r
-+            cap_image=new GLNyARRaster_RGB(gl,ar_param);\r
-+            //キャプチャ開始\r
-+            capture.start();\r
-        }catch(Exception e){\r
-             e.printStackTrace();\r
-         }\r
-@@ -166,17 +166,10 @@\r
-     {\r
-         \r
-         try{\r
--            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.\r
--          \r
--    \r
--            //キャプチャしたイメージを加工\r
--            Buffer b=capture.readBuffer();\r
--            //BufferToImage b2i=new BufferToImage((VideoFormat)b.getFormat());\r
--            if(b.getData()==null){\r
-+            if(!cap_image.hasData()){\r
-               return;\r
--            }else{\r
--              //画像準備OK\r
--            }\r
-+            }    \r
-+            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.          \r
-             //画像チェックしてマーカー探して、背景を書く\r
-             boolean is_marker_exist;\r
-             synchronized(cap_image){\r
-@@ -206,7 +199,7 @@\r
-     {\r
-       try{\r
-           synchronized(cap_image){\r
--              cap_image.setRawData((byte[])i_buffer.getData(), true);\r
-+              cap_image.setBuffer(i_buffer, true);\r
-           }\r
-       }catch(Exception e){\r
-           e.printStackTrace();\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/gutil/GLNyARRaster_RGB.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/gutil/GLNyARRaster_RGB.java        (revision 172)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/gutil/GLNyARRaster_RGB.java        (revision 173)\r
-@@ -1,5 +1,6 @@\r
- /**\r
-- * NyARRaster_RGBにOpenGL向け関数を追加したもの\r
-+ * NyARRaster_RGBにOpenGL向け関数を追加したものです。\r
-+ * \r
-  * (c)2008 R.iizuka\r
-  * airmail(at)ebony.plala.or.jp\r
-  * http://nyatla.jp/\r
-@@ -12,37 +13,58 @@\r
- import javax.media.opengl.GL;\r
- import javax.media.opengl.glu.GLU;\r
\r
-+import jp.nyatla.nyartoolkit.NyARException;\r
- import jp.nyatla.nyartoolkit.core.NyARParam;\r
--import jp.nyatla.nyartoolkit.core.raster.NyARRaster_RGB;\r
-+import jp.nyatla.nyartoolkit.jmfutil.*;\r
\r
--public class GLNyARRaster_RGB extends NyARRaster_RGB\r
-+public class GLNyARRaster_RGB extends JmfNyARRaster_RGB\r
- {\r
-     private NyARParam cparam;\r
-     private GL ref_gl;\r
-     private GLU glu;\r
--    public GLNyARRaster_RGB(GL i_ref_gl,NyARParam i_cparam,int i_width,int i_height)\r
-+    private byte[] gl_buf;\r
-+    private int gl_flag;\r
-+\r
-+    public GLNyARRaster_RGB(GL i_ref_gl,NyARParam i_cparam)\r
-     {\r
--        width=i_width;\r
--        height=i_height;\r
-+      super(i_cparam.getX(),i_cparam.getY());\r
-+      gl_flag=GL.GL_RGB;\r
-       cparam=i_cparam;\r
-       ref_gl=i_ref_gl;\r
-       glu=new GLU();\r
--      this.ref_buf=new byte[i_width*i_height*3];\r
-+      this.gl_buf=new byte[width*height*3];\r
-     }\r
--    public void setRawData(byte[] i_buf,boolean i_is_reverse)\r
-+    public void setBuffer(javax.media.Buffer i_buffer,boolean i_is_reverse) throws NyARException\r
-     {\r
-+      super.setBuffer(i_buffer);\r
-+      //メモ:この時点では、ref_dataにはi_bufferの参照値が入ってる。\r
-+      \r
-+      //GL用のデータを準備\r
-       if(i_is_reverse){\r
-           int length=width*3;\r
-           int src_idx=0;\r
-           int dest_idx=(height-1)*length;\r
-           for(int i=0;i<height;i++){\r
--              System.arraycopy(i_buf,src_idx,ref_buf,dest_idx,length);\r
-+              System.arraycopy(ref_buf,src_idx,gl_buf,dest_idx,length);\r
-               src_idx+=length;\r
-               dest_idx-=length;\r
-           }\r
-       }else{\r
--          System.arraycopy(i_buf,0,ref_buf,0,this.ref_buf.length);\r
-+          System.arraycopy(ref_buf,0,gl_buf,0,this.ref_buf.length);\r
-       }\r
-+      //GLのフラグ設定\r
-+      switch(this.pix_type){\r
-+      case GLNyARRaster_RGB.PIXEL_ORDER_BGR:\r
-+            gl_flag=GL.GL_BGR;\r
-+            break;\r
-+      case GLNyARRaster_RGB.PIXEL_ORDER_RGB:\r
-+            gl_flag=GL.GL_RGB;\r
-+            break;\r
-+        default:\r
-+            throw new NyARException();\r
-+      }\r
-+      //ref_bufをgl_bufに差し替える\r
-+      ref_buf=gl_buf;\r
-     }\r
-     /**\r
-      * 保持してるイメージをGLに出力する。\r
-@@ -104,15 +126,13 @@\r
-     {\r
-       float zoomf;\r
-       IntBuffer params=IntBuffer.allocate(4);\r
--      int xsize=cparam.getX();\r
--      int ysize=cparam.getY();\r
-       zoomf = (float)zoom;\r
-         ref_gl.glDisable(GL.GL_TEXTURE_2D);\r
-         ref_gl.glGetIntegerv(GL.GL_VIEWPORT,params);\r
--        ref_gl.glPixelZoom(zoomf * ((float)(params.get(2)) / (float)xsize),-zoomf * ((float)(params.get(3)) / (float)ysize));\r
-+        ref_gl.glPixelZoom(zoomf * ((float)(params.get(2)) / (float)width),-zoomf * ((float)(params.get(3)) / (float)height));\r
-         ref_gl.glRasterPos2i(-1,1);\r
-         ref_gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);\r
-         ByteBuffer buf=ByteBuffer.wrap(ref_buf);\r
--        ref_gl.glDrawPixels(xsize,ysize,GL.GL_BGR,GL.GL_UNSIGNED_BYTE,buf);\r
-+        ref_gl.glDrawPixels(width,height,gl_flag,GL.GL_UNSIGNED_BYTE,buf);\r
-     } \r
- }\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java       (revision 172)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java       (revision 173)\r
-@@ -20,7 +20,7 @@\r
-     {\r
-         setTitle("JmfCaptureTest");\r
-         setBounds(0,0,320+64,240+64);     \r
--        capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXCEL_FORMAT_RGB);\r
-+        capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);\r
-         capture.setCaptureListener(this);\r
-     }\r
\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmfutil/JmfNyARRaster_RGB.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmfutil/JmfNyARRaster_RGB.java      (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmfutil/JmfNyARRaster_RGB.java      (revision 173)\r
-@@ -0,0 +1,110 @@\r
-+/**\r
-+ * RGB形式のJMFバッファをラップするNyARRasterです。\r
-+ * 複数のピクセルの並び順に対応してます。\r
-+ * (c)2008 R.iizuka\r
-+ * airmail(at)ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.jmfutil;\r
-+\r
-+\r
-+import javax.media.format.RGBFormat;\r
-+import java.awt.Dimension;\r
-+import jp.nyatla.nyartoolkit.NyARException;\r
-+import jp.nyatla.nyartoolkit.core.raster.NyARRaster;\r
-+\r
-+\r
-+public class JmfNyARRaster_RGB implements NyARRaster\r
-+{\r
-+    public final static int PIXEL_ORDER_RGB=1;\r
-+    public final static int PIXEL_ORDER_BGR=2;\r
-+    protected int pix_type;\r
-+    private int red_idx;\r
-+    private int green_idx;\r
-+    private int blue_idx;\r
-+    protected byte[] ref_buf;\r
-+    protected int width=0;\r
-+    protected int height=0;\r
-+\r
-+    /**\r
-+     * RGB形式のJMFバッファをラップするオブジェクトをつくります。\r
-+     * 生成直後のオブジェクトはデータを持ちません。\r
-+     * メンバ関数はsetBufferを実行後に使用可能になります。\r
-+     */\r
-+    public JmfNyARRaster_RGB(int i_width,int i_height)\r
-+    {\r
-+      ref_buf=null;\r
-+      width=i_width;\r
-+      height=i_height;\r
-+    }\r
-+    /**\r
-+     * javax.media.Bufferを分析して、その分析結果をNyARRasterに適合する形で保持します。\r
-+     * 関数実行後に外部でi_bufferの内容変更した場合には、再度setBuffer関数を呼び出してください。\r
-+     * @param i_buffer\r
-+     * RGB形式のデータを格納したjavax.media.Bufferオブジェクトを指定してください。\r
-+     * @return\r
-+     * i_bufferをラップしたオブジェクトを返します。\r
-+     * @throws NyARException\r
-+     */\r
-+    public void setBuffer(javax.media.Buffer i_buffer) throws NyARException\r
-+    {\r
-+      RGBFormat fmt=(RGBFormat)i_buffer.getFormat();\r
-+      //データサイズの確認\r
-+        Dimension s=fmt.getSize();\r
-+        if(width!=s.width || height !=s.height){\r
-+          throw new NyARException();\r
-+        }\r
-+      //データ配列の確認\r
-+      red_idx  =fmt.getRedMask()-1;\r
-+      green_idx=fmt.getGreenMask()-1;\r
-+      blue_idx =fmt.getBlueMask()-1;\r
-+      \r
-+      //色配列の特定\r
-+      if(red_idx==0 && blue_idx==2){\r
-+          pix_type=PIXEL_ORDER_RGB;\r
-+      }else if(red_idx==2 && blue_idx==0){\r
-+          pix_type=PIXEL_ORDER_BGR;\r
-+      }else{\r
-+          throw new NyARException("Unknown pixel order.");\r
-+      }       \r
-+        ref_buf=(byte[])i_buffer.getData();\r
-+    }\r
-+    public int getPixelTotal(int i_x,int i_y)\r
-+    {\r
-+        int bp=(i_x+i_y*width)*3;\r
-+        return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);\r
-+    }\r
-+    public int getWidth()\r
-+    {\r
-+        return width;\r
-+    }\r
-+    public int getHeight()\r
-+    {\r
-+        return height;\r
-+    }\r
-+    public void pickRgbArray(int i_x,int i_y,int[] i_rgb)\r
-+    {\r
-+        int bp=(i_x+i_y*width)*3;\r
-+        i_rgb[0]=(ref_buf[bp+red_idx] & 0xff);//R\r
-+        i_rgb[1]=(ref_buf[bp+green_idx] & 0xff);//G\r
-+        i_rgb[2]=(ref_buf[bp+blue_idx] & 0xff);//B\r
-+    }\r
-+    /**\r
-+     * ピクセルの順序タイプを返します。\r
-+     * @return\r
-+     * その値\r
-+     */\r
-+    public int getPixelOrder()\r
-+    {\r
-+      return pix_type;\r
-+    }\r
-+    /**\r
-+     * データを持っているかを返します。\r
-+     * @return\r
-+     */\r
-+    public boolean hasData()\r
-+    {\r
-+      return ref_buf!=null;\r
-+    }\r
-+\r
-+}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java   (revision 172)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java   (revision 173)\r
-@@ -24,6 +24,7 @@\r
\r
- public class JmfCameraCapture\r
- {\r
-+    private Dimension image_size;\r
-     private JmfCaptureListener capture_listener;\r
-     private DataSource jmf_data_source;\r
-     private MonitorStream jmf_monitor_stream;\r
-@@ -31,13 +32,17 @@\r
-     private VideoFormat jmf_video_format;\r
-     \r
-     private Buffer read_buf=new Buffer();\r
--    public static final String PIXCEL_FORMAT_RGB="RGB";\r
-+    public static final String PIXEL_FORMAT_RGB="RGB";\r
-     public JmfCameraCapture(int i_width,int i_height,float i_rate,String i_pixcel_format)\r
-     {\r
-         String encoding = i_pixcel_format;//comboEncoding.getSelectedItem();\r
--        Dimension size = new Dimension(i_width,i_height);\r
--        jmf_video_format = new VideoFormat(encoding, size, Format.NOT_SPECIFIED,null,i_rate);\r
-+        image_size = new Dimension(i_width,i_height);\r
-+        jmf_video_format = new VideoFormat(encoding, image_size, Format.NOT_SPECIFIED,null,i_rate);\r
-     }\r
-+    public Dimension getSize()\r
-+    {\r
-+      return image_size;\r
-+    }\r
-     public javax.media.Buffer readBuffer() throws NyARException\r
-     {\r
-       if(jmf_monitor_stream==null){\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java  (revision 172)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java  (revision 173)\r
-@@ -12,7 +12,7 @@\r
\r
- import jp.nyatla.nyartoolkit.NyARException;\r
- import jp.nyatla.nyartoolkit.jmf.*;\r
--\r
-+import jp.nyatla.nyartoolkit.jmfutil.*;\r
- import java.awt.*;\r
\r
- import jp.nyatla.nyartoolkit.core.*;\r
-@@ -29,13 +29,14 @@\r
-     private final String PARAM_FILE   ="../../Data/camera_para.dat";\r
-     private JmfCameraCapture capture;\r
-     NyARSingleDetectMarker nya;\r
-+    JmfNyARRaster_RGB raster;\r
\r
-     public NyarToolkitLinkTest() throws NyARException,NyARException\r
-     {\r
-         setTitle("JmfCaptureTest");\r
-         setBounds(0,0,320+64,240+64);     \r
-         //キャプチャの準備\r
--        capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXCEL_FORMAT_RGB);\r
-+        capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);\r
-         capture.setCaptureListener(this);\r
-         \r
-         //NyARToolkitの準備\r
-@@ -45,6 +46,8 @@\r
-         ar_param.changeSize(320,240);\r
-         nya=new NyARSingleDetectMarker(ar_param,ar_code,80.0);\r
-         ar_code.loadFromARFile(CARCODE_FILE);\r
-+        //キャプチャイメージ用のラスタを準備\r
-+        raster=new JmfNyARRaster_RGB(320,240);\r
-     }\r
\r
\r
-@@ -52,15 +55,18 @@\r
-     public void onUpdateBuffer(Buffer i_buffer)\r
-     {\r
-       try{\r
--            //キャプチャしたイメージを加工\r
-+            //キャプチャしたバッファをラスタにセット\r
-+          raster.setBuffer(i_buffer);\r
-+\r
-+            //キャプチャしたイメージを表示用に加工\r
-             BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());\r
-             Image img=b2i.createImage(i_buffer);\r
--            Graphics g = getGraphics();\r
--            NyARRaster_RGB ra=NyARRaster_RGB.wrap((byte[])i_buffer.getData(), 320, 240);\r
--            //i_buffer.\r
--            boolean is_marker_exist=nya.detectMarkerLite(ra,100);\r
--            \r
-+\r
-+            Graphics g = getGraphics();            \r
-             double[][] atm=null;\r
-+\r
-+            //マーカー検出\r
-+            boolean is_marker_exist=nya.detectMarkerLite(raster,100);\r
-             if(is_marker_exist){\r
-                 //変換行列を取得\r
-                 atm=nya.getTransmationMatrix().getArray();\r
-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_Blank.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_Blank.java  (revision 172)\r
-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_Blank.java  (revision 173)\r
-@@ -38,16 +38,15 @@\r
-  */\r
- public class NyARRaster_Blank implements NyARRaster\r
- {\r
--    int width;\r
--    int height;\r
-+    private int width;\r
-+    private int height;\r
-     public NyARRaster_Blank(int i_width,int i_height)\r
-     {\r
--      NyARRaster_BGRA new_inst=new NyARRaster_BGRA();\r
--      new_inst.width  =i_width;\r
--      new_inst.height =i_height;\r
-+        width  =i_width;\r
-+        height =i_height;\r
-     }\r
-     //RGBの合計値を返す\r
--    public int getPixcelTotal(int i_x,int i_y)\r
-+    public int getPixelTotal(int i_x,int i_y)\r
-     {\r
-       return 0;\r
-     }\r
-@@ -61,8 +60,8 @@\r
-     }\r
-     public void pickRgbArray(int i_x,int i_y,int[] i_rgb)\r
-     {\r
--      i_rgb[0]=0;\r
--      i_rgb[1]=0;\r
--      i_rgb[2]=0;\r
-+        i_rgb[0]=0;\r
-+        i_rgb[1]=0;\r
-+        i_rgb[2]=0;\r
-     }\r
- }\r
-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_RGB.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_RGB.java    (revision 172)\r
-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_RGB.java    (revision 173)\r
-@@ -39,32 +39,32 @@\r
-     protected int height;\r
-     public static NyARRaster_RGB wrap(byte[] i_buffer,int i_width,int i_height)\r
-     {\r
--      NyARRaster_RGB new_inst=new NyARRaster_RGB();\r
--      new_inst.ref_buf=i_buffer;\r
--      new_inst.width  =i_width;\r
--      new_inst.height =i_height;\r
--      return new_inst;\r
-+        NyARRaster_RGB new_inst=new NyARRaster_RGB();\r
-+        new_inst.ref_buf=i_buffer;\r
-+        new_inst.width  =i_width;\r
-+        new_inst.height =i_height;\r
-+        return new_inst;\r
-     }\r
-     //RGBの合計値を返す\r
--    public int getPixcelTotal(int i_x,int i_y)\r
-+    public int getPixelTotal(int i_x,int i_y)\r
-     {\r
--      int bp=(i_x+i_y*width)*3;\r
--      return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);\r
-+        int bp=(i_x+i_y*width)*3;\r
-+        return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);\r
-     }\r
-     public int getWidth()\r
-     {\r
--      return width;\r
-+        return width;\r
-     }\r
-     public int getHeight()\r
-     {\r
--      return height;\r
-+        return height;\r
-     }\r
-     public void pickRgbArray(int i_x,int i_y,int[] i_rgb)\r
-     {\r
--      int bp=(i_x+i_y*width)*3;\r
--      i_rgb[0]=(ref_buf[bp+0] & 0xff);//R\r
--      i_rgb[1]=(ref_buf[bp+1] & 0xff);//G\r
--      i_rgb[2]=(ref_buf[bp+2] & 0xff);//B\r
-+        int bp=(i_x+i_y*width)*3;\r
-+        i_rgb[0]=(ref_buf[bp+0] & 0xff);//R\r
-+        i_rgb[1]=(ref_buf[bp+1] & 0xff);//G\r
-+        i_rgb[2]=(ref_buf[bp+2] & 0xff);//B\r
-     }\r
- }\r
\r
-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_BGRA.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_BGRA.java   (revision 172)\r
-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_BGRA.java   (revision 173)\r
-@@ -35,25 +35,25 @@\r
- public class NyARRaster_BGRA implements NyARRaster\r
- {\r
-     private byte[] ref_buf;\r
--    int width;\r
--    int height;\r
-+    private int width;\r
-+    private int height;\r
-     public static NyARRaster_BGRA wrap(byte[] i_buffer,int i_width,int i_height)\r
-     {\r
--      NyARRaster_BGRA new_inst=new NyARRaster_BGRA();\r
--      new_inst.ref_buf=i_buffer;\r
--      new_inst.width  =i_width;\r
--      new_inst.height =i_height;\r
--      return new_inst;\r
-+        NyARRaster_BGRA new_inst=new NyARRaster_BGRA();\r
-+        new_inst.ref_buf=i_buffer;\r
-+        new_inst.width  =i_width;\r
-+        new_inst.height =i_height;\r
-+        return new_inst;\r
-     }\r
-     //RGBの合計値を返す\r
--    public int getPixcelTotal(int i_x,int i_y)\r
-+    public int getPixelTotal(int i_x,int i_y)\r
-     {\r
--      int bp=(i_x+i_y*width)*4;\r
--      return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);\r
-+        int bp=(i_x+i_y*width)*4;\r
-+        return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);\r
-     }\r
-     public int getWidth()\r
-     {\r
--      return width;\r
-+        return width;\r
-     }\r
-     public int getHeight()\r
-     {\r
-@@ -61,10 +61,10 @@\r
-     }\r
-     public void pickRgbArray(int i_x,int i_y,int[] i_rgb)\r
-     {\r
--      int bp=(i_x+i_y*width)*4;\r
--      i_rgb[0]=(ref_buf[bp+2] & 0xff);//R\r
--      i_rgb[1]=(ref_buf[bp+1] & 0xff);//G\r
--      i_rgb[2]=(ref_buf[bp+0] & 0xff);//B\r
-+        int bp=(i_x+i_y*width)*4;\r
-+        i_rgb[0]=(ref_buf[bp+2] & 0xff);//R\r
-+        i_rgb[1]=(ref_buf[bp+1] & 0xff);//G\r
-+        i_rgb[2]=(ref_buf[bp+0] & 0xff);//B\r
-     }\r
- }\r
\r
-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java        (revision 172)\r
-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java        (revision 173)\r
-@@ -33,7 +33,7 @@\r
\r
- public interface NyARRaster{\r
-     //RGBの合計値を返す\r
--    public int getPixcelTotal(int i_x,int i_y);\r
-+    public int getPixelTotal(int i_x,int i_y);\r
-     public int getWidth();\r
-     public int getHeight();\r
-     public void pickRgbArray(int i_x,int i_y,int[] i_rgb);\r
-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARLabeling.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARLabeling.java     (revision 172)\r
-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARLabeling.java     (revision 173)\r
-@@ -206,7 +206,7 @@\r
-             int p2=j;\r
-           for(int i = 1; i < lxsize-1; i++, nya_pnt_start_x+=nya_poff_step) {//for(int i = 1; i < lxsize-1; i++, pnt+=poff, pnt2++) {\r
-               //RGBの合計値が閾値より大きいかな?\r
--              if(image.getPixcelTotal(nya_pnt_start_x,nya_pnt_start_y)<=thresht3){\r
-+              if(image.getPixelTotal(nya_pnt_start_x,nya_pnt_start_y)<=thresht3){\r
-                   //pnt1 = ShortPointer.wrap(pnt2, -lxsize);//pnt1 = &(pnt2[-lxsize]);\r
-                   if(label_img[p1][i]>0){//if( *pnt1 > 0 ) {\r
-                       label_img[p2][i]=label_img[p1][i];//*pnt2 = *pnt1;\r
-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARSquare.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARSquare.java       (revision 172)\r
-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARSquare.java       (revision 173)\r
-@@ -36,19 +36,19 @@\r
-  *\r
-  */\r
- public class NyARSquare{\r
--    private NyARMarker    marker;\r
--    public int                area;\r
--    public double[]   pos;\r
--    public double[][] line;  //double[4][3]\r
--    public double[][] vertex;//double[4][2];\r
-+    private NyARMarker marker;\r
-+    public int area;\r
-+    public double[] pos;\r
-+    public double[][] line;  //double[4][3]\r
-+    public double[][] vertex;//double[4][2];\r
-     public NyARSquare(NyARMarker i_marker,double[][] i_attached_line,double[][] i_attached_vertex)\r
-     {\r
--      //ARSquareは、ARMarkerを完全にラップするようにした。\r
--      marker=i_marker;\r
--      area=i_marker.area;\r
--      pos =i_marker.pos;\r
--      line  =i_attached_line;\r
--      vertex=i_attached_vertex;\r
-+        //ARSquareは、ARMarkerを完全にラップするようにした。\r
-+        marker=i_marker;\r
-+        area=i_marker.area;\r
-+        pos =i_marker.pos;\r
-+        line  =i_attached_line;\r
-+        vertex=i_attached_vertex;\r
-     }\r
-     public NyARMarker getMarker()\r
-     {\r
diff --git a/changelog/0.8.20080412.0.txt b/changelog/0.8.20080412.0.txt
deleted file mode 100644 (file)
index 2bccbce..0000000
+++ /dev/null
@@ -1,3158 +0,0 @@
-Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorListener.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorListener.java   (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorListener.java   (revision 178)\r
-@@ -0,0 +1,24 @@\r
-+/**\r
-+ * NyARToolkit\82ÌBehavior\82Ì\83\8a\83X\83i\r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail@ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.java3d.utils;\r
-+\r
-+import javax.media.j3d.*;\r
-+\r
-+public interface NyARSingleMarkerBehaviorListener\r
-+{\r
-+    /**\r
-+     * \82±\82Ì\83\8a\83X\83i\82Í\81A\83\8a\83X\83i\82É\83}\81[\83J\81[\82É\98A\93®\82µ\82Ä\83I\83u\83W\83F\83N\83g\82ð\91\80\8dì\82·\82é\83`\83\83\83\93\83X\82ð\97^\82¦\82Ü\82·\81B\r
-+     * \83\8a\83X\83i\82ÍNyARSingleMarkerBehavior\8aÖ\90\94\93à\82ÌprocessStimulus\8aÖ\90\94\82©\82ç\8cÄ\82Ñ\8fo\82³\82ê\82Ü\82·\81B\r
-+     * \r
-+     * @param i_is_marker_exist\r
-+     * \83}\81[\83J\81[\82ª\91\8dÝ\82·\82é\8fê\8d\87true\81A\91\8dÝ\82µ\82È\82¢\8fê\8d\87\81Afalse\82Å\82·\81B\r
-+     * @param i_transform3d\r
-+     * \83}\81[\83J\81[\82ª\91\8dÝ\82·\82é\8fê\8d\87\81A\82»\82Ì\95Ï\8a·\8ds\97ñ\82ª\8ew\92è\82³\82ê\82Ü\82·\81B\r
-+     * i_is_marker_exist\82ªtrue\82Ì\8e\9e\82¾\82¯\97L\8cø\82Å\82·\81B\r
-+     */\r
-+    public void onUpdate(boolean i_is_marker_exist,Transform3D i_transform3d);\r
-+}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java  (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java  (revision 178)\r
-@@ -0,0 +1,64 @@\r
-+/**\r
-+ * NyARRaster_RGB\82ÉOpenGL\8cü\82¯\8aÖ\90\94\82ð\92Ç\89Á\82µ\82½\82à\82Ì\r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail(at)ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.java3d.utils;\r
-+\r
-+import java.awt.image.*;\r
-+import java.awt.color.*;\r
-+\r
-+import javax.media.j3d.ImageComponent;\r
-+import javax.media.j3d.ImageComponent2D;\r
-+\r
-+\r
-+\r
-+import jp.nyatla.nyartoolkit.NyARException;\r
-+import jp.nyatla.nyartoolkit.core.NyARParam;\r
-+import jp.nyatla.nyartoolkit.jmf.utils.*;\r
-+\r
-+\r
-+public class J3dNyARRaster_RGB extends JmfNyARRaster_RGB\r
-+{\r
-+//    public ImageUpdater updater; \r
-+    private ImageComponent2D imc2d;\r
-+    private byte[] i2d_buf;\r
-+\r
-+    public void setBuffer(javax.media.Buffer i_buffer) throws NyARException\r
-+    {\r
-+        super.setBuffer(i_buffer);\r
-+        //\83\81\83\82\81F\82±\82Ì\8e\9e\93_\82Å\82Í\81Aref_data\82É\82Íi_buffer\82Ì\8eQ\8fÆ\92l\82ª\93ü\82Á\82Ä\82é\81B\r
-+        synchronized(imc2d){\r
-+            //\83L\83\83\83v\83`\83\83\83f\81[\83^\82ði2d\82Ì\83o\83b\83t\83@\82É\83R\83s\81[\82·\82é\81B\81i\82±\82ê\8fÈ\97ª\82µ\82½\82¢\82È\82 \81c\81B\81j\r
-+            System.arraycopy(ref_buf,0,i2d_buf,0,this.i2d_buf.length);\r
-+        }\r
-+      //\82±\82±\82Åref_buf\82Ì\8eQ\8fÆ\92l\82ðref_buf\82Ö\88Ú\93®\r
-+        ref_buf=i2d_buf;\r
-+    }  \r
-+    public J3dNyARRaster_RGB(NyARParam i_cparam)\r
-+    {\r
-+      super(i_cparam.getX(),i_cparam.getY());\r
-+\r
-+      //RGB\82Ì\83\89\83X\83^\82ð\8dì\82é\81B\r
-+//    ColorSpace cs=ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);\r
-+//    ComponentColorModel cm;\r
-+//    cm=new ComponentColorModel(cs,new int[]{8,8,8},false,false,ComponentColorModel.OPAQUE,DataBuffer.TYPE_BYTE);\r
-+//    java.awt.image.WritableRaster raster=cm.createCompatibleWritableRaster(width,height);\r
-+//    i2d_buf=((DataBufferByte)raster.getDataBuffer()).getData();\r
-+//    BufferedImage background_image = new BufferedImage(cm,raster, false, null);\r
-+      BufferedImage background_image = new BufferedImage(width,height,BufferedImage.TYPE_3BYTE_BGR);\r
-+      i2d_buf=((DataBufferByte)background_image.getRaster().getDataBuffer()).getData();\r
-+      //\r
-+      imc2d= new ImageComponent2D(ImageComponent2D.FORMAT_RGB, background_image, true, true);\r
-+      imc2d.setCapability(ImageComponent.ALLOW_IMAGE_WRITE);\r
-+    }\r
-+    /**\r
-+     * \82±\82Ì\83I\83u\83W\83F\83N\83g\82Æ\98A\93®\82·\82éImageComponent2D\83I\83u\83W\83F\83N\83g\82Ì\8eQ\8fÆ\92l\82ð\93¾\82é\81B\r
-+     * @return\r
-+     */\r
-+    public ImageComponent2D getImageComponent2D()\r
-+    {\r
-+      return imc2d;\r
-+    }\r
-+}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARParam.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARParam.java       (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARParam.java       (revision 178)\r
-@@ -0,0 +1,119 @@\r
-+/**\r
-+ * NyARParam\82ÉOpenGL\8cü\82¯\8aÖ\90\94\82ð\92Ç\89Á\82µ\82½\82à\82Ì\r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail(at)ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.java3d.utils;\r
-+\r
-+import jp.nyatla.nyartoolkit.core.*;\r
-+import javax.media.j3d.Transform3D;\r
-+\r
-+public class J3dNyARParam extends NyARParam\r
-+{\r
-+    private double view_distance_min=0.01;//1cm\81`10.0m\r
-+    private double view_distance_max=10.0;\r
-+    private Transform3D m_projection=null;\r
-+    /**\r
-+     * \8e\8b\91Ì\90Ï\82Ì\8bß\82¢\95û\82ð\83\81\81[\83g\83\8b\82Å\8ew\92è\r
-+     * @param i_new_value\r
-+     */\r
-+    public void setViewDistanceMin(double i_new_value)\r
-+    {\r
-+      m_projection=null;//\83L\83\83\83b\83V\83\85\8dÏ\95Ï\90\94\8f\89\8aú\89»\r
-+      view_distance_min=i_new_value;\r
-+    }\r
-+    /**\r
-+     * \8e\8b\91Ì\90Ï\82Ì\89\93\82¢\95û\82ð\83\81\81[\83g\83\8b\82Å\8ew\92è\r
-+     * @param i_new_value\r
-+     */\r
-+    public void setViewDistanceMax(double i_new_value)\r
-+    {\r
-+      m_projection=null;//\83L\83\83\83b\83V\83\85\8dÏ\95Ï\90\94\8f\89\8aú\89»\r
-+      view_distance_max=i_new_value;\r
-+    }\r
-+    /**\r
-+     * void arglCameraFrustumRH(const ARParam *cparam, const double focalmin, const double focalmax, GLdouble m_projection[16])\r
-+     * \8aÖ\90\94\82Ì\92u\82«\8a·\82¦\r
-+     * @param focalmin\r
-+     * @param focalmax\r
-+     * @return\r
-+     */\r
-+    public Transform3D getCameraTransform()\r
-+    {\r
-+      //\8aù\82É\92l\82ª\83L\83\83\83b\83V\83\85\82³\82ê\82Ä\82¢\82½\82ç\82»\82ê\82ð\8eg\82¤\r
-+      if(m_projection!=null){\r
-+          return m_projection;\r
-+      }\r
-+      //\96³\82¯\82ê\82Î\8cv\8eZ\r
-+\r
-+      NyARMat trans_mat=new NyARMat(3,4);\r
-+      NyARMat icpara_mat=new NyARMat(3,4);\r
-+        double[][]  p=new double[3][3], q=new double[4][4];\r
-+      double      width, height;\r
-+        int      i, j;\r
-+      \r
-+        width  = xsize;\r
-+        height = ysize;\r
-+      \r
-+        decompMat(icpara_mat,trans_mat);\r
-+\r
-+        double[][] icpara=icpara_mat.getArray();\r
-+        double[][] trans=trans_mat.getArray();\r
-+      for (i = 0; i < 4; i++) {\r
-+            icpara[1][i] = (height - 1)*(icpara[2][i]) - icpara[1][i];\r
-+        }\r
-+      \r
-+        for(i = 0; i < 3; i++) {\r
-+            for(j = 0; j < 3; j++) {\r
-+                p[i][j] = icpara[i][j] / icpara[2][2];\r
-+            }\r
-+        }\r
-+        //p[0][0],p[1][1]=n\r
-+        //p[0][2],p[1][2]=t+b\r
-+\r
-+        //Projection\82Ì\8cv\8eZ\r
-+        q[0][0] = (2.0 * p[0][0] / (width - 1));\r
-+        q[0][1] = (2.0 * p[0][1] / (width - 1));\r
-+        q[0][2] = -((2.0 * p[0][2] / (width - 1))  - 1.0);\r
-+        q[0][3] = 0.0;\r
-+      \r
-+        q[1][0] = 0.0;\r
-+        q[1][1] = -(2.0 * p[1][1] / (height - 1));\r
-+        q[1][2] = -((2.0 * p[1][2] / (height - 1)) - 1.0);\r
-+        q[1][3] = 0.0;\r
-+      \r
-+        q[2][0] = 0.0;\r
-+        q[2][1] = 0.0;\r
-+        q[2][2] = (view_distance_max + view_distance_min)/(view_distance_min - view_distance_max);\r
-+        q[2][3] = 2.0 * view_distance_max * view_distance_min / (view_distance_min - view_distance_max);\r
-+      \r
-+        q[3][0] = 0.0;\r
-+        q[3][1] = 0.0;\r
-+        q[3][2] = -1.0;\r
-+        q[3][3] = 0.0;\r
-+        \r
-+        q[2][2]=q[2][2]*-1;\r
-+        q[2][3]=q[2][3]*-1;\r
-+        \r
-+        double[] tmp_projection=new double[16];\r
-+        for (i = 0; i < 4; i++) { // Row.\r
-+              // First 3 columns of the current row.\r
-+            for (j = 0; j < 3; j++) { // Column.\r
-+              tmp_projection[i + j*4] =(\r
-+                    q[i][0] * trans[0][j] +\r
-+                    q[i][1] * trans[1][j] +\r
-+                    q[i][2] * trans[2][j]);\r
-+            }\r
-+              // Fourth column of the current row.\r
-+            tmp_projection[i + 3*4]=\r
-+              q[i][0] * trans[0][3] +\r
-+              q[i][1] * trans[1][3] +\r
-+                q[i][2] * trans[2][3] +\r
-+                q[i][3];\r
-+        }\r
-+        m_projection=new Transform3D(tmp_projection);\r
-+        m_projection.transpose();\r
-+        return        m_projection;\r
-+    }\r
-+}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java     (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java     (revision 178)\r
-@@ -0,0 +1,191 @@\r
-+/**\r
-+ * NyARToolkit\82ÌBehavior\83z\83\8b\83_\81[\r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail@ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.java3d.utils;\r
-+\r
-+import java.util.Enumeration;\r
-+\r
-+import javax.media.Buffer;\r
-+import javax.media.j3d.*;\r
-+import javax.vecmath.*;\r
-+\r
-+import jp.nyatla.nyartoolkit.core.NyARParam;\r
-+import jp.nyatla.nyartoolkit.detector.NyARSingleDetectMarker;\r
-+import jp.nyatla.nyartoolkit.jmf.*;\r
-+import jp.nyatla.nyartoolkit.jmf.utils.JmfCameraCapture;\r
-+import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener;\r
-+import jp.nyatla.nyartoolkit.*;\r
-+import jp.nyatla.nyartoolkit.core.*;\r
-+\r
-+/**\r
-+ * NyARToolkit\82Æ\98A\93®\82µ\82½Behavior\82ð\95Ô\8bp\82·\82é\83N\83\89\83X\82Å\82·\81B\r
-+ * \92ñ\8b\9f\82Å\82«\82éBehavior\82Í\81ABackground\82ÆTransformgroup\82Å\82·\81B\r
-+ *\r
-+ */\r
-+public class NyARSingleMarkerBehaviorHolder implements JmfCaptureListener\r
-+{\r
-+    private NyARParam cparam;\r
-+    private JmfCameraCapture capture;\r
-+    private J3dNyARRaster_RGB nya_raster;//\8dÅ\91å3\83X\83\8c\83b\83h\82Å\8b¤\97L\82³\82ê\82é\82Ì\82Å\81A\94r\91¼\90§\8cä\82©\82¯\82é\82±\82Æ\81B\r
-+    private NyARSingleDetectMarker nya;\r
-+    //Behavior\83z\83\8b\83_\r
-+    private NyARBehavior nya_behavior;\r
-+    public NyARSingleMarkerBehaviorHolder(NyARParam i_cparam,float i_rate,NyARCode i_ar_code,double i_marker_width) throws NyARException\r
-+    {\r
-+      nya_behavior=null;\r
-+      cparam=i_cparam;\r
-+      capture=new JmfCameraCapture(cparam.getX(),cparam.getY(),i_rate,JmfCameraCapture.PIXEL_FORMAT_RGB);\r
-+      capture.setCaptureListener(this);\r
-+      nya_raster=new J3dNyARRaster_RGB(cparam);       \r
-+      nya=new NyARSingleDetectMarker(cparam,i_ar_code,i_marker_width);\r
-+      nya_behavior=new NyARBehavior(nya,nya_raster,i_rate);\r
-+    }\r
-+    public Behavior getBehavior()\r
-+    {\r
-+      return nya_behavior;\r
-+    }\r
-+    /**\r
-+     * i_back_ground\82É\83L\83\83\83v\83`\83\83\89æ\91\9c\82ð\93]\91\97\82·\82é\82æ\82¤\82ÉBehavior\82ð\90Ý\92è\82µ\82Ü\82·\81B\r
-+     * i_back_groung\82ÍALLOW_IMAGE_WRITE\91®\90«\82ð\8e\9d\82Â\82à\82Ì\82Å\82 \82é\95K\97v\82ª\82 \82è\82Ü\82·\81B\r
-+     * @param i_back_groung\r
-+     * @return\r
-+     */\r
-+    public void setBackGround(Background i_back_ground)\r
-+    {\r
-+      //\83R\81[\83\8b\90æ\82Å\94r\91¼\90§\8cä\r
-+        nya_behavior.setRelatedBackGround(i_back_ground);\r
-+    }\r
-+    /**\r
-+     * i_trgroup\82Ì\8dÀ\95W\8cn\82ð\83}\81[\83J\81[\82É\82 \82í\82¹\82é\82æ\82¤\82ÉBehavior\82ð\90Ý\92è\82µ\82Ü\82·\81B\r
-+     *\r
-+     */\r
-+    public void setTransformGroup(TransformGroup i_trgroup)\r
-+    {\r
-+      //\83R\81[\83\8b\90æ\82Å\94r\91¼\90§\8cä\r
-+        nya_behavior.setRelatedTransformGroup(i_trgroup);\r
-+    }\r
-+    /**\r
-+     * \8dÀ\95W\8cn\8dÄ\8cv\8eZ\8cã\82É\8cÄ\82Ñ\8fo\82³\82ê\82é\83\8a\83X\83i\82Å\82·\81B\r
-+     * @param i_listener\r
-+     */\r
-+    public void setUpdateListener(NyARSingleMarkerBehaviorListener i_listener)\r
-+    {\r
-+      //\83R\81[\83\8b\90æ\82Å\94r\91¼\90§\8cä\r
-+      nya_behavior.setUpdateListener(i_listener);\r
-+    }\r
-+    /**\r
-+     * \83\89\83X\83^\82ð\8dX\90\83R\81[\83\8b\83o\83b\83N\8aÖ\90\94\82¾\82©\82ç\8cÄ\82ñ\82\82á\82ç\82ß\82¦\r
-+     */\r
-+    public void onUpdateBuffer(Buffer i_buffer)\r
-+    {\r
-+      try{\r
-+          synchronized(nya_raster){\r
-+              nya_raster.setBuffer(i_buffer);\r
-+          }\r
-+      }catch(Exception e){\r
-+          e.printStackTrace();\r
-+      }\r
-+    }\r
-+    public void start() throws NyARException\r
-+    {\r
-+      //\8aJ\8en\r
-+      capture.start();\r
-+    }\r
-+    public void stop()\r
-+    {\r
-+      capture.stop();\r
-+    }\r
-+}\r
-+\r
-+\r
-+class NyARBehavior extends Behavior\r
-+{\r
-+    private NyARSingleDetectMarker related_nya;\r
-+    private TransformGroup trgroup;\r
-+    private Background back_ground;\r
-+    private J3dNyARRaster_RGB raster;\r
-+    private WakeupCondition wakeup;\r
-+    private NyARSingleMarkerBehaviorListener listener;\r
-+    public void initialize()\r
-+    {\r
-+      wakeupOn(wakeup);\r
-+    }\r
-+    /**\r
-+     * i_related_ic2d\82Ì\93à\97e\82Å\92è\8aú\93I\82Éi_back_ground\82ð\8dX\90V\82·\82éBehavior\r
-+     * @param i_back_ground\r
-+     * @param i_related_ic2d\r
-+     */\r
-+    public NyARBehavior(NyARSingleDetectMarker i_related_nya,J3dNyARRaster_RGB i_related_raster,float i_rate)\r
-+    {\r
-+      super();\r
-+      wakeup=new WakeupOnElapsedTime((int)(1000/i_rate));\r
-+      related_nya=i_related_nya;\r
-+      trgroup    =null;\r
-+      raster     =i_related_raster;\r
-+        back_ground=null;\r
-+        listener=null;\r
-+        this.setSchedulingBounds(new BoundingSphere(new Point3d(), 100.0));\r
-+   }\r
-+    public void setRelatedBackGround(Background i_back_ground)\r
-+    {\r
-+      synchronized(raster){\r
-+          back_ground=i_back_ground;\r
-+      }\r
-+    }\r
-+    public void setRelatedTransformGroup(TransformGroup i_trgroup)\r
-+    {\r
-+      synchronized(raster){\r
-+          trgroup=i_trgroup;\r
-+      }       \r
-+    }\r
-+    public void setUpdateListener(NyARSingleMarkerBehaviorListener i_listener)\r
-+    {\r
-+      synchronized(raster){\r
-+          listener=i_listener;\r
-+      }\r
-+    }\r
-+\r
-+    /**\r
-+     * \82¢\82í\82ä\82é\83C\83x\83\93\83g\83n\83\93\83h\83\89\r
-+     */\r
-+    public void processStimulus(Enumeration criteria)\r
-+    {\r
-+      try{\r
-+            synchronized(raster){\r
-+              Transform3D t3d=null;\r
-+              boolean is_marker_exist=false;\r
-+              if(back_ground!=null){\r
-+                    back_ground.setImage(raster.getImageComponent2D());                   \r
-+              }\r
-+                if(raster.hasData()){\r
-+                    is_marker_exist=related_nya.detectMarkerLite(raster, 100);\r
-+                    if(is_marker_exist){\r
-+                        NyARMat nymat=related_nya.getTransmationMatrix();\r
-+                        double[][] src=nymat.getArray();\r
-+                        Matrix4d matrix=new Matrix4d(\r
-+                             src[0][0],-src[1][0],-src[2][0],0,\r
-+                            -src[0][1], src[1][1], src[2][1],0,\r
-+                            -src[0][2], src[1][2], src[2][2],0,\r
-+                            -src[0][3], src[1][3], src[2][3],1);\r
-+                        matrix.transpose();\r
-+                        t3d=new Transform3D(matrix);\r
-+                        if(trgroup!=null){\r
-+                            trgroup.setTransform(t3d);\r
-+                        }\r
-+                    }\r
-+                }\r
-+                if(listener!=null)\r
-+                {\r
-+                    listener.onUpdate(is_marker_exist, t3d);\r
-+                }\r
-+            }\r
-+            wakeupOn(wakeup);            \r
-+      }catch(Exception e){\r
-+          e.printStackTrace();\r
-+      }\r
-+    }\r
-+}\r
-+\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java        (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java        (revision 178)\r
-@@ -0,0 +1,148 @@\r
-+/**\r
-+ * Java3D\83T\83\93\83v\83\8b\83v\83\8d\83O\83\89\83\80\r
-+ * \83V\83\93\83O\83\8b\83}\81[\83J\81[\92Ç\90Õ\97p\82ÌBehavior\82ð\8eg\82Á\82Ä\81A\94w\8ci\82Æ\82P\8cÂ\82Ì\83}\81[\83J\81[\82É\98A\93®\82µ\82½TransformGroup\r
-+ * \82ð\93®\82©\82µ\82Ü\82·\81B\r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail@ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.java3d.sample;\r
-+\r
-+import java.awt.BorderLayout;\r
-+import javax.media.j3d.*;\r
-+\r
-+import com.sun.j3d.utils.universe.*;\r
-+import java.awt.*;\r
-+import javax.swing.JFrame;\r
-+import javax.vecmath.*;\r
-+\r
-+import jp.nyatla.nyartoolkit.core.*;\r
-+import jp.nyatla.nyartoolkit.java3d.utils.*;\r
-+\r
-+import com.sun.j3d.utils.geometry.ColorCube;\r
-+\r
-+public class NyARJava3D extends JFrame implements NyARSingleMarkerBehaviorListener \r
-+{\r
-+    private final String CARCODE_FILE ="../../Data/patt.hiro";\r
-+    private final String PARAM_FILE   ="../../Data/camera_para.dat";\r
-+    //NyARToolkit\8aÖ\8cW\r
-+    private NyARSingleMarkerBehaviorHolder nya_behavior;\r
-+    private J3dNyARParam ar_param;\r
-+    //universe\8aÖ\8cW\r
-+    private Canvas3D canvas;\r
-+    private Locale locale;\r
-+    private VirtualUniverse universe;\r
-+    public static void main(String[] args)\r
-+    {\r
-+      try{\r
-+            NyARJava3D frame = new NyARJava3D();\r
-+                \r
-+            frame.setVisible(true);\r
-+            Insets ins=frame.getInsets();\r
-+            frame.setSize(320+ins.left+ins.right,240+ins.top+ins.bottom);\r
-+            frame.startCapture();\r
-+            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
-+      }catch(Exception e){\r
-+          e.printStackTrace();\r
-+      }\r
-+    }\r
-+    public void onUpdate(boolean i_is_marker_exist,Transform3D i_transform3d)\r
-+    {\r
-+      /*\r
-+       * TODO:Please write your behavior operation code here.\r
-+       * \83}\81[\83J\81[\82Ì\8ep\90¨\82ð\8c³\82É\91¼\82Ì\82RD\83I\83u\83W\83F\83N\83g\82ð\91\80\8dì\82·\82é\82Æ\82«\82Í\81A\82±\82±\82É\8f\88\97\9d\82ð\8f\91\82«\82Ü\82·\81B*/\r
-+      \r
-+    }\r
-+    public void startCapture() throws Exception\r
-+    {\r
-+      nya_behavior.start();           \r
-+    }\r
-+    public NyARJava3D() throws Exception\r
-+    {\r
-+      super("Java3D Example NyARToolkit");\r
-+\r
-+        //NyARToolkit\82Ì\8f\80\94õ\r
-+        NyARCode ar_code  =new NyARCode(16,16);\r
-+        ar_code.loadFromARFile(CARCODE_FILE);\r
-+        ar_param=new J3dNyARParam();\r
-+        ar_param.loadFromARFile(PARAM_FILE);\r
-+        ar_param.changeSize(320,240);\r
-+        \r
-+      //locale\82Ì\8dì\90¬\82Ælocate\82Æview\82Ì\90Ý\92è\r
-+        universe = new VirtualUniverse();\r
-+        locale = new Locale( universe );\r
-+        canvas=new Canvas3D( SimpleUniverse.getPreferredConfiguration());\r
-+        View view = new View();\r
-+        ViewPlatform viewPlatform = new ViewPlatform();\r
-+        view.attachViewPlatform( viewPlatform );\r
-+        view.addCanvas3D(canvas);\r
-+        view.setPhysicalBody( new PhysicalBody() );\r
-+        view.setPhysicalEnvironment( new PhysicalEnvironment());\r
-+\r
-+        //\8e\8b\8aE\82Ì\90Ý\92è(\83J\83\81\83\89\90Ý\92è\82©\82ç\8eæ\93¾)\r
-+        Transform3D camera_3d=ar_param.getCameraTransform();\r
-+        view.setCompatibilityModeEnable(true);\r
-+        view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);\r
-+        view.setLeftProjection(camera_3d);\r
-+        \r
-+        //\8e\8b\93_\90Ý\92è(0,0,0\82©\82ç\81AY\8e²\82ð180\93x\89ñ\93]\82µ\82ÄZ+\95û\8cü\82ð\8cü\82­\82æ\82¤\82É\82·\82é\81B)\r
-+        TransformGroup viewGroup = new TransformGroup();\r
-+        Transform3D viewTransform = new Transform3D();\r
-+        viewTransform.rotY(Math.PI);\r
-+        viewTransform.setTranslation(new Vector3d(0.0,0.0,0.0));\r
-+        viewGroup.setTransform( viewTransform );\r
-+        viewGroup.addChild( viewPlatform );\r
-+        BranchGroup viewRoot = new BranchGroup();\r
-+        viewRoot.addChild( viewGroup );\r
-+        locale.addBranchGraph( viewRoot );\r
-+\r
-+        \r
-+      //\83o\83b\83N\83O\83\89\83E\83\93\83h\82Ì\8dì\90¬\r
-+        Background background =new Background();\r
-+      BoundingSphere bounds = new BoundingSphere();\r
-+        bounds.setRadius( 10.0 ); \r
-+      background.setApplicationBounds(bounds);\r
-+      background.setImageScaleMode(Background.SCALE_FIT_ALL);\r
-+      background.setCapability(Background.ALLOW_IMAGE_WRITE);\r
-+      BranchGroup root = new BranchGroup();\r
-+      root.addChild(background);\r
-+      \r
-+      //TransformGroup\82Å\88Í\82Á\82½\83V\81[\83\93\83O\83\89\83t\82Ì\8dì\90¬\r
-+      TransformGroup transform=new TransformGroup();\r
-+      transform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);\r
-+      transform.addChild(createSceneGraph());\r
-+      root.addChild(transform);\r
-+              \r
-+        //NyARToolkit\82ÌBehavior\82ð\8dì\82é\81B(\83}\81[\83J\81[\83T\83C\83Y\82Í\83\81\81[\83g\83\8b\82Å\8ew\92è\82·\82é\82±\82Æ)\r
-+      nya_behavior=new NyARSingleMarkerBehaviorHolder(ar_param,30f,ar_code,0.08);\r
-+      //Behavior\82É\98A\93®\82·\82é\83O\83\8b\81[\83v\82ð\83Z\83b\83g\r
-+      nya_behavior.setTransformGroup(transform);\r
-+      nya_behavior.setBackGround(background);\r
-+      \r
-+      //\8fo\97\88\82½behavior\82ð\83Z\83b\83g\r
-+      root.addChild(nya_behavior.getBehavior());\r
-+      nya_behavior.setUpdateListener(this);\r
-+      \r
-+      //\95\\8e¦\83u\83\89\83\93\83`\82ðLocate\82É\83Z\83b\83g\r
-+      locale.addBranchGraph(root);\r
-+      \r
-+      //\83E\83C\83\93\83h\83E\82Ì\90Ý\92è\r
-+      setLayout(new BorderLayout());\r
-+      add(canvas,BorderLayout.CENTER);\r
-+    }\r
-+    /**\r
-+     * \83V\81[\83\93\83O\83\89\83t\82ð\8dì\82Á\82Ä\81A\82»\82Ì\83m\81[\83h\82ð\95Ô\82·\81B\r
-+     * \82±\82Ì\83m\81[\83h\82Í40mm\82Ì\90F\82Â\82«\83i\83^\83f\83R\83R\82ð\95\\8e¦\82·\82é\83V\81[\83\93\81B\82\9a\8e²\82ð\8aî\8f\80\82É20mm\8fã\82É\95\82\82©\82¹\82Ä\82é\81B\r
-+     * @return\r
-+     */\r
-+    private Node createSceneGraph()\r
-+    {\r
-+      TransformGroup tg=new TransformGroup();\r
-+        Transform3D mt=new Transform3D();\r
-+        mt.setTranslation(new Vector3d(0.00,0.0,20*0.001));\r
-+        // \91å\82«\82³ 40mm\82Ì\90F\95t\82«\97§\95û\91Ì\82ð\81AZ\8e²\8fã\82Å20mm\93®\82©\82µ\82Ä\94z\92u\81j\r
-+        tg.setTransform(mt);\r
-+        tg.addChild(new ColorCube(20*0.001));\r
-+        return tg;\r
-+    }\r
-+}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java      (revision 174)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java      (revision 178)\r
-@@ -1,217 +0,0 @@\r
--/**\r
-- * simpleLite\82Æ\93¯\82\82æ\82¤\82È\83e\83X\83g\83v\83\8d\83O\83\89\83\80\r
-- * \83}\81[\83J\81[\82Ì\88ê\92v\93x\82Ì\8dÅ\92á\92l\82ð\83`\83F\83b\83N\82·\82é\82Æ\82±\82ë\82ð\94²\82¢\82½\82Ì\82Å\81A\93¯\82\83}\81[\83J\81[\82ð\91å\97Ê\82É\r
-- * \8c\9f\8fo\82·\82é\82Æ\96Ê\94\92\82¢\82±\82Æ\82É\82È\82è\82Ü\82·\81B\r
-- * (c)2008 R.iizuka\r
-- * airmail(at)ebony.plala.or.jp\r
-- * http://nyatla.jp/\r
-- */\r
--import java.awt.event.WindowAdapter;\r
--import java.awt.event.WindowEvent;\r
--import java.awt.*;\r
--\r
--import javax.media.Buffer;\r
--\r
--import javax.media.opengl.GL;\r
--import javax.media.opengl.GLAutoDrawable;\r
--import javax.media.opengl.GLEventListener;\r
--import javax.media.opengl.GLCanvas;\r
--\r
--import com.sun.opengl.util.Animator;\r
--\r
--import jp.nyatla.nyartoolkit.core.NyARCode;\r
--\r
--import jp.nyatla.nyartoolkit.jmf.JmfCameraCapture;\r
--import jp.nyatla.nyartoolkit.jmf.JmfCaptureListener;\r
--import jp.nyatla.nyartoolkit.gutil.*;\r
--\r
--\r
--public class JavaSimpleLite implements GLEventListener,JmfCaptureListener\r
--{\r
--    private final String CARCODE_FILE ="../../Data/patt.hiro";\r
--    private final String PARAM_FILE   ="../../Data/camera_para.dat";\r
--       \r
--    \r
--    private Animator animator;\r
--    private GLNyARRaster_RGB cap_image;\r
--    \r
--    private JmfCameraCapture capture;\r
--    private GL gl;\r
--    //NyARToolkit\8aÖ\8cW\r
--    private GLNyARSingleDetectMarker nya;\r
--    private GLNyARParam ar_param;\r
--    /**\r
--     * \97§\95û\91Ì\82ð\8f\91\82­\r
--     *\r
--     */\r
--    void drawCube()\r
--    {\r
--      // Colour cube data.\r
--      int polyList = 0;\r
--      float fSize = 0.5f;\r
--      int f, i;       \r
--      float[][] cube_vertices=new float[][]{\r
--              {1.0f, 1.0f, 1.0f}, {1.0f, -1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f},\r
--              {1.0f, 1.0f, -1.0f}, {1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}\r
--      };\r
--      float[][] cube_vertex_colors=new float[][]{\r
--      {1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 1.0f, 1.0f},\r
--      {1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}\r
--      };\r
--      int cube_num_faces = 6;\r
--      short[][] cube_faces =new short[][]{\r
--      {3, 2, 1, 0}, {2, 3, 7, 6}, {0, 1, 5, 4}, {3, 0, 4, 7}, {1, 2, 6, 5}, {4, 5, 6, 7}\r
--      };\r
--      \r
--      if (polyList==0) {\r
--            polyList = gl.glGenLists (1);\r
--            gl.glNewList(polyList, GL.GL_COMPILE);\r
--            gl.glBegin(GL.GL_QUADS);\r
--            for (f = 0; f < cube_num_faces; f++)\r
--                for (i = 0; i < 4; i++) {\r
--                    gl.glColor3f (cube_vertex_colors[cube_faces[f][i]][0], cube_vertex_colors[cube_faces[f][i]][1], cube_vertex_colors[cube_faces[f][i]][2]);\r
--                    gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);\r
--                }\r
--            gl.glEnd();\r
--            gl.glColor3f(0.0f, 0.0f, 0.0f);\r
--            for (f = 0; f < cube_num_faces; f++) {\r
--              gl.glBegin (GL.GL_LINE_LOOP);\r
--              for (i = 0; i < 4; i++)\r
--                      gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);\r
--              gl.glEnd ();\r
--            }\r
--            gl.glEndList ();\r
--      }\r
--      \r
--      gl.glPushMatrix(); // Save world coordinate system.\r
--      gl.glTranslatef(0.0f, 0.0f, 0.5f); // Place base of cube on marker surface.\r
--      gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f); // Rotate about z axis.\r
--      gl.glDisable(GL.GL_LIGHTING);   // Just use colours.\r
--      gl.glCallList(polyList);        // Draw the cube.\r
--      gl.glPopMatrix();       // Restore world coordinate system.\r
--      \r
--    }\r
--    \r
--    \r
--    \r
--    public JavaSimpleLite()\r
--    {\r
--        Frame frame = new Frame("Java simpleLite with NyARToolkit");\r
--\r
--\r
--        // 3D\82ð\95`\89æ\82·\82é\83R\83\93\83|\81[\83l\83\93\83g\r
--        GLCanvas canvas = new GLCanvas();\r
--        frame.add(canvas);\r
--        canvas.addGLEventListener(this);\r
--        frame.addWindowListener(new WindowAdapter() {\r
--                public void windowClosing(WindowEvent e) {\r
--                    System.exit(0);\r
--                }\r
--            });\r
--\r
--        frame.setVisible(true);\r
--        Insets ins=frame.getInsets();\r
--        frame.setSize(320+ins.left+ins.right,240+ins.top+ins.bottom);\r
--        canvas.setBounds(ins.left,ins.top,320,240);\r
--    }\r
--\r
--    public void init(GLAutoDrawable drawable) {\r
--        gl = drawable.getGL();\r
--        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);\r
--        //NyARToolkit\82Ì\8f\80\94õ\r
--        try{\r
--            //\83L\83\83\83v\83`\83\83\82Ì\8f\80\94õ\r
--            capture=new JmfCameraCapture(320,240,15f,JmfCameraCapture.PIXEL_FORMAT_RGB);\r
--            capture.setCaptureListener(this);\r
--            //NyARToolkit\82Ì\8f\80\94õ\r
--            ar_param=new GLNyARParam();\r
--            NyARCode ar_code  =new NyARCode(16,16);\r
--            ar_param.loadFromARFile(PARAM_FILE);\r
--            ar_param.changeSize(320,240);\r
--            nya=new GLNyARSingleDetectMarker(ar_param,ar_code,80.0);\r
--            ar_code.loadFromARFile(CARCODE_FILE);\r
--            //GL\91Î\89\9e\82ÌRGB\83\89\83X\83^\83I\83u\83W\83F\83N\83g\r
--            cap_image=new GLNyARRaster_RGB(gl,ar_param);\r
--            //\83L\83\83\83v\83`\83\83\8aJ\8en\r
--            capture.start();\r
--       }catch(Exception e){\r
--            e.printStackTrace();\r
--        }\r
--        animator = new Animator(drawable);\r
--\r
--        animator.start();\r
--\r
--    }\r
--\r
--    public void reshape(GLAutoDrawable drawable,\r
--        int x, int y,\r
--        int width, int height)\r
--    {\r
--      float ratio = (float)height / (float)width;\r
--        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);\r
--        gl.glViewport(0, 0,  width, height);\r
--\r
--        //\8e\8b\91Ì\90Ï\82Ì\90Ý\92è\r
--        gl.glMatrixMode(GL.GL_PROJECTION);\r
--        gl.glLoadIdentity();\r
--        gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,\r
--                   5.0f, 40.0f);\r
--        //\8c©\82é\88Ê\92u\r
--        gl.glMatrixMode(GL.GL_MODELVIEW);\r
--        gl.glLoadIdentity();\r
--        gl.glTranslatef(0.0f, 0.0f, -10.0f);\r
--    }\r
--\r
--    public void display(GLAutoDrawable drawable)\r
--    {\r
--        \r
--        try{\r
--            if(!cap_image.hasData()){\r
--              return;\r
--            }    \r
--            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.          \r
--            //\89æ\91\9c\83`\83F\83b\83N\82µ\82Ä\83}\81[\83J\81[\92T\82µ\82Ä\81A\94w\8ci\82ð\8f\91\82­\r
--            boolean is_marker_exist;\r
--            synchronized(cap_image){\r
--              is_marker_exist=nya.detectMarkerLite(cap_image,100);\r
--              //\94w\8ci\82ð\8f\91\82­\r
--              cap_image.glDispImage(1.0);\r
--            }\r
--            //\82 \82Á\82½\82ç\97§\95û\91Ì\82ð\8f\91\82­\r
--            if(is_marker_exist){\r
--                // Projection transformation.\r
--                gl.glMatrixMode(GL.GL_PROJECTION);\r
--                gl.glLoadMatrixd(ar_param.getCameraFrustumRH(),0);\r
--                gl.glMatrixMode(GL.GL_MODELVIEW);\r
--                // Viewing transformation.\r
--                gl.glLoadIdentity();\r
--                gl.glLoadMatrixd(nya.getCameraViewRH(),0);\r
--\r
--            \r
--                // All other lighting and geometry goes here.\r
--                drawCube();\r
--            }\r
--        }catch(Exception e){\r
--            e.printStackTrace();\r
--        }\r
--    }\r
--    public void onUpdateBuffer(Buffer i_buffer)\r
--    {\r
--      try{\r
--          synchronized(cap_image){\r
--              cap_image.setBuffer(i_buffer, true);\r
--          }\r
--      }catch(Exception e){\r
--          e.printStackTrace();\r
--      }        \r
--    }\r
--\r
--    public void displayChanged(GLAutoDrawable drawable,\r
--                               boolean modeChanged,\r
--                               boolean deviceChanged) {}\r
--\r
--    public static void main(String[] args) {\r
--        new JavaSimpleLite();\r
--    }\r
--}\r
--\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java   (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java   (revision 178)\r
-@@ -0,0 +1,76 @@\r
-+/**\r
-+ * NyARRaster_RGB\82ÉOpenGL\97p\82Ì\83f\81[\83^\95Ï\8a·\8b@\94\\82ð\92Ç\89Á\82µ\82½\82à\82Ì\82Å\82·\81B\r
-+ * \r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail(at)ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.jogl.utils;\r
-+\r
-+import javax.media.format.RGBFormat;\r
-+import javax.media.opengl.GL;\r
-+import jp.nyatla.nyartoolkit.NyARException;\r
-+import jp.nyatla.nyartoolkit.jmf.utils.*;\r
-+import jp.nyatla.nyartoolkit.core.*;\r
-+\r
-+public class GLNyARRaster_RGB extends JmfNyARRaster_RGB\r
-+{\r
-+    private byte[] gl_buf;\r
-+    private int gl_flag;\r
-+\r
-+    public GLNyARRaster_RGB(GL i_ref_gl,NyARParam i_param)\r
-+    {\r
-+      super(i_param.getX(),i_param.getY());\r
-+      this.gl_flag=GL.GL_RGB;\r
-+      this.gl_buf=new byte[this.width*this.height*3];\r
-+    }\r
-+    public void setBuffer(javax.media.Buffer i_buffer,boolean i_is_reverse) throws NyARException\r
-+    {\r
-+      //JMF\83f\81[\83^\82Å\83t\83H\81[\83}\83b\83g\83v\83\8d\83p\83e\83B\82ð\8f\89\8aú\89»\r
-+      initFormatProperty((RGBFormat)i_buffer.getFormat());\r
-+      \r
-+      byte[] src_buf=(byte[])i_buffer.getData();\r
-+      //GL\97p\82Ì\83f\81[\83^\82ð\8f\80\94õ\r
-+      if(i_is_reverse){\r
-+          int length=this.width*3;\r
-+          int src_idx=0;\r
-+          int dest_idx=(this.height-1)*length;\r
-+          for(int i=0;i<this.height;i++){\r
-+              System.arraycopy(src_buf,src_idx,this.gl_buf,dest_idx,length);\r
-+              src_idx+=length;\r
-+              dest_idx-=length;\r
-+          }\r
-+      }else{\r
-+          System.arraycopy(src_buf,0,gl_buf,0,src_buf.length);\r
-+      }\r
-+      //GL\82Ì\83t\83\89\83O\90Ý\92è\r
-+      switch(this.pix_type){\r
-+      case GLNyARRaster_RGB.PIXEL_ORDER_BGR:\r
-+          this.gl_flag=GL.GL_BGR;\r
-+            break;\r
-+      case GLNyARRaster_RGB.PIXEL_ORDER_RGB:\r
-+          this.gl_flag=GL.GL_RGB;\r
-+            break;\r
-+        default:\r
-+            throw new NyARException();\r
-+      }\r
-+      //ref_buf\82ðgl_buf\82É\8d·\82µ\91Ö\82¦\82é\r
-+      ref_buf=gl_buf;\r
-+    }\r
-+    /**\r
-+     * GL\82Å\82»\82Ì\82Ü\82Ü\95`\89æ\82Å\82«\82éRGB\83o\83b\83t\83@\82ð\95Ô\82·\81B\r
-+     * @return\r
-+     */\r
-+    public byte[] getGLRgbArray()\r
-+    {\r
-+      return this.ref_buf;\r
-+    }\r
-+    /**\r
-+     * GL\97p\82ÌRGB\83o\83b\83t\83@\82Ì\83o\83C\83g\95À\82Ñ\83^\83C\83v\82ð\95Ô\82·\81B\r
-+     * @return\r
-+     */\r
-+    public int getGLPixelFlag()\r
-+    {\r
-+      return this.gl_flag;\r
-+    }\r
-+}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java   (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java   (revision 178)\r
-@@ -0,0 +1,57 @@\r
-+/**\r
-+ * NyARSingleDetectMarker\82ÉOpenGL\8cü\82¯\8aÖ\90\94\82ð\92Ç\89Á\82µ\82½\82à\82Ì\r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail(at)ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.jogl.utils;\r
-+\r
-+import jp.nyatla.nyartoolkit.NyARException;\r
-+import jp.nyatla.nyartoolkit.core.NyARCode;\r
-+import jp.nyatla.nyartoolkit.core.NyARMat;\r
-+import jp.nyatla.nyartoolkit.core.NyARParam;\r
-+import jp.nyatla.nyartoolkit.detector.*;\r
-+\r
-+public class GLNyARSingleDetectMarker extends NyARSingleDetectMarker\r
-+{\r
-+    private double view_scale_factor=0.025;//#define VIEW_SCALEFACTOR         0.025           // 1.0 ARToolKit unit becomes 0.025 of my OpenGL units.\r
-+    public GLNyARSingleDetectMarker(NyARParam i_param,NyARCode i_code,double i_marker_width)\r
-+    {\r
-+      super(i_param,i_code,i_marker_width);   \r
-+    }\r
-+    public void setScaleFactor(double i_new_value)\r
-+    {\r
-+      view_scale_factor=i_new_value;\r
-+    }\r
-+    //    public static void arglCameraViewRH(const double para[3][4], GLdouble m_modelview[16], const double scale)\r
-+    public double[] getCameraViewRH() throws NyARException\r
-+    {\r
-+      //\8dÀ\95W\82ð\8cv\8eZ\r
-+      NyARMat mat=getTransmationMatrix();\r
-+      //\8ds\97ñ\95Ï\8a·\r
-+      double[][] para=mat.getArray();\r
-+      double[] result=new double[16];\r
-+      result[0 + 0*4] = para[0][0]; // R1C1\r
-+      result[0 + 1*4] = para[0][1]; // R1C2\r
-+      result[0 + 2*4] = para[0][2];\r
-+      result[0 + 3*4] = para[0][3];\r
-+      result[1 + 0*4] = -para[1][0]; // R2\r
-+      result[1 + 1*4] = -para[1][1];\r
-+      result[1 + 2*4] = -para[1][2];\r
-+      result[1 + 3*4] = -para[1][3];\r
-+      result[2 + 0*4] = -para[2][0]; // R3\r
-+      result[2 + 1*4] = -para[2][1];\r
-+      result[2 + 2*4] = -para[2][2];\r
-+      result[2 + 3*4] = -para[2][3];\r
-+      result[3 + 0*4] = 0.0;\r
-+      result[3 + 1*4] = 0.0;\r
-+      result[3 + 2*4] = 0.0;\r
-+      result[3 + 3*4] = 1.0;\r
-+      if (view_scale_factor != 0.0) {\r
-+          result[12] *= view_scale_factor;\r
-+          result[13] *= view_scale_factor;\r
-+          result[14] *= view_scale_factor;\r
-+      }\r
-+      return result;\r
-+    }\r
-+}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java (revision 178)\r
-@@ -0,0 +1,99 @@\r
-+/**\r
-+ * NyARToolkit\97p\82ÌJOGL\8ex\89\87\8aÖ\90\94\8cQ\r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail(at)ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.jogl.utils;\r
-+import java.nio.ByteBuffer;\r
-+import java.nio.IntBuffer;\r
-+\r
-+import javax.media.opengl.GL;\r
-+import javax.media.opengl.glu.GLU;\r
-+\r
-+import jp.nyatla.nyartoolkit.core.*;\r
-+\r
-+public class NyARGLUtil\r
-+{\r
-+    private NyARParam ar_param;\r
-+    private javax.media.opengl.GL gl;\r
-+    private javax.media.opengl.glu.GLU glu;\r
-+    public NyARGLUtil(javax.media.opengl.GL i_gl,NyARParam i_camera_param)\r
-+    {\r
-+      this.ar_param=i_camera_param;\r
-+      this.gl=i_gl;\r
-+      this.glu=new GLU();\r
-+    }\r
-+    /**\r
-+     * GLNyARRaster_RGB\82ð\83o\83b\83N\83O\83\89\83E\83\93\83h\82É\8f\91\82«\8fo\82·\81B\r
-+     * @param image\r
-+     * @param zoom\r
-+     */\r
-+    public void drawBackGround(GLNyARRaster_RGB i_raster,double i_zoom)\r
-+    {\r
-+      IntBuffer texEnvModeSave=IntBuffer.allocate(1); \r
-+      boolean lightingSave;\r
-+      boolean depthTestSave;\r
-+      javax.media.opengl.GL gl_=this.gl;\r
-+      \r
-+      // Prepare an orthographic projection, set camera position for 2D drawing, and save GL state.\r
-+      gl_.glGetTexEnviv(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, texEnvModeSave); // Save GL texture environment mode.\r
-+      if (texEnvModeSave.array()[0] != GL.GL_REPLACE){\r
-+      gl_.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);\r
-+      }\r
-+      lightingSave = gl_.glIsEnabled(GL.GL_LIGHTING);                 // Save enabled state of lighting.\r
-+      if (lightingSave == true){\r
-+            gl_.glDisable(GL.GL_LIGHTING);\r
-+      }\r
-+      depthTestSave = gl_.glIsEnabled(GL.GL_DEPTH_TEST);              // Save enabled state of depth test.\r
-+      if (depthTestSave == true){\r
-+            gl_.glDisable(GL.GL_DEPTH_TEST);\r
-+      }\r
-+      gl_.glMatrixMode(GL.GL_PROJECTION);\r
-+      gl_.glPushMatrix();\r
-+      gl_.glLoadIdentity();\r
-+      glu.gluOrtho2D(0.0,ar_param.getX(),0.0,ar_param.getY());\r
-+      gl_.glMatrixMode(GL.GL_MODELVIEW);\r
-+      gl_.glPushMatrix();\r
-+      gl_.glLoadIdentity();\r
-+      arglDispImageStateful(i_raster,i_zoom);\r
-+\r
-+\r
-+      // Restore previous projection, camera position, and GL state.\r
-+      gl_.glMatrixMode(GL.GL_PROJECTION);\r
-+      gl_.glPopMatrix();\r
-+      gl_.glMatrixMode(GL.GL_MODELVIEW);\r
-+      gl_.glPopMatrix();\r
-+        if (depthTestSave){\r
-+            gl_.glEnable(GL.GL_DEPTH_TEST);                   // Restore enabled state of depth test.\r
-+        }\r
-+        if (lightingSave){\r
-+            gl_.glEnable(GL.GL_LIGHTING);                     // Restore enabled state of lighting.\r
-+        }\r
-+      if (texEnvModeSave.get(0) != GL.GL_REPLACE){\r
-+            gl_.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, texEnvModeSave.get(0)); // Restore GL texture environment mode.\r
-+      }\r
-+      gl_.glEnd();\r
-+    }\r
-+    /**\r
-+     * arglDispImageStateful\8aÖ\90\94\83\82\83h\83L\r
-+     * @param image\r
-+     * @param zoom\r
-+     */\r
-+    private void arglDispImageStateful(GLNyARRaster_RGB i_raster,double zoom)\r
-+    {\r
-+      javax.media.opengl.GL gl_=this.gl;\r
-+      int width =i_raster.getWidth();\r
-+      int height=i_raster.getHeight();\r
-+      float zoomf;\r
-+      IntBuffer params=IntBuffer.allocate(4);\r
-+      zoomf = (float)zoom;\r
-+      gl_.glDisable(GL.GL_TEXTURE_2D);\r
-+      gl_.glGetIntegerv(GL.GL_VIEWPORT,params);\r
-+      gl_.glPixelZoom(zoomf * ((float)(params.get(2)) / (float)width),-zoomf * ((float)(params.get(3)) / (float)height));\r
-+      gl_.glRasterPos2f(0.0f,(float)height);\r
-+      gl_.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);\r
-+        ByteBuffer buf=ByteBuffer.wrap(i_raster.getGLRgbArray());\r
-+        gl_.glDrawPixels(width,height,i_raster.getGLPixelFlag(),GL.GL_UNSIGNED_BYTE,buf);\r
-+    }     \r
-+}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARParam.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARParam.java        (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARParam.java        (revision 178)\r
-@@ -0,0 +1,99 @@\r
-+/**\r
-+ * NyARParam\82ÉOpenGL\8cü\82¯\8aÖ\90\94\82ð\92Ç\89Á\82µ\82½\82à\82Ì\r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail(at)ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.jogl.utils;\r
-+\r
-+import jp.nyatla.nyartoolkit.core.*;\r
-+public class GLNyARParam extends NyARParam\r
-+{\r
-+    private double view_distance_min=0.1;//#define VIEW_DISTANCE_MIN          0.1                     // Objects closer to the camera than this will not be displayed.\r
-+    private double view_distance_max=100.0;//#define VIEW_DISTANCE_MAX                100.0           // Objects further away from the camera than this will not be displayed.\r
-+    private double[] m_projection=null;\r
-+    public void setViewDistanceMin(double i_new_value)\r
-+    {\r
-+      m_projection=null;//\83L\83\83\83b\83V\83\85\8dÏ\95Ï\90\94\8f\89\8aú\89»\r
-+      view_distance_min=i_new_value;\r
-+    }\r
-+    public void setViewDistanceMax(double i_new_value)\r
-+    {\r
-+      m_projection=null;//\83L\83\83\83b\83V\83\85\8dÏ\95Ï\90\94\8f\89\8aú\89»\r
-+      view_distance_max=i_new_value;\r
-+    }\r
-+    /**\r
-+     * void arglCameraFrustumRH(const ARParam *cparam, const double focalmin, const double focalmax, GLdouble m_projection[16])\r
-+     * \8aÖ\90\94\82Ì\92u\82«\8a·\82¦\r
-+     * @param focalmin\r
-+     * @param focalmax\r
-+     * @return\r
-+     */\r
-+    public double[] getCameraFrustumRH()\r
-+    {\r
-+      //\8aù\82É\92l\82ª\83L\83\83\83b\83V\83\85\82³\82ê\82Ä\82¢\82½\82ç\82»\82ê\82ð\8eg\82¤\r
-+      if(m_projection!=null){\r
-+          return m_projection;\r
-+      }\r
-+      //\96³\82¯\82ê\82Î\8cv\8eZ\r
-+      m_projection=new double[16];\r
-+      NyARMat trans_mat=new NyARMat(3,4);\r
-+      NyARMat icpara_mat=new NyARMat(3,4);\r
-+        double[][]  p=new double[3][3], q=new double[4][4];\r
-+      int      width, height;\r
-+        int      i, j;\r
-+      \r
-+        width  = xsize;\r
-+        height = ysize;\r
-+      \r
-+        decompMat(icpara_mat,trans_mat);\r
-+\r
-+        double[][] icpara=icpara_mat.getArray();\r
-+        double[][] trans=trans_mat.getArray();\r
-+      for (i = 0; i < 4; i++) {\r
-+            icpara[1][i] = (height - 1)*(icpara[2][i]) - icpara[1][i];\r
-+        }\r
-+      \r
-+        for(i = 0; i < 3; i++) {\r
-+            for(j = 0; j < 3; j++) {\r
-+                p[i][j] = icpara[i][j] / icpara[2][2];\r
-+            }\r
-+        }\r
-+        q[0][0] = (2.0 * p[0][0] / (width - 1));\r
-+        q[0][1] = (2.0 * p[0][1] / (width - 1));\r
-+        q[0][2] = -((2.0 * p[0][2] / (width - 1))  - 1.0);\r
-+        q[0][3] = 0.0;\r
-+      \r
-+        q[1][0] = 0.0;\r
-+        q[1][1] = -(2.0 * p[1][1] / (height - 1));\r
-+        q[1][2] = -((2.0 * p[1][2] / (height - 1)) - 1.0);\r
-+        q[1][3] = 0.0;\r
-+      \r
-+        q[2][0] = 0.0;\r
-+        q[2][1] = 0.0;\r
-+        q[2][2] = (view_distance_max + view_distance_min)/(view_distance_min - view_distance_max);\r
-+        q[2][3] = 2.0 * view_distance_max * view_distance_min / (view_distance_min - view_distance_max);\r
-+      \r
-+        q[3][0] = 0.0;\r
-+        q[3][1] = 0.0;\r
-+        q[3][2] = -1.0;\r
-+        q[3][3] = 0.0;\r
-+      \r
-+        for (i = 0; i < 4; i++) { // Row.\r
-+              // First 3 columns of the current row.\r
-+            for (j = 0; j < 3; j++) { // Column.\r
-+                m_projection[i + j*4] =\r
-+                    q[i][0] * trans[0][j] +\r
-+                    q[i][1] * trans[1][j] +\r
-+                    q[i][2] * trans[2][j];\r
-+            }\r
-+              // Fourth column of the current row.\r
-+            m_projection[i + 3*4]=\r
-+              q[i][0] * trans[0][3] +\r
-+              q[i][1] * trans[1][3] +\r
-+                q[i][2] * trans[2][3] +\r
-+                q[i][3];\r
-+        }\r
-+        return m_projection;\r
-+    }\r
-+}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java    (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java    (revision 178)\r
-@@ -0,0 +1,222 @@\r
-+/**\r
-+ * simpleLite\82Æ\93¯\82\82æ\82¤\82È\83e\83X\83g\83v\83\8d\83O\83\89\83\80\r
-+ * \83}\81[\83J\81[\82Ì\88ê\92v\93x\82Ì\8dÅ\92á\92l\82ð\83`\83F\83b\83N\82·\82é\82Æ\82±\82ë\82ð\94²\82¢\82½\82Ì\82Å\81A\93¯\82\83}\81[\83J\81[\82ð\91å\97Ê\82É\r
-+ * \8c\9f\8fo\82·\82é\82Æ\96Ê\94\92\82¢\82±\82Æ\82É\82È\82è\82Ü\82·\81B\r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail(at)ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.jogl.sample;\r
-+\r
-+import java.awt.event.WindowAdapter;\r
-+import java.awt.event.WindowEvent;\r
-+import java.awt.*;\r
-+\r
-+import javax.media.Buffer;\r
-+\r
-+import javax.media.opengl.GL;\r
-+import javax.media.opengl.GLAutoDrawable;\r
-+import javax.media.opengl.GLEventListener;\r
-+import javax.media.opengl.GLCanvas;\r
-+\r
-+import com.sun.opengl.util.Animator;\r
-+\r
-+import jp.nyatla.nyartoolkit.core.NyARCode;\r
-+\r
-+import jp.nyatla.nyartoolkit.jmf.utils.JmfCameraCapture;\r
-+import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener;\r
-+import jp.nyatla.nyartoolkit.jogl.utils.*;\r
-+\r
-+\r
-+public class JavaSimpleLite implements GLEventListener,JmfCaptureListener\r
-+{\r
-+    private final String CARCODE_FILE ="../../Data/patt.hiro";\r
-+    private final String PARAM_FILE   ="../../Data/camera_para.dat";\r
-+       \r
-+    private final static int SCREEN_X=320;\r
-+    private final static int SCREEN_Y=240;\r
-+    private Animator animator;\r
-+    private GLNyARRaster_RGB cap_image;\r
-+    \r
-+    private JmfCameraCapture capture;\r
-+    private GL  gl;\r
-+    private NyARGLUtil glnya;\r
-+\r
-+\r
-+    //NyARToolkit\8aÖ\8cW\r
-+    private GLNyARSingleDetectMarker nya;\r
-+    private GLNyARParam ar_param;\r
-+    /**\r
-+     * \97§\95û\91Ì\82ð\8f\91\82­\r
-+     *\r
-+     */\r
-+    void drawCube()\r
-+    {\r
-+      // Colour cube data.\r
-+      int polyList = 0;\r
-+      float fSize = 0.5f;//\83}\81[\83J\81[\83T\83C\83Y\82É\91Î\82µ\82Ä0.5\94{\82È\82Ì\82Å\81A4cm\82Ì\83i\83^\83f\83R\83R\r
-+      int f, i;       \r
-+      float[][] cube_vertices=new float[][]{\r
-+              {1.0f, 1.0f, 1.0f}, {1.0f, -1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f},\r
-+              {1.0f, 1.0f, -1.0f}, {1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}\r
-+      };\r
-+      float[][] cube_vertex_colors=new float[][]{\r
-+      {1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 1.0f, 1.0f},\r
-+      {1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}\r
-+      };\r
-+      int cube_num_faces = 6;\r
-+      short[][] cube_faces =new short[][]{\r
-+      {3, 2, 1, 0}, {2, 3, 7, 6}, {0, 1, 5, 4}, {3, 0, 4, 7}, {1, 2, 6, 5}, {4, 5, 6, 7}\r
-+      };\r
-+      \r
-+      if (polyList==0) {\r
-+            polyList = gl.glGenLists (1);\r
-+            gl.glNewList(polyList, GL.GL_COMPILE);\r
-+            gl.glBegin(GL.GL_QUADS);\r
-+            for (f = 0; f < cube_num_faces; f++)\r
-+                for (i = 0; i < 4; i++) {\r
-+                    gl.glColor3f (cube_vertex_colors[cube_faces[f][i]][0], cube_vertex_colors[cube_faces[f][i]][1], cube_vertex_colors[cube_faces[f][i]][2]);\r
-+                    gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);\r
-+                }\r
-+            gl.glEnd();\r
-+            gl.glColor3f(0.0f, 0.0f, 0.0f);\r
-+            for (f = 0; f < cube_num_faces; f++) {\r
-+              gl.glBegin (GL.GL_LINE_LOOP);\r
-+              for (i = 0; i < 4; i++)\r
-+                      gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);\r
-+              gl.glEnd ();\r
-+            }\r
-+            gl.glEndList ();\r
-+      }\r
-+      \r
-+      gl.glPushMatrix(); // Save world coordinate system.\r
-+      gl.glTranslatef(0.0f, 0.0f, 0.5f); // Place base of cube on marker surface.\r
-+      gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f); // Rotate about z axis.\r
-+      gl.glDisable(GL.GL_LIGHTING);   // Just use colours.\r
-+      gl.glCallList(polyList);        // Draw the cube.\r
-+      gl.glPopMatrix();       // Restore world coordinate system.\r
-+      \r
-+    }\r
-+    \r
-+    \r
-+    \r
-+    public JavaSimpleLite()\r
-+    {\r
-+        Frame frame = new Frame("Java simpleLite with NyARToolkit");\r
-+\r
-+\r
-+        // 3D\82ð\95`\89æ\82·\82é\83R\83\93\83|\81[\83l\83\93\83g\r
-+        GLCanvas canvas = new GLCanvas();\r
-+        frame.add(canvas);\r
-+        canvas.addGLEventListener(this);\r
-+        frame.addWindowListener(new WindowAdapter() {\r
-+                public void windowClosing(WindowEvent e) {\r
-+                    System.exit(0);\r
-+                }\r
-+            });\r
-+\r
-+        frame.setVisible(true);\r
-+        Insets ins=frame.getInsets();\r
-+        frame.setSize(SCREEN_X+ins.left+ins.right,SCREEN_Y+ins.top+ins.bottom);\r
-+        canvas.setBounds(ins.left,ins.top,SCREEN_X,SCREEN_Y);\r
-+    }\r
-+\r
-+    public void init(GLAutoDrawable drawable) {\r
-+        gl = drawable.getGL();\r
-+        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);\r
-+        //NyARToolkit\82Ì\8f\80\94õ\r
-+        try{\r
-+            //\83L\83\83\83v\83`\83\83\82Ì\8f\80\94õ\r
-+            capture=new JmfCameraCapture(320,240,15f,JmfCameraCapture.PIXEL_FORMAT_RGB);\r
-+            capture.setCaptureListener(this);\r
-+            //NyARToolkit\82Ì\8f\80\94õ\r
-+            ar_param=new GLNyARParam();\r
-+            NyARCode ar_code  =new NyARCode(16,16);\r
-+            ar_param.loadFromARFile(PARAM_FILE);\r
-+            ar_param.changeSize(SCREEN_X,SCREEN_Y);\r
-+            nya=new GLNyARSingleDetectMarker(ar_param,ar_code,80.0);\r
-+            ar_code.loadFromARFile(CARCODE_FILE);\r
-+            //NyARToolkit\97p\82Ì\8ex\89\87\83N\83\89\83X\r
-+            glnya=new NyARGLUtil(gl,ar_param);\r
-+            //GL\91Î\89\9e\82ÌRGB\83\89\83X\83^\83I\83u\83W\83F\83N\83g\r
-+            cap_image=new GLNyARRaster_RGB(gl,ar_param);\r
-+            //\83L\83\83\83v\83`\83\83\8aJ\8en\r
-+            capture.start();\r
-+       }catch(Exception e){\r
-+            e.printStackTrace();\r
-+        }\r
-+        animator = new Animator(drawable);\r
-+\r
-+        animator.start();\r
-+\r
-+    }\r
-+\r
-+    public void reshape(GLAutoDrawable drawable,\r
-+        int x, int y,\r
-+        int width, int height)\r
-+    {\r
-+        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);\r
-+        gl.glViewport(0, 0,  width, height);\r
-+\r
-+        //\8e\8b\91Ì\90Ï\82Ì\90Ý\92è\r
-+        gl.glMatrixMode(GL.GL_PROJECTION);\r
-+        gl.glLoadIdentity();\r
-+        //\8c©\82é\88Ê\92u\r
-+        gl.glMatrixMode(GL.GL_MODELVIEW);\r
-+        gl.glLoadIdentity();\r
-+    }\r
-+\r
-+    public void display(GLAutoDrawable drawable)\r
-+    {\r
-+        \r
-+        try{\r
-+            if(!cap_image.hasData()){\r
-+              return;\r
-+            }    \r
-+            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.          \r
-+            //\89æ\91\9c\83`\83F\83b\83N\82µ\82Ä\83}\81[\83J\81[\92T\82µ\82Ä\81A\94w\8ci\82ð\8f\91\82­\r
-+            boolean is_marker_exist;\r
-+            synchronized(cap_image){\r
-+              is_marker_exist=nya.detectMarkerLite(cap_image,100);\r
-+              //\94w\8ci\82ð\8f\91\82­\r
-+              glnya.drawBackGround(cap_image, 1.0);\r
-+            }\r
-+            //\82 \82Á\82½\82ç\97§\95û\91Ì\82ð\8f\91\82­\r
-+            if(is_marker_exist){\r
-+              //\83}\81[\83J\81[\82Ì\88ê\92v\93x\82ð\92²\8d¸\82·\82é\82È\82ç\82Î\81A\82±\82±\82Ånya.getConfidence()\82Å\88ê\92v\93x\82ð\92²\82×\82Ä\89º\82³\82¢\81B\r
-+                // Projection transformation.\r
-+                gl.glMatrixMode(GL.GL_PROJECTION);\r
-+                gl.glLoadMatrixd(ar_param.getCameraFrustumRH(),0);\r
-+                gl.glMatrixMode(GL.GL_MODELVIEW);\r
-+                // Viewing transformation.\r
-+                gl.glLoadIdentity();\r
-+                gl.glLoadMatrixd(nya.getCameraViewRH(),0);\r
-+\r
-+            \r
-+                // All other lighting and geometry goes here.\r
-+                drawCube();\r
-+            }\r
-+        }catch(Exception e){\r
-+            e.printStackTrace();\r
-+        }\r
-+    }\r
-+    public void onUpdateBuffer(Buffer i_buffer)\r
-+    {\r
-+      try{\r
-+          synchronized(cap_image){\r
-+              cap_image.setBuffer(i_buffer, true);\r
-+          }\r
-+      }catch(Exception e){\r
-+          e.printStackTrace();\r
-+      }        \r
-+    }\r
-+\r
-+    public void displayChanged(GLAutoDrawable drawable,\r
-+                               boolean modeChanged,\r
-+                               boolean deviceChanged) {}\r
-+\r
-+    public static void main(String[] args) {\r
-+        new JavaSimpleLite();\r
-+    }\r
-+}\r
-+\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java       (revision 174)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java       (revision 178)\r
-@@ -1,56 +0,0 @@\r
--/**\r
-- * VFM\83L\83\83\83v\83`\83\83\83e\83X\83g\83v\83\8d\83O\83\89\83\80\r
-- * (c)2008 R.iizuka\r
-- * airmail@ebony.plala.or.jp\r
-- * http://nyatla.jp/\r
-- */\r
--import javax.media.*;\r
--\r
--import javax.media.util.BufferToImage;\r
--import javax.media.format.*;\r
--\r
--import jp.nyatla.nyartoolkit.NyARException;\r
--import jp.nyatla.nyartoolkit.jmf.*;\r
--import java.awt.*;\r
--\r
--\r
--\r
--public class JmfCaptureTest extends Frame implements JmfCaptureListener{\r
--    public JmfCaptureTest() throws NyARException\r
--    {\r
--        setTitle("JmfCaptureTest");\r
--        setBounds(0,0,320+64,240+64);     \r
--        capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);\r
--        capture.setCaptureListener(this);\r
--    }\r
--\r
--\r
--\r
--    private JmfCameraCapture  capture;\r
--    public void onUpdateBuffer(Buffer i_buffer)\r
--    {\r
--      BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());\r
--      Image img=b2i.createImage(i_buffer);\r
--        Graphics g = getGraphics();        \r
--        g.drawImage(img, 32, 32,this);       \r
--    }\r
--    private void startCapture()\r
--    {\r
--      try{\r
--          capture.start();\r
--      }catch(Exception e){\r
--          e.printStackTrace();\r
--      }\r
--    }\r
--    public static void main(String[] args) {\r
--      try{\r
--            JmfCaptureTest mainwin = new JmfCaptureTest();\r
--            mainwin.setVisible(true);\r
--            mainwin.startCapture();\r
--      }catch(Exception e){\r
--          e.printStackTrace();\r
--      }\r
--        \r
--    }\r
--\r
--}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java  (revision 174)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java  (revision 178)\r
-@@ -1,114 +0,0 @@\r
--/**\r
-- * VFM+ARToolkit\83e\83X\83g\83v\83\8d\83O\83\89\83\80\r
-- * \83J\83\81\83\89\82©\82ç\8eæ\82è\8d\9e\82ñ\82¾\83f\81[\83^\82©\82ç\83}\81[\83J\81[\82ð\8c\9f\8fo\82µ\82Ä\81A\88ê\92v\93x\82Æ\95Ï\8a·\8ds\97ñ\82ð\95\\8e¦\82µ\82Ü\82·\81B\r
-- * (c)2008 R.iizuka\r
-- * airmail(at)ebony.plala.or.jp\r
-- * http://nyatla.jp/\r
-- */\r
--import javax.media.*;\r
--\r
--import javax.media.util.BufferToImage;\r
--import javax.media.format.*;\r
--\r
--import jp.nyatla.nyartoolkit.NyARException;\r
--import jp.nyatla.nyartoolkit.jmf.*;\r
--import jp.nyatla.nyartoolkit.jmfutil.*;\r
--import java.awt.*;\r
--\r
--import jp.nyatla.nyartoolkit.core.*;\r
--import jp.nyatla.nyartoolkit.detector.*;\r
--import jp.nyatla.nyartoolkit.core.raster.*;\r
--\r
--\r
--\r
--\r
--\r
--public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener\r
--{\r
--    private final String CARCODE_FILE ="../../Data/patt.hiro";\r
--    private final String PARAM_FILE   ="../../Data/camera_para.dat";\r
--    private JmfCameraCapture capture;\r
--    NyARSingleDetectMarker nya;\r
--    JmfNyARRaster_RGB raster;\r
--\r
--    public NyarToolkitLinkTest() throws NyARException,NyARException\r
--    {\r
--        setTitle("JmfCaptureTest");\r
--        setBounds(0,0,320+64,240+64);     \r
--        //\83L\83\83\83v\83`\83\83\82Ì\8f\80\94õ\r
--        capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);\r
--        capture.setCaptureListener(this);\r
--        \r
--        //NyARToolkit\82Ì\8f\80\94õ\r
--        NyARParam ar_param=new NyARParam();\r
--        NyARCode ar_code  =new NyARCode(16,16);\r
--        ar_param.loadFromARFile(PARAM_FILE);\r
--        ar_param.changeSize(320,240);\r
--        nya=new NyARSingleDetectMarker(ar_param,ar_code,80.0);\r
--        ar_code.loadFromARFile(CARCODE_FILE);\r
--        //\83L\83\83\83v\83`\83\83\83C\83\81\81[\83W\97p\82Ì\83\89\83X\83^\82ð\8f\80\94õ\r
--        raster=new JmfNyARRaster_RGB(320,240);\r
--    }\r
--\r
--\r
--\r
--    public void onUpdateBuffer(Buffer i_buffer)\r
--    {\r
--      try{\r
--            //\83L\83\83\83v\83`\83\83\82µ\82½\83o\83b\83t\83@\82ð\83\89\83X\83^\82É\83Z\83b\83g\r
--          raster.setBuffer(i_buffer);\r
--\r
--            //\83L\83\83\83v\83`\83\83\82µ\82½\83C\83\81\81[\83W\82ð\95\\8e¦\97p\82É\89Á\8dH\r
--            BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());\r
--            Image img=b2i.createImage(i_buffer);\r
--\r
--            Graphics g = getGraphics();            \r
--            double[][] atm=null;\r
--\r
--            //\83}\81[\83J\81[\8c\9f\8fo\r
--            boolean is_marker_exist=nya.detectMarkerLite(raster,100);\r
--            if(is_marker_exist){\r
--                //\95Ï\8a·\8ds\97ñ\82ð\8eæ\93¾\r
--                atm=nya.getTransmationMatrix().getArray();\r
--            }\r
--            //\8fî\95ñ\82ð\89æ\96Ê\82É\8f\91\82­       \r
--            g.drawImage(img, 32, 32,this);\r
--            if(is_marker_exist){\r
--                g.drawString("\83}\81[\83J\81[\8c\9f\8fo:"+nya.getConfidence(),32,50);\r
--                for(int i=0;i<3;i++){\r
--                    for(int i2=0;i2<4;i2++){\r
--                      g.drawString("["+i+"]["+i2+"]"+atm[i][i2],32,50+(1+i2*3+i)*16);\r
--                    }\r
--                    \r
--                }\r
--            }else{\r
--                g.drawString("\83}\81[\83J\81[\96¢\8c\9f\8fo:",32,100);\r
--            }\r
--      }catch(Exception e){\r
--          e.printStackTrace();\r
--      }\r
--       \r
--        \r
--        \r
--        \r
--    }\r
--    private void startCapture()\r
--    {\r
--      try{\r
--          capture.start();\r
--      }catch(Exception e){\r
--          e.printStackTrace();\r
--      }\r
--    }\r
--    public static void main(String[] args) {\r
--      try{\r
--            NyarToolkitLinkTest mainwin = new NyarToolkitLinkTest();\r
--            mainwin.setVisible(true);\r
--            mainwin.startCapture();\r
--      }catch(Exception e){\r
--          e.printStackTrace();\r
--      }\r
--        \r
--    }\r
--\r
--}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorCDS.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorCDS.java (revision 174)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorCDS.java (revision 178)\r
-@@ -1,136 +0,0 @@\r
--/*\r
-- * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.\r
-- *\r
-- * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,\r
-- * modify and redistribute this software in source and binary code form,\r
-- * provided that i) this copyright notice and license appear on all copies of\r
-- * the software; and ii) Licensee does not utilize the software in a manner\r
-- * which is disparaging to Sun.\r
-- *\r
-- * This software is provided "AS IS," without a warranty of any kind. ALL\r
-- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY\r
-- * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR\r
-- * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE\r
-- * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING\r
-- * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS\r
-- * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,\r
-- * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER\r
-- * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF\r
-- * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE\r
-- * POSSIBILITY OF SUCH DAMAGES.\r
-- *\r
-- * This software is not designed or intended for use in on-line control of\r
-- * aircraft, air traffic, aircraft navigation or aircraft communications; or in\r
-- * the design, construction, operation or maintenance of any nuclear\r
-- * facility. Licensee represents and warrants that it will not use or\r
-- * redistribute the Software for such purposes.\r
-- */\r
--package jp.nyatla.nyartoolkit.jmf;\r
--\r
--\r
--import javax.media.*;\r
--import javax.media.protocol.*;\r
--import javax.media.control.*;\r
--\r
--import java.io.IOException;\r
--\r
--\r
--\r
--public class MonitorCDS extends PushBufferDataSource{\r
--\r
--    private PushBufferDataSource delegate = null;\r
--    private PushBufferStream [] delStreams = null;\r
--    private MonitorStream monitorStream = null;\r
--    private PushBufferStream [] monitorStreams = null;\r
--    boolean delStarted = false; // variable used by MonitorStream also\r
--    private Control [] controls;\r
--\r
--    public MonitorCDS(DataSource ds)\r
--    {\r
--      // Get the stream from the actual datasource\r
--      // and create a MonitorStream from it\r
--      // Export the MonitorControl interface of the MonitorStream\r
--      if (ds instanceof PushBufferDataSource)\r
--      {\r
--          delegate = (PushBufferDataSource) ds;\r
--          delStreams = delegate.getStreams();\r
--          monitorStream = new MonitorStream(delStreams[0], this);\r
--          monitorStreams = new PushBufferStream[] {monitorStream};\r
--      }\r
--    }\r
--\r
--    public Object [] getControls()\r
--    {\r
--      return controls;\r
--    }\r
--\r
--    public Object getControl(String value) {\r
--      if (value.equals("jmfsample.MonitorStream") || value.equals("javax.media.control.MonitorControl"))\r
--          return monitorStream;\r
--      else\r
--          return null;\r
--    }\r
--\r
--    public javax.media.CaptureDeviceInfo getCaptureDeviceInfo()\r
--    {\r
--      return ((CaptureDevice)delegate).getCaptureDeviceInfo();\r
--    }\r
--\r
--    public FormatControl[] getFormatControls()\r
--    {\r
--      return ((CaptureDevice)delegate).getFormatControls();\r
--    }\r
--\r
--    public String getContentType()\r
--    {\r
--      return delegate.getContentType();\r
--    }\r
--\r
--    public void connect() throws IOException\r
--    {\r
--      if (delegate == null)\r
--          throw new IOException("Incompatible DataSource");\r
--      // Delegate is already connected\r
--    }\r
--\r
--    public void disconnect()\r
--    {\r
--      monitorStream.setEnabled(false);\r
--      delegate.disconnect();\r
--    }\r
--\r
--    public synchronized void start() throws IOException\r
--    {\r
--      startDelegate();\r
--      delStarted = true;\r
--    }\r
--\r
--    public synchronized void stop() throws IOException\r
--    {\r
--      if (!monitorStream.isEnabled()) {\r
--          stopDelegate();\r
--      }\r
--      delStarted = false;\r
--    }\r
--\r
--    public Time getDuration()\r
--    {\r
--      return delegate.getDuration();\r
--    }\r
--\r
--    public PushBufferStream [] getStreams()\r
--    {\r
--      return monitorStreams;\r
--    }\r
--\r
--    void startDelegate() throws IOException\r
--    {\r
--      delegate.start();\r
--    }\r
--\r
--    void stopDelegate() throws IOException\r
--    {\r
--      delegate.stop();\r
--    }\r
--\r
--}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorStream.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorStream.java      (revision 174)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorStream.java      (revision 178)\r
-@@ -1,196 +0,0 @@\r
--/*\r
-- * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.\r
-- *\r
-- * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,\r
-- * modify and redistribute this software in source and binary code form,\r
-- * provided that i) this copyright notice and license appear on all copies of\r
-- * the software; and ii) Licensee does not utilize the software in a manner\r
-- * which is disparaging to Sun.\r
-- *\r
-- * This software is provided "AS IS," without a warranty of any kind. ALL\r
-- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY\r
-- * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR\r
-- * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE\r
-- * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING\r
-- * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS\r
-- * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,\r
-- * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER\r
-- * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF\r
-- * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE\r
-- * POSSIBILITY OF SUCH DAMAGES.\r
-- *\r
-- * This software is not designed or intended for use in on-line control of\r
-- * aircraft, air traffic, aircraft navigation or aircraft communications; or in\r
-- * the design, construction, operation or maintenance of any nuclear\r
-- * facility. Licensee represents and warrants that it will not use or\r
-- * redistribute the Software for such purposes.\r
-- */\r
--package jp.nyatla.nyartoolkit.jmf;\r
--\r
--\r
--\r
--import javax.media.*;\r
--import javax.media.protocol.*;\r
--\r
--import javax.media.util.BufferToImage;\r
--import java.io.IOException;\r
--import java.awt.*;\r
--\r
--public class MonitorStream implements PushBufferStream, BufferTransferHandler {\r
--\r
--    JmfCaptureListener img_listener;\r
--    PushBufferStream actual = null;\r
--    boolean dataAvailable = false;\r
--    boolean terminate = false;\r
--    boolean enabled = false;\r
--    Object bufferLock = new Object();\r
--    Buffer cbuffer = new Buffer();\r
--    BufferTransferHandler transferHandler = null;\r
--    Component component = null;\r
--    MonitorCDS cds;\r
--    BufferToImage bti = null;\r
--    \r
--    MonitorStream(PushBufferStream actual, MonitorCDS cds) {\r
--      this.actual = actual;\r
--      actual.setTransferHandler(this);\r
--      this.cds = cds;\r
--    }\r
--\r
--    public javax.media.Format getFormat()\r
--    {\r
--      return actual.getFormat();\r
--    }\r
--    /**\r
--     * \94ñ\93¯\8aúREAD\r
--     */\r
--    public void read(Buffer buffer) throws IOException\r
--    {\r
--      // Wait for data to be available\r
--      // Doesn't get used much because the transferData\r
--      // call is made when data IS available. And most\r
--      // Processors/Players read the data in the same\r
--      // thread that called transferData, although that's\r
--      // not a safe assumption to make\r
--      if (!dataAvailable) {\r
--          synchronized (bufferLock) {\r
--              while (!dataAvailable && !terminate) {\r
--                  try {\r
--                      bufferLock.wait(100);\r
--                  } catch (InterruptedException ie) {\r
--                  }\r
--              }\r
--          }\r
--      }\r
--\r
--      if (dataAvailable) {\r
--          synchronized (bufferLock) {\r
--              // Copy the buffer attributes, but swap the data\r
--              // attributes so that no extra copy is made.\r
--              buffer.copy(cbuffer, true);\r
--              //dataAvailable = false;\r
--          }\r
--      }\r
--//    return;\r
--    }\r
--    public void setCaptureListener(JmfCaptureListener i_listener)\r
--    {\r
--      img_listener=i_listener;\r
--    }\r
--\r
--    public void transferData(PushBufferStream pbs)\r
--    {\r
--      // Get the data from the original source stream\r
--      synchronized (bufferLock) {\r
--          try {\r
--              pbs.read(cbuffer);\r
--          } catch (IOException ioe) {\r
--              return;\r
--          }\r
--          dataAvailable = true;\r
--          bufferLock.notifyAll();\r
--      }\r
--      if(img_listener!=null){\r
--          img_listener.onUpdateBuffer(cbuffer);\r
--      }\r
--      \r
--/*\r
--      // Display data if monitor is active\r
--      if (isEnabled()) {\r
--          if (bti == null) {\r
--              VideoFormat vf = (VideoFormat) cbuffer.getFormat();\r
--              bti = new BufferToImage(vf);\r
--          }\r
--          if (bti != null && component != null) {\r
--              Image im = bti.createImage(cbuffer);\r
--              Graphics g = component.getGraphics();\r
--              Dimension size = component.getSize();\r
--              if (g != null)\r
--                  g.drawImage(im, 0, 0, component);\r
--          }\r
--      }\r
--*/\r
--      // Maybe synchronize this with setTransferHandler() ?\r
--      if (transferHandler != null && cds.delStarted)\r
--          transferHandler.transferData(this);\r
--    }\r
--\r
--    public void setTransferHandler(BufferTransferHandler transferHandler) {\r
--      this.transferHandler = transferHandler;\r
--    }\r
--\r
--    public boolean setEnabled(boolean value) {\r
--      enabled = value;\r
--      if (value == false) {\r
--          if (!cds.delStarted) {\r
--              try {\r
--                  cds.stopDelegate();\r
--              } catch (IOException ioe) {\r
--              }\r
--          }\r
--      } else {\r
--          // Start the capture datasource if the monitor is enabled\r
--          try {\r
--              cds.startDelegate();\r
--          }catch (IOException ioe) {\r
--          }\r
--      }\r
--      return enabled;\r
--    }\r
--\r
--    public boolean isEnabled()\r
--    {\r
--      return enabled;\r
--    }\r
--\r
--\r
--\r
--    public float setPreviewFrameRate(float rate)\r
--    {\r
--      System.err.println("TODO");\r
--      return rate;\r
--    }\r
--      \r
--    public ContentDescriptor getContentDescriptor()\r
--    {\r
--      return actual.getContentDescriptor();\r
--    }\r
--\r
--    public long getContentLength()\r
--    {\r
--      return actual.getContentLength();\r
--    }\r
--\r
--    public boolean endOfStream() {\r
--      return actual.endOfStream();\r
--    }\r
--\r
--    public Object [] getControls() {\r
--      return new Object[0];\r
--    }\r
--\r
--    public Object getControl(String str) {\r
--      return null;\r
--    }\r
--\r
--\r
--}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCaptureListener.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCaptureListener.java (revision 174)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCaptureListener.java (revision 178)\r
-@@ -1,14 +0,0 @@\r
--/**\r
-- * JMF\82¨\8eè\8cy\83L\83\83\83v\83`\83\83\97p\83\8a\83X\83i\r
-- * (c)2008 R.Iizuka\r
-- * airmail@ebony.plala.or.jp\r
-- * http://nyatla.jp/\r
-- */\r
--package jp.nyatla.nyartoolkit.jmf;\r
--\r
--import javax.media.Buffer;\r
--\r
--public interface  JmfCaptureListener{\r
--    public void onUpdateBuffer(Buffer i_buffer);\r
--    \r
--}\r
-\ No newline at end of file\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java   (revision 174)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java   (revision 178)\r
-@@ -1,180 +0,0 @@\r
--/**\r
-- * JMF\82¨\8eè\8cy\83L\83\83\83v\83`\83\83\83N\83\89\83X\r
-- * (c)2008 R.Iizuka\r
-- * airmail@ebony.plala.or.jp\r
-- * http://nyatla.jp/\r
-- */\r
--package jp.nyatla.nyartoolkit.jmf;\r
--\r
--\r
--\r
--import javax.media.*;\r
--import javax.media.protocol.*;\r
--import javax.media.control.*;\r
--import javax.media.format.*;\r
--import java.awt.*;\r
--import java.util.*;\r
--import javax.media.protocol.DataSource;\r
--\r
--import jp.nyatla.nyartoolkit.NyARException;\r
--\r
--\r
--\r
--\r
--\r
--public class JmfCameraCapture\r
--{\r
--    private Dimension image_size;\r
--    private JmfCaptureListener capture_listener;\r
--    private DataSource jmf_data_source;\r
--    private MonitorStream jmf_monitor_stream;\r
--    private Processor jmf_processor;\r
--    private VideoFormat jmf_video_format;\r
--    \r
--    private Buffer read_buf=new Buffer();\r
--    public static final String PIXEL_FORMAT_RGB="RGB";\r
--    public JmfCameraCapture(int i_width,int i_height,float i_rate,String i_pixcel_format)\r
--    {\r
--        String encoding = i_pixcel_format;//comboEncoding.getSelectedItem();\r
--        image_size = new Dimension(i_width,i_height);\r
--        jmf_video_format = new VideoFormat(encoding, image_size, Format.NOT_SPECIFIED,null,i_rate);\r
--    }\r
--    public Dimension getSize()\r
--    {\r
--      return image_size;\r
--    }\r
--    public javax.media.Buffer readBuffer() throws NyARException\r
--    {\r
--      if(jmf_monitor_stream==null){\r
--            throw new NyARException();\r
--      }\r
--        try{\r
--            jmf_monitor_stream.read(read_buf);\r
--        }catch(Exception e){\r
--            throw new NyARException(e);\r
--        }\r
--        return read_buf;\r
--    }\r
--    public void setCaptureListener(JmfCaptureListener i_listener) throws NyARException\r
--    {\r
--      if(jmf_processor!=null){\r
--          throw new NyARException();\r
--      }\r
--      capture_listener=i_listener;\r
--      \r
--    }\r
--    public void start() throws NyARException\r
--    {\r
--        \r
--        DataSource ds=getCaptureDS(jmf_video_format);\r
--        VideoFormat[] formats=new VideoFormat[]{new VideoFormat(null)};\r
--        ProcessorModel pm = new ProcessorModel(ds,formats,null);//, formats, ftd);\r
--        Processor processor;\r
--        try {\r
--            processor = Manager.createRealizedProcessor(pm);\r
--        } catch (Exception e){\r
--            // Make sure the capture devices are released\r
--            ds.disconnect();\r
--            throw new NyARException(e);\r
--        }\r
--        // Get the monitor control:\r
--        // Since there are more than one MonitorControl objects\r
--        // exported by the DataSource, we get the specific one\r
--        // that is also the MonitorStream object.\r
--        jmf_monitor_stream=(MonitorStream)ds.getControl("jmfsample.MonitorStream");\r
--      jmf_monitor_stream.setCaptureListener(capture_listener);\r
--        jmf_data_source=ds;\r
--        jmf_processor=processor;\r
--        jmf_processor.start();\r
--    }\r
--    public void stop()\r
--    {\r
--        jmf_processor.stop();\r
--        jmf_processor.close();\r
--        jmf_processor = null;\r
--        \r
--    }\r
--    protected void finalize()\r
--    {\r
--        if(jmf_processor!=null){\r
--        jmf_processor.stop();\r
--        jmf_processor.close();\r
--        jmf_processor = null;\r
--        }\r
--    }\r
--    private static DataSource getCaptureDS(VideoFormat vf) {\r
--      DataSource dsVideo = null;\r
--      DataSource ds = null;\r
--\r
--      // Create a capture DataSource for the video\r
--      // If there is no video capture device, then exit with null\r
--      if (vf != null) {\r
--          dsVideo = createDataSource(vf);\r
--          if (dsVideo == null)\r
--              return null;\r
--      }\r
--\r
--\r
--      // Create the monitoring datasource wrapper\r
--      if (dsVideo != null) {\r
--          dsVideo = new MonitorCDS(dsVideo);\r
--          return dsVideo;\r
--      }\r
--\r
--      // Merge the data sources, if both audio and video are available\r
--      try {\r
--          ds = Manager.createMergingDataSource(new DataSource[]{dsVideo});\r
--      } catch (IncompatibleSourceException ise){\r
--          return null;\r
--      }\r
--\r
--      return ds;\r
--    }\r
--\r
--    private static DataSource createDataSource(Format format) {\r
--      DataSource ds;\r
--      Vector devices;\r
--      CaptureDeviceInfo cdi;\r
--      MediaLocator ml;\r
--\r
--      // Find devices for format\r
--      devices = CaptureDeviceManager.getDeviceList(format);\r
--      if (devices.size() < 1) {\r
--          System.err.println("! No Devices for " + format);\r
--          return null;\r
--      }\r
--      // Pick the first device\r
--      cdi = (CaptureDeviceInfo) devices.elementAt(0);\r
--\r
--      ml = cdi.getLocator();\r
--\r
--      try {\r
--          ds = Manager.createDataSource(ml);\r
--          ds.connect();\r
--          if (ds instanceof CaptureDevice)\r
--          {\r
--              setCaptureFormat((CaptureDevice) ds, format);\r
--          }\r
--      } catch (Exception e) {\r
--          System.err.println(e);\r
--          return null;\r
--      }\r
--      return ds;\r
--    }\r
--\r
--    private static void setCaptureFormat(CaptureDevice cdev, Format format) {\r
--      FormatControl [] fcs = cdev.getFormatControls();\r
--      if (fcs.length < 1){\r
--          return;\r
--      }\r
--      FormatControl fc = fcs[0];\r
--      Format [] formats = fc.getSupportedFormats();\r
--      for (int i = 0; i < formats.length; i++) {\r
--          if (formats[i].matches(format)){\r
--              format = formats[i].intersects(format);\r
--              fc.setFormat(format);\r
--              break;\r
--          }\r
--      }\r
--    }\r
--}\r
-\ No newline at end of file\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java    (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java    (revision 178)\r
-@@ -0,0 +1,119 @@\r
-+/**\r
-+ * RGB\8c`\8e®\82ÌJMF\83o\83b\83t\83@\82ð\83\89\83b\83v\82·\82éNyARRaster\82Å\82·\81B\r
-+ * JMF\82©\82ç\93¾\82½\83\89\83X\83^\83f\81[\83^\82Ì\83s\83N\83Z\83\8b\95À\82Ñ\8f\87\82ð\8dl\97\82µ\82Ü\82·\81B\r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail(at)ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.jmf.utils;\r
-+\r
-+\r
-+import javax.media.format.RGBFormat;\r
-+import java.awt.Dimension;\r
-+import jp.nyatla.nyartoolkit.NyARException;\r
-+import jp.nyatla.nyartoolkit.core.raster.NyARRaster;\r
-+\r
-+\r
-+public class JmfNyARRaster_RGB implements NyARRaster\r
-+{\r
-+    public final static int PIXEL_ORDER_RGB=1;\r
-+    public final static int PIXEL_ORDER_BGR=2;\r
-+    protected int pix_type;\r
-+    private int red_idx;\r
-+    private int green_idx;\r
-+    private int blue_idx;\r
-+    protected byte[] ref_buf;\r
-+    protected int width=0;\r
-+    protected int height=0;\r
-+\r
-+    /**\r
-+     * RGB\8c`\8e®\82ÌJMF\83o\83b\83t\83@\82ð\83\89\83b\83v\82·\82é\83I\83u\83W\83F\83N\83g\82ð\82Â\82­\82è\82Ü\82·\81B\r
-+     * \90\90¬\92¼\8cã\82Ì\83I\83u\83W\83F\83N\83g\82Í\83f\81[\83^\82ð\8e\9d\82¿\82Ü\82¹\82ñ\81B\r
-+     * \83\81\83\93\83o\8aÖ\90\94\82ÍsetBuffer\82ð\8eÀ\8ds\8cã\82É\8eg\97p\89Â\94\\82É\82È\82è\82Ü\82·\81B\r
-+     */\r
-+    public JmfNyARRaster_RGB(int i_width,int i_height)\r
-+    {\r
-+      ref_buf=null;\r
-+      width=i_width;\r
-+      height=i_height;\r
-+    }\r
-+    /**\r
-+     * \83t\83H\81[\83}\83b\83g\82ð\89ð\90Í\82µ\82Ä\81A\83C\83\93\83X\83^\83\93\83X\82Ì\83t\83H\81[\83}\83b\83g\83v\83\8d\83p\83e\83B\82ð\8f\89\8aú\89»\82µ\82Ü\82·\81B\r
-+     * \r
-+     * @param i_buffer\r
-+     * @throws NyARException\r
-+     */\r
-+    protected void initFormatProperty(RGBFormat i_fmt) throws NyARException\r
-+    {\r
-+      //\83f\81[\83^\83T\83C\83Y\82Ì\8am\94F\r
-+        Dimension s=i_fmt.getSize();\r
-+        if(width!=s.width || height !=s.height){\r
-+          throw new NyARException();\r
-+        }\r
-+      //\83f\81[\83^\94z\97ñ\82Ì\8am\94F\r
-+      red_idx  =i_fmt.getRedMask()-1;\r
-+      green_idx=i_fmt.getGreenMask()-1;\r
-+      blue_idx =i_fmt.getBlueMask()-1;\r
-+      \r
-+      //\90F\94z\97ñ\82Ì\93Á\92è\r
-+      if(red_idx==0 && blue_idx==2){\r
-+          pix_type=PIXEL_ORDER_RGB;\r
-+      }else if(red_idx==2 && blue_idx==0){\r
-+          pix_type=PIXEL_ORDER_BGR;\r
-+      }else{\r
-+          throw new NyARException("Unknown pixel order.");\r
-+      }       \r
-+    }\r
-+    /**\r
-+     * javax.media.Buffer\82ð\95ª\90Í\82µ\82Ä\81A\82»\82Ì\95ª\90Í\8c\8b\89Ê\82ðNyARRaster\82É\93K\8d\87\82·\82é\8c`\82Å\95Û\8e\9d\82µ\82Ü\82·\81B\r
-+     * \8aÖ\90\94\8eÀ\8ds\8cã\82É\8aO\95\94\82Åi_buffer\82Ì\93à\97e\95Ï\8dX\82µ\82½\8fê\8d\87\82É\82Í\81A\8dÄ\93xsetBuffer\8aÖ\90\94\82ð\8cÄ\82Ñ\8fo\82µ\82Ä\82­\82¾\82³\82¢\81B\r
-+     * @param i_buffer\r
-+     * RGB\8c`\8e®\82Ì\83f\81[\83^\82ð\8ai\94[\82µ\82½javax.media.Buffer\83I\83u\83W\83F\83N\83g\82ð\8ew\92è\82µ\82Ä\82­\82¾\82³\82¢\81B\r
-+     * @return\r
-+     * i_buffer\82ð\83\89\83b\83v\82µ\82½\83I\83u\83W\83F\83N\83g\82ð\95Ô\82µ\82Ü\82·\81B\r
-+     * @throws NyARException\r
-+     */\r
-+    public void setBuffer(javax.media.Buffer i_buffer) throws NyARException\r
-+    {\r
-+      initFormatProperty((RGBFormat)i_buffer.getFormat());\r
-+        ref_buf=(byte[])i_buffer.getData();\r
-+    }\r
-+    public int getPixelTotal(int i_x,int i_y)\r
-+    {\r
-+        int bp=(i_x+i_y*width)*3;\r
-+        return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);\r
-+    }\r
-+    public int getWidth()\r
-+    {\r
-+        return width;\r
-+    }\r
-+    public int getHeight()\r
-+    {\r
-+        return height;\r
-+    }\r
-+    public void pickRgbArray(int i_x,int i_y,int[] i_rgb)\r
-+    {\r
-+        int bp=(i_x+i_y*width)*3;\r
-+        i_rgb[0]=(ref_buf[bp+red_idx] & 0xff);//R\r
-+        i_rgb[1]=(ref_buf[bp+green_idx] & 0xff);//G\r
-+        i_rgb[2]=(ref_buf[bp+blue_idx] & 0xff);//B\r
-+    }\r
-+    /**\r
-+     * \83s\83N\83Z\83\8b\82Ì\8f\87\8f\98\83^\83C\83v\82ð\95Ô\82µ\82Ü\82·\81B\r
-+     * @return\r
-+     * \82»\82Ì\92l\r
-+     */\r
-+    public int getPixelOrder()\r
-+    {\r
-+      return pix_type;\r
-+    }\r
-+    /**\r
-+     * \83f\81[\83^\82ð\8e\9d\82Á\82Ä\82¢\82é\82©\82ð\95Ô\82µ\82Ü\82·\81B\r
-+     * @return\r
-+     */\r
-+    public boolean hasData()\r
-+    {\r
-+      return ref_buf!=null;\r
-+    }\r
-+\r
-+}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java   (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java   (revision 178)\r
-@@ -0,0 +1,136 @@\r
-+/*\r
-+ * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.\r
-+ *\r
-+ * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,\r
-+ * modify and redistribute this software in source and binary code form,\r
-+ * provided that i) this copyright notice and license appear on all copies of\r
-+ * the software; and ii) Licensee does not utilize the software in a manner\r
-+ * which is disparaging to Sun.\r
-+ *\r
-+ * This software is provided "AS IS," without a warranty of any kind. ALL\r
-+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY\r
-+ * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR\r
-+ * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE\r
-+ * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING\r
-+ * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS\r
-+ * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,\r
-+ * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER\r
-+ * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF\r
-+ * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE\r
-+ * POSSIBILITY OF SUCH DAMAGES.\r
-+ *\r
-+ * This software is not designed or intended for use in on-line control of\r
-+ * aircraft, air traffic, aircraft navigation or aircraft communications; or in\r
-+ * the design, construction, operation or maintenance of any nuclear\r
-+ * facility. Licensee represents and warrants that it will not use or\r
-+ * redistribute the Software for such purposes.\r
-+ */\r
-+package jp.nyatla.nyartoolkit.jmf.utils;\r
-+\r
-+\r
-+import javax.media.*;\r
-+import javax.media.protocol.*;\r
-+import javax.media.control.*;\r
-+\r
-+import java.io.IOException;\r
-+\r
-+\r
-+\r
-+public class MonitorCDS extends PushBufferDataSource{\r
-+\r
-+    private PushBufferDataSource delegate = null;\r
-+    private PushBufferStream [] delStreams = null;\r
-+    private MonitorStream monitorStream = null;\r
-+    private PushBufferStream [] monitorStreams = null;\r
-+    boolean delStarted = false; // variable used by MonitorStream also\r
-+    private Control [] controls;\r
-+\r
-+    public MonitorCDS(DataSource ds)\r
-+    {\r
-+      // Get the stream from the actual datasource\r
-+      // and create a MonitorStream from it\r
-+      // Export the MonitorControl interface of the MonitorStream\r
-+      if (ds instanceof PushBufferDataSource)\r
-+      {\r
-+          delegate = (PushBufferDataSource) ds;\r
-+          delStreams = delegate.getStreams();\r
-+          monitorStream = new MonitorStream(delStreams[0], this);\r
-+          monitorStreams = new PushBufferStream[] {monitorStream};\r
-+      }\r
-+    }\r
-+\r
-+    public Object [] getControls()\r
-+    {\r
-+      return controls;\r
-+    }\r
-+\r
-+    public Object getControl(String value) {\r
-+      if (value.equals("jmfsample.MonitorStream") || value.equals("javax.media.control.MonitorControl"))\r
-+          return monitorStream;\r
-+      else\r
-+          return null;\r
-+    }\r
-+\r
-+    public javax.media.CaptureDeviceInfo getCaptureDeviceInfo()\r
-+    {\r
-+      return ((CaptureDevice)delegate).getCaptureDeviceInfo();\r
-+    }\r
-+\r
-+    public FormatControl[] getFormatControls()\r
-+    {\r
-+      return ((CaptureDevice)delegate).getFormatControls();\r
-+    }\r
-+\r
-+    public String getContentType()\r
-+    {\r
-+      return delegate.getContentType();\r
-+    }\r
-+\r
-+    public void connect() throws IOException\r
-+    {\r
-+      if (delegate == null)\r
-+          throw new IOException("Incompatible DataSource");\r
-+      // Delegate is already connected\r
-+    }\r
-+\r
-+    public void disconnect()\r
-+    {\r
-+      monitorStream.setEnabled(false);\r
-+      delegate.disconnect();\r
-+    }\r
-+\r
-+    public synchronized void start() throws IOException\r
-+    {\r
-+      startDelegate();\r
-+      delStarted = true;\r
-+    }\r
-+\r
-+    public synchronized void stop() throws IOException\r
-+    {\r
-+      if (!monitorStream.isEnabled()) {\r
-+          stopDelegate();\r
-+      }\r
-+      delStarted = false;\r
-+    }\r
-+\r
-+    public Time getDuration()\r
-+    {\r
-+      return delegate.getDuration();\r
-+    }\r
-+\r
-+    public PushBufferStream [] getStreams()\r
-+    {\r
-+      return monitorStreams;\r
-+    }\r
-+\r
-+    void startDelegate() throws IOException\r
-+    {\r
-+      delegate.start();\r
-+    }\r
-+\r
-+    void stopDelegate() throws IOException\r
-+    {\r
-+      delegate.stop();\r
-+    }\r
-+\r
-+}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java        (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java        (revision 178)\r
-@@ -0,0 +1,196 @@\r
-+/*\r
-+ * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.\r
-+ *\r
-+ * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,\r
-+ * modify and redistribute this software in source and binary code form,\r
-+ * provided that i) this copyright notice and license appear on all copies of\r
-+ * the software; and ii) Licensee does not utilize the software in a manner\r
-+ * which is disparaging to Sun.\r
-+ *\r
-+ * This software is provided "AS IS," without a warranty of any kind. ALL\r
-+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY\r
-+ * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR\r
-+ * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE\r
-+ * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING\r
-+ * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS\r
-+ * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,\r
-+ * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER\r
-+ * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF\r
-+ * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE\r
-+ * POSSIBILITY OF SUCH DAMAGES.\r
-+ *\r
-+ * This software is not designed or intended for use in on-line control of\r
-+ * aircraft, air traffic, aircraft navigation or aircraft communications; or in\r
-+ * the design, construction, operation or maintenance of any nuclear\r
-+ * facility. Licensee represents and warrants that it will not use or\r
-+ * redistribute the Software for such purposes.\r
-+ */\r
-+package jp.nyatla.nyartoolkit.jmf.utils;\r
-+\r
-+\r
-+\r
-+import javax.media.*;\r
-+import javax.media.protocol.*;\r
-+\r
-+import javax.media.util.BufferToImage;\r
-+import java.io.IOException;\r
-+import java.awt.*;\r
-+\r
-+public class MonitorStream implements PushBufferStream, BufferTransferHandler {\r
-+\r
-+    JmfCaptureListener img_listener;\r
-+    PushBufferStream actual = null;\r
-+    boolean dataAvailable = false;\r
-+    boolean terminate = false;\r
-+    boolean enabled = false;\r
-+    Object bufferLock = new Object();\r
-+    Buffer cbuffer = new Buffer();\r
-+    BufferTransferHandler transferHandler = null;\r
-+    Component component = null;\r
-+    MonitorCDS cds;\r
-+    BufferToImage bti = null;\r
-+    \r
-+    MonitorStream(PushBufferStream actual, MonitorCDS cds) {\r
-+      this.actual = actual;\r
-+      actual.setTransferHandler(this);\r
-+      this.cds = cds;\r
-+    }\r
-+\r
-+    public javax.media.Format getFormat()\r
-+    {\r
-+      return actual.getFormat();\r
-+    }\r
-+    /**\r
-+     * \94ñ\93¯\8aúREAD\r
-+     */\r
-+    public void read(Buffer buffer) throws IOException\r
-+    {\r
-+      // Wait for data to be available\r
-+      // Doesn't get used much because the transferData\r
-+      // call is made when data IS available. And most\r
-+      // Processors/Players read the data in the same\r
-+      // thread that called transferData, although that's\r
-+      // not a safe assumption to make\r
-+      if (!dataAvailable) {\r
-+          synchronized (bufferLock) {\r
-+              while (!dataAvailable && !terminate) {\r
-+                  try {\r
-+                      bufferLock.wait(100);\r
-+                  } catch (InterruptedException ie) {\r
-+                  }\r
-+              }\r
-+          }\r
-+      }\r
-+\r
-+      if (dataAvailable) {\r
-+          synchronized (bufferLock) {\r
-+              // Copy the buffer attributes, but swap the data\r
-+              // attributes so that no extra copy is made.\r
-+              buffer.copy(cbuffer, true);\r
-+              //dataAvailable = false;\r
-+          }\r
-+      }\r
-+//    return;\r
-+    }\r
-+    public void setCaptureListener(JmfCaptureListener i_listener)\r
-+    {\r
-+      img_listener=i_listener;\r
-+    }\r
-+\r
-+    public void transferData(PushBufferStream pbs)\r
-+    {\r
-+      // Get the data from the original source stream\r
-+      synchronized (bufferLock) {\r
-+          try {\r
-+              pbs.read(cbuffer);\r
-+          } catch (IOException ioe) {\r
-+              return;\r
-+          }\r
-+          dataAvailable = true;\r
-+          bufferLock.notifyAll();\r
-+      }\r
-+      if(img_listener!=null){\r
-+          img_listener.onUpdateBuffer(cbuffer);\r
-+      }\r
-+      \r
-+/*\r
-+      // Display data if monitor is active\r
-+      if (isEnabled()) {\r
-+          if (bti == null) {\r
-+              VideoFormat vf = (VideoFormat) cbuffer.getFormat();\r
-+              bti = new BufferToImage(vf);\r
-+          }\r
-+          if (bti != null && component != null) {\r
-+              Image im = bti.createImage(cbuffer);\r
-+              Graphics g = component.getGraphics();\r
-+              Dimension size = component.getSize();\r
-+              if (g != null)\r
-+                  g.drawImage(im, 0, 0, component);\r
-+          }\r
-+      }\r
-+*/\r
-+      // Maybe synchronize this with setTransferHandler() ?\r
-+      if (transferHandler != null && cds.delStarted)\r
-+          transferHandler.transferData(this);\r
-+    }\r
-+\r
-+    public void setTransferHandler(BufferTransferHandler transferHandler) {\r
-+      this.transferHandler = transferHandler;\r
-+    }\r
-+\r
-+    public boolean setEnabled(boolean value) {\r
-+      enabled = value;\r
-+      if (value == false) {\r
-+          if (!cds.delStarted) {\r
-+              try {\r
-+                  cds.stopDelegate();\r
-+              } catch (IOException ioe) {\r
-+              }\r
-+          }\r
-+      } else {\r
-+          // Start the capture datasource if the monitor is enabled\r
-+          try {\r
-+              cds.startDelegate();\r
-+          }catch (IOException ioe) {\r
-+          }\r
-+      }\r
-+      return enabled;\r
-+    }\r
-+\r
-+    public boolean isEnabled()\r
-+    {\r
-+      return enabled;\r
-+    }\r
-+\r
-+\r
-+\r
-+    public float setPreviewFrameRate(float rate)\r
-+    {\r
-+      System.err.println("TODO");\r
-+      return rate;\r
-+    }\r
-+      \r
-+    public ContentDescriptor getContentDescriptor()\r
-+    {\r
-+      return actual.getContentDescriptor();\r
-+    }\r
-+\r
-+    public long getContentLength()\r
-+    {\r
-+      return actual.getContentLength();\r
-+    }\r
-+\r
-+    public boolean endOfStream() {\r
-+      return actual.endOfStream();\r
-+    }\r
-+\r
-+    public Object [] getControls() {\r
-+      return new Object[0];\r
-+    }\r
-+\r
-+    public Object getControl(String str) {\r
-+      return null;\r
-+    }\r
-+\r
-+\r
-+}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java   (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java   (revision 178)\r
-@@ -0,0 +1,14 @@\r
-+/**\r
-+ * JMF\82¨\8eè\8cy\83L\83\83\83v\83`\83\83\97p\83\8a\83X\83i\r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail@ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.jmf.utils;\r
-+\r
-+import javax.media.Buffer;\r
-+\r
-+public interface  JmfCaptureListener{\r
-+    public void onUpdateBuffer(Buffer i_buffer);\r
-+    \r
-+}\r
-\ No newline at end of file\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java     (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java     (revision 178)\r
-@@ -0,0 +1,180 @@\r
-+/**\r
-+ * JMF\82¨\8eè\8cy\83L\83\83\83v\83`\83\83\83N\83\89\83X\r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail@ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.jmf.utils;\r
-+\r
-+\r
-+\r
-+import javax.media.*;\r
-+import javax.media.protocol.*;\r
-+import javax.media.control.*;\r
-+import javax.media.format.*;\r
-+import java.awt.*;\r
-+import java.util.*;\r
-+import javax.media.protocol.DataSource;\r
-+\r
-+import jp.nyatla.nyartoolkit.NyARException;\r
-+\r
-+\r
-+\r
-+\r
-+\r
-+public class JmfCameraCapture\r
-+{\r
-+    private Dimension image_size;\r
-+    private JmfCaptureListener capture_listener;\r
-+    private DataSource jmf_data_source;\r
-+    private MonitorStream jmf_monitor_stream;\r
-+    private Processor jmf_processor;\r
-+    private VideoFormat jmf_video_format;\r
-+    \r
-+    private Buffer read_buf=new Buffer();\r
-+    public static final String PIXEL_FORMAT_RGB="RGB";\r
-+    public JmfCameraCapture(int i_width,int i_height,float i_rate,String i_pixcel_format)\r
-+    {\r
-+        String encoding = i_pixcel_format;//comboEncoding.getSelectedItem();\r
-+        image_size = new Dimension(i_width,i_height);\r
-+        jmf_video_format = new VideoFormat(encoding, image_size, Format.NOT_SPECIFIED,null,i_rate);\r
-+    }\r
-+    public Dimension getSize()\r
-+    {\r
-+      return image_size;\r
-+    }\r
-+    public javax.media.Buffer readBuffer() throws NyARException\r
-+    {\r
-+      if(jmf_monitor_stream==null){\r
-+            throw new NyARException();\r
-+      }\r
-+        try{\r
-+            jmf_monitor_stream.read(read_buf);\r
-+        }catch(Exception e){\r
-+            throw new NyARException(e);\r
-+        }\r
-+        return read_buf;\r
-+    }\r
-+    public void setCaptureListener(JmfCaptureListener i_listener) throws NyARException\r
-+    {\r
-+      if(jmf_processor!=null){\r
-+          throw new NyARException();\r
-+      }\r
-+      capture_listener=i_listener;\r
-+      \r
-+    }\r
-+    public void start() throws NyARException\r
-+    {\r
-+        \r
-+        DataSource ds=getCaptureDS(jmf_video_format);\r
-+        VideoFormat[] formats=new VideoFormat[]{new VideoFormat(null)};\r
-+        ProcessorModel pm = new ProcessorModel(ds,formats,null);//, formats, ftd);\r
-+        Processor processor;\r
-+        try {\r
-+            processor = Manager.createRealizedProcessor(pm);\r
-+        } catch (Exception e){\r
-+            // Make sure the capture devices are released\r
-+            ds.disconnect();\r
-+            throw new NyARException(e);\r
-+        }\r
-+        // Get the monitor control:\r
-+        // Since there are more than one MonitorControl objects\r
-+        // exported by the DataSource, we get the specific one\r
-+        // that is also the MonitorStream object.\r
-+        jmf_monitor_stream=(MonitorStream)ds.getControl("jmfsample.MonitorStream");\r
-+      jmf_monitor_stream.setCaptureListener(capture_listener);\r
-+        jmf_data_source=ds;\r
-+        jmf_processor=processor;\r
-+        jmf_processor.start();\r
-+    }\r
-+    public void stop()\r
-+    {\r
-+        jmf_processor.stop();\r
-+        jmf_processor.close();\r
-+        jmf_processor = null;\r
-+        \r
-+    }\r
-+    protected void finalize()\r
-+    {\r
-+        if(jmf_processor!=null){\r
-+        jmf_processor.stop();\r
-+        jmf_processor.close();\r
-+        jmf_processor = null;\r
-+        }\r
-+    }\r
-+    private static DataSource getCaptureDS(VideoFormat vf) {\r
-+      DataSource dsVideo = null;\r
-+      DataSource ds = null;\r
-+\r
-+      // Create a capture DataSource for the video\r
-+      // If there is no video capture device, then exit with null\r
-+      if (vf != null) {\r
-+          dsVideo = createDataSource(vf);\r
-+          if (dsVideo == null)\r
-+              return null;\r
-+      }\r
-+\r
-+\r
-+      // Create the monitoring datasource wrapper\r
-+      if (dsVideo != null) {\r
-+          dsVideo = new MonitorCDS(dsVideo);\r
-+          return dsVideo;\r
-+      }\r
-+\r
-+      // Merge the data sources, if both audio and video are available\r
-+      try {\r
-+          ds = Manager.createMergingDataSource(new DataSource[]{dsVideo});\r
-+      } catch (IncompatibleSourceException ise){\r
-+          return null;\r
-+      }\r
-+\r
-+      return ds;\r
-+    }\r
-+\r
-+    private static DataSource createDataSource(Format format) {\r
-+      DataSource ds;\r
-+      Vector devices;\r
-+      CaptureDeviceInfo cdi;\r
-+      MediaLocator ml;\r
-+\r
-+      // Find devices for format\r
-+      devices = CaptureDeviceManager.getDeviceList(format);\r
-+      if (devices.size() < 1) {\r
-+          System.err.println("! No Devices for " + format);\r
-+          return null;\r
-+      }\r
-+      // Pick the first device\r
-+      cdi = (CaptureDeviceInfo) devices.elementAt(0);\r
-+\r
-+      ml = cdi.getLocator();\r
-+\r
-+      try {\r
-+          ds = Manager.createDataSource(ml);\r
-+          ds.connect();\r
-+          if (ds instanceof CaptureDevice)\r
-+          {\r
-+              setCaptureFormat((CaptureDevice) ds, format);\r
-+          }\r
-+      } catch (Exception e) {\r
-+          System.err.println(e);\r
-+          return null;\r
-+      }\r
-+      return ds;\r
-+    }\r
-+\r
-+    private static void setCaptureFormat(CaptureDevice cdev, Format format) {\r
-+      FormatControl [] fcs = cdev.getFormatControls();\r
-+      if (fcs.length < 1){\r
-+          return;\r
-+      }\r
-+      FormatControl fc = fcs[0];\r
-+      Format [] formats = fc.getSupportedFormats();\r
-+      for (int i = 0; i < formats.length; i++) {\r
-+          if (formats[i].matches(format)){\r
-+              format = formats[i].intersects(format);\r
-+              fc.setFormat(format);\r
-+              break;\r
-+          }\r
-+      }\r
-+    }\r
-+}\r
-\ No newline at end of file\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/JmfCaptureTest.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/JmfCaptureTest.java      (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/JmfCaptureTest.java      (revision 178)\r
-@@ -0,0 +1,58 @@\r
-+/**\r
-+ * VFM\83L\83\83\83v\83`\83\83\83e\83X\83g\83v\83\8d\83O\83\89\83\80\r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail@ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.jmf.sample;\r
-+\r
-+import javax.media.*;\r
-+\r
-+import javax.media.util.BufferToImage;\r
-+import javax.media.format.*;\r
-+import jp.nyatla.nyartoolkit.NyARException;\r
-+import jp.nyatla.nyartoolkit.jmf.utils.*;\r
-+\r
-+import java.awt.*;\r
-+\r
-+\r
-+\r
-+public class JmfCaptureTest extends Frame implements JmfCaptureListener{\r
-+    public JmfCaptureTest() throws NyARException\r
-+    {\r
-+        setTitle("JmfCaptureTest");\r
-+        setBounds(0,0,320+64,240+64);     \r
-+        capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);\r
-+        capture.setCaptureListener(this);\r
-+    }\r
-+\r
-+\r
-+\r
-+    private JmfCameraCapture  capture;\r
-+    public void onUpdateBuffer(Buffer i_buffer)\r
-+    {\r
-+      BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());\r
-+      Image img=b2i.createImage(i_buffer);\r
-+        Graphics g = getGraphics();        \r
-+        g.drawImage(img, 32, 32,this);       \r
-+    }\r
-+    private void startCapture()\r
-+    {\r
-+      try{\r
-+          capture.start();\r
-+      }catch(Exception e){\r
-+          e.printStackTrace();\r
-+      }\r
-+    }\r
-+    public static void main(String[] args) {\r
-+      try{\r
-+            JmfCaptureTest mainwin = new JmfCaptureTest();\r
-+            mainwin.setVisible(true);\r
-+            mainwin.startCapture();\r
-+      }catch(Exception e){\r
-+          e.printStackTrace();\r
-+      }\r
-+        \r
-+    }\r
-+\r
-+}\r
-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java (revision 0)\r
-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java (revision 178)\r
-@@ -0,0 +1,116 @@\r
-+/**\r
-+ * VFM+ARToolkit\83e\83X\83g\83v\83\8d\83O\83\89\83\80\r
-+ * \83J\83\81\83\89\82©\82ç\8eæ\82è\8d\9e\82ñ\82¾\83f\81[\83^\82©\82ç\83}\81[\83J\81[\82ð\8c\9f\8fo\82µ\82Ä\81A\88ê\92v\93x\82Æ\95Ï\8a·\8ds\97ñ\82ð\95\\8e¦\82µ\82Ü\82·\81B\r
-+ * (c)2008 A\8cÕ\81\97nyatla.jp\r
-+ * airmail(at)ebony.plala.or.jp\r
-+ * http://nyatla.jp/\r
-+ */\r
-+package jp.nyatla.nyartoolkit.jmf.sample;\r
-+\r
-+import javax.media.*;\r
-+\r
-+import javax.media.util.BufferToImage;\r
-+import javax.media.format.*;\r
-+\r
-+import jp.nyatla.nyartoolkit.NyARException;\r
-+import jp.nyatla.nyartoolkit.jmf.utils.*;\r
-+\r
-+import java.awt.*;\r
-+\r
-+import jp.nyatla.nyartoolkit.core.*;\r
-+import jp.nyatla.nyartoolkit.detector.*;\r
-+\r
-+\r
-+\r
-+\r
-+\r
-+\r
-+public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener\r
-+{\r
-+    private final String CARCODE_FILE ="../../Data/patt.hiro";\r
-+    private final String PARAM_FILE   ="../../Data/camera_para.dat";\r
-+    private JmfCameraCapture capture;\r
-+    NyARSingleDetectMarker nya;\r
-+    JmfNyARRaster_RGB raster;\r
-+\r
-+    public NyarToolkitLinkTest() throws NyARException,NyARException\r
-+    {\r
-+        setTitle("JmfCaptureTest");\r
-+        setBounds(0,0,320+64,240+64);     \r
-+        //\83L\83\83\83v\83`\83\83\82Ì\8f\80\94õ\r
-+        capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);\r
-+        capture.setCaptureListener(this);\r
-+        \r
-+        //NyARToolkit\82Ì\8f\80\94õ\r
-+        NyARParam ar_param=new NyARParam();\r
-+        NyARCode ar_code  =new NyARCode(16,16);\r
-+        ar_param.loadFromARFile(PARAM_FILE);\r
-+        ar_param.changeSize(320,240);\r
-+        nya=new NyARSingleDetectMarker(ar_param,ar_code,80.0);\r
-+        ar_code.loadFromARFile(CARCODE_FILE);\r
-+        //\83L\83\83\83v\83`\83\83\83C\83\81\81[\83W\97p\82Ì\83\89\83X\83^\82ð\8f\80\94õ\r
-+        raster=new JmfNyARRaster_RGB(320,240);\r
-+    }\r
-+\r
-+\r
-+\r
-+    public void onUpdateBuffer(Buffer i_buffer)\r
-+    {\r
-+      try{\r
-+            //\83L\83\83\83v\83`\83\83\82µ\82½\83o\83b\83t\83@\82ð\83\89\83X\83^\82É\83Z\83b\83g\r
-+          raster.setBuffer(i_buffer);\r
-+\r
-+            //\83L\83\83\83v\83`\83\83\82µ\82½\83C\83\81\81[\83W\82ð\95\\8e¦\97p\82É\89Á\8dH\r
-+            BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());\r
-+            Image img=b2i.createImage(i_buffer);\r
-+\r
-+            Graphics g = getGraphics();            \r
-+            double[][] atm=null;\r
-+\r
-+            //\83}\81[\83J\81[\8c\9f\8fo\r
-+            boolean is_marker_exist=nya.detectMarkerLite(raster,100);\r
-+            if(is_marker_exist){\r
-+                //\95Ï\8a·\8ds\97ñ\82ð\8eæ\93¾\r
-+                atm=nya.getTransmationMatrix().getArray();\r
-+            }\r
-+            //\8fî\95ñ\82ð\89æ\96Ê\82É\8f\91\82­       \r
-+            g.drawImage(img, 32, 32,this);\r
-+            if(is_marker_exist){\r
-+                g.drawString("\83}\81[\83J\81[\8c\9f\8fo:"+nya.getConfidence(),32,50);\r
-+                for(int i=0;i<3;i++){\r
-+                    for(int i2=0;i2<4;i2++){\r
-+                      g.drawString("["+i+"]["+i2+"]"+atm[i][i2],32,50+(1+i2*3+i)*16);\r
-+                    }\r
-+                    \r
-+                }\r
-+            }else{\r
-+                g.drawString("\83}\81[\83J\81[\96¢\8c\9f\8fo:",32,100);\r
-+            }\r
-+      }catch(Exception e){\r
-+          e.printStackTrace();\r
-+      }\r
-+       \r
-+        \r
-+        \r
-+        \r
-+    }\r
-+    private void startCapture()\r
-+    {\r
-+      try{\r
-+          capture.start();\r
-+      }catch(Exception e){\r
-+          e.printStackTrace();\r
-+      }\r
-+    }\r
-+    public static void main(String[] args) {\r
-+      try{\r
-+            NyarToolkitLinkTest mainwin = new NyarToolkitLinkTest();\r
-+            mainwin.setVisible(true);\r
-+            mainwin.startCapture();\r
-+      }catch(Exception e){\r
-+          e.printStackTrace();\r
-+      }\r
-+        \r
-+    }\r
-+\r
-+}\r
--2008.03.29 R.Iizuka nyatla.jp\r
-+2008.03.29 R.Iizuka A\8cÕ\81\97nyatla.jp\r
-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARCode.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARCode.java (revision 174)\r
-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARCode.java (revision 178)\r
-@@ -33,6 +33,7 @@\r
- package jp.nyatla.nyartoolkit.core;\r
\r
- import java.io.FileInputStream;\r
-+import java.io.InputStream;\r
- import java.io.InputStreamReader;\r
- import java.io.StreamTokenizer;\r
\r
-@@ -84,19 +85,32 @@\r
-       pat=new int[4][height][width][3];//static int    pat[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];\r
-       patBW=new short[4][height][width];//static int    patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];\r
-     }\r
--\r
--\r
-     /**\r
-      * int arLoadPatt( const char *filename );\r
-      * ARToolKit\82Ì\83p\83^\81[\83\93\83t\83@\83C\83\8b\82ð\83\8d\81[\83h\82·\82é\81B\r
-+     * \83t\83@\83C\83\8b\8c`\8e®\82ÍBGR\8c`\8e®\82Å\8bL\98^\82³\82ê\82½\83p\83^\81[\83\93\83t\83@\83C\83\8b\82Å\82 \82é\82±\82Æ\81B\r
-      * @param filename\r
-      * @return\r
-      * @throws Exception\r
-      */\r
-     public void loadFromARFile(String filename) throws NyARException\r
-     {\r
-+      try {\r
-+          loadFromARFile(new FileInputStream(filename));\r
-+\r
-+      } catch (Exception e) {\r
-+      throw new NyARException(e);\r
-+      }\r
-+    }\r
-+    /**\r
-+     * \r
-+     * @param i_stream\r
-+     * @throws NyARException\r
-+     */\r
-+    public void loadFromARFile(InputStream i_stream) throws NyARException\r
-+    {\r
-       try{\r
--            StreamTokenizer st=new StreamTokenizer(new InputStreamReader(new FileInputStream(filename)));\r
-+            StreamTokenizer st=new StreamTokenizer(new InputStreamReader(i_stream));\r
-             //\83p\83^\81[\83\93\83f\81[\83^\82ÍGBRA\82Å\95À\82ñ\82Å\82é\81B\r
-             for(int h=0; h<4; h++ ) {\r
-                 int l = 0;\r
-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARParam.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARParam.java        (revision 174)\r
-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARParam.java        (revision 178)\r
-@@ -72,18 +72,25 @@\r
-      */\r
-     public void loadFromARFile(String i_filename) throws NyARException\r
-     {\r
--      try{\r
--            FileInputStream fs=new FileInputStream(i_filename);\r
--            NyARParam new_inst[]=arParamLoad(fs,1);\r
--            fs.close();\r
--            xsize     =new_inst[0].xsize;\r
--            ysize     =new_inst[0].ysize;\r
--            mat       =new_inst[0].mat;\r
--            dist_factor=new_inst[0].dist_factor;\r
--      }catch(Exception e){\r
--          throw new NyARException(e);\r
--      }\r
-+        try {\r
-+            loadFromARFile(new FileInputStream(i_filename));\r
-+        } catch (Exception e) {\r
-+            throw new NyARException(e);\r
-+        }\r
-     }\r
-+    public void loadFromARFile(InputStream i_stream) throws NyARException\r
-+    {\r
-+        try {\r
-+            NyARParam new_inst[] = arParamLoad(i_stream, 1);\r
-+            i_stream.close();\r
-+            xsize = new_inst[0].xsize;\r
-+            ysize = new_inst[0].ysize;\r
-+            mat = new_inst[0].mat;\r
-+            dist_factor = new_inst[0].dist_factor;\r
-+        } catch (Exception e) {\r
-+            throw new NyARException(e);\r
-+        }\r
-+    }\r
-     /*static double dot( double a1, double a2, double a3,double b1, double b2, double b3 )*/\r
-     private static double dot( double a1, double a2, double a3,double b1, double b2, double b3 )\r
-     {\r
-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt.java      (revision 174)\r
-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt.java      (revision 178)\r
-@@ -49,7 +49,7 @@\r
-     public double getConfidence();\r
-     public int getDirection();\r
-     public void evaluate(NyARCode i_code);\r
--    public void setPatt(NyARColorPatt i_target_patt) throws NyARException;\r
-+    public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException;\r
- }\r
\r
\r
-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java    (revision 174)\r
-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java    (revision 178)\r
-@@ -54,7 +54,7 @@\r
-     public int getDirection(){\r
-       return dir;\r
-     }\r
--    public void setPatt(NyARColorPatt i_target_patt) throws NyARException\r
-+    public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException\r
-     {\r
-       width=i_target_patt.getWidth();\r
-       height=i_target_patt.getHeight();\r
-@@ -81,11 +81,12 @@\r
-         }\r
-         datapow = Math.sqrt( (double)sum );\r
-         if(datapow == 0.0){\r
--            throw new NyARException();\r
-+            return false;//            throw new NyARException();\r
- //            dir.set(0);//*dir  = 0;\r
- //            cf.set(-1.0);//*cf   = -1.0;\r
- //            return -1;\r
--        }     \r
-+        }\r
-+        return true;\r
-     }\r
-     /**\r
-      * public int pattern_match(short[][][] data,IntPointer dir,DoublePointer cf)\r
-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java       (revision 174)\r
-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java       (revision 178)\r
-@@ -59,7 +59,7 @@\r
-     public int getDirection(){\r
-       return dir;\r
-     }\r
--    public void setPatt(NyARColorPatt i_target_patt) throws NyARException\r
-+    public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException\r
-     {\r
-       width=i_target_patt.getWidth();\r
-       height=i_target_patt.getHeight();\r
-@@ -87,11 +87,12 @@\r
-         }\r
-         datapow = Math.sqrt( (double)sum );\r
-         if(datapow == 0.0){\r
--            throw new NyARException();\r
-+            return false;//throw new NyARException();\r
- //            dir.set(0);//*dir  = 0;\r
- //            cf.set(-1.0);//*cf   = -1.0;\r
- //            return -1;\r
--        }     \r
-+        }\r
-+        return true;\r
-     }\r
-     /**\r
-      * public int pattern_match(short[][][] data,IntPointer dir,DoublePointer cf)\r
-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java   (revision 174)\r
-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java   (revision 178)\r
-@@ -47,7 +47,7 @@\r
-     private int dir=0;\r
-     private int ave;\r
-     private int[][][] input=new int[height][width][3];\r
--    public void setPatt(NyARColorPatt i_target_patt) throws NyARException\r
-+    public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException\r
-     {\r
-       width=i_target_patt.getWidth();\r
-       height=i_target_patt.getHeight();\r
-@@ -71,11 +71,12 @@\r
-         \r
-         datapow = Math.sqrt( (double)sum );\r
-         if( datapow == 0.0 ){\r
--            throw new NyARException();\r
-+            return false;//            throw new NyARException();\r
- //            dir.set(0);//*dir  = 0;\r
- //            cf.set(-1.0);//*cf   = -1.0;\r
- //            return -1;\r
-         }\r
-+        return true;\r
-     }\r
-     public double getConfidence()\r
-     {\r
-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java\r
-===================================================================\r
---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java       (revision 174)\r
-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java       (revision 178)\r
-@@ -91,7 +91,10 @@\r
-       //\83p\83^\81[\83\93\82Ì\95]\89¿\83I\83u\83W\83F\83N\83g\82ð\8dì\82é\81B\r
-       NyARMatchPatt_Color_WITHOUT_PCA eva=new NyARMatchPatt_Color_WITHOUT_PCA();\r
-       //\83p\83^\81[\83\93\82ð\95]\89¿\8aí\82É\83Z\83b\83g\r
--      eva.setPatt(patt);\r
-+      if(!eva.setPatt(patt)){\r
-+          //\8cv\8eZ\82É\8e¸\94s\82µ\82½\81B\r
-+          return false;\r
-+      }\r
-       //\83R\81[\83h\82Æ\94ä\8ar\82·\82é\r
-       eva.evaluate(code);\r
-       int square_index=0;\r
index 601f2eb..bdcf695 100644 (file)
@@ -1,7 +1,7 @@
 ARToolkit Java class library NyARToolkit.\r
 Copyright (C)2008 R.Iizuka\r
 \r
-version Alpha 0.8.20080412.0\r
+version 1.0.0.20080428.0\r
 \r
 http://nyatla.jp/\r
 airmail(at)ebony.plala.or.jp\r
@@ -112,7 +112,9 @@ sampleディレクトリ以下にあるソースはAPIは仕様が固まって
 クラスは関数機能毎にまとめた作りになっていますので、オリジナルの\r
 コード読んだことがあれば、なんとなく判ると思います。\r
 \r
-\r
+演算性能は、Windows環境下でVCリリース版の約85%です。\r
+マーカー認識部分はネイティブ版よりも低速ですが、変換行列計算部分\r
+はネイティブ版よりも高速に動作します。\r
 \r
 \r
 ・足りない機能等\r
@@ -140,4 +142,4 @@ NyARToolkitを使って面白いものが出来たら、是非教えてくださ
 \r
 ではでは、楽しく遊んでくださいネ。\r
 \r
-2008.03.29 R.Iizuka A虎@nyatla.jp\r
+2008.04.28 R.Iizuka A虎@nyatla.jp\r
index aa87143..55f018b 100644 (file)
@@ -2,10 +2,10 @@
 <classpath>\r
        <classpathentry path="src" kind="src"/>\r
        <classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>\r
-       <classpathentry path="C:/Program Files/Java/Java3D/1.4.0_01/lib/ext/j3dcore.jar" kind="lib"/>\r
-       <classpathentry path="C:/Program Files/Java/Java3D/1.4.0_01/lib/ext/j3dutils.jar" kind="lib"/>\r
-       <classpathentry path="C:/Program Files/Java/Java3D/1.4.0_01/lib/ext/vecmath.jar" kind="lib"/>\r
        <classpathentry path="C:/Program Files/JMF2.1.1e/lib/jmf.jar" kind="lib"/>\r
+       <classpathentry path="C:/Program Files/Java/Java3D/1.5.1/lib/ext/j3dcore.jar" kind="lib"/>\r
+       <classpathentry path="C:/Program Files/Java/Java3D/1.5.1/lib/ext/j3dutils.jar" kind="lib"/>\r
+       <classpathentry path="C:/Program Files/Java/Java3D/1.5.1/lib/ext/vecmath.jar" kind="lib"/>\r
        <classpathentry path="/NyARJMF" combineaccessrules="false" kind="src"/>\r
        <classpathentry path="/NyARToolkit" combineaccessrules="false" kind="src"/>\r
        <classpathentry path="bin" kind="output"/>\r
index 73d2ba3..1974a57 100644 (file)
@@ -18,47 +18,59 @@ import jp.nyatla.nyartoolkit.NyARException;
 import jp.nyatla.nyartoolkit.core.NyARParam;\r
 import jp.nyatla.nyartoolkit.jmf.utils.*;\r
 \r
-\r
+/**\r
+ * \r
+ * @author A虎@\r
+ * このクラスは、Java3Dと互換性のあるNyARToolkitのラスタイメージを保持します。\r
+ *\r
+ */\r
 public class J3dNyARRaster_RGB extends JmfNyARRaster_RGB\r
 {\r
-//    public ImageUpdater updater; \r
     private ImageComponent2D imc2d;\r
     private byte[] i2d_buf;\r
+    private BufferedImage bufferd_image;\r
 \r
+    /**\r
+     * JMFのキャプチャ画像をこのクラスのBufferedImageにコピーします。\r
+     * @param i_buffer\r
+     * 画像の格納されたバッファを指定して下さい。\r
+     * 画像サイズはコンストラクタで与えたパラメタと同じサイズである必要があります。\r
+     */\r
     public void setBuffer(javax.media.Buffer i_buffer) throws NyARException\r
     {\r
         super.setBuffer(i_buffer);\r
         //メモ:この時点では、ref_dataにはi_bufferの参照値が入ってる。\r
-        synchronized(imc2d){\r
+        synchronized(this){\r
             //キャプチャデータをi2dのバッファにコピーする。(これ省略したいなあ…。)\r
-            System.arraycopy(ref_buf,0,i2d_buf,0,this.i2d_buf.length);\r
+            System.arraycopy(this.ref_buf,0,this.i2d_buf,0,this.i2d_buf.length);\r
         }\r
        //ここでref_bufの参照値をref_bufへ移動\r
-        ref_buf=i2d_buf;\r
+        this.ref_buf=this.i2d_buf;\r
     }  \r
     public J3dNyARRaster_RGB(NyARParam i_cparam)\r
     {\r
        super(i_cparam.getX(),i_cparam.getY());\r
 \r
        //RGBのラスタを作る。\r
-//     ColorSpace cs=ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);\r
-//     ComponentColorModel cm;\r
-//     cm=new ComponentColorModel(cs,new int[]{8,8,8},false,false,ComponentColorModel.OPAQUE,DataBuffer.TYPE_BYTE);\r
-//     java.awt.image.WritableRaster raster=cm.createCompatibleWritableRaster(width,height);\r
-//     i2d_buf=((DataBufferByte)raster.getDataBuffer()).getData();\r
-//     BufferedImage background_image = new BufferedImage(cm,raster, false, null);\r
-       BufferedImage background_image = new BufferedImage(width,height,BufferedImage.TYPE_3BYTE_BGR);\r
-       i2d_buf=((DataBufferByte)background_image.getRaster().getDataBuffer()).getData();\r
-       //\r
-       imc2d= new ImageComponent2D(ImageComponent2D.FORMAT_RGB, background_image, true, true);\r
-       imc2d.setCapability(ImageComponent.ALLOW_IMAGE_WRITE);\r
+       this.bufferd_image = new BufferedImage(this.width,this.height,BufferedImage.TYPE_3BYTE_BGR);\r
+       i2d_buf=((DataBufferByte)bufferd_image.getRaster().getDataBuffer()).getData();\r
+        this.imc2d= new ImageComponent2D(ImageComponent2D.FORMAT_RGB, this.bufferd_image, true, true);\r
+        imc2d.setCapability(ImageComponent.ALLOW_IMAGE_WRITE);\r
     }\r
     /**\r
-     * このオブジェクトと連動するImageComponent2Dオブジェクトの参照値を得る。\r
-     * @return\r
+     * 自身の格納しているImageComponent2Dオブジェクトを作り直します。\r
+     * Java3D1.5がDirectXで動いた(らしいとき)に、ImageComponent2Dのインスタンス\r
+     * IDが異ならないと、Behavior内でイメージの更新を通知できない事象に対応するために実装してあります。\r
+     * Behavior内でgetImageComponent2()関数を実行する直前に呼び出すことで、この事象を回避することができます。\r
+     * \r
      */\r
+    public void renewImageComponent2D()\r
+    {\r
+        this.imc2d= new ImageComponent2D(ImageComponent2D.FORMAT_RGB, this.bufferd_image, true, true);\r
+        this.imc2d.setCapability(ImageComponent.ALLOW_IMAGE_WRITE);    \r
+    }\r
     public ImageComponent2D getImageComponent2D()\r
     {\r
-       return imc2d;\r
+       return this.imc2d;\r
     }\r
 }\r
index af3fc6f..56ed926 100644 (file)
@@ -147,7 +147,6 @@ class NyARBehavior extends Behavior
            listener=i_listener;\r
        }\r
     }\r
-\r
     /**\r
      * いわゆるイベントハンドラ\r
      */\r
@@ -158,7 +157,8 @@ class NyARBehavior extends Behavior
                Transform3D t3d=null;\r
                boolean is_marker_exist=false;\r
                if(back_ground!=null){\r
-                    back_ground.setImage(raster.getImageComponent2D());                    \r
+                   raster.renewImageComponent2D();/*DirectXモードのときの対策*/\r
+                    back_ground.setImage(raster.getImageComponent2D());\r
                }\r
                 if(raster.hasData()){\r
                     is_marker_exist=related_nya.detectMarkerLite(raster, 100);\r
index d36ebfa..9e9dd9e 100644 (file)
@@ -81,8 +81,18 @@ public class JmfNyARRaster_RGB implements NyARRaster
     public int getPixelTotal(int i_x,int i_y)\r
     {\r
         int bp=(i_x+i_y*width)*3;\r
-        return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);\r
+        byte[] ref=this.ref_buf;\r
+        return (ref[bp] & 0xff)+(ref[bp+1] & 0xff)+(ref[bp+2] & 0xff);\r
     }\r
+    public void getPixelTotalRowLine(int i_row,int[] o_line)\r
+    {\r
+        final byte[] ref=this.ref_buf;\r
+        int bp=(i_row+1)*this.width*3-3;\r
+        for(int i=this.width-1;i>=0;i--){\r
+           o_line[i]=(ref[bp] & 0xff)+(ref[bp+1] & 0xff)+(ref[bp+2] & 0xff);\r
+           bp-=3;\r
+       }\r
+    }    \r
     public int getWidth()\r
     {\r
         return width;\r
@@ -91,12 +101,13 @@ public class JmfNyARRaster_RGB implements NyARRaster
     {\r
         return height;\r
     }\r
-    public void pickRgbArray(int i_x,int i_y,int[] i_rgb)\r
+    public void getPixel(int i_x,int i_y,int[] i_rgb)\r
     {\r
-        int bp=(i_x+i_y*width)*3;\r
-        i_rgb[0]=(ref_buf[bp+red_idx] & 0xff);//R\r
-        i_rgb[1]=(ref_buf[bp+green_idx] & 0xff);//G\r
-        i_rgb[2]=(ref_buf[bp+blue_idx] & 0xff);//B\r
+        int bp=(i_x+i_y*this.width)*3;\r
+        byte[] ref=this.ref_buf;\r
+        i_rgb[0]=(ref[bp+this.red_idx] & 0xff);//R\r
+        i_rgb[1]=(ref[bp+this.green_idx] & 0xff);//G\r
+        i_rgb[2]=(ref[bp+this.blue_idx] & 0xff);//B\r
     }\r
     /**\r
      * ピクセルの順序タイプを返します。\r
@@ -115,5 +126,20 @@ public class JmfNyARRaster_RGB implements NyARRaster
     {\r
        return ref_buf!=null;\r
     }\r
-\r
+    public void getPixelSet(int[] i_x,int i_y[],int i_num,int[] o_rgb)\r
+    {\r
+       int ri=this.red_idx;\r
+       int bi=this.green_idx;\r
+       int gi=this.blue_idx;\r
+       int width=this.width;\r
+       byte[] ref=this.ref_buf;\r
+       int bp;\r
+       for(int i=i_num-1;i>=0;i--){\r
+           bp=(i_x[i]+i_y[i]*width)*3;\r
+           o_rgb[i*3+0]=(ref[bp+ri] & 0xff);//R\r
+           o_rgb[i*3+1]=(ref[bp+gi] & 0xff);//G\r
+           o_rgb[i*3+2]=(ref[bp+bi] & 0xff);//B\r
+       }       \r
+       return;\r
+    }\r
 }\r
index 034e881..ddda998 100644 (file)
@@ -15,7 +15,7 @@ import jp.nyatla.nyartoolkit.detector.*;
 public class GLNyARSingleDetectMarker extends NyARSingleDetectMarker\r
 {\r
     private double view_scale_factor=0.025;//#define VIEW_SCALEFACTOR          0.025           // 1.0 ARToolKit unit becomes 0.025 of my OpenGL units.\r
-    public GLNyARSingleDetectMarker(NyARParam i_param,NyARCode i_code,double i_marker_width)\r
+    public GLNyARSingleDetectMarker(NyARParam i_param,NyARCode i_code,double i_marker_width) throws NyARException\r
     {\r
        super(i_param,i_code,i_marker_width);   \r
     }\r
index 42a7368..270589d 100644 (file)
@@ -126,12 +126,12 @@ public class Param {
                NyARMat.matrixTrans(mat_at, mat_a );//if( arMatrixTrans( mat_at, mat_a ) < 0 ){\r
 \r
                NyARException.trap("未チェックのパス");\r
-               NyARMat.matrixMul( mat_wm1, mat_at, mat_a );//if( arMatrixMul( mat_wm1, mat_at, mat_a ) < 0 ) {\r
+               mat_wm1.matrixMul(mat_at, mat_a );//if( arMatrixMul( mat_wm1, mat_at, mat_a ) < 0 ) {\r
                NyARException.trap("未チェックのパス");\r
                mat_wm1.matrixSelfInv();//if( arMatrixSelfInv( mat_wm1 ) < 0 ) {\r
 \r
                NyARException.trap("未チェックのパス");\r
-               NyARMat.matrixMul( mat_wm2, mat_wm1, mat_at );//if( arMatrixMul( mat_wm2, mat_wm1, mat_at ) < 0 ) {\r
+               mat_wm2.matrixMul(mat_wm1, mat_at );//if( arMatrixMul( mat_wm2, mat_wm1, mat_at ) < 0 ) {\r
 \r
                //mat_cpara.row = AR_PARAM_CDMIN-1;//mat_cpara.row = AR_PARAM_CDMIN-1;\r
                //mat_cpara.clm = 1;\r
@@ -140,7 +140,7 @@ public class Param {
                NyARMat mat_cpara=new NyARMat(arParamGet_AR_PARAM_CDMIN-1,1);\r
                double[][] mat_cpara_array=mat_cpara.getArray();\r
                NyARException.trap("未チェックのパス");\r
-               NyARMat.matrixMul(mat_cpara, mat_wm2, mat_r );//if( arMatrixMul( &mat_cpara, mat_wm2, mat_r ) < 0 ) {\r
+               mat_cpara.matrixMul(mat_wm2, mat_r );//if( arMatrixMul( &mat_cpara, mat_wm2, mat_r ) < 0 ) {\r
 \r
                for(int i2=0;i<3;i++){\r
                    for(int i3=0;i3<4;i3++){\r
index f2f1021..e49acc0 100644 (file)
@@ -34,194 +34,13 @@ package jp.nyatla.nyartoolkit.core;
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.raster.*;\r
 \r
-/**\r
- * 24ビットカラーのマーカーを保持するために使うクラスです。\r
- * このクラスは、ARToolkitのパターンと、ラスタから取得したパターンを保持します。\r
- *\r
- */\r
-public class NyARColorPatt\r
+public interface NyARColorPatt\r
 {\r
-    public static final int AR_PATT_SAMPLE_NUM=64;//#define   AR_PATT_SAMPLE_NUM   64\r
-    private short extpat[][][];\r
-    private int width;\r
-    private int height;\r
-    public NyARColorPatt(int i_width,int i_height)\r
-    {\r
-       width=i_width;\r
-       height=i_height;\r
-       extpat=new short[i_height][i_width][3];\r
-    }\r
-    public short[][][] getPatArray()\r
-    {\r
-       return extpat;\r
-    }\r
-    public int getWidth()\r
-    {\r
-       return width;\r
-    }\r
-    public int getHeight()\r
-    {\r
-       return height;\r
-    }\r
-    private static void get_cpara( double world[][], double vertex[][],double para[][] ) throws NyARException\r
-    {\r
-        NyARMat a = new NyARMat( 8, 8 );\r
-        double[][] a_array=a.getArray();\r
-        NyARMat b = new NyARMat( 8, 1 );\r
-        double[][] b_array=b.getArray();\r
-        NyARMat c = new NyARMat( 8, 1 );\r
-        double[][] c_array=c.getArray();\r
-           \r
-        for(int i = 0; i < 4; i++ ) {\r
-            a_array[i*2][0]=world[i][0];//a->m[i*16+0]  = world[i][0];\r
-            a_array[i*2][1]=world[i][1];//a->m[i*16+1]  = world[i][1];\r
-            a_array[i*2][2]=1.0;//a->m[i*16+2]  = 1.0;\r
-            a_array[i*2][3]=0.0;//a->m[i*16+3]  = 0.0;\r
-            a_array[i*2][4]=0.0;//a->m[i*16+4]  = 0.0;\r
-            a_array[i*2][5]=0.0;//a->m[i*16+5]  = 0.0;\r
-            a_array[i*2][6]=-world[i][0] * vertex[i][0];//a->m[i*16+6]  = -world[i][0] * vertex[i][0];\r
-            a_array[i*2][7]=-world[i][1] * vertex[i][0];//a->m[i*16+7]  = -world[i][1] * vertex[i][0];\r
-            a_array[i*2+1][0]=0.0;//a->m[i*16+8]  = 0.0;\r
-            a_array[i*2+1][1]=0.0;//a->m[i*16+9]  = 0.0;\r
-            a_array[i*2+1][2]=0.0;//a->m[i*16+10] = 0.0;\r
-            a_array[i*2+1][3]=world[i][0];//a->m[i*16+11] = world[i][0];\r
-            a_array[i*2+1][4]=world[i][1];//a->m[i*16+12] = world[i][1];\r
-            a_array[i*2+1][5]=1.0;//a->m[i*16+13] = 1.0;\r
-            a_array[i*2+1][6]=-world[i][0] * vertex[i][1];//a->m[i*16+14] = -world[i][0] * vertex[i][1];\r
-            a_array[i*2+1][7]=-world[i][1] * vertex[i][1];//a->m[i*16+15] = -world[i][1] * vertex[i][1];\r
-            b_array[i*2+0][0]=vertex[i][0];//b->m[i*2+0] = vertex[i][0];\r
-            b_array[i*2+1][0]=vertex[i][1];//b->m[i*2+1] = vertex[i][1];\r
-        }\r
-//         JartkException.trap("未チェックのパス");\r
-        a.matrixSelfInv();\r
-           \r
-//         JartkException.trap("未チェックのパス");\r
-        NyARMat.matrixMul( c, a, b );\r
-        for(int i = 0; i < 2; i++ ) {\r
-            para[i][0] = c_array[i*3+0][0];//para[i][0] = c->m[i*3+0];\r
-            para[i][1] = c_array[i*3+1][0];//para[i][1] = c->m[i*3+1];\r
-            para[i][2] = c_array[i*3+2][0];//para[i][2] = c->m[i*3+2];\r
-        }\r
-        para[2][0] = c_array[2*3+0][0];//para[2][0] = c->m[2*3+0];\r
-        para[2][1] = c_array[2*3+1][0];//para[2][1] = c->m[2*3+1];\r
-        para[2][2] = 1.0;//para[2][2] = 1.0;\r
-    }\r
-    /**\r
-     * imageから、i_markerの位置にあるパターンを切り出して、保持します。\r
-     * @param image\r
-     * @param i_marker\r
-     * @throws Exception\r
-     */\r
-    public void pickFromRaster(NyARRaster image, NyARMarker i_marker) throws NyARException\r
-    {\r
-       int[] x_coord=i_marker.x_coord;\r
-       int[] y_coord=i_marker.y_coord;\r
-       int[] vertex=i_marker.vertex;\r
-       int[][][] ext_pat2=new int[height][width][3];//ARUint32  ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];\r
-       double[][] world=new double[4][2];//double    world[4][2];\r
-       double[][] local=new double[4][2];//double    local[4][2];\r
-        double[][] para=new double[3][3]; //double    para[3][3];\r
-        double         d, xw, yw;\r
-        int            xc, yc;\r
-        int            xdiv, ydiv;\r
-        int            xdiv2, ydiv2;\r
-        int            lx1, lx2, ly1, ly2;\r
-        int img_x,img_y;\r
-        \r
-        img_x=image.getWidth();\r
-        img_y=image.getHeight();\r
-\r
-        double    xdiv2_reciprocal; // [tp]\r
-        double    ydiv2_reciprocal; // [tp]\r
-        int       ext_pat2_x_index;\r
-        int       ext_pat2_y_index;\r
-        \r
-        world[0][0] = 100.0;\r
-        world[0][1] = 100.0;\r
-        world[1][0] = 100.0 + 10.0;\r
-        world[1][1] = 100.0;\r
-        world[2][0] = 100.0 + 10.0;\r
-        world[2][1] = 100.0 + 10.0;\r
-        world[3][0] = 100.0;\r
-        world[3][1] = 100.0 + 10.0;\r
-        for(int i = 0; i < 4; i++ ) {\r
-            local[i][0] = x_coord[vertex[i]];\r
-            local[i][1] = y_coord[vertex[i]];\r
-        }\r
-        get_cpara( world, local, para );\r
-\r
-        lx1 = (int)((local[0][0] - local[1][0])*(local[0][0] - local[1][0])+ (local[0][1] - local[1][1])*(local[0][1] - local[1][1]));\r
-        lx2 = (int)((local[2][0] - local[3][0])*(local[2][0] - local[3][0])+ (local[2][1] - local[3][1])*(local[2][1] - local[3][1]));\r
-        ly1 = (int)((local[1][0] - local[2][0])*(local[1][0] - local[2][0])+ (local[1][1] - local[2][1])*(local[1][1] - local[2][1]));\r
-        ly2 = (int)((local[3][0] - local[0][0])*(local[3][0] - local[0][0])+ (local[3][1] - local[0][1])*(local[3][1] - local[0][1]));\r
-        if( lx2 > lx1 ){\r
-            lx1 = lx2;\r
-        }\r
-        if( ly2 > ly1 ){\r
-            ly1 = ly2;\r
-        }\r
-        xdiv2 =width;\r
-        ydiv2 =height;\r
-        \r
-        while( xdiv2*xdiv2 < lx1/4 ){\r
-            xdiv2*=2;\r
-        }\r
-        while( ydiv2*ydiv2 < ly1/4 ){\r
-            ydiv2*=2;\r
-        }\r
-        \r
-        if( xdiv2 > AR_PATT_SAMPLE_NUM)\r
-        {\r
-            xdiv2 =AR_PATT_SAMPLE_NUM;\r
-        }\r
-        if( ydiv2 >AR_PATT_SAMPLE_NUM)\r
-        {\r
-            ydiv2 = AR_PATT_SAMPLE_NUM;\r
-        }\r
-        \r
-        xdiv = xdiv2/width;//xdiv = xdiv2/Config.AR_PATT_SIZE_X;\r
-        ydiv = ydiv2/height;//ydiv = ydiv2/Config.AR_PATT_SIZE_Y;\r
-/*\r
-printf("%3d(%f), %3d(%f)\n", xdiv2, sqrt(lx1), ydiv2, sqrt(ly1));\r
-*/\r
-\r
-        xdiv2_reciprocal = 1.0 / xdiv2;\r
-        ydiv2_reciprocal = 1.0 / ydiv2;\r
-        int[] rgb_tmp=new int[3];\r
- //    arGetCode_put_zero(ext_pat2);//put_zero( (ARUint8 *)ext_pat2, AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3*sizeof(ARUint32) );\r
-        for(int j = 0; j < ydiv2; j++ ) {\r
-       yw = 102.5 + 5.0 * (j+0.5) * ydiv2_reciprocal;\r
-       for(int i = 0; i < xdiv2; i++ ) {\r
-           xw = 102.5 + 5.0 * (i+0.5) * xdiv2_reciprocal;\r
-           d = para[2][0]*xw + para[2][1]*yw + para[2][2];\r
-           if( d == 0 ){\r
-               throw new NyARException();\r
-           }\r
-           xc = (int)((para[0][0]*xw + para[0][1]*yw + para[0][2])/d);\r
-           yc = (int)((para[1][0]*xw + para[1][1]*yw + para[1][2])/d);\r
-\r
+    public int getWidth();\r
+    public int getHeight();\r
+    public int[][][] getPatArray();\r
+    public void pickFromRaster(NyARRaster image, NyARMarker i_marker) throws NyARException;\r
+}\r
 \r
-           if( xc >= 0 && xc < img_x && yc >= 0 && yc < img_y ) {\r
-               ext_pat2_y_index = j/ydiv;\r
-               ext_pat2_x_index = i/xdiv;\r
-//             image_index = (yc*arUtil_c.arImXsize+xc)*Config.AR_PIX_SIZE_DEFAULT;\r
-               image.pickRgbArray(xc, yc, rgb_tmp);\r
 \r
-               ext_pat2[ext_pat2_y_index][ext_pat2_x_index][0] += rgb_tmp[0];//R\r
-               ext_pat2[ext_pat2_y_index][ext_pat2_x_index][1] += rgb_tmp[1];//G\r
-               ext_pat2[ext_pat2_y_index][ext_pat2_x_index][2] += rgb_tmp[2];//B\r
-//                                     System.out.println(xc+":"+yc+":"+rgb_tmp[0]+":"+rgb_tmp[1]+":"+rgb_tmp[2]);\r
-               }\r
-           }\r
-       }\r
-//            short[][][] ext_pat=new short[Config.AR_PATT_SIZE_Y][Config.AR_PATT_SIZE_X][3];//ARUint32  ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];\r
 \r
-        for(int j = 0; j < height; j++ ) {\r
-            for(int i = 0; i < width; i++ ) {                          // PRL 2006-06-08.\r
-                extpat[j][i][0]=(short)(ext_pat2[j][i][0] / (xdiv*ydiv));//ext_pat[j][i][0] = (byte)(ext_pat2[j][i][0] / (xdiv*ydiv));\r
-                extpat[j][i][1]=(short)(ext_pat2[j][i][1] / (xdiv*ydiv));//ext_pat[j][i][1] = (byte)(ext_pat2[j][i][1] / (xdiv*ydiv));\r
-                extpat[j][i][2]=(short)(ext_pat2[j][i][2] / (xdiv*ydiv));//ext_pat[j][i][2] = (byte)(ext_pat2[j][i][2] / (xdiv*ydiv));\r
-            }\r
-        }\r
-    }\r
-}
\ No newline at end of file
diff --git a/src/jp/nyatla/nyartoolkit/core/NyARColorPatt_O1.java b/src/jp/nyatla/nyartoolkit/core/NyARColorPatt_O1.java
new file mode 100644 (file)
index 0000000..db47266
--- /dev/null
@@ -0,0 +1,268 @@
+package jp.nyatla.nyartoolkit.core;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.NyARRaster;\r
+\r
+/**\r
+ * 24ビットカラーのマーカーを保持するために使うクラスです。\r
+ * このクラスは、ARToolkitのパターンと、ラスタから取得したパターンを保持します。\r
+ * 演算順序以外の最適化をしたもの\r
+ *\r
+ */\r
+public class NyARColorPatt_O1 implements NyARColorPatt\r
+{\r
+    private static final int AR_PATT_SAMPLE_NUM=64;//#define   AR_PATT_SAMPLE_NUM   64\r
+    private int extpat[][][];\r
+    private int width;\r
+    private int height;\r
+    public NyARColorPatt_O1(int i_width,int i_height)\r
+    {\r
+       this.width=i_width;\r
+       this.height=i_height;\r
+       this.extpat=new int[i_height][i_width][3];\r
+       this.wk_pickFromRaster_ext_pat2=new int[i_height][i_width][3];\r
+    }\r
+    public int[][][] getPatArray()\r
+    {\r
+       return extpat;\r
+    }\r
+    public int getWidth()\r
+    {\r
+       return width;\r
+    }\r
+    public int getHeight()\r
+    {\r
+       return height;\r
+    }\r
+    private final NyARMat wk_get_cpara_a=new NyARMat(8,8);\r
+    private final NyARMat wk_get_cpara_b=new NyARMat(8,1);\r
+    private final NyARMat wk_get_cpara_c=new NyARMat(8,1);\r
+    /**\r
+     * \r
+     * @param world\r
+     * @param vertex\r
+     * @param para\r
+     * [3x3]\r
+     * @throws NyARException\r
+     */\r
+    private void get_cpara( double world[][], double vertex[][],double[] para) throws NyARException\r
+    {\r
+        NyARMat a =wk_get_cpara_a;//次処理で値を設定するので、初期化不要// new NyARMat( 8, 8 );\r
+        double[][] a_array=a.getArray();\r
+        NyARMat b =wk_get_cpara_b;//次処理で値を設定するので、初期化不要// new NyARMat( 8, 1 );\r
+        double[][] b_array=b.getArray();\r
+        double[] a_pt0,a_pt1,world_pti;\r
+           \r
+        for(int i = 0; i < 4; i++ ) {\r
+            a_pt0=a_array[i*2];\r
+            a_pt1=a_array[i*2+1];\r
+            world_pti=world[i];\r
+            \r
+            a_pt0[0]=world_pti[0];//a->m[i*16+0]  = world[i][0];\r
+            a_pt0[1]=world_pti[1];//a->m[i*16+1]  = world[i][1];\r
+            a_pt0[2]=1.0;//a->m[i*16+2]  = 1.0;\r
+            a_pt0[3]=0.0;//a->m[i*16+3]  = 0.0;\r
+            a_pt0[4]=0.0;//a->m[i*16+4]  = 0.0;\r
+            a_pt0[5]=0.0;//a->m[i*16+5]  = 0.0;\r
+            a_pt0[6]=-world_pti[0] * vertex[i][0];//a->m[i*16+6]  = -world[i][0] * vertex[i][0];\r
+            a_pt0[7]=-world_pti[1] * vertex[i][0];//a->m[i*16+7]  = -world[i][1] * vertex[i][0];\r
+            a_pt1[0]=0.0;//a->m[i*16+8]  = 0.0;\r
+            a_pt1[1]=0.0;//a->m[i*16+9]  = 0.0;\r
+            a_pt1[2]=0.0;//a->m[i*16+10] = 0.0;\r
+            a_pt1[3]=world_pti[0];//a->m[i*16+11] = world[i][0];\r
+            a_pt1[4]=world_pti[1];//a->m[i*16+12] = world[i][1];\r
+            a_pt1[5]=1.0;//a->m[i*16+13] = 1.0;\r
+            a_pt1[6]=-world_pti[0] * vertex[i][1];//a->m[i*16+14] = -world[i][0] * vertex[i][1];\r
+            a_pt1[7]=-world_pti[1] * vertex[i][1];//a->m[i*16+15] = -world[i][1] * vertex[i][1];\r
+            b_array[i*2+0][0]=vertex[i][0];//b->m[i*2+0] = vertex[i][0];\r
+            b_array[i*2+1][0]=vertex[i][1];//b->m[i*2+1] = vertex[i][1];\r
+        }\r
+//         JartkException.trap("未チェックのパス");\r
+        a.matrixSelfInv();\r
+           \r
+//         JartkException.trap("未チェックのパス");\r
+        NyARMat c = wk_get_cpara_c;//次処理で結果を受け取るので、初期化不要//new NyARMat( 8, 1 );\r
+        double[][] c_array=c.getArray();\r
+\r
+        c.matrixMul(a, b);\r
+        for(int i = 0; i < 2; i++ ) {\r
+            para[i*3+0] = c_array[i*3+0][0];//para[i][0] = c->m[i*3+0];\r
+            para[i*3+1] = c_array[i*3+1][0];//para[i][1] = c->m[i*3+1];\r
+            para[i*3+2] = c_array[i*3+2][0];//para[i][2] = c->m[i*3+2];\r
+        }\r
+        para[2*3+0] = c_array[2*3+0][0];//para[2][0] = c->m[2*3+0];\r
+        para[2*3+1] = c_array[2*3+1][0];//para[2][1] = c->m[2*3+1];\r
+        para[2*3+2] = 1.0;//para[2][2] = 1.0;\r
+    }\r
+\r
+    private final double[][] wk_pickFromRaster_local=new double[4][2];\r
+    private final double[] wk_pickFromRaster_para=new double[9];//[3][3];\r
+    private int[][][] wk_pickFromRaster_ext_pat2=null;//コンストラクタでint[height][width][3]を作る\r
+    private final double[][] wk_pickFromRaster_world={//double    world[4][2];\r
+           {100.0,     100.0},\r
+           {100.0+10.0,100.0},\r
+           {100.0+10.0,100.0 + 10.0},\r
+           {100.0,     100.0 + 10.0}\r
+    };\r
+    /**\r
+     * pickFromRaster関数から使う変数です。\r
+     *\r
+     */\r
+    private static void initValue_wk_pickFromRaster_ext_pat2(int[][][] i_ext_pat2,int i_width,int i_height)\r
+    {\r
+       int i,i2;\r
+       int[][] pt2;\r
+       int[]   pt1;\r
+       for(i=i_height-1;i>=0;i--){\r
+           pt2=i_ext_pat2[i];\r
+           for(i2=i_width-1;i2>=0;i2--){\r
+               pt1=pt2[i2];\r
+               pt1[0]=0;\r
+               pt1[1]=0;\r
+               pt1[2]=0;\r
+           }\r
+       }\r
+    }\r
+    private final int[] wk_pickFromRaster_rgb_tmp=new int[3];\r
+    /**\r
+     * imageから、i_markerの位置にあるパターンを切り出して、保持します。\r
+     * Optimize:STEP[769->]\r
+     * @param image\r
+     * @param i_marker\r
+     * @throws Exception\r
+     */\r
+    public void pickFromRaster(NyARRaster image, NyARMarker i_marker) throws NyARException\r
+    {\r
+       double          d, xw, yw;\r
+       int             xc, yc;\r
+       int             xdiv, ydiv;\r
+       int             xdiv2, ydiv2;\r
+       int             lx1, lx2, ly1, ly2;\r
+\r
+       int img_x=image.getWidth();\r
+       int img_y=image.getHeight();\r
+\r
+       double    xdiv2_reciprocal; // [tp]\r
+       double    ydiv2_reciprocal; // [tp]\r
+\r
+\r
+       int[] x_coord=i_marker.x_coord;\r
+       int[] y_coord=i_marker.y_coord;\r
+       double[][] local=wk_pickFromRaster_local;//double    local[4][2];       \r
+       int[] vertex=i_marker.mkvertex;\r
+       for(int i = 0; i < 4; i++ ) {\r
+           local[i][0] = x_coord[vertex[i]];\r
+           local[i][1] = y_coord[vertex[i]];\r
+       }\r
+       double[][] world=wk_pickFromRaster_world;\r
+/*     world[0][0] = 100.0;\r
+       world[0][1] = 100.0;\r
+       world[1][0] = 100.0 + 10.0;\r
+       world[1][1] = 100.0;\r
+       world[2][0] = 100.0 + 10.0;\r
+       world[2][1] = 100.0 + 10.0;\r
+       world[3][0] = 100.0;\r
+       world[3][1] = 100.0 + 10.0;*/\r
+       double[] para =wk_pickFromRaster_para; //double    para[3][3];\r
+       get_cpara( world, local, para );\r
+       lx1 = (int)((local[0][0] - local[1][0])*(local[0][0] - local[1][0])+ (local[0][1] - local[1][1])*(local[0][1] - local[1][1]));\r
+       lx2 = (int)((local[2][0] - local[3][0])*(local[2][0] - local[3][0])+ (local[2][1] - local[3][1])*(local[2][1] - local[3][1]));\r
+       ly1 = (int)((local[1][0] - local[2][0])*(local[1][0] - local[2][0])+ (local[1][1] - local[2][1])*(local[1][1] - local[2][1]));\r
+       ly2 = (int)((local[3][0] - local[0][0])*(local[3][0] - local[0][0])+ (local[3][1] - local[0][1])*(local[3][1] - local[0][1]));\r
+       if( lx2 > lx1 ){\r
+           lx1 = lx2;\r
+       }\r
+       if( ly2 > ly1 ){\r
+           ly1 = ly2;\r
+       }\r
+       xdiv2 =this.width;\r
+       ydiv2 =this.height;\r
+\r
+       while( xdiv2*xdiv2 < lx1/4 ){\r
+           xdiv2*=2;\r
+       }\r
+       while( ydiv2*ydiv2 < ly1/4 ){\r
+           ydiv2*=2;\r
+       }\r
+\r
+       if( xdiv2 > AR_PATT_SAMPLE_NUM)\r
+       {\r
+           xdiv2 =AR_PATT_SAMPLE_NUM;\r
+       }\r
+       if( ydiv2 >AR_PATT_SAMPLE_NUM)\r
+       {\r
+           ydiv2 = AR_PATT_SAMPLE_NUM;\r
+       }\r
+\r
+       xdiv = xdiv2/width;//xdiv = xdiv2/Config.AR_PATT_SIZE_X;\r
+       ydiv = ydiv2/height;//ydiv = ydiv2/Config.AR_PATT_SIZE_Y;\r
+\r
+       /*wk_pickFromRaster_ext_pat2ワーク変数を初期化する。*/\r
+       int[][][] ext_pat2=wk_pickFromRaster_ext_pat2;//ARUint32  ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];\r
+       int extpat_j[][],extpat_j_i[];\r
+       int ext_pat2_j[][],ext_pat2_j_i[];\r
+\r
+       initValue_wk_pickFromRaster_ext_pat2(ext_pat2,this.width,this.height);\r
+\r
+       xdiv2_reciprocal = 1.0 / xdiv2;\r
+       ydiv2_reciprocal = 1.0 / ydiv2;\r
+       int i,j;\r
+       int[] rgb_tmp=wk_pickFromRaster_rgb_tmp;\r
+       //      arGetCode_put_zero(ext_pat2);//put_zero( (ARUint8 *)ext_pat2, AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3*sizeof(ARUint32) );\r
+       for(j = 0; j < ydiv2; j++ ) {\r
+           yw = 102.5 + 5.0 * (j+0.5) * ydiv2_reciprocal;\r
+           for(i = 0; i < xdiv2; i++ ) {\r
+               xw = 102.5 + 5.0 * (i+0.5) * xdiv2_reciprocal;\r
+               d = para[2*3+0]*xw + para[2*3+1]*yw + para[2*3+2];\r
+               if( d == 0 ){\r
+                   throw new NyARException();\r
+               }\r
+               xc = (int)((para[0*3+0]*xw + para[0*3+1]*yw + para[0*3+2])/d);\r
+               yc = (int)((para[1*3+0]*xw + para[1*3+1]*yw + para[1*3+2])/d);\r
+\r
+\r
+               if( xc >= 0 && xc < img_x && yc >= 0 && yc < img_y ) {\r
+                   image.getPixel(xc, yc, rgb_tmp);\r
+                   ext_pat2_j_i=ext_pat2[j/ydiv][i/xdiv];\r
+\r
+                   ext_pat2_j_i[0] += rgb_tmp[0];//R\r
+                   ext_pat2_j_i[1] += rgb_tmp[1];//G\r
+                   ext_pat2_j_i[2] += rgb_tmp[2];//B\r
+//                 System.out.println(xc+":"+yc+":"+rgb_tmp[0]+":"+rgb_tmp[1]+":"+rgb_tmp[2]);\r
+               }\r
+           }\r
+       }\r
+//     short[][][] ext_pat=new short[Config.AR_PATT_SIZE_Y][Config.AR_PATT_SIZE_X][3];//ARUint32  ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];\r
+       /*<Optimize>*/\r
+       int xdiv_x_ydiv=xdiv*ydiv;\r
+       for(j =  this.height-1; j>=0; j--){\r
+           extpat_j=extpat[j];\r
+           ext_pat2_j=ext_pat2[j];\r
+           for(i = this.width-1; i>=0; i--){                           // PRL 2006-06-08.\r
+               ext_pat2_j_i=ext_pat2_j[i];\r
+               extpat_j_i=extpat_j[i];\r
+               extpat_j_i[0]=(ext_pat2_j_i[0] / xdiv_x_ydiv);//ext_pat[j][i][0] = (byte)(ext_pat2[j][i][0] / (xdiv*ydiv));\r
+               extpat_j_i[1]=(ext_pat2_j_i[1] / xdiv_x_ydiv);//ext_pat[j][i][1] = (byte)(ext_pat2[j][i][1] / (xdiv*ydiv));\r
+               extpat_j_i[2]=(ext_pat2_j_i[2] / xdiv_x_ydiv);//ext_pat[j][i][2] = (byte)(ext_pat2[j][i][2] / (xdiv*ydiv));\r
+           }\r
+       }/*\r
+       int xdiv_mul_ydiv=xdiv*ydiv;\r
+       short [][] extpat_pt_2;\r
+       short[]    extpat_pt_1;\r
+       int[][]    ext_pat2_pt_2;\r
+       int[]      ext_pat2_pt_1;\r
+       for(int j=this.height-1; j>=0; j--){//for(int j = 0; j < this.height; j++ ){\r
+           extpat_pt_2=extpat[j];\r
+           ext_pat2_pt_2=ext_pat2[j];\r
+           for(int i = this.width-1; i>=0; i--){//for(int i = 0; i < this.width; i++ ){                                // PRL 2006-06-08.\r
+               extpat_pt_1=extpat_pt_2[i];\r
+               ext_pat2_pt_1=ext_pat2_pt_2[i];         \r
+               extpat_pt_1[0]=(short)(ext_pat2_pt_1[0] / xdiv_mul_ydiv);//ext_pat[j][i][0] = (byte)(ext_pat2[j][i][0] / (xdiv*ydiv));\r
+               extpat_pt_1[1]=(short)(ext_pat2_pt_1[1] / xdiv_mul_ydiv);//ext_pat[j][i][1] = (byte)(ext_pat2[j][i][1] / (xdiv*ydiv));\r
+               extpat_pt_1[2]=(short)(ext_pat2_pt_1[2] / xdiv_mul_ydiv);//ext_pat[j][i][2] = (byte)(ext_pat2[j][i][2] / (xdiv*ydiv));\r
+           }\r
+       }\r
+       /*</Optimize>*/\r
+       return;\r
+    }\r
+}
\ No newline at end of file
diff --git a/src/jp/nyatla/nyartoolkit/core/NyARColorPatt_O2.java b/src/jp/nyatla/nyartoolkit/core/NyARColorPatt_O2.java
new file mode 100644 (file)
index 0000000..0cea61b
--- /dev/null
@@ -0,0 +1,281 @@
+package jp.nyatla.nyartoolkit.core;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.NyARRaster;\r
+\r
+/**\r
+ * 24ビットカラーのマーカーを保持するために使うクラスです。\r
+ * このクラスは、ARToolkitのパターンと、ラスタから取得したパターンを保持します。\r
+ * 演算順序を含む最適化をしたもの\r
+ *\r
+ */\r
+public class NyARColorPatt_O2 implements NyARColorPatt\r
+{\r
+    private static final int AR_PATT_SAMPLE_NUM=64;//#define   AR_PATT_SAMPLE_NUM   64\r
+    private int extpat[][][];\r
+    private int width;\r
+    private int height;\r
+    public NyARColorPatt_O2(int i_width,int i_height)\r
+    {\r
+       this.width=i_width;\r
+       this.height=i_height;\r
+       this.extpat=new int[i_height][i_width][3];\r
+       this.wk_pickFromRaster_ext_pat2=new int[i_height][i_width][3];\r
+    }\r
+    public int[][][] getPatArray()\r
+    {\r
+       return extpat;\r
+    }\r
+    public int getWidth()\r
+    {\r
+       return width;\r
+    }\r
+    public int getHeight()\r
+    {\r
+       return height;\r
+    }\r
+    private final NyARMat wk_get_cpara_a=new NyARMat(8,8);\r
+    private final NyARMat wk_get_cpara_b=new NyARMat(8,1);\r
+//    private final NyARMat wk_get_cpara_c=new NyARMat(8,1);\r
+    /**\r
+     * \r
+     * @param world\r
+     * @param vertex\r
+     * @param para\r
+     * [3x3]\r
+     * @throws NyARException\r
+     */\r
+    /**\r
+     * @param world\r
+     * @param vertex\r
+     * @param o_para\r
+     * @throws NyARException\r
+     */\r
+    private void get_cpara(double vertex_0[], double vertex_1[],NyARMat o_para) throws NyARException\r
+    {\r
+       double world[][]=this.wk_pickFromRaster_world;\r
+        NyARMat a =wk_get_cpara_a;//次処理で値を設定するので、初期化不要// new NyARMat( 8, 8 );\r
+        double[][] a_array=a.getArray();\r
+        NyARMat b =wk_get_cpara_b;//次処理で値を設定するので、初期化不要// new NyARMat( 8, 1 );\r
+        double[][] b_array=b.getArray();\r
+        double[] a_pt0,a_pt1,world_pti;\r
+           \r
+        for(int i = 0; i < 4; i++ ) {\r
+            a_pt0=a_array[i*2];\r
+            a_pt1=a_array[i*2+1];\r
+            world_pti=world[i];\r
+            \r
+            a_pt0[0]=world_pti[0];//a->m[i*16+0]  = world[i][0];\r
+            a_pt0[1]=world_pti[1];//a->m[i*16+1]  = world[i][1];\r
+            a_pt0[2]=1.0;//a->m[i*16+2]  = 1.0;\r
+            a_pt0[3]=0.0;//a->m[i*16+3]  = 0.0;\r
+            a_pt0[4]=0.0;//a->m[i*16+4]  = 0.0;\r
+            a_pt0[5]=0.0;//a->m[i*16+5]  = 0.0;\r
+            a_pt0[6]=-world_pti[0] * vertex_0[i];//a->m[i*16+6]  = -world[i][0] * vertex[i][0];\r
+            a_pt0[7]=-world_pti[1] * vertex_0[i];//a->m[i*16+7]  = -world[i][1] * vertex[i][0];\r
+            a_pt1[0]=0.0;//a->m[i*16+8]  = 0.0;\r
+            a_pt1[1]=0.0;//a->m[i*16+9]  = 0.0;\r
+            a_pt1[2]=0.0;//a->m[i*16+10] = 0.0;\r
+            a_pt1[3]=world_pti[0];//a->m[i*16+11] = world[i][0];\r
+            a_pt1[4]=world_pti[1];//a->m[i*16+12] = world[i][1];\r
+            a_pt1[5]=1.0;//a->m[i*16+13] = 1.0;\r
+            a_pt1[6]=-world_pti[0] * vertex_1[i];//a->m[i*16+14] = -world[i][0] * vertex[i][1];\r
+            a_pt1[7]=-world_pti[1] * vertex_1[i];//a->m[i*16+15] = -world[i][1] * vertex[i][1];\r
+            b_array[i*2+0][0]=vertex_0[i];//b->m[i*2+0] = vertex[i][0];\r
+            b_array[i*2+1][0]=vertex_1[i];//b->m[i*2+1] = vertex[i][1];\r
+        }\r
+//         JartkException.trap("未チェックのパス");\r
+        a.matrixSelfInv();\r
+           \r
+//         JartkException.trap("未チェックのパス");\r
+//        NyARMat c = wk_get_cpara_c;//次処理で結果を受け取るので、初期化不要//new NyARMat( 8, 1 );\r
+//        double[][] c_array=c.getArray();\r
+\r
+        o_para.matrixMul(a, b);\r
+//        para[0*3+0] = c_array[0*3+0][0];//para[i][0] = c->m[i*3+0];\r
+//        para[0*3+1] = c_array[0*3+1][0];//para[i][1] = c->m[i*3+1];\r
+//        para[0*3+2] = c_array[0*3+2][0];//para[i][2] = c->m[i*3+2];\r
+//        para[1*3+0] = c_array[1*3+0][0];//para[i][0] = c->m[i*3+0];\r
+//        para[1*3+1] = c_array[1*3+1][0];//para[i][1] = c->m[i*3+1];\r
+//        para[i*3+2] = c_array[1*3+2][0];//para[i][2] = c->m[i*3+2];\r
+//        para[2*3+0] = c_array[2*3+0][0];//para[2][0] = c->m[2*3+0];\r
+//        para[2*3+1] = c_array[2*3+1][0];//para[2][1] = c->m[2*3+1];\r
+//        para[2*3+2] = 1.0;//para[2][2] = 1.0;\r
+        \r
+\r
+    }\r
+\r
+  //   private final double[] wk_pickFromRaster_para=new double[9];//[3][3];\r
+    private int[][][] wk_pickFromRaster_ext_pat2=null;//コンストラクタでint[height][width][3]を作る\r
+    private final double[][] wk_pickFromRaster_world={//double    world[4][2];\r
+           {100.0,     100.0},\r
+           {100.0+10.0,100.0},\r
+           {100.0+10.0,100.0 + 10.0},\r
+           {100.0,     100.0 + 10.0}\r
+    };\r
+    /**\r
+     * pickFromRaster関数から使う変数です。\r
+     *\r
+     */\r
+    private static void initValue_wk_pickFromRaster_ext_pat2(int[][][] i_ext_pat2,int i_width,int i_height)\r
+    {\r
+       int i,i2;\r
+       int[][] pt2;\r
+       int[]   pt1;\r
+       for(i=i_height-1;i>=0;i--){\r
+           pt2=i_ext_pat2[i];\r
+           for(i2=i_width-1;i2>=0;i2--){\r
+               pt1=pt2[i2];\r
+               pt1[0]=0;\r
+               pt1[1]=0;\r
+               pt1[2]=0;\r
+           }\r
+       }\r
+    }\r
+    private final double[][] wk_pickFromRaster_local=new double[2][4];\r
+    private final int[] wk_pickFromRaster_rgb_tmp=new int[3];\r
+    private final NyARMat wk_pickFromRaster_cpara=new NyARMat(8,1);\r
+    /**\r
+     * imageから、i_markerの位置にあるパターンを切り出して、保持します。\r
+     * Optimize:STEP[769->750]\r
+     * @param image\r
+     * @param i_marker\r
+     * @throws Exception\r
+     */\r
+    public void pickFromRaster(NyARRaster image, NyARMarker i_marker) throws NyARException\r
+    {\r
+       NyARMat cpara=this.wk_pickFromRaster_cpara;\r
+       //localの計算\r
+       int[] x_coord=i_marker.x_coord;\r
+       int[] y_coord=i_marker.y_coord;\r
+       int[] vertex=i_marker.mkvertex;\r
+       double[] local_0=wk_pickFromRaster_local[0];//double    local[4][2];    \r
+       double[] local_1=wk_pickFromRaster_local[1];//double    local[4][2];    \r
+       for(int i = 0; i < 4; i++ ) {\r
+           local_0[i] = x_coord[vertex[i]];\r
+           local_1[i] = y_coord[vertex[i]];\r
+       }\r
+       //xdiv2,ydiv2の計算\r
+       int xdiv2, ydiv2;\r
+       int l1,l2;\r
+       double w1,w2;\r
+\r
+       //x計算\r
+       w1=local_0[0] - local_0[1];\r
+       w2=local_1[0] - local_1[1];\r
+       l1 = (int)(w1*w1+w2*w2);\r
+       w1=local_0[2] - local_0[3];\r
+       w2=local_1[2] - local_1[3];\r
+       l2 = (int)(w1*w1+w2*w2);\r
+       if( l2 > l1 ){\r
+           l1 = l2;\r
+       }\r
+       l1=l1/4;\r
+       xdiv2 =this.width;\r
+       while( xdiv2*xdiv2 < l1 ){\r
+           xdiv2*=2;\r
+       }\r
+       if( xdiv2 > AR_PATT_SAMPLE_NUM)\r
+       {\r
+           xdiv2 =AR_PATT_SAMPLE_NUM;\r
+       }\r
+       \r
+       //y計算\r
+       w1=local_0[1] - local_0[2];\r
+       w2=local_1[1] - local_1[2];\r
+       l1 = (int)(w1*w1+ w2*w2);\r
+       w1=local_0[3] - local_0[0];\r
+       w2=local_1[3] - local_1[0];\r
+       l2 = (int)(w1*w1+ w2*w2);\r
+       if( l2 > l1 ){\r
+           l1 = l2;\r
+       }\r
+       ydiv2 =this.height;\r
+       l1=l1/4;\r
+       while( ydiv2*ydiv2 < l1 ){\r
+           ydiv2*=2;\r
+       }\r
+       if( ydiv2 >AR_PATT_SAMPLE_NUM)\r
+       {\r
+           ydiv2 = AR_PATT_SAMPLE_NUM;\r
+       }       \r
+       \r
+       //cparaの計算\r
+       get_cpara(local_0,local_1,cpara);\r
+\r
+       int img_x=image.getWidth();\r
+       int img_y=image.getHeight();\r
+\r
+       /*wk_pickFromRaster_ext_pat2ワーク変数を初期化する。*/\r
+       int[][][] ext_pat2=wk_pickFromRaster_ext_pat2;//ARUint32  ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];\r
+       int extpat_j[][],extpat_j_i[];\r
+       int ext_pat2_j[][],ext_pat2_j_i[];\r
+\r
+       initValue_wk_pickFromRaster_ext_pat2(ext_pat2,this.width,this.height);\r
+\r
+       double[][] cpara_array=cpara.getArray();\r
+       double para21_x_yw,para01_x_yw,para11_x_yw;\r
+       double para00,para01,para02,para10,para11,para12,para20,para21;\r
+        para00 = cpara_array[0*3+0][0];//para[i][0] = c->m[i*3+0];\r
+        para01 = cpara_array[0*3+1][0];//para[i][1] = c->m[i*3+1];\r
+        para02 = cpara_array[0*3+2][0];//para[i][2] = c->m[i*3+2];\r
+        para10 = cpara_array[1*3+0][0];//para[i][0] = c->m[i*3+0];\r
+        para11 = cpara_array[1*3+1][0];//para[i][1] = c->m[i*3+1];\r
+        para12 = cpara_array[1*3+2][0];//para[i][2] = c->m[i*3+2];\r
+        para20 = cpara_array[2*3+0][0];//para[2][0] = c->m[2*3+0];\r
+        para21 = cpara_array[2*3+1][0];//para[2][1] = c->m[2*3+1];\r
+        //para22 = 1.0;//para[2][2] = 1.0;\r
+\r
+       \r
+       double          d, xw, yw;\r
+       int             xc, yc;\r
+       int i,j;\r
+       int[] rgb_tmp=wk_pickFromRaster_rgb_tmp;\r
+       //      arGetCode_put_zero(ext_pat2);//put_zero( (ARUint8 *)ext_pat2, AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3*sizeof(ARUint32) );\r
+       int xdiv = xdiv2/width;//xdiv = xdiv2/Config.AR_PATT_SIZE_X;\r
+       int ydiv = ydiv2/height;//ydiv = ydiv2/Config.AR_PATT_SIZE_Y;\r
+       double xdiv2_reciprocal = 1.0 / xdiv2;\r
+       double ydiv2_reciprocal = 1.0 / ydiv2;\r
+\r
+       for(j = 0; j < ydiv2; j++ ) {\r
+           yw = 102.5 + 5.0 * ((double)j+0.5) * ydiv2_reciprocal;\r
+           para21_x_yw=para21*yw+1.0;\r
+           para11_x_yw=para11*yw+para12;\r
+           para01_x_yw=para01*yw+para02;\r
+           ext_pat2_j=ext_pat2[j/ydiv];\r
+           for(i = 0; i < xdiv2; i++ ) {\r
+               xw = 102.5 + 5.0 * ((double)i+0.5) * xdiv2_reciprocal;\r
+               d = para20*xw + para21_x_yw;\r
+               if( d == 0 ){\r
+                   throw new NyARException();\r
+               }\r
+               xc = (int)((para00*xw + para01_x_yw)/d);\r
+               yc = (int)((para10*xw + para11_x_yw)/d);\r
+\r
+\r
+               if( xc >= 0 && xc < img_x && yc >= 0 && yc < img_y ) {\r
+                   image.getPixel(xc, yc, rgb_tmp);\r
+                   ext_pat2_j_i=ext_pat2_j[i/xdiv];\r
+\r
+                   ext_pat2_j_i[0] += rgb_tmp[0];//R\r
+                   ext_pat2_j_i[1] += rgb_tmp[1];//G\r
+                   ext_pat2_j_i[2] += rgb_tmp[2];//B\r
+               }\r
+           }\r
+       }\r
+       /*<Optimize>*/\r
+       int xdiv_x_ydiv=xdiv*ydiv;\r
+       for(j =this.height-1; j>=0; j--){\r
+           extpat_j=extpat[j];\r
+           ext_pat2_j=ext_pat2[j];\r
+           for(i = this.width-1; i>=0; i--){                           // PRL 2006-06-08.\r
+               ext_pat2_j_i=ext_pat2_j[i];\r
+               extpat_j_i=extpat_j[i];\r
+               extpat_j_i[0]=(ext_pat2_j_i[0] / xdiv_x_ydiv);//ext_pat[j][i][0] = (byte)(ext_pat2[j][i][0] / (xdiv*ydiv));\r
+               extpat_j_i[1]=(ext_pat2_j_i[1] / xdiv_x_ydiv);//ext_pat[j][i][1] = (byte)(ext_pat2[j][i][1] / (xdiv*ydiv));\r
+               extpat_j_i[2]=(ext_pat2_j_i[2] / xdiv_x_ydiv);//ext_pat[j][i][2] = (byte)(ext_pat2[j][i][2] / (xdiv*ydiv));\r
+           }\r
+       }\r
+       return;\r
+    }\r
+}
\ No newline at end of file
diff --git a/src/jp/nyatla/nyartoolkit/core/NyARColorPatt_O3.java b/src/jp/nyatla/nyartoolkit/core/NyARColorPatt_O3.java
new file mode 100644 (file)
index 0000000..b56687e
--- /dev/null
@@ -0,0 +1,340 @@
+package jp.nyatla.nyartoolkit.core;\r
+\r
+\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.NyARRaster;\r
+\r
+/**\r
+ * 24ビットカラーのマーカーを保持するために使うクラスです。\r
+ * このクラスは、ARToolkitのパターンと、ラスタから取得したパターンを保持します。\r
+ * 演算順序を含む最適化をしたもの\r
+ *\r
+ */\r
+public class NyARColorPatt_O3 implements NyARColorPatt\r
+{\r
+    private static final int AR_PATT_SAMPLE_NUM=64;//#define   AR_PATT_SAMPLE_NUM   64\r
+    private int extpat[][][];\r
+    private int width;\r
+    private int height;\r
+    public NyARColorPatt_O3(int i_width,int i_height)\r
+    {\r
+       this.width=i_width;\r
+       this.height=i_height;\r
+       this.extpat=new int[i_height][i_width][3];\r
+    }\r
+    public int[][][] getPatArray()\r
+    {\r
+       return extpat;\r
+    }\r
+    public int getWidth()\r
+    {\r
+       return width;\r
+    }\r
+    public int getHeight()\r
+    {\r
+       return height;\r
+    }\r
+    private final NyARMat wk_get_cpara_a=new NyARMat(8,8);\r
+    private final NyARMat wk_get_cpara_b=new NyARMat(8,1);\r
+\r
+    /**\r
+     * \r
+     * @param world\r
+     * @param vertex\r
+     * @param para\r
+     * [3x3]\r
+     * @throws NyARException\r
+     */\r
+    /**\r
+     * @param world\r
+     * @param vertex\r
+     * @param o_para\r
+     * @throws NyARException\r
+     */\r
+    private void get_cpara(double vertex_0[], double vertex_1[],NyARMat o_para) throws NyARException\r
+    {\r
+       double world[][]=this.wk_pickFromRaster_world;\r
+        NyARMat a =wk_get_cpara_a;//次処理で値を設定するので、初期化不要// new NyARMat( 8, 8 );\r
+        double[][] a_array=a.getArray();\r
+        NyARMat b =wk_get_cpara_b;//次処理で値を設定するので、初期化不要// new NyARMat( 8, 1 );\r
+        double[][] b_array=b.getArray();\r
+        double[] a_pt0,a_pt1,world_pti;\r
+           \r
+        for(int i = 0; i < 4; i++ ) {\r
+            a_pt0=a_array[i*2];\r
+            a_pt1=a_array[i*2+1];\r
+            world_pti=world[i];\r
+            \r
+            a_pt0[0]=world_pti[0];//a->m[i*16+0]  = world[i][0];\r
+            a_pt0[1]=world_pti[1];//a->m[i*16+1]  = world[i][1];\r
+            a_pt0[2]=1.0;//a->m[i*16+2]  = 1.0;\r
+            a_pt0[3]=0.0;//a->m[i*16+3]  = 0.0;\r
+            a_pt0[4]=0.0;//a->m[i*16+4]  = 0.0;\r
+            a_pt0[5]=0.0;//a->m[i*16+5]  = 0.0;\r
+            a_pt0[6]=-world_pti[0] * vertex_0[i];//a->m[i*16+6]  = -world[i][0] * vertex[i][0];\r
+            a_pt0[7]=-world_pti[1] * vertex_0[i];//a->m[i*16+7]  = -world[i][1] * vertex[i][0];\r
+            a_pt1[0]=0.0;//a->m[i*16+8]  = 0.0;\r
+            a_pt1[1]=0.0;//a->m[i*16+9]  = 0.0;\r
+            a_pt1[2]=0.0;//a->m[i*16+10] = 0.0;\r
+            a_pt1[3]=world_pti[0];//a->m[i*16+11] = world[i][0];\r
+            a_pt1[4]=world_pti[1];//a->m[i*16+12] = world[i][1];\r
+            a_pt1[5]=1.0;//a->m[i*16+13] = 1.0;\r
+            a_pt1[6]=-world_pti[0] * vertex_1[i];//a->m[i*16+14] = -world[i][0] * vertex[i][1];\r
+            a_pt1[7]=-world_pti[1] * vertex_1[i];//a->m[i*16+15] = -world[i][1] * vertex[i][1];\r
+            b_array[i*2+0][0]=vertex_0[i];//b->m[i*2+0] = vertex[i][0];\r
+            b_array[i*2+1][0]=vertex_1[i];//b->m[i*2+1] = vertex[i][1];\r
+        }\r
+        a.matrixSelfInv();\r
+           \r
+\r
+        o_para.matrixMul(a, b);\r
+\r
+        \r
+\r
+    }\r
+\r
+  //   private final double[] wk_pickFromRaster_para=new double[9];//[3][3];\r
+    private final double[][] wk_pickFromRaster_world={//double    world[4][2];\r
+           {100.0,     100.0},\r
+           {100.0+10.0,100.0},\r
+           {100.0+10.0,100.0 + 10.0},\r
+           {100.0,     100.0 + 10.0}\r
+    };\r
+    /**\r
+     * pickFromRaster関数から使う変数です。\r
+     *\r
+     */\r
+    private static void initValue_wk_pickFromRaster_ext_pat2(int[][][] i_ext_pat2,int i_width,int i_height)\r
+    {\r
+       int i,i2;\r
+       int[][] pt2;\r
+       int[]   pt1;\r
+       for(i=i_height-1;i>=0;i--){\r
+           pt2=i_ext_pat2[i];\r
+           for(i2=i_width-1;i2>=0;i2--){\r
+               pt1=pt2[i2];\r
+               pt1[0]=0;\r
+               pt1[1]=0;\r
+               pt1[2]=0;\r
+           }\r
+       }\r
+    }\r
+    private final double[][] wk_pickFromRaster_local=new double[2][4];\r
+    private final NyARMat wk_pickFromRaster_cpara=new NyARMat(8,1);\r
+    /**\r
+     * imageから、i_markerの位置にあるパターンを切り出して、保持します。\r
+     * Optimize:STEP[769->750]\r
+     * @param image\r
+     * @param i_marker\r
+     * @throws Exception\r
+     */\r
+    public void pickFromRaster(NyARRaster image, NyARMarker i_marker) throws NyARException\r
+    {\r
+       NyARMat cpara=this.wk_pickFromRaster_cpara;\r
+       //localの計算\r
+       int[] x_coord=i_marker.x_coord;\r
+       int[] y_coord=i_marker.y_coord;\r
+       int[] vertex=i_marker.mkvertex;\r
+       double[] local_0=wk_pickFromRaster_local[0];//double    local[4][2];    \r
+       double[] local_1=wk_pickFromRaster_local[1];//double    local[4][2];    \r
+       for(int i = 0; i < 4; i++ ) {\r
+           local_0[i] = x_coord[vertex[i]];\r
+           local_1[i] = y_coord[vertex[i]];\r
+       }\r
+       //xdiv2,ydiv2の計算\r
+       int xdiv2, ydiv2;\r
+       int l1,l2;\r
+       double w1,w2;\r
+\r
+       //x計算\r
+       w1=local_0[0] - local_0[1];\r
+       w2=local_1[0] - local_1[1];\r
+       l1 = (int)(w1*w1+w2*w2);\r
+       w1=local_0[2] - local_0[3];\r
+       w2=local_1[2] - local_1[3];\r
+       l2 = (int)(w1*w1+w2*w2);\r
+       if( l2 > l1 ){\r
+           l1 = l2;\r
+       }\r
+       l1=l1/4;\r
+       xdiv2 =this.width;\r
+       while( xdiv2*xdiv2 < l1 ){\r
+           xdiv2*=2;\r
+       }\r
+       if( xdiv2 > AR_PATT_SAMPLE_NUM)\r
+       {\r
+           xdiv2 =AR_PATT_SAMPLE_NUM;\r
+       }\r
+       \r
+       //y計算\r
+       w1=local_0[1] - local_0[2];\r
+       w2=local_1[1] - local_1[2];\r
+       l1 = (int)(w1*w1+ w2*w2);\r
+       w1=local_0[3] - local_0[0];\r
+       w2=local_1[3] - local_1[0];\r
+       l2 = (int)(w1*w1+ w2*w2);\r
+       if( l2 > l1 ){\r
+           l1 = l2;\r
+       }\r
+       ydiv2 =this.height;\r
+       l1=l1/4;\r
+       while( ydiv2*ydiv2 < l1 ){\r
+           ydiv2*=2;\r
+       }\r
+       if( ydiv2 >AR_PATT_SAMPLE_NUM)\r
+       {\r
+           ydiv2 = AR_PATT_SAMPLE_NUM;\r
+       }       \r
+       \r
+       //cparaの計算\r
+       get_cpara(local_0,local_1,cpara);\r
+       updateExtpat(image,cpara,xdiv2,ydiv2);\r
+\r
+       return;\r
+    }\r
+    //かなり大きいワークバッファを取るな…。\r
+    private double[] wk_updateExtpat_para00_xw;\r
+    private double[] wk_updateExtpat_para10_xw;\r
+    private double[] wk_updateExtpat_para20_xw;\r
+    private int[] wk_updateExtpat_rgb_buf;\r
+    private int[] wk_updateExtpat_x_rgb_index;\r
+    private int[] wk_updateExtpat_y_rgb_index;\r
+    private int[] wk_updateExtpat_i_rgb_index;\r
+\r
+    /**\r
+     * ワークバッファを予約する\r
+     * @param i_xdiv2\r
+     */\r
+    private void reservWorkBuffers(int i_xdiv2)\r
+    {\r
+       int[] buf=this.wk_updateExtpat_rgb_buf;\r
+       if(this.wk_updateExtpat_rgb_buf==null){\r
+           wk_updateExtpat_para00_xw=new double[i_xdiv2];\r
+           wk_updateExtpat_para10_xw=new double[i_xdiv2];\r
+           wk_updateExtpat_para20_xw=new double[i_xdiv2];\r
+           wk_updateExtpat_rgb_buf=new int[i_xdiv2*3];\r
+           wk_updateExtpat_x_rgb_index=new int[i_xdiv2];\r
+           wk_updateExtpat_y_rgb_index=new int[i_xdiv2];\r
+           wk_updateExtpat_i_rgb_index=new int[i_xdiv2];\r
+       }else{\r
+           if(buf.length<i_xdiv2){\r
+               wk_updateExtpat_para00_xw=new double[i_xdiv2];\r
+               wk_updateExtpat_para10_xw=new double[i_xdiv2];\r
+               wk_updateExtpat_para20_xw=new double[i_xdiv2];\r
+               wk_updateExtpat_rgb_buf=new int[i_xdiv2*3];\r
+               wk_updateExtpat_x_rgb_index=new int[i_xdiv2];\r
+               wk_updateExtpat_y_rgb_index=new int[i_xdiv2];\r
+               wk_updateExtpat_i_rgb_index=new int[i_xdiv2];\r
+           }\r
+           //十分なら何もしない。\r
+       }\r
+       return;\r
+    }\r
+    \r
+    private void updateExtpat(NyARRaster image,NyARMat i_cpara,int i_xdiv2,int i_ydiv2) throws NyARException\r
+    {\r
+       int img_x=image.getWidth();\r
+       int img_y=image.getHeight();\r
+\r
+       /*wk_pickFromRaster_ext_pat2ワーク変数を初期化する。*/\r
+       //int[][][] ext_pat2=wk_pickFromRaster_ext_pat2;//ARUint32  ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];\r
+       int extpat_j[][],extpat_j_i[];\r
+       //int ext_pat2_j[][],ext_pat2_j_i[];\r
+\r
+       initValue_wk_pickFromRaster_ext_pat2(extpat,this.width,this.height);\r
+\r
+       double[][] cpara_array=i_cpara.getArray();\r
+       double para21_x_yw,para01_x_yw,para11_x_yw;\r
+       double para00,para01,para02,para10,para11,para12,para20,para21;\r
+        para00 = cpara_array[0*3+0][0];//para[i][0] = c->m[i*3+0];\r
+        para01 = cpara_array[0*3+1][0];//para[i][1] = c->m[i*3+1];\r
+        para02 = cpara_array[0*3+2][0];//para[i][2] = c->m[i*3+2];\r
+        para10 = cpara_array[1*3+0][0];//para[i][0] = c->m[i*3+0];\r
+        para11 = cpara_array[1*3+1][0];//para[i][1] = c->m[i*3+1];\r
+        para12 = cpara_array[1*3+2][0];//para[i][2] = c->m[i*3+2];\r
+        para20 = cpara_array[2*3+0][0];//para[2][0] = c->m[2*3+0];\r
+        para21 = cpara_array[2*3+1][0];//para[2][1] = c->m[2*3+1];\r
+\r
+       \r
+       double          d,yw;\r
+       int             xc, yc;\r
+       int i,j;\r
+       //      arGetCode_put_zero(ext_pat2);//put_zero( (ARUint8 *)ext_pat2, AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3*sizeof(ARUint32) );\r
+       int xdiv = i_xdiv2/width;//xdiv = xdiv2/Config.AR_PATT_SIZE_X;\r
+       int ydiv = i_ydiv2/height;//ydiv = ydiv2/Config.AR_PATT_SIZE_Y;\r
+       \r
+       //計算バッファを予約する\r
+       this.reservWorkBuffers(i_xdiv2);        \r
+       double[] para00_xw=this.wk_updateExtpat_para00_xw;\r
+       double[] para10_xw=this.wk_updateExtpat_para10_xw;\r
+       double[] para20_xw=this.wk_updateExtpat_para20_xw;\r
+       int[] x_rgb_index=this.wk_updateExtpat_x_rgb_index;\r
+       int[] y_rgb_index=this.wk_updateExtpat_y_rgb_index;\r
+       int[] i_rgb_index=this.wk_updateExtpat_i_rgb_index;\r
+       int[] rgb_buf=this.wk_updateExtpat_rgb_buf;\r
+       double xw;\r
+       for(i=0;i<i_xdiv2;i++){\r
+           xw= 102.5 + 5.0 * ((double)i+0.5) /i_xdiv2;\r
+           para20_xw[i]=para20*xw;\r
+           para00_xw[i]=para00*xw;\r
+           para10_xw[i]=para10*xw;\r
+       }\r
+\r
+       int index_num;\r
+       \r
+       for(j = 0; j < i_ydiv2; j++ ) {\r
+           yw = 102.5 + 5.0 * ((double)j+0.5) /i_ydiv2;\r
+           para21_x_yw=para21*yw+1.0;\r
+           para11_x_yw=para11*yw+para12;\r
+           para01_x_yw=para01*yw+para02;\r
+           extpat_j=extpat[j/ydiv];\r
+           index_num=0;\r
+           //ステップ1.RGB取得用のマップを作成\r
+           for(i = 0; i < i_xdiv2; i++ ) {\r
+               d = para20_xw[i] + para21_x_yw;\r
+               if( d == 0 ){\r
+                   throw new NyARException();\r
+               }\r
+               xc = (int)((para00_xw[i] + para01_x_yw)/d);\r
+               yc = (int)((para10_xw[i] + para11_x_yw)/d);\r
+               //範囲外は無視\r
+               if(xc<0 || xc >=img_x || yc<0 || yc >=img_y){\r
+                   continue;\r
+               }\r
+//             ピクセル値の計算\r
+//             image.getPixel(xc,yc,rgb_buf);\r
+//                ext_pat2_j_i=ext_pat2_j[i/xdiv];\r
+//                ext_pat2_j_i[0] += rgb_buf[0];//R\r
+//                ext_pat2_j_i[1] += rgb_buf[1];//G\r
+//                ext_pat2_j_i[2] += rgb_buf[2];//B\r
+\r
+               x_rgb_index[index_num]=xc;\r
+               y_rgb_index[index_num]=yc;\r
+               i_rgb_index[index_num]=i/xdiv;\r
+               index_num++;\r
+           }\r
+//         //ステップ2.ピクセル配列を取得\r
+           image.getPixelSet(x_rgb_index,y_rgb_index,index_num,rgb_buf);\r
+//         //ピクセル値の計算\r
+           for(i=index_num-1;i>=0;i--){\r
+                extpat_j_i=extpat_j[i_rgb_index[i]];\r
+                extpat_j_i[0] += rgb_buf[i*3+0];//R\r
+                extpat_j_i[1] += rgb_buf[i*3+1];//G\r
+                extpat_j_i[2] += rgb_buf[i*3+2];//B\r
+           }\r
+       }\r
+       /*<Optimize>*/\r
+       int xdiv_x_ydiv=xdiv*ydiv;\r
+       for(j =this.height-1; j>=0; j--){\r
+           extpat_j=extpat[j];\r
+           for(i = this.width-1; i>=0; i--){                           // PRL 2006-06-08.\r
+               extpat_j_i=extpat_j[i];\r
+               extpat_j_i[0]/=(xdiv_x_ydiv);//ext_pat[j][i][0] = (byte)(ext_pat2[j][i][0] / (xdiv*ydiv));\r
+               extpat_j_i[1]/=(xdiv_x_ydiv);//ext_pat[j][i][1] = (byte)(ext_pat2[j][i][1] / (xdiv*ydiv));\r
+               extpat_j_i[2]/=(xdiv_x_ydiv);//ext_pat[j][i][2] = (byte)(ext_pat2[j][i][2] / (xdiv*ydiv));\r
+           }\r
+       }\r
+       return; \r
+    }\r
+}
\ No newline at end of file
index 3d7370d..14a3baa 100644 (file)
@@ -35,7 +35,10 @@ package jp.nyatla.nyartoolkit.core;
 \r
 \r
 import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.util.IntValue;\r
+\r
+\r
+\r
+\r
 /**\r
  * イメージからマーカー情報を検出するクラス。\r
  * このクラスは、arDetectMarker2.cとの置き換えになります。\r
@@ -46,375 +49,254 @@ public class NyARDetectMarker {
     private static final int AR_AREA_MAX=100000;//#define   AR_AREA_MAX      100000\r
     private static final int AR_AREA_MIN=70;//#define   AR_AREA_MIN          70\r
 \r
-    private int area_max=AR_AREA_MAX;\r
-    private int area_min=AR_AREA_MIN;\r
-    private NyARMarker[] marker_holder;        //マーカーデータの保持配列\r
-    private NyARMarker[] marker_info2_array;   //マーカーデータのインデックス配列\r
-    private int marker_num;\r
+//    private final NyARMarker[] marker_holder;            //マーカーデータの保持配列\r
+//    private final NyARMarker[] marker_info2_array;//マーカーデータのインデックス配列\r
+//    private int marker_num;\r
     private int width,height;\r
     /**\r
      * 最大i_squre_max個のマーカーを検出するクラスを作成する。\r
      * @param i_width\r
      * @param i_height\r
-     * @param i_squre_max\r
      */\r
-    public NyARDetectMarker(int i_width,int i_height,int i_squre_max)\r
-    {\r
-       width =i_width;\r
-       height=i_height;\r
-       marker_holder=new NyARMarker[i_squre_max];\r
-       marker_info2_array=new NyARMarker[i_squre_max];\r
-    }\r
-    public int getMarkerNum()\r
+    public NyARDetectMarker(int i_width,int i_height)\r
     {\r
-       return marker_num;\r
-    }\r
-    public NyARMarker getMarker(int idx) throws NyARException\r
-    {\r
-       if(idx>=marker_num){\r
-           throw new NyARException();\r
-       }\r
-       return marker_info2_array[idx];\r
+       this.width =i_width;\r
+       this.height=i_height;\r
+       \r
+//     this.marker_holder=new NyARMarker[i_squre_max];\r
+//     this.marker_info2_array=new NyARMarker[i_squre_max];\r
+//     //先にマーカーホルダにオブジェクトを作っておく\r
+//     for(int i=0;i<i_squre_max;i++){\r
+//         this.marker_holder[i]=new NyARMarker();\r
+//     }\r
     }\r
+    private static final int AR_CHAIN_MAX=10000;\r
+    private final int[] wk_arGetContour_xdir={0,  1, 1, 1, 0,-1,-1,-1};\r
+    private final int[] wk_arGetContour_ydir={-1,-1, 0, 1, 1, 1, 0,-1};\r
+    private final int[] wk_arGetContour_xcoord=new int[AR_CHAIN_MAX];\r
+    private final int[] wk_arGetContour_ycoord=new int[AR_CHAIN_MAX];\r
     /**\r
-     * static int get_vertex( int x_coord[], int y_coord[], int st,  int ed,double thresh, int vertex[], int *vnum)\r
-     * 関数の代替関数\r
-     * @param x_coord\r
-     * @param y_coord\r
-     * @param st\r
-     * @param ed\r
-     * @param thresh\r
-     * @param vertex\r
-     * @param vnum\r
-     * @return\r
+     * int arGetContour( ARInt16 *limage, int *label_ref,int label, int clip[4], ARMarkerInfo2 *marker_info2 )\r
+     * 関数の代替品\r
+     * detectMarker関数から使う関数です。o_markerにlabelとclipで示される1個のマーカーを格納します。\r
+     * marker_holder[i_holder_num]にオブジェクトが無ければまず新規に作成し、もし\r
+     * 既に存在すればそこにマーカー情報を上書きして記録します。\r
+     * Optimize:STEP[591->543]\r
+     * @param o_marker\r
+     * @param limage\r
+     * @param label_ref\r
+     * @param label\r
+     * @param clip\r
+     * @throws NyARException\r
      */\r
-    private static boolean get_vertex( int[] x_coord, int[] y_coord, int st,  int ed,double thresh, int vertex[],IntValue vnum)\r
+    private final void arGetContour(NyARMarker o_marker,int[][] limage, int[] label_ref,int i_labelnum, NyARLabel i_label) throws NyARException\r
     {\r
-        double   d, dmax;\r
-        double   a, b, c;\r
-        int      i, v1=0;\r
-        \r
-        a = y_coord[ed] - y_coord[st];\r
-        b = x_coord[st] - x_coord[ed];\r
-        c = x_coord[ed]*y_coord[st] - y_coord[ed]*x_coord[st];\r
-        dmax = 0;\r
-        for(i=st+1;i<ed;i++) {\r
-            d = a*x_coord[i] + b*y_coord[i] + c;\r
-            if( d*d > dmax ) {\r
-               dmax = d*d;\r
-               v1 = i;\r
-            }\r
-        }\r
-        if( dmax/(a*a+b*b) > thresh ) {\r
-            if(!get_vertex(x_coord, y_coord, st,  v1, thresh, vertex, vnum)){\r
-               return false;\r
-            }\r
-            if( vnum.get() > 5 ){\r
-               return false;\r
-            }\r
-            vertex[vnum.get()] = v1;//vertex[(*vnum)] = v1;\r
-            vnum.inc();//(*vnum)++;\r
-        \r
-            if(!get_vertex(x_coord, y_coord, v1,  ed, thresh, vertex, vnum)){\r
-                       return false;\r
-            }\r
-        }\r
-        return true;\r
-    }\r
-    /**\r
-     * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor )\r
-     * 関数の代替関数\r
-     * @param area\r
-     * @param i_marker_info2\r
-     * @param factor\r
-     * @return\r
-     */\r
-    private static boolean check_square( int area, NyARMarker i_marker_info2, double factor )\r
-       {\r
-           int             sx, sy;\r
-           int             dmax, d, v1;\r
-           int[] vertex=new int[10];//int             vertex[10]\r
-           int[] wv1=new int[10],wv2=new int[10];//int wv1[10],wv2[10];\r
-           int v2;//       int   wvnum1,wvnum2,v2;\r
-           double          thresh;\r
-           int             i;\r
-           IntValue wvnum1=new IntValue(),wvnum2=new IntValue();\r
-\r
+       final int[] xcoord=wk_arGetContour_xcoord;\r
+       final int[] ycoord=wk_arGetContour_ycoord;\r
+       final int[] xdir=wk_arGetContour_xdir; //static int      xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1};\r
+       final int[] ydir=wk_arGetContour_ydir;//static int      ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1};\r
+       //ShortPointer p1;//ARInt16         *p1;\r
+       int coord_num;\r
+       int             sx=0, sy=0, dir;\r
+       int             dmax, d, v1=0;\r
+       int             i, j,w;\r
 \r
-           dmax = 0;\r
-           v1 = 0;\r
-           sx = i_marker_info2.x_coord[0];//sx = marker_info2->x_coord[0];\r
-           sy = i_marker_info2.y_coord[0];//sy = marker_info2->y_coord[0];\r
-           for(i=1;i<i_marker_info2.coord_num-1;i++){//for(i=1;i<marker_info2->coord_num-1;i++) {\r
-               d = (i_marker_info2.x_coord[i]-sx)*(i_marker_info2.x_coord[i]-sx)+ (i_marker_info2.y_coord[i]-sy)*(i_marker_info2.y_coord[i]-sy);\r
-               if( d > dmax ) {\r
-                   dmax = d;\r
-                   v1 = i;\r
-               }\r
+       int[] limage_j;\r
+       j = i_label.clip2;\r
+       limage_j=limage[j];\r
+       final int clip1=i_label.clip1;\r
+       //p1=ShortPointer.wrap(limage,j*xsize+clip.get());//p1 = &(limage[j*xsize+clip[0]]);\r
+       for( i = i_label.clip0; i <= clip1; i++){//for( i = clip[0]; i <= clip[1]; i++, p1++ ) {\r
+           w=limage_j[i];\r
+           if(w > 0 && label_ref[w-1] == i_labelnum ) {//if( *p1 > 0 && label_ref[(*p1)-1] == label ) {\r
+               sx = i;\r
+               sy = j;\r
+               break;\r
            }\r
+       }\r
+       if(i>clip1){//if( i > clip[1] ) {\r
+           System.out.println("??? 1");//printf();\r
+           throw new NyARException();//return(-1);\r
+       }\r
 \r
-           thresh = (area/0.75) * 0.01 * factor;\r
-//         vnum = 1;\r
-           vertex[0] = 0;\r
-           wvnum1.set(0);//        wvnum1 = 0;\r
-           wvnum2.set(0);//        wvnum2 = 0;\r
+//     //マーカーホルダが既に確保済みかを調べる\r
+//     if(marker_holder[i_holder_num]==null){\r
+//         //確保していなければ確保\r
+//         marker_holder[i_holder_num]=new NyARMarker();\r
+//     }\r
 \r
-           if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord, 0,  v1,thresh, wv1, wvnum1)){            //if( get_vertex(marker_info2->x_coord, marker_info2->y_coord, 0,  v1,thresh, wv1, &wvnum1) < 0 ) {\r
-               return false;\r
+\r
+       coord_num=1;//marker_info2->coord_num = 1;\r
+       xcoord[0]=sx;//marker_info2->x_coord[0] = sx;\r
+       ycoord[0]=sy;//marker_info2->y_coord[0] = sy;\r
+       dir = 5;\r
+       \r
+       int r,c;\r
+\r
+       for(;;){\r
+           r=ycoord[coord_num-1];\r
+           c=xcoord[coord_num-1];\r
+           //p1 = &(limage[marker_info2->y_coord[marker_info2->coord_num-1] * xsize+ marker_info2->x_coord[marker_info2->coord_num-1]]);\r
+           dir = (dir+5)%8;\r
+           for(i=0;i<8;i++) {\r
+               if(limage[r+ydir[dir]][c+xdir[dir]]>0){//if( p1[ydir[dir]*xsize+xdir[dir]] > 0 ){\r
+                   break;\r
+               }\r
+               dir = (dir+1)%8;        \r
            }\r
-           if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,v1,  i_marker_info2.coord_num-1, thresh, wv2, wvnum2)) {//if(get_vertex(marker_info2->x_coord, marker_info2->y_coord,v1,  marker_info2->coord_num-1, thresh, wv2, &wvnum2) < 0 ) {\r
-               return false;\r
+           if( i == 8 ){\r
+               System.out.println("??? 2");//printf("??? 2\n");\r
+               throw new NyARException();//return(-1);\r
            }\r
-\r
-           if( wvnum1.get() == 1 && wvnum2.get() == 1 ) {//if( wvnum1 == 1 && wvnum2 == 1 ) {\r
-               vertex[1] = wv1[0];\r
-               vertex[2] = v1;\r
-               vertex[3] = wv2[0];\r
-           }else if( wvnum1.get() > 1 && wvnum2.get() == 0 ) {//}else if( wvnum1 > 1 && wvnum2 == 0 ) {\r
-               v2 = v1 / 2;\r
-               wvnum1.set(0);wvnum2.set(0);//wvnum1 = wvnum2 = 0;\r
-               if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,0,  v2, thresh, wv1, wvnum1)) {\r
-                   return false;\r
-               }\r
-               if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,v2,  v1, thresh, wv2, wvnum2)) {\r
-                   return false;\r
-               }\r
-               if( wvnum1.get() == 1 && wvnum2.get() == 1 ) {\r
-                   vertex[1] = wv1[0];\r
-                   vertex[2] = wv2[0];\r
-                   vertex[3] = v1;\r
-               }else{\r
-                   return false;\r
-               }\r
-           }else if( wvnum1.get() == 0 && wvnum2.get() > 1 ) {\r
-               v2 = (v1 + i_marker_info2.coord_num-1) / 2;\r
-               \r
-               wvnum1.set(0);wvnum2.set(0);//wvnum1 = wvnum2 = 0;\r
-               if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,v1, v2, thresh, wv1,wvnum1)) {\r
-                   return false;\r
-               }\r
-               if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,v2, i_marker_info2.coord_num-1, thresh, wv2, wvnum2)) {\r
-                   return false;\r
-               }\r
-               if( wvnum1.get() == 1 && wvnum2.get() == 1 ) {\r
-                   vertex[1] = v1;\r
-                   vertex[2] = wv1[0];\r
-                   vertex[3] = wv2[0];\r
-               }\r
-               else {\r
-                   return false;\r
-               }\r
+           xcoord[coord_num]= xcoord[coord_num-1] + xdir[dir];//marker_info2->x_coord[marker_info2->coord_num]= marker_info2->x_coord[marker_info2->coord_num-1] + xdir[dir];\r
+           ycoord[coord_num]= ycoord[coord_num-1] + ydir[dir];//marker_info2->y_coord[marker_info2->coord_num]= marker_info2->y_coord[marker_info2->coord_num-1] + ydir[dir];\r
+           if(xcoord[coord_num] == sx && ycoord[coord_num] == sy ){\r
+               break;\r
            }\r
-           else {\r
-               return false;\r
+           coord_num++;\r
+           if(coord_num == xcoord.length-1){//if( marker_info2.coord_num == Config.AR_CHAIN_MAX-1 ){\r
+               System.out.println("??? 3");//printf("??? 3\n");\r
+               throw new NyARException();//return(-1);\r
            }\r
+       }\r
 \r
-           i_marker_info2.vertex[0] = vertex[0];\r
-           i_marker_info2.vertex[1] = vertex[1];\r
-           i_marker_info2.vertex[2] = vertex[2];\r
-           i_marker_info2.vertex[3] = vertex[3];\r
-           i_marker_info2.vertex[4] = i_marker_info2.coord_num-1;\r
-\r
-           return true;\r
+       dmax = 0;\r
+       for(i=1;i<coord_num;i++) {//    for(i=1;i<marker_info2->coord_num;i++) {\r
+           d = (xcoord[i]-sx)*(xcoord[i]-sx)+ (ycoord[i]-sy)*(ycoord[i]-sy);//   d = (marker_info2->x_coord[i]-sx)*(marker_info2->x_coord[i]-sx)+ (marker_info2->y_coord[i]-sy)*(marker_info2->y_coord[i]-sy);\r
+           if( d > dmax ) {\r
+               dmax = d;\r
+               v1 = i;\r
+           }\r
        }\r
+       //NyARMarkerへcoord情報をセット\r
+       //coordの並び替えと保存はNyARMarkerへ移動\r
+       o_marker.setCoordXY(v1,coord_num,xcoord,ycoord);\r
+\r
+//     int[]      wx=new int[v1];//new int[Config.AR_CHAIN_MAX];\r
+//     int[]      wy=new int[v1]; //new int[Config.AR_CHAIN_MAX];   \r
+//     for(i=0;i<v1;i++) {\r
+//         wx[i] = marker_ref.x_coord[i];//wx[i] = marker_info2->x_coord[i];\r
+//         wy[i] = marker_ref.y_coord[i];//wy[i] = marker_info2->y_coord[i];\r
+//     }\r
+//     for(i=0;i<marker_ref.coord_num-v1;i++) {//for(i=v1;i<marker_info2->coord_num;i++) {\r
+//         marker_ref.x_coord[i] = marker_ref.x_coord[i+v1];//marker_info2->x_coord[i-v1] = marker_info2->x_coord[i];\r
+//         marker_ref.y_coord[i] = marker_ref.y_coord[i+v1];//marker_info2->y_coord[i-v1] = marker_info2->y_coord[i];\r
+//     }\r
+//     for(i=0;i<v1;i++) {\r
+//         marker_ref.x_coord[i-v1+marker_ref.coord_num] = wx[i];//marker_info2->x_coord[i-v1+marker_info2->coord_num] = wx[i];\r
+//         marker_ref.y_coord[i-v1+marker_ref.coord_num] = wy[i];//marker_info2->y_coord[i-v1+marker_info2->coord_num] = wy[i];\r
+//     }\r
+//     marker_ref.x_coord[marker_ref.coord_num] = marker_ref.x_coord[0];//marker_info2->x_coord[marker_info2->coord_num] = marker_info2->x_coord[0];\r
+//     marker_ref.y_coord[marker_ref.coord_num] = marker_ref.y_coord[0];//marker_info2->y_coord[marker_info2->coord_num] = marker_info2->y_coord[0];\r
+//     marker_ref.coord_num++;//marker_info2->coord_num++;\r
+       return;\r
+    }\r
+\r
     /**\r
-     * int arGetContour( ARInt16 *limage, int *label_ref,int label, int clip[4], ARMarkerInfo2 *marker_info2 )\r
+     * ARMarkerInfo2 *arDetectMarker2( ARInt16 *limage, int label_num, int *label_ref,int *warea, double *wpos, int *wclip,int area_max, int area_min, double factor, int *marker_num )\r
      * 関数の代替品\r
-     * detectMarker関数から使う関数です。marker_holder[i_holder_num]にオブジェクトが無ければまず新規に作成し、もし\r
-     * 既に存在すればそこにマーカー情報を上書きして記録します。\r
-     * @param limage\r
-     * @param label_ref\r
-     * @param label\r
-     * @param clip\r
-     * @return\r
-     *         検出したマーカーからマーカーオブジェクトを生成して返す。\r
+     * ラベリング情報からマーカー一覧を作成してo_marker_listを更新します。\r
+     * 関数はo_marker_listに重なりを除外したマーカーリストを作成します。\r
+     * \r
+     * @param i_labeling\r
+     * ラベリング済みの情報を持つラベリングオブジェクト\r
+     * @param i_factor\r
+     * 何かの閾値?\r
+     * @param o_marker_list\r
+     * 抽出したマーカーを格納するリスト\r
      * @throws NyARException\r
      */\r
-    private NyARMarker arGetContour(int i_holder_num,short[][] limage, int[] label_ref,int label, int[] clip) throws NyARException\r
+    public final void detectMarker(NyARLabeling i_labeling,double i_factor,NyARMarkerList o_marker_list) throws NyARException\r
     {\r
-        final int[] xdir={0,  1, 1, 1, 0,-1,-1,-1}; //static int      xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1};\r
-        final int[] ydir={-1,-1, 0, 1, 1, 1, 0,-1};//static int      ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1};\r
-        //ShortPointer p1;//ARInt16         *p1;\r
-        int             sx=0, sy=0, dir;\r
-        int             dmax, d, v1=0;\r
-        int             i, j;\r
-    \r
-        j = clip[2];\r
-        //p1=ShortPointer.wrap(limage,j*xsize+clip.get());//p1 = &(limage[j*xsize+clip[0]]);\r
-        for( i = clip[0]; i <= clip[1]; i++){//for( i = clip[0]; i <= clip[1]; i++, p1++ ) {\r
-            if(limage[j][i] > 0 && label_ref[(limage[j][i])-1] == label ) {//if( *p1 > 0 && label_ref[(*p1)-1] == label ) {\r
-                sx = i; sy = j;\r
-                break;\r
-            }\r
-        }\r
-        if(i> clip[1]){//if( i > clip[1] ) {\r
-            System.out.println("??? 1");//printf();\r
-            throw new NyARException();//return(-1);\r
-        }\r
-        \r
-        //マーカーホルダが既に確保済みかを調べる\r
-        if(marker_holder[i_holder_num]==null){\r
-            //確保していなければ確保\r
-            marker_holder[i_holder_num]=new NyARMarker();\r
-        }\r
-        NyARMarker marker_ref=marker_holder[i_holder_num];\r
+       int i;\r
+       int               xsize, ysize;\r
+       NyARLabel[] labels=i_labeling.getLabel();\r
+//     int[] warea     =i_labeling.getArea();\r
+       int label_num   =i_labeling.getLabelNum();\r
+//     int[][] wclip   =i_labeling.getClip();\r
+//     double[] wpos   =i_labeling.getPos();\r
+       int[][] limage=i_labeling.getLabelImg();\r
+       int[] label_ref =i_labeling.getLabelRef();\r
 \r
-    \r
-        marker_ref.coord_num=1;//marker_info2->coord_num = 1;\r
-        marker_ref.x_coord[0]=sx;//marker_info2->x_coord[0] = sx;\r
-        marker_ref.y_coord[0]=sy;//marker_info2->y_coord[0] = sy;\r
-        dir = 5;\r
-    \r
-        for(;;){\r
-            int r=marker_ref.y_coord[marker_ref.coord_num-1];\r
-            int c=marker_ref.x_coord[marker_ref.coord_num-1];\r
-            //p1 = &(limage[marker_info2->y_coord[marker_info2->coord_num-1] * xsize+ marker_info2->x_coord[marker_info2->coord_num-1]]);\r
-            dir = (dir+5)%8;\r
-            for(i=0;i<8;i++) {\r
-                if(limage[r+ydir[dir]][c+xdir[dir]]>0){//if( p1[ydir[dir]*xsize+xdir[dir]] > 0 ){\r
-                    break;\r
-                }\r
-                dir = (dir+1)%8;       \r
-            }\r
-            if( i == 8 ){\r
-                System.out.println("??? 2");//printf("??? 2\n");\r
-                throw new NyARException();//return(-1);\r
-            }\r
-            marker_ref.x_coord[marker_ref.coord_num]= marker_ref.x_coord[marker_ref.coord_num-1] + xdir[dir];//marker_info2->x_coord[marker_info2->coord_num]= marker_info2->x_coord[marker_info2->coord_num-1] + xdir[dir];\r
-            marker_ref.y_coord[marker_ref.coord_num]= marker_ref.y_coord[marker_ref.coord_num-1] + ydir[dir];//marker_info2->y_coord[marker_info2->coord_num]= marker_info2->y_coord[marker_info2->coord_num-1] + ydir[dir];\r
-            if( marker_ref.x_coord[marker_ref.coord_num] == sx && marker_ref.y_coord[marker_ref.coord_num] == sy ){\r
-                break;\r
-            }\r
-            marker_ref.coord_num++;\r
-            if( marker_ref.coord_num == marker_ref.x_coord.length-1){//if( marker_info2.coord_num == Config.AR_CHAIN_MAX-1 ){\r
-                System.out.println("??? 3");//printf("??? 3\n");\r
-                throw new NyARException();//return(-1);\r
-            }\r
-        }\r
-    \r
-        dmax = 0;\r
-        for(i=1;i<marker_ref.coord_num;i++) {//        for(i=1;i<marker_info2->coord_num;i++) {\r
-            d = (marker_ref.x_coord[i]-sx)*(marker_ref.x_coord[i]-sx)+ (marker_ref.y_coord[i]-sy)*(marker_ref.y_coord[i]-sy);//          d = (marker_info2->x_coord[i]-sx)*(marker_info2->x_coord[i]-sx)+ (marker_info2->y_coord[i]-sy)*(marker_info2->y_coord[i]-sy);\r
-            if( d > dmax ) {\r
-               dmax = d;\r
-               v1 = i;\r
-            }\r
-        }\r
+       //マーカーホルダをリセット\r
+       o_marker_list.reset();\r
+//     marker_num=0;\r
+       xsize =width;\r
+       ysize =height;\r
+//     マーカーをmarker_holderに蓄積する。\r
+       NyARMarker current_marker=o_marker_list.getCurrentHolder();\r
+       NyARLabel label_pt;\r
+       for(i=0; i<label_num; i++ ){\r
+           label_pt=labels[i];\r
+           if( label_pt.area < AR_AREA_MIN || label_pt.area > AR_AREA_MAX ){\r
+               continue;\r
+           }\r
+           if( label_pt.clip0 == 1 || label_pt.clip1 == xsize-2 ){//if( wclip[i*4+0] == 1 || wclip[i*4+1] == xsize-2 ){\r
+               continue;\r
+           }\r
+           if( label_pt.clip2 == 1 || label_pt.clip3 == ysize-2 ){//if( wclip[i*4+2] == 1 || wclip[i*4+3] == ysize-2 ){\r
+               continue;\r
+           }\r
+           //ret = arGetContour( limage, label_ref, i+1,&(wclip[i*4]), &(marker_info2[marker_num2]));\r
+           arGetContour(current_marker,limage, label_ref, i+1,label_pt);\r
 \r
-        int[]      wx=new int[v1];//new int[Config.AR_CHAIN_MAX];\r
-        int[]      wy=new int[v1]; //new int[Config.AR_CHAIN_MAX];   \r
-        for(i=0;i<v1;i++) {\r
-            wx[i] = marker_ref.x_coord[i];//wx[i] = marker_info2->x_coord[i];\r
-            wy[i] = marker_ref.y_coord[i];//wy[i] = marker_info2->y_coord[i];\r
-        }\r
-        for(i=v1;i<marker_ref.coord_num;i++) {//for(i=v1;i<marker_info2->coord_num;i++) {\r
-            marker_ref.x_coord[i-v1] = marker_ref.x_coord[i];//marker_info2->x_coord[i-v1] = marker_info2->x_coord[i];\r
-            marker_ref.y_coord[i-v1] = marker_ref.y_coord[i];//marker_info2->y_coord[i-v1] = marker_info2->y_coord[i];\r
-        }\r
-        for(i=0;i<v1;i++) {\r
-            marker_ref.x_coord[i-v1+marker_ref.coord_num] = wx[i];//marker_info2->x_coord[i-v1+marker_info2->coord_num] = wx[i];\r
-            marker_ref.y_coord[i-v1+marker_ref.coord_num] = wy[i];//marker_info2->y_coord[i-v1+marker_info2->coord_num] = wy[i];\r
-        }\r
-        marker_ref.x_coord[marker_ref.coord_num] = marker_ref.x_coord[0];//marker_info2->x_coord[marker_info2->coord_num] = marker_info2->x_coord[0];\r
-        marker_ref.y_coord[marker_ref.coord_num] = marker_ref.y_coord[0];//marker_info2->y_coord[marker_info2->coord_num] = marker_info2->y_coord[0];\r
-        marker_ref.coord_num++;//marker_info2->coord_num++;\r
-    \r
-        return marker_ref;\r
-    }\r
-       /**\r
-        * ARMarkerInfo2 *arDetectMarker2( ARInt16 *limage, int label_num, int *label_ref,int *warea, double *wpos, int *wclip,int area_max, int area_min, double factor, int *marker_num )\r
-        * 関数の代替品\r
-        * ラベリング情報からマーカー一覧を作成して保持します。\r
-        * この関数を実行すると、前回のdetectMarker関数で計算した保持値は破壊されます。\r
-        * @param i_labeling\r
-        * ラベリング済みの情報を持つラベリングオブジェクト\r
-        * @param factor\r
-        * 何かの閾値?\r
-        * @return\r
-        * @throws NyARException\r
-        */\r
-//     public void detectMarker(short[][] limage,int label_num,int[] label_ref,int[] warea,double[] wpos,int[] wclip,int area_max, int area_min, double factor) throws JartkException\r
-    public void detectMarker(NyARLabeling i_labeling,double factor) throws NyARException\r
-    {\r
-        int               xsize, ysize;\r
-        int               marker_num2;\r
-        double            d;\r
-        int[] warea    =i_labeling.getArea();\r
-        int label_num  =i_labeling.getLabelNum();\r
-        int[][] wclip  =i_labeling.getClip();\r
-        double[] wpos  =i_labeling.getPos();\r
-        short[][] limage       =i_labeling.getLabelImg();\r
-        int[] label_ref        =i_labeling.getLabelRef();\r
-        \r
-        marker_num=0;\r
-        xsize =width;\r
-        ysize =height;\r
-        \r
-        marker_num2 = 0;\r
-        for(int i=0; i<label_num; i++ ) {\r
-            if( warea[i] < area_min || warea[i] > area_max ){\r
-                continue;\r
-            }\r
-            if( wclip[i][0] == 1 || wclip[i][1] == xsize-2 ){//if( wclip[i*4+0] == 1 || wclip[i*4+1] == xsize-2 ){\r
-                continue;\r
-            }\r
-            if( wclip[i][2] == 1 || wclip[i][3] == ysize-2 ){//if( wclip[i*4+2] == 1 || wclip[i*4+3] == ysize-2 ){\r
-                continue;\r
-            }\r
-            //ret = arGetContour( limage, label_ref, i+1,&(wclip[i*4]), &(marker_info2[marker_num2]));\r
-            arGetContour(marker_num2,limage, label_ref, i+1,wclip[i]);\r
-            \r
-            boolean ret = check_square( warea[i], marker_holder[marker_num2], factor );//ret = check_square( warea[i], &(marker_info2[marker_num2]), factor );\r
-            if(!ret){\r
-               //後半で整理するからここはいらない。//         marker_holder[marker_num2]=null;\r
-                continue;\r
-            }\r
-            marker_holder[marker_num2].area   = warea[i];\r
-            marker_holder[marker_num2].pos[0] = wpos[i*2+0];\r
-            marker_holder[marker_num2].pos[1] = wpos[i*2+1];\r
-            marker_num2++;\r
-            //マーカーリストが上限に達した\r
-            if( marker_num2 == marker_holder.length){\r
-                break;\r
-            }\r
-        }\r
-        for(int i=0; i < marker_num2; i++ ) {\r
-            for(int j=i+1; j < marker_num2; j++ ) {\r
-                d = (marker_holder[i].pos[0] - marker_holder[j].pos[0])*\r
-                    (marker_holder[i].pos[0] - marker_holder[j].pos[0])+\r
-                    (marker_holder[i].pos[1] - marker_holder[j].pos[1])*\r
-                    (marker_holder[i].pos[1] - marker_holder[j].pos[1]);\r
-                if(marker_holder[i].area >marker_holder[j].area ) {\r
-                    if( d <marker_holder[i].area / 4 ) {\r
-                       marker_holder[j].area = 0;\r
-                    }\r
-                }else{\r
-                    if( d < marker_holder[j].area / 4 ) {\r
-                       marker_holder[i].area = 0;\r
-                    }\r
-                }\r
-            }\r
-        }\r
-        //みつかったマーカーを整理する。\r
-        //エリアが0のマーカーを外した配列を作って、その数もついでに計算\r
-        for(int i=0;i<marker_num2;i++){\r
-            if(marker_holder[i].area==0.0){\r
-               continue;\r
-            }\r
-            marker_info2_array[marker_num]=marker_holder[i];\r
-            marker_num++;\r
-        }        \r
-//        for( i=0; i < marker_num2; i++ ) {\r
-//            if( marker_info2_array[i].area == 0.0 ) {\r
-//                for( j=i+1; j < marker_num2; j++ ){\r
-//                    marker_info2_array[j-1] = marker_info2_array[j];\r
-//                }\r
-//                marker_num2--;\r
-//            }\r
-//        }\r
-        //発見したマーカー数をセット\r
-//        marker_num=marker_num2;//*marker_num = marker_num2;\r
-        //return( &(marker_info2[0]) );\r
+           if(!current_marker.checkSquare(label_pt.area,i_factor,label_pt.pos_x,label_pt.pos_y)){\r
+               //後半で整理するからここはいらない。//         marker_holder[marker_num2]=null;\r
+               continue;\r
+           }\r
+//         この3行はcheckSquareの最終段に含める。\r
+//         marker_holder[marker_num2].area   = warea[i];\r
+//         marker_holder[marker_num2].pos[0] = wpos[i*2+0];\r
+//         marker_holder[marker_num2].pos[1] = wpos[i*2+1];\r
+           //マーカー検出→次のホルダを取得\r
+           current_marker=o_marker_list.getNextHolder();\r
+           //マーカーリストが上限に達したか確認\r
+           if(current_marker==null){\r
+               break;\r
+           }\r
+       }\r
+       //マーカーリストを整理(重なり処理とかはマーカーリストに責務押し付け)\r
+       o_marker_list.updateMarkerArray();\r
+//     重なり処理かな?\r
+//     double[] pos_j,pos_i;\r
+//     for(i=0; i < marker_num2; i++ ){\r
+//         pos_i=marker_holder[i].pos;\r
+//         for(j=i+1; j < marker_num2; j++ ) {\r
+//             pos_j=marker_holder[j].pos;\r
+//             d = (pos_i[0] - pos_j[0])*(pos_i[0] - pos_j[0])+\r
+//             (pos_i[1] - pos_j[1])*(pos_i[1] - pos_j[1]);\r
+//             if(marker_holder[i].area >marker_holder[j].area ) {\r
+//                 if( d <marker_holder[i].area / 4 ) {\r
+//                     marker_holder[j].area = 0;\r
+//                 }\r
+//             }else{\r
+//                 if( d < marker_holder[j].area / 4 ) {\r
+//                     marker_holder[i].area = 0;\r
+//                 }\r
+//             }\r
+//         }\r
+//     }\r
+//     みつかったマーカーを整理する。\r
+//     エリアが0のマーカーを外した配列を作って、その数もついでに計算\r
+//     for(i=0;i<marker_num2;i++){\r
+//         if(marker_holder[i].area==0.0){\r
+//             continue;\r
+//         }\r
+//         marker_info2_array[marker_num]=marker_holder[i];\r
+//         marker_num++;\r
+//     }        \r
+//     for( i=0; i < marker_num2; i++ ) {\r
+//     if( marker_info2_array[i].area == 0.0 ) {\r
+//     for( j=i+1; j < marker_num2; j++ ){\r
+//     marker_info2_array[j-1] = marker_info2_array[j];\r
+//     }\r
+//     marker_num2--;\r
+//     }\r
+//     }\r
+//     発見したマーカー数をセット\r
+//     marker_num=marker_num2;//*marker_num = marker_num2;\r
+//     return( &(marker_info2[0]) );\r
+       return;\r
     }\r
 \r
 }\r
index c53a678..7ba5259 100644 (file)
  */\r
 package jp.nyatla.nyartoolkit.core;\r
 \r
-import jp.nyatla.util.DoubleValue;\r
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.raster.*;\r
 \r
 \r
-public class NyARDetectSquare{\r
-    private NyARLabeling labeling;\r
-    private NyARDetectMarker detect;\r
 \r
-    private NyARSquare[] marker_info;\r
-    private int number_of_square;\r
+public class NyARDetectSquare\r
+{\r
+    private final NyARLabeling labeling;\r
+    private final NyARDetectMarker detect;\r
     private NyARParam param;\r
 \r
     /**\r
-     * 最大i_sqaure_max個のマーカー情報を抽出できるインスタンスを作る\r
-     * @param i_sqaure_max\r
+     * マーカー抽出インスタンスを作ります\r
+     * @param i_param\r
      */\r
-    public NyARDetectSquare(int i_sqaure_max,NyARParam i_param)\r
+    public NyARDetectSquare(NyARParam i_param)\r
     {\r
        param=i_param;\r
-       marker_info=new NyARSquare[i_sqaure_max];//static ARMarkerInfo    marker_infoL[AR_SQUARE_MAX];\r
        //解析オブジェクトを作る\r
        int width=i_param.getX();\r
        int height=i_param.getY();\r
 \r
-       labeling=new NyARLabeling(width,height);\r
-       detect=new NyARDetectMarker(width,height,i_sqaure_max);\r
-    }\r
-    public NyARSquare[] getSquareArray()\r
-    {\r
-       return marker_info;\r
-    }\r
-    public int getSquareCount()\r
-    {\r
-       return number_of_square;\r
+       labeling=new NyARLabeling_O2(width,height);\r
+       detect=new NyARDetectMarker(width,height);\r
     }\r
     /**\r
-     * 矩形を検出する\r
+     * ラスタイメージから矩形を検出して、結果o_square_holderへ格納します\r
      * @param i_marker\r
      * @param i_number_of_marker\r
+     * @param i_square_holder\r
      * @throws NyARException\r
      */\r
-    public void detectSquare(NyARRaster i_image,int i_thresh) throws NyARException\r
+    public void detectSquare(NyARRaster i_image,int i_thresh,NyARSquareList o_square_holder) throws NyARException\r
     {\r
-       number_of_square=0;\r
+//     number_of_square=0;\r
        labeling.labeling(i_image, i_thresh);\r
        if(labeling.getLabelNum()<1){\r
            return;\r
        }\r
-       detect.detectMarker(labeling,1.0);\r
-       int number_of_marker=detect.getMarkerNum();\r
-\r
-\r
+       //ここでマーカー配列を作成する。\r
+       detect.detectMarker(labeling,1.0,o_square_holder);\r
        \r
-       int j=0;\r
-       for (int i = 0; i <number_of_marker; i++){\r
-           double[][]  line    =new double[4][3];\r
-           double[][]  vertex  =new double[4][2];\r
-           NyARMarker marker=detect.getMarker(i);\r
-           \r
-           //・・・線の検出??\r
-            if (!getLine(marker.x_coord, marker.y_coord,marker.coord_num, marker.vertex,line,vertex))\r
-            {\r
-               continue;\r
-            }\r
-            //markerは参照渡し。実体はdetect内のバッファを共有してるので注意\r
-            marker_info[j]=new NyARSquare(marker,line,vertex);\r
+       //マーカー情報をフィルタして、スクエア配列を更新する。\r
+       o_square_holder.updateSquareArray(param);\r
 \r
-            \r
-//ここで計算するのは良くないと思うんだ       \r
-//             marker_infoL[j].id  = id.get();\r
-//             marker_infoL[j].dir = dir.get();\r
-//             marker_infoL[j].cf  = cf.get(); \r
-            j++;\r
-            //配列数こえたらドゴォォォンしないようにループを抜ける\r
-            if(j>=marker_info.length){\r
-               break;\r
-            }\r
-       }\r
-       number_of_square=j;\r
-    }\r
-    /**\r
-     * arGetLine(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[4][3], double v[4][2])\r
-     * arGetLine2(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[4][3], double v[4][2], double *dist_factor)\r
-     * の2関数の合成品です。\r
-     * @param x_coord\r
-     * @param y_coord\r
-     * @param coord_num\r
-     * @param vertex\r
-     * @param line\r
-     * @param v\r
-     * @return\r
-     * @throws NyARException\r
-     */\r
-    private boolean getLine(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[][], double v[][]) throws NyARException\r
-    {\r
-        NyARMat    input,evec;\r
-        NyARVec    ev,mean;\r
-        double   w1;\r
-        int      st, ed, n;\r
-        int      i, j;\r
-        DoubleValue dv1=new DoubleValue();\r
-        DoubleValue dv2=new DoubleValue();\r
-               \r
-        ev     = new NyARVec(2);\r
-        mean   = new NyARVec(2);\r
-        evec   = new NyARMat(2,2);\r
-        double[] mean_array=mean.getArray();\r
-        double[][] evec_array=evec.getArray();\r
-        for( i = 0; i < 4; i++ ) {\r
-            w1 = (double)(vertex[i+1]-vertex[i]+1) * 0.05 + 0.5;\r
-            st = (int)(vertex[i]   + w1);\r
-            ed = (int)(vertex[i+1] - w1);\r
-            n = ed - st + 1;\r
-            if(n<2){//nが2以下でmatrix.PCAを計算することはできないので、エラーにしておく。\r
-               //System.err.println("NyARDetectSquare::getLine 稀に出るエラーです。このエラーが出ても例外が起こらなければ平気だと思いますが、出たらnyatlaまで連絡してください。");\r
-               return false;//throw new NyARException();\r
-            }\r
-            input  = new NyARMat( n, 2 );\r
-            double [][] in_array=input.getArray();\r
-            for( j = 0; j < n; j++ ) {\r
-               param.observ2Ideal(x_coord[st+j], y_coord[st+j],dv1,dv2);//arParamObserv2Ideal( dist_factor, x_coord[st+j], y_coord[st+j],&(input->m[j*2+0]), &(input->m[j*2+1]) );\r
-                in_array[j][0]=dv1.value;\r
-                in_array[j][1]=dv2.value;\r
-            }\r
-            NyARMat.matrixPCA(input, evec, ev, mean);\r
-            \r
-            line[i][0] =  evec_array[0][1];//line[i][0] =  evec->m[1];\r
-            line[i][1] = -evec_array[0][0];//line[i][1] = -evec->m[0];\r
-            line[i][2] = -(line[i][0]*mean_array[0] + line[i][1]*mean_array[1]);//line[i][2] = -(line[i][0]*mean->v[0] + line[i][1]*mean->v[1]);\r
-        }\r
-        \r
-        for( i = 0; i < 4; i++ ) {\r
-            w1 = line[(i+3)%4][0] * line[i][1] - line[i][0] * line[(i+3)%4][1];\r
-            if( w1 == 0.0 ){\r
-                return false;\r
-            }\r
-            v[i][0] = (  line[(i+3)%4][1] * line[i][2]- line[i][1] * line[(i+3)%4][2] ) / w1;\r
-            v[i][1] = (  line[i][0] * line[(i+3)%4][2]- line[(i+3)%4][0] * line[i][2] ) / w1;\r
-        }\r
-        return true;\r
+//     NyARSquare square;\r
+//     int j=0;\r
+//     for (int i = 0; i <number_of_marker; i++){\r
+//     double[][]  line        =new double[4][3];\r
+//     double[][]  vertex      =new double[4][2];\r
+//     //NyARMarker marker=detect.getMarker(i);\r
+//     square=square_holder.getSquare(i);\r
+//     //・・・線の検出??\r
+//     if (!square.getLine(param))\r
+//     {\r
+//         continue;\r
+//     }\r
+//     ここで計算するのは良くないと思うんだ  \r
+//     marker_infoL[j].id  = id.get();\r
+//     marker_infoL[j].dir = dir.get();\r
+//     marker_infoL[j].cf  = cf.get(); \r
+//     j++;\r
+//     //配列数こえたらドゴォォォンしないようにループを抜ける\r
+//     if(j>=marker_info.length){\r
+//         break;\r
+//     }\r
+//    }\r
+//    number_of_square=j;\r
     }\r
 }\r
index 7fb86d9..a1bde60 100644 (file)
@@ -35,20 +35,186 @@ import jp.nyatla.nyartoolkit.NyARException;
 import jp.nyatla.nyartoolkit.core.raster.*;\r
 \r
 \r
+interface NyARLabeling{\r
+    /**\r
+     * 検出したラベルの数を返す\r
+     * @return\r
+     */\r
+    public int getLabelNum();\r
+    /**\r
+     * \r
+     * @return\r
+     * @throws NyARException\r
+     */\r
+    public int[] getLabelRef() throws NyARException;\r
+    /**\r
+     * 検出したラベル配列\r
+     * @return\r
+     * @throws NyARException\r
+     */\r
+    public NyARLabel[] getLabel() throws NyARException;\r
+    /**\r
+     * ラベリング済みイメージを返す\r
+     * @return\r
+     * @throws NyARException\r
+     */\r
+    public int[][] getLabelImg() throws NyARException;\r
+    /**\r
+     * static ARInt16 *labeling2( ARUint8 *image, int thresh,int *label_num, int **area, double **pos, int **clip,int **label_ref, int LorR )\r
+     * 関数の代替品\r
+     * ラスタimageをラベリングして、結果を保存します。\r
+     * Optimize:STEP[1514->1493]\r
+     * @param image\r
+     * @param thresh\r
+     * @throws NyARException\r
+     */\r
+    public void labeling(NyARRaster image,int thresh) throws NyARException;\r
+}\r
+\r
+\r
+\r
+\r
+/**\r
+ * NyARLabeling_O2のworkとwork2を可変長にするためのクラス\r
+ * \r
+ *\r
+ */\r
+class NyARWorkHolder\r
+{\r
+    private final static int ARRAY_APPEND_STEP=256;\r
+    public final int[] work;\r
+    public final int[][] work2;\r
+    private int allocate_size;\r
+    /**\r
+     * 最大i_holder_size個の動的割り当てバッファを準備する。\r
+     * @param i_holder_size\r
+     */\r
+    public NyARWorkHolder(int i_holder_size)\r
+    {\r
+       //ポインタだけははじめに確保しておく\r
+       this.work=new int[i_holder_size];\r
+       this.work2=new int[i_holder_size][];\r
+       this.allocate_size=0;\r
+    }\r
+    /**\r
+     * i_indexで指定した番号までのバッファを準備する。\r
+     * @param i_index\r
+     */\r
+    public final void reserv(int i_index) throws NyARException\r
+    {\r
+       //アロケート済みなら即リターン\r
+       if(this.allocate_size>i_index){\r
+           return;\r
+       }\r
+       //要求されたインデクスは範囲外\r
+       if(i_index>=this.work.length){\r
+           throw new NyARException();\r
+       }       \r
+       //追加アロケート範囲を計算\r
+       int range=i_index+ARRAY_APPEND_STEP;\r
+       if(range>=this.work.length){\r
+           range=this.work.length;\r
+       }\r
+       //アロケート\r
+       for(int i=this.allocate_size;i<range;i++)\r
+       {\r
+           this.work2[i]=new int[7];\r
+       }\r
+       this.allocate_size=range;\r
+    }\r
+}\r
+\r
+class NyARLabel\r
+{\r
+    public int area;\r
+    public int clip0;\r
+    public int clip1;\r
+    public int clip2;\r
+    public int clip3;\r
+    public double pos_x;\r
+    public double pos_y;\r
+}\r
+\r
+\r
+class NyARLabelHolder\r
+{\r
+    private final static int ARRAY_APPEND_STEP=128;\r
+    public final NyARLabel[] labels;\r
+    private int allocate_size;\r
+    /**\r
+     * 最大i_holder_size個の動的割り当てバッファを準備する。\r
+     * @param i_holder_size\r
+     */\r
+    public NyARLabelHolder(int i_holder_size)\r
+    {\r
+       //ポインタだけははじめに確保しておく\r
+       this.labels=new NyARLabel[i_holder_size];\r
+       this.allocate_size=0;\r
+    }\r
+    /**\r
+     * i_indexで指定した番号までのバッファを準備する。\r
+     * @param i_index\r
+     */\r
+    private final void reserv(int i_index) throws NyARException\r
+    {\r
+       //アロケート済みなら即リターン\r
+       if(this.allocate_size>i_index){\r
+           return;\r
+       }\r
+       //要求されたインデクスは範囲外\r
+       if(i_index>=this.labels.length){\r
+           throw new NyARException();\r
+       }       \r
+       //追加アロケート範囲を計算\r
+       int range=i_index+ARRAY_APPEND_STEP;\r
+       if(range>=this.labels.length){\r
+           range=this.labels.length;\r
+       }\r
+       //アロケート\r
+       for(int i=this.allocate_size;i<range;i++)\r
+       {\r
+           this.labels[i]=new NyARLabel();\r
+       }\r
+       this.allocate_size=range;\r
+    }\r
+    /**\r
+     * i_reserv_sizeまでのバッファを、初期条件i_lxsizeとi_lysizeで初期化する。\r
+     * @param i_reserv_size\r
+     * @param i_lxsize\r
+     * @param i_lysize\r
+     * @throws NyARException\r
+     */\r
+    public final void init(int i_reserv_size,int i_lxsize,int i_lysize) throws NyARException\r
+    {\r
+       reserv(i_reserv_size);\r
+       NyARLabel l;\r
+       for(int i=0;i<i_reserv_size;i++){\r
+           l=this.labels[i];\r
+           l.area=0;\r
+           l.pos_x=0;\r
+           l.pos_y=0;\r
+           l.clip0= i_lxsize;//wclip[i*4+0] = lxsize;\r
+           l.clip1= 0;//wclip[i*4+0] = lxsize;\r
+           l.clip2= i_lysize;//wclip[i*4+2] = lysize;\r
+           l.clip3= 0;//wclip[i*4+3] = 0;\r
+       }       \r
+    }\r
+}\r
 \r
 \r
 /**\r
  * ラベリングクラス。NyARRasterをラベリングして、結果値を保持します。\r
+ * 構造を維持して最適化をしたバージョン\r
  *\r
  */\r
-public class NyARLabeling{\r
-    private final int WORK_SIZE=1024*32;//#define WORK_SIZE   1024*32\r
-    private short[][] label_img;//static ARInt16 l_imageL[HARDCODED_BUFFER_WIDTH*HARDCODED_BUFFER_HEIGHT];\r
-    private int[] work=new int[WORK_SIZE];//static int workL[WORK_SIZE];\r
-    private int[] work2=new int[WORK_SIZE*7];//static int work2L[WORK_SIZE*7];\r
-    private int[] area=new int[WORK_SIZE];//static int          wareaL[WORK_SIZE];\r
-    private int[][] clip=new int[WORK_SIZE][4];//static int          wclipL[WORK_SIZE*4];\r
-    private double[] pos=new double[WORK_SIZE*2];//static double       wposL[WORK_SIZE*2];\r
+class NyARLabeling_O2 implements NyARLabeling\r
+{\r
+    private static final int WORK_SIZE=1024*32;//#define WORK_SIZE   1024*32\r
+    private final int[][] glabel_img;//static ARInt16 l_imageL[HARDCODED_BUFFER_WIDTH*HARDCODED_BUFFER_HEIGHT];\r
+\r
+    private final NyARWorkHolder work_holder=new NyARWorkHolder(WORK_SIZE);\r
+    private final NyARLabelHolder label_holder=new NyARLabelHolder(WORK_SIZE);\r
+\r
     private int label_num;\r
     //\r
     private int width;\r
@@ -59,11 +225,11 @@ public class NyARLabeling{
      * @param i_height\r
      * ラベリング画像の高さ。解析するラスタの高さより大きいこと。\r
      */\r
-    public NyARLabeling(int i_width,int i_height)\r
+    public NyARLabeling_O2(int i_width,int i_height)\r
     {\r
        width =i_width;\r
        height=i_height;\r
-       label_img=new short[height][width];\r
+       glabel_img=new int[height][width];\r
        label_num=0;\r
     }\r
     /**\r
@@ -75,268 +241,245 @@ public class NyARLabeling{
        return label_num;\r
     }\r
     /**\r
-     * \r
-     * @return\r
-     * @throws NyARException\r
-     */\r
-    public int[] getLabelRef() throws NyARException\r
-    {\r
-       if(label_num<1){\r
-           throw new NyARException();\r
-       }\r
-       return work;\r
-    }\r
-    /**\r
      * 検出したエリア配列?\r
      * @return\r
      * @throws NyARException\r
      */\r
-    public int[] getArea() throws NyARException\r
+    public NyARLabel[] getLabel() throws NyARException\r
     {\r
        if(label_num<1){\r
            throw new NyARException();\r
        }\r
-       return area;\r
-    }\r
+       return this.label_holder.labels;\r
+    }    \r
     /**\r
-     * 検出したクリップ配列?\r
+     * \r
      * @return\r
      * @throws NyARException\r
      */\r
-    public int[][] getClip() throws NyARException\r
+    public int[] getLabelRef() throws NyARException\r
     {\r
        if(label_num<1){\r
            throw new NyARException();\r
        }\r
-       return clip;\r
+       return work_holder.work;\r
     }\r
     /**\r
-     * 検出した位置配列?\r
+     * ラベリング済みイメージを返す\r
      * @return\r
      * @throws NyARException\r
      */\r
-    public double[] getPos() throws NyARException\r
+    public int[][] getLabelImg() throws NyARException\r
     {\r
-       if(label_num<1){\r
-           throw new NyARException();\r
-       }\r
-       return pos;\r
+       return glabel_img;\r
     }\r
+    \r
+    private int[] wk_reservLineBuffer_buf=null;\r
     /**\r
-     * ラベリング済みイメージを返す\r
+     * ラベリング関数から使うラインスキャン用メモリの予約関数です。\r
+     * i_widthピクセル分のラインスキャン用バッファを保障します。\r
+     * @param i_width\r
      * @return\r
-     * @throws NyARException\r
      */\r
-    public short[][] getLabelImg() throws NyARException\r
+    private int[] reservWorkLineBuffer(int i_width)\r
     {\r
-       if(label_num<1){\r
-           throw new NyARException();\r
+       int[] buf=this.wk_reservLineBuffer_buf;\r
+       if(buf==null){\r
+           buf=new int[i_width];\r
+           this.wk_reservLineBuffer_buf=buf;\r
+       }else{\r
+           if(buf.length<i_width){\r
+               buf=new int[i_width];\r
+               this.wk_reservLineBuffer_buf=buf;\r
+           }\r
+           //十分なら何もしない。\r
        }\r
-       return label_img;\r
-    }\r
-    /**\r
-     * 配列の先頭からsize個をゼロクリアする\r
-     * @param array\r
-     * @param size\r
-     */\r
-    private void putZero(int[] array,int size)\r
-    {\r
-       for(int i=0;i<size;i++){\r
-            array[i]=0;\r
-       }\r
-    }\r
-    /**\r
-     * 配列の先頭からsize個をゼロクリアする\r
-     * @param array\r
-     * @param size\r
-     */\r
-    private void putZero(double[] array,int size)\r
-    {\r
-       for(int i=0;i<size;i++){\r
-            array[i]=0;\r
-       }\r
+       return buf;\r
     }\r
     /**\r
      * static ARInt16 *labeling2( ARUint8 *image, int thresh,int *label_num, int **area, double **pos, int **clip,int **label_ref, int LorR )\r
      * 関数の代替品\r
      * ラスタimageをラベリングして、結果を保存します。\r
+     * Optimize:STEP[1514->1493]\r
      * @param image\r
      * @param thresh\r
      * @throws NyARException\r
      */\r
     public void labeling(NyARRaster image,int thresh) throws NyARException\r
     {\r
-        int       wk_max;                   /*  work                */\r
-        int       m,n;                      /*  work                */\r
-        int       lxsize, lysize;\r
-        int[] warea;//int       *warea;\r
-        int[][] wclip;//int       *wclip;\r
-        double[] wpos;//double    *wpos;\r
-        int              thresht3 = thresh * 3;\r
-        \r
-        //ラベル数を0に初期化\r
-        label_num=0;\r
-    \r
-        warea=area;//warea   = &wareaL[0];\r
-        wclip=clip;//wclip   = &wclipL[0];\r
-        wpos=pos;//wpos    = &wposL[0];\r
-    \r
-        lxsize=image.getWidth();//lxsize = arUtil_c.arImXsize;\r
-        lysize=image.getHeight();//lysize = arUtil_c.arImYsize;\r
-    \r
-        for(int i = 0; i < lxsize; i++){\r
-            label_img[0][i]=0;\r
-            label_img[lysize-1][i]=0;\r
-        }\r
-        for(int i = 0; i < lysize; i++) {\r
-            label_img[i][0]=0;\r
-            label_img[i][lxsize-1]=0;                      \r
-        }\r
-        int nya_pnt_start_x_start,nya_pnt_start_y_start;\r
-        int nya_poff_step;//スキャンステップ\r
-\r
-        wk_max = 0;\r
-        nya_pnt_start_y_start=1;\r
-        nya_pnt_start_x_start=1;\r
-        nya_poff_step=1;//スキャンステップ\r
-        int nya_pnt_start_y=nya_pnt_start_y_start;\r
-        for (int j = 1; j < lysize - 1; j++, nya_pnt_start_y++) {//for (int j = 1; j < lysize - 1; j++, pnt += poff*2, pnt2 += 2) {\r
-            int nya_pnt_start_x=nya_pnt_start_x_start;\r
-            int p1=j-1;\r
-            int p2=j;\r
-           for(int i = 1; i < lxsize-1; i++, nya_pnt_start_x+=nya_poff_step) {//for(int i = 1; i < lxsize-1; i++, pnt+=poff, pnt2++) {\r
+       int wk_max;                   /*  work                */\r
+       int m,n;                      /*  work                */\r
+       int lxsize, lysize;\r
+       int thresht3 = thresh * 3;\r
+       int i,j,k;\r
+\r
+       //ラベル数を0に初期化\r
+       this.label_num=0;\r
+//     int[][] work2=this.wk_labeling_work2;\r
+//     int[] work=this.gwork;\r
+\r
+       int[][] label_img=this.glabel_img;\r
+       \r
+       lxsize=image.getWidth();//lxsize = arUtil_c.arImXsize;\r
+       lysize=image.getHeight();//lysize = arUtil_c.arImYsize;\r
+\r
+       int[] label_img_pt0,label_img_pt1;\r
+       \r
+       //<Optimize>label_img_pt0,label_img_pt1\r
+       label_img_pt0=label_img[0];\r
+       label_img_pt1=label_img[lysize-1];\r
+       for(i = 0; i < lxsize; i++){\r
+           label_img_pt0[i]=0;\r
+           label_img_pt1[i]=0;\r
+       }\r
+       //</Optimize>\r
+       for(i = 0; i < lysize; i++) {\r
+           label_img[i][0]=0;\r
+           label_img[i][lxsize-1]=0;                       \r
+       }\r
+\r
+       int[] work2_pt;\r
+       wk_max = 0;\r
+\r
+       int label_pixel;\r
+       \r
+       int[] work=this.work_holder.work;\r
+       int[][] work2=this.work_holder.work2;\r
+       //1ライン分のメモリを予約\r
+       int[] line_bufferr=reservWorkLineBuffer(lxsize);\r
+\r
+       for(j = 1; j < lysize - 1; j++) {//for (int j = 1; j < lysize - 1; j++, pnt += poff*2, pnt2 += 2) {\r
+            label_img_pt0=label_img[j];\r
+            label_img_pt1=label_img[j-1];\r
+            image.getPixelTotalRowLine(j,line_bufferr);\r
+\r
+           for(i = 1; i < lxsize-1; i++) {//for(int i = 1; i < lxsize-1; i++, pnt+=poff, pnt2++) {\r
                //RGBの合計値が閾値より大きいかな?\r
-               if(image.getPixelTotal(nya_pnt_start_x,nya_pnt_start_y)<=thresht3){\r
+               if(line_bufferr[i]<=thresht3){\r
                    //pnt1 = ShortPointer.wrap(pnt2, -lxsize);//pnt1 = &(pnt2[-lxsize]);\r
-                   if(label_img[p1][i]>0){//if( *pnt1 > 0 ) {\r
-                       label_img[p2][i]=label_img[p1][i];//*pnt2 = *pnt1;\r
-\r
-\r
-                       int p2_index=(label_img[p2][i]-1)*7;\r
-                       work2[p2_index+0]++;//work2[((*pnt2)-1)*7+0] ++;\r
-                       work2[p2_index+1]+=i;//work2[((*pnt2)-1)*7+1] += i;\r
-                       work2[p2_index+2]+=j;//work2[((*pnt2)-1)*7+2] += j;\r
-                       work2[p2_index+6]=j;//work2[((*pnt2)-1)*7+6] = j;\r
-                   }else if(label_img[p1][i+1]> 0 ) {//}else if( *(pnt1+1) > 0 ) {\r
-                       if(label_img[p1][i-1] > 0 ) {//if( *(pnt1-1) > 0 ) {\r
-                           m = work[label_img[p1][i+1]-1];//m = work[*(pnt1+1)-1];\r
-                           n = work[label_img[p1][i-1]-1];//n = work[*(pnt1-1)-1];\r
+                   if(label_img_pt1[i]>0){//if( *pnt1 > 0 ) {\r
+                       label_pixel=label_img_pt1[i];//*pnt2 = *pnt1;\r
+\r
+\r
+                       work2_pt=work2[label_pixel-1];\r
+                       work2_pt[0]++;//work2[((*pnt2)-1)*7+0] ++;\r
+                       work2_pt[1]+=i;//work2[((*pnt2)-1)*7+1] += i;\r
+                       work2_pt[2]+=j;//work2[((*pnt2)-1)*7+2] += j;\r
+                       work2_pt[6]=j;//work2[((*pnt2)-1)*7+6] = j;\r
+                   }else if(label_img_pt1[i+1]> 0 ) {//}else if( *(pnt1+1) > 0 ) {\r
+                       if(label_img_pt1[i-1] > 0 ) {//if( *(pnt1-1) > 0 ) {\r
+                           m = work[label_img_pt1[i+1]-1];//m = work[*(pnt1+1)-1];\r
+                           n = work[label_img_pt1[i-1]-1];//n = work[*(pnt1-1)-1];\r
                            if( m > n ){\r
-                               //JartkException.trap("未チェックのパス");\r
-                               label_img[p2][i]=(short)n;//*pnt2 = n;\r
+                               label_pixel=n;//*pnt2 = n;\r
                                //wk=IntPointer.wrap(work, 0);//wk = &(work[0]);\r
-                               for(int k = 0; k < wk_max; k++) {\r
-                                   //JartkException.trap("未チェックのパス");\r
+                               for(k = 0; k < wk_max; k++) {\r
                                    if(work[k] == m ){//if( *wk == m ) \r
-                                       //JartkException.trap("未チェックのパス");\r
                                        work[k]=n;//*wk = n;\r
                                    }\r
                                }\r
                            }else if( m < n ) {\r
-                               //JartkException.trap("未チェックのパス");\r
-                               label_img[p2][i]=(short)m;//*pnt2 = m;\r
+                               label_pixel=m;//*pnt2 = m;\r
                                //wk=IntPointer.wrap(work,0);//wk = &(work[0]);\r
-                               for(int k = 0; k < wk_max; k++){\r
-                                   //JartkException.trap("未チェックのパス");\r
+                               for(k = 0; k < wk_max; k++){\r
                                    if(work[k]==n){//if( *wk == n ){\r
-                                       //JartkException.trap("未チェックのパス");\r
                                        work[k]=m;//*wk = m;\r
                                    }\r
                                }\r
                            }else{\r
-                               label_img[p2][i]=(short)m;//*pnt2 = m;\r
+                               label_pixel=m;//*pnt2 = m;\r
                            }\r
-\r
-                           int p2_index=(label_img[p2][i]-1)*7;\r
-                           work2[p2_index+0] ++;\r
-                           work2[p2_index+1] += i;\r
-                           work2[p2_index+2] += j;\r
-                           work2[p2_index+6] = j;\r
-                       }else if( (label_img[p2][i-1]) > 0 ) {//}else if( *(pnt2-1) > 0 ) {\r
-                           m = work[(label_img[p1][i+1])-1];//m = work[*(pnt1+1)-1];\r
-                           n = work[(label_img[p2][i-1])-1];//n = work[*(pnt2-1)-1];\r
+                           work2_pt=work2[label_pixel-1];\r
+                           work2_pt[0] ++;\r
+                           work2_pt[1] += i;\r
+                           work2_pt[2] += j;\r
+                           work2_pt[6] = j;\r
+                       }else if( (label_img_pt0[i-1]) > 0 ) {//}else if( *(pnt2-1) > 0 ) {\r
+                           m = work[(label_img_pt1[i+1])-1];//m = work[*(pnt1+1)-1];\r
+                           n = work[label_img_pt0[i-1]-1];//n = work[*(pnt2-1)-1];\r
                            if( m > n ) {\r
 \r
-                               label_img[p2][i]=(short)n;//*pnt2 = n;\r
-                               for(int k = 0; k < wk_max; k++) {\r
+                               label_pixel=n;//*pnt2 = n;\r
+                               for(k = 0; k < wk_max; k++) {\r
                                    if(work[k]==m){//if( *wk == m ){\r
                                        work[k]=n;//*wk = n;\r
                                    }\r
                                }\r
                            }else if( m < n ) {\r
-                               label_img[p2][i]=(short)m;//*pnt2 = m;\r
-                               for(int k = 0; k < wk_max; k++) {\r
+                               label_pixel=m;//*pnt2 = m;\r
+                               for(k = 0; k < wk_max; k++) {\r
                                    if(work[k]==n){//if( *wk == n ){\r
                                        work[k]=m;//*wk = m;\r
                                    }\r
                                }\r
                            }else{\r
-                               label_img[p2][i]=(short)m;//*pnt2 = m;\r
+                               label_pixel=m;//*pnt2 = m;\r
                            }\r
-\r
-\r
-                           int p2_index=((label_img[p2][i])-1)*7;\r
-                           work2[p2_index+0] ++;//work2[((*pnt2)-1)*7+0] ++;\r
-                           work2[p2_index+1] += i;//work2[((*pnt2)-1)*7+1] += i;\r
-                           work2[p2_index+2] += j;//work2[((*pnt2)-1)*7+2] += j;\r
+                           work2_pt=work2[label_pixel-1];\r
+                           work2_pt[0] ++;//work2[((*pnt2)-1)*7+0] ++;\r
+                           work2_pt[1] += i;//work2[((*pnt2)-1)*7+1] += i;\r
+                           work2_pt[2] += j;//work2[((*pnt2)-1)*7+2] += j;\r
                        }else{\r
 \r
-                           label_img[p2][i]=label_img[p1][i+1];//*pnt2 = *(pnt1+1);\r
-                           \r
-                           int p2_index=((label_img[p2][i])-1)*7;\r
-                           work2[p2_index+0] ++;//work2[((*pnt2)-1)*7+0] ++;\r
-                           work2[p2_index+1] += i;//work2[((*pnt2)-1)*7+1] += i;\r
-                           work2[p2_index+2] += j;//work2[((*pnt2)-1)*7+2] += j;\r
-                           if( work2[p2_index+3] > i ){//if( work2[((*pnt2)-1)*7+3] > i ){             \r
-                               work2[p2_index+3] = i;//        work2[((*pnt2)-1)*7+3] = i;\r
+                           label_pixel=label_img_pt1[i+1];//*pnt2 = *(pnt1+1);\r
+\r
+                           work2_pt=work2[label_pixel-1];\r
+                           work2_pt[0] ++;//work2[((*pnt2)-1)*7+0] ++;\r
+                           work2_pt[1] += i;//work2[((*pnt2)-1)*7+1] += i;\r
+                           work2_pt[2] += j;//work2[((*pnt2)-1)*7+2] += j;\r
+                           if( work2_pt[3] > i ){//if( work2[((*pnt2)-1)*7+3] > i ){           \r
+                               work2_pt[3] = i;//      work2[((*pnt2)-1)*7+3] = i;\r
                            }\r
-                           work2[p2_index+6] = j;//work2[((*pnt2)-1)*7+6] = j;\r
+                           work2_pt[6] = j;//work2[((*pnt2)-1)*7+6] = j;\r
                        }\r
-                   }else if( (label_img[p1][i-1]) > 0 ) {//}else if( *(pnt1-1) > 0 ) {\r
-                       label_img[p2][i]=label_img[p1][i-1];//*pnt2 = *(pnt1-1);\r
-\r
-                       int p2_index=((label_img[p2][i])-1)*7;\r
-                       work2[p2_index+0] ++;//work2[((*pnt2)-1)*7+0] ++;\r
-                       work2[p2_index+1] += i;//work2[((*pnt2)-1)*7+1] += i;\r
-                       work2[p2_index+2] += j;//work2[((*pnt2)-1)*7+2] += j;\r
-                       if( work2[p2_index+4] < i ){//if( work2[((*pnt2)-1)*7+4] < i ){\r
-                           work2[p2_index+4] = i;//    work2[((*pnt2)-1)*7+4] = i;\r
+                   }else if( (label_img_pt1[i-1]) > 0 ) {//}else if( *(pnt1-1) > 0 ) {\r
+                       label_pixel=label_img_pt1[i-1];//*pnt2 = *(pnt1-1);\r
+\r
+                       work2_pt=work2[label_pixel-1];\r
+                       work2_pt[0] ++;//work2[((*pnt2)-1)*7+0] ++;\r
+                       work2_pt[1] += i;//work2[((*pnt2)-1)*7+1] += i;\r
+                       work2_pt[2] += j;//work2[((*pnt2)-1)*7+2] += j;\r
+                       if( work2_pt[4] < i ){//if( work2[((*pnt2)-1)*7+4] < i ){\r
+                           work2_pt[4] = i;//  work2[((*pnt2)-1)*7+4] = i;\r
                        }\r
-                       work2[p2_index+6] = j;//work2[((*pnt2)-1)*7+6] = j;\r
-                   }else if(label_img[p2][i-1] > 0) {//}else if( *(pnt2-1) > 0) {\r
-                       label_img[p2][i]=label_img[p2][i-1];//*pnt2 = *(pnt2-1);\r
-\r
-                       int p2_index=((label_img[p2][i])-1)*7;\r
-                       work2[p2_index+0] ++;//work2[((*pnt2)-1)*7+0] ++;\r
-                       work2[p2_index+1] += i;//work2[((*pnt2)-1)*7+1] += i;\r
-                       work2[p2_index+2] += j;//work2[((*pnt2)-1)*7+2] += j;\r
-                       if( work2[p2_index+4] < i ){//if( work2[((*pnt2)-1)*7+4] < i ){\r
-                           work2[p2_index+4] = i;//    work2[((*pnt2)-1)*7+4] = i;\r
+                       work2_pt[6] = j;//work2[((*pnt2)-1)*7+6] = j;\r
+                   }else if(label_img_pt0[i-1] > 0) {//}else if( *(pnt2-1) > 0) {\r
+                       label_pixel=label_img_pt0[i-1];//*pnt2 = *(pnt2-1);\r
+\r
+                       work2_pt=work2[label_pixel-1];\r
+                       work2_pt[0] ++;//work2[((*pnt2)-1)*7+0] ++;\r
+                       work2_pt[1] += i;//work2[((*pnt2)-1)*7+1] += i;\r
+                       work2_pt[2] += j;//work2[((*pnt2)-1)*7+2] += j;\r
+                       if(work2_pt[4] < i ){//if( work2[((*pnt2)-1)*7+4] < i ){\r
+                           work2_pt[4] = i;//  work2[((*pnt2)-1)*7+4] = i;\r
                        }\r
                    }else{\r
+                       //現在地までの領域を予約\r
+                       this.work_holder.reserv(wk_max);\r
                        wk_max++;\r
-                       if( wk_max > WORK_SIZE ) {\r
-                           throw new NyARException();//return (0);\r
-                       }\r
-                       work[wk_max-1] = wk_max;label_img[p2][i]=(short)wk_max;//work[wk_max-1] = *pnt2 = wk_max;\r
-                       work2[(wk_max-1)*7+0] = 1;\r
-                       work2[(wk_max-1)*7+1] = i;\r
-                       work2[(wk_max-1)*7+2] = j;\r
-                       work2[(wk_max-1)*7+3] = i;\r
-                       work2[(wk_max-1)*7+4] = i;\r
-                       work2[(wk_max-1)*7+5] = j;\r
-                       work2[(wk_max-1)*7+6] = j;\r
+                       work[wk_max-1] = wk_max;\r
+                       label_pixel=wk_max;//work[wk_max-1] = *pnt2 = wk_max;\r
+                       work2_pt=work2[wk_max-1];\r
+                       work2_pt[0] = 1;\r
+                       work2_pt[1] = i;\r
+                       work2_pt[2] = j;\r
+                       work2_pt[3] = i;\r
+                       work2_pt[4] = i;\r
+                       work2_pt[5] = j;\r
+                       work2_pt[6] = j;\r
                    }\r
+                   label_img_pt0[i]=label_pixel;\r
                }else {\r
-                   label_img[p2][i]=0;//*pnt2 = 0;\r
+                   label_img_pt0[i]=0;//*pnt2 = 0;\r
                }\r
+               \r
            }\r
        }\r
-       int j = 1;\r
-       for(int i = 0; i < wk_max; i++){//for(int i = 1; i <= wk_max; i++, wk++) {\r
+       j = 1;\r
+       for(i = 0; i < wk_max; i++){//for(int i = 1; i <= wk_max; i++, wk++) {\r
            work[i]=(work[i]==i+1)? j++: work[work[i]-1];//*wk = (*wk==i)? j++: work[(*wk)-1];\r
        }\r
-       \r
+\r
        int wlabel_num=j - 1;//*label_num = *wlabel_num = j - 1;\r
 \r
        if(wlabel_num==0){//if( *label_num == 0 ) {\r
@@ -344,38 +487,67 @@ public class NyARLabeling{
            return;\r
        }\r
 \r
-       putZero(warea,wlabel_num);//put_zero( (ARUint8 *)warea, *label_num *     sizeof(int) );\r
-       putZero(wpos,wlabel_num*2);//put_zero( (ARUint8 *)wpos,  *label_num * 2 * sizeof(double) );\r
-       for(int i = 0; i < wlabel_num; i++) {//for(i = 0; i < *label_num; i++) {\r
-           wclip[i][0] = lxsize;//wclip[i*4+0] = lxsize;\r
-           wclip[i][1] = 0;//wclip[i*4+1] = 0;\r
-           wclip[i][2] = lysize;//wclip[i*4+2] = lysize;\r
-           wclip[i][3] = 0;//wclip[i*4+3] = 0;\r
-       }\r
-       for(int i = 0; i < wk_max; i++) {\r
-           j = work[i] - 1;\r
-           warea[j]    += work2[i*7+0];\r
-           wpos[j*2+0] += work2[i*7+1];\r
-           wpos[j*2+1] += work2[i*7+2];\r
-           if( wclip[j][0] > work2[i*7+3] ){\r
-               wclip[j][0] = work2[i*7+3];\r
+       \r
+       \r
+       //ラベルバッファを予約&初期化\r
+       this.label_holder.init(wlabel_num, lxsize, lysize);\r
+//     \r
+//     putZero(warea,wlabel_num);//put_zero( (ARUint8 *)warea, *label_num *     sizeof(int) );\r
+//     for(i=0;i<wlabel_num;i++){\r
+//         wpos[i*2+0]=0;\r
+//         wpos[i*2+1]=0;\r
+//     }\r
+//     for(i = 0; i < wlabel_num; i++) {//for(i = 0; i < *label_num; i++) {\r
+//         wclip[i][0] = lxsize;//wclip[i*4+0] = lxsize;\r
+//         wclip[i][1] = 0;//wclip[i*4+1] = 0;\r
+//         wclip[i][2] = lysize;//wclip[i*4+2] = lysize;\r
+//         wclip[i][3] = 0;//wclip[i*4+3] = 0;\r
+//     }\r
+       NyARLabel label_pt;\r
+       NyARLabel[] labels=this.label_holder.labels;\r
+       \r
+       for(i = 0; i < wk_max; i++){\r
+           label_pt=labels[work[i] - 1];\r
+           work2_pt=work2[i];\r
+           label_pt.area  += work2_pt[0];\r
+           label_pt.pos_x += work2_pt[1];\r
+           label_pt.pos_y += work2_pt[2];\r
+           if( label_pt.clip0 > work2_pt[3] ){\r
+               label_pt.clip0 = work2_pt[3];\r
            }\r
-           if( wclip[j][1] < work2[i*7+4] ){\r
-               wclip[j][1] = work2[i*7+4];\r
+           if( label_pt.clip1 < work2_pt[4] ){\r
+               label_pt.clip1 = work2_pt[4];\r
            }\r
-           if( wclip[j][2] > work2[i*7+5] ){\r
-               wclip[j][2] = work2[i*7+5];\r
+           if(label_pt.clip2 > work2_pt[5] ){\r
+               label_pt.clip2 = work2_pt[5];\r
            }\r
-           if( wclip[j][3] < work2[i*7+6] ){\r
-               wclip[j][3] = work2[i*7+6];\r
+           if( label_pt.clip3 < work2_pt[6] ){\r
+               label_pt.clip3 = work2_pt[6];\r
            }\r
+           \r
+//         warea[j]    += work2_pt[0];\r
+//         wpos[j*2+0] += work2_pt[1];\r
+//         wpos[j*2+1] += work2_pt[2];\r
+//         if( wclip[j][0] > work2_pt[3] ){\r
+//             wclip[j][0] = work2_pt[3];\r
+//         }\r
+//         if( wclip[j][1] < work2_pt[4] ){\r
+//             wclip[j][1] = work2_pt[4];\r
+//         }\r
+//         if( wclip[j][2] > work2_pt[5] ){\r
+//             wclip[j][2] = work2_pt[5];\r
+//         }\r
+//         if( wclip[j][3] < work2_pt[6] ){\r
+//             wclip[j][3] = work2_pt[6];\r
+//         }\r
        }\r
 \r
-       for(int i = 0; i < wlabel_num; i++ ) {//for(int i = 0; i < *label_num; i++ ) {\r
-           wpos[i*2+0] /= warea[i];\r
-           wpos[i*2+1] /= warea[i];\r
+       for(i = 0; i < wlabel_num; i++ ) {//for(int i = 0; i < *label_num; i++ ) {\r
+           label_pt=labels[i];\r
+           label_pt.pos_x /= label_pt.area;\r
+           label_pt.pos_y /= label_pt.area;\r
        }\r
-       \r
+\r
        label_num=wlabel_num;\r
        return;\r
     }\r
index 48fdaa6..7fd0989 100644 (file)
@@ -35,6 +35,8 @@ package jp.nyatla.nyartoolkit.core;
 \r
 \r
 \r
+\r
+\r
 /**\r
  * typedef struct {\r
  *     int     area;\r
@@ -48,13 +50,228 @@ package jp.nyatla.nyartoolkit.core;
  */\r
 class NyARMarker\r
 {\r
-    private static final int AR_CHAIN_MAX=10000;\r
-    int                area;\r
-    double[]   pos=new double[2];\r
+    /**\r
+     * メモリブロックのサイズ(32*4=128kb)\r
+     */\r
+    private static final int ALLOCATE_PAGE_SIZE=256;\r
+    /**\r
+     * メモリブロックの初期サイズ\r
+     */\r
+    private static final int INITIAL_SIZE=1;\r
+    int[]      x_coord=new int[INITIAL_SIZE];\r
+    int[]      y_coord=new int[INITIAL_SIZE];\r
     int                coord_num;\r
-    int[]      x_coord=new int[AR_CHAIN_MAX];\r
-    int[]      y_coord=new int[AR_CHAIN_MAX];\r
-    int[]      vertex=new int[5];\r
+    int                area;\r
+    final double[] pos=new double[2];\r
+    final int[] mkvertex=new int[5];\r
+    /**\r
+     * coordバッファをi_chain_num以上のサイズに再アロケートする。\r
+     * 内容の引継ぎは行われない。\r
+     * @param i_chain_num\r
+     */\r
+    private void reallocCoordArray(int i_chain_num)\r
+    {\r
+       if(x_coord.length<i_chain_num){\r
+           //ALLOCATE_PAGE_SIZE単位で確保する。\r
+           int new_size=((i_chain_num+ALLOCATE_PAGE_SIZE-1)/ALLOCATE_PAGE_SIZE)*ALLOCATE_PAGE_SIZE;\r
+           x_coord=new int[new_size];\r
+           y_coord=new int[new_size];\r
+           coord_num=0;\r
+       }\r
+    }\r
+    public void setCoordXY(int i_v1,int i_coord_num,int[] i_xcoord,int[] i_ycoord)\r
+    {\r
+       //メモリの割り当て保障\r
+       reallocCoordArray(i_coord_num+1);\r
+       //[A B C]を[B C A]に並べなおす。\r
+       System.arraycopy(i_xcoord,i_v1,x_coord,0,i_coord_num-i_v1);\r
+       System.arraycopy(i_xcoord,0,x_coord,i_coord_num-i_v1, i_v1);\r
+       x_coord[i_coord_num]=x_coord[0];\r
+       System.arraycopy(i_ycoord,i_v1,y_coord,0,i_coord_num-i_v1);\r
+       System.arraycopy(i_ycoord,0,y_coord,i_coord_num-i_v1, i_v1);\r
+       y_coord[i_coord_num]=y_coord[0];\r
+       coord_num=i_coord_num+1;\r
+       return;\r
+//arGetContour関数から取り外した部分        \r
+//     int[]      wx=new int[v1];//new int[Config.AR_CHAIN_MAX];\r
+//     int[]      wy=new int[v1]; //new int[Config.AR_CHAIN_MAX];   \r
+//     for(i=0;i<v1;i++) {\r
+//         wx[i] = marker_ref.x_coord[i];//wx[i] = marker_info2->x_coord[i];\r
+//         wy[i] = marker_ref.y_coord[i];//wy[i] = marker_info2->y_coord[i];\r
+//     }\r
+//     for(i=0;i<marker_ref.coord_num-v1;i++) {//for(i=v1;i<marker_info2->coord_num;i++) {\r
+//         marker_ref.x_coord[i] = marker_ref.x_coord[i+v1];//marker_info2->x_coord[i-v1] = marker_info2->x_coord[i];\r
+//         marker_ref.y_coord[i] = marker_ref.y_coord[i+v1];//marker_info2->y_coord[i-v1] = marker_info2->y_coord[i];\r
+//     }\r
+//     for(i=0;i<v1;i++) {\r
+//         marker_ref.x_coord[i-v1+marker_ref.coord_num] = wx[i];//marker_info2->x_coord[i-v1+marker_info2->coord_num] = wx[i];\r
+//         marker_ref.y_coord[i-v1+marker_ref.coord_num] = wy[i];//marker_info2->y_coord[i-v1+marker_info2->coord_num] = wy[i];\r
+//     }\r
+//     marker_ref.x_coord[marker_ref.coord_num] = marker_ref.x_coord[0];//marker_info2->x_coord[marker_info2->coord_num] = marker_info2->x_coord[0];\r
+//     marker_ref.y_coord[marker_ref.coord_num] = marker_ref.y_coord[0];//marker_info2->y_coord[marker_info2->coord_num] = marker_info2->y_coord[0];\r
+//     marker_ref.coord_num++;//marker_info2->coord_num++;\r
+    }\r
+    private final NyARVertexCounter wk_checkSquare_wv1=new NyARVertexCounter();\r
+    private final NyARVertexCounter wk_checkSquare_wv2=new NyARVertexCounter();\r
+    /**\r
+     * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor )\r
+     * 関数の代替関数\r
+     * OPTIMIZED STEP [450->397]\r
+     * @param i_area\r
+     * @param i_factor\r
+     * @return\r
+     */\r
+    public boolean checkSquare(int i_area,double i_factor,double i_pos_x,double i_pos_y)\r
+    {\r
+       final int[] l_vertex=mkvertex;\r
+       final int[] l_x_coord=x_coord;\r
+       final int[] l_y_coord=y_coord;\r
+       final NyARVertexCounter wv1=wk_checkSquare_wv1;\r
+       final NyARVertexCounter wv2=wk_checkSquare_wv2;\r
+       int             sx, sy;\r
+       int             dmax, d, v1;\r
+       \r
+       int v2;//           int   wvnum1,wvnum2,v2;\r
+       double          thresh;\r
+       int             i;\r
+       \r
+       dmax = 0;\r
+       v1 = 0;\r
+       sx = l_x_coord[0];//sx = marker_info2->x_coord[0];\r
+       sy = l_y_coord[0];//sy = marker_info2->y_coord[0];\r
+       for(i=1;i<this.coord_num-1;i++){//for(i=1;i<marker_info2->coord_num-1;i++) {\r
+           d = (l_x_coord[i]-sx)*(l_x_coord[i]-sx)+ (l_y_coord[i]-sy)*(l_y_coord[i]-sy);\r
+           if( d > dmax ) {\r
+               dmax = d;\r
+               v1 = i;\r
+           }\r
+       }\r
+\r
+       thresh = (i_area/0.75) * 0.01 * i_factor;\r
+\r
+       l_vertex[0] = 0;\r
+\r
+       if(!wv1.getVertex(l_x_coord,l_y_coord, 0,  v1,thresh)){     //if( get_vertex(marker_info2->x_coord, marker_info2->y_coord, 0,  v1,thresh, wv1, &wvnum1) < 0 ) {\r
+           return false;\r
+       }\r
+       if(!wv2.getVertex(l_x_coord,l_y_coord,v1,  this.coord_num-1, thresh)) {//if(get_vertex(marker_info2->x_coord, marker_info2->y_coord,v1,  marker_info2->coord_num-1, thresh, wv2, &wvnum2) < 0 ) {\r
+           return false;\r
+       }\r
+\r
+       if(wv1.number_of_vertex==1 && wv2.number_of_vertex==1) {//if( wvnum1 == 1 && wvnum2 == 1 ) {\r
+           l_vertex[1] = wv1.vertex[0];\r
+           l_vertex[2] = v1;\r
+           l_vertex[3] = wv2.vertex[0];\r
+       }else if( wv1.number_of_vertex>1 && wv2.number_of_vertex==0 ) {//}else if( wvnum1 > 1 && wvnum2 == 0 ) {\r
+           v2 = v1 / 2;\r
+           if(!wv1.getVertex(l_x_coord,l_y_coord,0,  v2, thresh)) {\r
+               return false;\r
+           }\r
+           if(!wv2.getVertex(l_x_coord,l_y_coord,v2,  v1, thresh)) {\r
+               return false;\r
+           }\r
+           if(wv1.number_of_vertex==1 && wv2.number_of_vertex==1 ) {\r
+               l_vertex[1] = wv1.vertex[0];\r
+               l_vertex[2] = wv2.vertex[0];\r
+               l_vertex[3] = v1;\r
+           }else{\r
+               return false;\r
+           }\r
+       }else if(wv1.number_of_vertex==0 && wv2.number_of_vertex> 1 ) {\r
+           v2 = (v1 + this.coord_num-1) / 2;\r
+\r
+           if(!wv1.getVertex(l_x_coord,l_y_coord,v1, v2, thresh)) {\r
+               return false;\r
+           }\r
+           if(!wv2.getVertex(l_x_coord,l_y_coord,v2, this.coord_num-1, thresh)) {\r
+               return false;\r
+           }\r
+           if( wv1.number_of_vertex==1 && wv2.number_of_vertex==1 ) {\r
+               l_vertex[1] = v1;\r
+               l_vertex[2] = wv1.vertex[0];\r
+               l_vertex[3] = wv2.vertex[0];\r
+           }\r
+           else {\r
+               return false;\r
+           }\r
+       }\r
+       else {\r
+           return false;\r
+       }\r
+       l_vertex[4] = this.coord_num-1;//この値使ってるの?\r
+       //\r
+       area   = i_area;\r
+       pos[0] = i_pos_x;\r
+       pos[1] = i_pos_y;\r
+//      marker_holder[marker_num2].pos[1] = wpos[i*2+1];       \r
+       return true;\r
+    }        \r
 }\r
 \r
 \r
+/**\r
+ * get_vertex関数を切り離すためのクラス\r
+ *\r
+ */\r
+final class NyARVertexCounter\r
+{\r
+    public final int[] vertex=new int[10];//5まで削れる\r
+    public int number_of_vertex;\r
+    private double thresh;\r
+    private int[] x_coord;\r
+    private int[] y_coord;\r
+\r
+    public boolean getVertex(int[] i_x_coord, int[] i_y_coord, int st,  int ed,double i_thresh)\r
+    {\r
+       this.number_of_vertex=0;\r
+       this.thresh=i_thresh;\r
+       this.x_coord=i_x_coord;\r
+       this.y_coord=i_y_coord;\r
+       return get_vertex(st,ed);\r
+    }\r
+    /**\r
+     * static int get_vertex( int x_coord[], int y_coord[], int st,  int ed,double thresh, int vertex[], int *vnum)\r
+     * 関数の代替関数\r
+     * @param x_coord\r
+     * @param y_coord\r
+     * @param st\r
+     * @param ed\r
+     * @param thresh\r
+     * @return\r
+     */\r
+    private boolean get_vertex(int st,  int ed)\r
+    {\r
+        double   d, dmax;\r
+        double   a, b, c;\r
+        int      i, v1=0;\r
+        final int[] lx_coord=this.x_coord;\r
+        final int[] ly_coord=this.y_coord;       \r
+        a = ly_coord[ed] - ly_coord[st];\r
+        b = lx_coord[st] - lx_coord[ed];\r
+        c = lx_coord[ed]*ly_coord[st] - ly_coord[ed]*lx_coord[st];\r
+        dmax = 0;\r
+        for(i=st+1;i<ed;i++) {\r
+            d = a*lx_coord[i] + b*ly_coord[i] + c;\r
+            if( d*d > dmax ) {\r
+               dmax = d*d;\r
+               v1 = i;\r
+            }\r
+        }\r
+        if( dmax/(a*a+b*b) > thresh ) {\r
+            if(!get_vertex(st,  v1)){\r
+               return false;\r
+            }\r
+            if(number_of_vertex > 5 ){\r
+               return false;\r
+            }\r
+            vertex[number_of_vertex] = v1;//vertex[(*vnum)] = v1;\r
+            number_of_vertex++;//(*vnum)++;\r
+        \r
+            if(!get_vertex(v1,  ed)){\r
+                       return false;\r
+            }\r
+        }\r
+        return true;\r
+    }\r
+}\r
+\r
diff --git a/src/jp/nyatla/nyartoolkit/core/NyARMarkerList.java b/src/jp/nyatla/nyartoolkit/core/NyARMarkerList.java
new file mode 100644 (file)
index 0000000..6e03c2f
--- /dev/null
@@ -0,0 +1,148 @@
+package jp.nyatla.nyartoolkit.core;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+\r
+/**\r
+ * このクラスは、detectMarkerがマーカーオブジェクトの蓄積に使うクラスです。\r
+ * 実体を伴うマーカーホルダと、これを参照するマーカーアレイを持ちます。\r
+ * \r
+ * マーカーアレイはマーカーホルダに存在するマーカーリストを特定の条件でフィルタした\r
+ * 結果を格納します。\r
+ * \r
+ * 一度作られたマーカーホルダは繰り返し使用されます。\r
+ * \r
+ *\r
+ */\r
+public class NyARMarkerList\r
+{\r
+    private int marker_holder_num;//marker_holderの使用中の数\r
+    protected int marker_array_num;//marker_arrayの有効な数\r
+    protected final NyARMarker[] marker_holder;//マーカーデータの保持配列\r
+    protected final NyARMarker[] marker_array; //マーカーデータのインデックス配列\r
+    /**\r
+     * 派生データ型をラップするときに使う\r
+     * @param i_holder\r
+     * 値の保持配列。全要素に実体を割り当てる必要がある。\r
+     */\r
+    protected  NyARMarkerList(NyARMarker[] i_holder)\r
+    {\r
+       this.marker_holder=i_holder;\r
+       this.marker_array =new NyARMarker[i_holder.length];\r
+       this.marker_array_num   =0;\r
+       this.marker_holder_num =0;\r
+    }\r
+    public NyARMarkerList(int i_number_of_holder)\r
+    {\r
+       this.marker_holder=new NyARMarker[i_number_of_holder];\r
+       //先にマーカーホルダにオブジェクトを作っておく\r
+       for(int i=0;i<i_number_of_holder;i++){\r
+           this.marker_holder[i]=new NyARMarker();\r
+       }\r
+       this.marker_array =new NyARMarker[this.marker_holder.length];\r
+       this.marker_array_num   =0;\r
+       this.marker_holder_num =0;\r
+    }\r
+    /**\r
+     * 現在位置のマーカーホルダを返す。\r
+     * 現在位置が終端の場合関数は失敗する。\r
+     * @return\r
+     */\r
+    public final NyARMarker getCurrentHolder() throws NyARException\r
+    {\r
+       if(this.marker_holder_num>=this.marker_holder.length){\r
+           throw new NyARException();\r
+       }       \r
+       return this.marker_holder[this.marker_holder_num];\r
+    }\r
+    /**\r
+     * マーカーホルダの現在位置を1つ進めて、そのホルダを返す。\r
+     * この関数を実行すると、使用中のマーカーホルダの数が1個増える。\r
+     * @return\r
+     * 空いているマーカーホルダが無ければnullを返します。\r
+     *\r
+     */\r
+    public final NyARMarker getNextHolder()\r
+    {\r
+       //現在位置が終端位置ならnullを返す。\r
+       if(this.marker_holder_num+1>=this.marker_holder.length){\r
+            this.marker_holder_num=this.marker_holder.length;\r
+           return null;\r
+       }\r
+       this.marker_holder_num++;\r
+       return this.marker_holder[this.marker_holder_num];\r
+    }\r
+    /**\r
+     * マーカーアレイのi_indexの要素を返す。\r
+     * @param i_index\r
+     * @return\r
+     * @throws NyARException\r
+     */\r
+    public final NyARMarker getMarker(int i_index) throws NyARException\r
+    {\r
+       if(i_index>=marker_array_num){\r
+           throw new NyARException();\r
+       }\r
+       return this.marker_array[i_index];\r
+    }\r
+    /**\r
+     * マーカーアレイの要素数を返す。\r
+     * @return\r
+     */\r
+    public final int getMarkerNum()\r
+    {\r
+       return marker_array_num;\r
+    }\r
+    /**\r
+     * マーカーアレイの要素数と、マーカーホルダの現在位置をリセットする。\r
+     * @return\r
+     */\r
+    public final void reset()\r
+    {\r
+       this.marker_array_num=0;\r
+       this.marker_holder_num=0;\r
+    }\r
+    /**\r
+     * マーカーホルダに格納済みのマーカーから重なっているのものを除外して、\r
+     * マーカーアレイにフィルタ結果を格納します。\r
+     * [[この関数はマーカー検出処理と密接に関係する関数です。\r
+     * NyARDetectMarkerクラス以外から呼び出さないで下さい。]]\r
+     * メモ:この関数はmarker_holderの内容を変化させまするので注意。\r
+     */\r
+    public final void updateMarkerArray()\r
+    {\r
+       //重なり処理かな?\r
+       int i;\r
+       double d;\r
+       double[] pos_j,pos_i;\r
+//     NyARMarker[] marker_holder;\r
+       for(i=0; i < this.marker_holder_num; i++ ){\r
+           pos_i=marker_holder[i].pos;\r
+           for(int j=i+1; j < this.marker_holder_num; j++ ) {\r
+               pos_j=marker_holder[j].pos;\r
+               d = (pos_i[0] - pos_j[0])*(pos_i[0] - pos_j[0])+\r
+               (pos_i[1] - pos_j[1])*(pos_i[1] - pos_j[1]);\r
+               if(marker_holder[i].area >marker_holder[j].area ) {\r
+                   if( d <marker_holder[i].area / 4 ) {\r
+                       marker_holder[j].area = 0;\r
+                   }\r
+               }else{\r
+                   if( d < marker_holder[j].area / 4 ) {\r
+                       marker_holder[i].area = 0;\r
+                   }\r
+               }\r
+           }\r
+       }\r
+       //みつかったマーカーを整理する。\r
+       int l_array_num=0;\r
+       //エリアが0のマーカーを外した配列を作って、その数もついでに計算\r
+       for(i=0;i<marker_holder_num;i++){\r
+           if(marker_holder[i].area==0.0){\r
+               continue;\r
+           }\r
+           marker_array[l_array_num]=marker_holder[i];\r
+           l_array_num++;\r
+       }\r
+       //マーカー個数を更新\r
+       this.marker_array_num=l_array_num;\r
+    }    \r
+}
\ No newline at end of file
index 8a3819c..6b2acad 100644 (file)
@@ -45,6 +45,11 @@ import jp.nyatla.nyartoolkit.NyARException;
  *\r
  */\r
 public class NyARMat{\r
+    /**\r
+     * 配列サイズと行列サイズは必ずしも一致しないことに注意\r
+     * 返された配列のサイズを行列の大きさとして使わないこと!\r
+     * \r
+     */\r
     private double[][] m;\r
     private int clm,row;\r
     public NyARMat(int i_row,int i_clm)\r
@@ -53,6 +58,24 @@ public class NyARMat{
        clm=i_clm;\r
        row=i_row;\r
     }\r
+    /**\r
+     * i_row x i_clmサイズの行列を格納できるように行列サイズを変更します。\r
+     * 実行後、行列の各値は不定になります。\r
+     * @param i_row\r
+     * @param i_clm\r
+     */\r
+    public void realloc(int i_row,int i_clm)\r
+    {\r
+       if(i_row<=this.m.length && i_clm<=this.m[0].length)\r
+       {\r
+           //十分な配列があれば何もしない。\r
+       }else{\r
+           //不十分なら取り直す。\r
+           m=new double[i_row][i_clm];\r
+       }\r
+        this.clm=i_clm;\r
+        this.row=i_row;\r
+    }\r
     public int getClm()\r
     {\r
        return clm;\r
@@ -66,63 +89,69 @@ public class NyARMat{
      */\r
     public void zeroClear()\r
     {\r
-       for(int i=0;i<row;i++){\r
-           for(int i2=0;i2<clm;i2++){\r
+       int i,i2;\r
+       //For順変更OK\r
+       for(i=row-1;i>=0;i--){\r
+           for(i2=clm-1;i2>=0;i2--){\r
                m[i][i2]=0.0;\r
            }\r
        }\r
     }\r
-    public double[] getRowArray(int i_row)\r
-    {\r
-       return m[i_row];\r
-    }\r
+\r
     public double[][] getArray()\r
     {\r
        return m;\r
     }\r
-    public NyARVec getRowVec(int i_row)\r
-    {\r
-       return NyARVec.wrap(m[i_row]);\r
-    }\r
+//    public void getRowVec(int i_row,NyARVec o_vec)\r
+//    {\r
+//     o_vec.set(this.m[i_row],this.clm);\r
+//    }\r
     /**\r
-     * aとbの積をdestに出力する。arMatrixMul()の代替品\r
-     * @param dest\r
+     * aとbの積を自分自身に格納する。arMatrixMul()の代替品\r
      * @param a\r
      * @param b\r
      * @throws NyARException\r
      */\r
-    public static void matrixMul(NyARMat dest, NyARMat a, NyARMat b) throws NyARException\r
+    public void matrixMul(NyARMat a, NyARMat b) throws NyARException\r
     {\r
-       if(a.clm != b.row || dest.row != a.row || dest.clm != b.clm){\r
+       if(a.clm != b.row || this.row != a.row || this.clm != b.clm){\r
            throw new NyARException();\r
        }\r
-       for(int r = 0; r < dest.row; r++){\r
-           for(int c = 0; c < dest.getClm(); c++){\r
-               dest.m[r][c]=0.0;//dest.setARELEM0(r, c,0.0);\r
-               for(int i = 0; i < a.getClm(); i++){\r
-                   dest.m[r][c]+=a.m[r][i]*b.m[i][c];//ARELEM0(dest, r, c) += ARELEM0(a, r, i) * ARELEM0(b, i, c);\r
+       double w;\r
+       int r,c,i;\r
+       double[][] am=a.m,bm=b.m,dm=this.m;\r
+       //For順変更禁止\r
+       for(r = 0; r < this.row; r++){\r
+           for(c = 0; c < this.clm; c++){\r
+               w=0.0;//dest.setARELEM0(r, c,0.0);\r
+               for(i = 0; i < a.clm; i++){\r
+                   w+=am[r][i]*bm[i][c];//ARELEM0(dest, r, c) += ARELEM0(a, r, i) * ARELEM0(b, i, c);\r
                }\r
+               dm[r][c]=w;\r
            }\r
        }\r
     }\r
     private int[] wk_nos_matrixSelfInv=new int[50];\r
+    private final static double matrixSelfInv_epsl=1.0e-10;\r
     /**\r
      * i_targetを逆行列に変換する。arMatrixSelfInv()と、arMatrixSelfInv_minv()関数を合成してあります。\r
+     * OPTIMIZE STEP[485->422]\r
      * @param i_target\r
      * 逆行列にする行列\r
      * @throws NyARException\r
      */\r
     public void matrixSelfInv() throws NyARException\r
     {\r
-       double[][] ap=m;\r
-       int dimen=ap.length;\r
-       double[] wcp,wap,wbp;\r
+       double[][] ap=this.m;\r
+       int dimen=this.row;\r
+       int dimen_1=dimen-1;\r
+       double[] ap_n,ap_ip,ap_i;//wap;\r
        int j,ip,nwork;\r
        int[] nos=wk_nos_matrixSelfInv;//この関数で初期化される。\r
-       double epsl;\r
+       //double epsl;\r
        double p,pbuf,work;\r
 \r
-       epsl = 1.0e-10;         /* Threshold value      */\r
+//     epsl = 1.0e-10;         /* Threshold value      */\r
        /* check size */\r
        switch(dimen){\r
        case 0:\r
@@ -141,20 +170,21 @@ public class NyARMat{
          * ループ内で0初期化していいかが判らない。\r
          */\r
                ip=0;\r
-               int wap_ptr,wbp_ptr;\r
+//             int wap_ptr,wbp_ptr;\r
+       //For順変更禁止\r
         for(int n=0; n<dimen;n++)\r
         {\r
-            wcp =ap[n];//wcp = ap + n * rowa;\r
+            ap_n =ap[n];//wcp = ap + n * rowa;\r
             p=0.0;\r
-            wap_ptr=0;//wap = DoublePointer.wrap(wcp);\r
+//            wap_ptr=0;//wap = DoublePointer.wrap(wcp);\r
             for(int i = n; i<dimen ; i++){//for(i = n, wap = wcp, p = 0.0; i < dimen ; i++, wap += rowa)\r
-               wap=ap[i];\r
-               if( p < ( pbuf = Math.abs(wap[0]))) {\r
+//             wap=ap[i];\r
+               if( p < ( pbuf = Math.abs(ap[i][0]))) {\r
                    p = pbuf;\r
                    ip = i;\r
                }\r
             }\r
-            if (p <= epsl){\r
+            if (p <= matrixSelfInv_epsl){\r
                 return;\r
             }\r
 \r
@@ -162,38 +192,40 @@ public class NyARMat{
             nos[ip]= nos[n];\r
             nos[n] = nwork;\r
             \r
-            wap=ap[ip];\r
-            wbp=wcp;\r
-            wap_ptr=0;\r
-            wbp_ptr=0;\r
+            ap_ip=ap[ip];\r
+//            wbp=ap_n;\r
+//            wap_ptr=0;\r
+//            wbp_ptr=0;\r
             for(j=0; j< dimen ; j++){//for(j = 0, wap = ap + ip * rowa, wbp = wcp; j < dimen ; j++) {\r
-               work = wap[wap_ptr];               //work = *wap;\r
-               wap[wap_ptr]=wbp[wbp_ptr];wap_ptr++;//*wap++ = *wbp;\r
-                wbp[wbp_ptr]=work;wbp_ptr++;     //*wbp++ = work;\r
+               work = ap_ip[j];               //work = *wap;\r
+               ap_ip[j]=ap_n[j];\r
+//             wap_ptr++;//*wap++ = *wbp;\r
+               ap_n[j]=work;\r
+//                wbp_ptr++;     //*wbp++ = work;\r
             }\r
             \r
-            wap=wcp;\r
-            wap_ptr=0;\r
-            work=wcp[0];\r
-            for(j = 1; j < dimen ; j++){//for(j = 1, wap = wcp, work = *wcp; j < dimen ; j++, wap++)\r
-               wap[wap_ptr]=wap[wap_ptr+1]/work;//*wap = *(wap + 1) / work;\r
-               wap_ptr++;\r
+//            wap=ap_n;\r
+//            wap_ptr=0;\r
+            work=ap_n[0];\r
+            for(j = 0; j < dimen_1 ; j++){//for(j = 1, wap = wcp, work = *wcp; j < dimen ; j++, wap++)\r
+               ap_n[j]=ap_n[j+1]/work;//*wap = *(wap + 1) / work;\r
+//             wap_ptr++;\r
             }\r
-            wap[wap_ptr]=1.0/work;//*wap = 1.0 / work;\r
-\r
+            ap_n[j]=1.0/work;//*wap = 1.0 / work;\r
+//            wbp=ap_n;\r
             for(int i = 0; i < dimen ; i++) {\r
                 if(i != n) {\r
-                    wap =ap[i];//wap = ap + i * rowa;\r
-                    wbp =wcp;\r
-                    wap_ptr=0;\r
-                    wbp_ptr=0;\r
-                    work=wap[0];\r
-                    for(j = 1;j < dimen ; j++){//for(j = 1, wbp = wcp, work = *wap;j < dimen ; j++, wap++, wbp++)\r
-                        wap[wap_ptr]=wap[wap_ptr+1]-work*wbp[wbp_ptr];//wap = *(wap + 1) - work * (*wbp);\r
-                        wap_ptr++;\r
-                        wbp_ptr++;\r
+                    ap_i =ap[i];//wap = ap + i * rowa;\r
+\r
+//                    wap_ptr=0;\r
+//                    wbp_ptr=0;\r
+                    work=ap_i[0];\r
+                    for(j = 0;j < dimen_1 ; j++){//for(j = 1, wbp = wcp, work = *wap;j < dimen ; j++, wap++, wbp++)\r
+                       ap_i[j]=ap_i[j+1]-work*ap_n[j];//wap = *(wap + 1) - work * (*wbp);\r
+//                        wap_ptr++;\r
+//                        wbp_ptr++;\r
                     }\r
-                    wap[wap_ptr]=-work*wbp[wbp_ptr];//*wap = -work * (*wbp);\r
+                    ap_i[j]=-work*ap_n[j];//*wap = -work * (*wbp);\r
                 }\r
             }\r
         }\r
@@ -206,11 +238,11 @@ public class NyARMat{
             }\r
             nos[j] = nos[n];\r
             for(int i = 0; i < dimen ;i++){//for(i = 0, wap = ap + j, wbp = ap + n; i < dimen ;i++, wap += rowa, wbp += rowa) {\r
-               wap=ap[i];\r
-               wbp=ap[i];\r
-                work  =wap[j];//work = *wap;\r
-                wap[j]=wbp[n];//*wap = *wbp;\r
-                wbp[n]=work;//*wbp = work;\r
+               ap_i=ap[i];\r
+//             wbp=ap[i];\r
+                work  =ap_i[j];//work = *wap;\r
+                ap_i[j]=ap_i[n];//*wap = *wbp;\r
+                ap_i[n]=work;//*wbp = work;\r
            }\r
         }\r
         return;\r
@@ -227,6 +259,7 @@ public class NyARMat{
            throw new NyARException();\r
        }\r
        NyARException.trap("未チェックのパス");\r
+       //For順変更禁止\r
        for(int r=0;r< dest.row;r++){\r
            for(int c=0;c<dest.clm;c++){\r
                dest.m[r][c]=source.m[c][r];\r
@@ -243,6 +276,7 @@ public class NyARMat{
            throw new NyARException();\r
        }\r
        NyARException.trap("未チェックのパス");\r
+       //For順変更禁止\r
        for(int r = 0; r < unit.getRow(); r++) {\r
            for(int c = 0; c < unit.getClm(); c++) {\r
                if(r == c) {\r
@@ -254,29 +288,43 @@ public class NyARMat{
        }\r
     }\r
     /**\r
-     * sourceの内容を自身にコピーする。\r
-     * @param dest\r
-     * @param source\r
+     * sourceの内容を自身に複製する。\r
+     * Optimized 2008.04.19\r
+     * @param i_source\r
      * @return\r
      */\r
-    public void matrixDup(NyARMat source) throws NyARException\r
+    public void matrixDup(NyARMat i_source) throws NyARException\r
     {\r
-       if(row != source.row || clm != source.clm)\r
-       {\r
-           throw new NyARException();\r
-       }\r
-       \r
-       for(int r = 0; r < row; r++){\r
-           for(int c = 0; c < clm; c++)\r
+       //自身の配列サイズを相手のそれより大きいことを保障する。\r
+       this.realloc(i_source.row,i_source.clm);\r
+       //内容を転写\r
+       int r,c;\r
+       double[][] src_m,dest_m;\r
+       src_m=i_source.m;\r
+       dest_m=this.m;\r
+       //コピーはFor順を変えてもOK\r
+       for(r = this.row-1; r>=0; r--){\r
+           for(c =this.clm-1;c>=0; c--)\r
            {\r
-               m[r][c]=source.m[r][c];\r
+               dest_m[r][c]=src_m[r][c];\r
            }\r
        }\r
     }\r
     public NyARMat matrixAllocDup() throws NyARException\r
     {\r
-       NyARMat result=new NyARMat(row,clm);\r
-       result.matrixDup(this);\r
+       NyARMat result=new NyARMat(this.row,this.clm);\r
+       //コピー\r
+       int r,c;\r
+       double[][] dest_m,src_m;\r
+       dest_m=result.m;\r
+       src_m =this.m;\r
+       //コピーはFor順を変えてもOK\r
+       for(r = this.row-1; r>=0; r--){\r
+           for(c =this.clm-1;c>=0; c--)\r
+           {\r
+               dest_m[r][c]=src_m[r][c];\r
+           }\r
+       }\r
        return result;\r
     }    \r
     /**\r
@@ -341,41 +389,39 @@ public class NyARMat{
     private final static double        PCA_VZERO=1e-16;        //#define     VZERO           1e-16\r
     /**\r
      * static int EX( ARMat *input, ARVec *mean )の代替関数\r
+     * Optimize:STEP:[144->110]\r
      * @param input\r
      * @param mean\r
      * @return\r
      * @throws NyARException\r
      */\r
-    private static void PCA_EX(NyARMat input, NyARVec mean) throws NyARException\r
+    private void PCA_EX(NyARVec mean) throws NyARException\r
     {\r
-        double[] v;\r
-\r
-        int     row, clm;\r
-        \r
-        row = input.row;\r
-        clm = input.clm;\r
-        if(row <= 0 || clm <= 0){\r
+       int lrow,lclm;\r
+       int i,i2;\r
+       lrow = this.row;\r
+       lclm = this.clm;\r
+       double lm[][]=this.m;\r
+       \r
+       if(lrow <= 0 || lclm <= 0){\r
            throw new NyARException();\r
-        }\r
-        if( mean.getClm() != clm ){\r
+       }\r
+       if( mean.getClm() != lclm ){\r
            throw new NyARException();\r
-        }\r
-        double[] mean_array=mean.getArray();\r
-        for(int i = 0; i < clm; i++ ){\r
-            mean_array[i]=0.0;//mean->v[i] = 0.0;\r
-        }\r
-        \r
-        v=mean.getArray();\r
-        for(int i = 0; i < row; i++ ) {\r
-            for(int j = 0; j < clm; j++ ){\r
-                //*(v++) += *(m++);\r
-                v[j]+=input.m[i][j];\r
-            }\r
-        }\r
-        \r
-        for(int i = 0; i < clm; i++ ){\r
-        mean_array[i]/=row;//mean->v[i] /= row;\r
-        }\r
+       }\r
+//     double[] mean_array=mean.getArray();\r
+//     mean.zeroClear();\r
+       final double[] mean_array=mean.getArray();\r
+       double w;\r
+       //For順変更禁止\r
+        for(i2=0;i2<lclm;i2++){\r
+            w=0.0;\r
+            for(i=0;i<lrow;i++){\r
+               //*(v++) += *(m++);\r
+               w+=lm[i][i2];\r
+           }\r
+           mean_array[i2]=w/lrow;//mean->v[i] /= row;\r
+       }\r
     }\r
     /**\r
      * static int CENTER( ARMat *inout, ARVec *mean )の代替関数\r
@@ -427,12 +473,12 @@ public class NyARMat{
         for(int i = 0; i < row; i++ ) {\r
             for(int j = 0; j < row; j++ ) {\r
                 if( j < i ) {\r
-                    NyARException.trap("未チェックのパス");{\r
+                    NyARException.trap("未チェックのパス");\r
                     output.m[i][j]=output.m[j][i];//*out = output->m[j*row+i];\r
-                   }\r
                 }else{\r
-                    in1=input.getRowArray(i);//in1 = &(input->m[clm*i]);\r
-                    in2=input.getRowArray(j);//in2 = &(input->m[clm*j]);\r
+                    NyARException.trap("未チェックのパス");\r
+                    in1=input.m[i];//input.getRowArray(i);//in1 = &(input->m[clm*i]);\r
+                    in2=input.m[j];//input.getRowArray(j);//in2 = &(input->m[clm*j]);\r
                     output.m[i][j]=0;//*out = 0.0;\r
                     for(int k = 0; k < clm; k++ ){\r
                         output.m[i][j]+=(in1[k]*in2[k]);//*out += *(in1++) * *(in2++);\r
@@ -444,148 +490,165 @@ public class NyARMat{
     }\r
     /**\r
      * static int xt_by_x( ARMat *input, ARMat *output )の代替関数\r
+     * Optimize:2008.04.19\r
      * @param input\r
-     * @param output\r
+     * @param i_output\r
      * @throws NyARException\r
      */\r
-    private static void PCA_xt_by_x(NyARMat input, NyARMat output) throws NyARException\r
+    private static void PCA_xt_by_x(NyARMat input, NyARMat i_output) throws NyARException\r
     {\r
         double[] in;\r
         int     row, clm;\r
     \r
         row = input.row;\r
         clm = input.clm;\r
-        if(output.row!= clm || output.clm != clm ){\r
+        if(i_output.row!= clm || i_output.clm != clm ){\r
            throw new NyARException();\r
         }\r
-    \r
+        \r
+        int k,j;\r
+        double[][] out_m=i_output.m;\r
+        double w;\r
         for(int i = 0; i < clm; i++ ) {\r
-            for(int j = 0; j < clm; j++ ) {\r
+            for(j = 0; j < clm; j++ ) {\r
                 if( j < i ) {\r
-                   output.m[i][j]=output.m[j][i];//*out = output->m[j*clm+i];\r
+                    out_m[i][j]=out_m[j][i];//*out = output->m[j*clm+i];\r
                 }else{\r
-                    output.m[i][j]=0.0;//*out = 0.0;\r
-                    for(int k = 0; k < row; k++ ){\r
-                        in=input.getRowArray(k);\r
-                        output.m[i][j]+=(in[i]*in[j]);//*out += *in1 * *in2;\r
+                    w=0.0;//*out = 0.0;\r
+                    for(k = 0; k < row; k++ ){\r
+                        in=input.m[k];//in=input.getRowArray(k);\r
+                        w+=(in[i]*in[j]);//*out += *in1 * *in2;\r
                     }\r
+                    out_m[i][j]=w;\r
                 }\r
             }\r
         }\r
     }\r
+    private final NyARVec wk_PCA_QRM_ev=new NyARVec(1);\r
     /**\r
      * static int QRM( ARMat *a, ARVec *dv )の代替関数\r
      * @param a\r
      * @param dv\r
      * @throws NyARException\r
      */\r
-    private static void PCA_QRM(NyARMat a, NyARVec dv) throws NyARException\r
+    private void PCA_QRM(NyARVec dv) throws NyARException\r
     {\r
-        double  w, t, s, x, y, c;\r
-        int     dim, iter;\r
-        double[] dv_array=dv.getArray();\r
-        \r
-        dim = a.row;\r
-        if( dim != a.clm || dim < 2 ){\r
+       double  w, t, s, x, y, c;\r
+       int     dim, iter;\r
+       double[] dv_array=dv.getArray();\r
+\r
+       dim = this.row;\r
+       if( dim != this.clm || dim < 2 ){\r
            throw new NyARException();\r
-        }\r
-        if( dv.getClm() != dim ){\r
+       }\r
+       if( dv.getClm() != dim ){\r
            throw new NyARException();\r
-        }\r
-    \r
-        NyARVec ev = new NyARVec( dim );\r
-        double[] ev_array=ev.getArray();\r
-        if( ev == null ){\r
+       }\r
+\r
+       NyARVec ev = this.wk_PCA_QRM_ev;\r
+       ev.realloc(dim);\r
+       double[] ev_array=ev.getArray();\r
+       if( ev == null ){\r
            throw new NyARException();\r
-        }\r
+       }\r
 \r
-        NyARVec.vecTridiagonalize(a,dv,ev,1);\r
-    \r
-        ev_array[0]=0.0;//ev->v[0] = 0.0;\r
-        for(int h = dim-1; h > 0; h-- ) {\r
-            int j = h;\r
-            while(j>0 && Math.abs(ev_array[j]) > PCA_EPS*(Math.abs(dv_array[j-1])+Math.abs(dv_array[j]))){// while(j>0 && fabs(ev->v[j]) > EPS*(fabs(dv->v[j-1])+fabs(dv->v[j]))) j--;\r
-                j--;\r
-            }\r
-            if( j == h ){\r
-                continue;\r
-            }\r
-            iter = 0;\r
-            do{\r
-                iter++;\r
-                if( iter > PCA_MAX_ITER ){\r
-                       break;\r
-                }\r
-                w = (dv_array[h-1] - dv_array[h]) / 2;//w = (dv->v[h-1] - dv->v[h]) / 2;//ここ?\r
-                t = ev_array[h] * ev_array[h];//t = ev->v[h] * ev->v[h];\r
-                s = Math.sqrt(w*w+t);\r
-                if( w < 0 ){\r
-                       s = -s;\r
-                }\r
-                x=dv_array[j] - dv_array[h] + t/(w+s);//x = dv->v[j] - dv->v[h] + t/(w+s);\r
-                y=ev_array[j+1];//y = ev->v[j+1];\r
-                for(int k = j; k < h; k++ ){\r
-                    if( Math.abs(x) >= Math.abs(y)){\r
-                        if( Math.abs(x) > PCA_VZERO ) {\r
-                       t = -y / x;\r
-                       c = 1 / Math.sqrt(t*t+1);\r
-                       s = t * c;\r
-                        }else{\r
-                       c = 1.0;\r
-                       s = 0.0;\r
-                        }\r
-                    }else{\r
-                        t = -x / y;\r
-                        s = 1.0 / Math.sqrt(t*t+1);\r
-                        c = t * s;\r
-                    }\r
-                    w = dv_array[k] - dv_array[k+1];//w = dv->v[k] - dv->v[k+1];\r
-                    t = (w * s + 2 * c * ev_array[k+1]) * s;//t = (w * s + 2 * c * ev->v[k+1]) * s;\r
-                    dv_array[k]-=t;//dv->v[k]   -= t;\r
-                    dv_array[k+1]+=t;//dv->v[k+1] += t;\r
-                    if( k > j){\r
-                        NyARException.trap("未チェックパス");{\r
-                        ev_array[k]=c * ev_array[k] - s * y;//ev->v[k] = c * ev->v[k] - s * y;\r
-                        }\r
-                    }\r
-                    ev_array[k+1]+=s * (c * w - 2 * s * ev_array[k+1]);//ev->v[k+1] += s * (c * w - 2 * s * ev->v[k+1]);\r
-    \r
-                    for(int i = 0; i < dim; i++ ){\r
-                        x = a.m[k][i];//x = a->m[k*dim+i];\r
-                        y = a.m[k+1][i];//y = a->m[(k+1)*dim+i];\r
-                        a.m[k][i]=c * x - s * y;//a->m[k*dim+i]     = c * x - s * y;\r
-                        a.m[k+1][i]=s * x + c * y;//a->m[(k+1)*dim+i] = s * x + c * y;\r
-                    }\r
-                    if( k < h-1 ) {\r
-                        NyARException.trap("未チェックパス");{\r
-                        x = ev_array[k+1];//x = ev->v[k+1];\r
-                        y =-s*ev_array[k+2];//y = -s * ev->v[k+2];\r
-                        ev_array[k+2]*=c;//ev->v[k+2] *= c;\r
-                        }\r
-                    }\r
-                }\r
-            }while(Math.abs(ev_array[h]) > PCA_EPS*(Math.abs(dv_array[h-1])+Math.abs(dv_array[h])));\r
-        }\r
-        double[] v1,v2;\r
-        for(int k = 0; k < dim-1; k++ ) {\r
-            int h = k;\r
-            t=dv_array[h];//t = dv->v[h];\r
-            for(int i = k+1; i < dim; i++ ){\r
-                if(dv_array[i] > t ){//if( dv->v[i] > t ) {\r
-                    h = i;\r
-                    t=dv_array[h];//t = dv->v[h];\r
-                }\r
-            }\r
-            dv_array[h]=dv_array[k];//dv->v[h] = dv->v[k];\r
-            dv_array[k]=t;//dv->v[k] = t;\r
-            v1=a.getRowArray(h);//v1 = &(a->m[h*dim]);\r
-            v2=a.getRowArray(k);//v2 = &(a->m[k*dim]);\r
-            for(int i = 0; i < dim; i++ ) {\r
-                w=v1[i];//w = *v1;\r
-                v1[i]=v2[i];//*v1 = *v2;\r
-                v2[i]=w;//*v2 = w;\r
-            }\r
-        }\r
+       this.vecTridiagonalize(dv,ev,1);\r
+\r
+       ev_array[0]=0.0;//ev->v[0] = 0.0;\r
+       for(int h = dim-1; h > 0; h-- ) {\r
+           int j = h;\r
+           while(j>0 && Math.abs(ev_array[j]) > PCA_EPS*(Math.abs(dv_array[j-1])+Math.abs(dv_array[j]))){// while(j>0 && fabs(ev->v[j]) > EPS*(fabs(dv->v[j-1])+fabs(dv->v[j]))) j--;\r
+               j--;\r
+           }\r
+           if( j == h ){\r
+               continue;\r
+           }\r
+           iter = 0;\r
+           do{\r
+               iter++;\r
+               if( iter > PCA_MAX_ITER ){\r
+                   break;\r
+               }\r
+               w = (dv_array[h-1] - dv_array[h]) / 2;//w = (dv->v[h-1] - dv->v[h]) / 2;//ここ?\r
+               t = ev_array[h] * ev_array[h];//t = ev->v[h] * ev->v[h];\r
+               s = Math.sqrt(w*w+t);\r
+               if( w < 0 ){\r
+                   s = -s;\r
+               }\r
+               x=dv_array[j] - dv_array[h] + t/(w+s);//x = dv->v[j] - dv->v[h] + t/(w+s);\r
+               y=ev_array[j+1];//y = ev->v[j+1];\r
+               for(int k = j; k < h; k++ ){\r
+                   if( Math.abs(x) >= Math.abs(y)){\r
+                       if( Math.abs(x) > PCA_VZERO ) {\r
+                           t = -y / x;\r
+                           c = 1 / Math.sqrt(t*t+1);\r
+                           s = t * c;\r
+                       }else{\r
+                           c = 1.0;\r
+                           s = 0.0;\r
+                       }\r
+                   }else{\r
+                       t = -x / y;\r
+                       s = 1.0 / Math.sqrt(t*t+1);\r
+                       c = t * s;\r
+                   }\r
+                   w = dv_array[k] - dv_array[k+1];//w = dv->v[k] - dv->v[k+1];\r
+                   t = (w * s + 2 * c * ev_array[k+1]) * s;//t = (w * s + 2 * c * ev->v[k+1]) * s;\r
+                   dv_array[k]-=t;//dv->v[k]   -= t;\r
+                   dv_array[k+1]+=t;//dv->v[k+1] += t;\r
+                   if( k > j){\r
+                       NyARException.trap("未チェックパス");{\r
+                           ev_array[k]=c * ev_array[k] - s * y;//ev->v[k] = c * ev->v[k] - s * y;\r
+                       }\r
+                   }\r
+                   ev_array[k+1]+=s * (c * w - 2 * s * ev_array[k+1]);//ev->v[k+1] += s * (c * w - 2 * s * ev->v[k+1]);\r
+\r
+                   for(int i = 0; i < dim; i++ ){\r
+                       x = this.m[k][i];//x = a->m[k*dim+i];\r
+                       y = this.m[k+1][i];//y = a->m[(k+1)*dim+i];\r
+                       this.m[k][i]=c * x - s * y;//a->m[k*dim+i]     = c * x - s * y;\r
+                       this.m[k+1][i]=s * x + c * y;//a->m[(k+1)*dim+i] = s * x + c * y;\r
+                   }\r
+                   if( k < h-1 ) {\r
+                       NyARException.trap("未チェックパス");{\r
+                           x = ev_array[k+1];//x = ev->v[k+1];\r
+                           y =-s*ev_array[k+2];//y = -s * ev->v[k+2];\r
+                           ev_array[k+2]*=c;//ev->v[k+2] *= c;\r
+                       }\r
+                   }\r
+               }\r
+           }while(Math.abs(ev_array[h]) > PCA_EPS*(Math.abs(dv_array[h-1])+Math.abs(dv_array[h])));\r
+       }\r
+       for(int k = 0; k < dim-1; k++ ) {\r
+           int h = k;\r
+           t=dv_array[h];//t = dv->v[h];\r
+           for(int i = k+1; i < dim; i++ ){\r
+               if(dv_array[i] > t ){//if( dv->v[i] > t ) {\r
+                   h = i;\r
+                   t=dv_array[h];//t = dv->v[h];\r
+               }\r
+           }\r
+           dv_array[h]=dv_array[k];//dv->v[h] = dv->v[k];\r
+           dv_array[k]=t;//dv->v[k] = t;\r
+           this.flipRow(h,k);\r
+       }\r
+    }\r
+    /**\r
+     * i_row_1番目の行と、i_row_2番目の行を入れ替える。\r
+     * @param i_row_1\r
+     * @param i_row_2\r
+     */\r
+    private void flipRow(int i_row_1,int i_row_2)\r
+    {\r
+       int i;\r
+       double w;\r
+       double[] r1=this.m[i_row_1],r2=this.m[i_row_2];\r
+       //For順変更OK\r
+       for(i=clm-1;i>=0;i--){\r
+           w=r1[i];\r
+           r1[i]=r2[i];\r
+           r2[i]=w;\r
+       }\r
     }\r
     /**\r
      * static int EV_create( ARMat *input, ARMat *u, ARMat *output, ARVec *ev )の代替関数\r
@@ -617,8 +680,9 @@ public class NyARMat{
         double[]  m1,ev_array;\r
         double  sum, work;\r
     \r
-        m =output.getArray();//m = output->m;\r
-        in=input.getArray();\r
+        NyARException.trap("未チェックのパス");\r
+        m =output.m;//m = output->m;\r
+        in=input.m;\r
         int i;\r
         ev_array=ev.getArray();\r
         for(i = 0; i < row; i++ ) {\r
@@ -630,7 +694,7 @@ public class NyARMat{
             work = 1 / Math.sqrt(Math.abs(ev_array[i]));//work = 1 / sqrt(fabs(ev->v[i]));\r
             for(int j = 0; j < clm; j++ ) {\r
                 sum = 0.0;\r
-                m1=u.getRowArray(i);//m1 = &(u->m[i*row]);\r
+                m1=u.m[i];//m1 = &(u->m[i*row]);\r
     //             m2=input.getPointer(j);//m2 = &(input->m[j]);\r
                 for(int k = 0; k < row; k++ ) {\r
                     sum+=m1[k]+in[k][j];//sum += *m1 * *m2;\r
@@ -653,46 +717,61 @@ public class NyARMat{
             }\r
         }\r
     }\r
-    /*static int PCA( ARMat *input, ARMat *output, ARVec *ev )*/\r
-    private static void PCA_PCA(NyARMat input, NyARMat output, NyARVec ev) throws NyARException\r
+    private NyARMat wk_PCA_PCA_u=null;\r
+    /**\r
+     * static int PCA( ARMat *input, ARMat *output, ARVec *ev )\r
+     * \r
+     * @param output\r
+     * @param o_ev\r
+     * @throws NyARException\r
+     */\r
+    private void PCA_PCA(NyARMat o_output, NyARVec o_ev) throws NyARException\r
     {\r
-        NyARMat    u;\r
-        int     row, clm, min;\r
-        double[] ev_array=ev.getArray();\r
+        \r
+        int l_row, l_clm, min;\r
+        double[] ev_array=o_ev.getArray();\r
 \r
-        row =input.row;//row = input->row;\r
-        clm =input.clm;//clm = input->clm;\r
-        min =(clm < row)? clm: row;\r
-        if( row < 2 || clm < 2 ){\r
+        l_row =this.row;//row = input->row;\r
+        l_clm =this.clm;//clm = input->clm;\r
+        min =(l_clm < l_row)? l_clm: l_row;\r
+        if( l_row < 2 || l_clm < 2 ){\r
            throw new NyARException();\r
         }\r
-        if( output.clm != input.clm){//if( output->clm != input->clm ){\r
+        if( o_output.clm != this.clm){//if( output->clm != input->clm ){\r
            throw new NyARException();\r
         }\r
-        if( output.row!= min ){//if( output->row != min ){\r
+        if( o_output.row!= min ){//if( output->row != min ){\r
            throw new NyARException();\r
         }\r
-        if( ev.getClm() != min ){//if( ev->clm != min ){\r
+        if( o_ev.getClm() != min ){//if( ev->clm != min ){\r
            throw new NyARException();\r
         }\r
-        u =new NyARMat( min, min );\r
+        \r
+        NyARMat u;//        u =new NyARMat( min, min );\r
+        if(this.wk_PCA_PCA_u==null){\r
+            u=new NyARMat( min, min );\r
+            this.wk_PCA_PCA_u=u;\r
+        }else{\r
+            u=this.wk_PCA_PCA_u;\r
+            u.realloc(min,min);\r
+        }\r
+        \r
     \r
-        if( row < clm ){\r
+        if( l_row < l_clm ){\r
             NyARException.trap("未チェックのパス");\r
-            PCA_x_by_xt( input, u );//if(x_by_xt( input, u ) < 0 ) {\r
+            PCA_x_by_xt( this, u );//if(x_by_xt( input, u ) < 0 ) {\r
         }else{\r
-            PCA_xt_by_x( input, u );//if(xt_by_x( input, u ) < 0 ) {\r
+            PCA_xt_by_x( this, u );//if(xt_by_x( input, u ) < 0 ) {\r
         }\r
-        PCA_QRM( u, ev );\r
+        u.PCA_QRM(o_ev);\r
 \r
         double[][] m1,m2;\r
-        if( row < clm ) {\r
-            NyARException.trap("未チェックのパス");{\r
-            PCA_EV_create( input, u, output, ev );\r
-            }\r
+        if( l_row < l_clm ) {\r
+            NyARException.trap("未チェックのパス");\r
+            PCA_EV_create( this, u, o_output, o_ev );\r
         }else{\r
             m1=u.m;//m1 = u->m;\r
-            m2=output.m;//m2 = output->m;\r
+            m2=o_output.m;//m2 = output->m;\r
             int i;\r
             for(i = 0; i < min; i++){\r
                if( ev_array[i] < PCA_VZERO){//if( ev->v[i] < VZERO ){\r
@@ -711,53 +790,76 @@ public class NyARMat{
             }\r
         }\r
     }\r
-       \r
-    /*int    arMatrixPCA( ARMat *input, ARMat *evec, ARVec *ev, ARVec *mean );*/\r
-    public static void matrixPCA(NyARMat input, NyARMat evec, NyARVec ev, NyARVec mean) throws NyARException\r
+    private NyARMat wk_work_matrixPCA=null;\r
+    /**\r
+     * int    arMatrixPCA( ARMat *input, ARMat *evec, ARVec *ev, ARVec *mean );\r
+     * 関数の置き換え。input引数がthisになる。\r
+     * Optimize:2008.04.19\r
+     * @param o_evec\r
+     * @param o_ev\r
+     * \r
+     * @param mean\r
+     * @throws NyARException\r
+     */    \r
+    public void matrixPCA(NyARMat o_evec, NyARVec o_ev, NyARVec mean) throws NyARException\r
     {\r
-        NyARMat   work;\r
         double srow, sum;\r
-        int     row, clm;\r
+        int     l_row, l_clm;\r
         int     check;\r
-    \r
-        row=input.row;//row = input->row;\r
-        clm=input.clm;//clm = input->clm;\r
-        check = (row < clm)? row: clm;\r
-        if( row < 2 || clm < 2 ){\r
+        \r
+\r
+        l_row=this.row;//row = input->row;\r
+        l_clm=this.clm;//clm = input->clm;\r
+        check = (l_row < l_clm)? l_row: l_clm;\r
+        if( l_row < 2 || l_clm < 2 ){\r
             throw new NyARException();\r
         }\r
-        if( evec.clm != input.clm || evec.row != check ){//if( evec->clm != input->clm || evec->row != check ){\r
+        if( o_evec.clm != l_clm || o_evec.row != check ){//if( evec->clm != input->clm || evec->row != check ){\r
             throw new NyARException();\r
         }\r
-        if( ev.getClm()   != check ){//if( ev->clm   != check ){\r
+        if( o_ev.getClm()   != check ){//if( ev->clm   != check ){\r
             throw new NyARException();\r
         }\r
-        if( mean.getClm() != input.clm){//if( mean->clm != input->clm ){\r
+        if( mean.getClm() != l_clm){//if( mean->clm != input->clm ){\r
             throw new NyARException();\r
         }\r
+\r
+        //自分の内容をワークにコピー(高速化の為に、1度作ったインスタンスは使いまわす)\r
+        NyARMat work;\r
+        if(this.wk_work_matrixPCA==null){\r
+            work=this.matrixAllocDup();\r
+            this.wk_work_matrixPCA=work;\r
+        }else{\r
+            work=this.wk_work_matrixPCA;\r
+            work.matrixDup(this);//arMatrixAllocDup( input );work = arMatrixAllocDup( input );\r
+        }\r
+        \r
     \r
-        work =input.matrixAllocDup();//arMatrixAllocDup( input );work = arMatrixAllocDup( input );\r
-    \r
-        srow = Math.sqrt((double)row);\r
-        PCA_EX( work, mean );\r
+        srow = Math.sqrt((double)l_row);\r
+        work.PCA_EX(mean );\r
 \r
         PCA_CENTER(work,mean);\r
 \r
 \r
-        for(int i=0; i<row; i++){\r
-            for(int j=0;j<clm;j++){\r
+        int i,j;\r
+       //For順変更OK\r
+        for(i=0; i<l_row; i++){\r
+            for(j=0;j<l_clm;j++){\r
                work.m[i][j]/=srow;//work->m[i] /= srow;\r
             }\r
         }\r
     \r
-        PCA_PCA( work, evec, ev );\r
+        work.PCA_PCA(o_evec, o_ev);\r
     \r
         sum = 0.0;\r
-        double[] ev_array=ev.getArray();\r
-        for(int i = 0; i < ev.getClm(); i++ ){//for(int i = 0; i < ev->clm; i++ ){\r
+        double[] ev_array=o_ev.getArray();\r
+        int ev_clm=o_ev.getClm();\r
+       //For順変更禁止\r
+        for(i=0;i<ev_clm;i++){//for(int i = 0; i < ev->clm; i++ ){\r
                sum+=ev_array[i];//sum += ev->v[i];\r
         }\r
-        for(int i = 0; i < ev.getClm(); i++ ){//for(int i = 0; i < ev->clm; i++ ){\r
+       //For順変更禁止\r
+        for(i=0;i<ev_clm;i++){//for(int i = 0; i < ev->clm; i++ ){\r
                ev_array[i]/=sum;//ev->v[i] /= sum;\r
         }\r
     }\r
@@ -789,7 +891,7 @@ public class NyARMat{
        work =input.matrixAllocDup();\r
 \r
         NyARException.trap("未チェックパス");\r
-        PCA_PCA( work, evec, ev );//rval = PCA( work, evec, ev );\r
+        work.PCA_PCA(evec, ev );//rval = PCA( work, evec, ev );\r
         sum = 0.0;\r
         double[] ev_array=ev.getArray();\r
         for(int i = 0; i < ev.getClm(); i++ ){//for( i = 0; i < ev->clm; i++ ){\r
@@ -807,7 +909,7 @@ public class NyARMat{
        NyARException.trap("未チェックのパス");\r
        NyARMat dest=new NyARMat(a.row, b.clm);\r
        NyARException.trap("未チェックのパス");\r
-       matrixMul(dest, a, b);\r
+       dest.matrixMul(a, b);\r
        return dest;\r
     }\r
     /*static double mdet(double *ap, int dimen, int rowa)*/\r
@@ -860,4 +962,122 @@ public class NyARMat{
        }\r
        return Det_mdet(m.getArray(), m.row, m.clm);//return mdet(m->m, m->row, m->row);\r
     }\r
+    private final NyARVec wk_vecTridiagonalize_vec=new NyARVec(0);\r
+    private final NyARVec wk_vecTridiagonalize_vec2=new NyARVec(0);\r
+    /**\r
+     * arVecTridiagonalize関数の代替品\r
+     * a,d,e間で演算をしてる。何をどうしているかはさっぱりさっぱり\r
+     * @param a\r
+     * @param d\r
+     * @param e\r
+     * @param i_e_start\r
+     * 演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる)\r
+     * @return\r
+     * @throws NyARException\r
+     */\r
+    private void vecTridiagonalize(NyARVec d, NyARVec e,int i_e_start) throws NyARException\r
+    {\r
+       NyARVec vec=wk_vecTridiagonalize_vec;\r
+       //double[][] a_array=a.getArray();\r
+       double  s, t, p, q;\r
+       int     dim;\r
+\r
+       if(this.clm!=this.row){//if(a.getClm()!=a.getRow()){\r
+           throw new NyARException();\r
+       }\r
+       if(this.clm != d.getClm()){//if(a.getClm() != d.clm){\r
+           throw new NyARException();\r
+       }\r
+       if(this.clm != e.getClm()){//if(a.getClm() != e.clm){\r
+           throw new NyARException();\r
+       }\r
+       dim = this.getClm();\r
+       \r
+       double[] d_vec,e_vec;\r
+       d_vec=d.getArray();\r
+       e_vec=e.getArray();\r
+       double[] a_vec_k;\r
+\r
+       for(int k = 0; k < dim-2; k++ ){\r
+           \r
+           a_vec_k=this.m[k];\r
+           vec.setNewArray(a_vec_k,clm);//vec=this.getRowVec(k);//double[] vec_array=vec.getArray();\r
+           NyARException.trap("未チェックパス"); \r
+           d_vec[k]=a_vec_k[k];//d.v[k]=vec.v[k];//d.set(k,v.get(k));    //d->v[k] = v[k];\r
+\r
+           //wv1.clm = dim-k-1;\r
+           //wv1.v = &(v[k+1]);\r
+           NyARException.trap("未チェックパス"); \r
+           e_vec[k+i_e_start]=vec.vecHousehold(k+1);//e.v[k+i_e_start]=vec.vecHousehold(k+1);//e->v[k] = arVecHousehold(&wv1);\r
+           if(e_vec[k+i_e_start]== 0.0 ){//if(e.v[k+i_e_start]== 0.0 ){//if(e.v[k+i_e_start]== 0.0 ){\r
+               continue;\r
+           }\r
+\r
+           for(int i = k+1; i < dim; i++ ){\r
+               s = 0.0;\r
+               for(int j = k+1; j < i; j++ ) {\r
+                   NyARException.trap("未チェックのパス");\r
+                   s += this.m[j][i] * a_vec_k[j];//s += a_array[j][i] * vec.v[j];//s += a.get(j*dim+i) * v.get(j);//s += a->m[j*dim+i] * v[j];\r
+               }\r
+               for(int j = i; j < dim; j++ ) {\r
+                   NyARException.trap("未チェックのパス");\r
+                   s += this.m[i][j] * a_vec_k[j];//s += a_array[i][j] * vec.v[j];//s += a.get(i*dim+j) * v.get(j);//s += a->m[i*dim+j] * v[j];\r
+               }\r
+               NyARException.trap("未チェックのパス");\r
+               d_vec[i]=s;//d.v[i]=s;//d->v[i] = s;\r
+           }\r
+        \r
+\r
+           //wv1.clm = wv2.clm = dim-k-1;\r
+           //wv1.v = &(v[k+1]);\r
+           //wv2.v = &(d->v[k+1]);\r
+           a_vec_k=this.m[k];\r
+           vec.setNewArray(a_vec_k,clm);//vec=this.getRowVec(k);\r
+//         vec_array=vec.getArray();\r
+           NyARException.trap("未チェックパス"); \r
+           t = vec.vecInnerproduct(d,k+1)/ 2;\r
+           for(int i = dim-1; i > k; i-- ) {\r
+               NyARException.trap("未チェックパス"); \r
+               p = a_vec_k[i];//p = v.get(i);//p = v[i];\r
+               d_vec[i]-=t*p;q=d_vec[i];//d.v[i]-=t*p;q=d.v[i];//q = d->v[i] -= t*p;\r
+               for(int j = i; j < dim; j++ ){\r
+                   NyARException.trap("未チェックパス"); \r
+                   this.m[i][j]-=p*(d_vec[j] + q*a_vec_k[j]);//a.m[i][j]-=p*(d.v[j] + q*vec.v[j]);//a->m[i*dim+j] -= p*(d->v[j]) + q*v[j];\r
+               }\r
+           }\r
+       }\r
+\r
+       if( dim >= 2) {\r
+           d_vec[dim-2]=this.m[dim-2][dim-2];//d.v[dim-2]=a.m[dim-2][dim-2];//d->v[dim-2] = a->m[(dim-2)*dim+(dim-2)];\r
+           e_vec[dim-2+i_e_start]=this.m[dim-2][dim-1];//e.v[dim-2+i_e_start]=a.m[dim-2][dim-1];//e->v[dim-2] = a->m[(dim-2)*dim+(dim-1)];\r
+       }\r
+\r
+       if( dim >= 1 ){\r
+           d_vec[dim-1]=this.m[dim-1][dim-1];//d.v[dim-1]=a_array[dim-1][dim-1];//d->v[dim-1] = a->m[(dim-1)*dim+(dim-1)];\r
+       }\r
+       NyARVec vec2=this.wk_vecTridiagonalize_vec2;\r
+       for(int k = dim-1; k >= 0; k--) {\r
+           a_vec_k=this.m[k];\r
+           vec.setNewArray(a_vec_k,clm);//vec=this.getRowVec(k);//v = a.getPointer(k*dim);//v = &(a->m[k*dim]);\r
+           if( k < dim-2 ) {\r
+               for(int i = k+1; i < dim; i++ ){\r
+                   //wv1.clm = wv2.clm = dim-k-1;\r
+                   //wv1.v = &(v[k+1]);\r
+                   //wv2.v = &(a->m[i*dim+k+1]);\r
+                   vec2.setNewArray(this.m[i],clm);//vec2=this.getRowVec(i);\r
+                   \r
+                   t = vec.vecInnerproduct(vec2,k+1);\r
+                   for(int j = k+1; j < dim; j++ ){\r
+                       NyARException.trap("未チェックパス"); \r
+                       this.m[i][j]-=t*a_vec_k[j];//a_array[i][j]-=t*vec.v[j];//a.subValue(i*dim+j,t*v.get(j));//a->m[i*dim+j] -= t * v[j];\r
+                   }\r
+               }\r
+           }\r
+           for(int i = 0; i < dim; i++ ){\r
+               a_vec_k[i]=0.0;//v.set(i,0.0);//v[i] = 0.0;\r
+           }\r
+           a_vec_k[k]=1;//v.set(k,1);//v[k] = 1;\r
+       }\r
+       return;\r
+    }   \r
 }
\ No newline at end of file
index 73a41cc..f9d4014 100644 (file)
@@ -47,8 +47,8 @@ public class NyARParam{
     private static final int SIZE_OF_PARAM_SET=4+4+(3*4*8)+(4*8);\r
     private static final int PD_LOOP = 3;\r
     protected int              xsize, ysize;\r
-    private double[][]         mat=new double[3][4];//Double2dArray    mat=new Double2dArray(3,4);\r
-    private double[]           dist_factor=new double[4];\r
+    private double[]   array34=new double[3*4];//Double2dArray mat=new Double2dArray(3,4);\r
+    private double[]  dist_factor=new double[4];\r
     public int getX()\r
     {\r
        return xsize;\r
@@ -61,9 +61,13 @@ public class NyARParam{
     {\r
        return dist_factor;\r
     }\r
-    public double[][] getMat()\r
+    /**\r
+     * パラメタを格納した[4x3]配列を返します。\r
+     * @return\r
+     */\r
+    public final double[] get34Array()\r
     {\r
-       return mat;\r
+       return array34;\r
     }\r
     /**\r
      * ARToolKit標準ファイルから1個目の設定をロードする。\r
@@ -85,25 +89,26 @@ public class NyARParam{
             i_stream.close();\r
             xsize = new_inst[0].xsize;\r
             ysize = new_inst[0].ysize;\r
-            mat = new_inst[0].mat;\r
+            array34 = new_inst[0].array34;\r
             dist_factor = new_inst[0].dist_factor;\r
         } catch (Exception e) {\r
             throw new NyARException(e);\r
         }\r
     }\r
     /*static double dot( double a1, double a2, double a3,double b1, double b2, double b3 )*/\r
-    private static double dot( double a1, double a2, double a3,double b1, double b2, double b3 )\r
+    private final static double dot( double a1, double a2, double a3,double b1, double b2, double b3 )\r
     {\r
         return( a1 * b1 + a2 * b2 + a3 * b3 );\r
     }\r
     /* static double norm( double a, double b, double c )*/\r
-    private static double norm( double a, double b, double c )\r
+    private final static double norm( double a, double b, double c )\r
     {\r
         return Math.sqrt( a*a + b*b + c*c );\r
     }\r
     /**\r
      * int  arParamDecompMat( double source[3][4], double cpara[3][4], double trans[3][4] );\r
      * 関数の置き換え\r
+     * Optimize STEP[754->665]\r
      * @param o_cpara\r
      * 戻り引数。3x4のマトリクスを指定すること。\r
      * @param o_trans\r
@@ -112,22 +117,32 @@ public class NyARParam{
      */\r
     public void decompMat(NyARMat o_cpara, NyARMat o_trans)\r
     {\r
-       double[][] source=mat;\r
-        double[][] Cpara=new double[3][4];//double    Cpara[3][4];\r
+       double[] source=array34;\r
+        double[] Cpara=new double[3*4];//double    Cpara[3][4];\r
         double    rem1, rem2, rem3;\r
-    \r
-        if(source[2][3]>= 0 ){//if( source[2][3] >= 0 ) {\r
-            for(int r = 0; r < 3; r++ ){\r
-                for(int c = 0; c < 4; c++ ){\r
-                    Cpara[r][c]=source[r][c];//Cpara[r][c] = source[r][c];\r
-                }\r
+        int i;\r
+        if(source[2*4+3]>= 0 ){//if( source[2][3] >= 0 ) {\r
+            //<Optimize>\r
+            //for(int r = 0; r < 3; r++ ){\r
+            //    for(int c = 0; c < 4; c++ ){\r
+            //        Cpara[r][c]=source[r][c];//Cpara[r][c] = source[r][c];\r
+            //    }\r
+            //}\r
+            for(i=0;i<12;i++){\r
+                Cpara[i]=source[i];//Cpara[r][c] = source[r][c];\r
             }\r
+            //</Optimize>\r
         }else {\r
-            for(int r = 0; r < 3; r++ ){\r
-               for(int c = 0; c < 4; c++ ){\r
-                    Cpara[r][c]=-source[r][c];//Cpara[r][c] = -(source[r][c]);\r
-                }\r
+            //<Optimize>\r
+            //for(int r = 0; r < 3; r++ ){\r
+            // for(int c = 0; c < 4; c++ ){\r
+            //        Cpara[r][c]=-source[r][c];//Cpara[r][c] = -(source[r][c]);\r
+            //    }\r
+            //}\r
+            for(i=0;i<12;i++){\r
+                Cpara[i]=source[i];//Cpara[r][c] = source[r][c];\r
             }\r
+            //</Optimize>\r
         }\r
     \r
        double[][] cpara=o_cpara.getArray();\r
@@ -137,33 +152,33 @@ public class NyARParam{
                 cpara[r][c]=0.0;//cpara[r][c] = 0.0;\r
             }\r
         }\r
-        cpara[2][2]=norm(Cpara[2][0],Cpara[2][1], Cpara[2][2]);//cpara[2][2] = norm( Cpara[2][0], Cpara[2][1], Cpara[2][2] );\r
-        trans[2][0]=Cpara[2][0] / cpara[2][2];//trans[2][0] = Cpara[2][0] / cpara[2][2];\r
-        trans[2][1]=Cpara[2][1]/ cpara[2][2];//trans[2][1] = Cpara[2][1] / cpara[2][2];\r
-        trans[2][2]=Cpara[2][2]/ cpara[2][2];//trans[2][2] = Cpara[2][2] / cpara[2][2];\r
-        trans[2][3]=Cpara[2][3] / cpara[2][2];//trans[2][3] = Cpara[2][3] / cpara[2][2];\r
+        cpara[2][2]=norm(Cpara[2*4+0],Cpara[2*4+1], Cpara[2*4+2]);//cpara[2][2] = norm( Cpara[2][0], Cpara[2][1], Cpara[2][2] );\r
+        trans[2][0]=Cpara[2*4+0] / cpara[2][2];//trans[2][0] = Cpara[2][0] / cpara[2][2];\r
+        trans[2][1]=Cpara[2*4+1]/ cpara[2][2];//trans[2][1] = Cpara[2][1] / cpara[2][2];\r
+        trans[2][2]=Cpara[2*4+2]/ cpara[2][2];//trans[2][2] = Cpara[2][2] / cpara[2][2];\r
+        trans[2][3]=Cpara[2*4+3] / cpara[2][2];//trans[2][3] = Cpara[2][3] / cpara[2][2];\r
        \r
-        cpara[1][2]=dot(trans[2][0], trans[2][1], trans[2][2],Cpara[1][0], Cpara[1][1], Cpara[1][2]);//cpara[1][2] = dot( trans[2][0], trans[2][1], trans[2][2],Cpara[1][0], Cpara[1][1], Cpara[1][2] );\r
-        rem1=Cpara[1][0]- cpara[1][2] * trans[2][0];//rem1 = Cpara[1][0] - cpara[1][2] * trans[2][0];\r
-        rem2=Cpara[1][1] - cpara[1][2] * trans[2][1];//rem2 = Cpara[1][1] - cpara[1][2] * trans[2][1];\r
-        rem3=Cpara[1][2] - cpara[1][2] * trans[2][2];//rem3 = Cpara[1][2] - cpara[1][2] * trans[2][2];\r
+        cpara[1][2]=dot(trans[2][0], trans[2][1], trans[2][2],Cpara[1*4+0], Cpara[1*4+1], Cpara[1*4+2]);//cpara[1][2] = dot( trans[2][0], trans[2][1], trans[2][2],Cpara[1][0], Cpara[1][1], Cpara[1][2] );\r
+        rem1=Cpara[1*4+0]- cpara[1][2] * trans[2][0];//rem1 = Cpara[1][0] - cpara[1][2] * trans[2][0];\r
+        rem2=Cpara[1*4+1] - cpara[1][2] * trans[2][1];//rem2 = Cpara[1][1] - cpara[1][2] * trans[2][1];\r
+        rem3=Cpara[1*4+2] - cpara[1][2] * trans[2][2];//rem3 = Cpara[1][2] - cpara[1][2] * trans[2][2];\r
         cpara[1][1]=norm(rem1, rem2, rem3 );//cpara[1][1] = norm( rem1, rem2, rem3 );\r
         trans[1][0]= rem1/cpara[1][1];//trans[1][0] = rem1 / cpara[1][1];\r
         trans[1][1]=rem2/cpara[1][1];//trans[1][1] = rem2 / cpara[1][1];\r
         trans[1][2]=rem3 / cpara[1][1];//trans[1][2] = rem3 / cpara[1][1];\r
     \r
-        cpara[0][2]=dot(trans[2][0],trans[2][1], trans[2][2],Cpara[0][0], Cpara[0][1], Cpara[0][2] );//cpara[0][2] = dot( trans[2][0], trans[2][1], trans[2][2],Cpara[0][0], Cpara[0][1], Cpara[0][2] );\r
-        cpara[0][1]=dot(trans[1][0],trans[1][1], trans[1][2],Cpara[0][0], Cpara[0][1], Cpara[0][2]);//cpara[0][1] = dot( trans[1][0], trans[1][1], trans[1][2],Cpara[0][0], Cpara[0][1], Cpara[0][2] );\r
-        rem1=Cpara[0][0]- cpara[0][1]*trans[1][0] - cpara[0][2]*trans[2][0];//rem1 = Cpara[0][0] - cpara[0][1]*trans[1][0] - cpara[0][2]*trans[2][0];\r
-        rem2 = Cpara[0][1] - cpara[0][1]*trans[1][1] - cpara[0][2]*trans[2][1];//rem2 = Cpara[0][1] - cpara[0][1]*trans[1][1] - cpara[0][2]*trans[2][1];\r
-        rem3 = Cpara[0][2] - cpara[0][1]*trans[1][2] - cpara[0][2]*trans[2][2];//rem3 = Cpara[0][2] - cpara[0][1]*trans[1][2] - cpara[0][2]*trans[2][2];\r
+        cpara[0][2]=dot(trans[2][0],trans[2][1], trans[2][2],Cpara[0*4+0], Cpara[0*4+1], Cpara[0*4+2] );//cpara[0][2] = dot( trans[2][0], trans[2][1], trans[2][2],Cpara[0][0], Cpara[0][1], Cpara[0][2] );\r
+        cpara[0][1]=dot(trans[1][0],trans[1][1], trans[1][2],Cpara[0*4+0], Cpara[0*4+1], Cpara[0*4+2]);//cpara[0][1] = dot( trans[1][0], trans[1][1], trans[1][2],Cpara[0][0], Cpara[0][1], Cpara[0][2] );\r
+        rem1=Cpara[0*4+0]- cpara[0][1]*trans[1][0] - cpara[0][2]*trans[2][0];//rem1 = Cpara[0][0] - cpara[0][1]*trans[1][0] - cpara[0][2]*trans[2][0];\r
+        rem2 = Cpara[0*4+1] - cpara[0][1]*trans[1][1] - cpara[0][2]*trans[2][1];//rem2 = Cpara[0][1] - cpara[0][1]*trans[1][1] - cpara[0][2]*trans[2][1];\r
+        rem3 = Cpara[0*4+2] - cpara[0][1]*trans[1][2] - cpara[0][2]*trans[2][2];//rem3 = Cpara[0][2] - cpara[0][1]*trans[1][2] - cpara[0][2]*trans[2][2];\r
         cpara[0][0]=norm(rem1, rem2, rem3);//cpara[0][0] = norm( rem1, rem2, rem3 );\r
         trans[0][0]=rem1 / cpara[0][0];//trans[0][0] = rem1 / cpara[0][0];\r
         trans[0][1]= rem2 / cpara[0][0];//trans[0][1] = rem2 / cpara[0][0];\r
         trans[0][2]= rem3 / cpara[0][0];//trans[0][2] = rem3 / cpara[0][0];\r
     \r
-        trans[1][3]=(Cpara[1][3] - cpara[1][2]*trans[2][3]) / cpara[1][1];//trans[1][3] = (Cpara[1][3] - cpara[1][2]*trans[2][3]) / cpara[1][1];\r
-        trans[0][3]=(Cpara[0][3] - cpara[0][1]*trans[1][3]- cpara[0][2]*trans[2][3]) / cpara[0][0];//trans[0][3] = (Cpara[0][3] - cpara[0][1]*trans[1][3]- cpara[0][2]*trans[2][3]) / cpara[0][0];\r
+        trans[1][3]=(Cpara[1*4+3] - cpara[1][2]*trans[2][3]) / cpara[1][1];//trans[1][3] = (Cpara[1][3] - cpara[1][2]*trans[2][3]) / cpara[1][1];\r
+        trans[0][3]=(Cpara[0*4+3] - cpara[0][1]*trans[1][3]- cpara[0][2]*trans[2][3]) / cpara[0][0];//trans[0][3] = (Cpara[0][3] - cpara[0][1]*trans[1][3]- cpara[0][2]*trans[2][3]) / cpara[0][0];\r
     \r
         for(int  r = 0; r < 3; r++ ){\r
             for(int c = 0; c < 3; c++ ){\r
@@ -181,7 +196,7 @@ public class NyARParam{
        System.out.println("Distortion factor = "+dist_factor[0]+" "+dist_factor[1]+" "+dist_factor[2]+" "+dist_factor[3]);//printf("Distortion factor = %f %f %f %f\n", param->dist_factor[0],param->dist_factor[1], param->dist_factor[2], param->dist_factor[3] );\r
        for(int j = 0; j < 3; j++ ) {//for(j = 0; j < 3; j++ ) {\r
            for(int i = 0; i < 4; i++ ){\r
-               System.out.print(mat[j][i]+" ");//printf("%7.5f ", param->mat[j][i]);\r
+               System.out.print(array34[j*4+i]+" ");//printf("%7.5f ", param->mat[j][i]);\r
            }\r
            System.out.println();//    printf("\n");\r
        }//}\r
@@ -215,9 +230,9 @@ public class NyARParam{
         scale = (double)i_xsize / (double)(xsize);//scale = (double)xsize / (double)(source->xsize);\r
     \r
         for(int i = 0; i < 4; i++ ) {\r
-            mat[0][i]=mat[0][i]*scale;//newparam->mat[0][i] = source->mat[0][i] * scale;\r
-            mat[1][i]=mat[1][i]*scale;//newparam->mat[1][i] = source->mat[1][i] * scale;\r
-            mat[2][i]=mat[2][i];//newparam->mat[2][i] = source->mat[2][i];\r
+            array34[0*4+i]=array34[0*4+i]*scale;//newparam->mat[0][i] = source->mat[0][i] * scale;\r
+            array34[1*4+i]=array34[1*4+i]*scale;//newparam->mat[1][i] = source->mat[1][i] * scale;\r
+            array34[2*4+i]=array34[2*4+i];//newparam->mat[2][i] = source->mat[2][i];\r
         }\r
     \r
         dist_factor[0] = dist_factor[0] * scale;//newparam->dist_factor[0] = source->dist_factor[0] * scale;\r
@@ -238,27 +253,44 @@ public class NyARParam{
      */\r
     public void ideal2Observ(double ix,double iy,DoubleValue ox, DoubleValue oy)\r
     {\r
-        double    x, y, d;\r
-        \r
-        x = (ix - dist_factor[0]) * dist_factor[3];\r
-        y = (iy - dist_factor[1]) * dist_factor[3];\r
-        if( x == 0.0 && y == 0.0 ) {\r
-            ox.value=dist_factor[0];\r
-            oy.value=dist_factor[1];\r
-        }else{\r
-            d = 1.0 - dist_factor[2]/100000000.0 * (x*x+y*y);\r
-            ox.value=x * d + dist_factor[0];\r
-            oy.value=y * d + dist_factor[1];\r
-        }\r
+\r
+       double    x, y, d;\r
+       final double d0,d1,d3;\r
+       final double df[]=this.dist_factor;\r
+       d0=df[0];\r
+       d1=df[1];\r
+       d3=df[3];\r
+       x = (ix - d0) * d3;\r
+       y = (iy - d1) * d3;\r
+       if( x == 0.0 && y == 0.0 ) {\r
+           ox.value=d0;\r
+           oy.value=d1;\r
+       }else{\r
+           d = 1.0 - df[2]/100000000.0 * (x*x+y*y);\r
+           ox.value=x * d + d0;\r
+           oy.value=y * d + d1;\r
+       }\r
     }\r
-    /*int arParamObserv2Ideal( const double dist_factor[4], const double ox, const double oy,double *ix, double *iy );*/\r
+    /**\r
+     * int arParamObserv2Ideal( const double dist_factor[4], const double ox, const double oy,double *ix, double *iy );\r
+     * \r
+     * @param ox\r
+     * @param oy\r
+     * @param ix\r
+     * @param iy\r
+     * @return\r
+     */\r
     public int observ2Ideal(double ox,double oy,DoubleValue ix,DoubleValue iy)\r
     {\r
        double  z02, z0, p, q, z, px, py,opttmp_1;\r
+       final double d0,d1,d3;\r
+       final double df[]=this.dist_factor;\r
+       d0=df[0];\r
+       d1=df[1];\r
        \r
-       px = ox - dist_factor[0];\r
-       py = oy - dist_factor[1];\r
-       p = dist_factor[2]/100000000.0;\r
+       px = ox - d0;\r
+       py = oy - d1;\r
+       p = df[2]/100000000.0;\r
        z02 = px*px+py*py;\r
        q = z0 = Math.sqrt(z02);//Optimize//q = z0 = Math.sqrt(px*px+ py*py);\r
        \r
@@ -267,10 +299,8 @@ public class NyARParam{
                //Optimize opttmp_1\r
                opttmp_1=p*z02;\r
                 z = z0 - ((1.0 - opttmp_1)*z0 - q) / (1.0 - 3.0*opttmp_1);\r
-               //Optimize opttmp_1       \r
-                opttmp_1=z / z0;\r
-                px = px * opttmp_1;\r
-                py = py * opttmp_1;\r
+                px = px*z/z0;\r
+                py = py*z/z0;\r
             }else {\r
                 px = 0.0;\r
                 py = 0.0;\r
@@ -282,12 +312,65 @@ public class NyARParam{
             z02 = px*px+ py*py;\r
             z0 = Math.sqrt(z02);//Optimize//z0 = Math.sqrt(px*px+ py*py);\r
        }\r
-       \r
-       ix.value=px / dist_factor[3] + dist_factor[0];\r
-       iy.value=py / dist_factor[3] + dist_factor[1];\r
+       d3=df[3];\r
+       ix.value=px / d3 + d0;\r
+       iy.value=py / d3 + d1;\r
        return 0;\r
     }\r
     /**\r
+     * 指定範囲のobserv2Idealをまとめて実行して、結果をo_idealに格納します。\r
+     * @param i_x_coord\r
+     * @param i_y_coord\r
+     * @param i_start\r
+     * 開始点\r
+     * @param i_num\r
+     * 計算数\r
+     * @param o_ideal\r
+     * 出力バッファ[i_num][2]であること。\r
+     */\r
+    public void observ2IdealBatch(int[] i_x_coord,int[] i_y_coord,int i_start,int i_num,double[][] o_ideal)\r
+    {\r
+       double  z02, z0,q, z, px, py,opttmp_1;\r
+       final double df[]=this.dist_factor;\r
+       final double d0=df[0];\r
+       final double d1=df[1];\r
+       final double d3=df[3];\r
+       final double p = df[2]/100000000.0;\r
+       for(int j = 0; j < i_num; j++ ){\r
+\r
+           px = i_x_coord[i_start+j] - d0;\r
+           py = i_y_coord[i_start+j] - d1;\r
+\r
+           z02 = px*px+py*py;\r
+           q = z0 = Math.sqrt(z02);//Optimize//q = z0 = Math.sqrt(px*px+ py*py);\r
+\r
+           for(int i = 1; ; i++ ) {\r
+               if( z0 != 0.0 ) {\r
+                   //Optimize opttmp_1\r
+                   opttmp_1=p*z02;\r
+                   z = z0 - ((1.0 - opttmp_1)*z0 - q) / (1.0 - 3.0*opttmp_1);\r
+                   px = px*z/z0;\r
+                   py = py*z/z0;\r
+               }else {\r
+                   px = 0.0;\r
+                   py = 0.0;\r
+                   break;\r
+               }\r
+               if( i == PD_LOOP ){\r
+                   break;\r
+               }\r
+               z02 = px*px+ py*py;\r
+               z0 = Math.sqrt(z02);//Optimize//z0 = Math.sqrt(px*px+ py*py);\r
+           }\r
+           o_ideal[j][0]=px / d3 + d0;\r
+           o_ideal[j][1]=py / d3 + d1;\r
+       }       \r
+    }    \r
+    \r
+    \r
+    \r
+    \r
+    /**\r
      * int    arParamLoad( const char *filename, int num, ARParam *param, ...);\r
      * i_streamの入力ストリームからi_num個の設定を読み込み、パラメタを配列にして返します。\r
      * @param filename\r
@@ -318,7 +401,7 @@ public class NyARParam{
                 new_param.ysize=bb.getInt();\r
                 for(int i2=0;i2<3;i2++){\r
                     for(int i3=0;i3<4;i3++){\r
-                       new_param.mat[i2][i3]=bb.getDouble();\r
+                       new_param.array34[i2*4+i3]=bb.getDouble();\r
                     }\r
                 }\r
                for(int i2=0;i2<4;i2++){\r
@@ -345,7 +428,7 @@ public class NyARParam{
             bb.putInt(param[i].ysize);\r
             for(int i2=0;i2<3;i2++){\r
                 for(int i3=0;i3<4;i3++){\r
-                    bb.putDouble(param[i].mat[i2][i3]);\r
+                    bb.putDouble(param[i].array34[i2*4+i3]);\r
                 }\r
             }\r
                 for(int i2=0;i2<4;i2++){\r
index 187f9db..8ffb0f0 100644 (file)
  * \r
  */\r
 package jp.nyatla.nyartoolkit.core;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.util.DoubleValue;\r
+\r
 /**\r
  * ARMarkerInfoに相当するクラス。\r
  * スクエア情報を保持します。\r
  *\r
  */\r
-public class NyARSquare{\r
-    private NyARMarker marker;\r
-    public int area;\r
-    public double[] pos;\r
-    public double[][] line;  //double[4][3]\r
-    public double[][] vertex;//double[4][2];\r
-    public NyARSquare(NyARMarker i_marker,double[][] i_attached_line,double[][] i_attached_vertex)\r
+public class NyARSquare extends NyARMarker{\r
+//    private NyARMarker marker;\r
+//    public int area;\r
+//    public double[] pos;\r
+    public double[][] line=new double[4][3];  //double[4][3]\r
+    public double[][] sqvertex=new double[4][2];//double[4][2];\r
+    public NyARSquare()\r
     {\r
-        //ARSquareは、ARMarkerを完全にラップするようにした。\r
-        marker=i_marker;\r
-        area=i_marker.area;\r
-        pos =i_marker.pos;\r
-        line  =i_attached_line;\r
-        vertex=i_attached_vertex;\r
+       super();\r
     }\r
-    public NyARMarker getMarker()\r
+    private final NyARMat wk_getLine_input=new NyARMat(1,2);\r
+    private final NyARMat wk_getLine_evec=new NyARMat(2,2);\r
+    private final NyARVec wk_getLine_ev=new NyARVec(2);\r
+    private final NyARVec wk_getLine_mean=new NyARVec(2);\r
+    /**\r
+     * arGetLine(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[4][3], double v[4][2])\r
+     * arGetLine2(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[4][3], double v[4][2], double *dist_factor)\r
+     * の2関数の合成品です。\r
+     * 格納しているマーカー情報に対して、GetLineの計算を行い、結果を返します。\r
+     * Optimize:STEP[424->391]\r
+     * @param i_cparam\r
+     * @return\r
+     * @throws NyARException\r
+     */\r
+    public boolean getLine(NyARParam i_cparam) throws NyARException\r
     {\r
-       return marker;\r
+       double   w1;\r
+       int      st, ed, n;\r
+       int      i;\r
+\r
+       final double[][] l_sqvertex=this.sqvertex;\r
+       final double[][] l_line=this.line;\r
+       final int[] l_mkvertex=this.mkvertex;\r
+       final int[] l_x_coord=this.x_coord;\r
+       final int[] l_y_coord=this.y_coord;     \r
+       final NyARVec ev     = this.wk_getLine_ev;  //matrixPCAの戻り値を受け取る\r
+       final NyARVec mean   = this.wk_getLine_mean;//matrixPCAの戻り値を受け取る\r
+       final double[] mean_array=mean.getArray();\r
+       double[] l_line_i,l_line_2;\r
+\r
+       NyARMat input=this.wk_getLine_input;//次処理で初期化される。\r
+       NyARMat evec =this.wk_getLine_evec;//アウトパラメータを受け取るから初期化不要//new NyARMat(2,2);\r
+       double[][] evec_array=evec.getArray();\r
+       for( i = 0; i < 4; i++ ) {\r
+           w1 = (double)(l_mkvertex[i+1]-l_mkvertex[i]+1) * 0.05 + 0.5;\r
+           st = (int)(l_mkvertex[i]   + w1);\r
+           ed = (int)(l_mkvertex[i+1] - w1);\r
+           n = ed - st + 1;\r
+           if(n<2){\r
+               //nが2以下でmatrix.PCAを計算することはできないので、エラーにしておく。\r
+               return false;//throw new NyARException();\r
+           }\r
+           input.realloc(n,2);\r
+           //バッチ取得\r
+           i_cparam.observ2IdealBatch(l_x_coord,l_y_coord,st,n,input.getArray());\r
+//         for( j = 0; j < n; j++ ) {\r
+//             i_cparam.observ2Ideal(l_x_coord[st+j], l_y_coord[st+j],dv1,dv2);//arParamObserv2Ideal( dist_factor, x_coord[st+j], y_coord[st+j],&(input->m[j*2+0]), &(input->m[j*2+1]) );\r
+//             in_array[j][0]=dv1.value;\r
+//             in_array[j][1]=dv2.value;\r
+//         }\r
+           input.matrixPCA(evec, ev, mean);\r
+           l_line_i=l_line[i];\r
+           l_line_i[0] =  evec_array[0][1];//line[i][0] =  evec->m[1];\r
+           l_line_i[1] = -evec_array[0][0];//line[i][1] = -evec->m[0];\r
+           l_line_i[2] = -(l_line_i[0]*mean_array[0] + l_line_i[1]*mean_array[1]);//line[i][2] = -(line[i][0]*mean->v[0] + line[i][1]*mean->v[1]);\r
+       }\r
+\r
+       for( i = 0; i < 4; i++ )\r
+       {\r
+           l_line_i=l_line[i];\r
+           l_line_2=l_line[(i+3)%4];\r
+           w1 = l_line_2[0] * l_line_i[1] - l_line_i[0] * l_line_2[1];\r
+           if( w1 == 0.0 ){\r
+               return false;\r
+           }\r
+           l_sqvertex[i][0] = (  l_line_2[1] * l_line_i[2]- l_line_i[1] * l_line_2[2] ) / w1;\r
+           l_sqvertex[i][1] = (  l_line_i[0] * l_line_2[2]- l_line_2[0] * l_line_i[2] ) / w1;\r
+       }\r
+       return true;\r
     }\r
 }\r
diff --git a/src/jp/nyatla/nyartoolkit/core/NyARSquareList.java b/src/jp/nyatla/nyartoolkit/core/NyARSquareList.java
new file mode 100644 (file)
index 0000000..638c302
--- /dev/null
@@ -0,0 +1,70 @@
+package jp.nyatla.nyartoolkit.core;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+\r
+public class NyARSquareList extends NyARMarkerList\r
+{\r
+    private final NyARSquare[] square_array;\r
+    private int square_array_num;\r
+    public NyARSquareList(int i_number_of_holder)\r
+    {\r
+       super(new NyARSquare[i_number_of_holder]);\r
+       //マーカーホルダに実体を割り当てる。\r
+       for(int i=0;i<this.marker_holder.length;i++){\r
+           this.marker_holder[i]=new NyARSquare();\r
+       }\r
+       this.square_array=new NyARSquare[i_number_of_holder];\r
+       this.square_array_num=0;\r
+    }\r
+    /**\r
+     * マーカーアレイをフィルタして、square_arrayを更新する。\r
+     * [[この関数はマーカー検出処理と密接に関係する関数です。\r
+     * NyARDetectSquareクラス以外から呼び出さないで下さい。]]\r
+     */\r
+    public final void updateSquareArray(NyARParam i_param) throws NyARException\r
+    {\r
+       NyARSquare square;\r
+       int j=0;\r
+       for (int i = 0; i <this.marker_array_num; i++){\r
+//         double[][]  line    =new double[4][3];\r
+//         double[][]  vertex  =new double[4][2];\r
+           //NyARMarker marker=detect.getMarker(i);\r
+           square=(NyARSquare)this.marker_array[i];\r
+           //・・・線の検出??\r
+            if (!square.getLine(i_param))\r
+            {\r
+               continue;\r
+            }\r
+            this.square_array[j]=square;\r
+//ここで計算するのは良くないと思うんだ       \r
+//             marker_infoL[j].id  = id.get();\r
+//             marker_infoL[j].dir = dir.get();\r
+//             marker_infoL[j].cf  = cf.get(); \r
+            j++;\r
+       }\r
+       this.square_array_num=j;\r
+    }\r
+    /**\r
+     * スクエア配列に格納されている要素数を返します。\r
+     * @return\r
+     */\r
+    public final int getSquareNum()\r
+    {\r
+       return  this.square_array_num;\r
+    }\r
+    /**\r
+     * スクエア配列の要素を返します。\r
+     * スクエア配列はマーカーアレイをさらにフィルタした結果です。\r
+     * マーカーアレイの部分集合になっている点に注意してください。\r
+     * @param i_index\r
+     * @return\r
+     * @throws NyARException\r
+     */\r
+    public final NyARSquare getSquare(int i_index) throws NyARException\r
+    {\r
+       if(i_index>=this.square_array_num){\r
+           throw new NyARException();\r
+       }\r
+       return this.square_array[i_index];\r
+    }\r
+}\r
index fe7013a..3e072a7 100644 (file)
@@ -43,25 +43,23 @@ import jp.nyatla.util.DoubleValue;
  *\r
  */\r
 public class NyARTransMat{\r
-    private static final int AR_FITTING_TO_IDEAL=0;//#define  AR_FITTING_TO_IDEAL          0\r
-    private static final int AR_FITTING_TO_INPUT=1;//#define  AR_FITTING_TO_INPUT          1\r
-    private static final int   arFittingMode   =AR_FITTING_TO_INPUT;\r
+    private final static int AR_FITTING_TO_IDEAL=0;//#define  AR_FITTING_TO_IDEAL          0\r
+    private final static int AR_FITTING_TO_INPUT=1;//#define  AR_FITTING_TO_INPUT          1\r
+    private final static int   arFittingMode   =AR_FITTING_TO_INPUT;\r
 \r
-    private static final int AR_GET_TRANS_MAT_MAX_LOOP_COUNT=5;//#define   AR_GET_TRANS_MAT_MAX_LOOP_COUNT         5\r
-    private static final double AR_GET_TRANS_MAT_MAX_FIT_ERROR=1.0;//#define   AR_GET_TRANS_MAT_MAX_FIT_ERROR          1.0\r
-    private final static int P_MAX=500;//#define P_MAX       500\r
-    private double[][] pos3d=new double[P_MAX][3];//pos3d[P_MAX][3];           \r
-    private double[][] pos2d=new double[P_MAX][2];//pos2d[P_MAX][2];\r
-\r
-    private double[] center={0.0,0.0};\r
-    private NyARParam param;\r
-    private double conv[][];\r
-    private NyARMat result_mat=new NyARMat(3,4);\r
-    public NyARTransMat(NyARParam i_param)\r
+    private final static int AR_GET_TRANS_MAT_MAX_LOOP_COUNT=5;//#define   AR_GET_TRANS_MAT_MAX_LOOP_COUNT         5\r
+    private final static double AR_GET_TRANS_MAT_MAX_FIT_ERROR=1.0;//#define   AR_GET_TRANS_MAT_MAX_FIT_ERROR          1.0\r
+    private final static int P_MAX=10;//頂点の数(4で十分だけどなんとなく10)//#define P_MAX       500\r
+    private final static int NUMBER_OF_VERTEX=4;//処理対象の頂点数\r
+    private final NyARTransRot transrot;\r
+    private final double[] center={0.0,0.0};\r
+    private final NyARParam param;\r
+    private final NyARMat result_mat=new NyARMat(3,4);\r
+    public NyARTransMat(NyARParam i_param)throws NyARException\r
     {\r
-       conv=result_mat.getArray();\r
        param=i_param;\r
-       \r
+       transrot=new NyARTransRot_O3(i_param,NUMBER_OF_VERTEX);\r
+\r
     }\r
     public void setCenter(double i_x,double i_y)\r
     {\r
@@ -72,6 +70,11 @@ public class NyARTransMat{
     {\r
        return result_mat;\r
     }\r
+\r
+    private final double[] wk_transMat_pos3d=new double[P_MAX*3];//pos3d[P_MAX][3];\r
+    private final double[][] wk_transMat_ppos2d=new double[4][2];\r
+    private final double[][] wk_transMat_ppos3d=new double[4][2];\r
+    private final double[] wk_transMat_off=new double[3];\r
     /**\r
      * double arGetTransMat( ARMarkerInfo *marker_info,double center[2], double width, double conv[3][4] )\r
      * 関数の置き換え。\r
@@ -85,796 +88,252 @@ public class NyARTransMat{
      */\r
     public double transMat( NyARSquare square,int i_direction, double width)throws NyARException\r
     {\r
-       double[][]  rot=new double[3][3];\r
-       double[][]  ppos2d=new double[4][2];\r
-       double[][]  ppos3d=new double[4][2];\r
-       int     dir;\r
-       double  err=-1;\r
+       double[][]  ppos2d=wk_transMat_ppos2d;\r
+       double[][]  ppos3d=wk_transMat_ppos3d;\r
+       double[] off=wk_transMat_off;\r
+       double[] pos3d=wk_transMat_pos3d;\r
+       int     dir;\r
+       double  err=-1;\r
 \r
 \r
 \r
-    \r
-       if( arGetInitRot( square,i_direction, rot ) < 0 ){\r
-            throw new NyARException();//return -1;\r
-       }\r
-    \r
-       dir = i_direction;\r
-       ppos2d[0][0] = square.vertex[(4-dir)%4][0];\r
-       ppos2d[0][1] = square.vertex[(4-dir)%4][1];\r
-       ppos2d[1][0] = square.vertex[(5-dir)%4][0];\r
-       ppos2d[1][1] = square.vertex[(5-dir)%4][1];\r
-       ppos2d[2][0] = square.vertex[(6-dir)%4][0];\r
-       ppos2d[2][1] = square.vertex[(6-dir)%4][1];\r
-       ppos2d[3][0] = square.vertex[(7-dir)%4][0];\r
-       ppos2d[3][1] = square.vertex[(7-dir)%4][1];\r
-       ppos3d[0][0] = center[0] - width/2.0;\r
-       ppos3d[0][1] = center[1] + width/2.0;\r
-       ppos3d[1][0] = center[0] + width/2.0;\r
-       ppos3d[1][1] = center[1] + width/2.0;\r
-       ppos3d[2][0] = center[0] + width/2.0;\r
-       ppos3d[2][1] = center[1] - width/2.0;\r
-       ppos3d[3][0] = center[0] - width/2.0;\r
-       ppos3d[3][1] = center[1] - width/2.0;\r
-       \r
+       transrot.initRot(square,i_direction);\r
 \r
-       \r
-       \r
-    \r
-        for(int i=0;i<AR_GET_TRANS_MAT_MAX_LOOP_COUNT; i++ ) {\r
-            err = arGetTransMat3( rot, ppos2d, ppos3d, 4);\r
-            if( err < AR_GET_TRANS_MAT_MAX_FIT_ERROR ){\r
-               break;\r
-            }\r
-        }\r
-       return err;\r
+       dir = i_direction;\r
+       ppos2d[0][0] = square.sqvertex[(4-dir)%4][0];\r
+       ppos2d[0][1] = square.sqvertex[(4-dir)%4][1];\r
+       ppos2d[1][0] = square.sqvertex[(5-dir)%4][0];\r
+       ppos2d[1][1] = square.sqvertex[(5-dir)%4][1];\r
+       ppos2d[2][0] = square.sqvertex[(6-dir)%4][0];\r
+       ppos2d[2][1] = square.sqvertex[(6-dir)%4][1];\r
+       ppos2d[3][0] = square.sqvertex[(7-dir)%4][0];\r
+       ppos2d[3][1] = square.sqvertex[(7-dir)%4][1];\r
+       ppos3d[0][0] = center[0] - width/2.0;\r
+       ppos3d[0][1] = center[1] + width/2.0;\r
+       ppos3d[1][0] = center[0] + width/2.0;\r
+       ppos3d[1][1] = center[1] + width/2.0;\r
+       ppos3d[2][0] = center[0] + width/2.0;\r
+       ppos3d[2][1] = center[1] - width/2.0;\r
+       ppos3d[3][0] = center[0] - width/2.0;\r
+       ppos3d[3][1] = center[1] - width/2.0;\r
+\r
+       //arGetTransMat3の前段処理(pos3dとoffを初期化)\r
+       arGetTransMat3_initPos3d(ppos3d,pos3d,off);\r
+\r
+\r
+\r
+       for(int i=0;i<AR_GET_TRANS_MAT_MAX_LOOP_COUNT; i++ ) {\r
+           err = arGetTransMat3(ppos2d, pos3d,off);\r
+           if( err < AR_GET_TRANS_MAT_MAX_FIT_ERROR ){\r
+               break;\r
+           }\r
+       }\r
+       return err;\r
     }\r
-    /*double arGetTransMat3( double rot[3][3], double ppos2d[][2],double ppos3d[][2], int num, double conv[3][4],double *dist_factor, double cpara[3][4] )*/\r
-    private double arGetTransMat3( double rot[][], double ppos2d[][],double ppos3d[][], int num)throws NyARException\r
+    private final double[] wk_arGetTransMat3_initPos3d_pmax=new double[3];\r
+    private final double[] wk_arGetTransMat3_initPos3d_pmin=new double[3];\r
+    /**\r
+     * arGetTransMat3関数の前処理部分。i_ppos3dから、o_pos3dとoffを計算する。\r
+     * 計算結果から再帰的に変更される可能性が無いので、切り離し。\r
+     * @param i_ppos3d\r
+     * 入力配列[num][3]\r
+     * @param o_pos3d\r
+     * 出力配列[P_MAX][3]\r
+     * @param o_off\r
+     * [3]\r
+     * @throws NyARException\r
+     */\r
+    private final void arGetTransMat3_initPos3d(double i_ppos3d[][],double[] o_pos3d,double[] o_off)throws NyARException\r
     {\r
-       double[]  off=new double[3], pmax=new double[3], pmin=new double[3];//double  off[3], pmax[3], pmin[3];\r
-        double  ret;\r
-        \r
-        pmax[0]=pmax[1]=pmax[2] = -10000000000.0;\r
-        pmin[0]=pmin[1]=pmin[2] =  10000000000.0;\r
-        for(int i = 0; i < num; i++ ) {\r
-            if( ppos3d[i][0] > pmax[0] ){\r
-               pmax[0] = ppos3d[i][0];\r
-            }\r
-            if( ppos3d[i][0] < pmin[0] ){\r
-               pmin[0] = ppos3d[i][0];\r
-            }\r
-            if( ppos3d[i][1] > pmax[1] ){\r
-               pmax[1] = ppos3d[i][1];\r
-            }\r
-            if( ppos3d[i][1] < pmin[1] ){\r
-               pmin[1] = ppos3d[i][1];\r
-            }\r
+       double[] pmax=wk_arGetTransMat3_initPos3d_pmax;//new double[3];\r
+       double[] pmin=wk_arGetTransMat3_initPos3d_pmin;//new double[3];//double  off[3], pmax[3], pmin[3];\r
+       pmax[0]=pmax[1]=pmax[2] = -10000000000.0;\r
+       pmin[0]=pmin[1]=pmin[2] =  10000000000.0;\r
+       for(int i = 0; i < NUMBER_OF_VERTEX; i++ ) {\r
+           if( i_ppos3d[i][0] > pmax[0] ){\r
+               pmax[0] = i_ppos3d[i][0];\r
+           }\r
+           if( i_ppos3d[i][0] < pmin[0] ){\r
+               pmin[0] = i_ppos3d[i][0];\r
+           }\r
+           if( i_ppos3d[i][1] > pmax[1] ){\r
+               pmax[1] = i_ppos3d[i][1];\r
+           }\r
+           if( i_ppos3d[i][1] < pmin[1] ){\r
+               pmin[1] = i_ppos3d[i][1];\r
+           }\r
        }\r
-        off[0] = -(pmax[0] + pmin[0]) / 2.0;\r
-        off[1] = -(pmax[1] + pmin[1]) / 2.0;\r
-        off[2] = -(pmax[2] + pmin[2]) / 2.0;\r
-        for(int i = 0; i < num; i++ ) {\r
-            pos3d[i][0] = ppos3d[i][0] + off[0];\r
-            pos3d[i][1] = ppos3d[i][1] + off[1];\r
-\r
-            pos3d[i][2] = 0.0;\r
-        }\r
-        ret = arGetTransMatSub( rot, ppos2d, pos3d, num);\r
-        \r
-        conv[0][3] = conv[0][0]*off[0] + conv[0][1]*off[1] + conv[0][2]*off[2] + conv[0][3];\r
-        conv[1][3] = conv[1][0]*off[0] + conv[1][1]*off[1] + conv[1][2]*off[2] + conv[1][3];\r
-        conv[2][3] = conv[2][0]*off[0] + conv[2][1]*off[1] + conv[2][2]*off[2] + conv[2][3];\r
-        \r
-        return ret;\r
+       o_off[0] = -(pmax[0] + pmin[0]) / 2.0;\r
+       o_off[1] = -(pmax[1] + pmin[1]) / 2.0;\r
+       o_off[2] = -(pmax[2] + pmin[2]) / 2.0;\r
+       for(int i = 0; i < NUMBER_OF_VERTEX; i++ ) {\r
+           o_pos3d[i*3+0] = i_ppos3d[i][0] + o_off[0];\r
+           o_pos3d[i*3+1] = i_ppos3d[i][1] + o_off[1];\r
+           o_pos3d[i*3+2] = 0.0;\r
+       }\r
+    }    \r
+    \r
+     \r
+    /**\r
+     * double arGetTransMat3( double rot[3][3], double ppos2d[][2],double ppos3d[][2], int num, double conv[3][4],double *dist_factor, double cpara[3][4] )\r
+     * STEP 414->\r
+     * @param ppos2d\r
+     * @param i_pos3d\r
+     * @param i_off\r
+     * @param num\r
+     * @return\r
+     * @throws NyARException\r
+     */\r
+    private final double arGetTransMat3(\r
+           double ppos2d[][],\r
+           final double i_pos3d[],\r
+           final double i_off[])throws NyARException{\r
+       \r
+       double  ret;\r
+       ret = arGetTransMatSub(ppos2d, i_pos3d);\r
+       double[][] conv=result_mat.getArray();\r
+       conv[0][3] = conv[0][0]*i_off[0] + conv[0][1]*i_off[1] + conv[0][2]*i_off[2] + conv[0][3];\r
+       conv[1][3] = conv[1][0]*i_off[0] + conv[1][1]*i_off[1] + conv[1][2]*i_off[2] + conv[1][3];\r
+       conv[2][3] = conv[2][0]*i_off[0] + conv[2][1]*i_off[1] + conv[2][2]*i_off[2] + conv[2][3];\r
+       return ret;\r
     }\r
-    /*static double arGetTransMatSub( double rot[3][3], double ppos2d[][2],double pos3d[][3], int num, double conv[3][4],double *dist_factor, double cpara[3][4] )*/\r
-    private double arGetTransMatSub( double rot[][], double ppos2d[][],double pos3d[][], int num) throws NyARException\r
+    private final NyARMat wk_arGetTransMatSub_mat_a=new NyARMat(NUMBER_OF_VERTEX*2,3);\r
+    private final NyARMat wk_arGetTransMatSub_mat_b=new NyARMat(3,NUMBER_OF_VERTEX*2);\r
+    private final NyARMat wk_arGetTransMatSub_mat_c=new NyARMat(NUMBER_OF_VERTEX*2,1);\r
+    private final NyARMat wk_arGetTransMatSub_mat_d=new NyARMat( 3, 3 );\r
+    private final NyARMat wk_arGetTransMatSub_mat_e=new NyARMat( 3, 1 );\r
+    private final NyARMat wk_arGetTransMatSub_mat_f=new NyARMat( 3, 1 );\r
+    private final double[] wk_arGetTransMatSub_trans=new double[3];\r
+    private final double[] wk_arGetTransMatSub_pos2d=new double[P_MAX*2];//pos2d[P_MAX][2];\r
+    private final DoubleValue wk_arGetTransMatSub_a1=new DoubleValue();\r
+    private final DoubleValue wk_arGetTransMatSub_a2=new DoubleValue();\r
+    \r
+\r
+    /**\r
+     * static double arGetTransMatSub( double rot[3][3], double ppos2d[][2],double pos3d[][3], int num, double conv[3][4],double *dist_factor, double cpara[3][4] )\r
+     * Optimize:2008.04.20:STEP[1033→1004]\r
+     * @param rot\r
+     * @param ppos2d\r
+     * @param pos3d\r
+     * @param num\r
+     * @return\r
+     * @throws NyARException\r
+     */\r
+    private final double arGetTransMatSub(double i_ppos2d[][],double i_pos3d[]) throws NyARException\r
     {\r
-       double cpara[][]=param.getMat();\r
+       double[] pos2d=wk_arGetTransMatSub_pos2d;\r
+       double cpara[]=param.get34Array();\r
        NyARMat mat_a,mat_b,mat_c,mat_d,mat_e,mat_f;//ARMat   *mat_a, *mat_b, *mat_c, *mat_d, *mat_e, *mat_f;\r
-       double[] trans=new double[3];//double  trans[3];\r
+\r
        double  wx, wy, wz;\r
        double  ret;\r
        int     i, j;\r
-       mat_a = new NyARMat(num*2, 3 );\r
-       mat_b = new NyARMat( 3, num*2 );\r
-       mat_c = new NyARMat( num*2, 1 );\r
-       mat_d = new NyARMat( 3, 3 );\r
-       mat_e = new NyARMat( 3, 1 );\r
-       mat_f = new NyARMat( 3, 1 );\r
+\r
+       mat_a =this.wk_arGetTransMatSub_mat_a;\r
+//     mat_a.realloc(NUMBER_OF_VERTEX*2,3);\r
        double[][] a_array=mat_a.getArray();\r
+\r
+       mat_b =this.wk_arGetTransMatSub_mat_b;\r
+//     mat_b.realloc(3,NUMBER_OF_VERTEX*2);\r
        double[][] b_array=mat_b.getArray();\r
-       double[][] c_array=mat_c.getArray();\r
-       double[][] f_array=mat_f.getArray();\r
-       \r
+\r
+\r
+        DoubleValue a1=wk_arGetTransMatSub_a1;\r
+        DoubleValue a2=wk_arGetTransMatSub_a2;\r
        if(arFittingMode == AR_FITTING_TO_INPUT ){\r
-           DoubleValue a1=new DoubleValue(),a2=new DoubleValue();\r
-           for( i = 0; i < num; i++ ) {\r
-               param.ideal2Observ(ppos2d[i][0], ppos2d[i][1],a1,a2);//arParamIdeal2Observ(dist_factor, ppos2d[i][0], ppos2d[i][1],&pos2d[i][0], &pos2d[i][1]);\r
-               pos2d[i][0]=a1.value;\r
-               pos2d[i][1]=a2.value;\r
+           for( i = 0; i < NUMBER_OF_VERTEX; i++ ) {\r
+               param.ideal2Observ(i_ppos2d[i][0], i_ppos2d[i][1],a1,a2);//arParamIdeal2Observ(dist_factor, ppos2d[i][0], ppos2d[i][1],&pos2d[i][0], &pos2d[i][1]);\r
+               pos2d[i*2+0]=a1.value;\r
+               pos2d[i*2+1]=a2.value;\r
            }\r
        }else{\r
-           for( i = 0; i < num; i++ ) {\r
-               pos2d[i][0] = ppos2d[i][0];\r
-               pos2d[i][1] = ppos2d[i][1];\r
+           for( i = 0; i < NUMBER_OF_VERTEX; i++ ) {\r
+               pos2d[i*2+0] = i_ppos2d[i][0];\r
+               pos2d[i*2+1] = i_ppos2d[i][1];\r
            }\r
        }\r
-       for( j = 0; j < num; j++ ) {\r
+       mat_c =this.wk_arGetTransMatSub_mat_c;//次処理で値をもらうので、初期化の必要は無い。\r
+//     mat_c.realloc(NUMBER_OF_VERTEX*2,1);\r
+       double[][] c_array=mat_c.getArray();\r
+       double[] rot=transrot.getArray();\r
+       for( j = 0; j < NUMBER_OF_VERTEX; j++ ) {\r
            int x2=j*2;\r
-           wx = rot[0][0] * pos3d[j][0]+ rot[0][1] * pos3d[j][1]+ rot[0][2] * pos3d[j][2];\r
-           wy = rot[1][0] * pos3d[j][0]+ rot[1][1] * pos3d[j][1]+ rot[1][2] * pos3d[j][2];\r
-           wz = rot[2][0] * pos3d[j][0]+ rot[2][1] * pos3d[j][1]+ rot[2][2] * pos3d[j][2];\r
-           a_array[x2  ][0]=b_array[0][x2]=cpara[0][0];//mat_a->m[j*6+0] = mat_b->m[num*0+j*2] = cpara[0][0];\r
-           a_array[x2  ][1]=b_array[1][x2]=cpara[0][1];//mat_a->m[j*6+1] = mat_b->m[num*2+j*2] = cpara[0][1];\r
-           a_array[x2  ][2]=b_array[2][x2]=cpara[0][2] - pos2d[j][0];//mat_a->m[j*6+2] = mat_b->m[num*4+j*2] = cpara[0][2] - pos2d[j][0];\r
+           //<Optimize>    \r
+           //wx = rot[0][0] * pos3d[j][0]+ rot[0][1] * pos3d[j][1]+ rot[0][2] * pos3d[j][2];\r
+           //wy = rot[1][0] * pos3d[j][0]+ rot[1][1] * pos3d[j][1]+ rot[1][2] * pos3d[j][2];\r
+           //wz = rot[2][0] * pos3d[j][0]+ rot[2][1] * pos3d[j][1]+ rot[2][2] * pos3d[j][2];\r
+           wx = rot[0] * i_pos3d[j*3+0]+ rot[1] * i_pos3d[j*3+1]+ rot[2] * i_pos3d[j*3+2];\r
+           wy = rot[3] * i_pos3d[j*3+0]+ rot[4] * i_pos3d[j*3+1]+ rot[5] * i_pos3d[j*3+2];\r
+           wz = rot[6] * i_pos3d[j*3+0]+ rot[7] * i_pos3d[j*3+1]+ rot[8] * i_pos3d[j*3+2];\r
+           //</Optimize>\r
+           a_array[x2  ][0]=b_array[0][x2]=cpara[0*4+0];//mat_a->m[j*6+0] = mat_b->m[num*0+j*2] = cpara[0][0];\r
+           a_array[x2  ][1]=b_array[1][x2]=cpara[0*4+1];//mat_a->m[j*6+1] = mat_b->m[num*2+j*2] = cpara[0][1];\r
+           a_array[x2  ][2]=b_array[2][x2]=cpara[0*4+2] - pos2d[j*2+0];//mat_a->m[j*6+2] = mat_b->m[num*4+j*2] = cpara[0][2] - pos2d[j][0];\r
            a_array[x2+1][0]=b_array[0][x2+1]=0.0;//mat_a->m[j*6+3] = mat_b->m[num*0+j*2+1] = 0.0;\r
-           a_array[x2+1][1]=b_array[1][x2+1]=cpara[1][1];//mat_a->m[j*6+4] = mat_b->m[num*2+j*2+1] = cpara[1][1];\r
-           a_array[x2+1][2]=b_array[2][x2+1]=cpara[1][2] - pos2d[j][1];//mat_a->m[j*6+5] = mat_b->m[num*4+j*2+1] = cpara[1][2] - pos2d[j][1];\r
-           c_array[x2][0]  =wz * pos2d[j][0]- cpara[0][0]*wx - cpara[0][1]*wy - cpara[0][2]*wz;//mat_c->m[j*2+0] = wz * pos2d[j][0]- cpara[0][0]*wx - cpara[0][1]*wy - cpara[0][2]*wz;\r
-           c_array[x2+1][0]=wz * pos2d[j][1]- cpara[1][1]*wy - cpara[1][2]*wz;//mat_c->m[j*2+1] = wz * pos2d[j][1]- cpara[1][1]*wy - cpara[1][2]*wz;\r
+           a_array[x2+1][1]=b_array[1][x2+1]=cpara[1*4+1];//mat_a->m[j*6+4] = mat_b->m[num*2+j*2+1] = cpara[1][1];\r
+           a_array[x2+1][2]=b_array[2][x2+1]=cpara[1*4+2] - pos2d[j*2+1];//mat_a->m[j*6+5] = mat_b->m[num*4+j*2+1] = cpara[1][2] - pos2d[j][1];\r
+           c_array[x2][0]  =wz * pos2d[j*2+0]- cpara[0*4+0]*wx - cpara[0*4+1]*wy - cpara[0*4+2]*wz;//mat_c->m[j*2+0] = wz * pos2d[j][0]- cpara[0][0]*wx - cpara[0][1]*wy - cpara[0][2]*wz;\r
+           c_array[x2+1][0]=wz * pos2d[j*2+1]- cpara[1*4+1]*wy - cpara[1*4+2]*wz;//mat_c->m[j*2+1] = wz * pos2d[j][1]- cpara[1][1]*wy - cpara[1][2]*wz;\r
        }\r
-//     JartkException.trap("未チェックのパス");{\r
-       NyARMat.matrixMul( mat_d, mat_b, mat_a );\r
-       NyARMat.matrixMul( mat_e, mat_b, mat_c );\r
+       mat_d = this.wk_arGetTransMatSub_mat_d;//次処理で値をもらうので、初期化の必要は無い。\r
+       mat_e = this.wk_arGetTransMatSub_mat_e;//次処理で値をもらうので、初期化の必要は無い。\r
+       mat_f = this.wk_arGetTransMatSub_mat_f;//次処理で値をもらうので、初期化の必要は無い。\r
+       double[][] f_array=mat_f.getArray();\r
+\r
+       mat_d.matrixMul(mat_b, mat_a );\r
+       mat_e.matrixMul(mat_b, mat_c );\r
        mat_d.matrixSelfInv();\r
-       NyARMat.matrixMul( mat_f, mat_d, mat_e );\r
-//     }\r
+       mat_f.matrixMul(mat_d, mat_e );\r
+\r
+       double[] trans=wk_arGetTransMatSub_trans;//double  trans[3];    \r
        trans[0] = f_array[0][0];//trans[0] = mat_f->m[0];\r
        trans[1] = f_array[1][0];\r
        trans[2] = f_array[2][0];//trans[2] = mat_f->m[2];\r
 \r
-       ret = arModifyMatrix( rot, trans, pos3d, pos2d, num );\r
-       for( j = 0; j < num; j++ ) {\r
+       ret =transrot.modifyMatrix(trans, i_pos3d, pos2d);\r
+       for( j = 0; j < NUMBER_OF_VERTEX; j++ ) {\r
            int x2=j*2;\r
-           wx = rot[0][0] * pos3d[j][0]+ rot[0][1] * pos3d[j][1]+ rot[0][2] * pos3d[j][2];\r
-           wy = rot[1][0] * pos3d[j][0]+ rot[1][1] * pos3d[j][1]+ rot[1][2] * pos3d[j][2];\r
-           wz = rot[2][0] * pos3d[j][0]+ rot[2][1] * pos3d[j][1]+ rot[2][2] * pos3d[j][2];\r
-           a_array[x2  ][0]=b_array[0][x2]=cpara[0][0];//mat_a->m[j*6+0] = mat_b->m[num*0+j*2] = cpara[0][0];\r
-           a_array[x2  ][1]=b_array[1][x2]=cpara[0][1];//mat_a->m[j*6+1] = mat_b->m[num*2+j*2] = cpara[0][1];\r
-           a_array[x2  ][2]=b_array[2][x2]=cpara[0][2] - pos2d[j][0];//mat_a->m[j*6+2] = mat_b->m[num*4+j*2] = cpara[0][2] - pos2d[j][0];\r
+           //<Optimize>    \r
+           //wx = rot[0][0] * pos3d[j][0]+ rot[0][1] * pos3d[j][1]+ rot[0][2] * pos3d[j][2];\r
+           //wy = rot[1][0] * pos3d[j][0]+ rot[1][1] * pos3d[j][1]+ rot[1][2] * pos3d[j][2];\r
+           //wz = rot[2][0] * pos3d[j][0]+ rot[2][1] * pos3d[j][1]+ rot[2][2] * pos3d[j][2];\r
+           wx = rot[0] * i_pos3d[j*3+0]+ rot[1] * i_pos3d[j*3+1]+ rot[2] * i_pos3d[j*3+2];\r
+           wy = rot[3] * i_pos3d[j*3+0]+ rot[4] * i_pos3d[j*3+1]+ rot[5] * i_pos3d[j*3+2];\r
+           wz = rot[6] * i_pos3d[j*3+0]+ rot[7] * i_pos3d[j*3+1]+ rot[8] * i_pos3d[j*3+2];\r
+           //</Optimize>\r
+           a_array[x2  ][0]=b_array[0][x2]=cpara[0*4+0];//mat_a->m[j*6+0] = mat_b->m[num*0+j*2] = cpara[0][0];\r
+           a_array[x2  ][1]=b_array[1][x2]=cpara[0*4+1];//mat_a->m[j*6+1] = mat_b->m[num*2+j*2] = cpara[0][1];\r
+           a_array[x2  ][2]=b_array[2][x2]=cpara[0*4+2] - pos2d[j*2+0];//mat_a->m[j*6+2] = mat_b->m[num*4+j*2] = cpara[0][2] - pos2d[j][0];\r
            a_array[x2+1][0]=b_array[0][x2+1]=0.0;//mat_a->m[j*6+3] = mat_b->m[num*0+j*2+1] = 0.0;\r
-           a_array[x2+1][1]=b_array[1][x2+1]=cpara[1][1];//mat_a->m[j*6+4] = mat_b->m[num*2+j*2+1] = cpara[1][1];\r
-           a_array[x2+1][2]=b_array[2][x2+1]=cpara[1][2] - pos2d[j][1];//mat_a->m[j*6+5] = mat_b->m[num*4+j*2+1] = cpara[1][2] - pos2d[j][1];\r
-           c_array[x2][0]  =wz * pos2d[j][0]- cpara[0][0]*wx - cpara[0][1]*wy - cpara[0][2]*wz;//mat_c->m[j*2+0] = wz * pos2d[j][0]- cpara[0][0]*wx - cpara[0][1]*wy - cpara[0][2]*wz;\r
-           c_array[x2+1][0]=wz * pos2d[j][1]- cpara[1][1]*wy - cpara[1][2]*wz;//mat_c->m[j*2+1] = wz * pos2d[j][1]- cpara[1][1]*wy - cpara[1][2]*wz;\r
+           a_array[x2+1][1]=b_array[1][x2+1]=cpara[1*4+1];//mat_a->m[j*6+4] = mat_b->m[num*2+j*2+1] = cpara[1][1];\r
+           a_array[x2+1][2]=b_array[2][x2+1]=cpara[1*4+2] - pos2d[j*2+1];//mat_a->m[j*6+5] = mat_b->m[num*4+j*2+1] = cpara[1][2] - pos2d[j][1];\r
+           c_array[x2][0]  =wz * pos2d[j*2+0]- cpara[0*4+0]*wx - cpara[0*4+1]*wy - cpara[0*4+2]*wz;//mat_c->m[j*2+0] = wz * pos2d[j][0]- cpara[0][0]*wx - cpara[0][1]*wy - cpara[0][2]*wz;\r
+           c_array[x2+1][0]=wz * pos2d[j*2+1]- cpara[1*4+1]*wy - cpara[1*4+2]*wz;//mat_c->m[j*2+1] = wz * pos2d[j][1]- cpara[1][1]*wy - cpara[1][2]*wz;\r
        }\r
 //     JartkException.trap("未チェックのパス");{\r
-       NyARMat.matrixMul( mat_d, mat_b, mat_a );\r
-       NyARMat.matrixMul( mat_e, mat_b, mat_c );\r
+       mat_d.matrixMul(mat_b, mat_a );\r
+       mat_e.matrixMul(mat_b, mat_c );\r
        mat_d.matrixSelfInv();\r
-       NyARMat.matrixMul( mat_f, mat_d, mat_e );\r
+       mat_f.matrixMul(mat_d, mat_e );\r
 //     }\r
        trans[0] = f_array[0][0];//trans[0] = mat_f->m[0];\r
        trans[1] = f_array[1][0];\r
        trans[2] = f_array[2][0];//trans[2] = mat_f->m[2];\r
 \r
 \r
-       ret = arModifyMatrix( rot, trans, pos3d, pos2d, num );\r
-       for( j = 0; j < 3; j++ ) {\r
-           for( i = 0; i < 3; i++ ){\r
-               conv[j][i] = rot[j][i];\r
-           }\r
+       ret = transrot.modifyMatrix(trans, i_pos3d, pos2d);\r
+       double[][] conv=result_mat.getArray();\r
+       for( j = 2; j >=0; j-- ) {//<Optimize/>for( j = 0; j < 3; j++ ) {\r
+           //<Optimize>\r
+           //for( i = 0; i < 3; i++ ){\r
+           //  conv[j][i] = rot[j][i];\r
+           //}\r
+           conv[j][0] = rot[j*3+0];\r
+           conv[j][1] = rot[j*3+1];\r
+           conv[j][2] = rot[j*3+2];\r
+           //</Optimize>\r
            conv[j][3] = trans[j];\r
        }\r
        return ret;\r
     }\r
-    private double arModifyMatrix( double rot[][], double trans[],double vertex[][], double pos2d[][], int num )\r
-    {\r
-        double    factor;\r
-        DoubleValue a=new DoubleValue(),b=new DoubleValue(),c=new DoubleValue();//double    a, b, c;\r
-        double    a1, b1, c1;\r
-        double    a2, b2, c2;\r
-        double    ma = 0.0, mb = 0.0, mc = 0.0;\r
-        double[][]    combo=new double[3][4];\r
-        double    hx, hy, h, x, y;\r
-        double    err, minerr=0;\r
-        int       t1, t2, t3;\r
-        int       s1 = 0, s2 = 0, s3 = 0;\r
-        int       i, j;\r
-\r
-        arGetAngle( rot, a, b, c);//arGetAngle( rot, &a, &b, &c );\r
-        a2 = a.value;\r
-        b2 = b.value;\r
-        c2 = c.value;\r
-        factor = 10.0*Math.PI/180.0;\r
-        for( j = 0; j < 10; j++ ) {\r
-            minerr = 1000000000.0;\r
-            for(t1=-1;t1<=1;t1++) {\r
-                for(t2=-1;t2<=1;t2++) {\r
-                    for(t3=-1;t3<=1;t3++) {\r
-                       a1 = a2 + factor*t1;\r
-                       b1 = b2 + factor*t2;\r
-                       c1 = c2 + factor*t3;\r
-                       arGetNewMatrix( a1, b1, c1, trans, null, combo );\r
-                       err = 0.0;\r
-                       for( i = 0; i < num; i++ ) {\r
-                            hx = combo[0][0] * vertex[i][0]+ combo[0][1] * vertex[i][1]+ combo[0][2] * vertex[i][2]+ combo[0][3];\r
-                            hy = combo[1][0] * vertex[i][0]+ combo[1][1] * vertex[i][1]+ combo[1][2] * vertex[i][2]+ combo[1][3];\r
-                            h  = combo[2][0] * vertex[i][0]+ combo[2][1] * vertex[i][1]+ combo[2][2] * vertex[i][2]+ combo[2][3];\r
-                            x = hx / h;\r
-                            y = hy / h;\r
-                            err += (pos2d[i][0] - x) * (pos2d[i][0] - x)+ (pos2d[i][1] - y) * (pos2d[i][1] - y);\r
-                       }\r
-                       if( err < minerr ) {\r
-                            minerr = err;\r
-                            ma = a1;\r
-                            mb = b1;\r
-                            mc = c1;\r
-                            s1 = t1;\r
-                            s2 = t2;\r
-                            s3 = t3;\r
-                       }\r
-                    }\r
-                }\r
-            }\r
-            if( s1 == 0 && s2 == 0 && s3 == 0 ){\r
-               factor *= 0.5;\r
-            }\r
-            a2 = ma;\r
-            b2 = mb;\r
-            c2 = mc;\r
-        }\r
-        arGetRot( ma, mb, mc, rot );\r
-        /*  printf("factor = %10.5f\n", factor*180.0/MD_PI); */\r
-        return minerr/num;\r
-    }\r
-    private double[][] wk_cpara2_arGetNewMatrix=new double[3][4];\r
-    private double[][] wk_rot_arGetNewMatrix   =new double[3][3];\r
-    /**\r
-     * \r
-     * @param a\r
-     * @param b\r
-     * @param c\r
-     * @param trans\r
-     * @param trans2\r
-     * @param ret\r
-     * @return\r
-     */\r
-    private int arGetNewMatrix( double a, double b, double c,double trans[], double trans2[][], double ret[][] )\r
-    {\r
-       double cpara[][]=param.getMat();\r
-        double[][] cpara2=wk_cpara2_arGetNewMatrix;    //この関数で初期化される。\r
-        double[][] rot   =wk_rot_arGetNewMatrix;       //arGetRotで初期化される。\r
-        int      i, j;\r
-        \r
-        arGetRot( a, b, c, rot );\r
-        \r
-        if( trans2 != null ) {\r
-            for( j = 0; j < 3; j++ ) {\r
-//             for( i = 0; i < 4; i++ ) {\r
-//                    cpara2[j][i] = cpara[j][0] * trans2[0][i]+ cpara[j][1] * trans2[1][i]+ cpara[j][2] * trans2[2][i];\r
-//             }\r
-//Optimize\r
-                cpara2[j][0] = cpara[j][0] * trans2[0][0]+ cpara[j][1] * trans2[1][0]+ cpara[j][2] * trans2[2][0];\r
-                cpara2[j][1] = cpara[j][0] * trans2[0][1]+ cpara[j][1] * trans2[1][1]+ cpara[j][2] * trans2[2][1];\r
-                cpara2[j][2] = cpara[j][0] * trans2[0][2]+ cpara[j][1] * trans2[1][2]+ cpara[j][2] * trans2[2][2];\r
-                cpara2[j][3] = cpara[j][0] * trans2[0][3]+ cpara[j][1] * trans2[1][3]+ cpara[j][2] * trans2[2][3];\r
-            }\r
-        }else{            \r
-            for( j = 0; j < 3; j++ ) {\r
-//             for( i = 0; i < 4; i++ ) {\r
-//                    cpara2[j][i] = cpara[j][i];\r
-//             }\r
-//Optimize             \r
-               cpara2[j][0] = cpara[j][0];\r
-               cpara2[j][1] = cpara[j][1];\r
-               cpara2[j][2] = cpara[j][2];\r
-               cpara2[j][3] = cpara[j][3];\r
-            }\r
-        }\r
-        for( j = 0; j < 3; j++ ) {\r
-//            for( i = 0; i < 3; i++ ) {\r
-//             ret[j][i] = cpara2[j][0] * rot[0][i]+ cpara2[j][1] * rot[1][i]+ cpara2[j][2] * rot[2][i];\r
-//            }\r
-//Optimize            \r
-            ret[j][0] = cpara2[j][0] * rot[0][0]+ cpara2[j][1] * rot[1][0]+ cpara2[j][2] * rot[2][0];\r
-            ret[j][1] = cpara2[j][0] * rot[0][1]+ cpara2[j][1] * rot[1][1]+ cpara2[j][2] * rot[2][1];\r
-            ret[j][2] = cpara2[j][0] * rot[0][2]+ cpara2[j][1] * rot[1][2]+ cpara2[j][2] * rot[2][2];\r
-//\r
-            ret[j][3] = cpara2[j][0] * trans[0]+ cpara2[j][1] * trans[1]+ cpara2[j][2] * trans[2]+ cpara2[j][3];\r
-        }\r
-        return(0);\r
-    }\r
-    private void arGetRot( double a, double b, double c, double rot[][] )\r
-    {\r
-        double   sina, sinb, sinc;\r
-        double   cosa, cosb, cosc;\r
-    \r
-        sina = Math.sin(a);\r
-        cosa = Math.cos(a);\r
-        sinb = Math.sin(b);\r
-        cosb = Math.cos(b);\r
-        sinc = Math.sin(c);\r
-        cosc = Math.cos(c);\r
-        //Optimize\r
-        double A,B,C,D,E,F,G;\r
-        A=sina*cosa;\r
-        B=sina*sina;\r
-        C=cosa*cosa;\r
-        D=cosa*sinb;\r
-        F=cosb*cosc;\r
-        E=cosb*sinc;\r
-        G=sina*sinb;\r
-\r
-        rot[0][0] = C*F + B*cosc + A*(E - sinc);\r
-        rot[0][1] = -C*E-B*sinc+A*(F-cosc);\r
-        rot[0][2] = D;\r
-        rot[1][0] = A*(F-cosc)+B*E+C*sinc;\r
-        rot[1][1] = A*(-E+sinc)+B*F+C*cosc;\r
-        rot[1][2] = G;\r
-        rot[2][0] = -D*cosc-G*sinc;\r
-        rot[2][1] = D*sinc-G*cosc;\r
-        rot[2][2] = cosb;\r
-  /*      \r
-       //49回\r
-        rot[0][0] = cosa*cosa*cosb*cosc+sina*sina*cosc+sina*cosa*cosb*sinc-sina*cosa*sinc;\r
-        rot[0][1] = -cosa*cosa*cosb*sinc-sina*sina*sinc+sina*cosa*cosb*cosc-sina*cosa*cosc;\r
-        rot[0][2] = cosa*sinb;\r
-        rot[1][0] = sina*cosa*cosb*cosc-sina*cosa*cosc+sina*sina*cosb*sinc+cosa*cosa*sinc;\r
-        rot[1][1] = -sina*cosa*cosb*sinc+sina*cosa*sinc+sina*sina*cosb*cosc+cosa*cosa*cosc;\r
-        rot[1][2] = sina*sinb;\r
-        rot[2][0] = -cosa*sinb*cosc-sina*sinb*sinc;\r
-        rot[2][1] = cosa*sinb*sinc-sina*sinb*cosc;\r
-        rot[2][2] = cosb;\r
-*/\r
-    }\r
-    /*int arGetAngle( double rot[3][3], double *wa, double *wb, double *wc )*/\r
-    private int arGetAngle( double rot[][], DoubleValue wa, DoubleValue wb, DoubleValue wc )\r
-    {\r
-        double      a, b, c;\r
-        double      sina, cosa, sinb, cosb, sinc, cosc;\r
-//             #if CHECK_CALC\r
-//             double   w[3];\r
-//             int      i;\r
-//             for(i=0;i<3;i++) w[i] = rot[i][0];\r
-//             for(i=0;i<3;i++) rot[i][0] = rot[i][1];\r
-//             for(i=0;i<3;i++) rot[i][1] = rot[i][2];\r
-//             for(i=0;i<3;i++) rot[i][2] = w[i];\r
-//             #endif    \r
-        if( rot[2][2] > 1.0 ) {\r
-        /* printf("cos(beta) = %f\n", rot[2][2]); */\r
-            rot[2][2] = 1.0;\r
-        }else if( rot[2][2] < -1.0 ) {\r
-            /* printf("cos(beta) = %f\n", rot[2][2]); */\r
-            rot[2][2] = -1.0;\r
-        }\r
-        cosb = rot[2][2];\r
-        b = Math.acos( cosb );\r
-        sinb = Math.sin( b );\r
-        if( b >= 0.000001 || b <= -0.000001) {\r
-            cosa = rot[0][2] / sinb;\r
-            sina = rot[1][2] / sinb;\r
-            if( cosa > 1.0 ) {\r
-                /* printf("cos(alph) = %f\n", cosa); */\r
-                cosa = 1.0;\r
-                sina = 0.0;\r
-            }\r
-            if( cosa < -1.0 ) {\r
-                /* printf("cos(alph) = %f\n", cosa); */\r
-                cosa = -1.0;\r
-                sina =  0.0;\r
-            }\r
-            if( sina > 1.0 ) {\r
-                /* printf("sin(alph) = %f\n", sina); */\r
-                sina = 1.0;\r
-                cosa = 0.0;\r
-            }\r
-            if( sina < -1.0 ) {\r
-                /* printf("sin(alph) = %f\n", sina); */\r
-                sina = -1.0;\r
-                cosa =  0.0;\r
-            }\r
-            a = Math.acos( cosa );\r
-            if( sina < 0 ){\r
-                a = -a;\r
-            }\r
-            sinc =  (rot[2][1]*rot[0][2]-rot[2][0]*rot[1][2])/ (rot[0][2]*rot[0][2]+rot[1][2]*rot[1][2]);\r
-            cosc =  -(rot[0][2]*rot[2][0]+rot[1][2]*rot[2][1])/ (rot[0][2]*rot[0][2]+rot[1][2]*rot[1][2]);\r
-            if( cosc > 1.0 ) {\r
-                /* printf("cos(r) = %f\n", cosc); */\r
-                cosc = 1.0;\r
-                sinc = 0.0;\r
-            }\r
-            if( cosc < -1.0 ) {\r
-                /* printf("cos(r) = %f\n", cosc); */\r
-                cosc = -1.0;\r
-                sinc =  0.0;\r
-            }\r
-            if( sinc > 1.0 ) {\r
-                /* printf("sin(r) = %f\n", sinc); */\r
-                sinc = 1.0;\r
-                cosc = 0.0;\r
-            }\r
-            if( sinc < -1.0 ) {\r
-                /* printf("sin(r) = %f\n", sinc); */\r
-                    sinc = -1.0;\r
-                    cosc =  0.0;\r
-            }\r
-            c = Math.acos( cosc );\r
-            if( sinc < 0 ){\r
-               c = -c;\r
-            }\r
-        }else {\r
-            a = b = 0.0;\r
-            cosa = cosb = 1.0;\r
-            sina = sinb = 0.0;\r
-            cosc = rot[0][0];\r
-            sinc = rot[1][0];\r
-            if( cosc > 1.0 ) {\r
-                /* printf("cos(r) = %f\n", cosc); */\r
-               cosc = 1.0;\r
-               sinc = 0.0;\r
-            }\r
-            if( cosc < -1.0 ) {\r
-                /* printf("cos(r) = %f\n", cosc); */\r
-                cosc = -1.0;\r
-                sinc =  0.0;\r
-            }\r
-            if( sinc > 1.0 ) {\r
-                /* printf("sin(r) = %f\n", sinc); */\r
-                sinc = 1.0;\r
-                cosc = 0.0;\r
-            }\r
-            if( sinc < -1.0 ) {\r
-                /* printf("sin(r) = %f\n", sinc); */\r
-                    sinc = -1.0;\r
-                    cosc =  0.0;\r
-            }\r
-            c = Math.acos( cosc );\r
-            if( sinc < 0 ) c = -c;\r
-        }\r
-        \r
-        wa.value=a;//*wa = a;\r
-        wb.value=b;//*wb = b;\r
-        wc.value=c;//*wc = c;\r
-        \r
-        return 0;\r
-    }\r
-    /*int arGetInitRot( ARMarkerInfo *marker_info, double cpara[3][4], double rot[3][3] )*/\r
-    private int arGetInitRot( NyARSquare marker_info,int i_direction, double rot[][] ) throws NyARException\r
-    {\r
-       double cpara[][]=param.getMat();\r
-        double[][]  wdir=new double[3][3];\r
-        double  w, w1, w2, w3;\r
-        int     dir;\r
-        int     j;\r
-    \r
-        dir = i_direction;\r
-    \r
-        for( j = 0; j < 2; j++ ) {\r
-            w1 = marker_info.line[(4-dir+j)%4][0] * marker_info.line[(6-dir+j)%4][1]- marker_info.line[(6-dir+j)%4][0] * marker_info.line[(4-dir+j)%4][1];\r
-            w2 = marker_info.line[(4-dir+j)%4][1] * marker_info.line[(6-dir+j)%4][2]- marker_info.line[(6-dir+j)%4][1] * marker_info.line[(4-dir+j)%4][2];\r
-            w3 = marker_info.line[(4-dir+j)%4][2] * marker_info.line[(6-dir+j)%4][0]- marker_info.line[(6-dir+j)%4][2] * marker_info.line[(4-dir+j)%4][0];\r
-    \r
-            wdir[j][0] =  w1*(cpara[0][1]*cpara[1][2]-cpara[0][2]*cpara[1][1])+  w2*cpara[1][1]-  w3*cpara[0][1];\r
-            wdir[j][1] = -w1*cpara[0][0]*cpara[1][2]+  w3*cpara[0][0];\r
-            wdir[j][2] =  w1*cpara[0][0]*cpara[1][1];\r
-            w = Math.sqrt( wdir[j][0]*wdir[j][0]+ wdir[j][1]*wdir[j][1]+ wdir[j][2]*wdir[j][2] );\r
-            wdir[j][0] /= w;\r
-            wdir[j][1] /= w;\r
-            wdir[j][2] /= w;\r
-        }\r
-    \r
-        if( check_dir(wdir[0], marker_info.vertex[(4-dir)%4],marker_info.vertex[(5-dir)%4], cpara) < 0 ){\r
-               return -1;\r
-        }\r
-        if( check_dir(wdir[1], marker_info.vertex[(7-dir)%4],marker_info.vertex[(4-dir)%4], cpara) < 0 ){\r
-               return -1;\r
-        }\r
-        if( check_rotation(wdir) < 0 ){\r
-               return -1;\r
-        }\r
-    \r
-        wdir[2][0] = wdir[0][1]*wdir[1][2] - wdir[0][2]*wdir[1][1];\r
-        wdir[2][1] = wdir[0][2]*wdir[1][0] - wdir[0][0]*wdir[1][2];\r
-        wdir[2][2] = wdir[0][0]*wdir[1][1] - wdir[0][1]*wdir[1][0];\r
-        w = Math.sqrt( wdir[2][0]*wdir[2][0]+ wdir[2][1]*wdir[2][1]+ wdir[2][2]*wdir[2][2] );\r
-        wdir[2][0] /= w;\r
-        wdir[2][1] /= w;\r
-        wdir[2][2] /= w;\r
-    /*\r
-        if( wdir[2][2] < 0 ) {\r
-            wdir[2][0] /= -w;\r
-            wdir[2][1] /= -w;\r
-            wdir[2][2] /= -w;\r
-        }\r
-        else {\r
-            wdir[2][0] /= w;\r
-            wdir[2][1] /= w;\r
-            wdir[2][2] /= w;\r
-        }\r
-    */\r
-    \r
-        rot[0][0] = wdir[0][0];\r
-        rot[1][0] = wdir[0][1];\r
-        rot[2][0] = wdir[0][2];\r
-        rot[0][1] = wdir[1][0];\r
-        rot[1][1] = wdir[1][1];\r
-        rot[2][1] = wdir[1][2];\r
-        rot[0][2] = wdir[2][0];\r
-        rot[1][2] = wdir[2][1];\r
-        rot[2][2] = wdir[2][2];\r
-    \r
-        return 0;\r
-    }\r
-\r
-    /*static int check_dir( double dir[3], double st[2], double ed[2],double cpara[3][4] )*/\r
-    private static int check_dir( double dir[], double st[], double ed[],double cpara[][]) throws NyARException\r
-    {\r
-    \r
-        double[][]     world=new double[2][3];\r
-        double[][] camera=new double[2][2];\r
-        double[][] v=new double[2][2];\r
-        double    h;\r
-        int       i, j;\r
-        //                 JartkException.trap("未チェックパス");\r
-        NyARMat mat_a = new NyARMat( 3, 3 );\r
-        double[][] a_array=mat_a.getArray();\r
-        for(j=0;j<3;j++){\r
-            for(i=0;i<3;i++){\r
-                a_array[j][i]=cpara[j][i];//m[j*3+i] = cpara[j][i];\r
-            }\r
-        }\r
-    // JartkException.trap("未チェックのパス");\r
-        mat_a.matrixSelfInv();\r
-        world[0][0] = a_array[0][0]*st[0]*10.0+ a_array[0][1]*st[1]*10.0+ a_array[0][2]*10.0;//mat_a->m[0]*st[0]*10.0+ mat_a->m[1]*st[1]*10.0+ mat_a->m[2]*10.0;\r
-        world[0][1] = a_array[1][0]*st[0]*10.0+ a_array[1][1]*st[1]*10.0+ a_array[1][2]*10.0;//mat_a->m[3]*st[0]*10.0+ mat_a->m[4]*st[1]*10.0+ mat_a->m[5]*10.0;\r
-        world[0][2] = a_array[2][0]*st[0]*10.0+ a_array[2][1]*st[1]*10.0+ a_array[2][2]*10.0;//mat_a->m[6]*st[0]*10.0+ mat_a->m[7]*st[1]*10.0+ mat_a->m[8]*10.0;\r
-        world[1][0] = world[0][0] + dir[0];\r
-        world[1][1] = world[0][1] + dir[1];\r
-        world[1][2] = world[0][2] + dir[2];\r
-    \r
-        for( i = 0; i < 2; i++ ) {\r
-            h = cpara[2][0] * world[i][0]+ cpara[2][1] * world[i][1]+ cpara[2][2] * world[i][2];\r
-            if( h == 0.0 ){\r
-                return -1;\r
-            }\r
-            camera[i][0] = (cpara[0][0] * world[i][0]+ cpara[0][1] * world[i][1]+ cpara[0][2] * world[i][2]) / h;\r
-            camera[i][1] = (cpara[1][0] * world[i][0]+ cpara[1][1] * world[i][1]+ cpara[1][2] * world[i][2]) / h;\r
-        }\r
-\r
-        v[0][0] = ed[0] - st[0];\r
-        v[0][1] = ed[1] - st[1];\r
-        v[1][0] = camera[1][0] - camera[0][0];\r
-        v[1][1] = camera[1][1] - camera[0][1];\r
-\r
-        if( v[0][0]*v[1][0] + v[0][1]*v[1][1] < 0 ) {\r
-            dir[0] = -dir[0];\r
-            dir[1] = -dir[1];\r
-            dir[2] = -dir[2];\r
-        }\r
-        return 0;\r
-    }\r
-\r
-               /*int check_rotation( double rot[2][3] )*/\r
-               private static int check_rotation( double rot[][] )\r
-               {\r
-                   double[]  v1=new double[3], v2=new double[3], v3=new double[3];\r
-                   double  ca, cb, k1, k2, k3, k4;\r
-                   double  a, b, c, d;\r
-                   double  p1, q1, r1;\r
-                   double  p2, q2, r2;\r
-                   double  p3, q3, r3;\r
-                   double  p4, q4, r4;\r
-                   double  w;\r
-                   double  e1, e2, e3, e4;\r
-                   int     f;\r
-               \r
-                   v1[0] = rot[0][0];\r
-                   v1[1] = rot[0][1];\r
-                   v1[2] = rot[0][2];\r
-                   v2[0] = rot[1][0];\r
-                   v2[1] = rot[1][1];\r
-                   v2[2] = rot[1][2];\r
-                   v3[0] = v1[1]*v2[2] - v1[2]*v2[1];\r
-                   v3[1] = v1[2]*v2[0] - v1[0]*v2[2];\r
-                   v3[2] = v1[0]*v2[1] - v1[1]*v2[0];\r
-                   w = Math.sqrt( v3[0]*v3[0]+v3[1]*v3[1]+v3[2]*v3[2] );\r
-                   if( w == 0.0 ) return -1;\r
-                   v3[0] /= w;\r
-                   v3[1] /= w;\r
-                   v3[2] /= w;\r
-               \r
-                   cb = v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];\r
-                   if( cb < 0 ) cb *= -1.0;\r
-                   ca = (Math.sqrt(cb+1.0) + Math.sqrt(1.0-cb)) * 0.5;\r
-               \r
-                   if( v3[1]*v1[0] - v1[1]*v3[0] != 0.0 ) {\r
-                       f = 0;\r
-                   }\r
-                   else {\r
-                       if( v3[2]*v1[0] - v1[2]*v3[0] != 0.0 ) {\r
-                           w = v1[1]; v1[1] = v1[2]; v1[2] = w;\r
-                           w = v3[1]; v3[1] = v3[2]; v3[2] = w;\r
-                           f = 1;\r
-                       }\r
-                       else {\r
-                           w = v1[0]; v1[0] = v1[2]; v1[2] = w;\r
-                           w = v3[0]; v3[0] = v3[2]; v3[2] = w;\r
-                           f = 2;\r
-                       }\r
-                   }\r
-                   if( v3[1]*v1[0] - v1[1]*v3[0] == 0.0 ){\r
-                       return -1;\r
-                   }\r
-                   k1 = (v1[1]*v3[2] - v3[1]*v1[2]) / (v3[1]*v1[0] - v1[1]*v3[0]);\r
-                   k2 = (v3[1] * ca) / (v3[1]*v1[0] - v1[1]*v3[0]);\r
-                   k3 = (v1[0]*v3[2] - v3[0]*v1[2]) / (v3[0]*v1[1] - v1[0]*v3[1]);\r
-                   k4 = (v3[0] * ca) / (v3[0]*v1[1] - v1[0]*v3[1]);\r
-               \r
-                   a = k1*k1 + k3*k3 + 1;\r
-                   b = k1*k2 + k3*k4;\r
-                   c = k2*k2 + k4*k4 - 1;\r
-               \r
-                   d = b*b - a*c;\r
-                   if( d < 0 ){\r
-                       return -1;\r
-                   }\r
-                   r1 = (-b + Math.sqrt(d))/a;\r
-                   p1 = k1*r1 + k2;\r
-                   q1 = k3*r1 + k4;\r
-                   r2 = (-b - Math.sqrt(d))/a;\r
-                   p2 = k1*r2 + k2;\r
-                   q2 = k3*r2 + k4;\r
-                   if( f == 1 ) {\r
-                       w = q1; q1 = r1; r1 = w;\r
-                       w = q2; q2 = r2; r2 = w;\r
-                       w = v1[1]; v1[1] = v1[2]; v1[2] = w;\r
-                       w = v3[1]; v3[1] = v3[2]; v3[2] = w;\r
-                       f = 0;\r
-                   }\r
-                   if( f == 2 ) {\r
-                       w = p1; p1 = r1; r1 = w;\r
-                       w = p2; p2 = r2; r2 = w;\r
-                       w = v1[0]; v1[0] = v1[2]; v1[2] = w;\r
-                       w = v3[0]; v3[0] = v3[2]; v3[2] = w;\r
-                       f = 0;\r
-                   }\r
-               \r
-                   if( v3[1]*v2[0] - v2[1]*v3[0] != 0.0 ) {\r
-                       f = 0;\r
-                   }\r
-                   else {\r
-                       if( v3[2]*v2[0] - v2[2]*v3[0] != 0.0 ) {\r
-                           w = v2[1]; v2[1] = v2[2]; v2[2] = w;\r
-                           w = v3[1]; v3[1] = v3[2]; v3[2] = w;\r
-                           f = 1;\r
-                       }\r
-                       else {\r
-                           w = v2[0]; v2[0] = v2[2]; v2[2] = w;\r
-                           w = v3[0]; v3[0] = v3[2]; v3[2] = w;\r
-                           f = 2;\r
-                       }\r
-                   }\r
-                   if( v3[1]*v2[0] - v2[1]*v3[0] == 0.0 ) return -1;\r
-                   k1 = (v2[1]*v3[2] - v3[1]*v2[2]) / (v3[1]*v2[0] - v2[1]*v3[0]);\r
-                   k2 = (v3[1] * ca) / (v3[1]*v2[0] - v2[1]*v3[0]);\r
-                   k3 = (v2[0]*v3[2] - v3[0]*v2[2]) / (v3[0]*v2[1] - v2[0]*v3[1]);\r
-                   k4 = (v3[0] * ca) / (v3[0]*v2[1] - v2[0]*v3[1]);\r
-               \r
-                   a = k1*k1 + k3*k3 + 1;\r
-                   b = k1*k2 + k3*k4;\r
-                   c = k2*k2 + k4*k4 - 1;\r
-               \r
-                   d = b*b - a*c;\r
-                   if( d < 0 ){\r
-                       return -1;\r
-                   }\r
-                   r3 = (-b + Math.sqrt(d))/a;\r
-                   p3 = k1*r3 + k2;\r
-                   q3 = k3*r3 + k4;\r
-                   r4 = (-b - Math.sqrt(d))/a;\r
-                   p4 = k1*r4 + k2;\r
-                   q4 = k3*r4 + k4;\r
-                   if( f == 1 ) {\r
-                       w = q3; q3 = r3; r3 = w;\r
-                       w = q4; q4 = r4; r4 = w;\r
-                       w = v2[1]; v2[1] = v2[2]; v2[2] = w;\r
-                       w = v3[1]; v3[1] = v3[2]; v3[2] = w;\r
-                       f = 0;\r
-                   }\r
-                   if( f == 2 ) {\r
-                       w = p3; p3 = r3; r3 = w;\r
-                       w = p4; p4 = r4; r4 = w;\r
-                       w = v2[0]; v2[0] = v2[2]; v2[2] = w;\r
-                       w = v3[0]; v3[0] = v3[2]; v3[2] = w;\r
-                       f = 0;\r
-                   }\r
-               \r
-                   e1 = p1*p3+q1*q3+r1*r3;\r
-                   if( e1 < 0 ){\r
-                       e1 = -e1;\r
-                   }\r
-                   e2 = p1*p4+q1*q4+r1*r4;\r
-                   if( e2 < 0 ){\r
-                       e2 = -e2;\r
-                   }\r
-                   e3 = p2*p3+q2*q3+r2*r3;\r
-                   if( e3 < 0 ){\r
-                       e3 = -e3;\r
-                   }\r
-                   e4 = p2*p4+q2*q4+r2*r4;\r
-                   if( e4 < 0 ){\r
-                       e4 = -e4;\r
-                   }\r
-                   if( e1 < e2 ) {\r
-                       if( e1 < e3 ) {\r
-                           if( e1 < e4 ) {\r
-                               rot[0][0] = p1;\r
-                               rot[0][1] = q1;\r
-                               rot[0][2] = r1;\r
-                               rot[1][0] = p3;\r
-                               rot[1][1] = q3;\r
-                               rot[1][2] = r3;\r
-                           }\r
-                           else {\r
-                               rot[0][0] = p2;\r
-                               rot[0][1] = q2;\r
-                               rot[0][2] = r2;\r
-                               rot[1][0] = p4;\r
-                               rot[1][1] = q4;\r
-                               rot[1][2] = r4;\r
-                           }\r
-                       }\r
-                       else {\r
-                           if( e3 < e4 ) {\r
-                               rot[0][0] = p2;\r
-                               rot[0][1] = q2;\r
-                               rot[0][2] = r2;\r
-                               rot[1][0] = p3;\r
-                               rot[1][1] = q3;\r
-                               rot[1][2] = r3;\r
-                           }\r
-                           else {\r
-                               rot[0][0] = p2;\r
-                               rot[0][1] = q2;\r
-                               rot[0][2] = r2;\r
-                               rot[1][0] = p4;\r
-                               rot[1][1] = q4;\r
-                               rot[1][2] = r4;\r
-                           }\r
-                       }\r
-                   }\r
-                   else {\r
-                       if( e2 < e3 ) {\r
-                           if( e2 < e4 ) {\r
-                               rot[0][0] = p1;\r
-                               rot[0][1] = q1;\r
-                               rot[0][2] = r1;\r
-                               rot[1][0] = p4;\r
-                               rot[1][1] = q4;\r
-                               rot[1][2] = r4;\r
-                           }\r
-                           else {\r
-                               rot[0][0] = p2;\r
-                               rot[0][1] = q2;\r
-                               rot[0][2] = r2;\r
-                               rot[1][0] = p4;\r
-                               rot[1][1] = q4;\r
-                               rot[1][2] = r4;\r
-                           }\r
-                       }\r
-                       else {\r
-                           if( e3 < e4 ) {\r
-                               rot[0][0] = p2;\r
-                               rot[0][1] = q2;\r
-                               rot[0][2] = r2;\r
-                               rot[1][0] = p3;\r
-                               rot[1][1] = q3;\r
-                               rot[1][2] = r3;\r
-                           }\r
-                           else {\r
-                               rot[0][0] = p2;\r
-                               rot[0][1] = q2;\r
-                               rot[0][2] = r2;\r
-                               rot[1][0] = p4;\r
-                               rot[1][1] = q4;\r
-                               rot[1][2] = r4;\r
-                           }\r
-                       }\r
-                   }\r
-                   return 0;\r
-               }\r
-\r
 }\r
diff --git a/src/jp/nyatla/nyartoolkit/core/NyARTransRot.java b/src/jp/nyatla/nyartoolkit/core/NyARTransRot.java
new file mode 100644 (file)
index 0000000..a993a2e
--- /dev/null
@@ -0,0 +1,1198 @@
+package jp.nyatla.nyartoolkit.core;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+\r
+interface NyARTransRot\r
+{\r
+    public double[] getArray();\r
+    /**\r
+     * \r
+     * @param trans\r
+     * @param vertex\r
+     * @param pos2d\r
+     * [n*2]配列\r
+     * @return\r
+     * @throws NyARException\r
+     */\r
+    public double modifyMatrix(double trans[],double vertex[], double pos2d[]) throws NyARException;\r
+    public void initRot(NyARSquare marker_info,int i_direction) throws NyARException;    \r
+}\r
+\r
+/**\r
+ * NyARTransRot派生クラスで共通に使いそうな関数類をまとめたもの。\r
+ * @author atla\r
+ *\r
+ */\r
+abstract class NyARTransRot_OptimizeCommon implements NyARTransRot\r
+{\r
+    protected final int number_of_vertex;\r
+    protected final double[] array=new double[9];\r
+    protected final NyARParam cparam;\r
+    public final double[] getArray()\r
+    {\r
+       return this.array;\r
+    }\r
+    /**\r
+     * インスタンスを準備します。\r
+     * @param i_param\r
+     * nullを指定した場合、一部の関数が使用不能になります。\r
+     */\r
+    public NyARTransRot_OptimizeCommon(NyARParam i_param,int i_number_of_vertex) throws NyARException\r
+    {\r
+       number_of_vertex=i_number_of_vertex;\r
+       cparam=i_param;\r
+    }\r
+\r
+    private final double[] wk_check_dir_world=new double[6];\r
+    private final double[] wk_check_dir_camera=new double[4];\r
+    private final NyARMat wk_check_dir_NyARMat=new NyARMat( 3, 3 );\r
+    /**\r
+     * static int check_dir( double dir[3], double st[2], double ed[2],double cpara[3][4] )\r
+     * Optimize:STEP[526->468]\r
+     * @param dir\r
+     * @param st\r
+     * @param ed\r
+     * @param cpara\r
+     * \r
+     * @throws NyARException\r
+     */\r
+    protected final void check_dir( double dir[], double st[], double ed[],double cpara[]) throws NyARException\r
+    {\r
+       double    h;\r
+       int       i, j;\r
+\r
+       NyARMat mat_a = this.wk_check_dir_NyARMat;//ここ、事前に初期化できそう\r
+       double[][] a_array=mat_a.getArray();\r
+       for(j=0;j<3;j++){\r
+           for(i=0;i<3;i++){\r
+               a_array[j][i]=cpara[j*4+i];//m[j*3+i] = cpara[j][i];\r
+           }\r
+           \r
+       }\r
+       //      JartkException.trap("未チェックのパス");\r
+       mat_a.matrixSelfInv();\r
+       double[] world=wk_check_dir_world;//[2][3];\r
+       //<Optimize>\r
+       //world[0][0] = a_array[0][0]*st[0]*10.0+ a_array[0][1]*st[1]*10.0+ a_array[0][2]*10.0;//mat_a->m[0]*st[0]*10.0+ mat_a->m[1]*st[1]*10.0+ mat_a->m[2]*10.0;\r
+       //world[0][1] = a_array[1][0]*st[0]*10.0+ a_array[1][1]*st[1]*10.0+ a_array[1][2]*10.0;//mat_a->m[3]*st[0]*10.0+ mat_a->m[4]*st[1]*10.0+ mat_a->m[5]*10.0;\r
+       //world[0][2] = a_array[2][0]*st[0]*10.0+ a_array[2][1]*st[1]*10.0+ a_array[2][2]*10.0;//mat_a->m[6]*st[0]*10.0+ mat_a->m[7]*st[1]*10.0+ mat_a->m[8]*10.0;\r
+       //world[1][0] = world[0][0] + dir[0];\r
+       //world[1][1] = world[0][1] + dir[1];\r
+       //world[1][2] = world[0][2] + dir[2];\r
+       world[0] = a_array[0][0]*st[0]*10.0+ a_array[0][1]*st[1]*10.0+ a_array[0][2]*10.0;//mat_a->m[0]*st[0]*10.0+ mat_a->m[1]*st[1]*10.0+ mat_a->m[2]*10.0;\r
+       world[1] = a_array[1][0]*st[0]*10.0+ a_array[1][1]*st[1]*10.0+ a_array[1][2]*10.0;//mat_a->m[3]*st[0]*10.0+ mat_a->m[4]*st[1]*10.0+ mat_a->m[5]*10.0;\r
+       world[2] = a_array[2][0]*st[0]*10.0+ a_array[2][1]*st[1]*10.0+ a_array[2][2]*10.0;//mat_a->m[6]*st[0]*10.0+ mat_a->m[7]*st[1]*10.0+ mat_a->m[8]*10.0;\r
+       world[3] = world[0] + dir[0];\r
+       world[4] = world[1] + dir[1];\r
+       world[5] = world[2] + dir[2];\r
+       //</Optimize>\r
+\r
+       double[] camera=wk_check_dir_camera;//[2][2];\r
+       for( i = 0; i < 2; i++ ) {\r
+           h = cpara[2*4+0] * world[i*3+0]+ cpara[2*4+1] * world[i*3+1]+ cpara[2*4+2] * world[i*3+2];\r
+           if( h == 0.0 ){\r
+               throw new NyARException();\r
+           }\r
+           camera[i*2+0] = (cpara[0*4+0] * world[i*3+0]+ cpara[0*4+1] * world[i*3+1]+ cpara[0*4+2] * world[i*3+2]) / h;\r
+           camera[i*2+1] = (cpara[1*4+0] * world[i*3+0]+ cpara[1*4+1] * world[i*3+1]+ cpara[1*4+2] * world[i*3+2]) / h;\r
+       }\r
+       //<Optimize>\r
+       //v[0][0] = ed[0] - st[0];\r
+       //v[0][1] = ed[1] - st[1];\r
+       //v[1][0] = camera[1][0] - camera[0][0];\r
+       //v[1][1] = camera[1][1] - camera[0][1];\r
+       double v=(ed[0]-st[0])*(camera[2]-camera[0])+(ed[1]-st[1])*(camera[3]-camera[1]);\r
+       //</Optimize>\r
+       if(v<0) {//if( v[0][0]*v[1][0] + v[0][1]*v[1][1] < 0 ) {\r
+           dir[0] = -dir[0];\r
+           dir[1] = -dir[1];\r
+           dir[2] = -dir[2];\r
+       }\r
+    }\r
+    /*int check_rotation( double rot[2][3] )*/\r
+    protected final static void check_rotation( double rot[][] ) throws NyARException\r
+    {\r
+       double[]  v1=new double[3], v2=new double[3], v3=new double[3];\r
+       double  ca, cb, k1, k2, k3, k4;\r
+       double  a, b, c, d;\r
+       double  p1, q1, r1;\r
+       double  p2, q2, r2;\r
+       double  p3, q3, r3;\r
+       double  p4, q4, r4;\r
+       double  w;\r
+       double  e1, e2, e3, e4;\r
+       int     f;\r
+\r
+       v1[0] = rot[0][0];\r
+       v1[1] = rot[0][1];\r
+       v1[2] = rot[0][2];\r
+       v2[0] = rot[1][0];\r
+       v2[1] = rot[1][1];\r
+       v2[2] = rot[1][2];\r
+       v3[0] = v1[1]*v2[2] - v1[2]*v2[1];\r
+       v3[1] = v1[2]*v2[0] - v1[0]*v2[2];\r
+       v3[2] = v1[0]*v2[1] - v1[1]*v2[0];\r
+       w = Math.sqrt( v3[0]*v3[0]+v3[1]*v3[1]+v3[2]*v3[2] );\r
+       if( w == 0.0 ){\r
+           throw new NyARException();\r
+       }\r
+       v3[0] /= w;\r
+       v3[1] /= w;\r
+       v3[2] /= w;\r
+\r
+       cb = v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];\r
+       if( cb < 0 ) cb *= -1.0;\r
+       ca = (Math.sqrt(cb+1.0) + Math.sqrt(1.0-cb)) * 0.5;\r
+\r
+       if( v3[1]*v1[0] - v1[1]*v3[0] != 0.0 ) {\r
+           f = 0;\r
+       }\r
+       else {\r
+           if( v3[2]*v1[0] - v1[2]*v3[0] != 0.0 ) {\r
+               w = v1[1]; v1[1] = v1[2]; v1[2] = w;\r
+               w = v3[1]; v3[1] = v3[2]; v3[2] = w;\r
+               f = 1;\r
+           }\r
+           else {\r
+               w = v1[0]; v1[0] = v1[2]; v1[2] = w;\r
+               w = v3[0]; v3[0] = v3[2]; v3[2] = w;\r
+               f = 2;\r
+           }\r
+       }\r
+       if( v3[1]*v1[0] - v1[1]*v3[0] == 0.0 ){\r
+           throw new NyARException();\r
+       }\r
+       k1 = (v1[1]*v3[2] - v3[1]*v1[2]) / (v3[1]*v1[0] - v1[1]*v3[0]);\r
+       k2 = (v3[1] * ca) / (v3[1]*v1[0] - v1[1]*v3[0]);\r
+       k3 = (v1[0]*v3[2] - v3[0]*v1[2]) / (v3[0]*v1[1] - v1[0]*v3[1]);\r
+       k4 = (v3[0] * ca) / (v3[0]*v1[1] - v1[0]*v3[1]);\r
+\r
+       a = k1*k1 + k3*k3 + 1;\r
+       b = k1*k2 + k3*k4;\r
+       c = k2*k2 + k4*k4 - 1;\r
+\r
+       d = b*b - a*c;\r
+       if( d < 0 ){\r
+           throw new NyARException();\r
+       }\r
+       r1 = (-b + Math.sqrt(d))/a;\r
+       p1 = k1*r1 + k2;\r
+       q1 = k3*r1 + k4;\r
+       r2 = (-b - Math.sqrt(d))/a;\r
+       p2 = k1*r2 + k2;\r
+       q2 = k3*r2 + k4;\r
+       if( f == 1 ) {\r
+           w = q1; q1 = r1; r1 = w;\r
+           w = q2; q2 = r2; r2 = w;\r
+           w = v1[1]; v1[1] = v1[2]; v1[2] = w;\r
+           w = v3[1]; v3[1] = v3[2]; v3[2] = w;\r
+           f = 0;\r
+       }\r
+       if( f == 2 ) {\r
+           w = p1; p1 = r1; r1 = w;\r
+           w = p2; p2 = r2; r2 = w;\r
+           w = v1[0]; v1[0] = v1[2]; v1[2] = w;\r
+           w = v3[0]; v3[0] = v3[2]; v3[2] = w;\r
+           f = 0;\r
+       }\r
+\r
+       if( v3[1]*v2[0] - v2[1]*v3[0] != 0.0 ) {\r
+           f = 0;\r
+       }else {\r
+           if( v3[2]*v2[0] - v2[2]*v3[0] != 0.0 ) {\r
+               w = v2[1]; v2[1] = v2[2]; v2[2] = w;\r
+               w = v3[1]; v3[1] = v3[2]; v3[2] = w;\r
+               f = 1;\r
+           }\r
+           else {\r
+               w = v2[0]; v2[0] = v2[2]; v2[2] = w;\r
+               w = v3[0]; v3[0] = v3[2]; v3[2] = w;\r
+               f = 2;\r
+           }\r
+       }\r
+       if( v3[1]*v2[0] - v2[1]*v3[0] == 0.0 ){\r
+           throw new NyARException();\r
+       }\r
+       k1 = (v2[1]*v3[2] - v3[1]*v2[2]) / (v3[1]*v2[0] - v2[1]*v3[0]);\r
+       k2 = (v3[1] * ca) / (v3[1]*v2[0] - v2[1]*v3[0]);\r
+       k3 = (v2[0]*v3[2] - v3[0]*v2[2]) / (v3[0]*v2[1] - v2[0]*v3[1]);\r
+       k4 = (v3[0] * ca) / (v3[0]*v2[1] - v2[0]*v3[1]);\r
+\r
+       a = k1*k1 + k3*k3 + 1;\r
+       b = k1*k2 + k3*k4;\r
+       c = k2*k2 + k4*k4 - 1;\r
+\r
+       d = b*b - a*c;\r
+       if( d < 0 ){\r
+           throw new NyARException();\r
+       }\r
+       r3 = (-b + Math.sqrt(d))/a;\r
+       p3 = k1*r3 + k2;\r
+       q3 = k3*r3 + k4;\r
+       r4 = (-b - Math.sqrt(d))/a;\r
+       p4 = k1*r4 + k2;\r
+       q4 = k3*r4 + k4;\r
+       if( f == 1 ) {\r
+           w = q3; q3 = r3; r3 = w;\r
+           w = q4; q4 = r4; r4 = w;\r
+           w = v2[1]; v2[1] = v2[2]; v2[2] = w;\r
+           w = v3[1]; v3[1] = v3[2]; v3[2] = w;\r
+           f = 0;\r
+       }\r
+       if( f == 2 ) {\r
+           w = p3; p3 = r3; r3 = w;\r
+           w = p4; p4 = r4; r4 = w;\r
+           w = v2[0]; v2[0] = v2[2]; v2[2] = w;\r
+           w = v3[0]; v3[0] = v3[2]; v3[2] = w;\r
+           f = 0;\r
+       }\r
+\r
+       e1 = p1*p3+q1*q3+r1*r3;\r
+       if( e1 < 0 ){\r
+           e1 = -e1;\r
+       }\r
+       e2 = p1*p4+q1*q4+r1*r4;\r
+       if( e2 < 0 ){\r
+           e2 = -e2;\r
+       }\r
+       e3 = p2*p3+q2*q3+r2*r3;\r
+       if( e3 < 0 ){\r
+           e3 = -e3;\r
+       }\r
+       e4 = p2*p4+q2*q4+r2*r4;\r
+       if( e4 < 0 ){\r
+           e4 = -e4;\r
+       }\r
+       if( e1 < e2 ) {\r
+           if( e1 < e3 ) {\r
+               if( e1 < e4 ) {\r
+                   rot[0][0] = p1;\r
+                   rot[0][1] = q1;\r
+                   rot[0][2] = r1;\r
+                   rot[1][0] = p3;\r
+                   rot[1][1] = q3;\r
+                   rot[1][2] = r3;\r
+               }\r
+               else {\r
+                   rot[0][0] = p2;\r
+                   rot[0][1] = q2;\r
+                   rot[0][2] = r2;\r
+                   rot[1][0] = p4;\r
+                   rot[1][1] = q4;\r
+                   rot[1][2] = r4;\r
+               }\r
+           }\r
+           else {\r
+               if( e3 < e4 ) {\r
+                   rot[0][0] = p2;\r
+                   rot[0][1] = q2;\r
+                   rot[0][2] = r2;\r
+                   rot[1][0] = p3;\r
+                   rot[1][1] = q3;\r
+                   rot[1][2] = r3;\r
+               }\r
+               else {\r
+                   rot[0][0] = p2;\r
+                   rot[0][1] = q2;\r
+                   rot[0][2] = r2;\r
+                   rot[1][0] = p4;\r
+                   rot[1][1] = q4;\r
+                   rot[1][2] = r4;\r
+               }\r
+           }\r
+       }\r
+       else {\r
+           if( e2 < e3 ) {\r
+               if( e2 < e4 ) {\r
+                   rot[0][0] = p1;\r
+                   rot[0][1] = q1;\r
+                   rot[0][2] = r1;\r
+                   rot[1][0] = p4;\r
+                   rot[1][1] = q4;\r
+                   rot[1][2] = r4;\r
+               }\r
+               else {\r
+                   rot[0][0] = p2;\r
+                   rot[0][1] = q2;\r
+                   rot[0][2] = r2;\r
+                   rot[1][0] = p4;\r
+                   rot[1][1] = q4;\r
+                   rot[1][2] = r4;\r
+               }\r
+           }\r
+           else {\r
+               if( e3 < e4 ) {\r
+                   rot[0][0] = p2;\r
+                   rot[0][1] = q2;\r
+                   rot[0][2] = r2;\r
+                   rot[1][0] = p3;\r
+                   rot[1][1] = q3;\r
+                   rot[1][2] = r3;\r
+               }\r
+               else {\r
+                   rot[0][0] = p2;\r
+                   rot[0][1] = q2;\r
+                   rot[0][2] = r2;\r
+                   rot[1][0] = p4;\r
+                   rot[1][1] = q4;\r
+                   rot[1][2] = r4;\r
+               }\r
+           }\r
+       }\r
+    }  \r
+    /**\r
+     * パラメタa,b,cからrotを計算してインスタンスに保存する。\r
+     * rotを1次元配列に変更\r
+     * Optimize:2008.04.20:STEP[253→186]\r
+     * @param a\r
+     * @param b\r
+     * @param c\r
+     * @param o_rot\r
+     */\r
+    protected final static void arGetRot( double a, double b, double c,double[] o_rot)\r
+    {\r
+       double   sina, sinb, sinc;\r
+       double   cosa, cosb, cosc;\r
+\r
+       sina = Math.sin(a);\r
+       cosa = Math.cos(a);\r
+       sinb = Math.sin(b);\r
+       cosb = Math.cos(b);\r
+       sinc = Math.sin(c);\r
+       cosc = Math.cos(c);\r
+       //Optimize\r
+       double CACA,SASA,SACA,SASB,CASB;\r
+       CACA=cosa*cosa;\r
+       SASA=sina*sina;\r
+       SACA=sina*cosa;\r
+       SASB=sina*sinb;\r
+       CASB=cosa*sinb;\r
+\r
+       o_rot[0] = CACA*cosb*cosc+SASA*cosc+SACA*cosb*sinc-SACA*sinc;\r
+       o_rot[1] = -CACA*cosb*sinc-SASA*sinc+SACA*cosb*cosc-SACA*cosc;\r
+       o_rot[2] = CASB;\r
+       o_rot[3] = SACA*cosb*cosc-SACA*cosc+SASA*cosb*sinc+CACA*sinc;\r
+       o_rot[4] = -SACA*cosb*sinc+SACA*sinc+SASA*cosb*cosc+CACA*cosc;\r
+       o_rot[5] = SASB;\r
+       o_rot[6] = -CASB*cosc-SASB*sinc;\r
+       o_rot[7] = CASB*sinc-SASB*cosc;\r
+       o_rot[8] = cosb;\r
+    }\r
+    /**\r
+     * int arGetAngle( double rot[3][3], double *wa, double *wb, double *wc )\r
+     * Optimize:2008.04.20:STEP[481→433]\r
+     * @param rot\r
+     * 2次元配列を1次元化してあります。\r
+     * @param o_abc\r
+     * @return\r
+     */\r
+    protected final int arGetAngle(double[] o_abc)\r
+    {\r
+       double      a, b, c;\r
+       double      sina, cosa, sinb, cosb, sinc, cosc;\r
+       double[] rot=array;\r
+       if( rot[8] > 1.0 ) {//<Optimize/>if( rot[2][2] > 1.0 ) {\r
+           rot[8] = 1.0;//<Optimize/>rot[2][2] = 1.0;\r
+       }else if( rot[8] < -1.0 ) {//<Optimize/>}else if( rot[2][2] < -1.0 ) {\r
+           rot[8] = -1.0;//<Optimize/>rot[2][2] = -1.0;\r
+       }\r
+       cosb = rot[8];//<Optimize/>cosb = rot[2][2];\r
+       b = Math.acos( cosb );\r
+       sinb = Math.sin( b );\r
+       if( b >= 0.000001 || b <= -0.000001) {\r
+           cosa = rot[2] / sinb;//<Optimize/>cosa = rot[0][2] / sinb;\r
+           sina = rot[5] / sinb;//<Optimize/>sina = rot[1][2] / sinb;\r
+           if( cosa > 1.0 ) {\r
+               /* printf("cos(alph) = %f\n", cosa); */\r
+               cosa = 1.0;\r
+               sina = 0.0;\r
+           }\r
+           if( cosa < -1.0 ) {\r
+               /* printf("cos(alph) = %f\n", cosa); */\r
+               cosa = -1.0;\r
+               sina =  0.0;\r
+           }\r
+           if( sina > 1.0 ) {\r
+               /* printf("sin(alph) = %f\n", sina); */\r
+               sina = 1.0;\r
+               cosa = 0.0;\r
+           }\r
+           if( sina < -1.0 ) {\r
+               /* printf("sin(alph) = %f\n", sina); */\r
+               sina = -1.0;\r
+               cosa =  0.0;\r
+           }\r
+           a = Math.acos( cosa );\r
+           if( sina < 0 ){\r
+               a = -a;\r
+           }\r
+           //<Optimize>\r
+           //sinc =  (rot[2][1]*rot[0][2]-rot[2][0]*rot[1][2])/ (rot[0][2]*rot[0][2]+rot[1][2]*rot[1][2]);\r
+           //cosc =  -(rot[0][2]*rot[2][0]+rot[1][2]*rot[2][1])/ (rot[0][2]*rot[0][2]+rot[1][2]*rot[1][2]);\r
+           sinc =  (rot[7]*rot[2]-rot[6]*rot[5])/ (rot[2]*rot[2]+rot[5]*rot[5]);\r
+           cosc =  -(rot[2]*rot[6]+rot[5]*rot[7])/ (rot[2]*rot[2]+rot[5]*rot[5]);\r
+           //</Optimize>\r
+\r
+           if( cosc > 1.0 ) {\r
+               /* printf("cos(r) = %f\n", cosc); */\r
+               cosc = 1.0;\r
+               sinc = 0.0;\r
+           }\r
+           if( cosc < -1.0 ) {\r
+               /* printf("cos(r) = %f\n", cosc); */\r
+               cosc = -1.0;\r
+               sinc =  0.0;\r
+           }\r
+           if( sinc > 1.0 ) {\r
+               /* printf("sin(r) = %f\n", sinc); */\r
+               sinc = 1.0;\r
+               cosc = 0.0;\r
+           }\r
+           if( sinc < -1.0 ) {\r
+               /* printf("sin(r) = %f\n", sinc); */\r
+               sinc = -1.0;\r
+               cosc =  0.0;\r
+           }\r
+           c = Math.acos( cosc );\r
+           if( sinc < 0 ){\r
+               c = -c;\r
+           }\r
+       }else {\r
+           a = b = 0.0;\r
+           cosa = cosb = 1.0;\r
+           sina = sinb = 0.0;\r
+           cosc = rot[0];//<Optimize/>cosc = rot[0][0];\r
+           sinc = rot[1];//<Optimize/>sinc = rot[1][0];\r
+           if( cosc > 1.0 ) {\r
+               /* printf("cos(r) = %f\n", cosc); */\r
+               cosc = 1.0;\r
+               sinc = 0.0;\r
+           }\r
+           if( cosc < -1.0 ) {\r
+               /* printf("cos(r) = %f\n", cosc); */\r
+               cosc = -1.0;\r
+               sinc =  0.0;\r
+           }\r
+           if( sinc > 1.0 ) {\r
+               /* printf("sin(r) = %f\n", sinc); */\r
+               sinc = 1.0;\r
+               cosc = 0.0;\r
+           }\r
+           if( sinc < -1.0 ) {\r
+               /* printf("sin(r) = %f\n", sinc); */\r
+               sinc = -1.0;\r
+               cosc =  0.0;\r
+           }\r
+           c = Math.acos( cosc );\r
+           if( sinc < 0 ){\r
+               c = -c;\r
+           }\r
+       }\r
+       o_abc[0]=a;//wa.value=a;//*wa = a;\r
+       o_abc[1]=b;//wb.value=b;//*wb = b;\r
+       o_abc[2]=c;//wc.value=c;//*wc = c;\r
+       return 0;\r
+    }    \r
+}\r
+\r
+/**\r
+ * NyARModifyMatrixの最適化バージョン1\r
+ * 配列の1次元化、計算ステップの圧縮等の最適化をしてみた。\r
+ *\r
+ */\r
+class NyARTransRot_O1 extends NyARTransRot_OptimizeCommon\r
+{\r
+    public NyARTransRot_O1(NyARParam i_param,int i_number_of_vertex) throws NyARException\r
+    {\r
+       super(i_param,i_number_of_vertex);\r
+    }\r
+    /**\r
+     * int arGetInitRot( ARMarkerInfo *marker_info, double cpara[3][4], double rot[3][3] )\r
+     * Optimize:2008.04.20:STEP[716→698]\r
+     * @param marker_info\r
+     * @param i_direction\r
+     * @param i_param\r
+     * @throws NyARException\r
+     */\r
+    public final void initRot(NyARSquare marker_info,int i_direction) throws NyARException\r
+    {\r
+       double cpara[]= cparam.get34Array();\r
+       double[][]  wdir=new double[3][3];\r
+       double  w, w1, w2, w3;\r
+       int     dir;\r
+       int     j;\r
+\r
+       dir = i_direction;\r
+\r
+       for( j = 0; j < 2; j++ ) {\r
+           w1 = marker_info.line[(4-dir+j)%4][0] * marker_info.line[(6-dir+j)%4][1]- marker_info.line[(6-dir+j)%4][0] * marker_info.line[(4-dir+j)%4][1];\r
+           w2 = marker_info.line[(4-dir+j)%4][1] * marker_info.line[(6-dir+j)%4][2]- marker_info.line[(6-dir+j)%4][1] * marker_info.line[(4-dir+j)%4][2];\r
+           w3 = marker_info.line[(4-dir+j)%4][2] * marker_info.line[(6-dir+j)%4][0]- marker_info.line[(6-dir+j)%4][2] * marker_info.line[(4-dir+j)%4][0];\r
+\r
+           wdir[j][0] =  w1*(cpara[0*4+1]*cpara[1*4+2]-cpara[0*4+2]*cpara[1*4+1])+  w2*cpara[1*4+1]-  w3*cpara[0*4+1];\r
+           wdir[j][1] = -w1*cpara[0*4+0]*cpara[1*4+2]+  w3*cpara[0*4+0];\r
+           wdir[j][2] =  w1*cpara[0*4+0]*cpara[1*4+1];\r
+           w = Math.sqrt( wdir[j][0]*wdir[j][0]+ wdir[j][1]*wdir[j][1]+ wdir[j][2]*wdir[j][2] );\r
+           wdir[j][0] /= w;\r
+           wdir[j][1] /= w;\r
+           wdir[j][2] /= w;\r
+       }\r
+\r
+       //以下3ケースは、計算エラーのときは例外が発生する。\r
+       check_dir(wdir[0], marker_info.sqvertex[(4-dir)%4],marker_info.sqvertex[(5-dir)%4], cpara);\r
+\r
+       check_dir(wdir[1], marker_info.sqvertex[(7-dir)%4],marker_info.sqvertex[(4-dir)%4], cpara);\r
+\r
+       check_rotation(wdir);\r
+\r
+\r
+       wdir[2][0] = wdir[0][1]*wdir[1][2] - wdir[0][2]*wdir[1][1];\r
+       wdir[2][1] = wdir[0][2]*wdir[1][0] - wdir[0][0]*wdir[1][2];\r
+       wdir[2][2] = wdir[0][0]*wdir[1][1] - wdir[0][1]*wdir[1][0];\r
+       w = Math.sqrt( wdir[2][0]*wdir[2][0]+ wdir[2][1]*wdir[2][1]+ wdir[2][2]*wdir[2][2] );\r
+       wdir[2][0] /= w;\r
+       wdir[2][1] /= w;\r
+       wdir[2][2] /= w;\r
+       /*\r
+        if( wdir[2][2] < 0 ) {\r
+            wdir[2][0] /= -w;\r
+            wdir[2][1] /= -w;\r
+            wdir[2][2] /= -w;\r
+        }\r
+        else {\r
+            wdir[2][0] /= w;\r
+            wdir[2][1] /= w;\r
+            wdir[2][2] /= w;\r
+        }\r
+        */\r
+       //<Optimize>\r
+       //rot[0][0] = wdir[0][0];\r
+       //rot[1][0] = wdir[0][1];\r
+       //rot[2][0] = wdir[0][2];\r
+       //rot[0][1] = wdir[1][0];\r
+       //rot[1][1] = wdir[1][1];\r
+       //rot[2][1] = wdir[1][2];\r
+       //rot[0][2] = wdir[2][0];\r
+       //rot[1][2] = wdir[2][1];\r
+       //rot[2][2] = wdir[2][2];\r
+       double[] rot=this.array;\r
+       rot[0] = wdir[0][0];\r
+       rot[3] = wdir[0][1];\r
+       rot[6] = wdir[0][2];\r
+       rot[1] = wdir[1][0];\r
+       rot[4] = wdir[1][1];\r
+       rot[7] = wdir[1][2];\r
+       rot[2] = wdir[2][0];\r
+       rot[5] = wdir[2][1];\r
+       rot[8] = wdir[2][2];\r
+       //</Optimize>    \r
+    }\r
+    private final double[] wk_arModifyMatrix_combo=new double[12];//[3][4];\r
+    private final double[] wk_arModifyMatrix_abc=new double[3];\r
+    private final double[] wk_arModifyMatrix_rot=new double[9];\r
+    /**\r
+     * Optimize:2008.04.20:STEP[456→-]\r
+     * @param rot\r
+     * [3x3]配列\r
+     * @param trans\r
+     * @param vertex\r
+     * @param pos2d\r
+     * @param num\r
+     * @return\r
+     */\r
+    public final double modifyMatrix(double trans[],double vertex[], double pos2d[]) throws NyARException\r
+    {\r
+       int num=this.number_of_vertex;\r
+       double    factor;\r
+       double    a1, b1, c1;\r
+       double    a2, b2, c2;\r
+       double    ma = 0.0, mb = 0.0, mc = 0.0;\r
+       double    hx, hy, h, x, y;\r
+       double    err, minerr=0;\r
+       int       t1, t2, t3;\r
+       int       s1 = 0, s2 = 0, s3 = 0;\r
+       int       i, j;\r
+       double[] combo=this.wk_arModifyMatrix_combo;//arGetNewMatrixで初期化されるので初期化不要//new double[3][4];\r
+       double[] abc=wk_arModifyMatrix_abc;\r
+       double[] rot=wk_arModifyMatrix_rot;\r
+\r
+       arGetAngle(abc);//arGetAngle( rot, &a, &b, &c );\r
+       a2 = abc[0];\r
+       b2 = abc[1];\r
+       c2 = abc[2];\r
+       factor = 10.0*Math.PI/180.0;\r
+       for( j = 0; j < 10; j++ ) {\r
+           minerr = 1000000000.0;\r
+           for(t1=-1;t1<=1;t1++) {\r
+               for(t2=-1;t2<=1;t2++) {\r
+                   for(t3=-1;t3<=1;t3++) {\r
+                        a1 = a2 + factor*t1;\r
+                        b1 = b2 + factor*t2;\r
+                       c1 = c2 + factor*t3;\r
+                       arGetRot( a1, b1, c1,rot);\r
+                       arGetNewMatrix(rot,trans, null, combo );\r
+                       err = 0.0;\r
+                       for( i = 0; i < num; i++ ) {\r
+                           hx = combo[0] * vertex[i*3+0]+ combo[1] * vertex[i*3+1]+ combo[2] * vertex[i*3+2]+ combo[3];\r
+                           hy = combo[4] * vertex[i*3+0]+ combo[5] * vertex[i*3+1]+ combo[6] * vertex[i*3+2]+ combo[7];\r
+                           h  = combo[8] * vertex[i*3+0]+ combo[9] * vertex[i*3+1]+ combo[10] * vertex[i*3+2]+ combo[11];\r
+                           x = hx / h;\r
+                           y = hy / h;\r
+                           err += (pos2d[i*2+0] - x) * (pos2d[i*2+0] - x)+ (pos2d[i*2+1] - y) * (pos2d[i*2+1] - y);\r
+                       }\r
+                       if( err < minerr ) {\r
+                           minerr = err;\r
+                           ma = a1;\r
+                           mb = b1;\r
+                           mc = c1;\r
+                           s1 = t1;\r
+                           s2 = t2;\r
+                           s3 = t3;\r
+                       }\r
+                   }\r
+               }\r
+           }\r
+           if( s1 == 0 && s2 == 0 && s3 == 0 ){\r
+               factor *= 0.5;\r
+           }\r
+           a2 = ma;\r
+           b2 = mb;\r
+           c2 = mc;\r
+       }\r
+       arGetRot(ma, mb, mc,this.array);\r
+       /*  printf("factor = %10.5f\n", factor*180.0/MD_PI); */\r
+       return minerr/num;\r
+    }\r
+    private final double[] wk_cpara2_arGetNewMatrix=new double[12];//[3][4];\r
+    /**\r
+     * Optimize:2008.04.20:STEP[569->432]\r
+     * @param i_rot\r
+     * [9]\r
+     * @param trans\r
+     * @param trans2\r
+     * @param ret\r
+     * double[3x4]配列\r
+     * @return\r
+     */\r
+    private final int arGetNewMatrix(double[] i_rot,double trans[], double trans2[][], double ret[]) throws NyARException\r
+    {\r
+       final double cpara[]=cparam.get34Array();\r
+       final double[] cpara2;  //この関数で初期化される。\r
+       int j,j_idx;\r
+//     double[] cpara_pt;\r
+       //cparaの2次元配列→1次元に変換して計算\r
+       if( trans2 != null ) {\r
+           cpara2=wk_cpara2_arGetNewMatrix;    //この関数で初期化される。\r
+\r
+           for( j = 0; j < 3; j++ ) {\r
+//             Optimize(使わないから最適化してない)\r
+               NyARException.trap("未チェックのパス");\r
+               cpara2[j*4+0] = cpara[j*4+0] * trans2[0][0]+ cpara[j*4+1] * trans2[1][0]+ cpara[j*4+2] * trans2[2][0];\r
+               cpara2[j*4+1] = cpara[j*4+0] * trans2[0][1]+ cpara[j*4+1] * trans2[1][1]+ cpara[j*4+2] * trans2[2][1];\r
+               cpara2[j*4+2] = cpara[j*4+0] * trans2[0][2]+ cpara[j*4+1] * trans2[1][2]+ cpara[j*4+2] * trans2[2][2];\r
+               cpara2[j*4+3] = cpara[j*4+0] * trans2[0][3]+ cpara[j*4+1] * trans2[1][3]+ cpara[j*4+2] * trans2[2][3];\r
+           }\r
+       }else{\r
+           cpara2=cpara;//cparaの値をそのまま使う\r
+       }\r
+       for( j = 0; j < 3; j++ ) {\r
+           //cpara2_pt=cpara2[j];\r
+           j_idx=j*4;\r
+           //<Optimize>\r
+           //ret[j][0] = cpara2_pt[0] * rot[0][0]+ cpara2_pt[1] * rot[1][0]+ cpara2_pt[2] * rot[2][0];\r
+           //ret[j][1] = cpara2_pt[0] * rot[0][1]+ cpara2_pt[1] * rot[1][1]+ cpara2_pt[2] * rot[2][1];\r
+           //ret[j][2] = cpara2_pt[0] * rot[0][2]+ cpara2_pt[1] * rot[1][2]+ cpara2_pt[2] * rot[2][2];\r
+           //ret[j][3] = cpara2_pt[0] * trans[0]+ cpara2_pt[1] * trans[1]+ cpara2_pt[2] * trans[2]+ cpara2_pt[3];\r
+           ret[j_idx+0] = cpara2[j_idx+0] * i_rot[0]+ cpara2[j_idx+1] * i_rot[3]+ cpara2[j_idx+2] * i_rot[6];\r
+           ret[j_idx+1] = cpara2[j_idx+0] * i_rot[1]+ cpara2[j_idx+1] * i_rot[4]+ cpara2[j_idx+2] * i_rot[7];\r
+           ret[j_idx+2] = cpara2[j_idx+0] * i_rot[2]+ cpara2[j_idx+1] * i_rot[5]+ cpara2[j_idx+2] * i_rot[8];\r
+           ret[j_idx+3] = cpara2[j_idx+0] * trans[0]+ cpara2[j_idx+1] * trans[1]+ cpara2[j_idx+2] * trans[2]+ cpara2[j_idx+3];\r
+           //</Optimize>\r
+       }\r
+       return(0);\r
+    }    \r
+}\r
+\r
+/**\r
+ * NyARModifyMatrixの最適化バージョン2\r
+ * 計算手順の変更、構造変更など含む最適化をしたもの\r
+ *\r
+ */\r
+class NyARTransRot_O2 extends NyARTransRot_OptimizeCommon\r
+{\r
+    public NyARTransRot_O2(NyARParam i_param,int i_number_of_vertex) throws NyARException\r
+    {\r
+       super(i_param,i_number_of_vertex);\r
+    }  \r
+    \r
+    //private double CACA,SASA,SACA,CA,SA;    \r
+    private double CACA,SASA,SACA,CA,SA;\r
+    final public void arGetRotA( double a)\r
+    {\r
+       double   sina,cosa;\r
+       sina = Math.sin(a);\r
+       cosa = Math.cos(a);\r
+       //Optimize\r
+       CACA=cosa*cosa;\r
+       SASA=sina*sina;\r
+       SACA=sina*cosa;\r
+       CA=cosa;\r
+       SA=sina;\r
+    }\r
+    private double CACACB,SACACB,SASACB,CASB,SASB;\r
+    final public void arGetRotB(double b,double[] o_rot)\r
+    {\r
+       double   sinb,cosb;\r
+       sinb = Math.sin(b);\r
+       cosb = Math.cos(b);\r
+       CACACB=CACA*cosb;\r
+       SACACB=SACA*cosb;\r
+       SASACB=SASA*cosb;\r
+       CASB=CA*sinb;\r
+       SASB=SA*sinb;\r
+       o_rot[2] = CASB;\r
+       o_rot[5] = SASB;\r
+       o_rot[8] = cosb;\r
+    }\r
+    /**\r
+     * 分割arGetRot\r
+     * @param c\r
+     */\r
+    public final void arGetRotC(double c,double[] o_rot)\r
+    {\r
+       double   sinc,cosc;\r
+       sinc = Math.sin(c);\r
+       cosc = Math.cos(c);\r
+       double SACASC,SACACBSC,SACACBCC,SACACC;\r
+       SACASC=SACA*sinc;\r
+       SACACC=SACA*cosc;\r
+       SACACBSC=SACACB*sinc;\r
+       SACACBCC=SACACB*cosc;\r
+       o_rot[0] = CACACB*cosc+SASA*cosc+SACACBSC-SACASC;\r
+       o_rot[1] = -CACACB*sinc-SASA*sinc+SACACBCC-SACACC;\r
+       o_rot[3] = SACACBCC-SACACC+SASACB*sinc+CACA*sinc;\r
+       o_rot[4] = -SACACBSC+SACASC+SASACB*cosc+CACA*cosc;\r
+       o_rot[6] = -CASB*cosc-SASB*sinc;\r
+       o_rot[7] = CASB*sinc-SASB*cosc;\r
+    }\r
+    private final double[][] wk_initRot_wdir=new double[3][3];\r
+    /**\r
+     * int arGetInitRot( ARMarkerInfo *marker_info, double cpara[3][4], double rot[3][3] )\r
+     * Optimize:2008.04.20:STEP[716→698]\r
+     * @param marker_info\r
+     * @param i_direction\r
+     * @param i_param\r
+     * @throws NyARException\r
+     */\r
+    public void initRot(NyARSquare marker_info,int i_direction) throws NyARException\r
+    {\r
+       double cpara[]= cparam.get34Array();\r
+       double[][]  wdir=wk_initRot_wdir;//この関数で初期化される\r
+       double  w, w1, w2, w3;\r
+       int     dir;\r
+       int     j;\r
+\r
+       dir = i_direction;\r
+\r
+       for( j = 0; j < 2; j++ ) {\r
+           w1 = marker_info.line[(4-dir+j)%4][0] * marker_info.line[(6-dir+j)%4][1]- marker_info.line[(6-dir+j)%4][0] * marker_info.line[(4-dir+j)%4][1];\r
+           w2 = marker_info.line[(4-dir+j)%4][1] * marker_info.line[(6-dir+j)%4][2]- marker_info.line[(6-dir+j)%4][1] * marker_info.line[(4-dir+j)%4][2];\r
+           w3 = marker_info.line[(4-dir+j)%4][2] * marker_info.line[(6-dir+j)%4][0]- marker_info.line[(6-dir+j)%4][2] * marker_info.line[(4-dir+j)%4][0];\r
+\r
+           wdir[j][0] =  w1*(cpara[0*4+1]*cpara[1*4+2]-cpara[0*4+2]*cpara[1*4+1])+  w2*cpara[1*4+1]-  w3*cpara[0*4+1];\r
+           wdir[j][1] = -w1*cpara[0*4+0]*cpara[1*4+2]+  w3*cpara[0*4+0];\r
+           wdir[j][2] =  w1*cpara[0*4+0]*cpara[1*4+1];\r
+           w = Math.sqrt( wdir[j][0]*wdir[j][0]+ wdir[j][1]*wdir[j][1]+ wdir[j][2]*wdir[j][2] );\r
+           wdir[j][0] /= w;\r
+           wdir[j][1] /= w;\r
+           wdir[j][2] /= w;\r
+       }\r
+\r
+       //以下3ケースは、計算エラーのときは例外が発生する。\r
+       check_dir(wdir[0], marker_info.sqvertex[(4-dir)%4],marker_info.sqvertex[(5-dir)%4], cpara);\r
+\r
+       check_dir(wdir[1], marker_info.sqvertex[(7-dir)%4],marker_info.sqvertex[(4-dir)%4], cpara);\r
+\r
+       check_rotation(wdir);\r
+\r
+\r
+       wdir[2][0] = wdir[0][1]*wdir[1][2] - wdir[0][2]*wdir[1][1];\r
+       wdir[2][1] = wdir[0][2]*wdir[1][0] - wdir[0][0]*wdir[1][2];\r
+       wdir[2][2] = wdir[0][0]*wdir[1][1] - wdir[0][1]*wdir[1][0];\r
+       w = Math.sqrt( wdir[2][0]*wdir[2][0]+ wdir[2][1]*wdir[2][1]+ wdir[2][2]*wdir[2][2] );\r
+       wdir[2][0] /= w;\r
+       wdir[2][1] /= w;\r
+       wdir[2][2] /= w;\r
+       //<Optimize>\r
+       //rot[0][0] = wdir[0][0];\r
+       //rot[1][0] = wdir[0][1];\r
+       //rot[2][0] = wdir[0][2];\r
+       //rot[0][1] = wdir[1][0];\r
+       //rot[1][1] = wdir[1][1];\r
+       //rot[2][1] = wdir[1][2];\r
+       //rot[0][2] = wdir[2][0];\r
+       //rot[1][2] = wdir[2][1];\r
+       //rot[2][2] = wdir[2][2];\r
+       double[] rot=this.array;\r
+       rot[0] = wdir[0][0];\r
+       rot[3] = wdir[0][1];\r
+       rot[6] = wdir[0][2];\r
+       rot[1] = wdir[1][0];\r
+       rot[4] = wdir[1][1];\r
+       rot[7] = wdir[1][2];\r
+       rot[2] = wdir[2][0];\r
+       rot[5] = wdir[2][1];\r
+       rot[8] = wdir[2][2];\r
+       //</Optimize>    \r
+    }\r
+    private final double[] wk_arModifyMatrix_combo=new double[12];//[3][4];\r
+    private final double[] wk_arModifyMatrix_abc=new double[3];\r
+    private final double[] wk_arModifyMatrix_rot=new double[9];    \r
+    /**\r
+     * arGetRot計算を階層化したModifyMatrix\r
+     * @param nyrot\r
+     * @param trans\r
+     * @param vertex\r
+     * @param pos2d\r
+     * @param num\r
+     * @return\r
+     * @throws NyARException\r
+     */\r
+    public double modifyMatrix(double trans[],double vertex[], double pos2d[]) throws NyARException\r
+    {\r
+       int num=this.number_of_vertex;\r
+       double    factor;\r
+       double    a1, b1, c1;\r
+       double    a2, b2, c2;\r
+       double    ma = 0.0, mb = 0.0, mc = 0.0;\r
+       double    hx, hy, h, x, y;\r
+       double    err, minerr=0;\r
+       int       t1, t2, t3;\r
+       int       s1 = 0, s2 = 0, s3 = 0;\r
+       int       i, j;\r
+       final double[] combo=this.wk_arModifyMatrix_combo;//arGetNewMatrixで初期化されるので初期化不要//new double[3][4];\r
+       final double[] abc=wk_arModifyMatrix_abc;\r
+       double[] rot=wk_arModifyMatrix_rot;\r
+\r
+       arGetAngle(abc);//arGetAngle( rot, &a, &b, &c );\r
+       a2 = abc[0];\r
+       b2 = abc[1];\r
+       c2 = abc[2];\r
+       factor = 10.0*Math.PI/180.0;\r
+\r
+       nyatla_arGetNewMatrix_row3(trans,combo);//comboの3行目を先に計算\r
+       for( j = 0; j < 10; j++ ) {\r
+           minerr = 1000000000.0;\r
+           for(t1=-1;t1<=1;t1++) {\r
+                a1 = a2 + factor*t1;\r
+               arGetRotA(a1);\r
+               for(t2=-1;t2<=1;t2++) {\r
+                    b1 = b2 + factor*t2;\r
+                    arGetRotB(b1,rot);\r
+                   for(t3=-1;t3<=1;t3++) {\r
+                       c1 = c2 + factor*t3;\r
+                       arGetRotC(c1,rot);\r
+                       //comboの0-2行目を計算\r
+                       nyatla_arGetNewMatrix_row012(rot,trans,combo);//第二パラメタは常にnull//arGetNewMatrix(trans, null, combo );\r
+                       err = 0.0;\r
+                       for( i = 0; i < num; i++ ) {\r
+                           hx = combo[0] * vertex[i*3+0]+ combo[1] * vertex[i*3+1]+ combo[2] * vertex[i*3+2]+ combo[3];\r
+                           hy = combo[4] * vertex[i*3+0]+ combo[5] * vertex[i*3+1]+ combo[6] * vertex[i*3+2]+ combo[7];\r
+                           h  = combo[8] * vertex[i*3+0]+ combo[9] * vertex[i*3+1]+ combo[10] * vertex[i*3+2]+ combo[11];\r
+                           x = hx / h;\r
+                           y = hy / h;\r
+                           err += (pos2d[i*2+0] - x) * (pos2d[i*2+0] - x)+ (pos2d[i*2+1] - y) * (pos2d[i*2+1] - y);\r
+                       }\r
+                       if( err < minerr ) {\r
+                           minerr = err;\r
+                           ma = a1;\r
+                           mb = b1;\r
+                           mc = c1;\r
+                           s1 = t1;\r
+                           s2 = t2;\r
+                           s3 = t3;\r
+                       }\r
+                   }\r
+               }\r
+           }\r
+           if( s1 == 0 && s2 == 0 && s3 == 0 ){\r
+               factor *= 0.5;\r
+           }\r
+           a2 = ma;\r
+           b2 = mb;\r
+           c2 = mc;\r
+       }\r
+       arGetRot(ma,mb,mc,this.array);\r
+       /*  printf("factor = %10.5f\n", factor*180.0/MD_PI); */\r
+       return minerr/num;\r
+    }\r
+    /**\r
+     * arGetNewMatrixの0-2行目を初期化する関数\r
+     * Optimize:2008.04.20:STEP[569->144]\r
+     * @param i_rot\r
+     * @param trans\r
+     * @param trans2\r
+     * @param ret\r
+     * double[3x4]配列\r
+     * @return\r
+     */\r
+    private final void nyatla_arGetNewMatrix_row012(double i_rot[],double trans[],double ret[]) throws NyARException\r
+    {\r
+       int j;\r
+       double c0,c1,c2;\r
+       final double cpara2[]=cparam.get34Array();\r
+       for( j = 0; j < 3; j++ ) {\r
+           //cpara2_pt=cpara2[j];\r
+           c0=cpara2[j*4+0];\r
+           c1=cpara2[j*4+1];\r
+           c2=cpara2[j*4+2];\r
+           ret[j*4+0] = c0 * i_rot[0]+ c1 * i_rot[3]+ c2 * i_rot[6];\r
+           ret[j*4+1] = c0 * i_rot[1]+ c1 * i_rot[4]+ c2 * i_rot[7];\r
+           ret[j*4+2] = c0 * i_rot[2]+ c1 * i_rot[5]+ c2 * i_rot[8];\r
+           //</Optimize>\r
+       }\r
+       return;\r
+    }\r
+    /**\r
+     * arGetNewMatrixの3行目を初期化する関数\r
+     * @param trans\r
+     * @param ret\r
+     * @throws NyARException\r
+     */\r
+    private final void nyatla_arGetNewMatrix_row3(double trans[],double ret[]) throws NyARException\r
+    {\r
+       final double cpara2[]=cparam.get34Array();\r
+       int j,j_idx;\r
+       for( j = 0; j < 3; j++ ) {\r
+           j_idx=j*4;\r
+           ret[j_idx+3] = cpara2[j_idx+0] * trans[0]+ cpara2[j_idx+1] * trans[1]+ cpara2[j_idx+2] * trans[2]+ cpara2[j_idx+3];\r
+       }\r
+       return;\r
+    }          \r
+}\r
+\r
+\r
+/**\r
+ * NyARModifyMatrixの最適化バージョン3\r
+ * 計算速度のみを追求する\r
+ *\r
+ */\r
+class NyARTransRot_O3 extends NyARTransRot_OptimizeCommon\r
+{\r
+    public NyARTransRot_O3(NyARParam i_param,int i_number_of_vertex) throws NyARException\r
+    {\r
+       super(i_param,i_number_of_vertex);\r
+       if(i_number_of_vertex!=4){\r
+           //4以外の頂点数は処理しない\r
+           throw new NyARException();\r
+       }\r
+    }  \r
+    \r
+    //private double CACA,SASA,SACA,CA,SA;    \r
+    private final double[][] wk_initRot_wdir=new double[3][3];\r
+    /**\r
+     * int arGetInitRot( ARMarkerInfo *marker_info, double cpara[3][4], double rot[3][3] )\r
+     * Optimize:2008.04.20:STEP[716→698]\r
+     * @param marker_info\r
+     * @param i_direction\r
+     * @param i_param\r
+     * @throws NyARException\r
+     */\r
+    public void initRot(NyARSquare marker_info,int i_direction) throws NyARException\r
+    {\r
+       double cpara[]= cparam.get34Array();\r
+       double[][]  wdir=wk_initRot_wdir;//この関数で初期化される\r
+       double  w, w1, w2, w3;\r
+       int     dir;\r
+       int     j;\r
+\r
+       dir = i_direction;\r
+\r
+       for( j = 0; j < 2; j++ ) {\r
+           w1 = marker_info.line[(4-dir+j)%4][0] * marker_info.line[(6-dir+j)%4][1]- marker_info.line[(6-dir+j)%4][0] * marker_info.line[(4-dir+j)%4][1];\r
+           w2 = marker_info.line[(4-dir+j)%4][1] * marker_info.line[(6-dir+j)%4][2]- marker_info.line[(6-dir+j)%4][1] * marker_info.line[(4-dir+j)%4][2];\r
+           w3 = marker_info.line[(4-dir+j)%4][2] * marker_info.line[(6-dir+j)%4][0]- marker_info.line[(6-dir+j)%4][2] * marker_info.line[(4-dir+j)%4][0];\r
+\r
+           wdir[j][0] =  w1*(cpara[0*4+1]*cpara[1*4+2]-cpara[0*4+2]*cpara[1*4+1])+  w2*cpara[1*4+1]-  w3*cpara[0*4+1];\r
+           wdir[j][1] = -w1*cpara[0*4+0]*cpara[1*4+2]+  w3*cpara[0*4+0];\r
+           wdir[j][2] =  w1*cpara[0*4+0]*cpara[1*4+1];\r
+           w = Math.sqrt( wdir[j][0]*wdir[j][0]+ wdir[j][1]*wdir[j][1]+ wdir[j][2]*wdir[j][2] );\r
+           wdir[j][0] /= w;\r
+           wdir[j][1] /= w;\r
+           wdir[j][2] /= w;\r
+       }\r
+\r
+       //以下3ケースは、計算エラーのときは例外が発生する。\r
+       check_dir(wdir[0], marker_info.sqvertex[(4-dir)%4],marker_info.sqvertex[(5-dir)%4], cpara);\r
+\r
+       check_dir(wdir[1], marker_info.sqvertex[(7-dir)%4],marker_info.sqvertex[(4-dir)%4], cpara);\r
+\r
+       check_rotation(wdir);\r
+\r
+\r
+       wdir[2][0] = wdir[0][1]*wdir[1][2] - wdir[0][2]*wdir[1][1];\r
+       wdir[2][1] = wdir[0][2]*wdir[1][0] - wdir[0][0]*wdir[1][2];\r
+       wdir[2][2] = wdir[0][0]*wdir[1][1] - wdir[0][1]*wdir[1][0];\r
+       w = Math.sqrt( wdir[2][0]*wdir[2][0]+ wdir[2][1]*wdir[2][1]+ wdir[2][2]*wdir[2][2] );\r
+       wdir[2][0] /= w;\r
+       wdir[2][1] /= w;\r
+       wdir[2][2] /= w;\r
+       double[] rot=this.array;\r
+       rot[0] = wdir[0][0];\r
+       rot[3] = wdir[0][1];\r
+       rot[6] = wdir[0][2];\r
+       rot[1] = wdir[1][0];\r
+       rot[4] = wdir[1][1];\r
+       rot[7] = wdir[1][2];\r
+       rot[2] = wdir[2][0];\r
+       rot[5] = wdir[2][1];\r
+       rot[8] = wdir[2][2];\r
+       //</Optimize>    \r
+    }\r
+    private final double[] wk_arModifyMatrix_abc=new double[3];\r
+    /**\r
+     * arGetRot計算を階層化したModifyMatrix\r
+     * 896\r
+     * @param nyrot\r
+     * @param trans\r
+     * @param vertex\r
+     * @param pos2d\r
+     * @param num\r
+     * @return\r
+     * @throws NyARException\r
+     */\r
+    public double modifyMatrix(double trans[],double vertex[], double pos2d[]) throws NyARException\r
+    {\r
+        double CACA,SASA,SACA,CA,SA;\r
+        double CACACB,SACACB,SASACB,CASB,SASB;\r
+        double SACASC,SACACBSC,SACACBCC,SACACC;        \r
+       double    factor;\r
+       double    a1, b1, c1;\r
+       double    a2, b2, c2;\r
+       double    ma = 0.0, mb = 0.0, mc = 0.0;\r
+       double    h, x, y;\r
+       double    err, minerr=0;\r
+       int       t1, t2, t3;\r
+       int       s1 = 0, s2 = 0, s3 = 0;\r
+       int       i;\r
+       final double[] abc=wk_arModifyMatrix_abc;\r
+\r
+       arGetAngle(abc);//arGetAngle( rot, &a, &b, &c );\r
+       a2 = abc[0];\r
+       b2 = abc[1];\r
+       c2 = abc[2];\r
+       factor = 10.0*Math.PI/180.0;\r
+       double rot0,rot1,rot3,rot4,rot6,rot7;\r
+       double combo00,combo01,combo02,combo03,combo10,combo11,combo12,combo13,combo20,combo21,combo22,combo23;\r
+       double combo02_2,combo02_5,combo02_8,combo02_11;\r
+       double combo22_2,combo22_5,combo22_8,combo22_11;\r
+       double combo12_2,combo12_5,combo12_8,combo12_11;\r
+       final double cpara[]=cparam.get34Array();\r
+        combo03 = cpara[0] * trans[0]+ cpara[1] * trans[1]+ cpara[2] * trans[2]+ cpara[3];\r
+        combo13 = cpara[4] * trans[0]+ cpara[5] * trans[1]+ cpara[6] * trans[2]+ cpara[7];\r
+        combo23 = cpara[8] * trans[0]+ cpara[9] * trans[1]+ cpara[10] * trans[2]+ cpara[11];\r
+       double wsin,wcos;\r
+       //comboの3行目を先に計算\r
+       for( i = 0; i < 10; i++ ) {\r
+           minerr = 1000000000.0;\r
+           for(t1=-1;t1<=1;t1++) {\r
+                a1 = a2 + factor*t1;\r
+               wsin = Math.sin(a1);\r
+               wcos = Math.cos(a1);\r
+               //Optimize\r
+               CACA=wcos*wcos;\r
+               SASA=wsin*wsin;\r
+               SACA=wsin*wcos;\r
+               CA=wcos;\r
+               SA=wsin;\r
+               for(t2=-1;t2<=1;t2++) {\r
+                    b1 = b2 + factor*t2;\r
+                    wsin = Math.sin(b1);\r
+                    wcos = Math.cos(b1);\r
+                   CACACB=CACA*wcos;\r
+                   SACACB=SACA*wcos;\r
+                   SASACB=SASA*wcos;\r
+                   CASB=CA*wsin;\r
+                   SASB=SA*wsin;\r
+                   //comboの計算1\r
+                   combo02 = cpara[0] * CASB+ cpara[1] * SASB+ cpara[2] * wcos;\r
+                   combo12 = cpara[4] * CASB+ cpara[5] * SASB+ cpara[6] * wcos;\r
+                   combo22 = cpara[8] * CASB+ cpara[9] * SASB+ cpara[10] * wcos;\r
+                   combo02_2 =combo02 * vertex[2]+combo03;\r
+                   combo02_5 =combo02 * vertex[5]+combo03;\r
+                   combo02_8 =combo02 * vertex[8]+combo03;\r
+                   combo02_11=combo02 * vertex[11]+combo03;\r
+                   combo12_2 =combo12 * vertex[2]+ combo13;\r
+                   combo12_5 =combo12 * vertex[5]+ combo13;\r
+                   combo12_8 =combo12 * vertex[8]+ combo13;\r
+                   combo12_11=combo12 * vertex[11]+ combo13;\r
+                   combo22_2 =combo22 * vertex[2]+ combo23;\r
+                   combo22_5 =combo22 * vertex[5]+ combo23;\r
+                   combo22_8 =combo22 * vertex[8]+ combo23;\r
+                   combo22_11=combo22 * vertex[11]+ combo23;\r
+           \r
+                   for(t3=-1;t3<=1;t3++) {\r
+                       c1 = c2 + factor*t3;\r
+                       wsin = Math.sin(c1);\r
+                       wcos = Math.cos(c1);\r
+                       SACASC=SACA*wsin;\r
+                       SACACC=SACA*wcos;\r
+                       SACACBSC=SACACB*wsin;\r
+                       SACACBCC=SACACB*wcos;\r
+                       \r
+                       rot0 = CACACB*wcos+SASA*wcos+SACACBSC-SACASC;\r
+                       rot3 = SACACBCC-SACACC+SASACB*wsin+CACA*wsin;\r
+                       rot6 = -CASB*wcos-SASB*wsin;\r
+                        combo00 = cpara[0] * rot0+ cpara[1] * rot3+ cpara[2] * rot6;\r
+                        combo10 = cpara[4] * rot0+ cpara[5] * rot3+ cpara[6] * rot6;\r
+                        combo20 = cpara[8] * rot0+ cpara[9] * rot3+ cpara[10] * rot6;\r
+                        \r
+                       rot1 = -CACACB*wsin-SASA*wsin+SACACBCC-SACACC;\r
+                       rot4 = -SACACBSC+SACASC+SASACB*wcos+CACA*wcos;\r
+                       rot7 = CASB*wsin-SASB*wcos;\r
+                        combo01 = cpara[0] * rot1+ cpara[1] * rot4+ cpara[2] * rot7;\r
+                        combo11 = cpara[4] * rot1+ cpara[5] * rot4+ cpara[6] * rot7;\r
+                        combo21 = cpara[8] * rot1+ cpara[9] * rot4+ cpara[10] * rot7;\r
+                        //\r
+                        err = 0.0;\r
+                        h  = combo20 * vertex[0]+ combo21 * vertex[1]+ combo22_2;\r
+                        x = pos2d[0] - (combo00 * vertex[0]+ combo01 * vertex[1]+ combo02_2) / h;\r
+                        y = pos2d[1] - (combo10 * vertex[0]+ combo11 * vertex[1]+ combo12_2) / h;\r
+                        err += x*x+y*y;\r
+                        h  = combo20 * vertex[3]+ combo21 * vertex[4]+ combo22_5;\r
+                        x = pos2d[2] - (combo00 * vertex[3]+ combo01 * vertex[4]+ combo02_5) / h;\r
+                        y = pos2d[3] - (combo10 * vertex[3]+ combo11 * vertex[4]+ combo12_5) / h;\r
+                        err += x*x+y*y;\r
+                        h  = combo20 * vertex[6]+ combo21 * vertex[7]+ combo22_8;\r
+                        x = pos2d[4] - (combo00 * vertex[6]+ combo01 * vertex[7]+ combo02_8) / h;\r
+                        y = pos2d[5] - (combo10 * vertex[6]+ combo11 * vertex[7]+ combo12_8) / h;\r
+                        err += x*x+y*y;\r
+                        h  = combo20 * vertex[9]+ combo21 * vertex[10]+ combo22_11;\r
+                        x = pos2d[6] - (combo00 * vertex[9]+ combo01 * vertex[10]+ combo02_11) / h;\r
+                        y = pos2d[7] - (combo10 * vertex[9]+ combo11 * vertex[10]+ combo12_11) / h;\r
+                        err += x*x+y*y;\r
+                       if( err < minerr ) {\r
+                           minerr = err;\r
+                           ma = a1;\r
+                           mb = b1;\r
+                           mc = c1;\r
+                           s1 = t1;\r
+                           s2 = t2;\r
+                           s3 = t3;\r
+                       }\r
+                   }\r
+               }\r
+           }\r
+           if( s1 == 0 && s2 == 0 && s3 == 0 ){\r
+               factor *= 0.5;\r
+           }\r
+           a2 = ma;\r
+           b2 = mb;\r
+           c2 = mc;\r
+       }\r
+       arGetRot(ma,mb,mc,this.array);\r
+       /*  printf("factor = %10.5f\n", factor*180.0/MD_PI); */\r
+       return minerr/4;\r
+    }                       \r
+}\r
+\r
index 53a22ff..66b81f2 100644 (file)
@@ -38,17 +38,28 @@ import jp.nyatla.nyartoolkit.NyARException;
 public class NyARVec\r
 {\r
     private int clm;\r
-    private NyARVec(double[] i_array)\r
-    {\r
-        v=i_array;\r
-        clm=v.length;\r
-    }\r
     public NyARVec(int i_clm)\r
     {\r
         v=new double[i_clm];\r
         clm=i_clm;\r
     }\r
     private double[] v;\r
+    /**\r
+     * i_clmサイズの列を格納できるように列サイズを変更します。\r
+     * 実行後、列の各値は不定になります。\r
+     * @param i_clm\r
+     */\r
+    public void realloc(int i_clm)\r
+    {\r
+       if(i_clm<=this.v.length)\r
+       {\r
+           //十分な配列があれば何もしない。\r
+       }else{\r
+           //不十分なら取り直す。\r
+           v=new double[i_clm];\r
+       }\r
+        this.clm=i_clm;\r
+    }    \r
     public int getClm()\r
     {\r
         return clm;\r
@@ -57,13 +68,9 @@ public class NyARVec
     {\r
         return v;\r
     }\r
-    public static NyARVec wrap(double[] i_array)\r
-    {\r
-       return new NyARVec(i_array);\r
-    }\r
     /**\r
      * arVecDispの代替品\r
-     * @param v\r
+     * @param value\r
      * @return\r
      */\r
     public int arVecDisp() throws NyARException\r
@@ -87,19 +94,19 @@ public class NyARVec
      * @return\r
      * @throws NyARException\r
      */\r
-    private static double vecInnerproduct(NyARVec x,NyARVec y,int i_start) throws NyARException\r
+    public double vecInnerproduct(NyARVec y,int i_start) throws NyARException\r
     {\r
         NyARException.trap("この関数は動作確認できていません。");    \r
         double result = 0.0;\r
 //        double[] x_array=x.v;.getArray();\r
 //        double[] y_array=y.getArray();\r
     \r
-        if(x.clm!= y.clm){\r
+        if(this.clm!= y.clm){\r
             throw new NyARException();//exit();\r
         }\r
-        for(int i = i_start; i < x.clm; i++ ) {\r
+        for(int i = i_start; i < this.clm; i++ ) {\r
             NyARException.trap("未チェックのパス");\r
-            result += x.v[i] * y.v[i];//result += x->v[i] * y->v[i];\r
+            result += this.v[i] * y.v[i];//result += x->v[i] * y->v[i];\r
         }    \r
         return result;\r
     }\r
@@ -111,133 +118,143 @@ public class NyARVec
      * @return\r
      * @throws NyARException\r
      */\r
-    private static double vecHousehold(NyARVec x,int i_start) throws NyARException\r
+    public double vecHousehold(int i_start) throws NyARException\r
     {\r
         NyARException.trap("この関数は動作確認できていません。");\r
         double s, t;\r
-        s = Math.sqrt(vecInnerproduct(x,x,i_start));\r
+        s = Math.sqrt(this.vecInnerproduct(this,i_start));\r
 //        double[] x_array=x.getArray();\r
         if( s != 0.0 ){\r
             NyARException.trap("未チェックのパス");\r
-            if(x.v[i_start]< 0){\r
+            if(this.v[i_start]< 0){\r
                s = -s;\r
             }\r
             NyARException.trap("未チェックのパス");{\r
-            x.v[i_start]+=s;//x->v[0] += s;\r
-            t = 1 / Math.sqrt(x.v[i_start]* s);//t = 1 / sqrt(x->v[0] * s);\r
+               this.v[i_start]+=s;//x->v[0] += s;\r
+            t = 1 / Math.sqrt(this.v[i_start]* s);//t = 1 / sqrt(x->v[0] * s);\r
            }\r
-            for(int i = i_start; i < x.clm; i++){\r
+            for(int i = i_start; i < this.clm; i++){\r
                 NyARException.trap("未チェックのパス");\r
-                x.v[i]*=t;//x->v[i] *= t;\r
+                this.v[i]*=t;//x->v[i] *= t;\r
             }\r
         }\r
         return -s;\r
     }\r
+//    /**\r
+//     * arVecTridiagonalize関数の代替品\r
+//     * a,d,e間で演算をしてる。何をどうしているかはさっぱりさっぱり\r
+//     * @param a\r
+//     * @param d\r
+//     * @param e\r
+//     * @param i_e_start\r
+//     * 演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる)\r
+//     * @return\r
+//     * @throws NyARException\r
+//     */\r
+//    public static void vecTridiagonalize(NyARMat a, NyARVec d, NyARVec e,int i_e_start) throws NyARException\r
+//    {\r
+//     NyARVec vec,vec2;\r
+//     double[][] a_array=a.getArray();\r
+//     double  s, t, p, q;\r
+//     int     dim;\r
+//\r
+//     if(a.getClm()!=a.getRow()){\r
+//         throw new NyARException();\r
+//     }\r
+//     if(a.getClm() != d.clm){\r
+//         throw new NyARException();\r
+//     }\r
+//     if(a.getClm() != e.clm){\r
+//         throw new NyARException();\r
+//     }\r
+//     dim = a.getClm();\r
+//\r
+//     for(int k = 0; k < dim-2; k++ ){\r
+//         vec=a.getRowVec(k);\r
+////       double[] vec_array=vec.getArray();\r
+//         NyARException.trap("未チェックパス"); \r
+//         d.v[k]=vec.v[k];//d.set(k,v.get(k));    //d->v[k] = v[k];\r
+//\r
+//         //wv1.clm = dim-k-1;\r
+//         //wv1.v = &(v[k+1]);\r
+//         NyARException.trap("未チェックパス"); \r
+//         e.v[k+i_e_start]=vec.vecHousehold(k+1);//e->v[k] = arVecHousehold(&wv1);\r
+//         if(e.v[k+i_e_start]== 0.0 ){\r
+//             continue;\r
+//         }\r
+//\r
+//         for(int i = k+1; i < dim; i++ ){\r
+//             s = 0.0;\r
+//             for(int j = k+1; j < i; j++ ) {\r
+//                 NyARException.trap("未チェックのパス");\r
+//                 s += a_array[j][i] * vec.v[j];//s += a.get(j*dim+i) * v.get(j);//s += a->m[j*dim+i] * v[j];\r
+//             }\r
+//             for(int j = i; j < dim; j++ ) {\r
+//                 NyARException.trap("未チェックのパス");\r
+//                 s += a_array[i][j] * vec.v[j];//s += a.get(i*dim+j) * v.get(j);//s += a->m[i*dim+j] * v[j];\r
+//             }\r
+//             NyARException.trap("未チェックのパス");\r
+//             d.v[i]=s;//d->v[i] = s;\r
+//         }\r
+//\r
+//\r
+//         //wv1.clm = wv2.clm = dim-k-1;\r
+//         //wv1.v = &(v[k+1]);\r
+//         //wv2.v = &(d->v[k+1]);\r
+//         vec=a.getRowVec(k);\r
+////       vec_array=vec.getArray();\r
+//         NyARException.trap("未チェックパス"); \r
+//         t = vec.vecInnerproduct(d,k+1)/ 2;\r
+//         for(int i = dim-1; i > k; i-- ) {\r
+//             NyARException.trap("未チェックパス"); \r
+//             p = vec.v[i];//p = v.get(i);//p = v[i];\r
+//             d.v[i]-=t*p;q=d.v[i];//q = d->v[i] -= t*p;\r
+//             for(int j = i; j < dim; j++ ){\r
+//                 NyARException.trap("未チェックパス"); \r
+//                 a_array[i][j]-=p*(d.v[j] + q*vec.v[j]);//a->m[i*dim+j] -= p*(d->v[j]) + q*v[j];\r
+//             }\r
+//         }\r
+//     }\r
+//\r
+//     if( dim >= 2) {\r
+//         d.v[dim-2]=a_array[dim-2][dim-2];//d->v[dim-2] = a->m[(dim-2)*dim+(dim-2)];\r
+//         e.v[dim-2+i_e_start]=a_array[dim-2][dim-1];//e->v[dim-2] = a->m[(dim-2)*dim+(dim-1)];\r
+//     }\r
+//\r
+//     if( dim >= 1 ){\r
+//         d.v[dim-1]=a_array[dim-1][dim-1];//d->v[dim-1] = a->m[(dim-1)*dim+(dim-1)];\r
+//     }\r
+//\r
+//     for(int k = dim-1; k >= 0; k--) {\r
+//         vec=a.getRowVec(k);//v = a.getPointer(k*dim);//v = &(a->m[k*dim]);\r
+//         if( k < dim-2 ) {\r
+//             for(int i = k+1; i < dim; i++ ){\r
+//                 //wv1.clm = wv2.clm = dim-k-1;\r
+//                 //wv1.v = &(v[k+1]);\r
+//                 //wv2.v = &(a->m[i*dim+k+1]);\r
+//                 vec2=a.getRowVec(i);\r
+//\r
+//                 t = vec.vecInnerproduct(vec2,k+1);\r
+//                 for(int j = k+1; j < dim; j++ ){\r
+//                     NyARException.trap("未チェックパス"); \r
+//                     a_array[i][j]-=t*vec.v[j];//a.subValue(i*dim+j,t*v.get(j));//a->m[i*dim+j] -= t * v[j];\r
+//                 }\r
+//             }\r
+//         }\r
+//         for(int i = 0; i < dim; i++ ){\r
+//             vec.v[i]=0.0;//v.set(i,0.0);//v[i] = 0.0;\r
+//         }\r
+//         vec.v[k]=1;//v.set(k,1);//v[k] = 1;\r
+//     }\r
+//    }\r
     /**\r
-     * arVecTridiagonalize関数の代替品\r
-     * a,d,e間で演算をしてる。何をどうしているかはさっぱりさっぱり\r
-     * @param a\r
-     * @param d\r
-     * @param e\r
-     * @param i_e_start\r
-     * 演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる)\r
-     * @return\r
-     * @throws NyARException\r
+     * 現在ラップしている配列を取り外して、新しい配列をラップします。\r
+     * @param i_v\r
+     * @param i_clm\r
      */\r
-    public static void vecTridiagonalize(NyARMat a, NyARVec d, NyARVec e,int i_e_start) throws NyARException\r
+    public void setNewArray(double[] i_array,int i_clm)\r
     {\r
-       NyARVec vec,vec2;\r
-       double[][] a_array=a.getArray();\r
-       double  s, t, p, q;\r
-       int     dim;\r
-\r
-       if(a.getClm()!=a.getRow()){\r
-           throw new NyARException();\r
-       }\r
-       if(a.getClm() != d.clm){\r
-           throw new NyARException();\r
-       }\r
-       if(a.getClm() != e.clm){\r
-           throw new NyARException();\r
-       }\r
-       dim = a.getClm();\r
-\r
-       for(int k = 0; k < dim-2; k++ ){\r
-           vec=a.getRowVec(k);\r
-//         double[] vec_array=vec.getArray();\r
-           NyARException.trap("未チェックパス"); \r
-           d.v[k]=vec.v[k];//d.set(k,v.get(k));    //d->v[k] = v[k];\r
-\r
-           //wv1.clm = dim-k-1;\r
-           //wv1.v = &(v[k+1]);\r
-           NyARException.trap("未チェックパス"); \r
-           e.v[k+i_e_start]=vecHousehold(vec,k+1);//e->v[k] = arVecHousehold(&wv1);\r
-           if(e.v[k+i_e_start]== 0.0 ){\r
-               continue;\r
-           }\r
-\r
-           for(int i = k+1; i < dim; i++ ){\r
-               s = 0.0;\r
-               for(int j = k+1; j < i; j++ ) {\r
-                   NyARException.trap("未チェックのパス");\r
-                   s += a_array[j][i] * vec.v[j];//s += a.get(j*dim+i) * v.get(j);//s += a->m[j*dim+i] * v[j];\r
-               }\r
-               for(int j = i; j < dim; j++ ) {\r
-                   NyARException.trap("未チェックのパス");\r
-                   s += a_array[i][j] * vec.v[j];//s += a.get(i*dim+j) * v.get(j);//s += a->m[i*dim+j] * v[j];\r
-               }\r
-               NyARException.trap("未チェックのパス");\r
-               d.v[i]=s;//d->v[i] = s;\r
-           }\r
-        \r
-\r
-           //wv1.clm = wv2.clm = dim-k-1;\r
-           //wv1.v = &(v[k+1]);\r
-           //wv2.v = &(d->v[k+1]);\r
-           vec=a.getRowVec(k);\r
-//         vec_array=vec.getArray();\r
-           NyARException.trap("未チェックパス"); \r
-           t = vecInnerproduct(vec,d,k+1)/ 2;\r
-           for(int i = dim-1; i > k; i-- ) {\r
-               NyARException.trap("未チェックパス"); \r
-               p = vec.v[i];//p = v.get(i);//p = v[i];\r
-               d.v[i]-=t*p;q=d.v[i];//q = d->v[i] -= t*p;\r
-               for(int j = i; j < dim; j++ ){\r
-                   NyARException.trap("未チェックパス"); \r
-                   a_array[i][j]-=p*(d.v[j] + q*vec.v[j]);//a->m[i*dim+j] -= p*(d->v[j]) + q*v[j];\r
-               }\r
-           }\r
-       }\r
-\r
-       if( dim >= 2) {\r
-           d.v[dim-2]=a_array[dim-2][dim-2];//d->v[dim-2] = a->m[(dim-2)*dim+(dim-2)];\r
-           e.v[dim-2+i_e_start]=a_array[dim-2][dim-1];//e->v[dim-2] = a->m[(dim-2)*dim+(dim-1)];\r
-       }\r
-\r
-       if( dim >= 1 ){\r
-           d.v[dim-1]=a_array[dim-1][dim-1];//d->v[dim-1] = a->m[(dim-1)*dim+(dim-1)];\r
-       }\r
-\r
-       for(int k = dim-1; k >= 0; k--) {\r
-           vec=a.getRowVec(k);//v = a.getPointer(k*dim);//v = &(a->m[k*dim]);\r
-           if( k < dim-2 ) {\r
-               for(int i = k+1; i < dim; i++ ){\r
-                   //wv1.clm = wv2.clm = dim-k-1;\r
-                   //wv1.v = &(v[k+1]);\r
-                   //wv2.v = &(a->m[i*dim+k+1]);\r
-                   vec2=a.getRowVec(i);\r
-                   \r
-                   t = vecInnerproduct(vec,vec2,k+1);\r
-                   for(int j = k+1; j < dim; j++ ){\r
-                       NyARException.trap("未チェックパス"); \r
-                       a_array[i][j]-=t*vec.v[j];//a.subValue(i*dim+j,t*v.get(j));//a->m[i*dim+j] -= t * v[j];\r
-                   }\r
-               }\r
-           }\r
-           for(int i = 0; i < dim; i++ ){\r
-               vec.v[i]=0.0;//v.set(i,0.0);//v[i] = 0.0;\r
-           }\r
-           vec.v[k]=1;//v.set(k,1);//v[k] = 1;\r
-       }\r
+        this.v=i_array;\r
+        this.clm=i_clm;        \r
     }\r
 }\r
index 26f3d24..7d8d371 100644 (file)
@@ -51,7 +51,7 @@ public class NyARMatchPatt_BlackWhite implements ARMatchPatt{
     {\r
        width=i_target_patt.getWidth();\r
        height=i_target_patt.getHeight();\r
-       short[][][] data=i_target_patt.getPatArray();   \r
+       int[][][] data=i_target_patt.getPatArray();     \r
        input=new int[height][width][3];\r
  \r
         int sum = ave = 0;\r
index 8f17c04..84df205 100644 (file)
@@ -40,12 +40,11 @@ import jp.nyatla.nyartoolkit.core.*;
  *\r
  */\r
 public class NyARMatchPatt_Color_WITHOUT_PCA implements ARMatchPatt{\r
-    private int[][][]  input;\r
-    private int ave;\r
+    private int[][][]  input=new int[1][1][3];\r
     private double datapow;\r
 \r
-    private int width;\r
-    private int height;\r
+    private int width =1;\r
+    private int height=1;\r
     private double cf=0;\r
     private int dir=0;\r
     public double getConfidence(){\r
@@ -54,29 +53,68 @@ public class NyARMatchPatt_Color_WITHOUT_PCA implements ARMatchPatt{
     public int getDirection(){\r
        return dir;\r
     }\r
-    public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException\r
+    /**\r
+     * input配列サイズを必要に応じて再アロケートする。\r
+     *\r
+     * @param i_width\r
+     * @param i_height\r
+     */\r
+    private void reallocInputArray(int i_width,int i_height)\r
     {\r
-       width=i_target_patt.getWidth();\r
-       height=i_target_patt.getHeight();\r
-       short[][][] data=i_target_patt.getPatArray();\r
+        if(this.input.length<i_height || this.input[0].length<i_width){\r
+            //配列が十分なサイズでなければ取り直す\r
+            this.input=new int[i_height][i_width][3];          \r
+        }\r
+        this.height=i_height;\r
+        this.width =i_width;\r
+    }\r
+    public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException\r
+    { \r
+       int i,k;\r
+       int[][][] data,linput;\r
        \r
-       input=new int[height][width][3];\r
-        int sum;\r
+       //input配列のサイズとwhも更新//       input=new int[height][width][3];\r
+       reallocInputArray(i_target_patt.getWidth(),i_target_patt.getHeight());\r
+       int lwidth =this.width;\r
+       int lheight=this.height;\r
+       linput=this.input;\r
+       data=i_target_patt.getPatArray();\r
 \r
-        sum = ave = 0;\r
-        for(int i=0;i<height;i++) {//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){\r
-            for(int i2=0;i2<width;i2++) {//for(int i2=0;i2<Config.AR_PATT_SIZE_X;i2++){\r
-                ave += (255-data[i][i2][0])+(255-data[i][i2][1])+(255-data[i][i2][2]);\r
+       int sum=0,l_ave=0,w_sum;\r
+        int[][] data_i,input_i;\r
+        int[] data_i_k,input_i_k;\r
+        for(i=lheight-1;i>=0;i--){//<Optimize/>for(int i=0;i<height;i++) {//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){\r
+            data_i=data[i];\r
+            for(k=lwidth-1;k>=0;k--) {//<Optimize/>for(int i2=0;i2<Config.AR_PATT_SIZE_X;i2++){\r
+               //<Optimize/>l_ave += (255-data[i][i2][0])+(255-data[i][i2][1])+(255-data[i][i2][2]);\r
+               data_i_k=data_i[k];\r
+               l_ave += 255*3-data_i_k[0]-data_i_k[1]-data_i_k[2];\r
             }\r
         }\r
-        ave /= (height*width*3);\r
-\r
-        for(int i=0;i<height;i++){//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){\r
-            for(int i2=0;i2<width;i2++){//for(int i2=0;i2<Config.AR_PATT_SIZE_X;i2++){\r
-                for(int i3=0;i3<3;i3++){\r
-                    input[i][i2][i3] = (255-data[i][i2][i3]) - ave;\r
-                    sum += input[i][i2][i3]*input[i][i2][i3];\r
-                }\r
+        l_ave /= (lheight*lwidth*3);\r
+        for(i=lheight-1;i>=0;i--){//for(i=0;i<height;i++){//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){\r
+            input_i=linput[i];\r
+            data_i=data[i];\r
+            for(k=lwidth-1;k>=0;k--){//for(i2=0;i2<width;i2++){//for(int i2=0;i2<Config.AR_PATT_SIZE_X;i2++){\r
+                //<Optimize>\r
+                //for(int i3=0;i3<3;i3++){\r
+                //    input[i][i2][i3] = (255-data[i][i2][i3]) - l_ave;\r
+                //    sum += input[i][i2][i3]*input[i][i2][i3];\r
+                //}\r
+               data_i_k =data_i[k];\r
+               input_i_k=input_i[k];\r
+               w_sum=(255-data_i_k[0]) - l_ave;\r
+               input_i_k[0]=w_sum;\r
+                sum += w_sum*w_sum;\r
+                \r
+                w_sum=(255-data_i_k[1]) - l_ave;\r
+                input_i_k[1]=w_sum;\r
+                sum += w_sum*w_sum;\r
+                \r
+                w_sum=(255-data_i_k[2]) - l_ave;\r
+                input_i_k[2]=w_sum;\r
+                sum+=w_sum*w_sum;\r
+                //</Optimize>\r
             }\r
         }\r
         datapow = Math.sqrt( (double)sum );\r
@@ -98,22 +136,35 @@ public class NyARMatchPatt_Color_WITHOUT_PCA implements ARMatchPatt{
        double[] patpow=i_code.getPatPow();\r
        int res= -1;\r
        double max=0.0;\r
-        for(int j = 0; j < 4; j++ ) {\r
-            int sum = 0;\r
-            for(int i=0;i<height;i++){//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){\r
-               for(int i2=0;i2<width;i2++){\r
-                   for(int i3=0;i3<3;i3++){\r
-                       sum += input[i][i2][i3]*pat[j][i][i2][i3];//sum += input[i][i2][i3]*pat[k][j][i][i2][i3];\r
-                   }\r
-               }\r
-            }\r
-            double sum2 = sum / patpow[j] / datapow;//sum2 = sum / patpow[k][j] / datapow;\r
-            if( sum2 > max ){\r
-               max = sum2;\r
-               res = j;\r
-            }\r
-        }\r
-        dir=res;\r
-        cf=max;\r
+       int[][][] pat_j,linput;\r
+       int[][] pat_j_i,input_i;\r
+       int[] pat_j_i_k,input_i_k;\r
+       int l_width=this.width;\r
+       int l_height=this.height;\r
+       linput=this.input;\r
+       for(int j = 0; j < 4; j++ ) {\r
+           int sum = 0;\r
+           pat_j=pat[j];\r
+           for(int i=l_height-1;i>=0;i--){//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){\r
+               input_i=linput[i];\r
+               pat_j_i=pat_j[i];\r
+               for(int k=l_width-1;k>=0;k--){\r
+                   pat_j_i_k=pat_j_i[k];\r
+                   input_i_k=input_i[k];\r
+//                 for(int i3=0;i3<3;i3++){\r
+                   sum += input_i_k[0]*pat_j_i_k[0];//sum += input[i][i2][i3]*pat[k][j][i][i2][i3];\r
+                   sum += input_i_k[1]*pat_j_i_k[1];//sum += input[i][i2][i3]*pat[k][j][i][i2][i3];\r
+                   sum += input_i_k[2]*pat_j_i_k[2];//sum += input[i][i2][i3]*pat[k][j][i][i2][i3];\r
+//                 }\r
+               }\r
+           }\r
+           double sum2 = sum / patpow[j] / datapow;//sum2 = sum / patpow[k][j] / datapow;\r
+           if( sum2 > max ){\r
+               max = sum2;\r
+               res = j;\r
+           }\r
+       }\r
+       dir=res;\r
+       cf=max;\r
     }\r
 }
\ No newline at end of file
index 17a38e7..11f9cce 100644 (file)
@@ -63,7 +63,7 @@ public class NyARMatchPatt_Color_WITH_PCA implements ARMatchPatt{
     {\r
        width=i_target_patt.getWidth();\r
        height=i_target_patt.getHeight();\r
-       short[][][] data=i_target_patt.getPatArray();\r
+       int[][][] data=i_target_patt.getPatArray();\r
        \r
        input=new int[height][width][3];\r
        evec=new double[EVEC_MAX][height][width][3];//static double evec[EVEC_MAX][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];\r
index 16f768f..ffda8b6 100644 (file)
@@ -34,9 +34,28 @@ package jp.nyatla.nyartoolkit.core.raster;
 public interface NyARRaster{\r
     //RGBの合計値を返す\r
     public int getPixelTotal(int i_x,int i_y);\r
+    /**\r
+     * 一行単位でi_row番目の合計値配列を計算して返す。\r
+     * @param i_row\r
+     * @param o_line\r
+     * getWidth()の戻り値以上のサイズが必要。\r
+     */\r
+    public void getPixelTotalRowLine(int i_row,int[] o_line);\r
     public int getWidth();\r
     public int getHeight();\r
-    public void pickRgbArray(int i_x,int i_y,int[] i_rgb);\r
+    public void getPixel(int i_x,int i_y,int[] i_rgb);\r
+    /**\r
+     * 複数のピクセル値をi_rgbへ返します。\r
+     * @param i_x\r
+     * xのインデックス配列\r
+     * @param i_y\r
+     * yのインデックス配列\r
+     * @param i_num\r
+     * 返すピクセル値の数\r
+     * @param i_rgb\r
+     * ピクセル値を返すバッファ\r
+     */\r
+    public void getPixelSet(int[] i_x,int i_y[],int i_num,int[] o_rgb);\r
 }\r
 \r
 \r
index 78797ce..01bcfc6 100644 (file)
@@ -48,8 +48,18 @@ public class NyARRaster_BGRA implements NyARRaster
     //RGBの合計値を返す\r
     public int getPixelTotal(int i_x,int i_y)\r
     {\r
-        int bp=(i_x+i_y*width)*4;\r
-        return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);\r
+        int bp=(i_x+i_y*this.width)*4;\r
+        byte[] ref=this.ref_buf;\r
+        return (ref[bp] & 0xff)+(ref[bp+1] & 0xff)+(ref[bp+2] & 0xff);\r
+    }\r
+    public void getPixelTotalRowLine(int i_row,int[] o_line)\r
+    {\r
+        final byte[] ref=this.ref_buf;\r
+        int bp=(i_row+1)*this.width*4-4;\r
+        for(int i=this.width-1;i>=0;i--){\r
+           o_line[i]=(ref[bp] & 0xff)+(ref[bp+1] & 0xff)+(ref[bp+2] & 0xff);\r
+           bp-=4;\r
+       }\r
     }\r
     public int getWidth()\r
     {\r
@@ -59,12 +69,25 @@ public class NyARRaster_BGRA implements NyARRaster
     {\r
        return height;\r
     }\r
-    public void pickRgbArray(int i_x,int i_y,int[] i_rgb)\r
+    public void getPixel(int i_x,int i_y,int[] i_rgb)\r
+    {\r
+       byte[] ref=this.ref_buf;\r
+        int bp=(i_x+i_y*this.width)*4;\r
+        i_rgb[0]=(ref[bp+2] & 0xff);//R\r
+        i_rgb[1]=(ref[bp+1] & 0xff);//G\r
+        i_rgb[2]=(ref[bp+0] & 0xff);//B\r
+    }\r
+    public void getPixelSet(int[] i_x,int i_y[],int i_num,int[] o_rgb)\r
     {\r
-        int bp=(i_x+i_y*width)*4;\r
-        i_rgb[0]=(ref_buf[bp+2] & 0xff);//R\r
-        i_rgb[1]=(ref_buf[bp+1] & 0xff);//G\r
-        i_rgb[2]=(ref_buf[bp+0] & 0xff);//B\r
+       int width=this.width;\r
+       byte[] ref=this.ref_buf;\r
+       int bp;\r
+       for(int i=i_num-1;i>=0;i--){\r
+           bp=(i_x[i]+i_y[i]*width)*4;\r
+           o_rgb[i*3+0]=(ref[bp+2] & 0xff);//R\r
+           o_rgb[i*3+1]=(ref[bp+1] & 0xff);//G\r
+           o_rgb[i*3+2]=(ref[bp+0] & 0xff);//B\r
+       }       \r
     }\r
 }\r
 \r
index 4f9d851..1bea194 100644 (file)
@@ -50,6 +50,12 @@ public class NyARRaster_Blank implements NyARRaster
     {\r
        return 0;\r
     }\r
+    public void getPixelTotalRowLine(int i_row,int[] o_line)\r
+    {\r
+        for(int i=this.width-1;i>=0;i--){\r
+           o_line[i]=0;\r
+       }\r
+    }    \r
     public int getWidth()\r
     {\r
        return width;\r
@@ -58,10 +64,18 @@ public class NyARRaster_Blank implements NyARRaster
     {\r
        return height;\r
     }\r
-    public void pickRgbArray(int i_x,int i_y,int[] i_rgb)\r
+    public void getPixel(int i_x,int i_y,int[] i_rgb)\r
     {\r
         i_rgb[0]=0;\r
         i_rgb[1]=0;\r
         i_rgb[2]=0;\r
     }\r
+    public void getPixelSet(int[] i_x,int i_y[],int i_num,int[] o_rgb)\r
+    {\r
+       for(int i=i_num-1;i>=0;i--){\r
+           o_rgb[i*3+0]=0;//R\r
+           o_rgb[i*3+1]=0;//G\r
+           o_rgb[i*3+2]=0;//B\r
+       }       \r
+    }    \r
 }\r
index e48040a..b223b9d 100644 (file)
@@ -48,9 +48,19 @@ public class NyARRaster_RGB implements NyARRaster
     //RGBの合計値を返す\r
     public int getPixelTotal(int i_x,int i_y)\r
     {\r
-        int bp=(i_x+i_y*width)*3;\r
-        return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);\r
+       byte[] ref=this.ref_buf;\r
+        int bp=(i_x+i_y*this.width)*3;\r
+        return (ref[bp] & 0xff)+(ref[bp+1] & 0xff)+(ref[bp+2] & 0xff);\r
     }\r
+    public void getPixelTotalRowLine(int i_row,int[] o_line)\r
+    {\r
+        final byte[] ref=this.ref_buf;\r
+        int bp=(i_row+1)*this.width*3-3;\r
+        for(int i=this.width-1;i>=0;i--){\r
+           o_line[i]=(ref[bp] & 0xff)+(ref[bp+1] & 0xff)+(ref[bp+2] & 0xff);\r
+           bp-=3;\r
+       }\r
+    }    \r
     public int getWidth()\r
     {\r
         return width;\r
@@ -59,12 +69,25 @@ public class NyARRaster_RGB implements NyARRaster
     {\r
         return height;\r
     }\r
-    public void pickRgbArray(int i_x,int i_y,int[] i_rgb)\r
+    public void getPixel(int i_x,int i_y,int[] i_rgb)\r
+    {\r
+        int bp=(i_x+i_y*this.width)*3;\r
+        byte[] ref=this.ref_buf;\r
+        i_rgb[0]=(ref[bp+0] & 0xff);//R\r
+        i_rgb[1]=(ref[bp+1] & 0xff);//G\r
+        i_rgb[2]=(ref[bp+2] & 0xff);//B\r
+    }\r
+    public void getPixelSet(int[] i_x,int i_y[],int i_num,int[] o_rgb)\r
     {\r
-        int bp=(i_x+i_y*width)*3;\r
-        i_rgb[0]=(ref_buf[bp+0] & 0xff);//R\r
-        i_rgb[1]=(ref_buf[bp+1] & 0xff);//G\r
-        i_rgb[2]=(ref_buf[bp+2] & 0xff);//B\r
+       int width=this.width;\r
+       byte[] ref=this.ref_buf;\r
+       int bp;\r
+       for(int i=i_num-1;i>=0;i--){\r
+           bp=(i_x[i]+i_y[i]*width)*3;\r
+           o_rgb[i*3+0]=(ref[bp+0] & 0xff);//R\r
+           o_rgb[i*3+1]=(ref[bp+1] & 0xff);//G\r
+           o_rgb[i*3+2]=(ref[bp+2] & 0xff);//B\r
+       }       \r
     }\r
 }\r
 \r
index a62e753..7e64092 100644 (file)
@@ -40,9 +40,10 @@ import jp.nyatla.nyartoolkit.core.raster.*;
  *\r
  */\r
 public class NyARSingleDetectMarker{\r
-    private static final int AR_SQUARE_MAX=10;\r
-    private NyARParam param;\r
+    private static final int AR_SQUARE_MAX=100;\r
+    private NyARMatchPatt_Color_WITHOUT_PCA match_patt;\r
     private NyARDetectSquare square;\r
+    private final NyARSquareList square_list=new NyARSquareList(AR_SQUARE_MAX);\r
     private NyARCode code;\r
     protected NyARTransMat transmat;\r
     private double marker_width;\r
@@ -51,18 +52,18 @@ public class NyARSingleDetectMarker{
     private double detected_confidence;\r
     private NyARSquare detected_square;\r
     private NyARColorPatt patt;\r
-    public NyARSingleDetectMarker(NyARParam i_param,NyARCode i_code,double i_marker_width)\r
+    public NyARSingleDetectMarker(NyARParam i_param,NyARCode i_code,double i_marker_width) throws NyARException\r
     {\r
-       param=i_param;\r
        //解析オブジェクトを作る\r
-       square=new NyARDetectSquare(AR_SQUARE_MAX,i_param);\r
-       transmat=new NyARTransMat(param);\r
+       this.square=new NyARDetectSquare(i_param);\r
+       this.transmat=new NyARTransMat(i_param);\r
        //比較コードを保存\r
-       code=i_code;\r
-       marker_width=i_marker_width;\r
+       this.code=i_code;\r
+       this.marker_width=i_marker_width;\r
        //評価パターンのホルダを作る\r
-       patt=new NyARColorPatt(code.getWidth(),code.getHeight());\r
-       \r
+       this.patt=new NyARColorPatt_O3(code.getWidth(),code.getHeight());\r
+       //評価器を作る。\r
+       this.match_patt=new NyARMatchPatt_Color_WITHOUT_PCA();  \r
     }\r
     /**\r
      * i_imageにマーカー検出処理を実行して、結果を保持します。\r
@@ -75,49 +76,48 @@ public class NyARSingleDetectMarker{
     public boolean detectMarkerLite(NyARRaster i_image,int i_thresh) throws NyARException\r
     {\r
        detected_square=null;\r
+       NyARSquareList l_square_list=this.square_list;\r
        //スクエアコードを探す\r
-       square.detectSquare(i_image, i_thresh);\r
-       int number_of_square=square.getSquareCount();\r
+       square.detectSquare(i_image, i_thresh,l_square_list);\r
+       \r
+       int number_of_square=l_square_list.getSquareNum();\r
        //コードは見つかった?\r
        if(number_of_square<1){\r
            return false;\r
        }\r
 \r
        //コードの一致度を調べる準備\r
-       NyARSquare[] squares=square.getSquareArray();\r
+//     NyARSquare[] squares=square.getSquareArray();\r
        //評価基準になるパターンをイメージから切り出す\r
-       patt.pickFromRaster(i_image,squares[0].getMarker());\r
-       \r
-       //パターンの評価オブジェクトを作る。\r
-       NyARMatchPatt_Color_WITHOUT_PCA eva=new NyARMatchPatt_Color_WITHOUT_PCA();\r
+       patt.pickFromRaster(i_image,l_square_list.getSquare(0));\r
        //パターンを評価器にセット\r
-       if(!eva.setPatt(patt)){\r
+       if(!this.match_patt.setPatt(patt)){\r
            //計算に失敗した。\r
-           return false;\r
+           throw new NyARException();\r
        }\r
        //コードと比較する\r
-       eva.evaluate(code);\r
+       match_patt.evaluate(code);\r
        int square_index=0;\r
-       int direction=eva.getDirection();\r
-       double confidence=eva.getConfidence();\r
+       int direction=match_patt.getDirection();\r
+       double confidence=match_patt.getConfidence();\r
        for(int i=1;i<number_of_square;i++){\r
            //次のパターンを取得\r
-           patt.pickFromRaster(i_image,squares[i].getMarker());\r
+           patt.pickFromRaster(i_image,l_square_list.getSquare(i));\r
            //評価器にセットする。\r
-           eva.setPatt(patt);\r
+           match_patt.setPatt(patt);\r
             //コードと比較する\r
-            eva.evaluate(code);\r
-           double c2=eva.getConfidence();\r
+           match_patt.evaluate(code);\r
+           double c2=match_patt.getConfidence();\r
            if(confidence>c2){\r
                continue;\r
            }\r
            //もっと一致するマーカーがあったぽい\r
            square_index=i;\r
-           direction=eva.getDirection();\r
+           direction=match_patt.getDirection();\r
            confidence=c2;\r
        }\r
        //マーカー情報を保存\r
-       detected_square=squares[square_index];\r
+       detected_square=l_square_list.getSquare(square_index);\r
        detected_direction=direction;\r
        detected_confidence=confidence;\r
        return true;\r
index d1b84f3..1ba2ed6 100644 (file)
@@ -36,7 +36,8 @@ import jp.nyatla.nyartoolkit.detector.*;
 \r
 /**\r
  * 320x240のBGRA32で記録されたRAWイメージから、1種類のパターンを認識し、\r
- * その変換行列を求めます。\r
+ * その変換行列を1000回求め、それにかかったミリ秒時間を表示します。\r
+ * \r
  * \r
  * @author R.iizuka\r
  *\r
@@ -69,15 +70,19 @@ public class RawFileTest {
         \r
         //1パターンのみを追跡するクラスを作成\r
         NyARSingleDetectMarker ar=new NyARSingleDetectMarker(ap,code,80.0);\r
+        ar.detectMarkerLite(ra,100);\r
+        ar.getTransmationMatrix();\r
     \r
         //マーカーを検出\r
+        double[][] tm;\r
         Date d2=new Date();\r
-        for(int i=0;i<100;i++){\r
-            ar.detectMarkerLite(ra,100);\r
+        for(int i=0;i<1000;i++){\r
             //変換行列を取得\r
-            double[][] tm=ar.getTransmationMatrix().getArray();\r
+            ar.detectMarkerLite(ra,100);\r
+            ar.getTransmationMatrix();\r
         }\r
         Date d=new Date();\r
+        tm=null;\r
         System.out.println(d.getTime()-d2.getTime()); \r
     }\r
     public static void main(String[] args)\r
index 7743171..be2d7da 100644 (file)
@@ -1,17 +1,17 @@
 package jp.nyatla.util;\r
 \r
 public class IntValue {\r
-       private int v;\r
-       public void set(int i_v){\r
-               v=i_v;\r
-       }\r
-       public int get(){\r
-               return v;\r
-       }\r
-       public void inc(){\r
-               v++;\r
-       }\r
-       public void add(int i_v){\r
-               v+=i_v;\r
-       }\r
+    public int value;\r
+/*    public void set(int i_v){\r
+       v=i_v;\r
+    }\r
+    public int get(){\r
+       return v;\r
+    }\r
+    public void inc(){\r
+       v++;\r
+    }\r
+    public void add(int i_v){\r
+       v+=i_v;\r
+    }*/\r
 }\r