Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 203 | chris | 1 | /* |
| 2 | * PROJECT: NyARToolkit |
||
| 3 | * -------------------------------------------------------------------------------- |
||
| 4 | * This work is based on the original ARToolKit developed by |
||
| 5 | * Hirokazu Kato |
||
| 6 | * Mark Billinghurst |
||
| 7 | * HITLab, University of Washington, Seattle |
||
| 8 | * http://www.hitl.washington.edu/artoolkit/ |
||
| 9 | * |
||
| 10 | * The NyARToolkit is Java version ARToolkit class library. |
||
| 11 | * Copyright (C)2008 R.Iizuka |
||
| 12 | * |
||
| 13 | * This program is free software; you can redistribute it and/or |
||
| 14 | * modify it under the terms of the GNU General Public License |
||
| 15 | * as published by the Free Software Foundation; either version 2 |
||
| 16 | * of the License, or (at your option) any later version. |
||
| 17 | * |
||
| 18 | * This program is distributed in the hope that it will be useful, |
||
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 21 | * GNU General Public License for more details. |
||
| 22 | * |
||
| 23 | * You should have received a copy of the GNU General Public License |
||
| 24 | * along with this framework; if not, write to the Free Software |
||
| 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
| 26 | * |
||
| 27 | * For further information please contact. |
||
| 28 | * http://nyatla.jp/nyatoolkit/ |
||
| 29 | * <airmail(at)ebony.plala.or.jp> |
||
| 30 | * |
||
| 31 | */ |
||
| 32 | package jp.nyatla.nyartoolkit.core; |
||
| 33 | |||
| 34 | import jp.nyatla.nyartoolkit.NyARException; |
||
| 35 | |||
| 36 | |||
| 37 | |||
| 38 | public class NyARVec |
||
| 39 | { |
||
| 40 | private int clm; |
||
| 41 | public NyARVec(int i_clm) |
||
| 42 | { |
||
| 43 | v=new double[i_clm]; |
||
| 44 | clm=i_clm; |
||
| 45 | } |
||
| 46 | private double[] v; |
||
| 47 | /** |
||
| 48 | * i_clmサイズの列を格納できるように列サイズを変更します。 |
||
| 49 | * 実行後、列の各値は不定になります。 |
||
| 50 | * @param i_clm |
||
| 51 | */ |
||
| 52 | public void realloc(int i_clm) |
||
| 53 | { |
||
| 54 | if(i_clm<=this.v.length) |
||
| 55 | { |
||
| 56 | //十分な配列があれば何もしない。 |
||
| 57 | }else{ |
||
| 58 | //不十分なら取り直す。 |
||
| 59 | v=new double[i_clm]; |
||
| 60 | } |
||
| 61 | this.clm=i_clm; |
||
| 62 | } |
||
| 63 | public int getClm() |
||
| 64 | { |
||
| 65 | return clm; |
||
| 66 | } |
||
| 67 | public double[] getArray() |
||
| 68 | { |
||
| 69 | return v; |
||
| 70 | } |
||
| 71 | /** |
||
| 72 | * arVecDispの代替品 |
||
| 73 | * @param value |
||
| 74 | * @return |
||
| 75 | */ |
||
| 76 | public int arVecDisp() throws NyARException |
||
| 77 | { |
||
| 78 | NyARException.trap("未チェックのパス"); |
||
| 79 | System.out.println(" === vector ("+clm+") ===\n");//printf(" === vector (%d) ===\n", v->clm); |
||
| 80 | System.out.print(" |");//printf(" |"); |
||
| 81 | for(int c = 0; c < clm; c++ ){//for( c = 0; c < v->clm; c++ ){ |
||
| 82 | System.out.print(" "+v[c]);//printf( " %10g", v->v[c] ); |
||
| 83 | } |
||
| 84 | System.out.println(" |");//printf(" |\n"); |
||
| 85 | System.out.println(" ===================");//printf(" ===================\n"); |
||
| 86 | return 0; |
||
| 87 | } |
||
| 88 | /** |
||
| 89 | * arVecInnerproduct関数の代替品 |
||
| 90 | * @param x |
||
| 91 | * @param y |
||
| 92 | * @param i_start |
||
| 93 | * 演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる) |
||
| 94 | * @return |
||
| 95 | * @throws NyARException |
||
| 96 | */ |
||
| 97 | public double vecInnerproduct(NyARVec y,int i_start) throws NyARException |
||
| 98 | { |
||
| 99 | NyARException.trap("この関数は動作確認できていません。"); |
||
| 100 | double result = 0.0; |
||
| 101 | // double[] x_array=x.v;.getArray(); |
||
| 102 | // double[] y_array=y.getArray(); |
||
| 103 | |||
| 104 | if(this.clm!= y.clm){ |
||
| 105 | throw new NyARException();//exit(); |
||
| 106 | } |
||
| 107 | for(int i = i_start; i < this.clm; i++ ) { |
||
| 108 | NyARException.trap("未チェックのパス"); |
||
| 109 | result += this.v[i] * y.v[i];//result += x->v[i] * y->v[i]; |
||
| 110 | } |
||
| 111 | return result; |
||
| 112 | } |
||
| 113 | /** |
||
| 114 | * double arVecHousehold関数の代替品 |
||
| 115 | * @param x |
||
| 116 | * @param i_start |
||
| 117 | * 演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる) |
||
| 118 | * @return |
||
| 119 | * @throws NyARException |
||
| 120 | */ |
||
| 121 | public double vecHousehold(int i_start) throws NyARException |
||
| 122 | { |
||
| 123 | NyARException.trap("この関数は動作確認できていません。"); |
||
| 124 | double s, t; |
||
| 125 | s = Math.sqrt(this.vecInnerproduct(this,i_start)); |
||
| 126 | // double[] x_array=x.getArray(); |
||
| 127 | if( s != 0.0 ){ |
||
| 128 | NyARException.trap("未チェックのパス"); |
||
| 129 | if(this.v[i_start]< 0){ |
||
| 130 | s = -s; |
||
| 131 | } |
||
| 132 | NyARException.trap("未チェックのパス");{ |
||
| 133 | this.v[i_start]+=s;//x->v[0] += s; |
||
| 134 | t = 1 / Math.sqrt(this.v[i_start]* s);//t = 1 / sqrt(x->v[0] * s); |
||
| 135 | } |
||
| 136 | for(int i = i_start; i < this.clm; i++){ |
||
| 137 | NyARException.trap("未チェックのパス"); |
||
| 138 | this.v[i]*=t;//x->v[i] *= t; |
||
| 139 | } |
||
| 140 | } |
||
| 141 | return -s; |
||
| 142 | } |
||
| 143 | // /** |
||
| 144 | // * arVecTridiagonalize関数の代替品 |
||
| 145 | // * a,d,e間で演算をしてる。何をどうしているかはさっぱりさっぱり |
||
| 146 | // * @param a |
||
| 147 | // * @param d |
||
| 148 | // * @param e |
||
| 149 | // * @param i_e_start |
||
| 150 | // * 演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる) |
||
| 151 | // * @return |
||
| 152 | // * @throws NyARException |
||
| 153 | // */ |
||
| 154 | // public static void vecTridiagonalize(NyARMat a, NyARVec d, NyARVec e,int i_e_start) throws NyARException |
||
| 155 | // { |
||
| 156 | // NyARVec vec,vec2; |
||
| 157 | // double[][] a_array=a.getArray(); |
||
| 158 | // double s, t, p, q; |
||
| 159 | // int dim; |
||
| 160 | // |
||
| 161 | // if(a.getClm()!=a.getRow()){ |
||
| 162 | // throw new NyARException(); |
||
| 163 | // } |
||
| 164 | // if(a.getClm() != d.clm){ |
||
| 165 | // throw new NyARException(); |
||
| 166 | // } |
||
| 167 | // if(a.getClm() != e.clm){ |
||
| 168 | // throw new NyARException(); |
||
| 169 | // } |
||
| 170 | // dim = a.getClm(); |
||
| 171 | // |
||
| 172 | // for(int k = 0; k < dim-2; k++ ){ |
||
| 173 | // vec=a.getRowVec(k); |
||
| 174 | //// double[] vec_array=vec.getArray(); |
||
| 175 | // NyARException.trap("未チェックパス"); |
||
| 176 | // d.v[k]=vec.v[k];//d.set(k,v.get(k)); //d->v[k] = v[k]; |
||
| 177 | // |
||
| 178 | // //wv1.clm = dim-k-1; |
||
| 179 | // //wv1.v = &(v[k+1]); |
||
| 180 | // NyARException.trap("未チェックパス"); |
||
| 181 | // e.v[k+i_e_start]=vec.vecHousehold(k+1);//e->v[k] = arVecHousehold(&wv1); |
||
| 182 | // if(e.v[k+i_e_start]== 0.0 ){ |
||
| 183 | // continue; |
||
| 184 | // } |
||
| 185 | // |
||
| 186 | // for(int i = k+1; i < dim; i++ ){ |
||
| 187 | // s = 0.0; |
||
| 188 | // for(int j = k+1; j < i; j++ ) { |
||
| 189 | // NyARException.trap("未チェックのパス"); |
||
| 190 | // s += a_array[j][i] * vec.v[j];//s += a.get(j*dim+i) * v.get(j);//s += a->m[j*dim+i] * v[j]; |
||
| 191 | // } |
||
| 192 | // for(int j = i; j < dim; j++ ) { |
||
| 193 | // NyARException.trap("未チェックのパス"); |
||
| 194 | // s += a_array[i][j] * vec.v[j];//s += a.get(i*dim+j) * v.get(j);//s += a->m[i*dim+j] * v[j]; |
||
| 195 | // } |
||
| 196 | // NyARException.trap("未チェックのパス"); |
||
| 197 | // d.v[i]=s;//d->v[i] = s; |
||
| 198 | // } |
||
| 199 | // |
||
| 200 | // |
||
| 201 | // //wv1.clm = wv2.clm = dim-k-1; |
||
| 202 | // //wv1.v = &(v[k+1]); |
||
| 203 | // //wv2.v = &(d->v[k+1]); |
||
| 204 | // vec=a.getRowVec(k); |
||
| 205 | //// vec_array=vec.getArray(); |
||
| 206 | // NyARException.trap("未チェックパス"); |
||
| 207 | // t = vec.vecInnerproduct(d,k+1)/ 2; |
||
| 208 | // for(int i = dim-1; i > k; i-- ) { |
||
| 209 | // NyARException.trap("未チェックパス"); |
||
| 210 | // p = vec.v[i];//p = v.get(i);//p = v[i]; |
||
| 211 | // d.v[i]-=t*p;q=d.v[i];//q = d->v[i] -= t*p; |
||
| 212 | // for(int j = i; j < dim; j++ ){ |
||
| 213 | // NyARException.trap("未チェックパス"); |
||
| 214 | // a_array[i][j]-=p*(d.v[j] + q*vec.v[j]);//a->m[i*dim+j] -= p*(d->v[j]) + q*v[j]; |
||
| 215 | // } |
||
| 216 | // } |
||
| 217 | // } |
||
| 218 | // |
||
| 219 | // if( dim >= 2) { |
||
| 220 | // d.v[dim-2]=a_array[dim-2][dim-2];//d->v[dim-2] = a->m[(dim-2)*dim+(dim-2)]; |
||
| 221 | // e.v[dim-2+i_e_start]=a_array[dim-2][dim-1];//e->v[dim-2] = a->m[(dim-2)*dim+(dim-1)]; |
||
| 222 | // } |
||
| 223 | // |
||
| 224 | // if( dim >= 1 ){ |
||
| 225 | // d.v[dim-1]=a_array[dim-1][dim-1];//d->v[dim-1] = a->m[(dim-1)*dim+(dim-1)]; |
||
| 226 | // } |
||
| 227 | // |
||
| 228 | // for(int k = dim-1; k >= 0; k--) { |
||
| 229 | // vec=a.getRowVec(k);//v = a.getPointer(k*dim);//v = &(a->m[k*dim]); |
||
| 230 | // if( k < dim-2 ) { |
||
| 231 | // for(int i = k+1; i < dim; i++ ){ |
||
| 232 | // //wv1.clm = wv2.clm = dim-k-1; |
||
| 233 | // //wv1.v = &(v[k+1]); |
||
| 234 | // //wv2.v = &(a->m[i*dim+k+1]); |
||
| 235 | // vec2=a.getRowVec(i); |
||
| 236 | // |
||
| 237 | // t = vec.vecInnerproduct(vec2,k+1); |
||
| 238 | // for(int j = k+1; j < dim; j++ ){ |
||
| 239 | // NyARException.trap("未チェックパス"); |
||
| 240 | // a_array[i][j]-=t*vec.v[j];//a.subValue(i*dim+j,t*v.get(j));//a->m[i*dim+j] -= t * v[j]; |
||
| 241 | // } |
||
| 242 | // } |
||
| 243 | // } |
||
| 244 | // for(int i = 0; i < dim; i++ ){ |
||
| 245 | // vec.v[i]=0.0;//v.set(i,0.0);//v[i] = 0.0; |
||
| 246 | // } |
||
| 247 | // vec.v[k]=1;//v.set(k,1);//v[k] = 1; |
||
| 248 | // } |
||
| 249 | // } |
||
| 250 | /** |
||
| 251 | * 現在ラップしている配列を取り外して、新しい配列をラップします。 |
||
| 252 | * @param i_v |
||
| 253 | * @param i_clm |
||
| 254 | */ |
||
| 255 | public void setNewArray(double[] i_array,int i_clm) |
||
| 256 | { |
||
| 257 | this.v=i_array; |
||
| 258 | this.clm=i_clm; |
||
| 259 | } |
||
| 260 | } |