2 * PROJECT: NyARToolkit
\r
3 * --------------------------------------------------------------------------------
\r
4 * This work is based on the original ARToolKit developed by
\r
7 * HITLab, University of Washington, Seattle
\r
8 * http://www.hitl.washington.edu/artoolkit/
\r
10 * The NyARToolkit is Java version ARToolkit class library.
\r
11 * Copyright (C)2008-2009 R.Iizuka
\r
13 * This program is free software; you can redistribute it and/or
\r
14 * modify it under the terms of the GNU General Public License
\r
15 * as published by the Free Software Foundation; either version 2
\r
16 * of the License, or (at your option) any later version.
\r
18 * This program is distributed in the hope that it will be useful,
\r
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 * GNU General Public License for more details.
\r
23 * You should have received a copy of the GNU General Public License
\r
24 * along with this framework; if not, write to the Free Software
\r
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
27 * For further information please contact.
\r
28 * http://nyatla.jp/nyatoolkit/
\r
29 * <airmail(at)ebony.plala.or.jp>
\r
32 package jp.nyatla.nyartoolkit.core.utils;
\r
34 import jp.nyatla.nyartoolkit.NyARException;
\r
35 import jp.nyatla.nyartoolkit.core.types.NyARIntPoint2d;
\r
38 * 遠近法を用いたPerspectiveパラメータを計算するクラスです。
\r
41 public class NyARPerspectiveParamGenerator
\r
43 protected int _local_x;
\r
44 protected int _local_y;
\r
45 protected int _width;
\r
46 protected int _height;
\r
47 public NyARPerspectiveParamGenerator(int i_local_x,int i_local_y,int i_width, int i_height)
\r
49 this._height=i_height;
\r
50 this._width=i_width;
\r
51 this._local_x=i_local_x;
\r
52 this._local_y=i_local_y;
\r
55 public boolean getParam(final NyARIntPoint2d[] i_vertex,double[] o_param)throws NyARException
\r
59 double ltx=this._local_x;
\r
60 double lty=this._local_y;
\r
61 double rbx=ltx+this._width;
\r
62 double rby=lty+this._height;
\r
63 la1=new double[4][5];
\r
64 la2=new double[4][5];
\r
68 la1[0][0]=ltx; la1[0][1]=lty; la1[0][2]=1; la1[0][3]=-ltx*i_vertex[0].x; la1[0][4]=-lty*i_vertex[0].x;
\r
69 la1[1][0]=rbx; la1[1][1]=lty; la1[1][2]=1; la1[1][3]=-rbx*i_vertex[1].x; la1[1][4]=-lty*i_vertex[1].x;
\r
70 la1[2][0]=rbx; la1[2][1]=rby; la1[2][2]=1; la1[2][3]=-rbx*i_vertex[2].x; la1[2][4]=-rby*i_vertex[2].x;
\r
71 la1[3][0]=ltx; la1[3][1]=rby; la1[3][2]=1; la1[3][3]=-ltx*i_vertex[3].x; la1[3][4]=-rby*i_vertex[3].x;
\r
72 ra1[0]=i_vertex[0].x;ra1[1]=i_vertex[1].x;ra1[2]=i_vertex[2].x;ra1[3]=i_vertex[3].x;
\r
73 NyARSystemOfLinearEquationsProcessor.doGaussianElimination(la1,ra1,5,4);
\r
76 la2[0][0]=ltx; la2[0][1]=lty; la2[0][2]=1; la2[0][3]=-ltx*i_vertex[0].y; la2[0][4]=-lty*i_vertex[0].y;
\r
77 la2[1][0]=rbx; la2[1][1]=lty; la2[1][2]=1; la2[1][3]=-rbx*i_vertex[1].y; la2[1][4]=-lty*i_vertex[1].y;
\r
78 la2[2][0]=rbx; la2[2][1]=rby; la2[2][2]=1; la2[2][3]=-rbx*i_vertex[2].y; la2[2][4]=-rby*i_vertex[2].y;
\r
79 la2[3][0]=ltx; la2[3][1]=rby; la2[3][2]=1; la2[3][3]=-ltx*i_vertex[3].y; la2[3][4]=-rby*i_vertex[3].y;
\r
80 ra2[0]=i_vertex[0].y;ra2[1]=i_vertex[1].y;ra2[2]=i_vertex[2].y;ra2[3]=i_vertex[3].y;
\r
81 NyARSystemOfLinearEquationsProcessor.doGaussianElimination(la2,ra2,5,4);
\r
83 double A,B,C,D,E,F,G,H;
\r
84 H=(ra2[3]-ra1[3])/(la2[3][4]-la1[3][4]);
\r
85 G=ra2[3]-la2[3][4]*H;
\r
87 F=ra2[2]-H*la2[2][4]-G*la2[2][3];
\r
88 E=ra2[1]-H*la2[1][4]-G*la2[1][3]-F*la2[1][2];
\r
89 D=ra2[0]-H*la2[0][4]-G*la2[0][3]-F*la2[0][2]-E*la2[0][1];
\r
90 C=ra1[2]-H*la1[2][4]-G*la1[2][3];
\r
91 B=ra1[1]-H*la1[1][4]-G*la1[1][3]-C*la1[1][2];
\r
92 A=ra1[0]-H*la1[0][4]-G*la1[0][3]-C*la1[0][2]-B*la1[0][1];
\r