return current;\r
}\r
\r
- private void addFragment(RleElement i_rel_img, int i_nof, int i_row_index, int i_rel_index,RleInfoStack o_stack) throws NyARException\r
+ private void addFragment(RleElement i_rel_img, int i_nof, int i_row_index,RleInfoStack o_stack) throws NyARException\r
{\r
int l=i_rel_img.l;\r
final int len=i_rel_img.r - l;\r
len_prev = toRel(in_buf, i_top, width, rle_prev);\r
for (int i = 0; i < len_prev; i++) {\r
// フラグメントID=フラグメント初期値、POS=Y値、RELインデクス=行\r
- addFragment(rle_prev[i], id_max, i_top, i,rlestack);\r
+ addFragment(rle_prev[i], id_max, i_top,rlestack);\r
id_max++;\r
// nofの最大値チェック\r
label_count++;\r
continue;\r
} else if (rle_prev[index_prev].l - rle_current[i].r > 0) {// 0なら8方位ラベリングになる\r
// prevがcur右方にある→独立フラグメント\r
- addFragment(rle_current[i], id_max, y, i,rlestack);\r
+ addFragment(rle_current[i], id_max, y,rlestack);\r
id_max++;\r
label_count++;\r
// 次のindexをしらべる\r
// curにidが割り当てられたかを確認\r
// 右端独立フラグメントを追加\r
if (id < 0){\r
- addFragment(rle_current[i], id_max, y, i,rlestack);\r
+ addFragment(rle_current[i], id_max, y,rlestack);\r
id_max++;\r
label_count++;\r
}\r
\r
interface IpickFromRaster_Impl\r
{\r
- public void pickFromRaster(double[] i_cpara,INyARRgbRaster image, NyARSquare i_square,int[] o_patt)throws NyARException;\r
+ public void pickFromRaster(double[] i_cpara,INyARRgbRaster image, int[] o_patt)throws NyARException;\r
}\r
\r
/**\r
private double[] _cp4cy_cp5;\r
private double[] _cp7cy_1;\r
\r
- public void pickFromRaster(double[] i_cpara,INyARRgbRaster image, NyARSquare i_square,int[] o_patt)throws NyARException\r
+ public void pickFromRaster(double[] i_cpara,INyARRgbRaster image,int[] o_patt)throws NyARException\r
{\r
int i2x,i2y;//プライム変数\r
int x,y;\r
private int[] _rgb_py;\r
\r
\r
- public void pickFromRaster(double[] i_cpara,INyARRgbRaster image, NyARSquare i_square,int[] o_patt)throws NyARException\r
+ public void pickFromRaster(double[] i_cpara,INyARRgbRaster image,int[] o_patt)throws NyARException\r
{\r
double d0,m0;\r
int x,y;\r
private int[] _rgb_py;\r
\r
\r
- public void pickFromRaster(double[] i_cpara,INyARRgbRaster image, NyARSquare i_square,int[] o_patt)throws NyARException\r
+ public void pickFromRaster(double[] i_cpara,INyARRgbRaster image,int[] o_patt)throws NyARException\r
{\r
double d0,m0,d1,m1;\r
int x,y;\r
private int[] _rgb_px;\r
private int[] _rgb_py;\r
\r
- public void pickFromRaster(double[] i_cpara,INyARRgbRaster image, NyARSquare i_square,int[] o_patt)throws NyARException\r
+ public void pickFromRaster(double[] i_cpara,INyARRgbRaster image,int[] o_patt)throws NyARException\r
{\r
int x,y;\r
double d,m;\r
if (!this._perspective_gen.getParam(i_square.imvertex, cpara)) {\r
return false;\r
} \r
- this._pickup.pickFromRaster(cpara, image, i_square, this._patdata);\r
+ this._pickup.pickFromRaster(cpara, image,this._patdata);\r
return true;\r
}\r
\r
import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;\r
import jp.nyatla.nyartoolkit.core.types.*;\r
import jp.nyatla.nyartoolkit.core.types.matrix.*;\r
-import jp.nyatla.nyartoolkit.core.utils.NyARDoubleMatrixProcessor;\r
+\r
\r
\r
/**\r
mat.m31=0;\r
mat.m32=i_height-1;\r
mat.m33=1.0;\r
- NyARDoubleMatrixProcessor.inverse(mat,mat);\r
+ mat.inverse(mat);\r
return;\r
} \r
\r
import jp.nyatla.nyartoolkit.NyARException;\r
import jp.nyatla.nyartoolkit.core.param.*;\r
import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;\r
-import jp.nyatla.nyartoolkit.core.transmat.fitveccalc.NyARFitVecCalculator;\r
+import jp.nyatla.nyartoolkit.core.transmat.solver.*;\r
import jp.nyatla.nyartoolkit.core.transmat.optimize.*;\r
import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;\r
import jp.nyatla.nyartoolkit.core.types.*;\r
*/\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
\r
private final NyARDoublePoint2d _center=new NyARDoublePoint2d(0,0);\r
private final NyARTransOffset _offset=new NyARTransOffset();\r
protected NyARRotMatrix _rotmatrix;\r
- protected NyARFitVecCalculator _calculator;\r
- protected INyARRotTransOptimize _mat_optimize;\r
+ protected INyARTransportVectorSolver _transsolver;\r
+ protected INyARRotMatrixOptimize _mat_optimize;\r
+ private NyARCameraDistortionFactor _ref_dist_factor;\r
\r
/**\r
* 派生クラスで自分でメンバオブジェクトを指定したい場合はこちらを使う。\r
{\r
final NyARCameraDistortionFactor dist=i_param.getDistortionFactor();\r
final NyARPerspectiveProjectionMatrix pmat=i_param.getPerspectiveProjectionMatrix();\r
- this._calculator=new NyARFitVecCalculator(pmat,dist);\r
+ this._transsolver=new NyARTransportVectorSolver_ARToolKit(pmat);\r
//互換性が重要な時は、NyARRotMatrix_ARToolKitを使うこと。\r
//理屈はNyARRotMatrix_NyARToolKitもNyARRotMatrix_ARToolKitも同じだけど、少しだけ値がずれる。\r
this._rotmatrix = new NyARRotMatrix_NyARToolKit(pmat);\r
-// this._rotmatrix = new NyARRotMatrix_ARToolKit(pmat);\r
- this._mat_optimize=new NyARRotTransOptimize_O2(pmat);\r
+ this._mat_optimize=new NyARRotMatrixOptimize_O2(pmat);\r
+ this._ref_dist_factor=dist;\r
}\r
\r
public void setCenter(double i_x, double i_y)\r
\r
\r
private final NyARDoublePoint2d[] __transMat_sqvertex_ref = new NyARDoublePoint2d[4];\r
+ private final NyARDoublePoint2d[] __transMat_vertex_2d = NyARDoublePoint2d.createArray(4);\r
+ private final NyARDoublePoint3d[] __transMat_vertex_3d = NyARDoublePoint3d.createArray(4);\r
private final NyARLinear[] __transMat_linear_ref=new NyARLinear[4];\r
private final NyARDoublePoint3d __transMat_trans=new NyARDoublePoint3d();\r
/**\r
//計算用に頂点情報を初期化(順番調整)\r
initVertexOrder(i_square, i_direction, sqvertex_ref,linear_ref);\r
\r
- //基準矩形を設定\r
+ //平行移動量計算機に、2D座標系をセット\r
+ NyARDoublePoint2d[] vertex_2d=this.__transMat_vertex_2d;\r
+ NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;\r
+ this._ref_dist_factor.ideal2ObservBatch(sqvertex_ref, vertex_2d,4); \r
+ this._transsolver.set2dVertex(vertex_2d,4);\r
+ \r
+ //基準矩形の3D座標系を作成\r
this._offset.setSquare(i_width,this._center);\r
\r
- // rotationを矩形情報から計算\r
+ //回転行列を計算\r
this._rotmatrix.initRotBySquare(linear_ref,sqvertex_ref);\r
-\r
- //平行移動量計算機にオフセット頂点をセット\r
- this._calculator.setOffsetSquare(this._offset);\r
\r
- //平行移動量計算機に適応先矩形の情報をセット\r
- this._calculator.setFittedSquare(sqvertex_ref); \r
-\r
- //回転行列の平行移動量の計算\r
- this._calculator.calculateTransfer(this._rotmatrix,trans);\r
+ //回転後の3D座標系から、平行移動量を計算\r
+ this._rotmatrix.getPoint3dBatch(this._offset.vertex,vertex_3d,4);\r
+ this._transsolver.solveTransportVector(vertex_3d,trans);\r
\r
- //計算結果の最適化(this._rotmatrix,trans)\r
- this._mat_optimize.optimize(this._rotmatrix,trans,this._calculator);\r
+ //計算結果の最適化(平行移動量と回転行列の最適化)\r
+ 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
* (non-Javadoc)\r
* @see jp.nyatla.nyartoolkit.core.transmat.INyARTransMat#transMatContinue(jp.nyatla.nyartoolkit.core.NyARSquare, int, double, jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult)\r
*/\r
- public void transMatContinue(NyARSquare i_square, int i_direction, double i_width, NyARTransMatResult io_result_conv) throws NyARException\r
+ public void transMatContinue(NyARSquare i_square, int i_direction, double i_width, NyARTransMatResult o_result_conv) throws NyARException\r
{\r
final NyARDoublePoint2d[] sqvertex_ref = __transMat_sqvertex_ref;\r
final NyARLinear[] linear_ref=__transMat_linear_ref;\r
final NyARDoublePoint3d trans=this.__transMat_trans;\r
\r
// io_result_convが初期値なら、transMatで計算する。\r
- if (!io_result_conv.has_value) {\r
- this.transMat(i_square, i_direction, i_width, io_result_conv);\r
+ if (!o_result_conv.has_value) {\r
+ this.transMat(i_square, i_direction, i_width, o_result_conv);\r
return;\r
}\r
\r
//計算用に頂点情報を初期化(順番調整)\r
initVertexOrder(i_square, i_direction, sqvertex_ref,linear_ref);\r
+\r
\r
- //基準矩形を設定\r
+ //平行移動量計算機に、2D座標系をセット\r
+ NyARDoublePoint2d[] vertex_2d=this.__transMat_vertex_2d;\r
+ NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;\r
+ this._ref_dist_factor.ideal2ObservBatch(sqvertex_ref, vertex_2d,4); \r
+ this._transsolver.set2dVertex(vertex_2d,4);\r
+ \r
+ //基準矩形の3D座標系を作成\r
this._offset.setSquare(i_width,this._center);\r
\r
- // rotationを矩形情報を一つ前の変換行列で初期化\r
- this._rotmatrix.initRotByPrevResult(io_result_conv);\r
-\r
- //平行移動量計算機に、オフセット頂点をセット\r
- this._calculator.setOffsetSquare(this._offset);\r
+ //回転行列を計算\r
+ this._rotmatrix.initRotByPrevResult(o_result_conv);\r
\r
- //平行移動量計算機に、適応先矩形の情報をセット\r
- this._calculator.setFittedSquare(sqvertex_ref); \r
- \r
- //回転行列の平行移動量の計算\r
- this._calculator.calculateTransfer(this._rotmatrix,trans);\r
+ //回転後の3D座標系から、平行移動量を計算\r
+ this._rotmatrix.getPoint3dBatch(this._offset.vertex,vertex_3d,4);\r
+ this._transsolver.solveTransportVector(vertex_3d,trans);\r
\r
- //計算結果の最適化(this._rotmatrix,trans)\r
- final double err=this._mat_optimize.optimize(this._rotmatrix,trans,this._calculator);\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
- //計算結果を保存\r
- this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,io_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
- this._calculator.calculateTransfer(this._rotmatrix,trans);\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._mat_optimize.optimize(this._rotmatrix,trans,this._calculator);\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,io_result_conv);\r
+ this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);\r
}\r
}\r
return;\r
}\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
+ 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
+ break;\r
+ }\r
+ io_rotmat.getPoint3dBatch(i_offset_3d,vertex_3d,4);\r
+ i_solver.solveTransportVector(vertex_3d, io_transvec);\r
+ }\r
+ return err;\r
+ } \r
/**\r
* パラメータで変換行列を更新します。\r
* \r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java 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
- * 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
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core.transmat.fitveccalc;\r
-\r
-import jp.nyatla.nyartoolkit.core.*;\r
-import jp.nyatla.nyartoolkit.core.transmat.NyARTransOffset;\r
-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.NyARRotMatrix;\r
-import jp.nyatla.nyartoolkit.core.types.*;\r
-import jp.nyatla.nyartoolkit.*;\r
-import jp.nyatla.nyartoolkit.core.param.*;\r
-/**\r
- * 平行移動量を計算するクラス\r
- * \r
- * NyARPerspectiveProjectionMatrixに直接アクセスしてる場所があるけど、\r
- * この辺の計算はNyARPerspectiveProjectionMatrixクラスの関数にして押し込む予定。\r
- *\r
- */\r
-public class NyARFitVecCalculator\r
-{\r
- private final NyARMat _mat_b = new NyARMat(3,8);//3,NUMBER_OF_VERTEX*2\r
- private final NyARMat _mat_a = new NyARMat(8,3);/*NUMBER_OF_VERTEX,3*/\r
- private final NyARMat _mat_d = new NyARMat(3,3);\r
- private final NyARPerspectiveProjectionMatrix _projection_mat;\r
- private final NyARCameraDistortionFactor _distortionfactor;\r
-\r
-\r
-// private NyARDoublePoint2d[] _vertex_2d_ref;\r
- public NyARFitVecCalculator(final NyARPerspectiveProjectionMatrix i_projection_mat_ref,final NyARCameraDistortionFactor i_distortion_ref)\r
- {\r
- // 変換マトリクスdとbの準備(arGetTransMatSubの一部)\r
- final double[][] a_array = this._mat_a.getArray();\r
- final double[][] b_array = this._mat_b.getArray();\r
-\r
- //変換用行列のcpara固定値の部分を先に初期化してしまう。\r
- for (int i = 0; i < 4; i++) {\r
- final int x2 = i * 2;\r
- a_array[x2][0] = b_array[0][x2] = i_projection_mat_ref.m00;// 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] = i_projection_mat_ref.m01;// 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] - o_marker_vertex_2d[i].x;// 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] = i_projection_mat_ref.m11;// 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] - o_marker_vertex_2d[i].y;// mat_a->m[j*6+5]=mat_b->m[num*4+j*2+1]=cpara[1][2]-pos2d[j][1];\r
- }\r
- this._projection_mat=i_projection_mat_ref;\r
- this._distortionfactor=i_distortion_ref;\r
- return;\r
- }\r
- private final NyARDoublePoint2d[] _fitsquare_vertex=NyARDoublePoint2d.createArray(4);;\r
- private NyARTransOffset _offset_square;\r
- public void setOffsetSquare(NyARTransOffset i_offset)\r
- {\r
- this._offset_square=i_offset;\r
- return;\r
- }\r
- public NyARDoublePoint2d[] getFitSquare()\r
- {\r
- return this._fitsquare_vertex;\r
- }\r
- public NyARTransOffset getOffsetVertex()\r
- {\r
- return this._offset_square;\r
- }\r
-\r
- /**\r
- * 適合させる矩形座標を指定します。\r
- * @param i_square_vertex\r
- * @throws NyARException\r
- */\r
- public void setFittedSquare(NyARDoublePoint2d[] i_square_vertex) throws NyARException\r
- {\r
- final NyARDoublePoint2d[] vertex=_fitsquare_vertex;\r
-// int i;\r
-// if (arFittingMode == AR_FITTING_TO_INPUT) {\r
-// // arParamIdeal2Observをバッチ処理\r
- this._distortionfactor.ideal2ObservBatch(i_square_vertex, vertex,4);\r
-// } else {\r
-// for (i = 0; i < NUMBER_OF_VERTEX; i++) {\r
-// o_marker_vertex_2d[i].x = i_square_vertex[i].x;\r
-// o_marker_vertex_2d[i].y = i_square_vertex[i].y;\r
-// }\r
-// } \r
- \r
- \r
- final double cpara02=this._projection_mat.m02;\r
- final double cpara12=this._projection_mat.m12; \r
- final NyARMat mat_d=_mat_d;\r
- final NyARMat mat_a=this._mat_a;\r
- final NyARMat mat_b=this._mat_b;\r
- final double[][] a_array = mat_a.getArray();\r
- final double[][] b_array = mat_b.getArray();\r
- for (int i = 0; i < 4; i++) {\r
- final int x2 = i * 2; \r
- a_array[x2][2] = b_array[2][x2] = cpara02 - vertex[i].x;// mat_a->m[j*6+2]=mat_b->m[num*4+j*2]=cpara[0][2]-pos2d[j][0];\r
- a_array[x2 + 1][2] = b_array[2][x2 + 1] = cpara12 - vertex[i].y;// mat_a->m[j*6+5]=mat_b->m[num*4+j*2+1]=cpara[1][2]-pos2d[j][1];\r
- }\r
- // mat_d\r
- mat_d.matrixMul(mat_b, mat_a);\r
- mat_d.matrixSelfInv(); \r
- return;\r
- }\r
- private final NyARMat _mat_e = new NyARMat(3, 1);\r
- private final NyARMat _mat_f = new NyARMat(3, 1);\r
- private final NyARMat __calculateTransferVec_mat_c = new NyARMat(8, 1);//NUMBER_OF_VERTEX * 2, 1\r
- private final NyARDoublePoint3d[] __calculateTransfer_point3d=NyARDoublePoint3d.createArray(4); \r
- \r
- /**\r
- * 現在のオフセット矩形、適合先矩形と、回転行列から、平行移動量を計算します。\r
- * @param i_rotation\r
- * @param o_transfer\r
- * @throws NyARException\r
- */\r
- final public void calculateTransfer(NyARRotMatrix i_rotation,NyARDoublePoint3d o_transfer) throws NyARException\r
- {\r
- assert(this._offset_square!=null);\r
- final double cpara00=this._projection_mat.m00;\r
- final double cpara01=this._projection_mat.m01;\r
- final double cpara02=this._projection_mat.m02;\r
- final double cpara11=this._projection_mat.m11;\r
- final double cpara12=this._projection_mat.m12;\r
- \r
- final NyARDoublePoint3d[] point3d=this.__calculateTransfer_point3d;\r
- final NyARDoublePoint3d[] vertex3d=this._offset_square.vertex; \r
- final NyARDoublePoint2d[] vertex2d=this._fitsquare_vertex;\r
- final NyARMat mat_c = this.__calculateTransferVec_mat_c;// 次処理で値をもらうので、初期化の必要は無い。\r
- \r
- final double[][] f_array = this._mat_f.getArray();\r
- final double[][] c_array = mat_c.getArray();\r
- \r
- \r
- //(3D座標?)を一括請求\r
- i_rotation.getPoint3dBatch(vertex3d,point3d,4);\r
- for (int i = 0; i < 4; i++) {\r
- final int x2 = i+i;\r
- final NyARDoublePoint3d point3d_ptr=point3d[i];\r
-// i_rotation.getPoint3d(vertex3d[i],point3d);\r
- //透視変換?\r
- c_array[x2][0] = point3d_ptr.z * vertex2d[i].x - cpara00 * point3d_ptr.x - cpara01 * point3d_ptr.y - cpara02 * point3d_ptr.z;// 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] = point3d_ptr.z * vertex2d[i].y - cpara11 * point3d_ptr.y - cpara12 * point3d_ptr.z;// mat_c->m[j*2+1]= wz*pos2d[j][1]-cpara[1][1]*wy-cpara[1][2]*wz;\r
- }\r
- this._mat_e.matrixMul(this._mat_b, mat_c);\r
- this._mat_f.matrixMul(this._mat_d, this._mat_e);\r
-\r
- // double[] trans=wk_arGetTransMatSub_trans;//double trans[3];\r
- o_transfer.x= f_array[0][0];// trans[0] = mat_f->m[0];\r
- o_transfer.y= f_array[1][0];\r
- o_transfer.z= f_array[2][0];// trans[2] = mat_f->m[2];\r
- return;\r
- }\r
- \r
- \r
- \r
-}\r
package jp.nyatla.nyartoolkit.core.transmat.optimize;\r
\r
import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.transmat.fitveccalc.NyARFitVecCalculator;\r
import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.NyARRotMatrix;\r
-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;\r
+import jp.nyatla.nyartoolkit.core.types.*;\r
\r
-public interface INyARRotTransOptimize\r
+public interface INyARRotMatrixOptimize\r
{\r
- public double optimize(NyARRotMatrix io_rotmat,NyARDoublePoint3d io_transvec,NyARFitVecCalculator i_calculator) throws NyARException;\r
-\r
+ /**\r
+ * @param io_rotmat\r
+ * 初期回転行列\r
+ * @param io_transvec\r
+ * 初期並進ベクトル\r
+ * @param i_solver\r
+ * i_offset_3dを設定したsolver\r
+ * @param i_offset_3d\r
+ * 3dオフセット座標\r
+ * @param i_2d_vertex\r
+ * 画面上の点\r
+ * @return\r
+ * @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
+ \r
}\r
\r
import jp.nyatla.nyartoolkit.NyARException;\r
import jp.nyatla.nyartoolkit.core.param.*;\r
-import jp.nyatla.nyartoolkit.core.transmat.fitveccalc.NyARFitVecCalculator;\r
import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.NyARRotMatrix;\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
/**\r
* を繰り返して、変換行列を最適化する。\r
*\r
*/\r
-public class NyARRotTransOptimize implements INyARRotTransOptimize\r
+public class NyARRotMatrixOptimize implements INyARRotMatrixOptimize\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 NyARPerspectiveProjectionMatrix _projection_mat_ref;\r
- public NyARRotTransOptimize(NyARPerspectiveProjectionMatrix i_projection_mat_ref)\r
+ public NyARRotMatrixOptimize(NyARPerspectiveProjectionMatrix i_projection_mat_ref)\r
{\r
this._projection_mat_ref=i_projection_mat_ref;\r
return;\r
}\r
- \r
- final public double optimize(NyARRotMatrix io_rotmat,NyARDoublePoint3d io_transvec,NyARFitVecCalculator i_calculator) throws NyARException\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
{\r
- final NyARDoublePoint2d[] fit_vertex=i_calculator.getFitSquare();\r
- final NyARDoublePoint3d[] offset_square=i_calculator.getOffsetVertex().vertex;\r
- \r
double err = -1;\r
/*ループを抜けるタイミングをARToolKitと合わせるために変なことしてます。*/\r
for (int i = 0;; i++) {\r
// <arGetTransMat3>\r
- err = modifyMatrix(io_rotmat,io_transvec,offset_square,fit_vertex);\r
- i_calculator.calculateTransfer(io_rotmat, io_transvec);\r
- err = modifyMatrix(io_rotmat,io_transvec,offset_square,fit_vertex); \r
+ err = modifyMatrix(io_rotmat,io_transvec,i_offset_3d,i_2d_vertex);\r
+ i_solver.solveTransportVector(i_offset_3d, io_transvec);\r
+ err = 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
- i_calculator.calculateTransfer(io_rotmat, io_transvec);\r
+ i_solver.solveTransportVector(i_offset_3d, io_transvec);\r
} \r
return err;\r
}\r
* @return\r
* @throws NyARException\r
*/\r
- private double modifyMatrix(NyARRotMatrix io_rot,NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException\r
+ public double modifyMatrix(NyARRotMatrix io_rot,NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException\r
{\r
double factor;\r
double a2, b2, c2;\r
\r
import jp.nyatla.nyartoolkit.NyARException;\r
import jp.nyatla.nyartoolkit.core.param.*;\r
-import jp.nyatla.nyartoolkit.core.transmat.fitveccalc.NyARFitVecCalculator;\r
import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.NyARRotMatrix;\r
import jp.nyatla.nyartoolkit.core.types.matrix.*;\r
import jp.nyatla.nyartoolkit.core.types.*;\r
* 処理構造がわかる程度に展開したNyARRotTransOptimize\r
* \r
*/\r
-public class NyARRotTransOptimize_Base implements INyARRotTransOptimize\r
+public class NyARRotMatrixOptimize_Base implements INyARRotMatrixOptimize\r
{\r
- private final static int AR_GET_TRANS_MAT_MAX_LOOP_COUNT = 5;// #define AR_GET_TRANS_MAT_MAX_LOOP_COUNT 5\r
-\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
-\r
private final NyARPerspectiveProjectionMatrix _projection_mat_ref;\r
\r
- public NyARRotTransOptimize_Base(NyARPerspectiveProjectionMatrix i_projection_mat_ref)\r
+ public NyARRotMatrixOptimize_Base(NyARPerspectiveProjectionMatrix i_projection_mat_ref)\r
{\r
this._projection_mat_ref = i_projection_mat_ref;\r
return;\r
}\r
-\r
- final public double optimize(NyARRotMatrix io_rotmat, NyARDoublePoint3d io_transvec, NyARFitVecCalculator i_calculator) throws NyARException\r
- {\r
- final NyARDoublePoint2d[] fit_vertex = i_calculator.getFitSquare();\r
- final NyARDoublePoint3d[] offset_square = i_calculator.getOffsetVertex().vertex;\r
-\r
- double err = -1;\r
- /* ループを抜けるタイミングをARToolKitと合わせるために変なことしてます。 */\r
- for (int i = 0;; i++) {\r
- // <arGetTransMat3>\r
- err = modifyMatrix(io_rotmat, io_transvec, offset_square, fit_vertex);\r
- i_calculator.calculateTransfer(io_rotmat, io_transvec);\r
- err = modifyMatrix(io_rotmat, io_transvec, offset_square, fit_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
- i_calculator.calculateTransfer(io_rotmat, io_transvec);\r
- }\r
- return err;\r
- }\r
private double[] __createRotationMap_b_map=new double[6];\r
private double[] __createRotationMap_c_map=new double[6];\r
private double[] __createRotationMap_f=new double[3];\r
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 final double modifyMatrix(NyARRotMatrix io_rot, NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException\r
+ public double modifyMatrix(NyARRotMatrix 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
//評価して一番宜しいIDを保存\r
best_idx=(1+1*3+1*9);\r
for(i2=0;i2<27;i2++){\r
- this.getNewMatrix(next_rot_matrix[i2],trans,combo);\r
+ this.getNewMatrix(next_rot_matrix[i2],i_trans,combo);\r
err = 0.0;\r
for (i = 0; i < 4; i++) {\r
hx = combo.m00 * i_vertex3d[i].x + combo.m01 * i_vertex3d[i].y + combo.m02 * i_vertex3d[i].z + combo.m03;\r
\r
import jp.nyatla.nyartoolkit.NyARException;\r
import jp.nyatla.nyartoolkit.core.param.*;\r
-import jp.nyatla.nyartoolkit.core.transmat.fitveccalc.NyARFitVecCalculator;\r
import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.NyARRotMatrix;\r
import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;\r
import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;\r
* を繰り返して、変換行列を最適化する。\r
*\r
*/\r
-public class NyARRotTransOptimize_O2 implements INyARRotTransOptimize\r
+public class NyARRotMatrixOptimize_O2 implements INyARRotMatrixOptimize\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 NyARPerspectiveProjectionMatrix _projection_mat_ref;\r
- public NyARRotTransOptimize_O2(NyARPerspectiveProjectionMatrix i_projection_mat_ref)\r
+ public NyARRotMatrixOptimize_O2(NyARPerspectiveProjectionMatrix i_projection_mat_ref)\r
{\r
this._projection_mat_ref=i_projection_mat_ref;\r
return;\r
}\r
- \r
- final public double optimize(NyARRotMatrix io_rotmat,NyARDoublePoint3d io_transvec,NyARFitVecCalculator i_calculator) throws NyARException\r
- {\r
- final NyARDoublePoint2d[] fit_vertex=i_calculator.getFitSquare();\r
- final NyARDoublePoint3d[] offset_square=i_calculator.getOffsetVertex().vertex;\r
- \r
- double err = -1;\r
- /*ループを抜けるタイミングをARToolKitと合わせるために変なことしてます。*/\r
- for (int i = 0;; i++) {\r
- // <arGetTransMat3>\r
- err = modifyMatrix(io_rotmat,io_transvec,offset_square,fit_vertex);\r
- i_calculator.calculateTransfer(io_rotmat, io_transvec);\r
- err = modifyMatrix(io_rotmat,io_transvec,offset_square,fit_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
- i_calculator.calculateTransfer(io_rotmat, io_transvec);\r
- } \r
- return err;\r
- }\r
- \r
private final double[][] __modifyMatrix_double1D = new double[8][3];\r
/**\r
* arGetRot計算を階層化したModifyMatrix 896\r
* @return\r
* @throws NyARException\r
*/\r
- private double modifyMatrix(NyARRotMatrix io_rot,NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException\r
+ public double modifyMatrix(NyARRotMatrix io_rot,NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException\r
{\r
double factor;\r
double a2, b2, c2;\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java 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
+ * 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
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core.transmat.solver;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;\r
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;\r
+\r
+/**\r
+ * 並進ベクトル[T]を3次元座標[b]と基点の回転済行列[M]から計算するインタフェイスです。\r
+ * [M][T]=[b]\r
+ *\r
+ */\r
+public interface INyARTransportVectorSolver\r
+{\r
+ public void set2dVertex(NyARDoublePoint2d[] i_ref_vertex_2d,int i_number_of_vertex) throws NyARException;\r
+ /**\r
+ * 画面座標群と3次元座標群から、平行移動量を計算します。\r
+ * 2d座標系は、直前に実行したset2dVertexのものを使用します。\r
+ * @param i_vertex_2d\r
+ * 直前のset2dVertexコールで指定したものと同じものを指定してください。\r
+ * @param i_vertex3d\r
+ * 3次元空間の座標群を設定します。頂点の順番は、画面座標群と同じ順序で格納してください。\r
+ * @param o_transfer\r
+ * @throws NyARException\r
+ */\r
+ public void solveTransportVector(NyARDoublePoint3d[] i_vertex3d,NyARDoublePoint3d o_transfer) throws NyARException;\r
+}
\ No newline at end of file
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit(Extension)\r
+ * --------------------------------------------------------------------------------\r
+ *\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
+ * 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
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core.transmat.solver;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.param.NyARPerspectiveProjectionMatrix;\r
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;\r
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;\r
+\r
+/**\r
+ * 並進ベクトル[T]を3次元座標[b]と基点の回転済行列[M]から計算します。\r
+ * \r
+ * アルゴリズムは、ARToolKit 拡張現実プログラミング入門 の、P207のものです。\r
+ * \r
+ * 計算手順\r
+ * [A]*[T]=bを、[A]T*[A]*[T]=[A]T*[b]にする。\r
+ * set2dVertexで[A]T*[A]=[M]を計算して、Aの3列目の情報だけ保存しておく。\r
+ * getTransportVectorで[M]*[T]=[A]T*[b]を連立方程式で解いて、[T]を得る。\r
+ */\r
+public class NyARTransportVectorSolver implements INyARTransportVectorSolver\r
+{\r
+ private double[] _cx;\r
+ private double[] _cy; \r
+ private final NyARPerspectiveProjectionMatrix _projection_mat;\r
+ private int _nmber_of_vertex;\r
+ public NyARTransportVectorSolver(final NyARPerspectiveProjectionMatrix i_projection_mat_ref,int i_max_vertex)\r
+ {\r
+ this._projection_mat=i_projection_mat_ref;\r
+ this._cx=new double[i_max_vertex];\r
+ this._cy=new double[i_max_vertex]; \r
+ return;\r
+ }\r
+ private double _a00,_a01,_a02_20,_a10,_a11,_a12_21,_a22;\r
+ /**\r
+ * 画面上の座標群を指定します。\r
+ * @param i_ref_vertex_2d\r
+ * 歪み矯正済の画面上の頂点座標群への参照値を指定します。\r
+ * @throws NyARException\r
+ * \r
+ */\r
+ public void set2dVertex(NyARDoublePoint2d[] i_ref_vertex_2d,int i_number_of_vertex) throws NyARException\r
+ {\r
+ //3x2nと2n*3の行列から、最小二乗法計算するために3x3マトリクスを作る。 \r
+ //[A]*[A]T\r
+ //行列[A]の3列目のキャッシュ\r
+ final double[] cx=this._cx;\r
+ final double[] cy=this._cy;\r
+ \r
+ double m22;\r
+ double p00=this._projection_mat.m00;\r
+ double p01=this._projection_mat.m01;\r
+ double p11=this._projection_mat.m11;\r
+ double p12=this._projection_mat.m12;\r
+ double p02=this._projection_mat.m02;\r
+ double w1,w2,w3,w4;\r
+ this._a00=i_number_of_vertex*p00*p00;\r
+ this._a01=i_number_of_vertex*p00*p01;\r
+ this._a10=i_number_of_vertex*p00*p01;\r
+ this._a11=i_number_of_vertex*(p01*p01+p11*p11);\r
+ \r
+ m22=0;\r
+ w1=w2=0;\r
+ for(int i=0;i<i_number_of_vertex;i++){\r
+ //座標を保存しておく。\r
+ w3=p02-(cx[i]=i_ref_vertex_2d[i].x);\r
+ w4=p12-(cy[i]=i_ref_vertex_2d[i].y);\r
+ w1+=w3;\r
+ w2+=w4;\r
+ m22+=w3*w3+w4*w4;\r
+ }\r
+ this._a02_20=w1*p00;\r
+ this._a12_21=p01*w1+p11*w2;\r
+ this._a22=m22;\r
+\r
+ this._nmber_of_vertex=i_number_of_vertex;\r
+ return;\r
+ }\r
+ \r
+ /**\r
+ * 画面座標群と3次元座標群から、平行移動量を計算します。\r
+ * 2d座標系は、直前に実行したset2dVertexのものを使用します。\r
+ * @param i_vertex_2d\r
+ * 直前のset2dVertexコールで指定したものと同じものを指定してください。\r
+ * @param i_vertex3d\r
+ * 3次元空間の座標群を設定します。頂点の順番は、画面座標群と同じ順序で格納してください。\r
+ * @param o_transfer\r
+ * @throws NyARException\r
+ */\r
+ final public void solveTransportVector(NyARDoublePoint3d[] i_vertex3d,NyARDoublePoint3d o_transfer) throws NyARException\r
+ {\r
+ final int number_of_vertex=this._nmber_of_vertex;\r
+ final double p00=this._projection_mat.m00;\r
+ final double p01=this._projection_mat.m01;\r
+ final double p02=this._projection_mat.m02;\r
+ final double p11=this._projection_mat.m11;\r
+ final double p12=this._projection_mat.m12;\r
+ //行列[A]の3列目のキャッシュ\r
+ final double[] cx=this._cx;\r
+ final double[] cy=this._cy; \r
+ \r
+ //回転行列を元座標の頂点群に適応\r
+ //[A]T*[b]を計算\r
+ double bt1=0,bt2=0,bt3=0;\r
+ for(int i=0;i<number_of_vertex;i++)\r
+ {\r
+ double w1=i_vertex3d[i].z*cx[i]-p00*i_vertex3d[i].x-p01*i_vertex3d[i].y-p02*i_vertex3d[i].z;\r
+ double w2=i_vertex3d[i].z*cy[i]-p11*i_vertex3d[i].y-p12*i_vertex3d[i].z;\r
+ bt1+=w1;\r
+ bt2+=w2;\r
+ bt3+=-cx[i]*w1-cy[i]*w2;\r
+ }\r
+ //([A]*T[A])*[T]=[A]T*[b]を方程式で解く。\r
+ //a01とa10を0と仮定しても良いんじゃないかな?\r
+ double b00=bt1*p00;\r
+ double m00=this._a00;\r
+ double m10=this._a10;\r
+ double m20=this._a02_20;\r
+ double m12_21=this._a12_21;\r
+ double m01=this._a01;\r
+\r
+ double a=(this._a11*m00-m10*m01); \r
+ double b=(m00*m12_21-m20*m01); \r
+ double c=(m00*this._a22-m20*m20); \r
+ double d=(m00*(bt1*p02+bt2*p12+bt3)-m20*b00); \r
+\r
+ double z,y;\r
+ o_transfer.z=z=((a*d)-(b*(m00*(b00+bt2*p11)-m10*b00)))/((c*a)-(b*(m00*m12_21-m10)));\r
+ o_transfer.y=y=(d-c*z)/(b);\r
+ o_transfer.x=(b00-m01*y-m20*z)/m00;\r
+ return;\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java 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
+ * 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
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core.transmat.solver;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.NyARMat;\r
+import jp.nyatla.nyartoolkit.core.param.NyARPerspectiveProjectionMatrix;\r
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;\r
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;\r
+\r
+/**\r
+ * 並進ベクトル[T]を3次元座標[b]と基点の回転済行列[M]から計算します。\r
+ * ARToolKit互換の数値を計算します。\r
+ *\r
+ */\r
+public class NyARTransportVectorSolver_ARToolKit implements INyARTransportVectorSolver\r
+{\r
+ private final NyARMat _mat_at = new NyARMat(3,8);//3,NUMBER_OF_VERTEX*2\r
+ private final NyARMat _mat_a = new NyARMat(8,3);//NUMBER_OF_VERTEX,3\r
+ private final NyARMat _mat_t = new NyARMat(3,3);//NUMBER_OF_VERTEX,3\r
+ private final NyARMat _mat_c = new NyARMat(8,1);//NUMBER_OF_VERTEX * 2, 1\r
+ private final NyARMat _mat_e = new NyARMat(3,1);\r
+ private final NyARMat _mat_f = new NyARMat(3,1);\r
+ private double[] _cx=new double[4];\r
+ private double[] _cy=new double[4];\r
+ \r
+ private final NyARPerspectiveProjectionMatrix _projection_mat;\r
+ public NyARTransportVectorSolver_ARToolKit(final NyARPerspectiveProjectionMatrix i_projection_mat_ref)\r
+ {\r
+ this._projection_mat=i_projection_mat_ref;\r
+ //aとb(aの転置行列)の固定部分を設定。\r
+ final double[][] mata = this._mat_a.getArray();\r
+ final double[][] matat = this._mat_at.getArray();\r
+\r
+ //変換用行列のcpara部分を先に作成\r
+ for (int i = 0; i < 4; i++) {\r
+ final int x2 = i * 2;\r
+ mata[x2][0] = matat[0][x2] = i_projection_mat_ref.m00;// mat_a->m[j*6+0]=mat_b->m[num*0+j*2] =cpara[0][0];\r
+ mata[x2][1] = matat[1][x2] = i_projection_mat_ref.m01;// mat_a->m[j*6+1]=mat_b->m[num*2+j*2]=cpara[0][1];\r
+ mata[x2 + 1][0] = matat[0][x2 + 1] = 0.0;// mat_a->m[j*6+3] =mat_b->m[num*0+j*2+1]= 0.0;\r
+ mata[x2 + 1][1] = matat[1][x2 + 1] = i_projection_mat_ref.m11;// mat_a->m[j*6+4] =mat_b->m[num*2+j*2+1]= cpara[1][1];\r
+ }\r
+ return;\r
+ }\r
+ public void set2dVertex(NyARDoublePoint2d[] i_ref_vertex_2d,int i_number_of_vertex) throws NyARException\r
+ { \r
+ assert(i_number_of_vertex==4);\r
+ final double[] cx=this._cx;\r
+ final double[] cy=this._cy;\r
+ final double cpara02=this._projection_mat.m02;\r
+ final double cpara12=this._projection_mat.m12; \r
+ final NyARMat mat_t=this._mat_t;\r
+ final double[][] mata = this._mat_a.getArray();\r
+ final double[][] matat= this._mat_at.getArray();\r
+ for (int i = 0; i < 4; i++){\r
+ cx[i]=i_ref_vertex_2d[i].x;\r
+ cy[i]=i_ref_vertex_2d[i].y;\r
+ final int x2 = i * 2; \r
+ mata[x2][2] = matat[2][x2] = cpara02 - i_ref_vertex_2d[i].x;// mat_a->m[j*6+2]=mat_b->m[num*4+j*2]=cpara[0][2]-pos2d[j][0];\r
+ mata[x2 + 1][2] = matat[2][x2 + 1] = cpara12 - i_ref_vertex_2d[i].y;// mat_a->m[j*6+5]=mat_b->m[num*4+j*2+1]=cpara[1][2]-pos2d[j][1];\r
+ }\r
+ //T(3x3行列)の作成\r
+ mat_t.matrixMul(this._mat_at, this._mat_a);\r
+ mat_t.matrixSelfInv(); \r
+ return; \r
+ }\r
+ /**\r
+ * 画面座標群と3次元座標群から、平行移動量を計算します。\r
+ * 2d座標系は、直前に実行したset2dVertexのものを使用します。\r
+ * @param i_vertex_2d\r
+ * 直前のset2dVertexコールで指定したものと同じものを指定してください。\r
+ * @param i_vertex3d\r
+ * 3次元空間の座標群を設定します。頂点の順番は、画面座標群と同じ順序で格納してください。\r
+ * @param o_transfer\r
+ * @throws NyARException\r
+ */\r
+ public void solveTransportVector(NyARDoublePoint3d[] i_vertex3d,NyARDoublePoint3d o_transfer) throws NyARException\r
+ {\r
+ final double[][] matc = this._mat_c.getArray();\r
+ final double cpara00=this._projection_mat.m00;\r
+ final double cpara01=this._projection_mat.m01;\r
+ final double cpara02=this._projection_mat.m02;\r
+ final double cpara11=this._projection_mat.m11;\r
+ final double cpara12=this._projection_mat.m12;\r
+ final double[] cx=this._cx;\r
+ final double[] cy=this._cy;\r
+ \r
+ //(3D座標?)を一括請求\r
+ for (int i = 0; i < 4; i++) {\r
+ final int x2 = i+i;\r
+ final NyARDoublePoint3d point3d_ptr=i_vertex3d[i];\r
+ //透視変換?\r
+ matc[x2][0] = point3d_ptr.z * cx[i] - cpara00 * point3d_ptr.x - cpara01 * point3d_ptr.y - cpara02 * point3d_ptr.z;// mat_c->m[j*2+0] = wz*pos2d[j][0]-cpara[0][0]*wx-cpara[0][1]*wy-cpara[0][2]*wz;\r
+ matc[x2 + 1][0] = point3d_ptr.z * cy[i] - cpara11 * point3d_ptr.y - cpara12 * point3d_ptr.z;// mat_c->m[j*2+1]= wz*pos2d[j][1]-cpara[1][1]*wy-cpara[1][2]*wz;\r
+ }\r
+ this._mat_e.matrixMul(this._mat_at,this._mat_c);\r
+ this._mat_f.matrixMul(this._mat_t, this._mat_e);\r
+ \r
+ final double[][] matf = this._mat_f.getArray();\r
+ o_transfer.x= matf[0][0];// trans[0] = mat_f->m[0];\r
+ o_transfer.y= matf[1][0];\r
+ o_transfer.z= matf[2][0];// trans[2] = mat_f->m[2];\r
+ return; \r
+ }\r
+}\r
/* \r
- * PROJECT: NyARToolkit\r
+ * PROJECT: NyARToolkit(Extension)\r
* --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
* The NyARToolkit is Java version ARToolkit class library.\r
* Copyright (C)2008 R.Iizuka\r
*\r
o_value[4]=this.m11;\r
return;\r
}\r
+ public boolean inverse(NyARDoubleMatrix22 i_src)\r
+ {\r
+ final double a11,a12,a21,a22;\r
+ a11=i_src.m00;\r
+ a12=i_src.m01;\r
+ a21=i_src.m10;\r
+ a22=i_src.m11;\r
+ double det=a11*a22-a12*a21;\r
+ if(det==0){\r
+ return false;\r
+ }\r
+ det=1/det;\r
+ this.m00=a22*det;\r
+ this.m01=-a12*det;\r
+ this.m10=a21*det;\r
+ this.m11=-a11*det;\r
+ return true;\r
+ } \r
}\r
/* \r
- * PROJECT: NyARToolkit\r
+ * PROJECT: NyARToolkit(Extension)\r
* --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
* The NyARToolkit is Java version ARToolkit class library.\r
* Copyright (C)2008 R.Iizuka\r
*\r
o_value[8]=this.m22;\r
return;\r
}\r
+ public boolean inverse(NyARDoubleMatrix33 i_src)\r
+ {\r
+ final double a11,a12,a13,a21,a22,a23,a31,a32,a33;\r
+ final double b11,b12,b13,b21,b22,b23,b31,b32,b33; \r
+ a11=i_src.m00;a12=i_src.m01;a13=i_src.m02;\r
+ a21=i_src.m10;a22=i_src.m11;a23=i_src.m12;\r
+ a31=i_src.m20;a32=i_src.m21;a33=i_src.m22;\r
+ \r
+ b11=a22*a33-a23*a32;\r
+ b12=a32*a13-a33*a12;\r
+ b13=a12*a23-a13*a22;\r
+ \r
+ b21=a13*a31-a21*a33;\r
+ b22=a33*a11-a31*a13;\r
+ b23=a13*a21-a11*a23;\r
+ \r
+ b31=a21*a32-a22*a31;\r
+ b32=a31*a12-a32*a11;\r
+ b33=a11*a22-a12*a21;\r
+ \r
+ double det_1=a11*b11+a21*b12+a31*b13;\r
+ if(det_1==0){\r
+ return false;\r
+ }\r
+ det_1=1/det_1;\r
+\r
+ this.m00=b11*det_1;\r
+ this.m01=b12*det_1;\r
+ this.m02=b13*det_1;\r
+ \r
+ this.m10=b21*det_1;\r
+ this.m11=b22*det_1;\r
+ this.m12=b23*det_1;\r
+ \r
+ this.m20=b31*det_1;\r
+ this.m21=b32*det_1;\r
+ this.m22=b33*det_1;\r
+ \r
+ return true;\r
+ } \r
+ \r
}\r
/* \r
- * PROJECT: NyARToolkit\r
+ * PROJECT: NyARToolkit(Extension)\r
* --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
* The NyARToolkit is Java version ARToolkit class library.\r
* Copyright (C)2008 R.Iizuka\r
- *\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
/* \r
- * PROJECT: NyARToolkit\r
+ * PROJECT: NyARToolkit(Extension)\r
* --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
* The NyARToolkit is Java version ARToolkit class library.\r
* Copyright (C)2008 R.Iizuka\r
*\r
o_value[15]=this.m33;\r
return;\r
}\r
+ public boolean inverse(NyARDoubleMatrix44 i_src)\r
+ {\r
+ final double a11,a12,a13,a14,a21,a22,a23,a24,a31,a32,a33,a34,a41,a42,a43,a44;\r
+ final double b11,b12,b13,b14,b21,b22,b23,b24,b31,b32,b33,b34,b41,b42,b43,b44; \r
+ double t1,t2,t3,t4,t5,t6;\r
+ a11=i_src.m00;a12=i_src.m01;a13=i_src.m02;a14=i_src.m03;\r
+ a21=i_src.m10;a22=i_src.m11;a23=i_src.m12;a24=i_src.m13;\r
+ a31=i_src.m20;a32=i_src.m21;a33=i_src.m22;a34=i_src.m23;\r
+ a41=i_src.m30;a42=i_src.m31;a43=i_src.m32;a44=i_src.m33;\r
+ \r
+ t1=a33*a44-a34*a43;\r
+ t2=a34*a42-a32*a44;\r
+ t3=a32*a43-a33*a42;\r
+ t4=a34*a41-a31*a44;\r
+ t5=a31*a43-a33*a41;\r
+ t6=a31*a42-a32*a41;\r
+ \r
+ b11=a22*t1+a23*t2+a24*t3;\r
+ b21=-(a23*t4+a24*t5+a21*t1);\r
+ b31=a24*t6-a21*t2+a22*t4;\r
+ b41=-(a21*t3-a22*t5+a23*t6);\r
+ \r
+ t1=a43*a14-a44*a13;\r
+ t2=a44*a12-a42*a14;\r
+ t3=a42*a13-a43*a12;\r
+ t4=a44*a11-a41*a14;\r
+ t5=a41*a13-a43*a11;\r
+ t6=a41*a12-a42*a11;\r
+\r
+ b12=-(a32*t1+a33*t2+a34*t3);\r
+ b22=a33*t4+a34*t5+a31*t1;\r
+ b32=-(a34*t6-a31*t2+a32*t4);\r
+ b42=a31*t3-a32*t5+a33*t6;\r
+ \r
+ t1=a13*a24-a14*a23;\r
+ t2=a14*a22-a12*a24;\r
+ t3=a12*a23-a13*a22;\r
+ t4=a14*a21-a11*a24;\r
+ t5=a11*a23-a13*a21;\r
+ t6=a11*a22-a12*a21;\r
+\r
+ b13=a42*t1+a43*t2+a44*t3;\r
+ b23=-(a43*t4+a44*t5+a41*t1);\r
+ b33=a44*t6-a41*t2+a42*t4;\r
+ b43=-(a41*t3-a42*t5+a43*t6);\r
+\r
+ t1=a23*a34-a24*a33;\r
+ t2=a24*a32-a22*a34;\r
+ t3=a22*a33-a23*a32;\r
+ t4=a24*a31-a21*a34; \r
+ t5=a21*a33-a23*a31;\r
+ t6=a21*a32-a22*a31;\r
+\r
+ b14=-(a12*t1+a13*t2+a14*t3);\r
+ b24=a13*t4+a14*t5+a11*t1;\r
+ b34=-(a14*t6-a11*t2+a12*t4);\r
+ b44=a11*t3-a12*t5+a13*t6;\r
+ \r
+ double det_1=(a11*b11+a21*b12+a31*b13+a41*b14);\r
+ if(det_1==0){\r
+ return false;\r
+ }\r
+ det_1=1/det_1;\r
+\r
+ this.m00=b11*det_1;\r
+ this.m01=b12*det_1;\r
+ this.m02=b13*det_1;\r
+ this.m03=b14*det_1;\r
+ \r
+ this.m10=b21*det_1;\r
+ this.m11=b22*det_1;\r
+ this.m12=b23*det_1;\r
+ this.m13=b24*det_1;\r
+ \r
+ this.m20=b31*det_1;\r
+ this.m21=b32*det_1;\r
+ this.m22=b33*det_1;\r
+ this.m23=b34*det_1;\r
+ \r
+ this.m30=b41*det_1;\r
+ this.m31=b42*det_1;\r
+ this.m32=b43*det_1;\r
+ this.m33=b44*det_1;\r
+ \r
+ return true;\r
+ } \r
}\r
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit(Extension)\r
- * --------------------------------------------------------------------------------\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
- * 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
- * \r
- * For further information please contact.\r
- * http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.core.utils;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix22;\r
-import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix33;\r
-import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix44;\r
-\r
-public class NyARDoubleMatrixProcessor\r
-{\r
- /**\r
- * i_srcの逆行列を計算して、thisへ格納します。\r
- * @param i_src\r
- * @return\r
- */\r
- public static boolean inverse(NyARDoubleMatrix22 i_src,NyARDoubleMatrix22 o_dest)\r
- {\r
- final double a11,a12,a21,a22;\r
- a11=i_src.m00;\r
- a12=i_src.m01;\r
- a21=i_src.m10;\r
- a22=i_src.m11;\r
- double det=a11*a22-a12*a21;\r
- if(det==0){\r
- return false;\r
- }\r
- det=1/det;\r
- o_dest.m00=a22*det;\r
- o_dest.m01=-a12*det;\r
- o_dest.m10=a21*det;\r
- o_dest.m11=-a11*det;\r
- return true;\r
- } \r
- public static boolean inverse(NyARDoubleMatrix33 i_src,NyARDoubleMatrix33 o_dest) throws NyARException\r
- {\r
- /*i_srcの逆行列をthisへ格納するコードを書くこと。*/\r
- NyARException.notImplement();\r
- return false;\r
- }\r
- /**\r
- * i_srcの逆行列を計算して、結果をo_destへセットします。\r
- * @param i_src\r
- * @return\r
- */\r
- public static boolean inverse(NyARDoubleMatrix44 i_src,NyARDoubleMatrix44 o_dest)\r
- {\r
- final double a11,a12,a13,a14,a21,a22,a23,a24,a31,a32,a33,a34,a41,a42,a43,a44;\r
- final double b11,b12,b13,b14,b21,b22,b23,b24,b31,b32,b33,b34,b41,b42,b43,b44; \r
- double t1,t2,t3,t4,t5,t6;\r
- a11=i_src.m00;a12=i_src.m01;a13=i_src.m02;a14=i_src.m03;\r
- a21=i_src.m10;a22=i_src.m11;a23=i_src.m12;a24=i_src.m13;\r
- a31=i_src.m20;a32=i_src.m21;a33=i_src.m22;a34=i_src.m23;\r
- a41=i_src.m30;a42=i_src.m31;a43=i_src.m32;a44=i_src.m33;\r
- \r
- t1=a33*a44-a34*a43;\r
- t2=a34*a42-a32*a44;\r
- t3=a32*a43-a33*a42;\r
- t4=a34*a41-a31*a44;\r
- t5=a31*a43-a33*a41;\r
- t6=a31*a42-a32*a41;\r
- \r
- b11=a22*t1+a23*t2+a24*t3;\r
- b21=-(a23*t4+a24*t5+a21*t1);\r
- b31=a24*t6-a21*t2+a22*t4;\r
- b41=-(a21*t3-a22*t5+a23*t6);\r
- \r
- t1=a43*a14-a44*a13;\r
- t2=a44*a12-a42*a14;\r
- t3=a42*a13-a43*a12;\r
- t4=a44*a11-a41*a14;\r
- t5=a41*a13-a43*a11;\r
- t6=a41*a12-a42*a11;\r
-\r
- b12=-(a32*t1+a33*t2+a34*t3);\r
- b22=a33*t4+a34*t5+a31*t1;\r
- b32=-(a34*t6-a31*t2+a32*t4);\r
- b42=a31*t3-a32*t5+a33*t6;\r
- \r
- t1=a13*a24-a14*a23;\r
- t2=a14*a22-a12*a24;\r
- t3=a12*a23-a13*a22;\r
- t4=a14*a21-a11*a24;\r
- t5=a11*a23-a13*a21;\r
- t6=a11*a22-a12*a21;\r
-\r
- b13=a42*t1+a43*t2+a44*t3;\r
- b23=-(a43*t4+a44*t5+a41*t1);\r
- b33=a44*t6-a41*t2+a42*t4;\r
- b43=-(a41*t3-a42*t5+a43*t6);\r
-\r
- t1=a23*a34-a24*a33;\r
- t2=a24*a32-a22*a34;\r
- t3=a22*a33-a23*a32;\r
- t4=a24*a31-a21*a34; \r
- t5=a21*a33-a23*a31;\r
- t6=a21*a32-a22*a31;\r
-\r
- b14=-(a12*t1+a13*t2+a14*t3);\r
- b24=a13*t4+a14*t5+a11*t1;\r
- b34=-(a14*t6-a11*t2+a12*t4);\r
- b44=a11*t3-a12*t5+a13*t6;\r
- \r
- double det_1=(a11*b11+a21*b12+a31*b13+a41*b14);\r
- if(det_1==0){\r
- return false;\r
- }\r
- det_1=1/det_1;\r
-\r
- o_dest.m00=b11*det_1;\r
- o_dest.m01=b12*det_1;\r
- o_dest.m02=b13*det_1;\r
- o_dest.m03=b14*det_1;\r
- \r
- o_dest.m10=b21*det_1;\r
- o_dest.m11=b22*det_1;\r
- o_dest.m12=b23*det_1;\r
- o_dest.m13=b24*det_1;\r
- \r
- o_dest.m20=b31*det_1;\r
- o_dest.m21=b32*det_1;\r
- o_dest.m22=b33*det_1;\r
- o_dest.m23=b34*det_1;\r
- \r
- o_dest.m30=b41*det_1;\r
- o_dest.m31=b42*det_1;\r
- o_dest.m32=b43*det_1;\r
- o_dest.m33=b44*det_1;\r
- \r
- return true;\r
- }\r
-}\r
*/\r
public class NyARSingleDetectMarker extends NyARCustomSingleDetectMarker\r
{\r
- public final static int PF_ARTOOLKIT_CONPATIBLE=1;\r
+ public final static int PF_ARTOOLKIT_COMPATIBLE=1;\r
public final static int PF_NYARTOOLKIT=2;\r
\r
/**\r
INyARSquareDetector sqdetect_inst;\r
\r
switch(i_profile_id){\r
- case PF_ARTOOLKIT_CONPATIBLE:\r
+ 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
break;\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java 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
+ * 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
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.sample;\r
+\r
+import java.io.*;\r
+\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
+import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;\r
+import jp.nyatla.nyartoolkit.core.transmat.*;\r
+import jp.nyatla.nyartoolkit.core.*;\r
+import jp.nyatla.nyartoolkit.processor.*;\r
+\r
+public class SingleARMarkerTest\r
+{\r
+ class MarkerProcessor extends SingleARMarkerProcesser\r
+ { \r
+ private Object _sync_object=new Object();\r
+ public NyARTransMatResult transmat=null;\r
+ public int current_code=-1;\r
+\r
+ public MarkerProcessor(NyARParam i_cparam,int i_raster_format) throws NyARException\r
+ {\r
+ //アプリケーションフレームワークの初期化\r
+ super();\r
+ initInstance(i_cparam,i_raster_format);\r
+ return;\r
+ }\r
+ protected void onEnterHandler(int i_code)\r
+ {\r
+ synchronized(this._sync_object){\r
+ current_code=i_code;\r
+ }\r
+ }\r
+ protected void onLeaveHandler()\r
+ {\r
+ synchronized(this._sync_object){\r
+ current_code=-1;\r
+ this.transmat=null;\r
+ }\r
+ return; \r
+ }\r
+\r
+ protected void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result)\r
+ {\r
+ synchronized(this._sync_object){\r
+ this.transmat=result;\r
+ } \r
+ }\r
+ }\r
+ private final static String CARCODE_FILE = "../Data/patt.hiro";\r
+ private final static String PARAM_FILE = "../Data/camera_para.dat"; \r
+ private final String data_file = "../Data/320x240ABGR.raw";\r
+\r
+ public SingleARMarkerTest()\r
+ {\r
+ }\r
+ public void Test() throws Exception\r
+ {\r
+ //AR用カメラパラメタファイルをロード\r
+ NyARParam ap = new NyARParam();\r
+ ap.loadARParamFromFile(PARAM_FILE);\r
+ ap.changeScreenSize(320, 240);\r
+\r
+ // 試験イメージの読み出し(320x240 BGRAのRAWデータ)\r
+ File f = new File(data_file);\r
+ FileInputStream fs = new FileInputStream(data_file);\r
+ byte[] buf = new byte[(int) f.length()];\r
+ fs.read(buf); \r
+\r
+ NyARRgbRaster_BGRA ra = NyARRgbRaster_BGRA.wrap(buf, 320, 240);\r
+\r
+ MarkerProcessor pr = new MarkerProcessor(ap, ra.getBufferReader().getBufferType());\r
+ NyARCode[] codes=new NyARCode[1];\r
+ codes[0]=new NyARCode(16,16);\r
+ codes[0].loadARPattFromFile(CARCODE_FILE);\r
+ pr.setARCodeTable(codes,16,80.0);\r
+ pr.detectMarker(ra);\r
+ return;\r
+ }\r
+ public static void main(String[] args)\r
+ {\r
+\r
+ try {\r
+ SingleARMarkerTest t = new SingleARMarkerTest();\r
+ // t.Test_arGetVersion();\r
+ t.Test();\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ } \r
+}\r