OSDN Git Service

[Backup]NyARToolkit for Java
authornyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Thu, 8 Oct 2009 11:50:46 +0000 (11:50 +0000)
committernyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Thu, 8 Oct 2009 11:50:46 +0000 (11:50 +0000)
モジュール構成修正

git-svn-id: http://svn.sourceforge.jp/svnroot/nyartoolkit/NyARToolkit@292 7cac0a50-4618-4814-88d0-24b83990f816

17 files changed:
trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARSingleQrDetector.java
trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARTransMat_X2.java
trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat.java
trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMatResult.java
trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat_ARToolKit.java [moved from trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat_NyARToolkit.java with 61% similarity]
trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/INyARRotMatrixOptimize.java [moved from trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/INyARRotMatrixOptimize.java with 84% similarity]
trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize.java [moved from trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotMatrixOptimize.java with 92% similarity]
trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize_Base.java [moved from trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotMatrixOptimize_Base.java with 93% similarity]
trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize_O2.java [moved from trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotMatrixOptimize_O2.java with 93% similarity]
trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix.java
trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit.java
trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit_O2.java [moved from trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_NyARToolKit.java with 91% similarity]
trunk/src/jp/nyatla/nyartoolkit/detector/NyARDetectMarker.java
trunk/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java
trunk/src/jp/nyatla/nyartoolkit/processor/SingleARMarkerProcesser.java
trunk/src/jp/nyatla/nyartoolkit/processor/SingleNyIdMarkerProcesser.java
trunk/test/jp/nyatla/nyartoolkit/dev/OptimizeView.java

index 99eefba..98ceae3 100644 (file)
@@ -79,7 +79,7 @@ public class NyARSingleQrDetector
                final NyARIntSize scr_size=i_param.getScreenSize();             \r
                // 解析オブジェクトを作る\r
                this._square_detect = new NyARQrCodeDetector(i_param.getDistortionFactor(),scr_size);\r
-               this._transmat = new NyARTransMat(i_param);\r
+               this._transmat = new NyARTransMat_ARToolKit(i_param);\r
                this._marker_width = i_marker_width;\r
                //2値画像バッファを作る\r
                this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h);\r
index 7f6e6e4..d233d51 100644 (file)
@@ -218,9 +218,6 @@ public class NyARTransMat_X2 implements INyARTransMat
                \r
                final NyARFixedFloat16Point3d angle=i_rot.refAngle();\r
 \r
-               o_result.angle.x=(double)angle.x/NyMath.FIXEDFLOAT16_1;\r
-               o_result.angle.y=(double)angle.y/NyMath.FIXEDFLOAT16_1;\r
-               o_result.angle.z=(double)angle.z/NyMath.FIXEDFLOAT16_1;\r
                o_result.has_value = true;\r
                return;\r
        }       \r
index 548e238..074bc66 100644 (file)
@@ -1,5 +1,5 @@
 /* \r
- * PROJECT: NyARToolkit\r
+ * PROJECT: NyARToolkit (Extension)\r
  * --------------------------------------------------------------------------------\r
  * This work is based on the original ARToolKit developed by\r
  *   Hirokazu Kato\r
  * The NyARToolkit is Java version ARToolkit class library.\r
  * Copyright (C)2008 R.Iizuka\r
  *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Lesser General Public License as \r
+ * published by the Free Software Foundation; either version 3 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful, \r
  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- * \r
- * You should have received a copy of the GNU General Public License\r
- * along with this framework; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
+ * See the GNU Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public \r
+ * License along with this program. If not, see <http://www.gnu.org/licenses/>.\r
  * \r
  * For further information please contact.\r
- *     http://nyatla.jp/nyatoolkit/\r
+ *     http://nyatla.jp/\r
  *     <airmail(at)ebony.plala.or.jp>\r
- * \r
  */\r
 package jp.nyatla.nyartoolkit.core.transmat;\r
 \r
@@ -35,10 +33,10 @@ import jp.nyatla.nyartoolkit.NyARException;
 import jp.nyatla.nyartoolkit.core.param.*;\r
 import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;\r
 import jp.nyatla.nyartoolkit.core.transmat.solver.*;\r
-import jp.nyatla.nyartoolkit.core.transmat.optimize.*;\r
+import jp.nyatla.nyartoolkit.core.transmat.optimize.NyARPartialDifferentiationOptimize;\r
 import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
-\r
+import jp.nyatla.nyartoolkit.core.types.matrix.*;\r
 \r
 /**\r
  * This class calculates ARMatrix from square information and holds it. --\r
@@ -47,15 +45,17 @@ import jp.nyatla.nyartoolkit.core.types.*;
  */\r
 public class NyARTransMat implements INyARTransMat\r
 {\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 double AR_GET_TRANS_CONT_MAT_MAX_FIT_ERROR = 1.0;\r
+       private final static double FIT_DIFF_THRESHOLD = 0.01;\r
+       private final static double FIT_DIFF_THRESHOLD_CONT = 1.0;\r
 \r
        private final NyARDoublePoint2d _center=new NyARDoublePoint2d(0,0);\r
        private final NyARTransOffset _offset=new NyARTransOffset();\r
+       private NyARPerspectiveProjectionMatrix _projection_mat_ref;\r
        protected NyARRotMatrix _rotmatrix;\r
        protected INyARTransportVectorSolver _transsolver;\r
-       protected INyARRotMatrixOptimize _mat_optimize;\r
+       protected NyARPartialDifferentiationOptimize _mat_optimize;\r
+\r
+\r
        private NyARCameraDistortionFactor _ref_dist_factor;\r
 \r
        /**\r
@@ -75,9 +75,10 @@ public class NyARTransMat implements INyARTransMat
                this._transsolver=new NyARTransportVectorSolver_ARToolKit(pmat);\r
                //互換性が重要な時は、NyARRotMatrix_ARToolKitを使うこと。\r
                //理屈はNyARRotMatrix_NyARToolKitもNyARRotMatrix_ARToolKitも同じだけど、少しだけ値がずれる。\r
-               this._rotmatrix = new NyARRotMatrix_NyARToolKit(pmat);\r
-               this._mat_optimize=new NyARRotMatrixOptimize_O2(pmat);\r
+               this._rotmatrix = new NyARRotMatrix(pmat);\r
+               this._mat_optimize=new NyARPartialDifferentiationOptimize(pmat);\r
                this._ref_dist_factor=dist;\r
+               this._projection_mat_ref=pmat;\r
        }\r
 \r
        public void setCenter(double i_x, double i_y)\r
@@ -194,51 +195,104 @@ public class NyARTransMat implements INyARTransMat
                //回転後の3D座標系から、平行移動量を計算\r
                this._rotmatrix.getPoint3dBatch(this._offset.vertex,vertex_3d,4);\r
                this._transsolver.solveTransportVector(vertex_3d,trans);\r
-               \r
-               //計算結果の最適化(平行移動量と回転行列の最適化)\r
-               double err=this.optimize(this._rotmatrix, trans, this._transsolver, this._offset.vertex, vertex_2d);\r
-               \r
-               // マトリクスの保存\r
-               this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);\r
-               \r
-               // エラー値が許容範囲でなければTransMatをやり直し\r
-               if (err > AR_GET_TRANS_CONT_MAT_MAX_FIT_ERROR) {\r
-                       // rotationを矩形情報で初期化\r
+\r
+               //現在のエラーレートを計算しておく\r
+               double min_err=errRate(this._rotmatrix,trans, this._offset.vertex, vertex_2d,4,vertex_3d);\r
+               NyARDoubleMatrix33 rot=this.__rot;\r
+               //エラーレートが閾値超えてたらアゲイン\r
+               if(min_err<FIT_DIFF_THRESHOLD_CONT){\r
+                       rot.setValue(this._rotmatrix);\r
+                       //最適化してみる。\r
+                       for (int i = 0;i<5; i++) {\r
+                               //変換行列の最適化\r
+                               this._mat_optimize.modifyMatrix(rot, trans, this._offset.vertex, vertex_2d, 4);\r
+                               double err=errRate(rot,trans,this._offset.vertex, vertex_2d,4,vertex_3d);\r
+                               //System.out.println("E:"+err);\r
+                               if(min_err-err<FIT_DIFF_THRESHOLD){\r
+                                       //System.out.println("BREAK");\r
+                                       break;\r
+                               }\r
+                               this._transsolver.solveTransportVector(vertex_3d, trans);\r
+                               this._rotmatrix.setValue(rot);\r
+                               min_err=err;\r
+                       }\r
+                       this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);\r
+               }else{\r
+                       //回転行列を計算\r
                        this._rotmatrix.initRotBySquare(linear_ref,sqvertex_ref);\r
-                       //回転行列の平行移動量の計算\r
+                       \r
+                       //回転後の3D座標系から、平行移動量を計算\r
                        this._rotmatrix.getPoint3dBatch(this._offset.vertex,vertex_3d,4);\r
                        this._transsolver.solveTransportVector(vertex_3d,trans);\r
-                       //計算結果の最適化(this._rotmatrix,trans)\r
-                       final double err2=this.optimize(this._rotmatrix, trans, this._transsolver, this._offset.vertex, vertex_2d);\r
-                       //エラー値が低かったら値を差換え\r
-                       if (err2 < err) {\r
-                               // 良い値が取れたら、差換え\r
-                               this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);\r
-                       }\r
+                       \r
+                       //計算結果の最適化(平行移動量と回転行列の最適化)\r
+                       this.optimize(this._rotmatrix, trans, this._transsolver,this._offset.vertex, vertex_2d);\r
+                       this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);\r
                }\r
                return;\r
        }\r
+       private NyARDoubleMatrix33 __rot=new NyARDoubleMatrix33();\r
        private double optimize(NyARRotMatrix io_rotmat,NyARDoublePoint3d io_transvec,INyARTransportVectorSolver i_solver,NyARDoublePoint3d[] i_offset_3d,NyARDoublePoint2d[] i_2d_vertex) throws NyARException\r
        {\r
+               //System.out.println("START");\r
                NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;\r
-               double err = -1;\r
-               // ループを抜けるタイミングをARToolKitと合わせるために変なことしてます。 \r
-               for (int i = 0;; i++) {\r
-                       // <arGetTransMat3>\r
-                       err = this._mat_optimize.modifyMatrix(io_rotmat, io_transvec, i_offset_3d, i_2d_vertex);\r
-                       io_rotmat.getPoint3dBatch(i_offset_3d,vertex_3d,4);\r
-                       i_solver.solveTransportVector(vertex_3d, io_transvec);\r
-                       \r
-                       err = this._mat_optimize.modifyMatrix(io_rotmat, io_transvec, i_offset_3d, i_2d_vertex);\r
-                       // //</arGetTransMat3>\r
-                       if (err < AR_GET_TRANS_MAT_MAX_FIT_ERROR || i == AR_GET_TRANS_MAT_MAX_LOOP_COUNT - 1) {\r
+               //初期のエラー値を計算\r
+               double min_err=errRate(io_rotmat, io_transvec, i_offset_3d, i_2d_vertex,4,vertex_3d);\r
+               NyARDoubleMatrix33 rot=this.__rot;\r
+               rot.setValue(io_rotmat);\r
+               for (int i = 0;i<5; i++) {\r
+                       //変換行列の最適化\r
+                       this._mat_optimize.modifyMatrix(rot, io_transvec, i_offset_3d, i_2d_vertex, 4);\r
+                       double err=errRate(rot,io_transvec, i_offset_3d, i_2d_vertex,4,vertex_3d);\r
+                       //System.out.println("E:"+err);\r
+                       if(min_err-err<FIT_DIFF_THRESHOLD){\r
+                               //System.out.println("BREAK");\r
                                break;\r
                        }\r
-                       io_rotmat.getPoint3dBatch(i_offset_3d,vertex_3d,4);\r
                        i_solver.solveTransportVector(vertex_3d, io_transvec);\r
+                       io_rotmat.setValue(rot);\r
+                       min_err=err;\r
                }\r
-               return err;\r
-       }       \r
+               //System.out.println("END");\r
+               return min_err;\r
+       }\r
+       \r
+       //エラーレート計算機\r
+       public double errRate(NyARDoubleMatrix33 io_rot,NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d,int i_number_of_vertex,NyARDoublePoint3d[] o_rot_vertex) throws NyARException\r
+       {\r
+               NyARPerspectiveProjectionMatrix cp = this._projection_mat_ref;\r
+               final double cp00=cp.m00;\r
+               final double cp01=cp.m01;\r
+               final double cp02=cp.m02;\r
+               final double cp11=cp.m11;\r
+               final double cp12=cp.m12;\r
+\r
+               double err=0;\r
+               for(int i=0;i<i_number_of_vertex;i++){\r
+                       double x3d,y3d,z3d;\r
+                       o_rot_vertex[i].x=x3d=io_rot.m00*i_vertex3d[i].x+io_rot.m01*i_vertex3d[i].y+io_rot.m02*i_vertex3d[i].z;\r
+                       o_rot_vertex[i].y=y3d=io_rot.m10*i_vertex3d[i].x+io_rot.m11*i_vertex3d[i].y+io_rot.m12*i_vertex3d[i].z;\r
+                       o_rot_vertex[i].z=z3d=io_rot.m20*i_vertex3d[i].x+io_rot.m21*i_vertex3d[i].y+io_rot.m22*i_vertex3d[i].z;\r
+                       x3d+=i_trans.x;\r
+                       y3d+=i_trans.y;\r
+                       z3d+=i_trans.z;\r
+                       \r
+                       //射影変換\r
+                       double x2d=x3d*cp00+y3d*cp01+z3d*cp02;\r
+                       double y2d=y3d*cp11+z3d*cp12;\r
+                       double h2d=z3d;\r
+                       \r
+                       //エラーレート計算\r
+                       double t1=i_vertex2d[i].x-x2d/h2d;\r
+                       double t2=i_vertex2d[i].y-y2d/h2d;\r
+                       err+=t1*t1+t2*t2;\r
+                       \r
+               }\r
+               return err/i_number_of_vertex;\r
+       }               \r
+       \r
+       \r
+       \r
        /**\r
         * パラメータで変換行列を更新します。\r
         * \r
@@ -263,7 +317,6 @@ public class NyARTransMat implements INyARTransMat
                o_result.m22 = i_rot.m22;\r
                o_result.m23 = i_rot.m20 * i_off.x + i_rot.m21 * i_off.y + i_rot.m22 * i_off.z + i_trans.z;\r
 \r
-               o_result.angle.setValue(i_rot.refAngle());\r
                o_result.has_value = true;\r
                return;\r
        }       \r
index f8ee00d..e6a4a45 100644 (file)
@@ -33,7 +33,6 @@ package jp.nyatla.nyartoolkit.core.transmat;
 \r
 \r
 import jp.nyatla.nyartoolkit.core.types.matrix.*;\r
-import jp.nyatla.nyartoolkit.core.types.*;\r
 \r
 /**\r
  * NyARTransMat戻り値専用のNyARMat\r
@@ -42,5 +41,4 @@ import jp.nyatla.nyartoolkit.core.types.*;
 public class NyARTransMatResult extends NyARDoubleMatrix34\r
 {\r
        public boolean has_value = false;\r
-       public final NyARDoublePoint3d angle=new NyARDoublePoint3d();\r
 }\r
@@ -1,5 +1,5 @@
 /* \r
- * PROJECT: NyARToolkit (Extension)\r
+ * PROJECT: NyARToolkit\r
  * --------------------------------------------------------------------------------\r
  * This work is based on the original ARToolKit developed by\r
  *   Hirokazu Kato\r
  * The NyARToolkit is Java version ARToolkit class library.\r
  * Copyright (C)2008 R.Iizuka\r
  *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as \r
- * published by the Free Software Foundation; either version 3 of the\r
- * License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful, \r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
- * See the GNU Lesser General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public \r
- * License along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
  * \r
  * For further information please contact.\r
- *     http://nyatla.jp/\r
+ *     http://nyatla.jp/nyatoolkit/\r
  *     <airmail(at)ebony.plala.or.jp>\r
+ * \r
  */\r
 package jp.nyatla.nyartoolkit.core.transmat;\r
 \r
@@ -33,52 +35,51 @@ import jp.nyatla.nyartoolkit.NyARException;
 import jp.nyatla.nyartoolkit.core.param.*;\r
 import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;\r
 import jp.nyatla.nyartoolkit.core.transmat.solver.*;\r
-import jp.nyatla.nyartoolkit.core.transmat.optimize.NyARPartialDifferentiationOptimize;\r
+import jp.nyatla.nyartoolkit.core.transmat.optimize.*;\r
+import jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit.INyARRotMatrixOptimize;\r
+import jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit.NyARRotMatrixOptimize_O2;\r
 import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
-import jp.nyatla.nyartoolkit.core.types.matrix.*;\r
+\r
 \r
 /**\r
  * This class calculates ARMatrix from square information and holds it. --\r
  * 変換行列を計算して、結果を保持するクラス。\r
  * \r
  */\r
-public class NyARTransMat_NyARToolkit implements INyARTransMat\r
+public class NyARTransMat_ARToolKit implements INyARTransMat\r
 {\r
-       private final static double FIT_DIFF_THRESHOLD = 0.01;\r
-       private final static double FIT_DIFF_THRESHOLD_CONT = 1.0;\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 double AR_GET_TRANS_CONT_MAT_MAX_FIT_ERROR = 1.0;\r
 \r
        private final NyARDoublePoint2d _center=new NyARDoublePoint2d(0,0);\r
        private final NyARTransOffset _offset=new NyARTransOffset();\r
-       private NyARPerspectiveProjectionMatrix _projection_mat_ref;\r
-       protected NyARRotMatrix _rotmatrix;\r
+       protected NyARRotMatrix_ARToolKit _rotmatrix;\r
        protected INyARTransportVectorSolver _transsolver;\r
-       protected NyARPartialDifferentiationOptimize _mat_optimize;\r
-\r
-\r
+       protected INyARRotMatrixOptimize _mat_optimize;\r
        private NyARCameraDistortionFactor _ref_dist_factor;\r
 \r
        /**\r
         * 派生クラスで自分でメンバオブジェクトを指定したい場合はこちらを使う。\r
         *\r
         */\r
-       protected NyARTransMat_NyARToolkit()\r
+       protected NyARTransMat_ARToolKit()\r
        {\r
                //_calculator,_rotmatrix,_mat_optimizeをコンストラクタの終了後に\r
                //作成して割り当ててください。\r
                return;\r
        }\r
-       public NyARTransMat_NyARToolkit(NyARParam i_param) throws NyARException\r
+       public NyARTransMat_ARToolKit(NyARParam i_param) throws NyARException\r
        {\r
                final NyARCameraDistortionFactor dist=i_param.getDistortionFactor();\r
                final NyARPerspectiveProjectionMatrix pmat=i_param.getPerspectiveProjectionMatrix();\r
                this._transsolver=new NyARTransportVectorSolver_ARToolKit(pmat);\r
                //互換性が重要な時は、NyARRotMatrix_ARToolKitを使うこと。\r
                //理屈はNyARRotMatrix_NyARToolKitもNyARRotMatrix_ARToolKitも同じだけど、少しだけ値がずれる。\r
-               this._rotmatrix = new NyARRotMatrix_NyARToolKit(pmat);\r
-               this._mat_optimize=new NyARPartialDifferentiationOptimize(pmat);\r
+               this._rotmatrix = new NyARRotMatrix_ARToolKit_O2(pmat);\r
+               this._mat_optimize=new NyARRotMatrixOptimize_O2(pmat);\r
                this._ref_dist_factor=dist;\r
-               this._projection_mat_ref=pmat;\r
        }\r
 \r
        public void setCenter(double i_x, double i_y)\r
@@ -195,104 +196,51 @@ public class NyARTransMat_NyARToolkit implements INyARTransMat
                //回転後の3D座標系から、平行移動量を計算\r
                this._rotmatrix.getPoint3dBatch(this._offset.vertex,vertex_3d,4);\r
                this._transsolver.solveTransportVector(vertex_3d,trans);\r
-\r
-               //現在のエラーレートを計算しておく\r
-               double min_err=errRate(this._rotmatrix,trans, this._offset.vertex, vertex_2d,4,vertex_3d);\r
-               NyARDoubleMatrix33 rot=this.__rot;\r
-               //エラーレートが閾値超えてたらアゲイン\r
-               if(min_err<FIT_DIFF_THRESHOLD_CONT){\r
-                       rot.setValue(this._rotmatrix);\r
-                       //最適化してみる。\r
-                       for (int i = 0;i<5; i++) {\r
-                               //変換行列の最適化\r
-                               this._mat_optimize.modifyMatrix(rot, trans, this._offset.vertex, vertex_2d, 4);\r
-                               double err=errRate(rot,trans,this._offset.vertex, vertex_2d,4,vertex_3d);\r
-                               //System.out.println("E:"+err);\r
-                               if(min_err-err<FIT_DIFF_THRESHOLD){\r
-                                       //System.out.println("BREAK");\r
-                                       break;\r
-                               }\r
-                               this._transsolver.solveTransportVector(vertex_3d, trans);\r
-                               this._rotmatrix.setValue(rot);\r
-                               min_err=err;\r
-                       }\r
-                       this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);\r
-               }else{\r
-                       //回転行列を計算\r
+               \r
+               //計算結果の最適化(平行移動量と回転行列の最適化)\r
+               double err=this.optimize(this._rotmatrix, trans, this._transsolver, this._offset.vertex, vertex_2d);\r
+               \r
+               // マトリクスの保存\r
+               this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);\r
+               \r
+               // エラー値が許容範囲でなければTransMatをやり直し\r
+               if (err > AR_GET_TRANS_CONT_MAT_MAX_FIT_ERROR) {\r
+                       // rotationを矩形情報で初期化\r
                        this._rotmatrix.initRotBySquare(linear_ref,sqvertex_ref);\r
-                       \r
-                       //回転後の3D座標系から、平行移動量を計算\r
+                       //回転行列の平行移動量の計算\r
                        this._rotmatrix.getPoint3dBatch(this._offset.vertex,vertex_3d,4);\r
                        this._transsolver.solveTransportVector(vertex_3d,trans);\r
-                       \r
-                       //計算結果の最適化(平行移動量と回転行列の最適化)\r
-                       this.optimize(this._rotmatrix, trans, this._transsolver,this._offset.vertex, vertex_2d);\r
-                       this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);\r
+                       //計算結果の最適化(this._rotmatrix,trans)\r
+                       final double err2=this.optimize(this._rotmatrix, trans, this._transsolver, this._offset.vertex, vertex_2d);\r
+                       //エラー値が低かったら値を差換え\r
+                       if (err2 < err) {\r
+                               // 良い値が取れたら、差換え\r
+                               this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);\r
+                       }\r
                }\r
                return;\r
        }\r
-       private NyARDoubleMatrix33 __rot=new NyARDoubleMatrix33();\r
-       private double optimize(NyARRotMatrix io_rotmat,NyARDoublePoint3d io_transvec,INyARTransportVectorSolver i_solver,NyARDoublePoint3d[] i_offset_3d,NyARDoublePoint2d[] i_2d_vertex) throws NyARException\r
+       private double optimize(NyARRotMatrix_ARToolKit io_rotmat,NyARDoublePoint3d io_transvec,INyARTransportVectorSolver i_solver,NyARDoublePoint3d[] i_offset_3d,NyARDoublePoint2d[] i_2d_vertex) throws NyARException\r
        {\r
-               //System.out.println("START");\r
                NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;\r
-               //初期のエラー値を計算\r
-               double min_err=errRate(io_rotmat, io_transvec, i_offset_3d, i_2d_vertex,4,vertex_3d);\r
-               NyARDoubleMatrix33 rot=this.__rot;\r
-               rot.setValue(io_rotmat);\r
-               for (int i = 0;i<5; i++) {\r
-                       //変換行列の最適化\r
-                       this._mat_optimize.modifyMatrix(rot, io_transvec, i_offset_3d, i_2d_vertex, 4);\r
-                       double err=errRate(rot,io_transvec, i_offset_3d, i_2d_vertex,4,vertex_3d);\r
-                       //System.out.println("E:"+err);\r
-                       if(min_err-err<FIT_DIFF_THRESHOLD){\r
-                               //System.out.println("BREAK");\r
+               double err = -1;\r
+               // ループを抜けるタイミングをARToolKitと合わせるために変なことしてます。 \r
+               for (int i = 0;; i++) {\r
+                       // <arGetTransMat3>\r
+                       err = this._mat_optimize.modifyMatrix(io_rotmat, io_transvec, i_offset_3d, i_2d_vertex);\r
+                       io_rotmat.getPoint3dBatch(i_offset_3d,vertex_3d,4);\r
+                       i_solver.solveTransportVector(vertex_3d, io_transvec);\r
+                       \r
+                       err = this._mat_optimize.modifyMatrix(io_rotmat, io_transvec, i_offset_3d, i_2d_vertex);\r
+                       // //</arGetTransMat3>\r
+                       if (err < AR_GET_TRANS_MAT_MAX_FIT_ERROR || i == AR_GET_TRANS_MAT_MAX_LOOP_COUNT - 1) {\r
                                break;\r
                        }\r
+                       io_rotmat.getPoint3dBatch(i_offset_3d,vertex_3d,4);\r
                        i_solver.solveTransportVector(vertex_3d, io_transvec);\r
-                       io_rotmat.setValue(rot);\r
-                       min_err=err;\r
-               }\r
-               //System.out.println("END");\r
-               return min_err;\r
-       }\r
-       \r
-       //エラーレート計算機\r
-       public double errRate(NyARDoubleMatrix33 io_rot,NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d,int i_number_of_vertex,NyARDoublePoint3d[] o_rot_vertex) throws NyARException\r
-       {\r
-               NyARPerspectiveProjectionMatrix cp = this._projection_mat_ref;\r
-               final double cp00=cp.m00;\r
-               final double cp01=cp.m01;\r
-               final double cp02=cp.m02;\r
-               final double cp11=cp.m11;\r
-               final double cp12=cp.m12;\r
-\r
-               double err=0;\r
-               for(int i=0;i<i_number_of_vertex;i++){\r
-                       double x3d,y3d,z3d;\r
-                       o_rot_vertex[i].x=x3d=io_rot.m00*i_vertex3d[i].x+io_rot.m01*i_vertex3d[i].y+io_rot.m02*i_vertex3d[i].z;\r
-                       o_rot_vertex[i].y=y3d=io_rot.m10*i_vertex3d[i].x+io_rot.m11*i_vertex3d[i].y+io_rot.m12*i_vertex3d[i].z;\r
-                       o_rot_vertex[i].z=z3d=io_rot.m20*i_vertex3d[i].x+io_rot.m21*i_vertex3d[i].y+io_rot.m22*i_vertex3d[i].z;\r
-                       x3d+=i_trans.x;\r
-                       y3d+=i_trans.y;\r
-                       z3d+=i_trans.z;\r
-                       \r
-                       //射影変換\r
-                       double x2d=x3d*cp00+y3d*cp01+z3d*cp02;\r
-                       double y2d=y3d*cp11+z3d*cp12;\r
-                       double h2d=z3d;\r
-                       \r
-                       //エラーレート計算\r
-                       double t1=i_vertex2d[i].x-x2d/h2d;\r
-                       double t2=i_vertex2d[i].y-y2d/h2d;\r
-                       err+=t1*t1+t2*t2;\r
-                       \r
                }\r
-               return err/i_number_of_vertex;\r
-       }               \r
-       \r
-       \r
-       \r
+               return err;\r
+       }       \r
        /**\r
         * パラメータで変換行列を更新します。\r
         * \r
@@ -317,7 +265,6 @@ public class NyARTransMat_NyARToolkit implements INyARTransMat
                o_result.m22 = i_rot.m22;\r
                o_result.m23 = i_rot.m20 * i_off.x + i_rot.m21 * i_off.y + i_rot.m22 * i_off.z + i_trans.z;\r
 \r
-               o_result.angle.setValue(i_rot.refAngle());\r
                o_result.has_value = true;\r
                return;\r
        }       \r
  *     <airmail(at)ebony.plala.or.jp>\r
  * \r
  */\r
-package jp.nyatla.nyartoolkit.core.transmat.optimize;\r
+package jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit;\r
 \r
 import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.NyARRotMatrix;\r
+import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
 \r
 public interface INyARRotMatrixOptimize\r
@@ -51,6 +51,6 @@ public interface INyARRotMatrixOptimize
         * @throws NyARException\r
         */\r
 //     public double optimize(NyARRotMatrix io_rotmat,NyARDoublePoint3d io_transvec,INyARTransportVectorSolver i_solver,NyARDoublePoint3d[] i_offset_3d,NyARDoublePoint2d[] i_2d_vertex) throws NyARException;\r
-       public double modifyMatrix(NyARRotMatrix io_rot, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException;\r
+       public double modifyMatrix(NyARRotMatrix_ARToolKit io_rot, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException;\r
        \r
 }\r
  *     <airmail(at)ebony.plala.or.jp>\r
  * \r
  */\r
-package jp.nyatla.nyartoolkit.core.transmat.optimize;\r
+package jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit;\r
 \r
 \r
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.param.*;\r
-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.NyARRotMatrix;\r
+import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;\r
 import jp.nyatla.nyartoolkit.core.transmat.solver.INyARTransportVectorSolver;\r
 import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;\r
 import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;\r
@@ -53,7 +53,7 @@ public class NyARRotMatrixOptimize implements INyARRotMatrixOptimize
                this._projection_mat_ref=i_projection_mat_ref;\r
                return;\r
        }\r
-       final public double optimize(NyARRotMatrix io_rotmat,NyARDoublePoint3d io_transvec,INyARTransportVectorSolver i_solver,NyARDoublePoint3d[] i_offset_3d,NyARDoublePoint2d[] i_2d_vertex) throws NyARException\r
+       final public double optimize(NyARRotMatrix_ARToolKit io_rotmat,NyARDoublePoint3d io_transvec,INyARTransportVectorSolver i_solver,NyARDoublePoint3d[] i_offset_3d,NyARDoublePoint2d[] i_2d_vertex) throws NyARException\r
        {\r
                double err = -1;\r
                /*ループを抜けるタイミングをARToolKitと合わせるために変なことしてます。*/\r
@@ -84,7 +84,7 @@ public class NyARRotMatrixOptimize implements INyARRotMatrixOptimize
         * @return\r
         * @throws NyARException\r
         */\r
-       public double modifyMatrix(NyARRotMatrix io_rot,NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException\r
+       public double modifyMatrix(NyARRotMatrix_ARToolKit io_rot,NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException\r
        {\r
                double factor;\r
                double a2, b2, c2;\r
  *     <airmail(at)ebony.plala.or.jp>\r
  * \r
  */\r
-package jp.nyatla.nyartoolkit.core.transmat.optimize;\r
+package jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit;\r
 \r
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.param.*;\r
-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.NyARRotMatrix;\r
+import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;\r
 import jp.nyatla.nyartoolkit.core.types.matrix.*;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
 \r
@@ -141,7 +141,7 @@ public class NyARRotMatrixOptimize_Base implements INyARRotMatrixOptimize
        private final NyARDoublePoint3d __modifyMatrix_angle = new NyARDoublePoint3d();\r
        private final NyARDoubleMatrix34 __modifyMatrix_combo=new NyARDoubleMatrix34();\r
        private final NyARDoubleMatrix33[] __modifyMatrix_next_rot_matrix=NyARDoubleMatrix33.createArray(27); \r
-       public double modifyMatrix(NyARRotMatrix io_rot, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException\r
+       public double modifyMatrix(NyARRotMatrix_ARToolKit io_rot, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException\r
        {\r
                final NyARDoublePoint3d angle = this.__modifyMatrix_angle;\r
                final NyARDoubleMatrix34 combo=this.__modifyMatrix_combo;\r
  *     <airmail(at)ebony.plala.or.jp>\r
  * \r
  */\r
-package jp.nyatla.nyartoolkit.core.transmat.optimize;\r
+package jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit;\r
 \r
 \r
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.param.*;\r
-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.NyARRotMatrix;\r
+import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;\r
 import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;\r
 import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;\r
 /**\r
@@ -62,7 +62,7 @@ public class NyARRotMatrixOptimize_O2 implements INyARRotMatrixOptimize
         * @return\r
         * @throws NyARException\r
         */\r
-       public double modifyMatrix(NyARRotMatrix io_rot,NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException\r
+       public double modifyMatrix(NyARRotMatrix_ARToolKit io_rot,NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException\r
        {\r
                double factor;\r
                double a2, b2, c2;\r
index cd2fdfa..dc3987f 100644 (file)
@@ -32,6 +32,7 @@
 package jp.nyatla.nyartoolkit.core.transmat.rotmatrix;\r
 \r
 import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.param.NyARPerspectiveProjectionMatrix;\r
 import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
 import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix33;\r
@@ -39,38 +40,115 @@ import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix33;
  * 回転行列計算用の、3x3行列\r
  *\r
  */\r
-public abstract class NyARRotMatrix extends NyARDoubleMatrix33\r
-{      \r
+public class NyARRotMatrix extends NyARDoubleMatrix33\r
+{\r
        /**\r
-        * NyARTransMatResultの内容からNyARRotMatrixを復元します。\r
-        * @param i_prev_result\r
+        * インスタンスを準備します。\r
+        * \r
+        * @param i_param\r
         */\r
-       public abstract void initRotByPrevResult(NyARTransMatResult i_prev_result);\r
-       public abstract void initRotBySquare(final NyARLinear[] i_linear,final NyARDoublePoint2d[] i_sqvertex) throws NyARException;\r
+       public NyARRotMatrix(NyARPerspectiveProjectionMatrix i_matrix) throws NyARException\r
+       {\r
+               this.__initRot_vec1=new NyARRotVector(i_matrix);\r
+               this.__initRot_vec2=new NyARRotVector(i_matrix);\r
+               return;\r
+       }\r
+       final private NyARRotVector __initRot_vec1;\r
+       final private NyARRotVector __initRot_vec2;\r
        /**\r
-        * 格納しているAngleの参照値を返します。\r
-        * 返したオブジェクトはクラスに所有し続けられ、内容が変わることがあります。\r
-        * @return\r
+        * NyARTransMatResultの内容からNyARRotMatrixを復元します。\r
+        * @param i_prev_result\r
         */\r
-       public abstract NyARDoublePoint3d refAngle();\r
+       public final void initRotByPrevResult(NyARTransMatResult i_prev_result)\r
+       {\r
+\r
+               this.m00=i_prev_result.m00;\r
+               this.m01=i_prev_result.m01;\r
+               this.m02=i_prev_result.m02;\r
+\r
+               this.m10=i_prev_result.m10;\r
+               this.m11=i_prev_result.m11;\r
+               this.m12=i_prev_result.m12;\r
+\r
+               this.m20=i_prev_result.m20;\r
+               this.m21=i_prev_result.m21;\r
+               this.m22=i_prev_result.m22;\r
+               return;\r
+       }       \r
        /**\r
-        * 回転角から回転行列を計算してセットします。\r
-        * @param i_x\r
-        * @param i_y\r
-        * @param i_z\r
+        * \r
+        * @param i_linear\r
+        * @param i_sqvertex\r
+        * @throws NyARException\r
         */\r
-       public abstract void setAngle(final double i_x, final double i_y, final double i_z);\r
+       public void initRotBySquare(final NyARLinear[] i_linear,final NyARDoublePoint2d[] i_sqvertex) throws NyARException\r
+       {\r
+               final NyARRotVector vec1=this.__initRot_vec1;\r
+               final NyARRotVector vec2=this.__initRot_vec2;\r
+\r
+               //向かい合った辺から、2本のベクトルを計算\r
+               \r
+               //軸1\r
+               vec1.exteriorProductFromLinear(i_linear[0], i_linear[2]);\r
+               vec1.checkVectorByVertex(i_sqvertex[0], i_sqvertex[1]);\r
+\r
+               //軸2\r
+               vec2.exteriorProductFromLinear(i_linear[1], i_linear[3]);\r
+               vec2.checkVectorByVertex(i_sqvertex[3], i_sqvertex[0]);\r
+\r
+               //回転の最適化?\r
+               NyARRotVector.checkRotation(vec1,vec2);\r
+\r
+               this.m00 =vec1.v1;\r
+               this.m10 =vec1.v2;\r
+               this.m20 =vec1.v3;\r
+               this.m01 =vec2.v1;\r
+               this.m11 =vec2.v2;\r
+               this.m21 =vec2.v3;\r
+               \r
+               //最後の軸を計算\r
+               final double w02 = vec1.v2 * vec2.v3 - vec1.v3 * vec2.v2;\r
+               final double w12 = vec1.v3 * vec2.v1 - vec1.v1 * vec2.v3;\r
+               final double w22 = vec1.v1 * vec2.v2 - vec1.v2 * vec2.v1;\r
+               final double w = Math.sqrt(w02 * w02 + w12 * w12 + w22 * w22);\r
+               this.m02 = w02/w;\r
+               this.m12 = w12/w;\r
+               this.m22 = w22/w;\r
+               return;\r
+       }\r
        /**\r
         * i_in_pointを変換行列で座標変換する。\r
         * @param i_in_point\r
         * @param i_out_point\r
-        */     \r
-       public abstract void getPoint3d(final NyARDoublePoint3d i_in_point,final NyARDoublePoint3d i_out_point);\r
+        */\r
+       public final void getPoint3d(final NyARDoublePoint3d i_in_point,final NyARDoublePoint3d i_out_point)\r
+       {\r
+               final double x=i_in_point.x;\r
+               final double y=i_in_point.y;\r
+               final double z=i_in_point.z;\r
+               i_out_point.x=this.m00 * x + this.m01 * y + this.m02 * z;\r
+               i_out_point.y=this.m10 * x + this.m11 * y + this.m12 * z;\r
+               i_out_point.z=this.m20 * x + this.m21 * y + this.m22 * z;\r
+               return;\r
+       }\r
        /**\r
         * 複数の頂点を一括して変換する\r
         * @param i_in_point\r
         * @param i_out_point\r
         * @param i_number_of_vertex\r
         */\r
-       public abstract void getPoint3dBatch(final NyARDoublePoint3d[] i_in_point,NyARDoublePoint3d[] i_out_point,int i_number_of_vertex);\r
+       public final void getPoint3dBatch(final NyARDoublePoint3d[] i_in_point,NyARDoublePoint3d[] i_out_point,int i_number_of_vertex)\r
+       {\r
+               for(int i=i_number_of_vertex-1;i>=0;i--){\r
+                       final NyARDoublePoint3d out_ptr=i_out_point[i];\r
+                       final NyARDoublePoint3d in_ptr=i_in_point[i];\r
+                       final double x=in_ptr.x;\r
+                       final double y=in_ptr.y;\r
+                       final double z=in_ptr.z;\r
+                       out_ptr.x=this.m00 * x + this.m01 * y + this.m02 * z;\r
+                       out_ptr.y=this.m10 * x + this.m11 * y + this.m12 * z;\r
+                       out_ptr.z=this.m20 * x + this.m21 * y + this.m22 * z;\r
+               }\r
+               return;\r
+       }\r
 }\r
index e32085d..271a873 100644 (file)
@@ -32,7 +32,6 @@
 package jp.nyatla.nyartoolkit.core.transmat.rotmatrix;\r
 \r
 import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
 import jp.nyatla.nyartoolkit.core.param.*;\r
 /**\r
@@ -48,69 +47,17 @@ public class NyARRotMatrix_ARToolKit extends NyARRotMatrix
         */\r
        public NyARRotMatrix_ARToolKit(NyARPerspectiveProjectionMatrix i_matrix) throws NyARException\r
        {\r
-               this.__initRot_vec1=new NyARRotVector(i_matrix);\r
-               this.__initRot_vec2=new NyARRotVector(i_matrix);\r
+               super(i_matrix);\r
                this._angle=new NyARDoublePoint3d();\r
                return;\r
        }\r
-       final private NyARRotVector __initRot_vec1;\r
-       final private NyARRotVector __initRot_vec2;\r
        final protected NyARDoublePoint3d _angle;\r
        \r
 \r
        \r
-\r
-       public final void initRotByPrevResult(NyARTransMatResult i_prev_result)\r
-       {\r
-\r
-               this.m00=i_prev_result.m00;\r
-               this.m01=i_prev_result.m01;\r
-               this.m02=i_prev_result.m02;\r
-\r
-               this.m10=i_prev_result.m10;\r
-               this.m11=i_prev_result.m11;\r
-               this.m12=i_prev_result.m12;\r
-\r
-               this.m20=i_prev_result.m20;\r
-               this.m21=i_prev_result.m21;\r
-               this.m22=i_prev_result.m22;\r
-               return;\r
-       }       \r
-       \r
-       \r
        public final void initRotBySquare(final NyARLinear[] i_linear,final NyARDoublePoint2d[] i_sqvertex) throws NyARException\r
        {\r
-               final NyARRotVector vec1=this.__initRot_vec1;\r
-               final NyARRotVector vec2=this.__initRot_vec2;\r
-\r
-               //向かい合った辺から、2本のベクトルを計算\r
-               \r
-               //軸1\r
-               vec1.exteriorProductFromLinear(i_linear[0], i_linear[2]);\r
-               vec1.checkVectorByVertex(i_sqvertex[0], i_sqvertex[1]);\r
-\r
-               //軸2\r
-               vec2.exteriorProductFromLinear(i_linear[1], i_linear[3]);\r
-               vec2.checkVectorByVertex(i_sqvertex[3], i_sqvertex[0]);\r
-\r
-               //回転の最適化?\r
-               NyARRotVector.checkRotation(vec1,vec2);\r
-\r
-               this.m00 =vec1.v1;\r
-               this.m10 =vec1.v2;\r
-               this.m20 =vec1.v3;\r
-               this.m01 =vec2.v1;\r
-               this.m11 =vec2.v2;\r
-               this.m21 =vec2.v3;\r
-               \r
-               //最後の軸を計算\r
-               final double w02 = vec1.v2 * vec2.v3 - vec1.v3 * vec2.v2;\r
-               final double w12 = vec1.v3 * vec2.v1 - vec1.v1 * vec2.v3;\r
-               final double w22 = vec1.v1 * vec2.v2 - vec1.v2 * vec2.v1;\r
-               final double w = Math.sqrt(w02 * w02 + w12 * w12 + w22 * w22);\r
-               this.m02 = w02/w;\r
-               this.m12 = w12/w;\r
-               this.m22 = w22/w;\r
+               super.initRotBySquare(i_linear,i_sqvertex);\r
                //Matrixからangleをロード\r
                this.updateAngleFromMatrix();\r
                return;\r
@@ -154,41 +101,6 @@ public class NyARRotMatrix_ARToolKit extends NyARRotMatrix
                return;\r
        }\r
        /**\r
-        * i_in_pointを変換行列で座標変換する。\r
-        * @param i_in_point\r
-        * @param i_out_point\r
-        */\r
-       public final void getPoint3d(final NyARDoublePoint3d i_in_point,final NyARDoublePoint3d i_out_point)\r
-       {\r
-               final double x=i_in_point.x;\r
-               final double y=i_in_point.y;\r
-               final double z=i_in_point.z;\r
-               i_out_point.x=this.m00 * x + this.m01 * y + this.m02 * z;\r
-               i_out_point.y=this.m10 * x + this.m11 * y + this.m12 * z;\r
-               i_out_point.z=this.m20 * x + this.m21 * y + this.m22 * z;\r
-               return;\r
-       }\r
-       /**\r
-        * 複数の頂点を一括して変換する\r
-        * @param i_in_point\r
-        * @param i_out_point\r
-        * @param i_number_of_vertex\r
-        */\r
-       public final void getPoint3dBatch(final NyARDoublePoint3d[] i_in_point,NyARDoublePoint3d[] i_out_point,int i_number_of_vertex)\r
-       {\r
-               for(int i=i_number_of_vertex-1;i>=0;i--){\r
-                       final NyARDoublePoint3d out_ptr=i_out_point[i];\r
-                       final NyARDoublePoint3d in_ptr=i_in_point[i];\r
-                       final double x=in_ptr.x;\r
-                       final double y=in_ptr.y;\r
-                       final double z=in_ptr.z;\r
-                       out_ptr.x=this.m00 * x + this.m01 * y + this.m02 * z;\r
-                       out_ptr.y=this.m10 * x + this.m11 * y + this.m12 * z;\r
-                       out_ptr.z=this.m20 * x + this.m21 * y + this.m22 * z;\r
-               }\r
-               return;\r
-       }\r
-       /**\r
         * 現在のMatrixからangkeを復元する。\r
         * @param o_angle\r
         */\r
@@ -39,14 +39,14 @@ import jp.nyatla.nyartoolkit.core.param.*;
  * 処理を省略しているため、下位12桁目の計算値が異なる。\r
  *\r
  */\r
-public class NyARRotMatrix_NyARToolKit extends NyARRotMatrix_ARToolKit\r
+public class NyARRotMatrix_ARToolKit_O2 extends NyARRotMatrix_ARToolKit\r
 {      \r
        /**\r
         * インスタンスを準備します。\r
         * \r
         * @param i_param\r
         */\r
-       public NyARRotMatrix_NyARToolKit(NyARPerspectiveProjectionMatrix i_matrix) throws NyARException\r
+       public NyARRotMatrix_ARToolKit_O2(NyARPerspectiveProjectionMatrix i_matrix) throws NyARException\r
        {\r
                super(i_matrix);\r
                return;\r
index 43dcf4e..9ca8b49 100644 (file)
@@ -136,7 +136,7 @@ public class NyARDetectMarker
                final NyARIntSize scr_size=i_ref_param.getScreenSize();\r
                // 解析オブジェクトを作る\r
 \r
-               this._transmat = new NyARTransMat_NyARToolkit(i_ref_param);\r
+               this._transmat = new NyARTransMat(i_ref_param);\r
                //各コード用の比較器を作る。\r
                this._match_patt=new NyARMatchPatt_Color_WITHOUT_PCA[i_number_of_code];\r
                final int cw = i_ref_code[0].getWidth();\r
index 2107a98..f0adac4 100644 (file)
@@ -102,17 +102,17 @@ public class NyARSingleDetectMarker extends NyARCustomSingleDetectMarker
                case PF_ARTOOLKIT_COMPATIBLE:\r
                        patt_inst=new NyARColorPatt_O3(i_ref_code.getWidth(), i_ref_code.getHeight());\r
                        sqdetect_inst=new NyARSquareDetector_ARToolKit(i_ref_param.getDistortionFactor(),i_ref_param.getScreenSize());\r
-                       transmat_inst=new NyARTransMat(i_ref_param);\r
+                       transmat_inst=new NyARTransMat_ARToolKit(i_ref_param);\r
                        break;\r
                case PF_NYARTOOLKIT_ARTOOLKIT_FITTING:\r
                        patt_inst=new NyARColorPatt_Perspective_O2(i_ref_code.getWidth(), i_ref_code.getHeight(),4,25);\r
                        sqdetect_inst=new NyARSquareDetector_Rle(i_ref_param.getDistortionFactor(),i_ref_param.getScreenSize());\r
-                       transmat_inst=new NyARTransMat(i_ref_param);\r
+                       transmat_inst=new NyARTransMat_ARToolKit(i_ref_param);\r
                        break;\r
-               case PF_NYARTOOLKIT:\r
+               case PF_NYARTOOLKIT://default\r
                        patt_inst=new NyARColorPatt_Perspective_O2(i_ref_code.getWidth(), i_ref_code.getHeight(),4,25);\r
                        sqdetect_inst=new NyARSquareDetector_Rle(i_ref_param.getDistortionFactor(),i_ref_param.getScreenSize());\r
-                       transmat_inst=new NyARTransMat_NyARToolkit(i_ref_param);\r
+                       transmat_inst=new NyARTransMat(i_ref_param);\r
                        break;\r
                default:\r
                        throw new NyARException();\r
index d61958b..fe3120e 100644 (file)
@@ -107,7 +107,7 @@ public abstract class SingleARMarkerProcesser
                NyARIntSize scr_size = i_param.getScreenSize();\r
                // 解析オブジェクトを作る\r
                this._square_detect = new NyARSquareDetector_Rle(i_param.getDistortionFactor(), scr_size);\r
-               this._transmat = new NyARTransMat_NyARToolkit(i_param);\r
+               this._transmat = new NyARTransMat(i_param);\r
                this._tobin_filter=new NyARRasterFilter_ARToolkitThreshold(110,i_raster_type);\r
 \r
                // 2値画像バッファを作る\r
index c4bcd12..ea7b750 100644 (file)
@@ -78,7 +78,7 @@ public abstract class SingleNyIdMarkerProcesser
                NyARIntSize scr_size = i_param.getScreenSize();\r
                // 解析オブジェクトを作る\r
                this._square_detect = new NyARSquareDetector_Rle(i_param.getDistortionFactor(), scr_size);\r
-               this._transmat = new NyARTransMat_NyARToolkit(i_param);\r
+               this._transmat = new NyARTransMat(i_param);\r
                this._encoder=i_encoder;\r
 \r
                // 2値画像バッファを作る\r
index 5186d21..3e33dd0 100644 (file)
@@ -45,8 +45,8 @@ class Program implements JmfCaptureListener
        public Object _sync_object=new Object();        \r
        public NyARParam _ar_param;\r
        public NyARCode _ar_code;\r
-       private final static int SCREEN_X = 320;\r
-       private final static int SCREEN_Y = 240;\r
+       private final static int SCREEN_X = 640;\r
+       private final static int SCREEN_Y = 480;\r
        private JmfCaptureDevice _capture;\r
        public GLNyARRaster_RGB _cap_image;\r
        public Program(NyARParam i_param, NyARCode i_ar_code) throws NyARException\r
@@ -63,7 +63,7 @@ class Program implements JmfCaptureListener
                // GL対応のRGBラスタオブジェクト\r
                this._cap_image = new GLNyARRaster_RGB(i_param, this._capture.getCaptureFormat());      \r
                this._view1=new OptimizeView(this,NyARSingleDetectMarker.PF_NYARTOOLKIT);\r
-               this._view2=new OptimizeView(this,NyARSingleDetectMarker.PF_TEST1);\r
+               this._view2=new OptimizeView(this,NyARSingleDetectMarker.PF_NYARTOOLKIT_ARTOOLKIT_FITTING);\r
                this._capture.start();\r
                return;\r
        }\r
@@ -127,9 +127,9 @@ class Program implements JmfCaptureListener
  */\r
 public class OptimizeView implements GLEventListener\r
 {\r
-       private final static int SCREEN_X = 320;\r
+       private final static int SCREEN_X = 640;\r
 \r
-       private final static int SCREEN_Y = 240;\r
+       private final static int SCREEN_Y = 480;\r
 \r
        private Animator _animator;\r
        \r
@@ -157,7 +157,7 @@ public class OptimizeView implements GLEventListener
 \r
                // NyARToolkitの準備\r
                this._nya = new NyARSingleDetectMarker(this._ar_param, i_program._ar_code, 80.0,i_program._cap_image.getBufferReader().getBufferType(),i_pf);\r
-               this._nya.setContinueMode(true);// ここをtrueにすると、transMatContinueモード(History計算)になります。\r
+               this._nya.setContinueMode(false);// ここをtrueにすると、transMatContinueモード(History計算)になります。\r
                \r
                // 3Dを描画するコンポーネント\r
                GLCanvas canvas = new GLCanvas();\r