ダウンロードリスト

Sponsored link

システム要件

システム要件が設定されていません

リリース時刻: 2009-10-15 15:53
NyARToolkit for Java - NyARToolkit Core 2.4.0 (1 個のファイル 非表示)

リリースノート

ライセンス

  • ライブラリのライセンスを、GPLv3へ変更しました。

性能向上

  • 以下のアルゴリズム組み換えにより、負荷を55%削減しました。
  • 偏微分フィッティングの追加 - フィッティング処理に偏微分フィッティングを採用したことにより、座標変換速度高速化しています。複数のマーカを扱う時に、最大10倍程度の高速化が見込めます。
  • RLE符号ラベリングの追加 - ラベリング速度が(殆どの場合)高速化します。
  • 演算式の最適化 - 並進ベクトル計算器をARToolKitの本を参考に再実装にしました。

マーカ一個辺りの姿勢計算コストが1/10になり、1フレーム辺りのマーカ検出コストが1/2になっています。

主なAPI変更

  • NyARTransmatResultの、angleプロパティを削除しました。
  • 機能統合により、いくつかの内部クラスを削除しました。

機能追加

  • NyARTransmatResultZXY系の角度情報を取得するAPIを追加しました。

変更履歴

Index: D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/CopyOfNyARColorPatt_NyIdMarker.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/CopyOfNyARColorPatt_NyIdMarker.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/CopyOfNyARColorPatt_NyIdMarker.java (revision 302)
@@ -1,1119 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.dev;
-
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.NyARSquare;
-import jp.nyatla.nyartoolkit.core.raster.rgb.*;
-import jp.nyatla.nyartoolkit.core.rasterreader.*;
-import jp.nyatla.nyartoolkit.core.types.*;
-import jp.nyatla.nyartoolkit.core.utils.*;
-import jp.nyatla.nyartoolkit.core.labeling.NyARLabelingLabel;
-import jp.nyatla.nyartoolkit.core.pickup.*;
-import jp.nyatla.nyartoolkit.nyidmarker.MarkerPattEncoder;
-import jp.nyatla.nyartoolkit.nyidmarker.PerspectivePixelReader;
-
-
-
-/**
- * 1区間にある1個のエッジ位置を推定するクラスです。
- *
- */
-class NyARSingleEdgeFinder2
-{
- public static class TEdgeInfo
- {
- double point; //検出したエッジの位置
- int sub; //エッジの差分
- }
- private int[] _work;
- private int _width;
- private int _height;
- public NyARSingleEdgeFinder2(int i_width,int i_height)
- {
- this._work=new int[(i_width>i_height?i_width:i_height)+1];
- this._work[this._work.length-1]=0;
- this._width=i_width;
- this._height=i_height;
- return;
- }
- /**
- * この関数は、一区間に1個のエッジが含まれていると仮定して、その位置を推定します。
- * [n]個の配列を与えた場合、[n+2]~[n-1]の間にあるエッジを検出します。
- * 検出方向は左→右の順です
- * @param i_pixcel
- * @param i_start
- * @param i_length
- * @param o_out
- * @return
- */
- public boolean scanSingleEdgeLeftToRight(int[] i_pixcel,int i_y,TEdgeInfo o_out)
- {
- final int[] temp=this._work;
- //1回微分(0-8)
- final int length=this._width-1;
- int p=i_y*this._width;
- for(int i2=0;i2<length;i2++){
- temp[i2]=i_pixcel[p+1]-i_pixcel[p];
- p++;
- }
- return scanSingleEdge(temp,length,o_out);
- }
- /**
- * 線分内のエッジを検出します。
- * この関数は、1区間に1個のエッジが含まれていると仮定して、その位置を推定します。
- * [n]個の配列を与えた場合、[n+2]~[n-1]の間にあるエッジを検出します。
- * 検出方向は右→左の順です
- * @param i_pixcel
- * @param i_start
- * @param i_length
- * @param o_out
- * @return
- */
- public boolean scanSingleEdgeRightToLeft(int[] i_pixcel,int i_y,TEdgeInfo o_out)
- {
- final int[] temp=this._work;
- //1回微分(0-8)
- final int length=this._width-1;
- int p=(i_y+1)*this._width-1;
- for(int i2=0;i2<length;i2++){
- temp[i2]=i_pixcel[p-1]-i_pixcel[p];
- p--;
- }
- return scanSingleEdge(temp,length,o_out);
- }
- public boolean scanSingleEdgeTopToBottom(int[] i_pixcel,int i_x,TEdgeInfo o_out)
- {
- final int[] temp=this._work;
- //1回微分(0-8)
- final int step=this._width;
- final int length=this._height-1;
- int p=i_x;
- for(int i2=0;i2<length;i2++){
- temp[i2]=i_pixcel[p+step]-i_pixcel[p];
- p+=step;
- }
- return scanSingleEdge(temp,length,o_out);
- }
- public boolean scanSingleEdgeBottomToTop(int[] i_pixcel,int i_x,TEdgeInfo o_out)
- {
- final int[] temp=this._work;
- //1回微分(0-8)
- final int step=this._width;
- final int length=this._height-1;
- int p=i_x+step*length;
- for(int i2=0;i2<length;i2++){
- temp[i2]=i_pixcel[p-step]-i_pixcel[p];
- p-=step;
- }
- return scanSingleEdge(temp,length,o_out);
- }
- private boolean scanSingleEdge(int[] i_pixels,int i_length,TEdgeInfo o_out)
- {
- //微分(2回目)して、極値2か所を得る
- int max_index,min_index;
- int length=i_length-1;
- max_index=min_index=0;
- int max_value,min_value;
- max_value=min_value=0;
- for(int i2=0;i2<length;i2++){
- int t=i_pixels[i2+1]-i_pixels[i2];
- if(t>max_value){
- max_index=i2;
- max_value=t;
- }
- if(t<min_value){
- min_index=i2;
- min_value=t;
- }
- }
- //同符号である場合、範囲内にエッジはない
- if(max_value*min_value>=0){
- return false;
- }
- o_out.point=(max_index+min_index)/2.0;
- o_out.sub=max_value-min_value;
- return true;
- }
- public int scanEdgeLeftToRight(int[] i_pixel,int i_y,int i_noise_th,double[] o_edge_index)
- {
- final int[] temp=this._work;
- //1回微分(0-8)
- final int length=this._width-1;
- int p=i_y*this._width;
- for(int i2=0;i2<length;i2++){
- temp[i2]=i_pixel[p+1]-i_pixel[p];
- p++;
- }
- //0終端させるために1要素を後続に追加
- return scanEdge(temp,length+1,i_noise_th,o_edge_index);
- }
- private int scanEdge(int[] i_pixels,int i_length,int i_noise_th,double[] o_out)
- {
- int points=0;
- final int length=i_length;
- //エッジ1区間を抜き出す
- for(int i2=0;i2<length;i2++){
- int t=i_pixels[i2];
- if(t>i_noise_th){
- int st=i2;
- i2++;
- for(;i2<length;i2++){
- t=i_pixels[i2];
- if(t<=0){
- //(st - i2で1区間)
- //エッジ位置は区間の中央にする。
- o_out[points]=(st+i2)/2.0;
- points++;
- if(t<0){
- //マイナスであれば、0を補完する
- i2--;
- i_pixels[i2]=0;
- }
- break;
- }
-
- }
- }else if(t<-i_noise_th){
- int st=i2;
- i2++;
- for(;i2<length;i2++){
- t=i_pixels[i2];
- if(t>=0){
- //(st - i2で1区間)
- //エッジ位置は区間の中央にする。
- o_out[points]=(st+i2)/2.0;
- points++;
- if(t>0){
- //プラスであれば、0を補完する
- i2--;
- i_pixels[i2]=0;
- }
- break;
- }
- }
- }
- }
- return points;
- }
- /**
- * 指定した配列をノイズパターンとして、ノイズ値を計算します。
- * このノイズ値は、scanEdgeのノイズ値として使用できます。
- * @param i_pixels
- * @param i_length
- * @return
- */
- public int getNoiseValue(int[] i_pixels,int i_length)
- {
- //1回微分して、その最大値と最小値を計算
- int length=i_length-1;
- int max_value,min_value;
- max_value=min_value=0;
- for(int i2=0;i2<length;i2++){
- int t=i_pixels[i2+1]-i_pixels[i2];
- if(t>max_value){
- max_value=t;
- }
- if(t<min_value){
- min_value=t;
- }
- }
- return (-min_value>max_value)?-min_value:max_value;
- }
-}
-
-class MarkerEncoder2
-{
- private final static int[] _bit_table_3={
- 25, 26, 27, 28, 29, 30, 31,
- 48, 9, 10, 11, 12, 13, 32,
- 47, 24, 1, 2, 3, 14, 33,
- 46, 23, 8, 0, 4, 15, 34,
- 45, 22, 7, 6, 5, 16, 35,
- 44, 21, 20, 19, 18, 17, 36,
- 43, 42, 41, 40, 39, 38, 37
- };
- private final static int[] _bit_table_2={
- 9, 10, 11, 12, 13,
- 24, 1, 2, 3, 14,
- 23, 8, 0, 4, 15,
- 22, 7, 6, 5, 16,
- 21, 20, 19, 18, 17};
- private final static int[][] _bit_tables={
- _bit_table_2,_bit_table_3
- };
- /**
- * RECT(0):[0]=(0)
- * RECT(1):[1]=(1-8)
- * RECT(2):[2]=(9-16),[3]=(17-24)
- * RECT(3):[4]=(25-32),[5]=(33-40),[6]=(41-48)
- */
- int[] _bit_table;
- int[] _bits=new int[16];
- int[] _work=new int[16];
- int _model;
- public void setBitByBitIndex(int i_index_no,int i_value)
- {
- assert i_value==0 || i_value==1;
- final int bit_no=this._bit_table[i_index_no];
- if(bit_no==0){
- this._bits[0]=i_value;
- }else{
- int bidx=(bit_no-1)/8+1;
- int sidx=(bit_no-1)%8;
- this._bits[bidx]=(this._bits[bidx]&(~(0x01<<sidx)))|(i_value<<sidx);
- }
- return;
- }
-
- public void setBit(int i_bit_no,int i_value)
- {
- assert i_value==0 || i_value==1;
- if(i_bit_no==0){
- this._bits[0]=i_value;
- }else{
- int bidx=(i_bit_no-1)/8+1;
- int sidx=(i_bit_no-1)%8;
- this._bits[bidx]=(this._bits[bidx]&(~(0x01<<sidx)))|(i_value<<sidx);
- }
- return;
- }
- public int getBit(int i_bit_no)
- {
- if(i_bit_no==0){
- return this._bits[0];
- }else{
- int bidx=(i_bit_no-1)/8+1;
- int sidx=(i_bit_no-1)%8;
- return (this._bits[bidx]>>(sidx))&(0x01);
- }
- }
- public boolean initEncoder(int i_model)
- {
- if(i_model>=4 || i_model<2){
- //Lv4以降に対応する時は、この制限を変える。
- return false;
- }
- this._bit_table=_bit_tables[i_model-2];
- this._model=i_model;
- return true;
- }
- private int getDirection()
- {
- int l,t,r,b;
- switch(this._model){
- case 2:
- //トラッキングセルを得る
- t=this._bits[2] & 0x07;
- r=(this._bits[2] & 0x70)>>4;
- b=this._bits[3] & 0x07;
- l=(this._bits[3] & 0x70)>>4;
- break;
- case 3:
- default:
- return -3;
- }
- //101であるかを確認
- if(t==0x05){
- if(r==0x05){
- return (b!=0x05 && l!=0x05)?2:-2;
- }else if(l==0x05){
- return (b!=0x05 && r!=0x05)?3:-2;
- }
- }else if(b==0x05){
- if(r==0x05){
- return (t!=0x05 && l!=0x05)?1:-2;
- }else if(l==0x05){
- return (t!=0x05 && r!=0x05)?0:-2;
- }
- }
- return -1;
- }
-
- public boolean encode()
- {
- int d=getDirection();
- if(d<0){
- return false;
- }
- //回転操作
-
- rotateDirection(d);
- //デコード
-
- return true;
- }
- private void rotateDirection(int i_direction)
- {
- int sl=i_direction*2;
- int sr=8-sl;
-
- int w1;
- //RECT1
- w1=this._bits[1];
- this._bits[1]=(w1<<sl)|(w1>>sr);
-
- //RECT2
- sl=i_direction*4;
- sr=16-sl;
- w1=this._bits[2]|(this._bits[3]<<8);
- w1=(w1<<sl)|(w1>>sr);
- this._bits[2]=w1 & 0xff;
- this._bits[3]=(w1>>8) & 0xff;
-
- if(this._model<2){
- return;
- }
-
- //RECT3
- sl=i_direction*6;
- sr=24-sl;
- w1=this._bits[4]|(this._bits[5]<<8)|(this._bits[6]<<16);
- w1=(w1<<sl)|(w1>>sr);
- this._bits[4]=w1 & 0xff;
- this._bits[5]=(w1>>8) & 0xff;
- this._bits[6]=(w1>>16) & 0xff;
-
- if(this._model<3){
- return;
- }
- //RECT4(Lv4以降はここの制限を変える)
-// shiftLeft(this._bits,7,3,i_direction*);
-
- return;
- }
- public void shiftLeft(int[] i_pack,int i_start,int i_length,int i_ls)
- {
- int[] work=this._work;
- //端数シフト
- final int mod_shift=i_ls%8;
- for(int i=i_length-1;i>=1;i--){
- work[i]=(i_pack[i+i_start]<<mod_shift)|(0xff&(i_pack[i+i_start-1]>>(8-mod_shift)));
- }
- work[0]=(i_pack[i_start]<<mod_shift)|(0xff&(i_pack[i_start+i_length-1]>>(8-mod_shift)));
- //バイトシフト
- final int byte_shift=(i_ls/8)%i_length;
- for(int i=i_length-1;i>=0;i--){
- i_pack[(byte_shift+i)%i_length+i_start]=0xff & work[i];
- }
- return;
- }
-
-
-}
-
-
-/**
- * NyARColorPatt_NyIdMarkerがラスタからPerspective変換して読みだすためのクラス
- *
- */
-class PerspectivePixelReader2 extends NyARPerspectiveParamGenerator_O1
-{
- private double[] _cparam=new double[8];
-
- public PerspectivePixelReader2(int i_local_x,int i_local_y,int i_width, int i_height)
- {
- super(i_local_x,i_local_y,i_width,i_height);
- this._temp1=new int[i_width];
- this._temp2=new int[i_width];
- this._pixcel_temp=new int[i_width*3];
-
- return;
- }
- private int[] _temp1;
- private int[] _temp2;
- private int[] _pixcel_temp;
- private INyARRgbRaster _raster;
- public void setSourceRaster(INyARRgbRaster i_raster)
- {
- this._raster=i_raster;
- return;
- }
- public boolean setSourceSquare(NyARIntPoint2d[] i_vertex)throws NyARException
- {
- return this.getParam(i_vertex, this._cparam);
- }
- public void rectPixels(int i_lt_x,int i_lt_y,int i_width,int i_height,int[] o_pixcel)throws NyARException
- {
- final double[] cpara=this._cparam;
- final INyARRgbPixelReader reader=this._raster.getRgbPixelReader();
- final int[] ref_x=this._temp1;
- final int[] ref_y=this._temp2;
- final int[] pixcel_temp=this._pixcel_temp;
- int out_index=0;
-
- for(int i=0;i<i_height;i++){
- //1列分のピクセルのインデックス値を計算する。
- int cy0=1+i+i_lt_y;
- double cpy0_12=cpara[1]*cy0+cpara[2];
- double cpy0_45=cpara[4]*cy0+cpara[5];
- double cpy0_7=cpara[7]*cy0+1.0;
- int pt=0;
- for(int i2=0;i2<i_width;i2++)
- {
- int cx0=1+i2+i_lt_x;
-
- double cp6_0=cpara[6]*cx0;
- double cpx0_0=cpara[0]*cx0;
- double cpx3_0=cpara[3]*cx0;
-
- final double d=cp6_0+cpy0_7;
- ref_x[pt]=(int)((cpx0_0+cpy0_12)/d);
- ref_y[pt]=(int)((cpx3_0+cpy0_45)/d);
- pt++;
- }
- //1行分のピクセルを取得(場合によっては専用アクセサを書いた方がいい)
- reader.getPixelSet(ref_x,ref_y,i_width,pixcel_temp);
- //グレースケールにしながら、line→mapへの転写
- for(int i2=0;i2<i_width;i2++){
- int index=i2*3;
- o_pixcel[out_index]=(pixcel_temp[index+0]+pixcel_temp[index+1]+pixcel_temp[index+2])/3;
- out_index++;
- }
- }
- return;
- }
-
-
-
-
- //タイミングパターン用のパラメタ(FRQ_POINTS*FRQ_STEPが100を超えないようにすること)
- private static int FRQ_STEP=2;
- private static int FRQ_POINTS=45;
- public static int FRQ_EDGE=5;
-
-
- /**
- * i_y1行目とi_y2行目を平均して、タイミングパターンの周波数を得ます。
- * LHLを1周期として、たとえばLHLHLの場合は2を返します。LHLHやHLHL等の始端と終端のレベルが異なるパターンを
- * 検出した場合、関数は失敗します。
- *
- * @param i_y1
- * @param i_y2
- * @param i_th_h
- * @param i_th_l
- * @param o_edge_index
- * 検出したエッジ位置(H->L,L->H)のインデクスを受け取る配列です。
- * [FRQ_POINTS]以上の配列を指定してください。
- * @return
- * @throws NyARException
- */
- public int getRowFrequency(int i_y1,int i_th_h,int i_th_l,int[] o_edge_index)throws NyARException
- {
- final double[] cpara=this._cparam;
- final INyARRgbPixelReader reader=this._raster.getRgbPixelReader();
- final int[] ref_x=this._temp1;
- final int[] ref_y=this._temp2;
- final int[] pixcel_temp=this._pixcel_temp;
-
- //2行分のピクセルインデックスを計算
- int cy0=1+i_y1;
- double cpy0_12=cpara[1]*cy0+cpara[2];
- double cpy0_45=cpara[4]*cy0+cpara[5];
- double cpy0_7=cpara[7]*cy0+1.0;
-
-
- int pt=0;
- for(int i2=0;i2<FRQ_POINTS;i2++)
- {
- double d;
- final int cx0=1+i2*FRQ_STEP+FRQ_EDGE;
- d=(cpara[6]*cx0)+cpy0_7;
- ref_x[pt]=(int)((cpara[0]*cx0+cpy0_12)/d);
- ref_y[pt]=(int)((cpara[3]*cx0+cpy0_45)/d);
- pt++;
- }
-
- //ピクセルを取得(入力画像を多様化するならここから先を調整すること)
- reader.getPixelSet(ref_x,ref_y,FRQ_POINTS,pixcel_temp);
- return getFreqInfo(pixcel_temp,i_th_h,i_th_l,o_edge_index);
- }
- public int getColFrequency(int i_x1,int i_th_h,int i_th_l,int[] o_edge_index)throws NyARException
- {
- final double[] cpara=this._cparam;
- final INyARRgbPixelReader reader=this._raster.getRgbPixelReader();
- final int[] ref_x=this._temp1;
- final int[] ref_y=this._temp2;
- final int[] pixcel_temp=this._pixcel_temp;
-
- final int cx0=1+i_x1;
- final double cp6_0=cpara[6]*cx0;
- final double cpx0_0=cpara[0]*cx0;
- final double cpx3_0=cpara[3]*cx0;
-
- int pt=0;
- for(int i2=0;i2<FRQ_POINTS;i2++)
- {
- double d;
- int cy=1+i2*FRQ_STEP+FRQ_EDGE;
- double cpy_12=cpara[1]*cy+cpara[2];
- double cpy_45=cpara[4]*cy+cpara[5];
- double cpy_7=cpara[7]*cy+1.0;
-
- d=cp6_0+cpy_7;
- ref_x[pt]=(int)((cpx0_0+cpy_12)/d);
- ref_y[pt]=(int)((cpx3_0+cpy_45)/d);
- pt++;
-
- }
-
- //ピクセルを取得(入力画像を多様化するならここから先を調整すること)
- reader.getPixelSet(ref_x,ref_y,FRQ_POINTS,pixcel_temp);
- return getFreqInfo(pixcel_temp,i_th_h,i_th_l,o_edge_index);
- }
-
- /**
- * デバックすんだらstaticにしておk
- * @param i_pixcels
- * @param i_th_h
- * @param i_th_l
- * @param o_edge_index
- * @return
- */
- private int getFreqInfo(int[] i_pixcels,int i_th_h,int i_th_l,int[] o_edge_index)
- {
- //トークンを解析して、周波数を計算
- int i=0;
- int frq_l2h=0;
- int frq_h2l=0;
- while(i<FRQ_POINTS){
- //L->Hトークンを検出する
- while(i<FRQ_POINTS){
- final int index=i*3;
- final int pix=(i_pixcels[index+0]+i_pixcels[index+1]+i_pixcels[index+2])/3;
- if(pix>i_th_h){
- //トークン発見
- o_edge_index[frq_l2h+frq_h2l]=i;
- frq_l2h++;
- break;
- }
- i++;
- }
- i++;
- //L->Hトークンを検出する
- while(i<FRQ_POINTS){
- final int index=i*3;
- final int pix=(i_pixcels[index+0]+i_pixcels[index+1]+i_pixcels[index+2])/3;
- if(pix<=i_th_l){
- //トークン発見
- o_edge_index[frq_l2h+frq_h2l]=i;
- frq_h2l++;
- break;
- }
- i++;
- }
- i++;
- }
- return frq_l2h==frq_h2l?frq_l2h:-1;
- }
-
-
-
- public boolean readDataBits(double[] i_index_x,double[] i_index_y,int i_size,int i_th,MarkerPattEncoder o_bitbuffer)throws NyARException
- {
-
- assert i_size*4<this._width;
-
- final double[] cpara=this._cparam;
-
- final int[] ref_x=this._temp1;
- final int[] ref_y=this._temp2;
- final INyARRgbPixelReader reader=this._raster.getRgbPixelReader();
- final int[] pixcel_temp=this._pixcel_temp;
-
- int p=0;
- for(int i=0;i<i_size;i++){
- //1列分のピクセルのインデックス値を計算する。
- double cy0=1+i_index_y[i*2+0];
- double cy1=1+i_index_y[i*2+1];
- double cpy0_12=cpara[1]*cy0+cpara[2];
- double cpy0_45=cpara[4]*cy0+cpara[5];
- double cpy0_7=cpara[7]*cy0+1.0;
- double cpy1_12=cpara[1]*cy1+cpara[2];
- double cpy1_45=cpara[4]*cy1+cpara[5];
- double cpy1_7=cpara[7]*cy1+1.0;
-
- int pt=0;
- for(int i2=0;i2<i_size;i2++)
- {
-
- double d;
- double cx0=1+i_index_x[i2*2+0];
- double cx1=1+i_index_x[i2*2+1];
-
- double cp6_0=cpara[6]*cx0;
- double cp6_1=cpara[6]*cx1;
- double cpx0_0=cpara[0]*cx0;
- double cpx3_0=cpara[3]*cx0;
-
- d=cp6_0+cpy0_7;
- ref_x[pt]=(int)((cpx0_0+cpy0_12)/d);
- ref_y[pt]=(int)((cpx3_0+cpy0_45)/d);
- pt++;
-
- d=cp6_0+cpy1_7;
- ref_x[pt]=(int)((cpx0_0+cpy1_12)/d);
- ref_y[pt]=(int)((cpx3_0+cpy1_45)/d);
- pt++;
-
- d=cp6_1+cpy0_7;
- ref_x[pt]=(int)((cpara[0]*cx1+cpy0_12)/d);
- ref_y[pt]=(int)((cpara[3]*cx1+cpy0_45)/d);
- pt++;
-
- d=cp6_1+cpy1_7;
- ref_x[pt]=(int)((cpara[0]*cx1+cpy1_12)/d);
- ref_y[pt]=(int)((cpara[3]*cx1+cpy1_45)/d);
- pt++;
- }
- //1行分のピクセルを取得(場合によっては専用アクセサを書いた方がいい)
- reader.getPixelSet(ref_x,ref_y,i_size*4,pixcel_temp);
- //グレースケールにしながら、line→mapへの転写
- for(int i2=0;i2<i_size;i2++){
- int index=i2*3*4;
- int pixel=( pixcel_temp[index+0]+pixcel_temp[index+1]+pixcel_temp[index+2]+
- pixcel_temp[index+3]+pixcel_temp[index+4]+pixcel_temp[index+5]+
- pixcel_temp[index+6]+pixcel_temp[index+7]+pixcel_temp[index+8]+
- pixcel_temp[index+9]+pixcel_temp[index+10]+pixcel_temp[index+11])/(4*3);
- o_bitbuffer.setBitByBitIndex(p,pixel>i_th?1:0);
- p++;
- }
- }
- return true;
- }
-
- public boolean setSquare(NyARIntPoint2d[] i_vertex) throws NyARException
- {
- if (!getParam(i_vertex,this._cparam)) {
- return false;
- }
- return true;
- }
-}
-
-/**
- * 遠近法を使ったパースペクティブ補正付きのINyARColorPatt
- *
- */
-public class CopyOfNyARColorPatt_NyIdMarker implements INyARColorPatt
-{
- private int[] _patdata;
- private NyARBufferReader _buf_reader;
- private NyARRgbPixelReader_INT1D_GLAY_8 _pixelreader;
- private NyARIntSize _size;
- PerspectivePixelReader2 _perspective_gen;
- private static final int LOCAL_LT=1;
- /**
- * 例えば、64
- * @param i_width
- * 取得画像の解像度幅
- * @param i_height
- * 取得画像の解像度高さ
- * @param i_edge_percentage
- * エッジ幅の割合(ARToolKit標準と同じなら、25)
- */
- public CopyOfNyARColorPatt_NyIdMarker(int i_model)
- {
- //入力制限
- assert i_model==2;
- int resolution=i_model*2+1;
- this._size=new NyARIntSize(resolution,resolution);
- this._patdata = new int[resolution*resolution];
- this._buf_reader=new NyARBufferReader(this._patdata,NyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8);
- this._pixelreader=new NyARRgbPixelReader_INT1D_GLAY_8(this._patdata,this._size);
- this._perspective_gen=new PerspectivePixelReader2(LOCAL_LT,LOCAL_LT,100,100);
- return;
- }
-
- public final int getWidth()
- {
- return this._size.w;
- }
- public final int getHeight()
- {
- return this._size.h;
- }
- public final NyARIntSize getSize()
- {
- return this._size;
- }
- public final INyARBufferReader getBufferReader()
- {
- return this._buf_reader;
- }
- public final INyARRgbPixelReader getRgbPixelReader()
- {
- return this._pixelreader;
- }
-
-
- public int[] vertex_x=new int[49*4];
- public int[] vertex_y=new int[49*4];
- public int[] vertex2_x=new int[400];
- public int[] vertex2_y=new int[400];
- public int[] line1=new int[45];
- public int[] line2=new int[45];
- public int[] sv=new int[4];
- private int[] temp_pixcel=new int[144];
-// private NyARSingleEdgeFinder _edge_finder=new NyARSingleEdgeFinder(12,12);
-
-
- /**
- * マーカパラメータを格納する構造体
- */
- private class TMarkerParam{
- int threshold;
- int model;
- private double[] index_x=new double[25*2];
- private double[] index_y=new double[25*2];
- }
- /**
- * 周期が等間隔か調べる。
- * 次段半周期が、前段の80%より大きく、120%未満であるものを、等間隔周期であるとみなす。
- * @param i_freq
- * @param i_width
- */
- private boolean checkFreqWidth(int[] i_freq,int i_width)
- {
- int c=i_freq[1]-i_freq[0];
- for(int i=1;i<i_width*2-1;i++){
- final int n=i_freq[i+1]-i_freq[i];
- final int v=n*100/c;
- if(v>150 || v<50){
- return false;
- }
- c=n;
- }
- return true;
- }
- private static int MIN_FREQ=3;
- private static int MAX_FREQ=10;
-
- private int getRowFreq(int i_y,int i_th_h,int i_th_l,int[] o_freq_index)throws NyARException
- {
- //3,4,5,6,7,8,9,10
- int freq_index1[]=new int[45];
- int freq_count_table[]=new int[10];
- //0,2,4,6,8,10,12,14,16,18,20の要素を持つ配列
- int freq_table[][]=new int[10][20];
- //初期化
-
- //10-20ピクセル目からタイミングパターンを検出
- for(int i=i_y;i<i_y+10;i++){
- final int freq_t=this._perspective_gen.getRowFrequency(i,i_th_h,i_th_l,freq_index1);
- //周期は3-10であること
- if(freq_t<MIN_FREQ || freq_t>MAX_FREQ){
- continue;
- }
- //周期は等間隔であること
- if(!checkFreqWidth(freq_index1,freq_t)){
- continue;
- }
- //検出カウンタを追加
- freq_count_table[freq_t]++;
- for(int i2=0;i2<freq_t*2;i2++){
- freq_table[freq_t][i2]+=freq_index1[i2];
- }
- }
- //一番成分の大きいものを得る
- int index=-1;
- int max=0;
- for(int i=0;i<MAX_FREQ;i++){
- if(max<freq_count_table[i]){
- index=i;
- max=freq_count_table[i];
- }
- }
- /*周波数インデクスを計算*/
- for(int i=0;i<index*2;i++)
- {
- o_freq_index[i]=freq_table[index][i]/max;
- }
- return index;
- }
- private int getColFreq(int i_y,int i_th_h,int i_th_l,int[] o_freq_index)throws NyARException
- {
- //3,4,5,6,7,8,9,10
- int freq_index1[]=new int[45];
- int freq_count_table[]=new int[10];
- int freq_table[][]=new int[10][20];
- //初期化
-
- //10-20ピクセル目からタイミングパターンを検出
- for(int i=i_y;i<i_y+10;i++){
- final int freq_t=this._perspective_gen.getColFrequency(i,i_th_h,i_th_l,freq_index1);
- //周期は3-10であること
- if(freq_t<MIN_FREQ || freq_t>MAX_FREQ){
- continue;
- }
- //周期は等間隔であること
- if(!checkFreqWidth(freq_index1,freq_t)){
- continue;
- }
- //検出カウンタを追加
- freq_count_table[freq_t]++;
- for(int i2=0;i2<freq_t*2;i2++){
- freq_table[freq_t][i2]+=freq_index1[i2];
- }
- }
- //一番成分の大きいものを得る
- int index=-1;
- int max=0;
- for(int i=0;i<MAX_FREQ;i++){
- if(max<freq_count_table[i]){
- index=i;
- max=freq_count_table[i];
- }
- }
- for(int i=0;i<10;i++){
- System.out.print(freq_count_table[i]+",");
- }
- System.out.println();
- if(index==-1){
- return -1;
- }
- /*周波数インデクスを計算*/
- for(int i=0;i<index*2;i++)
- {
- o_freq_index[i]=freq_table[index][i]/max;
- }
- return index;
- }
- private boolean detectMarkerParam(INyARRgbPixelReader i_reader,TMarkerParam o_param)throws NyARException
- {
- TThreshold th=new TThreshold();
-
- detectThresholdValue(i_reader,10,10,th);
- //周波数測定(最も正しい周波数を検出する)
-
-
-
-
- //左上,右下から、12x12(抽出範囲は10x10)の調査用矩形を抽出
-
-
-
- //周波数を測定
- int freq_index1[]=new int[45];
- int freq_index2[]=new int[45];
- int frq_t=getRowFreq(10,th.th_h,th.th_l,freq_index1);
- int frq_b=getRowFreq(80,th.th_h,th.th_l,freq_index2);
- //周波数はまとも?
- if((frq_t<0 && frq_b<0) || frq_t==frq_b){
- System.out.print("FRQ_R");
- return false;
- }
- //タイミングパターンからインデクスを作成
- int freq;
- int[] index;
- if(frq_t>frq_b){
- freq=frq_t;
- index=freq_index1;
- }else{
- freq=frq_b;
- index=freq_index2;
- }
- for(int i=0;i<freq*2-1;i++){
- o_param.index_x[i*2]=((index[i+1]-index[i])*2/5+index[i])*2+PerspectivePixelReader.FRQ_EDGE;
- o_param.index_x[i*2+1]=((index[i+1]-index[i])*3/5+index[i])*2+PerspectivePixelReader.FRQ_EDGE;
- }
- int frq_l=getColFreq(10,th.th_h,th.th_l,freq_index1);
- int frq_r=getColFreq(80,th.th_h,th.th_l,freq_index2);
- //周波数はまとも?
- if((frq_l<0 && frq_r<0) || frq_l==frq_r){
- System.out.print("FRQ_C");
- return false;
- }
- //タイミングパターンからインデクスを作成
- if(frq_l>frq_r){
- freq=frq_l;
- index=freq_index1;
- }else{
- freq=frq_r;
- index=freq_index2;
- }
- for(int i=0;i<freq*2-1;i++){
- o_param.index_y[i*2]=((index[i+1]-index[i])*2/5+index[i])*2+PerspectivePixelReader.FRQ_EDGE;
- o_param.index_y[i*2+1]=((index[i+1]-index[i])*3/5+index[i])*2+PerspectivePixelReader.FRQ_EDGE;
- }
-
-
-
- //Lv4以上は無理
- if(freq>4){
- System.out.print("LVL_4");
- return false;
- }
- o_param.model=freq-1;
- o_param.threshold=th.th;
- return true;
-
- }
- private class TThreshold{
- public int th_h;
- public int th_l;
- public int th;
- }
- /**
- * 指定した場所のピクセル値を調査して、閾値を計算して返します。
- * @param i_reader
- * @param i_x
- * @param i_y
- * @return
- * @throws NyARException
- */
- private void detectThresholdValue(INyARRgbPixelReader i_reader,int i_x,int i_y,TThreshold o_threshold)throws NyARException
- {
- final int[] temp_pixel=this.temp_pixcel;
- //特定エリアから画素を得る
- this._perspective_gen.rectPixels(i_x,i_y,10,10,temp_pixel);
- //ソート
- int len=100;
- int h = len *13/10;
- for(;;){
- int swaps = 0;
- for (int i = 0; i + h < len; i++) {
- if (temp_pixel[i + h] > temp_pixel[i]) {
- final int temp = temp_pixel[i + h];
- temp_pixel[i + h] = temp_pixel[i];
- temp_pixel[i] = temp;
- swaps++;
- }
- }
- if (h == 1) {
- if (swaps == 0){
- break;
- }
- }else{
- h=h*10/13;
- }
- }
- //値の大きい方と小さい方の各4点を取得
- //4点の中間を閾値中心とする
- final int th_l=temp_pixel[99]+temp_pixel[98]+temp_pixel[97]+temp_pixel[96];
- final int th_h=temp_pixel[0]+temp_pixel[1]+temp_pixel[2]+temp_pixel[3];
- int th_sub=(th_h-th_l)/(4*5);//ヒステリシス(20%)
- int th=(th_h+th_l)/8;
- o_threshold.th=th;
- o_threshold.th_h=th+th_sub;//ヒステリシス付き閾値
- o_threshold.th_l=th-th_sub;//ヒステリシス付き閾値
- System.out.println(o_threshold.th+","+o_threshold.th_h+","+o_threshold.th_l);
- return;
- }
-
-
- /**
- *
- * @param image
- * @param i_marker
- * @return 切り出しに失敗した
- * @throws Exception
- */
- public boolean pickFromRaster(INyARRgbRaster image, NyARSquare i_square)throws NyARException
- {
- this._perspective_gen.setSourceRaster(image);
- i_square.imvertex[0].x=149;
- i_square.imvertex[0].y=179;
- i_square.imvertex[0].x=27;
- i_square.imvertex[0].y=96;
- i_square.imvertex[0].x=152;
- i_square.imvertex[0].y=29;
- i_square.imvertex[0].x=280;
- i_square.imvertex[0].y=72;
-
- //遠近法のパラメータを計算
- if(!this._perspective_gen.setSourceSquare(i_square.imvertex)){
- return false;
- };
-
- final INyARRgbPixelReader reader=image.getRgbPixelReader();
-
-
- TMarkerParam param=new TMarkerParam();
- MarkerPattEncoder encoder=new MarkerPattEncoder();
- //マーカパラメータを取得
- if(!detectMarkerParam(reader,param))
- {
- System.out.println("E");
- return false;
- }
- final int resolution=(param.model*2)+1;
- //Threshold検出
-
- if(!encoder.initEncoder(param.model)){
- return false;
- }
- //int i_stx,int i_sty,int size_x,int size_y,int i_resolution,int i_th,
- //this._perspective_gen.readDataBits(st_x,st_y,size_x,size_y,resolution, param.threshold, encoder);
- this._perspective_gen.readDataBits(param.index_x,param.index_y,resolution, param.threshold, encoder);
- encoder.encode();
-
- for(int i=0;i<49*4;i++){
- this.vertex_x[i]=0;
- this.vertex_y[i]=0;
- }
- for(int i=0;i<resolution*2;i++){
- for(int i2=0;i2<resolution*2;i2++){
- this.vertex_x[i*resolution*2+i2]=(int)param.index_x[i2];
- this.vertex_y[i*resolution*2+i2]=(int)param.index_y[i];
-
- }
- }
-
- System.out.println(param.model);
-/*
- //マップを作りなおす
- for(int i=0;i<size*size;i++){
- this._patdata[i]=encoder.getBit(_role_table[i])==0?0:255;
- }
-*/
-
-
- return true;
- }
- public static void main(String[] args)
- {
- try {
- double[] a=new double[10];
- int[] d={
- // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
- 0,0,0,0,0,0,0,1,5,1,2,0,0,0,1,2,5,2,1,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
- NyARSingleEdgeFinder px=new NyARSingleEdgeFinder(20,2);
- System.out.print(px.scanEdgeLeftToRight(d,0,0,a));
- System.out.print("");
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/PattPickupTest.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/PattPickupTest.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/PattPickupTest.java (revision 302)
@@ -9,17 +9,25 @@
import javax.media.Buffer;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;
+
+import java.awt.color.ColorSpace;
import java.awt.image.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Date;
+
import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.jmf.utils.*;
import jp.nyatla.nyartoolkit.nyidmarker.NyIdMarkerPickup;
import jp.nyatla.nyartoolkit.core.*;
import jp.nyatla.nyartoolkit.core.param.*;
import jp.nyatla.nyartoolkit.core.pickup.*;
-import jp.nyatla.nyartoolkit.core.raster.NyARBinRaster;
+import jp.nyatla.nyartoolkit.core.raster.*;
+import jp.nyatla.nyartoolkit.core.raster.rgb.*;
import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;
import jp.nyatla.utils.j2se.*;
import jp.nyatla.nyartoolkit.nyidmarker.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.*;

public class PattPickupTest extends Frame implements JmfCaptureListener
{
@@ -30,15 +38,15 @@
private JmfCaptureDevice _capture;

private JmfNyARRaster_RGB _capraster;
+ private int W=320;
+ private int H=240;

- private NyARSquareDetector _detector;

- protected INyARRasterFilter_RgbToBin _tobin_filter;

private NyARBinRaster _bin_raster;

private NyARSquareStack _stack = new NyARSquareStack(100);
-
+ private NyARSquareDetector_Rle detect;
public PattPickupTest() throws NyARException
{
setTitle("JmfCaptureTest");
@@ -46,19 +54,18 @@
this.setSize(640 + ins.left + ins.right, 480 + ins.top + ins.bottom);
JmfCaptureDeviceList dl = new JmfCaptureDeviceList();
this._capture = dl.getDevice(0);
- if (!this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB, 320, 240, 30.0f)) {
- if (!this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_YUV, 320, 240, 30.0f)) {
+ if (!this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB, W, H, 30.0f)) {
+ if (!this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_YUV, W, H, 30.0f)) {
throw new NyARException("キャプチャフォーマットが見つかりません。");
}
}
NyARParam ar_param = new NyARParam();
ar_param.loadARParamFromFile(PARAM_FILE);
- ar_param.changeScreenSize(320, 240);
- this._capraster = new JmfNyARRaster_RGB(320, 240, this._capture.getCaptureFormat());
+ ar_param.changeScreenSize(W, H);
+ this.detect=new NyARSquareDetector_Rle(ar_param.getDistortionFactor(),ar_param.getScreenSize());
+ this._capraster = new JmfNyARRaster_RGB(W, H, this._capture.getCaptureFormat());
this._capture.setOnCapture(this);
- this._detector = new NyARSquareDetector(ar_param.getDistortionFactor(), ar_param.getScreenSize());
- this._bin_raster = new NyARBinRaster(320, 240);
- this._tobin_filter = new NyARRasterFilter_ARToolkitThreshold(110);
+ this._bin_raster = new NyARBinRaster(W, H);
return;
}

@@ -77,13 +84,15 @@
return (int) Math.sqrt((lx1 * lx1) + (ly1 * ly1)) * (int) Math.sqrt(((lx2 * lx2) + (ly2 * ly2)));
}

+ private final String data_file = "../Data/320x240ABGR.raw";
+
private INyARColorPatt _patt1 = new NyARColorPatt_O3(16, 16);

- private INyARColorPatt _patt2 = new NyARColorPatt_Perspective(100,100);
+ private INyARColorPatt _patt2 = new NyARColorPatt_Perspective_O2(16,16,4,25);

- private NyIdMarkerPickup _patt3 = new NyIdMarkerPickup();
+ private INyARColorPatt _patt3 = new NyARColorPatt_Perspective(16,16,4,25);

- public void onUpdateBuffer(Buffer i_buffer)
+ public void draw(INyARRgbRaster i_raster)
{
try {
Insets ins = this.getInsets();
@@ -91,99 +100,91 @@

{// ピックアップ画像の表示
// 矩形抽出
- this._capraster.setBuffer(i_buffer);
- this._tobin_filter.doFilter(this._capraster, this._bin_raster);
- this._detector.detectMarker(this._bin_raster, this._stack);
+ INyARRasterFilter_RgbToBin to_binfilter= new NyARRasterFilter_ARToolkitThreshold(110,i_raster.getBufferReader().getBufferType());
+ to_binfilter.doFilter(i_raster, this._bin_raster);
+ this.detect.detectMarker(this._bin_raster, this._stack);

int max_point = 0;
NyARSquare t = null;
// ど れ に し よ う か なー
for (int i = this._stack.getLength() - 1; i >= 0; i--) {
- NyARSquare sq = (NyARSquare) this._stack.getItem(i);
+ NyARSquare sq = this._stack.getItem(i);
int wp = getSQPoint(sq);
if (wp < max_point) {
continue;
}
t = sq;
}
+// NyARSquare t=new NyARSquare();
if (t != null) {
+ BufferedImage sink=new BufferedImage(this._patt1.getWidth(),this._patt1.getHeight(),ColorSpace.TYPE_RGB);
+ BufferedImage sink2=new BufferedImage(this._patt2.getWidth(),this._patt2.getHeight(),ColorSpace.TYPE_RGB);
+/* t.imvertex[0].x=(int)483.0639377595418;
+ t.imvertex[0].y=(int)303.17616747966747;

- BufferedImageSink sink = new BufferedImageSink(this._patt1.getWidth(), this._patt1.getHeight());
- BufferedImageSink sink2 = new BufferedImageSink(this._patt2.getWidth(), this._patt2.getHeight());
-// BufferedImageSink sink3 = new BufferedImageSink(this._patt3.getWidth(), this._patt3.getHeight());
+ t.imvertex[1].x=(int)506.1019505415998;
+ t.imvertex[1].y=(int)310.5313224526344;
+
+ t.imvertex[2].x=(int)589.3605435960492;
+ t.imvertex[2].y=(int)258.46261716798523;
+
+ t.imvertex[3].x=(int)518.1385869954609;
+ t.imvertex[3].y=(int)325.1434618295405;
+*/
Graphics g1,g2,g3;
{// ARToolkit
// 一番それっぽいパターンを取得
- this._patt1.pickFromRaster(this._capraster, t);
+ this._patt1.pickFromRaster(i_raster, t);
+ Date d2 = new Date();
+ for (int i = 0; i < 10000; i++) {
+ this._patt1.pickFromRaster(i_raster, t);
+ }
+ Date d = new Date();
+ System.out.println(d.getTime() - d2.getTime());
+
+
// パターンを書く
- sink.sinkFromRaster(this._patt1);
+ NyARRasterImageIO.copy(this._patt1,sink);
g1=sink.getGraphics();
g1.setColor(Color.red);
- g1.drawLine(this._patt1.getWidth()/2,0,this._patt1.getWidth()/2,this._patt1.getHeight());
- g1.drawLine(0,this._patt1.getHeight()/2,this._patt1.getWidth(),this._patt1.getHeight()/2);
}
{// 疑似アフィン変換
// 一番それっぽいパターンを取得
- this._patt2.pickFromRaster(this._capraster, t);
+ for(int i2=0;i2<5;i2++){
+ Date d2 = new Date();
+ for (int i = 0; i < 10000; i++) {
+ this._patt2.pickFromRaster(i_raster, t);
+ }
+ Date d = new Date();
+ System.out.println(d.getTime() - d2.getTime());
// パターンを書く
- sink2.sinkFromRaster(this._patt2);
+ }
+ NyARRasterImageIO.copy(this._patt2,sink2);
g2=sink2.getGraphics();
g2.setColor(Color.red);
- g2.drawLine(this._patt1.getWidth()/2,0,this._patt1.getWidth()/2,this._patt1.getHeight());
- g2.drawLine(0,this._patt1.getHeight()/2,this._patt1.getWidth(),this._patt1.getHeight()/2);
- }
- {// IDマーカ
- NyIdMarkerPattern data =new NyIdMarkerPattern();
- NyIdMarkerParam param =new NyIdMarkerParam();
-
- // 一番それっぽいパターンを取得
- this._patt3.pickFromRaster(this._capraster, t,data,param);
- System.out.println("model="+data.model);
- System.out.println("domain="+data.ctrl_domain);
- System.out.println("maskl="+data.ctrl_mask);
- System.out.println("data= "+data.data[0]+","+data.data[1]+","+data.data[2]);
- // パターンを書く
-/* sink3.sinkFromRaster(this._patt3);
- g3=sink.getGraphics();
- g3.setColor(Color.red);
- g2.drawRect(10,10,10,10);
- g2.drawRect(80,10,10,10);
- g2.drawRect(10,80,10,10);
- g2.drawRect(80,80,10,10);*/
-// g2.drawLine(this._patt3.sv[0]-1,this._patt3.sv[1],this._patt3.sv[0]+1,this._patt3.sv[1]);
-// g2.drawLine(this._patt3.sv[0],this._patt3.sv[1]-1,this._patt3.sv[0],this._patt3.sv[1]+1);
-// g2.drawLine(this._patt3.sv[2]-1,this._patt3.sv[3],this._patt3.sv[2]+1,this._patt3.sv[3]);
-// g2.drawLine(this._patt3.sv[2],this._patt3.sv[3]-1,this._patt3.sv[2],this._patt3.sv[3]+1);
-
- BufferedImage img=new BufferedImage(45,256, BufferedImage.TYPE_INT_RGB);
+ this._patt3.pickFromRaster(i_raster, t);
+ {//比較
+ int[] p2=(int[])this._patt2.getBufferReader().getBuffer();
+ int[] p3=(int[])this._patt3.getBufferReader().getBuffer();
+ for(int i=0;i<this._patt2.getHeight()*this._patt2.getWidth();i++){
+ if(p2[i]!=p3[i]){
+ System.out.print(i+",");
+ }
+ }
+ }

- g.drawImage(img, ins.left, ins.top+240,45,256, null);
-/*
- g2.setColor(Color.blue);
- for (int i = 0; i < 225*4; i++) {
- g2.drawRect(this._patt3.vertex_x[i]-1,this._patt3.vertex_y[i]-1, 2, 2);
- }
-*/ g2.setColor(Color.red);
}
g.drawImage(sink, ins.left + 320, ins.top, 128, 128, null);
- g.drawImage(sink2, ins.left + 320, ins.top + 128, 400, 400, null);
+ g.drawImage(sink2, ins.left + 320, ins.top + 128, 128, 128, null);
// g.drawImage(sink3, ins.left + 100, ins.top + 240, this._patt3.getWidth() * 10, this._patt3.getHeight() * 10, null);
}

{// 撮影画像
- BufferToImage b2i = new BufferToImage((VideoFormat) i_buffer.getFormat());
- Image img = b2i.createImage(i_buffer);
- g.drawImage(img, ins.left, ins.top, this);
- g.setColor(Color.blue);
+ BufferedImage sink=new BufferedImage(i_raster.getWidth(),i_raster.getHeight(),ColorSpace.TYPE_RGB);
+ NyARRasterImageIO.copy(i_raster, sink);
+ g.drawImage(sink, ins.left, ins.top, this);
+ }

-
- }
- /*
- * { //輪郭パターン NyARSquare s=new NyARSquare(); for(int i=0;i<4;i++){ s.imvertex[i].x=(int)t.sqvertex[i].x; s.imvertex[i].y=(int)t.sqvertex[i].y; }
- * //一番それっぽいパターンを取得 this._patt1.pickFromRaster(this._capraster,s); //パターンを書く BufferedImageSink sink=new
- * BufferedImageSink(this._patt1.getWidth(),this._patt1.getHeight()); sink.sinkFromRaster(this._patt1);
- * g.drawImage(sink,ins.left+320,ins.top+128,128,128,null); }
- */
{// 信号取得テスト

}
@@ -192,7 +193,20 @@
e.printStackTrace();
}
}
+ public void onUpdateBuffer(Buffer i_buffer)
+ {
+ try {

+ {// ピックアップ画像の表示
+ // 矩形抽出
+ this._capraster.setBuffer(i_buffer);
+ draw(this._capraster);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
public void startCapture()
{
try {
@@ -201,13 +215,29 @@
e.printStackTrace();
}
}
+ public void startImage()
+ {
+ try {
+ // 試験イメージの読み出し(320x240 BGRAのRAWデータ)
+ File f = new File(data_file);
+ FileInputStream fs = new FileInputStream(data_file);
+ byte[] buf = new byte[(int) f.length()*4];
+ fs.read(buf);
+ INyARRgbRaster ra = NyARRgbRaster_BGRA.wrap(buf, W, H);
+ draw(ra);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }

public static void main(String[] args)
{
try {
PattPickupTest mainwin = new PattPickupTest();
mainwin.setVisible(true);
- mainwin.startCapture();
+ //mainwin.startCapture();
+ mainwin.startImage();
} catch (Exception e) {
e.printStackTrace();
}
Index: D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/LabelingCamera.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/LabelingCamera.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/LabelingCamera.java (revision 302)
@@ -16,8 +16,11 @@

import java.awt.*;

-import jp.nyatla.nyartoolkit.core.INyARSquareDetector;
import jp.nyatla.nyartoolkit.core.labeling.*;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabel;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabelStack;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabeling_ARToolKit;
import jp.nyatla.nyartoolkit.core.match.*;
import jp.nyatla.nyartoolkit.core.param.*;
import jp.nyatla.nyartoolkit.core.pca2d.INyARPca2d;
@@ -33,6 +36,10 @@
import jp.nyatla.utils.NyObjectStack;
import jp.nyatla.utils.j2se.LabelingBufferdImage;
import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.INyARSquareDetector;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARVertexCounter;
import jp.nyatla.nyartoolkit.core.transmat.*;
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix22;
@@ -361,11 +368,11 @@
}

final NyARLabelingLabelStack stack = limage.getLabelStack();
- final NyARLabelingLabel[] labels = (NyARLabelingLabel[]) stack.getArray();
-
// ラベルを大きい順に整列
stack.sortByArea();
+ final NyARLabelingLabel[] labels = stack.getArray();

+
// デカいラベルを読み飛ばし
int i;
for (i = 0; i < label_num; i++) {
@@ -464,7 +471,7 @@
if(number_of_edge<3){
return;
}
- NyARSquare[] sa=(NyARSquare[])i_square_stack.getArray();
+ NyARSquare[] sa=i_square_stack.getArray();
for(int i=0;i<number_of_edge;i++)
{
for(int i2=i+1;i2<number_of_edge;i2++)
@@ -864,7 +871,7 @@
labeling.attachDestination(limage);
labeling.labeling(_binraster1);
this._bimg.drawImage(this._gsraster1);
- NyARLabelingLabel[] labels = (NyARLabelingLabel[]) limage.getLabelStack().getArray();
+ NyARLabelingLabel[] labels = limage.getLabelStack().getArray();

NyARSquareStack stack = new NyARSquareStack(100);
NyARQRCodeDetector detect = new NyARQRCodeDetector(ap.getDistortionFactor(), new NyARIntSize(320,240));
Index: D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/OptimizeView.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/OptimizeView.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/OptimizeView.java (revision 302)
@@ -0,0 +1,288 @@
+/*
+ * PROJECT: NyARToolkit JOGL sample program.
+ * --------------------------------------------------------------------------------
+ * The MIT License
+ * Copyright (c) 2008 nyatla
+ * airmail(at)ebony.plala.or.jp
+ * http://nyatla.jp/nyartoolkit/
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+package jp.nyatla.nyartoolkit.dev;
+
+import java.awt.event.*;
+import java.awt.*;
+import javax.media.Buffer;
+import javax.media.opengl.*;
+import com.sun.opengl.util.*;
+import jp.nyatla.nyartoolkit.*;
+import jp.nyatla.nyartoolkit.core.*;
+import jp.nyatla.nyartoolkit.core.param.*;
+import jp.nyatla.nyartoolkit.core.transmat.*;
+import jp.nyatla.nyartoolkit.detector.*;
+import jp.nyatla.nyartoolkit.jmf.utils.*;
+import jp.nyatla.nyartoolkit.jogl.utils.*;
+class Program implements JmfCaptureListener
+{
+ private OptimizeView _view1;
+ private OptimizeView _view2;
+ public Object _sync_object=new Object();
+ public NyARParam _ar_param;
+ public NyARCode _ar_code;
+ private final static int SCREEN_X = 640;
+ private final static int SCREEN_Y = 480;
+ private JmfCaptureDevice _capture;
+ public GLNyARRaster_RGB _cap_image;
+ public Program(NyARParam i_param, NyARCode i_ar_code) throws NyARException
+ {
+ // キャプチャの準備
+ JmfCaptureDeviceList devlist = new JmfCaptureDeviceList();
+ this._capture = devlist.getDevice(0);
+ if (!this._capture.setCaptureFormat(SCREEN_X, SCREEN_Y, 30.0f)) {
+ throw new NyARException();
+ }
+ this._ar_param=i_param;
+ this._ar_code=i_ar_code;
+ this._capture.setOnCapture(this);
+ // GL対応のRGBラスタオブジェクト
+ this._cap_image = new GLNyARRaster_RGB(i_param, this._capture.getCaptureFormat());
+ this._view1=new OptimizeView(this,NyARSingleDetectMarker.PF_NYARTOOLKIT);
+ this._view2=new OptimizeView(this,NyARSingleDetectMarker.PF_NYARTOOLKIT_ARTOOLKIT_FITTING);
+ this._capture.start();
+ return;
+ }
+ public void onUpdateBuffer(Buffer i_buffer)
+ {
+ try {
+ synchronized (this._sync_object) {
+ this._cap_image.setBuffer(i_buffer);
+ this._view1.updateCapture(this._cap_image);
+ this._view2.updateCapture(this._cap_image);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ //GL API
+ void glDrawCube(GL i_gl)
+ {
+ // Colour cube data.
+ int polyList = 0;
+ float fSize = 0.5f;// マーカーサイズに対して0.5倍なので、4cmの立方体
+ int f, i;
+ float[][] cube_vertices = new float[][] { { 1.0f, 1.0f, 1.0f }, { 1.0f, -1.0f, 1.0f }, { -1.0f, -1.0f, 1.0f }, { -1.0f, 1.0f, 1.0f }, { 1.0f, 1.0f, -1.0f }, { 1.0f, -1.0f, -1.0f }, { -1.0f, -1.0f, -1.0f }, { -1.0f, 1.0f, -1.0f } };
+ float[][] cube_vertex_colors = new float[][] { { 1.0f, 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 1.0f }, { 1.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } };
+ int cube_num_faces = 6;
+ short[][] cube_faces = new short[][] { { 3, 2, 1, 0 }, { 2, 3, 7, 6 }, { 0, 1, 5, 4 }, { 3, 0, 4, 7 }, { 1, 2, 6, 5 }, { 4, 5, 6, 7 } };
+
+ if (polyList == 0) {
+ polyList = i_gl.glGenLists(1);
+ i_gl.glNewList(polyList, GL.GL_COMPILE);
+ i_gl.glBegin(GL.GL_QUADS);
+ for (f = 0; f < cube_num_faces; f++)
+ for (i = 0; i < 4; i++) {
+ i_gl.glColor3f(cube_vertex_colors[cube_faces[f][i]][0], cube_vertex_colors[cube_faces[f][i]][1], cube_vertex_colors[cube_faces[f][i]][2]);
+ i_gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);
+ }
+ i_gl.glEnd();
+ i_gl.glColor3f(0.0f, 0.0f, 0.0f);
+ for (f = 0; f < cube_num_faces; f++) {
+ i_gl.glBegin(GL.GL_LINE_LOOP);
+ for (i = 0; i < 4; i++)
+ i_gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);
+ i_gl.glEnd();
+ }
+ i_gl.glEndList();
+ }
+
+ i_gl.glPushMatrix(); // Save world coordinate system.
+ i_gl.glTranslatef(0.0f, 0.0f, 0.5f); // Place base of cube on marker surface.
+ i_gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f); // Rotate about z axis.
+ i_gl.glDisable(GL.GL_LIGHTING); // Just use colours.
+ i_gl.glCallList(polyList); // Draw the cube.
+ i_gl.glPopMatrix(); // Restore world coordinate system.
+ return;
+ }
+
+}
+/**
+ * simpleLiteと同じようなテストプログラム 出来る限りARToolKitのサンプルと似せて作ってあります。 最も一致する"Hiro"マーカーを一つ選択して、その上に立方体を表示します。
+ *
+ */
+public class OptimizeView implements GLEventListener
+{
+ private final static int SCREEN_X = 640;
+
+ private final static int SCREEN_Y = 480;
+
+ private Animator _animator;
+
+ private Program _parent;
+
+
+// private JmfCaptureDevice _capture;
+
+ private GL _gl;
+ private NyARGLUtil _glnya;
+
+ // NyARToolkit関係
+ private NyARSingleDetectMarker _nya;
+ private NyARParam _ar_param;
+
+ private double[] _camera_projection = new double[16];
+
+
+ public OptimizeView(Program i_program,int i_pf) throws NyARException
+ {
+ this._parent=i_program;
+ this._ar_param = i_program._ar_param;
+
+ Frame frame = new Frame("["+i_pf+"]");
+
+ // NyARToolkitの準備
+ this._nya = new NyARSingleDetectMarker(this._ar_param, i_program._ar_code, 80.0,i_program._cap_image.getBufferReader().getBufferType(),i_pf);
+ this._nya.setContinueMode(false);// ここをtrueにすると、transMatContinueモード(History計算)になります。
+
+ // 3Dを描画するコンポーネント
+ GLCanvas canvas = new GLCanvas();
+ frame.add(canvas);
+ canvas.addGLEventListener(this);
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e)
+ {
+ System.exit(0);
+ }
+ });
+
+ frame.setVisible(true);
+ Insets ins = frame.getInsets();
+ frame.setSize(SCREEN_X + ins.left + ins.right, SCREEN_Y + ins.top + ins.bottom);
+ canvas.setBounds(ins.left, ins.top, SCREEN_X, SCREEN_Y);
+ }
+
+ public void init(GLAutoDrawable drawable)
+ {
+ this._gl = drawable.getGL();
+ this._gl.glEnable(GL.GL_DEPTH_TEST);
+ this._gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ // NyARToolkitの準備
+ try {
+ // NyARToolkit用の支援クラス
+ _glnya = new NyARGLUtil(_gl);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ // カメラパラメータの計算
+ this._glnya.toCameraFrustumRH(this._ar_param,this._camera_projection);
+ this._animator = new Animator(drawable);
+ this._animator.start();
+ return;
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
+ {
+ _gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ _gl.glViewport(0, 0, width, height);
+
+ // 視体積の設定
+ _gl.glMatrixMode(GL.GL_PROJECTION);
+ _gl.glLoadIdentity();
+ // 見る位置
+ _gl.glMatrixMode(GL.GL_MODELVIEW);
+ _gl.glLoadIdentity();
+ }
+
+ private boolean _is_marker_exist=false;
+ private NyARTransMatResult __display_transmat_result = new NyARTransMatResult();
+
+ private double[] __display_wk = new double[16];
+
+ public void display(GLAutoDrawable drawable)
+ {
+ NyARTransMatResult transmat_result = __display_transmat_result;
+ if (!this._parent._cap_image.hasData()) {
+ return;
+ }
+ // 背景を書く
+ this._gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
+ this._glnya.drawBackGround(this._parent._cap_image, 1.0);
+ try{
+ synchronized(this._parent._sync_object){
+ // マーカーがあれば、立方体を描画
+ if (this._is_marker_exist){
+ // マーカーの一致度を調査するならば、ここでnya.getConfidence()で一致度を調べて下さい。
+ // Projection transformation.
+ _gl.glMatrixMode(GL.GL_PROJECTION);
+ _gl.glLoadMatrixd(_camera_projection, 0);
+ _gl.glMatrixMode(GL.GL_MODELVIEW);
+ // Viewing transformation.
+ _gl.glLoadIdentity();
+ // 変換行列を取得
+ _nya.getTransmationMatrix(transmat_result);
+ // 変換行列をOpenGL形式に変換
+ _glnya.toCameraViewRH(transmat_result, __display_wk);
+ _gl.glLoadMatrixd(__display_wk, 0);
+
+ // All other lighting and geometry goes here.
+ this._parent.glDrawCube(_gl);
+ }
+ }
+ Thread.sleep(1);// タスク実行権限を一旦渡す
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ }
+
+ public void updateCapture(GLNyARRaster_RGB i_img)
+ {
+ try {
+ synchronized (this._parent._sync_object) {
+ this._is_marker_exist =this._nya.detectMarkerLite(i_img, 110);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged)
+ {
+ }
+
+ private final static String CARCODE_FILE = "../Data/patt.hiro";
+
+ private final static String PARAM_FILE = "../Data/camera_para.dat";
+
+ public static void main(String[] args)
+ {
+ try {
+ NyARParam param = new NyARParam();
+ param.loadARParamFromFile(PARAM_FILE);
+ param.changeScreenSize(SCREEN_X, SCREEN_Y);
+
+ NyARCode code = new NyARCode(16, 16);
+ code.loadARPattFromFile(CARCODE_FILE);
+
+ new Program(param, code);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return;
+ }
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/LabelingTest.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/LabelingTest.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/LabelingTest.java (revision 302)
@@ -5,45 +5,378 @@
package jp.nyatla.nyartoolkit.dev;

import java.awt.Frame;
+import java.awt.*;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;

+import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.raster.*;
import jp.nyatla.nyartoolkit.core.raster.rgb.NyARRgbRaster_BGRA;
-import jp.nyatla.nyartoolkit.core.labeling.*;
+import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;

-import jp.nyatla.nyartoolkit.core2.rasteranalyzer.*;
+
import jp.nyatla.utils.j2se.*;

public class LabelingTest extends Frame
{
- private final String data_file ="../Data/320x240ABGR.raw";
- public void drawImage() throws Exception
- {
- File f=new File(data_file);
- FileInputStream fs=new FileInputStream(data_file);
- byte[] buf=new byte[(int)f.length()];
- fs.read(buf);
- NyARRgbRaster_BGRA ra=NyARRgbRaster_BGRA.wrap(buf, 320, 240);
- NyARLabelingImage limage=new NyARLabelingImage(320,240);
- INyARLabeling labeling=new NyARLabeling_ARToolKit();
-// INyARLabeling labeling=new NyLineLabeling();
- INyARRasterReaderFactory rf=new NyARRasterReaderFactory_RgbTotal();
- labeling.attachDestination(limage);
- labeling.labeling(rf.createReader(ra));
- LabelingBufferdImage img=new LabelingBufferdImage(320,240,LabelingBufferdImage.COLOR_125_COLOR);
- img.setLabelingImage(limage);
- this.getGraphics().drawImage(img, 32,32,this);
- }
- public static void main(String[] args)
- {
- try{
- LabelingTest app=new LabelingTest();
- app.setVisible(true);
- app.setBounds(0,0,640,480);
- app.drawImage();
- }catch(Exception e){
- e.printStackTrace();
+ private final String data_file = "../Data/320x240ABGR.raw";
+
+ final int W=10;
+ final int H=10;
+ public void drawImage() throws Exception
+ {
+ File f = new File(data_file);
+ FileInputStream fs = new FileInputStream(data_file);
+ byte[] buf = new byte[(int) f.length()];
+ fs.read(buf);
+ NyARRgbRaster_BGRA ra = NyARRgbRaster_BGRA.wrap(buf, W, H);
+ // 二値化
+ NyARRasterFilter_ARToolkitThreshold filter = new NyARRasterFilter_ARToolkitThreshold(110, ra.getBufferReader().getBufferType());
+ NyARBinRaster bin = new NyARBinRaster(W,240);
+ filter.doFilter(ra, bin);
+ int[] t = (int[]) bin.getBufferReader().getBuffer();
+ int[] s = {
+ 1,1,1,1,1,1,1,1,1,1,
+
+ 1,0,0,0,0,1,0,1,1,1,
+ 1,0,1,1,0,1,0,1,1,1,
+ 1,1,1,1,1,0,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1, 0};
+ System.arraycopy(s, 0, t, 0, 10*10);
+ NyARRasterImageIO sink = new NyARRasterImageIO(W, H);
+ RleImage rle = new RleImage(bin.getWidth(),bin.getHeight());
+ RleLabelingTable table=createRelTable(rle,bin,sink);
+ for(int i=0;;i++){
+ int nof=i%table.number_of_fragment;
+ if(table._fragment_area[nof]==0){
+ continue;
+ }
+ drawLabelingImage(nof,rle,table,bin,sink);
+ Graphics g;
+ g=this.getGraphics();
+ g.drawImage(sink, 100, 100,100,100, this);
+ Thread.sleep(500);
+ }
}
- }
+ public void drawLabelingImage(int id,RleImage rle, RleLabelingTable i_table,NyARBinRaster i_source,NyARRasterImageIO i_img)
+ {
+// RleImage rle = new RleImage(i_source.getWidth(),i_source.getHeight());
+// i_table.labeling(rle,0,10);
+ int p=0;
+ for(int i=0;i<H;i++){
+ for(int i2=0;i2<W;i2++){
+ i_img.setRGB(i2,i,0xffffff);
+ }
+ for(int i2=0;i2<rle.row_length[i];i2++){
+ for(int i3=rle.rle_img_l[rle.row_index[i]+i2];i3<rle.rle_img_r[rle.row_index[i]+i2];i3++)
+ {
+ int c=0x0000ff;
+ int tid=i_table._fragment_id[i_table.rle_img_id[p]];
+ if(tid==id){
+ c=0x00ff00;
+ }
+ i_img.setRGB(i3,i,c);
+ }
+ p++;
+ }
+ }
+
+ i_img.setRGB(i_table._flagment_entry_x[id],i_table._flagment_entry_y[id],0xff0000);
+// i_img.setRGB(i_table._flagment_entry_x[id]+1,i_table._flagment_entry_y[id],0xff0000);
+// i_img.setRGB(i_table._flagment_entry_x[id],i_table._flagment_entry_y[id]+1,0xff0000);
+// i_img.setRGB(i_table._flagment_entry_x[id]+1,i_table._flagment_entry_y[id]+1,0xff0000);
+ }
+
+ public RleLabelingTable createRelTable(RleImage rle,NyARBinRaster i_source,NyARRasterImageIO i_img)
+ {
+ // RELイメージの作成
+ rle.toRel(i_source);
+ // 1行目のテーブル登録
+ RleLabelingTable table = new RleLabelingTable(10000);
+ table.labeling(rle,0,H);
+ return table;
+ }
+
+ public LabelingTest() throws NyARException
+ {
+ this.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e)
+ {
+ System.exit(0);
+ }
+ });
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ LabelingTest app = new LabelingTest();
+ app.setVisible(true);
+ app.setBounds(0, 0, 640, 480);
+ app.drawImage();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ class RleImage
+ {
+ int _width;
+
+ int _height;
+
+ // RELデータ
+ short[] rle_img_l;// RELのフラグメント左
+
+ short[] rle_img_r;// RELのフラグメント右
+
+ // Rowデータ
+ int[] row_index;
+
+ short[] row_length;
+
+ int rle_buf_size;
+
+ public RleImage(int i_width, int i_height)
+ {
+ final int size = i_width * i_height / 2;
+ // 1/2に圧縮できることを想定。
+ this.rle_img_l = new short[size]; // RELのフラグメント長
+ this.rle_img_r = new short[size]; // RELの開始位置
+ this.rle_buf_size = size;
+
+ this.row_index = new int[i_height];
+ this.row_length = new short[i_height];
+ this._width = i_width;
+ this._height = i_height;
+ return;
+ }
+
+ /**
+ * binラスタからRELに変換する
+ *
+ * @param i_bin_raster
+ */
+ public void toRel(NyARBinRaster i_bin_raster)
+ {
+ final int width = this._width;
+ final int height = this._height;
+ int[] in_buf = (int[]) i_bin_raster.getBufferReader().getBuffer();
+
+ short current = 0;
+ short r = -1;
+ for (int y = 0; y < height; y++) {
+ this.row_index[y] = current;
+ // 行確定開始
+ int row_index = y * width;
+ int x = row_index;
+ final int right_edge = (y + 1) * width - 1;
+ while (x < right_edge) {
+ // 暗点(0)スキャン
+ if (in_buf[x] != 0) {
+ x++;
+ continue;
+ }
+ // 暗点発見→暗点長を調べる
+ r = (short) (x - row_index);
+ this.rle_img_l[current] = r;
+ r++;// 暗点+1
+ x++;
+ while (x < right_edge) {
+ if (in_buf[x] != 0) {
+ // 明点(1)→暗点(0)配列終了>登録
+ this.rle_img_r[current] = r;
+ current++;
+ x++;// 次点の確認。
+ r = -1;// 右端の位置を0に。
+ break;
+ } else {
+ // 暗点(0)長追加
+ r++;
+ x++;
+ }
+ }
+ }
+ // 最後の1点だけ判定方法が少し違うの。
+ if (in_buf[x] != 0) {
+ // 明点→rカウント中なら暗点配列終了>登録
+ if (r >= 0) {
+ this.rle_img_r[current] = r;
+ current++;
+ }
+ } else {
+ // 暗点→カウント中でなければl1で追加
+ if (r >= 0) {
+ this.rle_img_r[current] = (short) (x + 1);
+ } else {
+ // 最後の1点の場合
+ this.rle_img_l[current] = (short) (width - 1);
+ this.rle_img_r[current] = (short) (width);
+ }
+ current++;
+ }
+ // 行確定
+ this.row_length[y] = (short) (current - this.row_index[y]);
+ }
+ }
+
+ public void fromRel(NyARBinRaster i_bin_raster)
+ {
+
+ }
+ }
+
+ // RleImageをラベリングする。
+ class RleLabelingTable
+ {
+ short[] rle_img_id;
+
+ short[] _fragment_id; // フラグメントラベルのインデクス
+
+ int[] _fragment_area; // フラグメントラベルの領域数
+
+ int[] _fragment_pos_x; // フラグメントラベルの位置
+
+ int[] _fragment_pos_y; // フラグメントラベルの位置
+
+ short[] _flagment_entry_x; // フラグメントラベルの位置
+
+ short[] _flagment_entry_y; // フラグメントラベルの位置
+
+ short number_of_fragment; // 現在のフラグメントの数
+
+ public RleLabelingTable(int i_max_fragment)
+ {
+ this.rle_img_id = new short[i_max_fragment];
+ this._fragment_id = new short[i_max_fragment];
+ this._fragment_area = new int[i_max_fragment];
+ this._fragment_pos_x = new int[i_max_fragment];
+ this._fragment_pos_y = new int[i_max_fragment];
+ this._flagment_entry_x = new short[i_max_fragment];
+ this._flagment_entry_y = new short[i_max_fragment];
+ }
+
+ private void addFragment(RleImage i_rel_img, short i_nof, int i_row_index, int i_rel_index)
+ {
+ this.rle_img_id[i_rel_index] = i_nof;// REL毎の固有ID
+ this._fragment_id[i_nof] = i_nof;
+ this._flagment_entry_x[i_nof] = i_rel_img.rle_img_l[i_rel_index];
+ this._flagment_entry_y[i_nof] = (short) i_row_index;
+ this._fragment_area[i_nof] = i_rel_img.rle_img_r[i_rel_index] - i_rel_img.rle_img_l[i_rel_index];
+ return;
+ }
+
+
+
+ // 指定した行のフラグメントをマージします。
+ public void labeling(RleImage i_rel_img, int i_top, int i_bottom)
+ {
+ short[] rle_l = i_rel_img.rle_img_l;
+ short[] rle_r = i_rel_img.rle_img_r;
+ short nof = this.number_of_fragment;
+ // 初段登録
+ int index = i_rel_img.row_index[i_top];
+ int eol = i_rel_img.row_length[i_top];
+ for (int i = index; i < index + eol; i++) {
+ // フラグメントID=フラグメント初期値、POS=Y値、RELインデクス=行
+ addFragment(i_rel_img, nof, i_top, i);
+ nof++;
+ // nofの最大値チェック
+ }
+ // 次段結合
+ for (int y = i_top+1; y < i_bottom; y++) {
+ int index_prev = i_rel_img.row_index[y - 1];
+ int eol_prev = index_prev + i_rel_img.row_length[y - 1];
+ index = i_rel_img.row_index[y];
+ eol = index + i_rel_img.row_length[y];
+
+ SCAN_CUR:for (int i = index; i < eol; i++) {
+ // index_prev,len_prevの位置を調整する
+ short id = -1;
+ //チェックすべきprevがあれば確認
+ SCAN_PREV: while (index_prev < eol_prev) {
+ if (rle_l[i] - rle_r[index_prev] > 0) {// 0なら8方位ラベリング
+ // prevがcurの左方にある→次のフラグメントを探索
+ index_prev++;
+ continue;
+ } else if (rle_l[index_prev] - rle_r[i] > 0) {// 0なら8方位ラベリングになる
+ // prevがcur右方にある→独立フラグメント
+ addFragment(i_rel_img, nof, y, i);
+ nof++;
+ // 次のindexをしらべる
+ continue SCAN_CUR;
+ }
+ // 結合対象->prevのIDをコピーして、対象フラグメントの情報を更新
+ id = this._fragment_id[this.rle_img_id[index_prev]];
+ this.rle_img_id[i] = id;
+ this._fragment_area[id] += (rle_r[i] - rle_l[i]);
+ // エントリポイントの情報をコピー
+ this._flagment_entry_x[id] = this._flagment_entry_x[this.rle_img_id[index_prev]];
+ this._flagment_entry_y[id] = this._flagment_entry_y[this.rle_img_id[index_prev]];
+ //多重リンクの確認
+
+ index_prev++;
+ while (index_prev < eol_prev) {
+ if (rle_l[i] - rle_r[index_prev] > 0) {// 0なら8方位ラベリング
+ // prevがcurの左方にある→prevはcurに連結していない。
+ break SCAN_PREV;
+ } else if (rle_l[index_prev] - rle_r[i] > 0) {// 0なら8方位ラベリングになる
+ // prevがcurの右方にある→prevはcurに連結していない。
+ index_prev--;
+ continue SCAN_CUR;
+ }
+ // prevとcurは連結している。
+ final short prev_id = this.rle_img_id[index_prev];
+ if (id != prev_id) {
+ this._fragment_area[id] += this._fragment_area[prev_id];
+ this._fragment_area[prev_id] = 0;
+ // 結合対象->現在のidをインデクスにセット
+ this._fragment_id[prev_id]=id;
+ // エントリポイントを訂正
+ if (this._flagment_entry_y[id] > this._flagment_entry_y[prev_id]) {
+ // 現在のエントリポイントの方が下にある。(何もしない)
+ }
+ if (this._flagment_entry_y[id] < this._flagment_entry_y[prev_id]) {
+ // 現在のエントリポイントの方が上にある。(エントリポイントの交換)
+ this._flagment_entry_y[id] = this._flagment_entry_y[prev_id];
+ this._flagment_entry_x[id] = this._flagment_entry_x[prev_id];
+ } else {
+ // 水平方向で小さい方がエントリポイント。
+ if (this._flagment_entry_x[id] > this._flagment_entry_x[prev_id]) {
+ this._flagment_entry_y[id] = this._flagment_entry_y[prev_id];
+ this._flagment_entry_x[id] = this._flagment_entry_x[prev_id];
+ }
+ }
+ }
+ index_prev++;
+ }
+ index_prev--;
+ break;
+ }
+ // curにidが割り当てられたかを確認
+ // 右端独立フラグメントを追加
+ if (id < 0) {
+ addFragment(i_rel_img, nof, y, i);
+ nof++;
+ }
+
+ }
+ }
+ // フラグメントの数を更新
+ this.number_of_fragment = nof;
+ }
+ }
}
+
+// REL圧縮配列を作成
+// REL結合
+// 面積計算
+// 参照インデクス化
+// ラベルイメージ化
Index: D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/NyARColorPatt_DiagonalRatio.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/NyARColorPatt_DiagonalRatio.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/test/jp/nyatla/nyartoolkit/dev/NyARColorPatt_DiagonalRatio.java (revision 302)
@@ -27,9 +27,9 @@


import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.NyARSquare;
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
import jp.nyatla.nyartoolkit.core.rasterreader.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.core.types.matrix.*;
import jp.nyatla.nyartoolkit.core.pickup.*;
Index: D:/project.sorceforge/NyARToolkit/trunk/LICENCE.txt
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/LICENCE.txt (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/LICENCE.txt (revision 302)
@@ -1,10 +1,10 @@
ARToolkit Java class library NyARToolkit.
-Copyright (C)2008 R.Iizuka
+Copyright (C)2008-2009 Ryo Iizuka

-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -12,24 +12,22 @@
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+along with this program. If not, see <http://www.gnu.org/licenses/>.

+


Java版 ARToolkit クラスライブラリ NyARToolkit
-Copyright (C)2008 R.Iizuka
+Copyright (C)2008-2009 Ryo Iizuka

-このプログラムはフリーソフトウェアです。あなたはこれを、フリーソフトウェ
-ア財団によって発行された GNU 一般公衆利用許諾契約書(バージョン2か、希
-望によってはそれ以降のバージョンのうちどれか)の定める条件の下で再頒布
-または改変することができます。
+このプログラムはフリーソフトウェアです。あなたはこれを、フリーソフトウェア
+財団によって発行されたGNU 一般公衆利用許諾書(バージョン3か、それ以降のバー
+ジョンのうちどれか)が定める条件の下で再頒布または改変 することができます。

-このプログラムは有用であることを願って頒布されますが、*全くの無保証*
-です。商業可能性の保証や特定の目的への適合性は、言外に示されたものも含
-め全く存在しません。詳しくはGNU 一般公衆利用許諾契約書をご覧ください。
-
-あなたはこのプログラムと共に、GNU 一般公衆利用許諾契約書の複製物を一部
-受け取ったはずです。もし受け取っていなければ、フリーソフトウェア財団ま
-で請求してください(宛先は the Free Software Foundation, Inc., 59
-Temple Place, Suite 330, Boston, MA 02111-1307 USA)。
\ No newline at end of file
+このプログラムは有用であることを願って頒布されますが、*全くの無保証 *です。
+商業可能性の保証や特定目的への適合性は、言外に示されたものも 含め、全く存
+在しません。詳しくはGNU 一般公衆利用許諾書をご覧ください。
+
+あなたはこのプログラムと共に、GNU 一般公衆利用許諾書のコピーを一部受け取って
+いるはずです。もし受け取っていなければ、<http://www.gnu.org/licenses/>
+ご覧ください。
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/qt/jp/nyatla/nyartoolkit/qt/sample/NyarToolkitLinkTest.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/qt/jp/nyatla/nyartoolkit/qt/sample/NyarToolkitLinkTest.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/qt/jp/nyatla/nyartoolkit/qt/sample/NyarToolkitLinkTest.java (revision 302)
@@ -68,10 +68,10 @@
NyARCode ar_code = new NyARCode(16, 16);
ar_param.loadARParamFromFile(PARAM_FILE);
ar_param.changeScreenSize(320, 240);
- nya = new NyARSingleDetectMarker(ar_param, ar_code, 80.0);
+ raster = new QtNyARRaster_RGB(320, 240);
+ nya = new NyARSingleDetectMarker(ar_param, ar_code, 80.0,raster.getBufferReader().getBufferType());
ar_code.loadARPattFromFile(CARCODE_FILE);
//キャプチャイメージ用のラスタを準備
- raster = new QtNyARRaster_RGB(320, 240);
}

public void onUpdateBuffer(byte[] pixels)
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/SingleARMarker.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/SingleARMarker.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/SingleARMarker.java (revision 302)
@@ -0,0 +1,298 @@
+/*
+ * PROJECT: NyARToolkit JOGL sample program.
+ * --------------------------------------------------------------------------------
+ * The MIT License
+ * Copyright (c) 2008 nyatla
+ * airmail(at)ebony.plala.or.jp
+ * http://nyatla.jp/nyartoolkit/
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+package jp.nyatla.nyartoolkit.jogl.sample;
+
+
+import java.awt.event.*;
+import java.awt.*;
+import java.util.Date;
+
+import javax.media.Buffer;
+import javax.media.opengl.*;
+
+import com.sun.opengl.util.*;
+import com.sun.opengl.util.j2d.*;
+import jp.nyatla.nyartoolkit.*;
+import jp.nyatla.nyartoolkit.core.*;
+import jp.nyatla.nyartoolkit.core.param.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.transmat.*;
+import jp.nyatla.nyartoolkit.jmf.utils.*;
+import jp.nyatla.nyartoolkit.jogl.utils.*;
+import jp.nyatla.nyartoolkit.processor.*;
+
+/*
+
+
+*/
+
+
+public class SingleARMarker implements GLEventListener, JmfCaptureListener
+{
+ class TextPanel
+ {
+ private TextRenderer _tr;
+ public TextPanel(int i_size)
+ {
+ this._tr=new TextRenderer(new Font("SansSerif", Font.BOLD, 36));
+
+ }
+ public void draw(String i_str,float i_scale)
+ {
+ this._tr.begin3DRendering();
+ this._tr.setColor(1.0f, 0.2f, 0.2f, 0.8f);
+ this._tr.draw3D(i_str, 0f,0f,0f,i_scale);
+ this._tr.end3DRendering();
+ return;
+ }
+ }
+ /**
+ * 1個のRawBit-Idマーカを認識するロジッククラス。
+ * detectMarker関数の呼び出しに同期して、transmatとcurrent_idパラメタを更新します。
+ *
+ *
+ */
+ class MarkerProcessor extends SingleARMarkerProcesser
+ {
+ private Object _sync_object=new Object();
+ public NyARTransMatResult transmat=null;
+ public int current_code=-1;
+
+ public MarkerProcessor(NyARParam i_cparam,int i_raster_format) throws NyARException
+ {
+ //アプリケーションフレームワークの初期化
+ super();
+ initInstance(i_cparam,i_raster_format);
+ return;
+ }
+ protected void onEnterHandler(int i_code)
+ {
+ synchronized(this._sync_object){
+ current_code=i_code;
+ }
+ }
+ protected void onLeaveHandler()
+ {
+ synchronized(this._sync_object){
+ current_code=-1;
+ this.transmat=null;
+ }
+ return;
+ }
+
+ protected void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result)
+ {
+ synchronized(this._sync_object){
+ this.transmat=result;
+ }
+ }
+ }
+
+ private final String CARCODE_FILE1 = "../../Data/patt.hiro";
+
+
+ private Animator _animator;
+ private GLNyARRaster_RGB _cap_image;
+ private JmfCaptureDevice _capture;
+
+ private GL _gl;
+ private NyARGLUtil _glnya;
+ private TextPanel _panel;
+
+
+ //NyARToolkit関係
+ private NyARParam _ar_param;
+
+ private double[] _camera_projection=new double[16];
+
+ private Object _sync_object=new Object();
+ private MarkerProcessor _processor;
+ private NyARCode[] _code_table=new NyARCode[1];
+
+ public SingleARMarker(NyARParam i_cparam) throws NyARException
+ {
+ JmfCaptureDeviceList devlist=new JmfCaptureDeviceList();
+ this._ar_param=i_cparam;
+
+ //キャプチャリソースの準備
+ this._capture=devlist.getDevice(0);
+ if(!this._capture.setCaptureFormat(SCREEN_X, SCREEN_Y,30.0f)){
+ throw new NyARException();
+ }
+ this._capture.setOnCapture(this);
+ this._cap_image = new GLNyARRaster_RGB(i_cparam,this._capture.getCaptureFormat());
+
+ this._code_table[0]=new NyARCode(16,16);
+ this._code_table[0].loadARPattFromFile(CARCODE_FILE1);
+ //プロセッサの準備
+ this._processor=new MarkerProcessor(i_cparam,this._cap_image.getBufferReader().getBufferType());
+ this._processor.setARCodeTable(_code_table,16,80.0);
+
+ //OpenGLフレームの準備(OpenGLリソースの初期化、カメラの撮影開始は、initコールバック関数内で実行)
+ Frame frame = new Frame("Java simpleLite with NyARToolkit");
+ GLCanvas canvas = new GLCanvas();
+ frame.add(canvas);
+ canvas.addGLEventListener(this);
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e)
+ {
+ System.exit(0);
+ }
+ });
+
+ //ウインドウサイズの調整
+ frame.setVisible(true);
+ Insets ins = frame.getInsets();
+ frame.setSize(SCREEN_X + ins.left + ins.right, SCREEN_Y + ins.top + ins.bottom);
+ canvas.setBounds(ins.left, ins.top, SCREEN_X, SCREEN_Y);
+ return;
+ }
+ public void init(GLAutoDrawable drawable)
+ {
+ this._panel = new TextPanel(100);
+
+
+ this._gl = drawable.getGL();
+ this._gl.glEnable(GL.GL_DEPTH_TEST);
+
+ this._gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ //NyARToolkitの準備
+ try {
+ this._glnya = new NyARGLUtil(this._gl);
+ //カメラパラメータの計算
+ this._glnya.toCameraFrustumRH(this._ar_param,this._camera_projection);
+ //キャプチャ開始
+ this._capture.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ this._animator = new Animator(drawable);
+ this._animator.start();
+ return;
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
+ {
+
+ _gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ _gl.glViewport(0, 0, width, height);
+
+ //視体積の設定
+ _gl.glMatrixMode(GL.GL_PROJECTION);
+ _gl.glLoadIdentity();
+ //見る位置
+ _gl.glMatrixMode(GL.GL_MODELVIEW);
+ _gl.glLoadIdentity();
+ }
+ private double[] __display_wk=new double[16];
+
+
+ public void display(GLAutoDrawable drawable)
+ {
+ NyARTransMatResult transmat_result = this._processor.transmat;
+ if (!_cap_image.hasData()) {
+ return;
+ }
+ // 背景を書く
+ this._gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
+ this._glnya.drawBackGround(this._cap_image, 1.0);
+ if(this._processor.current_code<0 || transmat_result==null){
+
+ }else{
+ try{
+ synchronized(this._sync_object){
+ // Projection transformation.
+ this._gl.glMatrixMode(GL.GL_PROJECTION);
+ this._gl.glLoadMatrixd(_camera_projection, 0);
+ this._gl.glMatrixMode(GL.GL_MODELVIEW);
+ // Viewing transformation.
+ this._gl.glLoadIdentity();
+ // 変換行列をOpenGL形式に変換
+ this._glnya.toCameraViewRH(transmat_result, __display_wk);
+ this._gl.glLoadMatrixd(__display_wk, 0);
+ // All other lighting and geometry goes here.
+ this._gl.glPushMatrix();
+ this._gl.glDisable(GL.GL_LIGHTING);
+
+
+ //マーカのXZ平面をマーカの左上、表示開始位置を10cm上空へ。
+ //くるーんくるん
+ Date d = new Date();
+ float r=(d.getTime()/50)%360;
+ this._gl.glRotatef(r,0f,0f,1.0f);
+ this._gl.glTranslatef(-1.0f,0f,1.0f);
+ this._gl.glRotatef(90,1.0f,0f,0f);
+ this._panel.draw("MarkerId:"+this._processor.current_code,0.01f);
+ this._gl.glPopMatrix();
+ }
+ Thread.sleep(1);// タスク実行権限を一旦渡す
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+ return;
+
+ }
+ /**
+ * カメラデバイスからのコールバック
+ */
+ public void onUpdateBuffer(Buffer i_buffer)
+ {
+ try {
+ synchronized (this._sync_object) {
+ this._cap_image.setBuffer(i_buffer);
+ //フレームワークに画像を転送
+ this._processor.detectMarker(this._cap_image);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged)
+ {
+ }
+
+
+ private final static int SCREEN_X = 640;
+ private final static int SCREEN_Y = 480;
+ private final static String PARAM_FILE = "../../Data/camera_para.dat";
+ //エントリポイント
+ public static void main(String[] args)
+ {
+ try{
+ NyARParam cparam= new NyARParam();
+ cparam.loadARParamFromFile(PARAM_FILE);
+ cparam.changeScreenSize(SCREEN_X, SCREEN_Y);
+ new SingleARMarker(cparam);
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ return;
+ }
+}
+
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/SingleNyIdMarker.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/SingleNyIdMarker.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/SingleNyIdMarker.java (revision 302)
@@ -40,6 +40,7 @@
import jp.nyatla.nyartoolkit.*;
import jp.nyatla.nyartoolkit.core.*;
import jp.nyatla.nyartoolkit.core.param.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
import jp.nyatla.nyartoolkit.core.transmat.*;
import jp.nyatla.nyartoolkit.jmf.utils.*;
import jp.nyatla.nyartoolkit.jogl.utils.*;
@@ -79,7 +80,8 @@
public MarkerProcessor(NyARParam i_cparam,int i_raster_format) throws NyARException
{
//アプリケーションフレームワークの初期化
- super(i_cparam,new NyIdMarkerDataEncoder_RawBit(),i_raster_format);
+ super();
+ initInstance(i_cparam,new NyIdMarkerDataEncoder_RawBit(),i_raster_format);
return;
}
/**
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java (revision 302)
@@ -116,7 +116,6 @@
this._ar_param = i_param;

Frame frame = new Frame("Java simpleLite with NyARToolkit");
- this._nya = new NyARSingleDetectMarker(this._ar_param, i_ar_code, 80.0);


// キャプチャの準備
@@ -126,11 +125,12 @@
throw new NyARException();
}
this._capture.setOnCapture(this);
- // NyARToolkitの準備
- this._nya.setContinueMode(true);// ここをtrueにすると、transMatContinueモード(History計算)になります。
// GL対応のRGBラスタオブジェクト
this._cap_image = new GLNyARRaster_RGB(this._ar_param, this._capture.getCaptureFormat());

+ // NyARToolkitの準備
+ this._nya = new NyARSingleDetectMarker(this._ar_param, i_ar_code, 80.0,this._cap_image.getBufferReader().getBufferType());
+ this._nya.setContinueMode(false);// ここをtrueにすると、transMatContinueモード(History計算)になります。

// 3Dを描画するコンポーネント
GLCanvas canvas = new GLCanvas();
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite2.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite2.java (revision 302)
@@ -158,22 +158,23 @@
ar_codes[0].loadARPattFromFile(CARCODE_FILE1);
ar_codes[1] = new NyARCode(16, 16);
ar_codes[1].loadARPattFromFile(CARCODE_FILE2);
- _nya = new NyARDetectMarker(_ar_param, ar_codes, width, 2);
- _nya.setContinueMode(false);//ここをtrueにすると、transMatContinueモード(History計算)になります。
+ //GL対応のRGBラスタオブジェクト
+ this._cap_image = new GLNyARRaster_RGB(this._ar_param,_capture.getCaptureFormat());
+
+ this._nya = new NyARDetectMarker(this._ar_param, ar_codes, width, 2,this._cap_image.getBufferReader().getBufferType());
+ this._nya.setContinueMode(false);//ここをtrueにすると、transMatContinueモード(History計算)になります。
//NyARToolkit用の支援クラス
- _glnya = new NyARGLUtil(_gl);
- //GL対応のRGBラスタオブジェクト
- _cap_image = new GLNyARRaster_RGB(_ar_param,_capture.getCaptureFormat());
+ this._glnya = new NyARGLUtil(_gl);
//キャプチャ開始
- _capture.start();
+ this._capture.start();
} catch (Exception e) {
e.printStackTrace();
}
//カメラパラメータの計算
- _glnya.toCameraFrustumRH(_ar_param,_camera_projection);
+ this._glnya.toCameraFrustumRH(_ar_param,_camera_projection);

- _animator = new Animator(drawable);
- _animator.start();
+ this._animator = new Animator(drawable);
+ this._animator.start();

}

Index: D:/project.sorceforge/NyARToolkit/trunk/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java (revision 302)
@@ -35,6 +35,8 @@
import jp.nyatla.nyartoolkit.jmf.utils.*;

import java.awt.*;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;

import jp.nyatla.nyartoolkit.core.*;
import jp.nyatla.nyartoolkit.core.param.NyARParam;
@@ -67,24 +69,29 @@
setBounds(0, 0, 320 + 64, 240 + 64);
//キャプチャの準備
JmfCaptureDeviceList devlist=new JmfCaptureDeviceList();
- _capture=devlist.getDevice(0);
+ this._capture=devlist.getDevice(0);
//JmfNyARRaster_RGBはYUVよりもRGBで高速に動作します。
- if(!_capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,320, 240,15f)){
- if(!_capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_YUV,320, 240,15f)){
+ if(!this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,320, 240,15f)){
+ if(!this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_YUV,320, 240,15f)){
throw new NyARException("キャプチャフォーマットが見つかりません");
}
}
- _capture.setOnCapture(this);
-
+ this._capture.setOnCapture(this);
+ this.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e)
+ {
+ System.exit(0);
+ }
+ });
//NyARToolkitの準備
NyARParam ar_param = new NyARParam();
NyARCode ar_code = new NyARCode(16, 16);
ar_param.loadARParamFromFile(PARAM_FILE);
ar_param.changeScreenSize(320, 240);
- this._nya = new NyARSingleDetectMarker(ar_param, ar_code, 80.0);
+ this._raster = new JmfNyARRaster_RGB(320, 240,this._capture.getCaptureFormat());
+ this._nya = new NyARSingleDetectMarker(ar_param, ar_code, 80.0,this._raster.getBufferReader().getBufferType());
ar_code.loadARPattFromFile(CARCODE_FILE);
//キャプチャイメージ用のラスタを準備
- this._raster = new JmfNyARRaster_RGB(320, 240,_capture.getCaptureFormat());
return;
}

Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARSingleDetectMarker_Quad.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARSingleDetectMarker_Quad.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARSingleDetectMarker_Quad.java (revision 302)
@@ -38,6 +38,9 @@
import jp.nyatla.nyartoolkit.core.pickup.*;
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
import jp.nyatla.nyartoolkit.core.raster.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.INyARSquareDetector;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;
import jp.nyatla.nyartoolkit.core.transmat.*;
import jp.nyatla.nyartoolkit.core.types.NyARIntSize;

@@ -149,7 +152,7 @@
double confidence = 0;
for(int i=0;i<number_of_square;i++){
// 評価基準になるパターンをイメージから切り出す
- if (!this._patt.pickFromRaster(i_raster, (NyARSquare)l_square_list.getItem(i))){
+ if (!this._patt.pickFromRaster(i_raster,l_square_list.getItem(i))){
continue;
}
//取得パターンをカラー差分データに変換して評価する。
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARSquareDetector_Quad.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARSquareDetector_Quad.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARSquareDetector_Quad.java (revision 302)
@@ -32,15 +32,16 @@
package jp.nyatla.nyartoolkit.sandbox.quadx2;
import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.labeling.*;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.*;
import jp.nyatla.nyartoolkit.core.raster.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.ContourPickup;
+import jp.nyatla.nyartoolkit.core.squaredetect.INyARSquareDetector;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;
+import jp.nyatla.nyartoolkit.core.squaredetect.SquareContourDetector;
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.core.param.*;

-
-import jp.nyatla.nyartoolkit.core2.types.NyARI64Linear;
-import jp.nyatla.nyartoolkit.core2.types.NyARI64Point2d;
-import jp.nyatla.nyartoolkit.core2.types.matrix.NyARI64Matrix22;
-import jp.nyatla.nyartoolkit.core.*;
import jp.nyatla.nyartoolkit.sandbox.x2.*;


@@ -50,21 +51,19 @@
*/
public class NyARSquareDetector_Quad implements INyARSquareDetector
{
- private static int PCA_LENGTH = 20;
- private static double VERTEX_FACTOR = 1.0;// 線検出のファクタ
-
private static int AR_AREA_MAX = 25000;// #define AR_AREA_MAX 100000

private static int AR_AREA_MIN = 20;// #define AR_AREA_MIN 70
private int _width;
private int _height;

- private INyARLabeling _labeling;
+ private NyARLabeling_ARToolKit _labeling;

private NyARLabelingImage _limage;

- private OverlapChecker _overlap_checker = new OverlapChecker();
- private NyARFixedFloatObserv2IdealMap _dist_factor;
+ private final LabelOverlapChecker<NyARLabelingLabel> _overlap_checker = new LabelOverlapChecker<NyARLabelingLabel>(32,NyARLabelingLabel.class);
+ private final SquareContourDetector _sqconvertor;
+ private final ContourPickup _cpickup=new ContourPickup();
/**
* 最大i_squre_max個のマーカーを検出するクラスを作成する。
*
@@ -74,9 +73,9 @@
{
this._width = i_size.w / 2;
this._height = i_size.h / 2;
- this._labeling = new NyARLabeling_ARToolKit_X2();
+ this._labeling = new NyARLabeling_ARToolKit();
this._limage = new NyARLabelingImage(this._width, this._height);
- this._labeling.attachDestination(this._limage);
+ this._sqconvertor=new SquareContourDetector(i_size,i_dist_factor_ref);

// 輪郭の最大長は画面に映りうる最大の長方形サイズ。
int number_of_coord = (this._width + this._height) * 2;
@@ -90,27 +89,12 @@
NyARCameraDistortionFactor quadfactor = new NyARCameraDistortionFactor();
quadfactor.copyFrom(i_dist_factor_ref);
quadfactor.changeScale(0.5);
- this._dist_factor = new NyARFixedFloatObserv2IdealMap(quadfactor, i_size);
- //PCA
- this._pca = new NyARFixedFloatPca2d();
- this._xpos = new int[PCA_LENGTH];//最大辺長はthis._width+this._height
- this._ypos = new int[PCA_LENGTH];//最大辺長はthis._width+this._height
-
}

private int _max_coord;
private int[] _xcoord;
private int[] _ycoord;

- private void normalizeCoord(int[] i_coord_x, int[] i_coord_y, int i_index, int i_coord_num)
- {
- // vertex1を境界にして、後方に配列を連結
- System.arraycopy(i_coord_x, 1, i_coord_x, i_coord_num, i_index);
- System.arraycopy(i_coord_y, 1, i_coord_y, i_coord_num, i_index);
- }
-
- private int[] __detectMarker_mkvertex = new int[5];
-
/**
* arDetectMarker2を基にした関数
* この関数はNyARSquare要素のうち、directionを除くパラメータを取得して返します。
@@ -123,7 +107,6 @@
*/
public void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException
{
- INyARLabeling labeling_proc = this._labeling;
NyARLabelingImage limage = this._limage;

// 初期化
@@ -132,7 +115,7 @@
o_square_stack.clear();

// ラベリング
- labeling_proc.labeling(i_raster);
+ this._labeling.labeling(i_raster,limage);

// ラベル数が0ならここまで
int label_num = limage.getLabelStack().getLength();
@@ -142,12 +125,11 @@
}

NyARLabelingLabelStack stack = limage.getLabelStack();
- NyARLabelingLabel[] labels = (NyARLabelingLabel[])stack.getArray();
+ // ラベルを大きい順に整列
+ stack.sortByArea();
+
+ NyARLabelingLabel[] labels = stack.getArray();

-
- // ラベルを大きい順に整列
- stack.sortByArea();
-
// デカいラベルを読み飛ばし
int i;
for (i = 0; i < label_num; i++)
@@ -164,14 +146,13 @@
int[] xcoord = this._xcoord;
int[] ycoord = this._ycoord;
int coord_max = this._max_coord;
- int[] mkvertex = this.__detectMarker_mkvertex;
- OverlapChecker overlap = this._overlap_checker;
- int coord_num;
+ final LabelOverlapChecker<NyARLabelingLabel> overlap = this._overlap_checker;
+
int label_area;
NyARLabelingLabel label_pt;

//重なりチェッカの最大数を設定
- overlap.reset(label_num);
+ overlap.setMaxLabels(label_num);

for (; i < label_num; i++)
{
@@ -197,316 +178,32 @@
// 重なっているようだ。
continue;
}
+ // 既に検出された矩形との重なりを確認
+ if (!overlap.check(label_pt)) {
+ // 重なっているようだ。
+ continue;
+ }
+ // 輪郭を取得
+ final int coord_num = _cpickup.getContour(limage,limage.getTopClipTangentX(label_pt),label_pt.clip_t, coord_max, xcoord, ycoord);
+ if (coord_num == coord_max) {
+ // 輪郭が大きすぎる。
+ continue;
+ }
+ //輪郭分析用に正規化する。
+ final int vertex1 = SquareContourDetector.normalizeCoord(xcoord, ycoord, coord_num);

- // 輪郭を取得
- coord_num = limage.getContour(i, coord_max, xcoord, ycoord);
- if (coord_num == coord_max)
- {
- // 輪郭が大きすぎる。
- continue;
- }
- //頂点候補のインデクスを取得
- int vertex1 = scanVertex(xcoord, ycoord, coord_num);
-
- // 頂点候補(vertex1)を先頭に並べなおした配列を作成する。
- normalizeCoord(xcoord, ycoord, vertex1, coord_num);
-
- // 領域を準備する。
- NyARSquare square_ptr = (NyARSquare)o_square_stack.prePush();
-
- // 頂点情報を取得
- if (!getSquareVertex(xcoord, ycoord, vertex1, coord_num, label_area, mkvertex))
- {
- o_square_stack.pop();// 頂点の取得が出来なかったので破棄
- continue;
- }
- // マーカーを検出
- if (!getSquareLine(mkvertex, xcoord, ycoord, square_ptr))
- {
- // 矩形が成立しなかった。
- o_square_stack.pop();
- continue;
- }
+ //ここから先が輪郭分析
+ NyARSquare square_ptr = o_square_stack.prePush();
+ if(!this._sqconvertor.coordToSquare(xcoord,ycoord,vertex1,coord_num,label_area,square_ptr)){
+ o_square_stack.pop();// 頂点の取得が出来なかったので破棄
+ continue;
+ }
+
// 検出済の矩形の属したラベルを重なりチェックに追加する。
overlap.push(label_pt);
}
return;
}
-
- /**
- * 辺からの対角線が最長になる点を対角線候補として返す。
- *
- * @param i_xcoord
- * @param i_ycoord
- * @param i_coord_num
- * @return
- */
- private int scanVertex(int[] i_xcoord, int[] i_ycoord, int i_coord_num)
- {
- int sx = i_xcoord[0];
- int sy = i_ycoord[0];
- int d = 0;
- int w, x, y;
- int ret = 0;
- for (int i = 1; i < i_coord_num; i++)
- {
- x = i_xcoord[i] - sx;
- y = i_ycoord[i] - sy;
- w = x * x + y * y;
- if (w > d)
- {
- d = w;
- ret = i;
- }
- // ここでうまく終了条件入れられないかな。
- }
- return ret;
- }
-
- private NyARVertexCounter __getSquareVertex_wv1 = new NyARVertexCounter();
-
- private NyARVertexCounter __getSquareVertex_wv2 = new NyARVertexCounter();
-
- /**
- * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor ) 関数の代替関数 OPTIMIZED STEP [450->415] o_squareに頂点情報をセットします。
- *
- * @param i_x_coord
- * @param i_y_coord
- * @param i_vertex1_index
- * @param i_coord_num
- * @param i_area
- * @param o_vertex
- * 要素数はint[4]である事
- * @return
- */
- private boolean getSquareVertex(int[] i_x_coord, int[] i_y_coord, int i_vertex1_index, int i_coord_num, int i_area, int[] o_vertex)
- {
- NyARVertexCounter wv1 = this.__getSquareVertex_wv1;
- NyARVertexCounter wv2 = this.__getSquareVertex_wv2;
- int end_of_coord = i_vertex1_index + i_coord_num - 1;
- int sx = i_x_coord[i_vertex1_index];// sx = marker_info2->x_coord[0];
- int sy = i_y_coord[i_vertex1_index];// sy = marker_info2->y_coord[0];
- int dmax = 0;
- int v1 = i_vertex1_index;
- for (int i = 1 + i_vertex1_index; i < end_of_coord; i++)
- {// for(i=1;i<marker_info2->coord_num-1;i++)
- // {
- int d = (i_x_coord[i] - sx) * (i_x_coord[i] - sx) + (i_y_coord[i] - sy) * (i_y_coord[i] - sy);
- if (d > dmax)
- {
- dmax = d;
- v1 = i;
- }
- }
- double thresh = (i_area / 0.75) * 0.01 * VERTEX_FACTOR;
-
- o_vertex[0] = i_vertex1_index;
-
- if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v1, thresh))
- { // if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,0,v1,thresh,wv1,&wvnum1)<
- // 0 ) {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v1, end_of_coord, thresh))
- {// if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,v1,marker_info2->coord_num-1,thresh,wv2,&wvnum2)
- // < 0) {
- return false;
- }
-
- int v2;
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1)
- {// if(wvnum1 == 1 && wvnum2== 1) {
- o_vertex[1] = wv1.vertex[0];
- o_vertex[2] = v1;
- o_vertex[3] = wv2.vertex[0];
- }
- else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0)
- {// }else if( wvnum1 > 1 && wvnum2== 0) {
- //頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。
- v2 = (v1 - i_vertex1_index) / 2 + i_vertex1_index;
- if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v2, thresh))
- {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v2, v1, thresh))
- {
- return false;
- }
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1)
- {
- o_vertex[1] = wv1.vertex[0];
- o_vertex[2] = wv2.vertex[0];
- o_vertex[3] = v1;
- }
- else
- {
- return false;
- }
- }
- else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1)
- {
- //v2 = (v1-i_vertex1_index+ end_of_coord-i_vertex1_index) / 2+i_vertex1_index;
- v2 = (v1 + end_of_coord) / 2;
-
- if (!wv1.getVertex(i_x_coord, i_y_coord, v1, v2, thresh))
- {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v2, end_of_coord, thresh))
- {
- return false;
- }
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1)
- {
- o_vertex[1] = v1;
- o_vertex[2] = wv1.vertex[0];
- o_vertex[3] = wv2.vertex[0];
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- o_vertex[4] = end_of_coord;
- return true;
- }
- private int[] _xpos;
- private int[] _ypos;
- private NyARFixedFloatPca2d _pca;
- private NyARI64Matrix22 __getSquareLine_evec = new NyARI64Matrix22();
- private NyARI64Point2d __getSquareLine_mean = new NyARI64Point2d();
- private NyARI64Point2d __getSquareLine_ev = new NyARI64Point2d();
- private NyARI64Linear[] __getSquareLine_i64liner = NyARI64Linear.createArray(4);
- /**
- * arGetLine(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[4][3], double v[4][2]) arGetLine2(int x_coord[], int y_coord[], int
- * coord_num,int vertex[], double line[4][3], double v[4][2], double *dist_factor) の2関数の合成品です。 マーカーのvertex,lineを計算して、結果をo_squareに保管します。
- * Optimize:STEP[424->391]
- *
- * @param i_cparam
- * @return
- * @throws NyARException
- */
- private boolean getSquareLine(int[] i_mkvertex, int[] i_xcoord, int[] i_ycoord, NyARSquare o_square) throws NyARException
- {
- NyARLinear[] l_line = o_square.line;
- NyARI64Matrix22 evec = this.__getSquareLine_evec;
- NyARI64Point2d mean = this.__getSquareLine_mean;
- NyARI64Point2d ev = this.__getSquareLine_ev;
- NyARI64Linear[] i64liner = this.__getSquareLine_i64liner;
-
-
- for (int i = 0; i < 4; i++)
- {
- double w1 = (double)(i_mkvertex[i + 1] - i_mkvertex[i] + 1) * 0.05 + 0.5;
- int st = (int)(i_mkvertex[i] + w1);
- int ed = (int)(i_mkvertex[i + 1] - w1);
- int n = ed - st + 1;
- if (n < 2)
- {
- // nが2以下でmatrix.PCAを計算することはできないので、エラー
- return false;
- }
- //配列作成
- n = this._dist_factor.observ2IdealSampling(i_xcoord, i_ycoord, st, n, this._xpos, this._ypos, PCA_LENGTH);
-
- //主成分分析する。
- this._pca.pcaF16(this._xpos, this._ypos, n, evec, ev, mean);
- NyARI64Linear l_line_i = i64liner[i];
- l_line_i.run = evec.m01;// line[i][0] = evec->m[1];
- l_line_i.rise = -evec.m00;// line[i][1] = -evec->m[0];
- l_line_i.intercept = -((l_line_i.run * mean.x + l_line_i.rise * mean.y) >> 16);// line[i][2] = -(line[i][0]*mean->v[0] + line[i][1]*mean->v[1]);
- }
-
- NyARDoublePoint2d[] l_sqvertex = o_square.sqvertex;
- NyARIntPoint2d[] l_imvertex = o_square.imvertex;
- for (int i = 0; i < 4; i++)
- {
- NyARI64Linear l_line_i = i64liner[i];
- NyARI64Linear l_line_2 = i64liner[(i + 3) % 4];
- long w1 = (l_line_2.run * l_line_i.rise - l_line_i.run * l_line_2.rise) >> 16;
- if (w1 == 0)
- {
- return false;
- }
- l_sqvertex[i].x = (double)((l_line_2.rise * l_line_i.intercept - l_line_i.rise * l_line_2.intercept) / w1) *2/ 65536.0;
- l_sqvertex[i].y = (double)((l_line_i.run * l_line_2.intercept - l_line_2.run * l_line_i.intercept) / w1) *2/ 65536.0;
- // 頂点インデクスから頂点座標を得て保存
- l_imvertex[i].x = i_xcoord[i_mkvertex[i]]*2;
- l_imvertex[i].y = i_ycoord[i_mkvertex[i]]*2;
- l_line[i].run = (double)l_line_i.run / 65536.0;
- l_line[i].rise = (double)l_line_i.rise / 65536.0;
- l_line[i].intercept = (double)l_line_i.intercept*2 / 65536.0;
- }
- return true;
- }
}


-/**
- * ラベル同士の重なり(内包関係)を調べるクラスです。
- * ラベルリストに内包するラベルを蓄積し、それにターゲットのラベルが内包されているか を確認します。
- */
-class OverlapChecker
-{
- private NyARLabelingLabel[] _labels = new NyARLabelingLabel[32];
-
- private int _length;
-
- /**
- * 最大i_max_label個のラベルを蓄積できるようにオブジェクトをリセットする
- *
- * @param i_max_label
- */
- public void reset(int i_max_label)
- {
- if (i_max_label > this._labels.length)
- {
- this._labels = new NyARLabelingLabel[i_max_label];
- }
- this._length = 0;
- }
-
- /**
- * チェック対象のラベルを追加する。
- *
- * @param i_label_ref
- */
- public void push(NyARLabelingLabel i_label_ref)
- {
- this._labels[this._length] = i_label_ref;
- this._length++;
- }
-
- /**
- * 現在リストにあるラベルと重なっているかを返す。
- *
- * @param i_label
- * @return 何れかのラベルの内側にあるならばfalse,独立したラベルである可能性が高ければtrueです.
- */
- public boolean check(NyARLabelingLabel i_label)
- {
- // 重なり処理かな?
- NyARLabelingLabel[] label_pt = this._labels;
- int px1 = (int)i_label.pos_x;
- int py1 = (int)i_label.pos_y;
- for (int i = this._length - 1; i >= 0; i--)
- {
- int px2 = (int)label_pt[i].pos_x;
- int py2 = (int)label_pt[i].pos_y;
- int d = (px1 - px2) * (px1 - px2) + (py1 - py2) * (py1 - py2);
- if (d < label_pt[i].area / 4)
- {
- // 対象外
- return false;
- }
- }
- // 対象
- return true;
- }
-}
-
-
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/vertexdetect/NyARVertexDetector.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/vertexdetect/NyARVertexDetector.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/vertexdetect/NyARVertexDetector.java (revision 302)
@@ -32,45 +32,43 @@
package jp.nyatla.nyartoolkit.sandbox.vertexdetect;
import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.labeling.*;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.*;
import jp.nyatla.nyartoolkit.core.raster.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.*;
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.core.param.*;
-import jp.nyatla.nyartoolkit.core.*;
-import jp.nyatla.nyartoolkit.sandbox.x2.*;
/**
* PCAではなく、頂点座標そのものからSquare位置を計算するクラス
*
*/
public class NyARVertexDetector implements INyARSquareDetector
{
- private static final double VERTEX_FACTOR = 1.0;// 線検出のファクタ
-
private static final int AR_AREA_MAX = 100000;// #define AR_AREA_MAX 100000

private static final int AR_AREA_MIN = 70;// #define AR_AREA_MIN 70
private final int _width;
private final int _height;

- private final NyARLabeling_ARToolKit_X2 _labeling;
+ private final NyARLabeling_ARToolKit _labeling;

private final NyARLabelingImage _limage;

- private final OverlapChecker _overlap_checker = new OverlapChecker();
- private final NyARObserv2IdealMap _dist_factor_ref;
+ private final LabelOverlapChecker<NyARLabelingLabel> _overlap_checker = new LabelOverlapChecker<NyARLabelingLabel>(32,NyARLabelingLabel.class);
+ private final SquareContourDetector _sqconvertor;
+ private final ContourPickup _cpickup=new ContourPickup();

/**
* 最大i_squre_max個のマーカーを検出するクラスを作成する。
*
* @param i_param
*/
- public NyARVertexDetector(NyARObserv2IdealMap i_dist_factor_ref,NyARIntSize i_size) throws NyARException
+ public NyARVertexDetector(NyARCameraDistortionFactor i_dist_factor_ref,NyARIntSize i_size) throws NyARException
{
this._width = i_size.w;
this._height = i_size.h;
- this._dist_factor_ref = i_dist_factor_ref;
- this._labeling = new NyARLabeling_ARToolKit_X2();
+ this._labeling = new NyARLabeling_ARToolKit();
this._limage = new NyARLabelingImage(this._width, this._height);
- this._labeling.attachDestination(this._limage);
+ this._sqconvertor=new SquareContourDetector(i_size,i_dist_factor_ref);

// 輪郭の最大長は画面に映りうる最大の長方形サイズ。
int number_of_coord = (this._width + this._height) * 2;
@@ -85,15 +83,6 @@
private final int[] _xcoord;
private final int[] _ycoord;

- private void normalizeCoord(int[] i_coord_x, int[] i_coord_y, int i_index, int i_coord_num)
- {
- // vertex1を境界にして、後方に配列を連結
- System.arraycopy(i_coord_x, 1, i_coord_x, i_coord_num, i_index);
- System.arraycopy(i_coord_y, 1, i_coord_y, i_coord_num, i_index);
- }
-
- private final int[] __detectMarker_mkvertex = new int[5];
-
/**
* ARMarkerInfo2 *arDetectMarker2( ARInt16 *limage, int label_num, int *label_ref,int *warea, double *wpos, int *wclip,int area_max, int area_min, double
* factor, int *marker_num ) 関数の代替品 ラベリング情報からマーカー一覧を作成してo_marker_listを更新します。 関数はo_marker_listに重なりを除外したマーカーリストを作成します。
@@ -106,7 +95,6 @@
*/
public final void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException
{
- final INyARLabeling labeling_proc = this._labeling;
final NyARLabelingImage limage = this._limage;

// 初期化
@@ -115,20 +103,20 @@
o_square_stack.clear();

// ラベリング
- labeling_proc.labeling(i_raster);
+ this._labeling.labeling(i_raster,this._limage);

// ラベル数が0ならここまで
final int label_num = limage.getLabelStack().getLength();
if (label_num < 1) {
return;
}
+

final NyARLabelingLabelStack stack = limage.getLabelStack();
- final NyARLabelingLabel[] labels = (NyARLabelingLabel[])stack.getArray();
-
-
// ラベルを大きい順に整列
stack.sortByArea();
+
+ final NyARLabelingLabel[] labels = stack.getArray();

// デカいラベルを読み飛ばし
int i;
@@ -144,14 +132,12 @@
final int[] xcoord = this._xcoord;
final int[] ycoord = this._ycoord;
final int coord_max = this._max_coord;
- final int[] mkvertex = this.__detectMarker_mkvertex;
- final OverlapChecker overlap = this._overlap_checker;
- int coord_num;
+ final LabelOverlapChecker<NyARLabelingLabel> overlap = this._overlap_checker;
int label_area;
NyARLabelingLabel label_pt;

//重なりチェッカの最大数を設定
- overlap.reset(label_num);
+ overlap.setMaxLabels(label_num);

for (; i < label_num; i++) {
label_pt = labels[i];
@@ -172,333 +158,25 @@
// 重なっているようだ。
continue;
}
-
// 輪郭を取得
- coord_num = limage.getContour(i, coord_max, xcoord, ycoord);
+ final int coord_num = _cpickup.getContour(limage,limage.getTopClipTangentX(label_pt),label_pt.clip_t, coord_max, xcoord, ycoord);
if (coord_num == coord_max) {
// 輪郭が大きすぎる。
continue;
}
- //頂点候補のインデクスを取得
- final int vertex1 = scanVertex(xcoord, ycoord, coord_num);
+ //輪郭分析用に正規化する。
+ final int vertex1 = SquareContourDetector.normalizeCoord(xcoord, ycoord, coord_num);

- // 頂点候補(vertex1)を先頭に並べなおした配列を作成する。
- normalizeCoord(xcoord, ycoord, vertex1, coord_num);
-
- // 領域を準備する。
- NyARSquare square_ptr = (NyARSquare)o_square_stack.prePush();
-
- // 頂点情報を取得
- if (!getSquareVertex(xcoord, ycoord, vertex1, coord_num, label_area, mkvertex)) {
+ //ここから先が輪郭分析
+ NyARSquare square_ptr = o_square_stack.prePush();
+ if(!this._sqconvertor.coordToSquare(xcoord,ycoord,vertex1,coord_num,label_area,square_ptr)){
o_square_stack.pop();// 頂点の取得が出来なかったので破棄
- continue;
+ continue;
}
- //頂点情報からライン情報を作っちゃう
- getSquare(mkvertex, xcoord, ycoord, square_ptr);
-
// 検出済の矩形の属したラベルを重なりチェックに追加する。
overlap.push(label_pt);
}
return;
}
- /**
- * 2つの頂点座標を結ぶ直線から、NyARLinearを計算する。
- * @param i_v1
- * @param i_v2
- * @param o_line
- */
- final private void getLine(NyARDoublePoint2d i_v1,NyARDoublePoint2d i_v2,NyARLinear o_line)
- {
- final double x=i_v1.x-i_v2.x;
- final double y=i_v1.y-i_v2.y;
- final double x2=x*x;
- final double y2=y*y;
- final double rise_=Math.sqrt(x2/(x2+y2));
- o_line.rise=rise_;
- o_line.run=Math.sqrt(y2/(x2+y2));
- if(x<0){
- if(y<0){
- o_line.rise=-o_line.rise;
- }else{
- o_line.rise=-o_line.rise;
- o_line.run=-o_line.run;
- }
- }else{
- if(y<0){
- o_line.rise=-o_line.rise;
- o_line.run=-o_line.run;
- }else{
- o_line.rise=-o_line.rise;
- }
- }
- o_line.intercept=(i_v1.y+(o_line.run/o_line.rise)*(i_v1.x))*rise_;
-
- }

- private void getSquare(int[] i_mkvertex, int[] i_xcoord, int[] i_ycoord, NyARSquare o_square)
- {
- final NyARObserv2IdealMap dist_factor=this._dist_factor_ref;
- final NyARDoublePoint2d[] vertex=o_square.sqvertex;
- //歪み補正
- for(int i=0;i<4;i++)
- {
- final int idx=i_mkvertex[i];
- o_square.imvertex[i].x=i_xcoord[idx];
- o_square.imvertex[i].y=i_ycoord[idx];
- dist_factor.observ2Ideal(i_xcoord[idx], i_ycoord[idx],vertex[i]);
- }
- //ライン計算
- getLine(vertex[1],vertex[0],o_square.line[0]);
- getLine(vertex[2],vertex[1],o_square.line[1]);
- getLine(vertex[3],vertex[2],o_square.line[2]);
- getLine(vertex[0],vertex[3],o_square.line[3]);
- return;
- }
-
- /**
- * 辺からの対角線が最長になる点を対角線候補として返す。
- *
- * @param i_xcoord
- * @param i_ycoord
- * @param i_coord_num
- * @return
- */
- private int scanVertex(int[] i_xcoord, int[] i_ycoord, int i_coord_num)
- {
- final int sx = i_xcoord[0];
- final int sy = i_ycoord[0];
- int d = 0;
- int w, x, y;
- int ret = 0;
- for (int i = 1; i < i_coord_num; i++) {
- x = i_xcoord[i] - sx;
- y = i_ycoord[i] - sy;
- w = x * x + y * y;
- if (w > d) {
- d = w;
- ret = i;
- }
- // ここでうまく終了条件入れられないかな。
- }
- return ret;
- }
-
- private final NyARVertexCounter __getSquareVertex_wv1 = new NyARVertexCounter();
-
- private final NyARVertexCounter __getSquareVertex_wv2 = new NyARVertexCounter();
-
- /**
- * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor ) 関数の代替関数 OPTIMIZED STEP [450->415] o_squareに頂点情報をセットします。
- *
- * @param i_x_coord
- * @param i_y_coord
- * @param i_vertex1_index
- * @param i_coord_num
- * @param i_area
- * @param o_vertex
- * 要素数はint[4]である事
- * @return
- */
- private boolean getSquareVertex(int[] i_x_coord, int[] i_y_coord, int i_vertex1_index, int i_coord_num, int i_area, int[] o_vertex)
- {
- final NyARVertexCounter wv1 = this.__getSquareVertex_wv1;
- final NyARVertexCounter wv2 = this.__getSquareVertex_wv2;
- final int end_of_coord = i_vertex1_index + i_coord_num - 1;
- final int sx = i_x_coord[i_vertex1_index];// sx = marker_info2->x_coord[0];
- final int sy = i_y_coord[i_vertex1_index];// sy = marker_info2->y_coord[0];
- int dmax = 0;
- int v1 = i_vertex1_index;
- for (int i = 1 + i_vertex1_index; i < end_of_coord; i++) {// for(i=1;i<marker_info2->coord_num-1;i++)
- // {
- final int d = (i_x_coord[i] - sx) * (i_x_coord[i] - sx) + (i_y_coord[i] - sy) * (i_y_coord[i] - sy);
- if (d > dmax) {
- dmax = d;
- v1 = i;
- }
- }
- final double thresh = (i_area / 0.75) * 0.01 * VERTEX_FACTOR;
-
- o_vertex[0] = i_vertex1_index;
-
- if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v1, thresh)) { // if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,0,v1,thresh,wv1,&wvnum1)<
- // 0 ) {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v1, end_of_coord, thresh)) {// if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,v1,marker_info2->coord_num-1,thresh,wv2,&wvnum2)
- // < 0) {
- return false;
- }
-
- int v2;
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {// if(wvnum1 == 1 && wvnum2== 1) {
- o_vertex[1] = wv1.vertex[0];
- o_vertex[2] = v1;
- o_vertex[3] = wv2.vertex[0];
- } else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0) {// }else if( wvnum1 > 1 && wvnum2== 0) {
- //頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。
- v2 = (v1-i_vertex1_index)/2+i_vertex1_index;
- if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v2, thresh)) {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v2, v1, thresh)) {
- return false;
- }
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
- o_vertex[1] = wv1.vertex[0];
- o_vertex[2] = wv2.vertex[0];
- o_vertex[3] = v1;
- } else {
- return false;
- }
- } else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1) {
- //v2 = (v1-i_vertex1_index+ end_of_coord-i_vertex1_index) / 2+i_vertex1_index;
- v2 = (v1+ end_of_coord)/2;
-
- if (!wv1.getVertex(i_x_coord, i_y_coord, v1, v2, thresh)) {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v2, end_of_coord, thresh)) {
- return false;
- }
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
- o_vertex[1] = v1;
- o_vertex[2] = wv1.vertex[0];
- o_vertex[3] = wv2.vertex[0];
- } else {
- return false;
- }
- } else {
- return false;
- }
- o_vertex[4] = end_of_coord;
- return true;
- }
-}
-
-/**
- * get_vertex関数を切り離すためのクラス
- *
- */
-final class NyARVertexCounter
-{
- public final int[] vertex = new int[10];// 5まで削れる
-
- public int number_of_vertex;
-
- private double thresh;
-
- private int[] x_coord;
-
- private int[] y_coord;
-
- public boolean getVertex(int[] i_x_coord, int[] i_y_coord, int st, int ed, double i_thresh)
- {
- this.number_of_vertex = 0;
- this.thresh = i_thresh;
- this.x_coord = i_x_coord;
- this.y_coord = i_y_coord;
- return get_vertex(st, ed);
- }
-
- /**
- * static int get_vertex( int x_coord[], int y_coord[], int st, int ed,double thresh, int vertex[], int *vnum) 関数の代替関数
- *
- * @param x_coord
- * @param y_coord
- * @param st
- * @param ed
- * @param thresh
- * @return
- */
- private boolean get_vertex(int st, int ed)
- {
- int v1 = 0;
- final int[] lx_coord = this.x_coord;
- final int[] ly_coord = this.y_coord;
- final double a = ly_coord[ed] - ly_coord[st];
- final double b = lx_coord[st] - lx_coord[ed];
- final double c = lx_coord[ed] * ly_coord[st] - ly_coord[ed] * lx_coord[st];
- double dmax = 0;
- for (int i = st + 1; i < ed; i++) {
- final double d = a * lx_coord[i] + b * ly_coord[i] + c;
- if (d * d > dmax) {
- dmax = d * d;
- v1 = i;
- }
- }
- if (dmax / (a * a + b * b) > thresh) {
- if (!get_vertex(st, v1)) {
- return false;
- }
- if (number_of_vertex > 5) {
- return false;
- }
- vertex[number_of_vertex] = v1;// vertex[(*vnum)] = v1;
- number_of_vertex++;// (*vnum)++;
-
- if (!get_vertex(v1, ed)) {
- return false;
- }
- }
- return true;
- }
-}
-
-/**
- * ラベル同士の重なり(内包関係)を調べるクラスです。 ラベルリストに内包するラベルを蓄積し、それにターゲットのラベルが内包されているか を確認します。
- */
-class OverlapChecker
-{
- private NyARLabelingLabel[] _labels = new NyARLabelingLabel[32];
-
- private int _length;
-
- /**
- * 最大i_max_label個のラベルを蓄積できるようにオブジェクトをリセットする
- *
- * @param i_max_label
- */
- public void reset(int i_max_label)
- {
- if (i_max_label > this._labels.length) {
- this._labels = new NyARLabelingLabel[i_max_label];
- }
- this._length = 0;
- }
-
- /**
- * チェック対象のラベルを追加する。
- *
- * @param i_label_ref
- */
- public void push(NyARLabelingLabel i_label_ref)
- {
- this._labels[this._length] = i_label_ref;
- this._length++;
- }
-
- /**
- * 現在リストにあるラベルと重なっているかを返す。
- *
- * @param i_label
- * @return 何れかのラベルの内側にあるならばfalse,独立したラベルである可能性が高ければtrueです.
- */
- public boolean check(NyARLabelingLabel i_label)
- {
- // 重なり処理かな?
- final NyARLabelingLabel[] label_pt = this._labels;
- final int px1 = (int) i_label.pos_x;
- final int py1 = (int) i_label.pos_y;
- for (int i = this._length - 1; i >= 0; i--) {
- final int px2 = (int) label_pt[i].pos_x;
- final int py2 = (int) label_pt[i].pos_y;
- final int d = (px1 - px2) * (px1 - px2) + (py1 - py2) * (py1 - py2);
- if (d < label_pt[i].area / 4) {
- // 対象外
- return false;
- }
- }
- // 対象
- return true;
- }
}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARLabeling_ARToolKit_X2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARLabeling_ARToolKit_X2.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARLabeling_ARToolKit_X2.java (revision 302)
@@ -1,384 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.sandbox.x2;
-
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.raster.*;
-import jp.nyatla.nyartoolkit.core.types.*;
-import jp.nyatla.nyartoolkit.core.labeling.*;
-
-/**
- * 計算部から浮動小数点計算を除外したNyARLabeling_ARToolKit
- * NyARLabeling_ARToolKitと同じ処理をするけど、エリア計算にintを使う。
- * 画面サイズが1600x1600を超えると挙動が怪しくなる。
- *
- */
-public class NyARLabeling_ARToolKit_X2 implements INyARLabeling
-{
- private static final int WORK_SIZE = 1024 * 32;// #define WORK_SIZE 1024*32
-
- private final NyARWorkHolder work_holder = new NyARWorkHolder(WORK_SIZE);
-
- private NyARIntSize _dest_size;
-
- private INyARLabelingImage _out_image;
-
- public void attachDestination(INyARLabelingImage i_destination_image) throws NyARException
- {
- // サイズチェック
- NyARIntSize size = i_destination_image.getSize();
- this._out_image = i_destination_image;
-
- // NyLabelingImageのイメージ初期化(枠書き)
- int[] img = (int[])i_destination_image.getBufferReader().getBuffer();
- int bottom_ptr=(size.h - 1)*size.w;
- for (int i = 0; i < size.w; i++) {
- img[i] = 0;
- img[bottom_ptr+i] = 0;
- }
- for (int i = 0; i < size.h; i++) {
- img[i*size.w] = 0;
- img[(i+1)*size.w - 1] = 0;
- }
-
- // サイズ(参照値)を保存
- this._dest_size = size;
- return;
- }
-
- public INyARLabelingImage getAttachedDestination()
- {
- return this._out_image;
- }
-
- /**
- * static ARInt16 *labeling2( ARUint8 *image, int thresh,int *label_num, int **area, double **pos, int **clip,int **label_ref, int LorR ) 関数の代替品
- * ラスタimageをラベリングして、結果を保存します。 Optimize:STEP[1514->1493]
- *
- * @param i_raster
- * @throws NyARException
- */
- public void labeling(NyARBinRaster i_raster) throws NyARException
- {
- int m, n; /* work */
- int i, j, k;
- INyARLabelingImage out_image = this._out_image;
-
- // サイズチェック
- NyARIntSize in_size = i_raster.getSize();
- this._dest_size.isEqualSize(in_size);
-
- final int lxsize = in_size.w;// lxsize = arUtil_c.arImXsize;
- final int lysize = in_size.h;// lysize = arUtil_c.arImYsize;
- int[] label_img = (int[])out_image.getBufferReader().getBuffer();
-
- // 枠作成はインスタンスを作った直後にやってしまう。
-
- //ラベリング情報のリセット(ラベリングインデックスを使用)
- out_image.reset(true);
-
- int[] label_idxtbl=out_image.getIndexArray();
-
- int[] work2_pt;
- int wk_max = 0;
-
- int label_pixel;
- int[] raster_buf=(int[])i_raster.getBufferReader().getBuffer();
- int line_ptr;
- int[][] work2 = this.work_holder.work2;
- int label_img_ptr0, label_img_ptr1;
- for (j = 1; j < lysize - 1; j++) {// for (int j = 1; j < lysize - 1;j++, pnt += poff*2, pnt2 += 2) {
- line_ptr=j*lxsize;
- label_img_ptr0=j*lxsize;//label_img_pt0 = label_img[j];
- label_img_ptr1=label_img_ptr0-lxsize;//label_img_pt1 = label_img[j - 1];
- for (i = 1; i < lxsize - 1; i++) {// for(int i = 1; i < lxsize-1;i++, pnt+=poff, pnt2++) {
- // RGBの合計値が閾値より小さいかな?
- if (raster_buf[line_ptr+i]==0) {
- // pnt1 = ShortPointer.wrap(pnt2, -lxsize);//pnt1 =&(pnt2[-lxsize]);
- if (label_img[label_img_ptr1+i] > 0) {//if (label_img_pt1[i] > 0) {// if( *pnt1 > 0 ) {
- label_pixel = label_img[label_img_ptr1+i];//label_pixel = label_img_pt1[i];// *pnt2 = *pnt1;
-
- work2_pt = work2[label_pixel - 1];
- work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
- work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
- work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
- work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
- } else if (label_img[label_img_ptr1+i + 1] > 0) {//} else if (label_img_pt1[i + 1] > 0) {// }else if(*(pnt1+1) > 0 ) {
- if (label_img[label_img_ptr1+i - 1] > 0) {//if (label_img_pt1[i - 1] > 0) {// if( *(pnt1-1) > 0 ) {
- m = label_idxtbl[label_img[label_img_ptr1+i + 1] - 1];//m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1];
- n = label_idxtbl[label_img[label_img_ptr1+i - 1] - 1];//n = label_idxtbl[label_img_pt1[i - 1] - 1];// n =work[*(pnt1-1)-1];
- if (m > n) {
- label_pixel = n;// *pnt2 = n;
- // wk=IntPointer.wrap(work, 0);//wk =
- // &(work[0]);
- for (k = 0; k < wk_max; k++) {
- if (label_idxtbl[k] == m) {// if( *wk == m )
- label_idxtbl[k] = n;// *wk = n;
- }
- }
- } else if (m < n) {
- label_pixel = m;// *pnt2 = m;
- // wk=IntPointer.wrap(work,0);//wk = &(work[0]);
- for (k = 0; k < wk_max; k++) {
- if (label_idxtbl[k] == n) {// if( *wk == n ){
- label_idxtbl[k] = m;// *wk = m;
- }
- }
- } else {
- label_pixel = m;// *pnt2 = m;
- }
- work2_pt = work2[label_pixel - 1];
- work2_pt[0]++;
- work2_pt[1] += i;
- work2_pt[2] += j;
- work2_pt[6] = j;
- } else if ((label_img[label_img_ptr0+i - 1]) > 0) {//} else if ((label_img_pt0[i - 1]) > 0) {// }else if(*(pnt2-1) > 0) {
- m = label_idxtbl[label_img[label_img_ptr1+i + 1] - 1];//m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1];
- n = label_idxtbl[label_img[label_img_ptr0+i - 1] - 1];//n = label_idxtbl[label_img_pt0[i - 1] - 1];// n =work[*(pnt2-1)-1];
- if (m > n) {
-
- label_pixel = n;// *pnt2 = n;
- for (k = 0; k < wk_max; k++) {
- if (label_idxtbl[k] == m) {// if( *wk == m ){
- label_idxtbl[k] = n;// *wk = n;
- }
- }
- } else if (m < n) {
- label_pixel = m;// *pnt2 = m;
- for (k = 0; k < wk_max; k++) {
- if (label_idxtbl[k] == n) {// if( *wk == n ){
- label_idxtbl[k] = m;// *wk = m;
- }
- }
- } else {
- label_pixel = m;// *pnt2 = m;
- }
- work2_pt = work2[label_pixel - 1];
- work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
- work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
- work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
- } else {
-
- label_pixel = label_img[label_img_ptr1+i + 1];//label_pixel = label_img_pt1[i + 1];// *pnt2 =
- // *(pnt1+1);
-
- work2_pt = work2[label_pixel - 1];
- work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
- work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
- work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
- if (work2_pt[3] > i) {// if(
- // work2[((*pnt2)-1)*7+3] >
- // i ){
- work2_pt[3] = i;// work2[((*pnt2)-1)*7+3] = i;
- }
- work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
- }
- } else if ((label_img[label_img_ptr1+i - 1]) > 0) {//} else if ((label_img_pt1[i - 1]) > 0) {// }else if(
- // *(pnt1-1) > 0 ) {
- label_pixel = label_img[label_img_ptr1+i - 1];//label_pixel = label_img_pt1[i - 1];// *pnt2 =
- // *(pnt1-1);
-
- work2_pt = work2[label_pixel - 1];
- work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
- work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
- work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
- if (work2_pt[4] < i) {// if( work2[((*pnt2)-1)*7+4] <i ){
- work2_pt[4] = i;// work2[((*pnt2)-1)*7+4] = i;
- }
- work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
- } else if (label_img[label_img_ptr0+i - 1] > 0) {//} else if (label_img_pt0[i - 1] > 0) {// }else if(*(pnt2-1) > 0) {
- label_pixel = label_img[label_img_ptr0+i - 1];//label_pixel = label_img_pt0[i - 1];// *pnt2 =*(pnt2-1);
-
- work2_pt = work2[label_pixel - 1];
- work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
- work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
- work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
- if (work2_pt[4] < i) {// if( work2[((*pnt2)-1)*7+4] <i ){
- work2_pt[4] = i;// work2[((*pnt2)-1)*7+4] = i;
- }
- } else {
- // 現在地までの領域を予約
- this.work_holder.reserv(wk_max);
- wk_max++;
- label_idxtbl[wk_max - 1] = wk_max;
- label_pixel = wk_max;// work[wk_max-1] = *pnt2 = wk_max;
- work2_pt = work2[wk_max - 1];
- work2_pt[0] = 1;
- work2_pt[1] = i;
- work2_pt[2] = j;
- work2_pt[3] = i;
- work2_pt[4] = i;
- work2_pt[5] = j;
- work2_pt[6] = j;
- }
- label_img[label_img_ptr0+i] = label_pixel;//label_img_pt0[i] = label_pixel;
- } else {
- label_img[label_img_ptr0+i] = 0;//label_img_pt0[i] = 0;// *pnt2 = 0;
- }
- }
- }
- // インデックステーブルとラベル数の計算
- int wlabel_num = 1;// *label_num = *wlabel_num = j - 1;
-
- for (i = 0; i < wk_max; i++) {// for(int i = 1; i <= wk_max; i++,wk++) {
- label_idxtbl[i] = (label_idxtbl[i] == i + 1) ? wlabel_num++ : label_idxtbl[label_idxtbl[i] - 1];// *wk=(*wk==i)?j++:work[(*wk)-1];
- }
- wlabel_num -= 1;// *label_num = *wlabel_num = j - 1;
- if (wlabel_num == 0) {// if( *label_num == 0 ) {
- // 発見数0
- out_image.getLabelStack().clear();
- return;
- }
- // ラベルの整理
- updateLabelStackLarge(out_image.getLabelStack(), label_idxtbl, in_size, work2, wk_max, wlabel_num);
-
- return;
- }
- private int[][] __updateLabelStackLarge_temp=new int[64][7];/*area,x,y,l,r,t,b*/
-
- /* 構造が変わるから、ハイスピード版実装するときに使う。 */
- private void updateLabelStackLarge(NyARLabelingLabelStack i_stack, int[] i_lindex, NyARIntSize i_size, int[][] i_work, int i_work_max, int i_number_of_label) throws NyARException
- {
- //計算用のワークを確保
- int[][] temp=this.__updateLabelStackLarge_temp;
- if(temp.length<i_number_of_label){
- temp=new int[i_number_of_label+64][7];
- this.__updateLabelStackLarge_temp=temp;
- }
-
- // ラベルバッファを予約
- i_stack.reserv(i_number_of_label);
- // エリアと重心、クリップ領域を計算
- final NyARLabelingLabel[] labels = (NyARLabelingLabel[])i_stack.getArray();
- for (int i = 0; i < i_number_of_label; i++) {
- final int[] temp_ptr = temp[i];
- temp_ptr[0]=0;//area
- temp_ptr[1]=0;//x
- temp_ptr[2]=0;//y
- temp_ptr[3]=i_size.w;//l
- temp_ptr[4]=0;//r
- temp_ptr[5]=i_size.h;//t
- temp_ptr[6]=0;//b
- }
- //計算!
-
- for (int i = 0; i < i_work_max; i++) {
- final int temp_ptr[] = temp[i_lindex[i] - 1];
- final int[] work2_pt = i_work[i];
- temp_ptr[0] += work2_pt[0];
- temp_ptr[1] += work2_pt[1];
- temp_ptr[2] += work2_pt[2];
- if (temp_ptr[3] > work2_pt[3]) {
- temp_ptr[3] = work2_pt[3];
- }
- if (temp_ptr[4] < work2_pt[4]) {
- temp_ptr[4] = work2_pt[4];
- }
- if (temp_ptr[5] > work2_pt[5]) {
- temp_ptr[5] = work2_pt[5];
- }
- if (temp_ptr[6] < work2_pt[6]) {
- temp_ptr[6] = work2_pt[6];
- }
- }
- //ストア
- for (int i = 0; i < i_number_of_label; i++) {// for(int i = 0; i < *label_num; i++ ) {
- final NyARLabelingLabel label_pt = labels[i];
- final int temp_ptr[] = temp[i];
- label_pt.id=i+1;
- label_pt.area=temp_ptr[0];
- label_pt.pos_x= (double)temp_ptr[1]/label_pt.area;
- label_pt.pos_y= (double)temp_ptr[2]/label_pt.area;
- label_pt.clip_l= temp_ptr[3];
- label_pt.clip_r= temp_ptr[4];
- label_pt.clip_t= temp_ptr[5];
- label_pt.clip_b= temp_ptr[6];
- }
- return;
- }
-}
-
-/**
- * NyARLabeling_O2のworkとwork2を可変長にするためのクラス
- *
- *
- */
-final class NyARWorkHolder
-{
- private final static int ARRAY_APPEND_STEP = 256;
-
- public final int[] work;
-
- public final int[][] work2;
-
- private int allocate_size;
-
- /**
- * 最大i_holder_size個の動的割り当てバッファを準備する。
- *
- * @param i_holder_size
- */
- public NyARWorkHolder(int i_holder_size)
- {
- // ポインタだけははじめに確保しておく
- this.work = new int[i_holder_size];
- this.work2 = new int[i_holder_size][];
- this.allocate_size = 0;
- }
-
- /**
- * i_indexで指定した番号までのバッファを準備する。
- *
- * @param i_index
- */
- public final void reserv(int i_index) throws NyARException
- {
- // アロケート済みなら即リターン
- if (this.allocate_size > i_index) {
- return;
- }
- // 要求されたインデクスは範囲外
- if (i_index >= this.work.length) {
- throw new NyARException();
- }
- // 追加アロケート範囲を計算
- int range = i_index + ARRAY_APPEND_STEP;
- if (range >= this.work.length) {
- range = this.work.length;
- }
- // アロケート
- for (int i = this.allocate_size; i < range; i++) {
- this.work2[i] = new int[8];
- }
- this.allocate_size = range;
- }
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/RawFileTest_X2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/RawFileTest_X2.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/RawFileTest_X2.java (revision 302)
@@ -80,7 +80,7 @@

// 1パターンのみを追跡するクラスを作成
// NyARSingleDetectMarker_Quad ar = new NyARSingleDetectMarker_Quad(ap, code, 80.0);
- NyARSingleDetectMarker_X2 ar = new NyARSingleDetectMarker_X2(ap, code, 80.0);
+ NyARSingleDetectMarker_X2 ar = new NyARSingleDetectMarker_X2(ap, code, 80.0,ra.getBufferReader().getBufferType());
NyARTransMatResult result_mat = new NyARTransMatResult();
ar.setContinueMode(false);
ar.detectMarkerLite(ra, 100);
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/VisualTest.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/VisualTest.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/VisualTest.java (revision 302)
@@ -18,9 +18,12 @@
import java.awt.*;

import jp.nyatla.nyartoolkit.core.labeling.*;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabeling_ARToolKit;
import jp.nyatla.nyartoolkit.core.param.*;
import jp.nyatla.nyartoolkit.core.raster.*;
import jp.nyatla.nyartoolkit.core.rasterfilter.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;
import jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs.*;
import jp.nyatla.nyartoolkit.core2.rasterfilter.gs2bin.*;
import jp.nyatla.utils.j2se.LabelingBufferdImage;
@@ -97,8 +100,7 @@
// 画像3
NyARLabelingImage limage = new NyARLabelingImage(320, 240);
NyARLabeling_ARToolKit labeling = new NyARLabeling_ARToolKit();
- labeling.attachDestination(limage);
- labeling.labeling(_binraster1);
+ labeling.labeling(_binraster1,limage);
this._bimg.drawImage(this._gsraster1);

NyARSquareStack stack = new NyARSquareStack(100);
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/SingleARMarkerProcesser_X2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/SingleARMarkerProcesser_X2.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/SingleARMarkerProcesser_X2.java (revision 302)
@@ -0,0 +1,353 @@
+/*
+ * Capture Test NyARToolkitCSサンプルプログラム
+ * --------------------------------------------------------------------------------
+ * Copyright (C)2008 R.Iizuka
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this framework; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.sandbox.x2;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.*;
+import jp.nyatla.nyartoolkit.core.match.*;
+import jp.nyatla.nyartoolkit.core.param.*;
+import jp.nyatla.nyartoolkit.core.pickup.*;
+import jp.nyatla.nyartoolkit.core.raster.*;
+import jp.nyatla.nyartoolkit.core.raster.rgb.*;
+import jp.nyatla.nyartoolkit.core.transmat.*;
+import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;
+import jp.nyatla.nyartoolkit.core.types.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.*;
+import jp.nyatla.nyartoolkit.core2.rasteranalyzer.threshold.NyARRasterThresholdAnalyzer_SlidePTile;
+
+/**
+ * このクラスは、同時に1個のマーカを処理することのできる、アプリケーションプロセッサです。
+ * マーカの出現・移動・消滅を、イベントで通知することができます。
+ * クラスには複数のマーカを登録できます。一つのマーカが見つかると、プロセッサは継続して同じマーカを
+ * 1つだけ認識し続け、見失うまでの間は他のマーカを認識しません。
+ *
+ * イベントは、 OnEnter→OnUpdate[n]→OnLeaveの順で発生します。
+ * マーカが見つかるとまずOnEnterが1度発生して、何番のマーカが発見されたかがわかります。
+ * 次にOnUpdateにより、現在の変換行列が連続して渡されます。最後にマーカを見失うと、OnLeave
+ * イベントが発生します。
+ *
+ */
+public abstract class SingleARMarkerProcesser_X2
+{
+ /**selectARCodeIndexFromListが値を返す時に使う変数型です。
+ */
+
+ private class TResult_selectARCodeIndex
+ {
+ public int direction;
+
+ public double confidence;
+
+ public int code_index;
+ }
+ /**オーナーが自由に使えるタグ変数です。
+ */
+ public Object tag;
+
+ private int _lost_delay_count = 0;
+
+ private int _lost_delay = 5;
+
+ private INyARSquareDetector _square_detect;
+
+ //<X2 patch>
+ protected NyARTransMat_X2 _transmat;
+ //</X2 patch>
+ private double _marker_width;
+
+ private NyARMatchPatt_Color_WITHOUT_PCA[] _match_patt;
+
+ private NyARSquareStack _square_list = new NyARSquareStack(100);
+
+ private INyARColorPatt _patt = null;
+
+ private double _cf_threshold_new = 0.30;
+ private double _cf_threshold_exist = 0.15;
+
+ private int _threshold = 110;
+ // [AR]検出結果の保存用
+ private NyARBinRaster _bin_raster;
+
+ private NyARRasterFilter_ARToolkitThreshold _tobin_filter;
+
+ protected int _current_arcode_index = -1;
+
+ private NyARMatchPattDeviationColorData _deviation_data;
+ private NyARRasterThresholdAnalyzer_SlidePTile _threshold_detect;
+
+ protected SingleARMarkerProcesser_X2()
+ {
+ return;
+ }
+
+
+ protected void initInstance(NyARParam i_param,int i_raster_type) throws NyARException
+ {
+ NyARIntSize scr_size = i_param.getScreenSize();
+ // 解析オブジェクトを作る
+//<X2 patch>
+ this._square_detect = new NyARSquareDetector_X2(i_param.getDistortionFactor(), scr_size);
+ this._transmat = new NyARTransMat_X2(i_param);
+//</X2 patch>
+
+ this._tobin_filter=new NyARRasterFilter_ARToolkitThreshold(110,i_raster_type);
+
+ // 2値画像バッファを作る
+ this._bin_raster = new NyARBinRaster(scr_size.w, scr_size.h);
+ this._threshold_detect=new NyARRasterThresholdAnalyzer_SlidePTile(15,i_raster_type,4);
+ return;
+ }
+
+ /**検出するマーカコードの配列を指定します。 検出状態でこの関数を実行すると、
+ * オブジェクト状態に強制リセットがかかります。
+ */
+ public void setARCodeTable(NyARCode[] i_ref_code_table, int i_code_resolution, double i_marker_width)
+ {
+ if (this._current_arcode_index != -1) {
+ // 強制リセット
+ reset(true);
+ }
+ //検出するマーカセット、情報、検出器を作り直す。(1ピクセル4ポイントサンプリング,マーカのパターン領域は50%)
+ this._patt = new NyARColorPatt_Perspective_O2(i_code_resolution, i_code_resolution,4,25);
+ this._deviation_data=new NyARMatchPattDeviationColorData(i_code_resolution, i_code_resolution);
+ this._marker_width = i_marker_width;
+
+ this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA[i_ref_code_table.length];
+ for(int i=0;i<i_ref_code_table.length;i++){
+ this._match_patt[i]=new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code_table[i]);
+ }
+ return;
+ }
+
+ public void reset(boolean i_is_force)
+ {
+ if (this._current_arcode_index != -1 && i_is_force == false) {
+ // 強制書き換えでなければイベントコール
+ this.onLeaveHandler();
+ }
+ // カレントマーカをリセット
+ this._current_arcode_index = -1;
+ return;
+ }
+
+ public void detectMarker(INyARRgbRaster i_raster) throws NyARException
+ {
+ // サイズチェック
+ assert(this._bin_raster.getSize().isEqualSize(i_raster.getSize().w, i_raster.getSize().h));
+
+ // コードテーブルが無ければここで終わり
+ if (this._match_patt== null) {
+ return;
+ }
+
+ // ラスタを(1/4の画像の)2値イメージに変換する.
+ this._tobin_filter.setThreshold(this._threshold);
+ this._tobin_filter.doFilter(i_raster, this._bin_raster);
+
+ NyARSquareStack square_stack = this._square_list;
+ // スクエアコードを探す
+ this._square_detect.detectMarker(this._bin_raster, square_stack);
+ // 認識処理
+ if (this._current_arcode_index == -1) { // マーカ未認識
+ detectNewMarker(i_raster, square_stack);
+ } else { // マーカ認識中
+ detectExistMarker(i_raster, square_stack, this._current_arcode_index);
+ }
+ return;
+ }
+
+
+ private final NyARMatchPattResult __detectMarkerLite_mr=new NyARMatchPattResult();
+
+ /**ARCodeのリストから、最も一致するコード番号を検索します。
+ */
+ private boolean selectARCodeIndexFromList(INyARRgbRaster i_raster, NyARSquare i_square, TResult_selectARCodeIndex o_result) throws NyARException
+ {
+ // 現在コードテーブルはアクティブ?
+ if (this._match_patt==null) {
+ return false;
+ }
+ // 評価基準になるパターンをイメージから切り出す
+ if (!this._patt.pickFromRaster(i_raster, i_square)) {
+ return false;
+ }
+ //評価データを作成して、評価器にセット
+ this._deviation_data.setRaster(this._patt);
+ final NyARMatchPattResult mr=this.__detectMarkerLite_mr;
+ int code_index = 0;
+ int dir = 0;
+ double c1 = 0;
+ // コードと比較する
+ for (int i = 0; i < this._match_patt.length; i++) {
+ this._match_patt[i].evaluate(this._deviation_data,mr);
+ double c2 = mr.confidence;
+ if (c1 < c2) {
+ code_index = i;
+ c1 = c2;
+ dir = mr.direction;
+ }
+ }
+ o_result.code_index = code_index;
+ o_result.direction = dir;
+ o_result.confidence = c1;
+ return true;
+ }
+
+ private TResult_selectARCodeIndex __detect_X_Marker_detect_result = new TResult_selectARCodeIndex();
+
+ /**新規マーカ検索 現在認識中のマーカがないものとして、最も認識しやすいマーカを1個認識します。
+ */
+ private void detectNewMarker(INyARRgbRaster i_raster, NyARSquareStack i_stack) throws NyARException
+ {
+ int number_of_square = i_stack.getLength();
+ double cf = 0;
+ int dir = 0;
+ int code_index = -1;
+ int square_index = 0;
+ TResult_selectARCodeIndex detect_result = this.__detect_X_Marker_detect_result;
+ for (int i = 0; i < number_of_square; i++) {
+ if (!selectARCodeIndexFromList(i_raster, (i_stack.getItem(i)), detect_result)) {
+ // 見つからない。
+ return;
+ }
+ if (detect_result.confidence < this._cf_threshold_new) {
+ continue;
+ }
+ if (detect_result.confidence < cf) {
+ // 一致度が低い。
+ continue;
+ }
+ cf = detect_result.confidence;
+ code_index = detect_result.code_index;
+ square_index = i;
+ dir = detect_result.direction;
+ }
+ // 認識状態を更新
+ final boolean is_id_found=updateStatus(this._square_list.getItem(square_index), code_index, cf, dir);
+ //閾値フィードバック(detectExistMarkerにもあるよ)
+ if(!is_id_found){
+ //マーカがなければ、探索+DualPTailで基準輝度検索
+ this._threshold_detect.analyzeRaster(i_raster);
+ this._threshold=(this._threshold+this._threshold_detect.getThreshold())/2;
+ }
+ }
+
+ /**マーカの継続認識 現在認識中のマーカを優先して認識します。
+ * (注)この機能はたぶん今後いろいろ発展するからNewと混ぜないこと。
+ */
+ private void detectExistMarker(INyARRgbRaster i_raster, NyARSquareStack i_stack, int i_current_id) throws NyARException
+ {
+ int number_of_square = i_stack.getLength();
+ double cf = 0;
+ int dir = 0;
+ int code_index = -1;
+ int square_index = 0;
+ TResult_selectARCodeIndex detect_result = this.__detect_X_Marker_detect_result;
+ for (int i = 0; i < number_of_square; i++) {
+ if (!selectARCodeIndexFromList(i_raster,i_stack.getItem(i), detect_result)) {
+ // 見つからない。
+ return;
+ }
+ // 現在のマーカを認識したか?
+ if (detect_result.code_index != i_current_id) {
+ // 認識中のマーカではないので無視
+ continue;
+ }
+ if (detect_result.confidence < this._cf_threshold_exist) {
+ continue;
+ }
+ if (detect_result.confidence < cf) {
+ // 一致度が高い方を選ぶ
+ continue;
+ }
+ cf = detect_result.confidence;
+ code_index = detect_result.code_index;
+ dir = detect_result.direction;
+ square_index = i;
+ }
+ // 認識状態を更新
+ final boolean is_id_found=updateStatus(this._square_list.getItem(square_index), code_index, cf, dir);
+ //閾値フィードバック(detectExistMarkerにもあるよ)
+ if(!is_id_found){
+ //マーカがなければ、探索+DualPTailで基準輝度検索
+ this._threshold_detect.analyzeRaster(i_raster);
+ this._threshold=(this._threshold+this._threshold_detect.getThreshold())/2;
+ }
+
+ }
+
+ private NyARTransMatResult __NyARSquare_result = new NyARTransMatResult();
+
+ /** オブジェクトのステータスを更新し、必要に応じてハンドル関数を駆動します。
+ * 戻り値は、「実際にマーカを発見する事ができたか」です。クラスの状態とは異なります。
+ */
+ private boolean updateStatus(NyARSquare i_square, int i_code_index, double i_cf, int i_dir) throws NyARException
+ {
+ NyARTransMatResult result = this.__NyARSquare_result;
+ if (this._current_arcode_index < 0) {// 未認識中
+ if (i_code_index < 0) {// 未認識から未認識の遷移
+ // なにもしないよーん。
+ return false;
+ } else {// 未認識から認識の遷移
+ this._current_arcode_index = i_code_index;
+ // イベント生成
+ // OnEnter
+ this.onEnterHandler(i_code_index);
+ // 変換行列を作成
+ this._transmat.transMat(i_square, i_dir, this._marker_width, result);
+ // OnUpdate
+ this.onUpdateHandler(i_square, result);
+ this._lost_delay_count = 0;
+ return true;
+ }
+ } else {// 認識中
+ if (i_code_index < 0) {// 認識から未認識の遷移
+ this._lost_delay_count++;
+ if (this._lost_delay < this._lost_delay_count) {
+ // OnLeave
+ this._current_arcode_index = -1;
+ this.onLeaveHandler();
+ }
+ return false;
+ } else if (i_code_index == this._current_arcode_index) {// 同じARCodeの再認識
+ // イベント生成
+ // 変換行列を作成
+ this._transmat.transMat(i_square, i_dir, this._marker_width, result);
+ // OnUpdate
+ this.onUpdateHandler(i_square, result);
+ this._lost_delay_count = 0;
+ return true;
+ } else {// 異なるコードの認識→今はサポートしない。
+ throw new NyARException();
+ }
+ }
+ }
+
+ protected abstract void onEnterHandler(int i_code);
+
+ protected abstract void onLeaveHandler();
+
+ protected abstract void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result);
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/SquareContourDetector_X2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/SquareContourDetector_X2.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/SquareContourDetector_X2.java (revision 302)
@@ -0,0 +1,215 @@
+package jp.nyatla.nyartoolkit.sandbox.x2;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.param.NyARCameraDistortionFactor;
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
+import jp.nyatla.nyartoolkit.core.types.NyARIntPoint2d;
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
+import jp.nyatla.nyartoolkit.core.types.NyARLinear;
+import jp.nyatla.nyartoolkit.core.squaredetect.*;
+import jp.nyatla.nyartoolkit.core2.types.NyARI64Linear;
+import jp.nyatla.nyartoolkit.core2.types.NyARI64Point2d;
+import jp.nyatla.nyartoolkit.core2.types.matrix.NyARI64Matrix22;
+
+public class SquareContourDetector_X2
+{
+ private final int PCA_LENGTH=20;
+ private final int[] _xpos=new int[PCA_LENGTH];
+ private final int[] _ypos=new int[PCA_LENGTH];
+ private final int[] __detectMarker_mkvertex = new int[5];
+ private final NyARFixedFloatVertexCounter __getSquareVertex_wv1 = new NyARFixedFloatVertexCounter();
+ private final NyARFixedFloatVertexCounter __getSquareVertex_wv2 = new NyARFixedFloatVertexCounter();
+ private final NyARFixedFloatPca2d _pca;
+ private final NyARI64Matrix22 __getSquareLine_evec=new NyARI64Matrix22();
+ private final NyARI64Point2d __getSquareLine_mean=new NyARI64Point2d();
+ private final NyARI64Point2d __getSquareLine_ev=new NyARI64Point2d();
+ private final NyARI64Linear[] __getSquareLine_i64liner=NyARI64Linear.createArray(4);
+ private final NyARFixedFloatObserv2IdealMap _dist_factor;
+ public SquareContourDetector_X2(NyARIntSize i_size,NyARCameraDistortionFactor i_distfactor_ref)
+ {
+ //歪み計算テーブルを作ると、8*width/height*2の領域を消費します。
+ //領域を取りたくない場合は、i_dist_factor_refの値をそのまま使ってください。
+ this._dist_factor = new NyARFixedFloatObserv2IdealMap(i_distfactor_ref,i_size);
+
+
+ // 輪郭バッファは頂点変換をするので、輪郭バッファの2倍取る。
+ this._pca=new NyARFixedFloatPca2d();
+ return;
+ }
+
+ public boolean coordToSquare(int[] i_xcoord,int[] i_ycoord,int i_st_index,int i_coord_num,int i_label_area,NyARSquare o_square) throws NyARException
+ {
+
+ final int[] mkvertex = this.__detectMarker_mkvertex;
+
+ // 頂点情報を取得
+ if (!getSquareVertex(i_xcoord, i_ycoord, i_st_index, i_coord_num, i_label_area, mkvertex)) {
+ // 頂点の取得が出来なかったので破棄
+ return false;
+ }
+ // マーカーを検出
+ if (!getSquareLine(mkvertex, i_xcoord, i_ycoord, o_square)){
+ // 矩形が成立しなかった。
+ return false;
+ }
+ return true;
+ }
+
+ private boolean getSquareLine(int[] i_mkvertex, int[] i_xcoord, int[] i_ycoord, NyARSquare o_square) throws NyARException
+ {
+ final NyARLinear[] l_line = o_square.line;
+ final NyARI64Matrix22 evec=this.__getSquareLine_evec;
+ final NyARI64Point2d mean=this.__getSquareLine_mean;
+ final NyARI64Point2d ev=this.__getSquareLine_ev;
+ final NyARI64Linear[] i64liner=this.__getSquareLine_i64liner;
+
+ for (int i = 0; i < 4; i++) {
+// final double w1 = (double) (i_mkvertex[i + 1] - i_mkvertex[i] + 1) * 0.05 + 0.5;
+ final int w1 = ((((i_mkvertex[i + 1] - i_mkvertex[i] + 1)<<8)*13)>>8) + (1<<7);
+ final int st = i_mkvertex[i] + (w1>>8);
+ final int ed = i_mkvertex[i + 1] - (w1>>8);
+ int n = ed - st + 1;
+ if (n < 2) {
+ // nが2以下でmatrix.PCAを計算することはできないので、エラー
+ return false;
+ }
+ //配列作成
+ n=this._dist_factor.observ2IdealSampling(i_xcoord, i_ycoord, st, n,this._xpos,this._ypos,PCA_LENGTH);
+ //主成分分析する。
+ this._pca.pcaF16(this._xpos,this._ypos, n,evec, ev,mean);
+ final NyARI64Linear l_line_i = i64liner[i];
+ l_line_i.run = evec.m01;// line[i][0] = evec->m[1];
+ l_line_i.rise = -evec.m00;// line[i][1] = -evec->m[0];
+ l_line_i.intercept = -((l_line_i.run * mean.x + l_line_i.rise * mean.y)>>16);// line[i][2] = -(line[i][0]*mean->v[0] + line[i][1]*mean->v[1]);
+ }
+
+ final NyARDoublePoint2d[] l_sqvertex = o_square.sqvertex;
+ final NyARIntPoint2d[] l_imvertex = o_square.imvertex;
+ for (int i = 0; i < 4; i++) {
+ final NyARI64Linear l_line_i = i64liner[i];
+ final NyARI64Linear l_line_2 = i64liner[(i + 3) % 4];
+ final long w1 =(l_line_2.run * l_line_i.rise - l_line_i.run * l_line_2.rise)>>16;
+ if (w1 == 0) {
+ return false;
+ }
+ l_sqvertex[i].x = (double)((l_line_2.rise * l_line_i.intercept - l_line_i.rise * l_line_2.intercept) / w1)/65536.0;
+ l_sqvertex[i].y = (double)((l_line_i.run * l_line_2.intercept - l_line_2.run * l_line_i.intercept) / w1)/65536.0;
+ // 頂点インデクスから頂点座標を得て保存
+ l_imvertex[i].x = i_xcoord[i_mkvertex[i]];
+ l_imvertex[i].y = i_ycoord[i_mkvertex[i]];
+ l_line[i].run=(double)l_line_i.run/65536.0;
+ l_line[i].rise=(double)l_line_i.rise/65536.0;
+ l_line[i].intercept=(double)l_line_i.intercept/65536.0;
+ }
+ return true;
+ }
+ private boolean getSquareVertex(int[] i_x_coord, int[] i_y_coord, int i_vertex1_index, int i_coord_num, int i_area, int[] o_vertex)
+ {
+ final NyARFixedFloatVertexCounter wv1 = this.__getSquareVertex_wv1;
+ final NyARFixedFloatVertexCounter wv2 = this.__getSquareVertex_wv2;
+ final int end_of_coord = i_vertex1_index + i_coord_num - 1;
+ final int sx = i_x_coord[i_vertex1_index];// sx = marker_info2->x_coord[0];
+ final int sy = i_y_coord[i_vertex1_index];// sy = marker_info2->y_coord[0];
+ int dmax = 0;
+ int v1 = i_vertex1_index;
+ for (int i = 1 + i_vertex1_index; i < end_of_coord; i++) {// for(i=1;i<marker_info2->coord_num-1;i++)
+ // {
+ final int d = (i_x_coord[i] - sx) * (i_x_coord[i] - sx) + (i_y_coord[i] - sy) * (i_y_coord[i] - sy);
+ if (d > dmax) {
+ dmax = d;
+ v1 = i;
+ }
+ }
+ //final double thresh = (i_area / 0.75) * 0.01;
+ final long thresh_f16 =(i_area<<16)/75;
+
+ o_vertex[0] = i_vertex1_index;
+
+ if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v1, thresh_f16)) { // if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,0,v1,thresh,wv1,&wvnum1)<
+ // 0 ) {
+ return false;
+ }
+ if (!wv2.getVertex(i_x_coord, i_y_coord, v1, end_of_coord, thresh_f16)) {// if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,v1,marker_info2->coord_num-1,thresh,wv2,&wvnum2)
+ // < 0) {
+ return false;
+ }
+
+ int v2;
+ if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {// if(wvnum1 == 1 && wvnum2== 1) {
+ o_vertex[1] = wv1.vertex[0];
+ o_vertex[2] = v1;
+ o_vertex[3] = wv2.vertex[0];
+ } else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0) {// }else if( wvnum1 > 1 && wvnum2== 0) {
+ //頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。
+ v2 = (v1-i_vertex1_index)/2+i_vertex1_index;
+ if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v2, thresh_f16)) {
+ return false;
+ }
+ if (!wv2.getVertex(i_x_coord, i_y_coord, v2, v1, thresh_f16)) {
+ return false;
+ }
+ if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
+ o_vertex[1] = wv1.vertex[0];
+ o_vertex[2] = wv2.vertex[0];
+ o_vertex[3] = v1;
+ } else {
+ return false;
+ }
+ } else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1) {
+ //v2 = (v1-i_vertex1_index+ end_of_coord-i_vertex1_index) / 2+i_vertex1_index;
+ v2 = (v1+ end_of_coord)/2;
+
+ if (!wv1.getVertex(i_x_coord, i_y_coord, v1, v2, thresh_f16)) {
+ return false;
+ }
+ if (!wv2.getVertex(i_x_coord, i_y_coord, v2, end_of_coord, thresh_f16)) {
+ return false;
+ }
+ if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
+ o_vertex[1] = v1;
+ o_vertex[2] = wv1.vertex[0];
+ o_vertex[3] = wv2.vertex[0];
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ o_vertex[4] = end_of_coord;
+ return true;
+ }
+
+ /**
+ * 輪郭線の矩形検出開始ポイントを特定して、座標を並べ替えます。
+ * 輪郭線の先頭から、対角線が最長になる点を1点検索し、それより前の区間をバッファの後方に接続します。
+ * 戻り値は対角線が最長になった点です。関数終了後、返却値+i_coord_numの要素が有効になります。
+ * @param i_xcoord
+ * @param i_ycoord
+ * @param i_coord_num
+ * @return
+ */
+ public static int normalizeCoord(int[] i_coord_x, int[] i_coord_y,int i_coord_num)
+ {
+ //
+ final int sx = i_coord_x[0];
+ final int sy = i_coord_y[0];
+ int d = 0;
+ int w, x, y;
+ int ret = 0;
+ for (int i = 1; i < i_coord_num; i++) {
+ x = i_coord_x[i] - sx;
+ y = i_coord_y[i] - sy;
+ w = x * x + y * y;
+ if (w > d) {
+ d = w;
+ ret = i;
+ }
+ // ここでうまく終了条件入れられないかな。
+ }
+ // vertex1を境界にして、後方に配列を連結
+ System.arraycopy(i_coord_x, 1, i_coord_x, i_coord_num, ret);
+ System.arraycopy(i_coord_y, 1, i_coord_y, i_coord_num, ret);
+ return ret;
+ }
+
+}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatObserv2IdealMap.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatObserv2IdealMap.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatObserv2IdealMap.java (revision 302)
@@ -44,6 +44,11 @@
private int _stride;
private int[] _mapx;
private int[] _mapy;
+ public NyARFixedFloatObserv2IdealMap(double[] i_map_x,double[] i_map_y,NyARIntSize i_screen_size)
+ {
+
+ }
+
public NyARFixedFloatObserv2IdealMap(NyARCameraDistortionFactor i_distfactor,NyARIntSize i_screen_size)
{
NyARDoublePoint2d opoint=new NyARDoublePoint2d();
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSingleDetectMarker_X2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSingleDetectMarker_X2.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSingleDetectMarker_X2.java (revision 302)
@@ -41,6 +41,9 @@
import jp.nyatla.nyartoolkit.core.transmat.*;
import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.NyARRasterFilter_ARToolkitThreshold;
+import jp.nyatla.nyartoolkit.core.squaredetect.INyARSquareDetector;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;


/**
@@ -81,13 +84,11 @@
* ARコードの物理サイズを、ミリメートルで指定します。
* @throws NyARException
*/
- public NyARSingleDetectMarker_X2(NyARParam i_param, NyARCode i_code, double i_marker_width) throws NyARException
+ public NyARSingleDetectMarker_X2(NyARParam i_param, NyARCode i_code, double i_marker_width,int i_raster_type) throws NyARException
{
final NyARIntSize scr_size=i_param.getScreenSize();
- final NyARFixedFloatObserv2IdealMap dist_map = new NyARFixedFloatObserv2IdealMap(i_param.getDistortionFactor(), scr_size);
-
// 解析オブジェクトを作る
- this._square_detect = new NyARSquareDetector_X2(dist_map,scr_size);
+ this._square_detect = new NyARSquareDetector_X2(i_param.getDistortionFactor(),scr_size);
this._transmat = new NyARTransMat_X2(i_param);
this._marker_width = i_marker_width;
int cw=i_code.getWidth();
@@ -100,11 +101,12 @@
this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h);
//差分データインスタンスの作成
this._deviation_data=new NyARMatchPattDeviationColorData(cw,ch);
+ this._tobin_filter=new NyARRasterFilter_ARToolkitThreshold(100,i_raster_type);
return;
}

private NyARBinRaster _bin_raster;
- private NyARRasterFilter_ARToolkitThreshold _tobin_filter=new NyARRasterFilter_ARToolkitThreshold(100);
+ private NyARRasterFilter_ARToolkitThreshold _tobin_filter;
private final NyARMatchPattResult __detectMarkerLite_mr=new NyARMatchPattResult();
private NyARMatchPattDeviationColorData _deviation_data;

@@ -148,7 +150,7 @@
double confidence = 0;
for(int i=0;i<number_of_square;i++){
// 評価基準になるパターンをイメージから切り出す
- if (!this._patt.pickFromRaster(i_raster, (NyARSquare)l_square_list.getItem(i))){
+ if (!this._patt.pickFromRaster(i_raster, l_square_list.getItem(i))){
continue;
}
//取得パターンをカラー差分データに変換して評価する。
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/JavaSimpleLite_X2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/JavaSimpleLite_X2.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/JavaSimpleLite_X2.java (revision 302)
@@ -157,13 +157,13 @@
NyARCode ar_code = new NyARCode(16, 16);
_ar_param.loadARParamFromFile(PARAM_FILE);
_ar_param.changeScreenSize(SCREEN_X, SCREEN_Y);
- _nya = new NyARSingleDetectMarker_X2(_ar_param, ar_code, 80.0);
- _nya.setContinueMode(false);//ここをtrueにすると、transMatContinueモード(History計算)になります。
ar_code.loadARPattFromFile(CARCODE_FILE);
//NyARToolkit用の支援クラス
_glnya = new NyARGLUtil(_gl);
//GL対応のRGBラスタオブジェクト
_cap_image = new GLNyARRaster_RGB(_ar_param,_capture.getCaptureFormat());
+ _nya = new NyARSingleDetectMarker_X2(_ar_param, ar_code, 80.0,this._cap_image.getBufferReader().getBufferType());
+ _nya.setContinueMode(false);//ここをtrueにすると、transMatContinueモード(History計算)になります。
//キャプチャ開始
_capture.start();
} catch (Exception e) {
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARTransMat_X2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARTransMat_X2.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARTransMat_X2.java (revision 302)
@@ -32,8 +32,8 @@
package jp.nyatla.nyartoolkit.sandbox.x2;

import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.NyARSquare;
import jp.nyatla.nyartoolkit.core.param.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
import jp.nyatla.nyartoolkit.core.transmat.*;
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.core2.types.*;
@@ -218,9 +218,6 @@

final NyARFixedFloat16Point3d angle=i_rot.refAngle();

- o_result.angle.x=(double)angle.x/NyMath.FIXEDFLOAT16_1;
- o_result.angle.y=(double)angle.y/NyMath.FIXEDFLOAT16_1;
- o_result.angle.z=(double)angle.z/NyMath.FIXEDFLOAT16_1;
o_result.has_value = true;
return;
}
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSquareDetector_X2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSquareDetector_X2.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSquareDetector_X2.java (revision 302)
@@ -32,11 +32,11 @@
package jp.nyatla.nyartoolkit.sandbox.x2;
import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.labeling.*;
+import jp.nyatla.nyartoolkit.core.labeling.rlelabeling.*;
import jp.nyatla.nyartoolkit.core.raster.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.*;
import jp.nyatla.nyartoolkit.core.types.*;
-import jp.nyatla.nyartoolkit.core2.types.*;
-import jp.nyatla.nyartoolkit.core2.types.matrix.NyARI64Matrix22;
-import jp.nyatla.nyartoolkit.core.*;
+import jp.nyatla.nyartoolkit.core.param.*;



@@ -47,35 +47,30 @@
*/
public class NyARSquareDetector_X2 implements INyARSquareDetector
{
- private static final int AR_AREA_MAX = 100000;// #define AR_AREA_MAX 100000
-
- private static final int AR_AREA_MIN = 70;// #define AR_AREA_MIN 70
private final int _width;
private final int _height;

- private final INyARLabeling _labeling;
+ private final LabelOverlapChecker<RleLabelFragmentInfoStack.RleLabelFragmentInfo> _overlap_checker = new LabelOverlapChecker<RleLabelFragmentInfoStack.RleLabelFragmentInfo>(32,RleLabelFragmentInfoStack.RleLabelFragmentInfo.class);
+ private final SquareContourDetector_X2 _sqconvertor;
+ private final ContourPickup _cpickup=new ContourPickup();
+ private final RleLabelFragmentInfoStack _stack;

- private final NyARLabelingImage _limage;
-
- private final OverlapChecker _overlap_checker = new OverlapChecker();
- private final NyARFixedFloatObserv2IdealMap _dist_factor_ref;
-// private final NyARFixFloatCameraDistortionFactorMap _dist_factor_ref;
- private final NyARFixedFloatPca2d _pca;
-// private final INyARPca2d _pca;
-
+
+
+ private final NyARLabeling_Rle _labeling;
/**
* 最大i_squre_max個のマーカーを検出するクラスを作成する。
*
* @param i_param
*/
- public NyARSquareDetector_X2(NyARFixedFloatObserv2IdealMap i_dist_factor_ref,NyARIntSize i_size) throws NyARException
+ public NyARSquareDetector_X2(NyARCameraDistortionFactor i_dist_factor_ref,NyARIntSize i_size) throws NyARException
{
this._width = i_size.w;
this._height = i_size.h;
- this._dist_factor_ref = i_dist_factor_ref;
- this._labeling = new NyARLabeling_ARToolKit_X2();
- this._limage = new NyARLabelingImage(this._width, this._height);
- this._labeling.attachDestination(this._limage);
+ this._labeling = new NyARLabeling_Rle(this._width,this._height);
+ this._sqconvertor=new SquareContourDetector_X2(i_size,i_dist_factor_ref);
+ this._stack=new RleLabelFragmentInfoStack(i_size.w*i_size.h*2048/(320*240)+32);//検出可能な最大ラベル数
+

// 輪郭の最大長は画面に映りうる最大の長方形サイズ。
int number_of_coord = (this._width + this._height) * 2;
@@ -84,26 +79,11 @@
this._max_coord = number_of_coord;
this._xcoord = new int[number_of_coord * 2];
this._ycoord = new int[number_of_coord * 2];
- //PCA
-
- this._pca=new NyARFixedFloatPca2d();
}
- private final int PCA_LENGTH=20;
-
private final int _max_coord;
private final int[] _xcoord;
private final int[] _ycoord;
- private final int[] _xpos=new int[PCA_LENGTH];
- private final int[] _ypos=new int[PCA_LENGTH];
-
- private void normalizeCoord(int[] i_coord_x, int[] i_coord_y, int i_index, int i_coord_num)
- {
- // vertex1を境界にして、後方に配列を連結
- System.arraycopy(i_coord_x, 1, i_coord_x, i_coord_num, i_index);
- System.arraycopy(i_coord_y, 1, i_coord_y, i_coord_num, i_index);
- }

- private final int[] __detectMarker_mkvertex = new int[5];

/**
* arDetectMarker2を基にした関数
@@ -117,65 +97,42 @@
*/
public final void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException
{
- final INyARLabeling labeling_proc = this._labeling;
- final NyARLabelingImage limage = this._limage;
+ final RleLabelFragmentInfoStack flagment=this._stack;
+ final LabelOverlapChecker<RleLabelFragmentInfoStack.RleLabelFragmentInfo> overlap = this._overlap_checker;

// 初期化

// マーカーホルダをリセット
o_square_stack.clear();

- // ラベリング
- labeling_proc.labeling(i_raster);
-
- // ラベル数が0ならここまで
- final int label_num = limage.getLabelStack().getLength();
+ // ラベル数が0ならここまで(Labeling内部でソートするようにした。)
+ final int label_num=this._labeling.labeling(i_raster, 0, i_raster.getHeight(), flagment);
if (label_num < 1) {
return;
}
+ //ラベルをソートしておく
+ flagment.sortByArea();
+ RleLabelFragmentInfoStack.RleLabelFragmentInfo[] labels=flagment.getArray();

- final NyARLabelingLabelStack stack = limage.getLabelStack();
- final NyARLabelingLabel[] labels = (NyARLabelingLabel[])stack.getArray();
-
-
- // ラベルを大きい順に整列
- stack.sortByArea();

- // デカいラベルを読み飛ばし
- int i;
- for (i = 0; i < label_num; i++) {
- // 検査対象内のラベルサイズになるまで無視
- if (labels[i].area <= AR_AREA_MAX) {
- break;
- }
- }
-
final int xsize = this._width;
final int ysize = this._height;
final int[] xcoord = this._xcoord;
final int[] ycoord = this._ycoord;
final int coord_max = this._max_coord;
- final int[] mkvertex = this.__detectMarker_mkvertex;
- final OverlapChecker overlap = this._overlap_checker;
- int coord_num;
- int label_area;
- NyARLabelingLabel label_pt;

//重なりチェッカの最大数を設定
- overlap.reset(label_num);
+ overlap.setMaxLabels(label_num);

- for (; i < label_num; i++) {
- label_pt = labels[i];
- label_area = label_pt.area;
- // 検査対象サイズよりも小さくなったら終了
- if (label_area < AR_AREA_MIN) {
- break;
- }
+ for (int i=0; i < label_num; i++) {
+ final RleLabelFragmentInfoStack.RleLabelFragmentInfo label_pt=labels[i];
+ final int label_area = label_pt.area;
+
// クリップ領域が画面の枠に接していれば除外
- if (label_pt.clip_l == 1 || label_pt.clip_r == xsize - 2) {// if(wclip[i*4+0] == 1 || wclip[i*4+1] ==xsize-2){
+ if (label_pt.clip_l == 0 || label_pt.clip_r == xsize-1){
continue;
}
- if (label_pt.clip_t == 1 || label_pt.clip_b == ysize - 2) {// if( wclip[i*4+2] == 1 || wclip[i*4+3] ==ysize-2){
+ if (label_pt.clip_t == 0 || label_pt.clip_b == ysize-1){
continue;
}
// 既に検出された矩形との重なりを確認
@@ -183,280 +140,27 @@
// 重なっているようだ。
continue;
}
-
+
// 輪郭を取得
- coord_num = limage.getContour(i, coord_max, xcoord, ycoord);
+ final int coord_num = _cpickup.getContour(i_raster,label_pt.entry_x,label_pt.clip_t, coord_max, xcoord, ycoord);
if (coord_num == coord_max) {
// 輪郭が大きすぎる。
continue;
}
- //頂点候補のインデクスを取得
- final int vertex1 = scanVertex(xcoord, ycoord, coord_num);
+ //輪郭分析用に正規化する。
+ final int vertex1 = SquareContourDetector_X2.normalizeCoord(xcoord, ycoord, coord_num);

- // 頂点候補(vertex1)を先頭に並べなおした配列を作成する。
- normalizeCoord(xcoord, ycoord, vertex1, coord_num);
-
- // 領域を準備する。
- NyARSquare square_ptr = (NyARSquare)o_square_stack.prePush();
-
- // 頂点情報を取得
- if (!getSquareVertex(xcoord, ycoord, vertex1, coord_num, label_area, mkvertex)) {
+ //ここから先が輪郭分析
+ NyARSquare square_ptr = o_square_stack.prePush();
+ if(!this._sqconvertor.coordToSquare(xcoord,ycoord,vertex1,coord_num,label_area,square_ptr)){
o_square_stack.pop();// 頂点の取得が出来なかったので破棄
- continue;
+ continue;
}
- // マーカーを検出
- if (!getSquareLine(mkvertex, xcoord, ycoord, square_ptr)) {
- // 矩形が成立しなかった。
- o_square_stack.pop();
- continue;
- }
// 検出済の矩形の属したラベルを重なりチェックに追加する。
overlap.push(label_pt);
- }
- return;
- }
-
- /**
- * 辺からの対角線が最長になる点を対角線候補として返す。
- *
- * @param i_xcoord
- * @param i_ycoord
- * @param i_coord_num
- * @return
- */
- private int scanVertex(int[] i_xcoord, int[] i_ycoord, int i_coord_num)
- {
- final int sx = i_xcoord[0];
- final int sy = i_ycoord[0];
- int d = 0;
- int w, x, y;
- int ret = 0;
- for (int i = 1; i < i_coord_num; i++) {
- x = i_xcoord[i] - sx;
- y = i_ycoord[i] - sy;
- w = x * x + y * y;
- if (w > d) {
- d = w;
- ret = i;
- }
- // ここでうまく終了条件入れられないかな。
}
- return ret;
+ return;
}
-
- private final NyARFixedFloatVertexCounter __getSquareVertex_wv1 = new NyARFixedFloatVertexCounter();
-
- private final NyARFixedFloatVertexCounter __getSquareVertex_wv2 = new NyARFixedFloatVertexCounter();
-
- /**
- * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor ) 関数の代替関数 OPTIMIZED STEP [450->415] o_squareに頂点情報をセットします。
- *
- * @param i_x_coord
- * @param i_y_coord
- * @param i_vertex1_index
- * @param i_coord_num
- * @param i_area
- * @param o_vertex
- * 要素数はint[4]である事
- * @return
- */
- private boolean getSquareVertex(int[] i_x_coord, int[] i_y_coord, int i_vertex1_index, int i_coord_num, int i_area, int[] o_vertex)
- {
- final NyARFixedFloatVertexCounter wv1 = this.__getSquareVertex_wv1;
- final NyARFixedFloatVertexCounter wv2 = this.__getSquareVertex_wv2;
- final int end_of_coord = i_vertex1_index + i_coord_num - 1;
- final int sx = i_x_coord[i_vertex1_index];// sx = marker_info2->x_coord[0];
- final int sy = i_y_coord[i_vertex1_index];// sy = marker_info2->y_coord[0];
- int dmax = 0;
- int v1 = i_vertex1_index;
- for (int i = 1 + i_vertex1_index; i < end_of_coord; i++) {// for(i=1;i<marker_info2->coord_num-1;i++)
- // {
- final int d = (i_x_coord[i] - sx) * (i_x_coord[i] - sx) + (i_y_coord[i] - sy) * (i_y_coord[i] - sy);
- if (d > dmax) {
- dmax = d;
- v1 = i;
- }
- }
- //final double thresh = (i_area / 0.75) * 0.01;
- final long thresh_f16 =(i_area<<16)/75;
-
- o_vertex[0] = i_vertex1_index;
-
- if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v1, thresh_f16)) { // if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,0,v1,thresh,wv1,&wvnum1)<
- // 0 ) {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v1, end_of_coord, thresh_f16)) {// if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,v1,marker_info2->coord_num-1,thresh,wv2,&wvnum2)
- // < 0) {
- return false;
- }
-
- int v2;
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {// if(wvnum1 == 1 && wvnum2== 1) {
- o_vertex[1] = wv1.vertex[0];
- o_vertex[2] = v1;
- o_vertex[3] = wv2.vertex[0];
- } else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0) {// }else if( wvnum1 > 1 && wvnum2== 0) {
- //頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。
- v2 = (v1-i_vertex1_index)/2+i_vertex1_index;
- if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v2, thresh_f16)) {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v2, v1, thresh_f16)) {
- return false;
- }
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
- o_vertex[1] = wv1.vertex[0];
- o_vertex[2] = wv2.vertex[0];
- o_vertex[3] = v1;
- } else {
- return false;
- }
- } else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1) {
- //v2 = (v1-i_vertex1_index+ end_of_coord-i_vertex1_index) / 2+i_vertex1_index;
- v2 = (v1+ end_of_coord)/2;
-
- if (!wv1.getVertex(i_x_coord, i_y_coord, v1, v2, thresh_f16)) {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v2, end_of_coord, thresh_f16)) {
- return false;
- }
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
- o_vertex[1] = v1;
- o_vertex[2] = wv1.vertex[0];
- o_vertex[3] = wv2.vertex[0];
- } else {
- return false;
- }
- } else {
- return false;
- }
- o_vertex[4] = end_of_coord;
- return true;
- }
-
- private final NyARI64Matrix22 __getSquareLine_evec=new NyARI64Matrix22();
- private final NyARI64Point2d __getSquareLine_mean=new NyARI64Point2d();
- private final NyARI64Point2d __getSquareLine_ev=new NyARI64Point2d();
- private final NyARI64Linear[] __getSquareLine_i64liner=NyARI64Linear.createArray(4);
-
- /**
- * arGetLine(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[4][3], double v[4][2]) arGetLine2(int x_coord[], int y_coord[], int
- * coord_num,int vertex[], double line[4][3], double v[4][2], double *dist_factor) の2関数の合成品です。 マーカーのvertex,lineを計算して、結果をo_squareに保管します。
- * Optimize:STEP[424->391]
- *
- * @param i_cparam
- * @return
- * @throws NyARException
- */
- private boolean getSquareLine(int[] i_mkvertex, int[] i_xcoord, int[] i_ycoord, NyARSquare o_square) throws NyARException
- {
- final NyARLinear[] l_line = o_square.line;
- final NyARI64Matrix22 evec=this.__getSquareLine_evec;
- final NyARI64Point2d mean=this.__getSquareLine_mean;
- final NyARI64Point2d ev=this.__getSquareLine_ev;
- final NyARI64Linear[] i64liner=this.__getSquareLine_i64liner;
-
- for (int i = 0; i < 4; i++) {
-// final double w1 = (double) (i_mkvertex[i + 1] - i_mkvertex[i] + 1) * 0.05 + 0.5;
- final int w1 = ((((i_mkvertex[i + 1] - i_mkvertex[i] + 1)<<8)*13)>>8) + (1<<7);
- final int st = i_mkvertex[i] + (w1>>8);
- final int ed = i_mkvertex[i + 1] - (w1>>8);
- int n = ed - st + 1;
- if (n < 2) {
- // nが2以下でmatrix.PCAを計算することはできないので、エラー
- return false;
- }
- //配列作成
- n=this._dist_factor_ref.observ2IdealSampling(i_xcoord, i_ycoord, st, n,this._xpos,this._ypos,PCA_LENGTH);
- //主成分分析する。
- this._pca.pcaF16(this._xpos,this._ypos, n,evec, ev,mean);
- final NyARI64Linear l_line_i = i64liner[i];
- l_line_i.run = evec.m01;// line[i][0] = evec->m[1];
- l_line_i.rise = -evec.m00;// line[i][1] = -evec->m[0];
- l_line_i.intercept = -((l_line_i.run * mean.x + l_line_i.rise * mean.y)>>16);// line[i][2] = -(line[i][0]*mean->v[0] + line[i][1]*mean->v[1]);
- }
-
- final NyARDoublePoint2d[] l_sqvertex = o_square.sqvertex;
- final NyARIntPoint2d[] l_imvertex = o_square.imvertex;
- for (int i = 0; i < 4; i++) {
- final NyARI64Linear l_line_i = i64liner[i];
- final NyARI64Linear l_line_2 = i64liner[(i + 3) % 4];
- final long w1 =(l_line_2.run * l_line_i.rise - l_line_i.run * l_line_2.rise)>>16;
- if (w1 == 0) {
- return false;
- }
- l_sqvertex[i].x = (double)((l_line_2.rise * l_line_i.intercept - l_line_i.rise * l_line_2.intercept) / w1)/65536.0;
- l_sqvertex[i].y = (double)((l_line_i.run * l_line_2.intercept - l_line_2.run * l_line_i.intercept) / w1)/65536.0;
- // 頂点インデクスから頂点座標を得て保存
- l_imvertex[i].x = i_xcoord[i_mkvertex[i]];
- l_imvertex[i].y = i_ycoord[i_mkvertex[i]];
- l_line[i].run=(double)l_line_i.run/65536.0;
- l_line[i].rise=(double)l_line_i.rise/65536.0;
- l_line[i].intercept=(double)l_line_i.intercept/65536.0;
- }
- return true;
- }
}


-/**
- * ラベル同士の重なり(内包関係)を調べるクラスです。
- * ラベルリストに内包するラベルを蓄積し、それにターゲットのラベルが内包されているか を確認します。
- */
-class OverlapChecker
-{
- private NyARLabelingLabel[] _labels = new NyARLabelingLabel[32];
-
- private int _length;
-
- /**
- * 最大i_max_label個のラベルを蓄積できるようにオブジェクトをリセットする
- *
- * @param i_max_label
- */
- public void reset(int i_max_label)
- {
- if (i_max_label > this._labels.length) {
- this._labels = new NyARLabelingLabel[i_max_label];
- }
- this._length = 0;
- }
-
- /**
- * チェック対象のラベルを追加する。
- *
- * @param i_label_ref
- */
- public void push(NyARLabelingLabel i_label_ref)
- {
- this._labels[this._length] = i_label_ref;
- this._length++;
- }
-
- /**
- * 現在リストにあるラベルと重なっているかを返す。
- *
- * @param i_label
- * @return 何れかのラベルの内側にあるならばfalse,独立したラベルである可能性が高ければtrueです.
- */
- public boolean check(NyARLabelingLabel i_label)
- {
- // 重なり処理かな?
- final NyARLabelingLabel[] label_pt = this._labels;
- final int px1 = (int) i_label.pos_x;
- final int py1 = (int) i_label.pos_y;
- for (int i = this._length - 1; i >= 0; i--) {
- final int px2 = (int) label_pt[i].pos_x;
- final int py2 = (int) label_pt[i].pos_y;
- final int d = (px1 - px2) * (px1 - px2) + (py1 - py2) * (py1 - py2);
- if (d < label_pt[i].area / 4) {
- // 対象外
- return false;
- }
- }
- // 対象
- return true;
- }
-}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotTransOptimize_O2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotTransOptimize_O2.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotTransOptimize_O2.java (revision 302)
@@ -269,7 +269,7 @@
}
io_rot.setAngle((int)a2,(int)b2,(int)c2);
/* printf("factor = %10.5f\n", factor*180.0/MD_PI); */
- return minerr /4;
+ return minerr /4;//この設定値おかしくね?16bitfixedfloatなら16で割らないと。
}


Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARQrCodeDetector.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARQrCodeDetector.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARQrCodeDetector.java (revision 302)
@@ -1,26 +1,22 @@
package jp.nyatla.nyartoolkit.sandbox.qrcode;

import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.INyARSquareDetector;
-import jp.nyatla.nyartoolkit.core.NyARSquare;
-import jp.nyatla.nyartoolkit.core.NyARSquareStack;
-import jp.nyatla.nyartoolkit.core.NyARVertexCounter;
-import jp.nyatla.nyartoolkit.core.labeling.INyARLabeling;
-import jp.nyatla.nyartoolkit.core.labeling.NyARLabelingImage;
-import jp.nyatla.nyartoolkit.core.labeling.NyARLabelingLabel;
-import jp.nyatla.nyartoolkit.core.labeling.NyARLabelingLabelStack;
-import jp.nyatla.nyartoolkit.core.labeling.NyARLabeling_ARToolKit;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabel;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabelStack;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabeling_ARToolKit;
import jp.nyatla.nyartoolkit.core.param.NyARCameraDistortionFactor;
-import jp.nyatla.nyartoolkit.core.pca2d.INyARPca2d;
-import jp.nyatla.nyartoolkit.core.pca2d.*;
import jp.nyatla.nyartoolkit.core.raster.NyARBinRaster;
+import jp.nyatla.nyartoolkit.core.squaredetect.ContourPickup;
+import jp.nyatla.nyartoolkit.core.squaredetect.INyARSquareDetector;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;
+import jp.nyatla.nyartoolkit.core.squaredetect.SquareContourDetector;
import jp.nyatla.nyartoolkit.core.types.*;
-import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix22;

public class NyARQrCodeDetector implements INyARSquareDetector
{
private NyARQrCodeSymbolBinder _binder;
- private static final double VERTEX_FACTOR = 2.0;// 線検出のファクタ

private static final int AR_AREA_MAX = 10000;

@@ -34,9 +30,9 @@

private final NyARLabelingImage _limage;

- private final NyARCameraDistortionFactor _dist_factor_ref;
- private final double[] _xpos;
- private final double[] _ypos;
+ private final SquareContourDetector _sqconvertor;
+ private final ContourPickup _cpickup=new ContourPickup();
+
/**
* 最大i_squre_max個のマーカーを検出するクラスを作成する。
*
@@ -46,11 +42,10 @@
{
this._width = i_size.w;
this._height = i_size.h;
- this._dist_factor_ref = i_dist_factor_ref;
this._labeling = new NyARLabeling_ARToolKit();
this._limage = new NyARLabelingImage(this._width, this._height);
- this._labeling.attachDestination(this._limage);
this._binder=new NyARQrCodeSymbolBinder(i_dist_factor_ref);
+ this._sqconvertor=new SquareContourDetector(i_size,i_dist_factor_ref);

// 輪郭の最大長はMAX_COORD_NUMの2倍に制限
int number_of_coord = MAX_COORD_NUM* 2;
@@ -59,8 +54,6 @@
this._max_coord = number_of_coord;
this._xcoord = new int[number_of_coord * 2];
this._ycoord = new int[number_of_coord * 2];
- this._xpos=new double[this._width+this._height];//最大辺長はthis._width+this._height
- this._ypos=new double[this._width+this._height];//最大辺長はthis._width+this._height

}

@@ -70,15 +63,7 @@

private final int[] _ycoord;

- private void normalizeCoord(int[] i_coord_x, int[] i_coord_y, int i_index, int i_coord_num)
- {
- // vertex1を境界にして、後方に配列を連結
- System.arraycopy(i_coord_x, 1, i_coord_x, i_coord_num, i_index);
- System.arraycopy(i_coord_y, 1, i_coord_y, i_coord_num, i_index);
- }

- private final int[] __detectMarker_mkvertex = new int[5];
-
/**
* ARMarkerInfo2 *arDetectMarker2( ARInt16 *limage, int label_num, int *label_ref,int *warea, double *wpos, int *wclip,int area_max, int area_min, double
* factor, int *marker_num ) 関数の代替品 ラベリング情報からマーカー一覧を作成してo_marker_listを更新します。 関数はo_marker_listに重なりを除外したマーカーリストを作成します。
@@ -91,7 +76,6 @@
*/
public final void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException
{
- final INyARLabeling labeling_proc = this._labeling;
final NyARLabelingImage limage = this._limage;

// 初期化
@@ -100,7 +84,7 @@
o_square_stack.clear();

// ラベリング
- labeling_proc.labeling(i_raster);
+ this._labeling.labeling(i_raster,limage);

// ラベル数が0ならここまで
final int label_num = limage.getLabelStack().getLength();
@@ -109,11 +93,10 @@
}

final NyARLabelingLabelStack stack = limage.getLabelStack();
- final NyARLabelingLabel[] labels = (NyARLabelingLabel[]) stack.getArray();
-
// ラベルを大きい順に整列
stack.sortByArea();

+ final NyARLabelingLabel[] labels = stack.getArray();
// デカいラベルを読み飛ばし
int i;
for (i = 0; i < label_num; i++) {
@@ -128,10 +111,9 @@
final int[] xcoord = this._xcoord;
final int[] ycoord = this._ycoord;
final int coord_max = this._max_coord;
- final int[] mkvertex = this.__detectMarker_mkvertex;
final int[] buf = (int[]) limage.getBufferReader().getBuffer();
final int[] indextable = limage.getIndexArray();
- int coord_num;
+
int label_area;
NyARLabelingLabel label_pt;
NyARSquareStack wk_stack=new NyARSquareStack(10);
@@ -155,29 +137,21 @@
if (!hasQrEdgeFeature(buf, indextable, label_pt)) {
continue;
}
-
// 輪郭を取得
- coord_num = limage.getContour(i, coord_max, xcoord, ycoord);
+ final int coord_num = _cpickup.getContour(limage,limage.getTopClipTangentX(label_pt),label_pt.clip_t, coord_max, xcoord, ycoord);
if (coord_num == coord_max) {
// 輪郭が大きすぎる。
continue;
}
- // 頂点候補のインデクスを取得
- final int vertex1 = scanVertex(xcoord, ycoord, coord_num);
+ //輪郭分析用に正規化する。
+ final int vertex1 = SquareContourDetector.normalizeCoord(xcoord, ycoord, coord_num);

- // 頂点候補(vertex1)を先頭に並べなおした配列を作成する。
- normalizeCoord(xcoord, ycoord, vertex1, coord_num);
-
- // 頂点情報を取得
- if (!getSquareVertex(xcoord, ycoord, vertex1, coord_num, label_area, mkvertex)) {
- continue;
+ //ここから先が輪郭分析
+ NyARSquare square_ptr = o_square_stack.prePush();
+ if(!this._sqconvertor.coordToSquare(xcoord,ycoord,vertex1,coord_num,label_area,square_ptr)){
+ o_square_stack.pop();// 頂点の取得が出来なかったので破棄
+ continue;
}
- NyARSquare square=(NyARSquare)wk_stack.prePush();
- //矩形からラインと観察座標を取得
- if(!getSquareLine(mkvertex,xcoord,ycoord,square.line,square.imvertex)){
- wk_stack.pop();
- continue;
- }
}
//シンボルの関連付け
bindQrcodeEdge(wk_stack,o_square_stack);
@@ -197,7 +171,7 @@
if(number_of_edge<3){
return;
}
- NyARSquare[] sa=(NyARSquare[])i_square_stack.getArray();
+ NyARSquare[] sa=i_square_stack.getArray();
for(int i=0;i<number_of_edge-2;i++)
{
group[0]=sa[i];
@@ -217,173 +191,8 @@
return;
}
private static int MAX_COORD_NUM=(320+240)*2;//サイズの1/2の長方形の編程度が目安(VGAなら(320+240)*2)
- private final INyARPca2d _pca=new NyARPca2d_MatrixPCA_O2();
- private final NyARDoubleMatrix22 __getSquareLine_evec=new NyARDoubleMatrix22();
- private final NyARDoublePoint2d __getSquareLine_mean=new NyARDoublePoint2d();
- private final NyARDoublePoint2d __getSquareLine_ev=new NyARDoublePoint2d();
- /**
- * 頂点インデクスと輪郭配列から、Ideal座標系とLineを作成して変数に返す
- * @param i_cparam
- * @return
- * @throws NyARException
- */
- private boolean getSquareLine(int[] i_mkvertex, int[] i_xcoord, int[] i_ycoord, NyARLinear[] o_line,NyARIntPoint2d[] o_imvertex) throws NyARException
- {
- final NyARDoubleMatrix22 evec=this.__getSquareLine_evec;
- final NyARDoublePoint2d mean=this.__getSquareLine_mean;
- final NyARDoublePoint2d ev=this.__getSquareLine_ev;
-
-
- for (int i = 0; i < 4; i++) {
- final double w1 = (double) (i_mkvertex[i + 1] - i_mkvertex[i] + 1) * 0.05 + 0.5;
- final int st = (int) (i_mkvertex[i] + w1);
- final int ed = (int) (i_mkvertex[i + 1] - w1);
- final int n = ed - st + 1;
- if (n < 2 || n>MAX_COORD_NUM) {
- // nが2以下、又はMAX_COORD_NUM以上なら主成分分析をしない。
- return false;
- }
- //配列作成
- this._dist_factor_ref.observ2IdealBatch(i_xcoord, i_ycoord, st, n,this._xpos,this._ypos);
-
- //主成分分析する。
- this._pca.pca(this._xpos,this._ypos,n,evec, ev,mean);
- final NyARLinear l_line_i = o_line[i];
- l_line_i.run = evec.m01;// line[i][0] = evec->m[1];
- l_line_i.rise = -evec.m00;// line[i][1] = -evec->m[0];
- l_line_i.intercept = -(l_line_i.run * mean.x + l_line_i.rise * mean.y);// line[i][2] = -(line[i][0]*mean->v[0] + line[i][1]*mean->v[1]);
- }
- for (int i = 0; i < 4; i++) {
- final NyARLinear l_line_i = o_line[i];
- final NyARLinear l_line_2 = o_line[(i + 3) % 4];
- final double w1 = l_line_2.run * l_line_i.rise - l_line_i.run * l_line_2.rise;
- if (w1 == 0.0) {
- return false;
- }
- // 頂点インデクスから頂点座標を得て保存
- o_imvertex[i].x = i_xcoord[i_mkvertex[i]];
- o_imvertex[i].y = i_ycoord[i_mkvertex[i]];
- }
- return true;
- }
- /**
- * 辺からの対角線が最長になる点を対角線候補として返す。
- *
- * @param i_xcoord
- * @param i_ycoord
- * @param i_coord_num
- * @return
- */
- private int scanVertex(int[] i_xcoord, int[] i_ycoord, int i_coord_num)
- {
- final int sx = i_xcoord[0];
- final int sy = i_ycoord[0];
- int d = 0;
- int w, x, y;
- int ret = 0;
- for (int i = 1; i < i_coord_num; i++) {
- x = i_xcoord[i] - sx;
- y = i_ycoord[i] - sy;
- w = x * x + y * y;
- if (w > d) {
- d = w;
- ret = i;
- }
- // ここでうまく終了条件入れられないかな。
- }
- return ret;
- }

- private final NyARVertexCounter __getSquareVertex_wv1 = new NyARVertexCounter();
- private final NyARVertexCounter __getSquareVertex_wv2 = new NyARVertexCounter();
-
/**
- * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor ) 関数の代替関数 OPTIMIZED STEP [450->415] o_squareに頂点情報をセットします。
- *
- * @param i_x_coord
- * @param i_y_coord
- * @param i_vertex1_index
- * @param i_coord_num
- * @param i_area
- * @param o_vertex
- * 要素数はint[4]である事
- * @return
- */
- private boolean getSquareVertex(int[] i_x_coord, int[] i_y_coord, int i_vertex1_index, int i_coord_num, int i_area, int[] o_vertex)
- {
- final NyARVertexCounter wv1 = this.__getSquareVertex_wv1;
- final NyARVertexCounter wv2 = this.__getSquareVertex_wv2;
- final int end_of_coord = i_vertex1_index + i_coord_num - 1;
- final int sx = i_x_coord[i_vertex1_index];// sx = marker_info2->x_coord[0];
- final int sy = i_y_coord[i_vertex1_index];// sy = marker_info2->y_coord[0];
- int dmax = 0;
- int v1 = i_vertex1_index;
- for (int i = 1 + i_vertex1_index; i < end_of_coord; i++) {// for(i=1;i<marker_info2->coord_num-1;i++)
- // {
- final int d = (i_x_coord[i] - sx) * (i_x_coord[i] - sx) + (i_y_coord[i] - sy) * (i_y_coord[i] - sy);
- if (d > dmax) {
- dmax = d;
- v1 = i;
- }
- }
- final double thresh = (i_area / 0.75) * 0.01 * VERTEX_FACTOR;
-
- o_vertex[0] = i_vertex1_index;
-
- if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v1, thresh)) { // if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,0,v1,thresh,wv1,&wvnum1)<
- // 0 ) {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v1, end_of_coord, thresh)) {// if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,v1,marker_info2->coord_num-1,thresh,wv2,&wvnum2)
- // < 0) {
- return false;
- }
-
- int v2;
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {// if(wvnum1 == 1 && wvnum2== 1) {
- o_vertex[1] = wv1.vertex[0];
- o_vertex[2] = v1;
- o_vertex[3] = wv2.vertex[0];
- } else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0) {// }else if( wvnum1 > 1 && wvnum2== 0) {
- // 頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。
- v2 = (v1 - i_vertex1_index) / 2 + i_vertex1_index;
- if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v2, thresh)) {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v2, v1, thresh)) {
- return false;
- }
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
- o_vertex[1] = wv1.vertex[0];
- o_vertex[2] = wv2.vertex[0];
- o_vertex[3] = v1;
- } else {
- return false;
- }
- } else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1) {
- // v2 = (v1-i_vertex1_index+ end_of_coord-i_vertex1_index) / 2+i_vertex1_index;
- v2 = (v1 + end_of_coord) / 2;
-
- if (!wv1.getVertex(i_x_coord, i_y_coord, v1, v2, thresh)) {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v2, end_of_coord, thresh)) {
- return false;
- }
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
- o_vertex[1] = v1;
- o_vertex[2] = wv1.vertex[0];
- o_vertex[3] = wv2.vertex[0];
- } else {
- return false;
- }
- } else {
- return false;
- }
- o_vertex[4] = end_of_coord;
- return true;
- }
- /**
* QRコードのシンボル特徴を持つラベルであるかを調べる
* @param buf
* @param index_table
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARQrCodeSymbolBinder.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARQrCodeSymbolBinder.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARQrCodeSymbolBinder.java (revision 302)
@@ -1,6 +1,7 @@
package jp.nyatla.nyartoolkit.sandbox.qrcode;

import jp.nyatla.nyartoolkit.core.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.core.param.*;
/**
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/SingleQrTest.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/SingleQrTest.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/SingleQrTest.java (revision 302)
@@ -12,14 +12,16 @@
import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.jmf.utils.*;

-import jp.nyatla.nyartoolkit.core.*;

import java.awt.*;

-import jp.nyatla.nyartoolkit.core.labeling.*;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabeling_ARToolKit;
import jp.nyatla.nyartoolkit.core.param.*;
import jp.nyatla.nyartoolkit.core.raster.*;
import jp.nyatla.nyartoolkit.core.rasterfilter.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;
import jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs.*;
import jp.nyatla.nyartoolkit.core2.rasterfilter.gs2bin.*;
import jp.nyatla.utils.j2se.LabelingBufferdImage;
@@ -96,8 +98,7 @@
// 画像3
NyARLabelingImage limage = new NyARLabelingImage(320, 240);
NyARLabeling_ARToolKit labeling = new NyARLabeling_ARToolKit();
- labeling.attachDestination(limage);
- labeling.labeling(_binraster1);
+ labeling.labeling(_binraster1,limage);
this._bimg.drawImage(this._gsraster1);

NyARSquareStack stack = new NyARSquareStack(100);
@@ -106,7 +107,7 @@

detect.detectMarker(_binraster1, stack);
for (int i = 0; i < stack.getLength(); i++) {
- NyARSquare[] square_ptr = (NyARSquare[]) stack.getArray();
+ NyARSquare[] square_ptr = stack.getArray();
int d=square_ptr[i].direction;
int[] xp=new int[4];
int[] yp=new int[4];
Index: D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARSingleQrDetector.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARSingleQrDetector.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARSingleQrDetector.java (revision 302)
@@ -37,6 +37,9 @@
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
import jp.nyatla.nyartoolkit.core.rasterfilter.*;
import jp.nyatla.nyartoolkit.core.raster.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.INyARSquareDetector;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;
import jp.nyatla.nyartoolkit.core.transmat.*;
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs.*;
@@ -76,7 +79,7 @@
final NyARIntSize scr_size=i_param.getScreenSize();
// 解析オブジェクトを作る
this._square_detect = new NyARQrCodeDetector(i_param.getDistortionFactor(),scr_size);
- this._transmat = new NyARTransMat(i_param);
+ this._transmat = new NyARTransMat_ARToolKit(i_param);
this._marker_width = i_marker_width;
//2値画像バッファを作る
this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h);
@@ -121,7 +124,7 @@
if (number_of_square < 1) {
return false;
}
- this._detected_square=(NyARSquare)l_square_list.getItem(0);
+ this._detected_square=l_square_list.getItem(0);
return true;
}

Index: D:/project.sorceforge/NyARToolkit/trunk/readme.ja.txt
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/readme.ja.txt (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/readme.ja.txt (revision 302)
@@ -1,7 +1,7 @@
ARToolKit Java class library NyARToolkit.
Copyright (C)2008 R.Iizuka

-version 2.3.1
+version 2.4.0

http://nyatla.jp/nyartoolkit/
airmail(at)ebony.plala.or.jp
@@ -11,7 +11,7 @@



-・NyARToolkit/2.3
+・NyARToolkit/2.4

NyARToolkitは、Pure Javaで実装したARToolKitクラスライブラリです。

@@ -29,18 +29,25 @@

・NyARToolkitの特徴

- -ARToolKitと同等な処理シーケンスを、クラスベースで再構築してあります。
+ -ARToolKitと同等な処理シーケンスを、クラスベースで再構築しています。

- -構造的な最適化により、ARToolKitと比較して可読性に優れています。
+ -ARToolKitと比較して、処理構造が最適化されています。

- -座標変換の演算性能が1.5倍ほど高速です。(JIT有効時)複数マーカー取り扱い時は、
-  オリジナルよりも良い成績が得られます。
+ -ARToolKit互換モードと、NyARToolkit最適化モードを搭載しています。(Version/2.4.0より)
+ 
+ --NyARToolkit最適化モード
+ いくつかのアルゴリズムをARToolKitのものと差換え、高速化・精度の向上を図ります。
+ ARToolKit比で、約2倍高速です。(JIT有効時)複数マーカー取り扱い時は、
+ 更に高速になります。ただし、計算結果はARToolKitのそれと若干ズレがでます。

- -取り扱える画像サイズに制限がありません。
+ --ARToolKit互換モード
+ ARToolKitのアルゴリズムを最適化し、高速化を図ります。
+ ARToolKit比で、約1倍高速です。(JIT有効時)

- -取り扱えるマーカー個数の最大値が可変です。
+ -取り扱える画像サイズに制限がありません。
+ -取り扱えるマーカー個数の最大値が可変です。
+ -Idマーカシステム(NyId)が利用できます。(Version/2.3.0より)

- -Idマーカシステム(NyId)が利用できます。(Version/2.3.0より)



@@ -67,8 +74,8 @@
NyARJMF/CaptureQT/NyARJog/NyARJ3dは、下位のキャプチャモジュール
や3Dライブラリを使いやすくするためのラッパークラス群です。

-各モジュールとNyARToolkitは容易に分離可能であり、個々を単独で
-使用することも可能です。
+各モジュールとNyARToolkitは分離可能であり、個々を単独で使用する
+ことも可能です。



@@ -175,24 +182,21 @@

・ライセンス

-NyARToolkitは、商用ライセンスとGPLv2以降のデュアルライセンスを採用しています。
+NyARToolkitは、商用ライセンスとGPLv3以降のデュアルライセンスを採用しています。
+(Version/2.4.0より、GPLv3ライセンスになりました。)

-GPLについては、LICENCE.txtをお読みください。
+ -GPL
+ GPLについては、LICENCE.txtをお読みください。

-商用ライセンスについては、ARToolWorks社に管理を委託しておりますので、
-下記URLを参考に、ARToolWorks社へお問い合わせください。
-http://nyatla.jp/nyartoolkit/wiki/index.php?Licence
+ -商用ライセンス
+ 商用ライセンスについては、ARToolWorks社に管理を委託しております。
+ http://www.artoolworks.com/Home.html

+ 日本国内での販売については、下記にお問い合わせ下さい。
+ http://www.msoft.co.jp/pressrelease/press090928-1.html

-ライセンスに関する日本語でのお問い合わせについては、下記URLの連絡先にて受け付けています。
-http://nyatla.jp/nyartoolkit/wiki/index.php?PressRelease%2F20090407%20forward%20order%20email%20service


-ソースコード毎のライセンスについては、ソースコード先頭の署名をご確認ください。
-
-
-
-
・謝辞

arc@dmzさん
Index: D:/project.sorceforge/NyARToolkit/trunk/src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java (revision 302)
@@ -69,7 +69,7 @@
this._capture.setCaptureFormat(scr_size.w, scr_size.h,15f);
this._capture.setOnCapture(this);
this._nya_raster = new J3dNyARRaster_RGB(this._cparam,this._capture.getCaptureFormat());
- this._nya = new NyARSingleDetectMarker(this._cparam, i_ar_code, i_marker_width);
+ this._nya = new NyARSingleDetectMarker(this._cparam, i_ar_code, i_marker_width,this._nya_raster.getBufferReader().getBufferType());
this._nya_behavior = new NyARBehavior(this._nya, this._nya_raster, i_rate);
}

Index: D:/project.sorceforge/NyARToolkit/trunk/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.jogl.utils;
Index: D:/project.sorceforge/NyARToolkit/trunk/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.jogl.utils;
Index: D:/project.sorceforge/NyARToolkit/trunk/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java (revision 302)
@@ -134,6 +134,14 @@
}
return;
}
+ public void setPixel(int i_x, int i_y, int[] i_rgb) throws NyARException
+ {
+ NyARException.notImplement();
+ }
+ public void setPixels(int[] i_x, int[] i_y, int i_num, int[] i_intrgb) throws NyARException
+ {
+ NyARException.notImplement();
+ }

}

@@ -223,6 +231,15 @@
}
return;
}
+ public void setPixel(int i_x, int i_y, int[] i_rgb) throws NyARException
+ {
+ NyARException.notImplement();
+ }
+ public void setPixels(int[] i_x, int[] i_y, int i_num, int[] i_intrgb) throws NyARException
+ {
+ NyARException.notImplement();
+ }
+
}


Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/processor/SingleARMarkerProcesser.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/processor/SingleARMarkerProcesser.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/processor/SingleARMarkerProcesser.java (revision 302)
@@ -1,25 +1,25 @@
/*
* Capture Test NyARToolkitCSサンプルプログラム
* --------------------------------------------------------------------------------
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.processor;
@@ -34,6 +34,8 @@
import jp.nyatla.nyartoolkit.core.transmat.*;
import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;
import jp.nyatla.nyartoolkit.core.types.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.*;
+import jp.nyatla.nyartoolkit.core2.rasteranalyzer.threshold.NyARRasterThresholdAnalyzer_SlidePTile;

/**
* このクラスは、同時に1個のマーカを処理することのできる、アプリケーションプロセッサです。
@@ -68,9 +70,9 @@

private int _lost_delay = 5;

- private NyARSquareDetector _square_detect;
+ private INyARSquareDetector _square_detect;

- protected NyARTransMat _transmat;
+ protected INyARTransMat _transmat;

private double _marker_width;

@@ -78,41 +80,48 @@

private NyARSquareStack _square_list = new NyARSquareStack(100);

- private NyARColorPatt_O3 _patt = null;
+ private INyARColorPatt _patt = null;

private double _cf_threshold_new = 0.30;
-
private double _cf_threshold_exist = 0.15;

private int _threshold = 110;
// [AR]検出結果の保存用
private NyARBinRaster _bin_raster;

- private NyARRasterFilter_ARToolkitThreshold _tobin_filter = new NyARRasterFilter_ARToolkitThreshold(110);
+ private NyARRasterFilter_ARToolkitThreshold _tobin_filter;

protected int _current_arcode_index = -1;

private NyARMatchPattDeviationColorData _deviation_data;
+ private NyARRasterThresholdAnalyzer_SlidePTile _threshold_detect;
+
+ protected SingleARMarkerProcesser()
+ {
+ return;
+ }


- public SingleARMarkerProcesser(NyARParam i_param) throws NyARException
+ protected void initInstance(NyARParam i_param,int i_raster_type) throws NyARException
{
NyARIntSize scr_size = i_param.getScreenSize();
// 解析オブジェクトを作る
- this._square_detect = new NyARSquareDetector(i_param.getDistortionFactor(), scr_size);
+ this._square_detect = new NyARSquareDetector_Rle(i_param.getDistortionFactor(), scr_size);
this._transmat = new NyARTransMat(i_param);
- this._deviation_data=new NyARMatchPattDeviationColorData(scr_size.w,scr_size.h);
+ this._tobin_filter=new NyARRasterFilter_ARToolkitThreshold(110,i_raster_type);

// 2値画像バッファを作る
this._bin_raster = new NyARBinRaster(scr_size.w, scr_size.h);
+ this._threshold_detect=new NyARRasterThresholdAnalyzer_SlidePTile(15,i_raster_type,4);
return;
}

+ /*自動・手動の設定が出来ないので、コメントアウト
public void setThreshold(int i_threshold)
{
this._threshold = i_threshold;
return;
- }
+ }*/

/**検出するマーカコードの配列を指定します。 検出状態でこの関数を実行すると、
* オブジェクト状態に強制リセットがかかります。
@@ -123,8 +132,9 @@
// 強制リセット
reset(true);
}
- // 検出するマーカセット、情報、検出器を作り直す。
- this._patt = new NyARColorPatt_O3(i_code_resolution, i_code_resolution);
+ //検出するマーカセット、情報、検出器を作り直す。(1ピクセル4ポイントサンプリング,マーカのパターン領域は50%)
+ this._patt = new NyARColorPatt_Perspective_O2(i_code_resolution, i_code_resolution,4,25);
+ this._deviation_data=new NyARMatchPattDeviationColorData(i_code_resolution, i_code_resolution);
this._marker_width = i_marker_width;

this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA[i_ref_code_table.length];
@@ -148,9 +158,7 @@
public void detectMarker(INyARRgbRaster i_raster) throws NyARException
{
// サイズチェック
- if (!this._bin_raster.getSize().isEqualSize(i_raster.getSize().w / 2, i_raster.getSize().h / 2)) {
- throw new NyARException();
- }
+ assert(this._bin_raster.getSize().isEqualSize(i_raster.getSize().w, i_raster.getSize().h));

// コードテーブルが無ければここで終わり
if (this._match_patt== null) {
@@ -223,7 +231,7 @@
int square_index = 0;
TResult_selectARCodeIndex detect_result = this.__detect_X_Marker_detect_result;
for (int i = 0; i < number_of_square; i++) {
- if (!selectARCodeIndexFromList(i_raster, (NyARSquare) i_stack.getItem(i), detect_result)) {
+ if (!selectARCodeIndexFromList(i_raster, (i_stack.getItem(i)), detect_result)) {
// 見つからない。
return;
}
@@ -240,7 +248,13 @@
dir = detect_result.direction;
}
// 認識状態を更新
- updateStatus((NyARSquare) this._square_list.getItem(square_index), code_index, cf, dir);
+ final boolean is_id_found=updateStatus(this._square_list.getItem(square_index), code_index, cf, dir);
+ //閾値フィードバック(detectExistMarkerにもあるよ)
+ if(!is_id_found){
+ //マーカがなければ、探索+DualPTailで基準輝度検索
+ this._threshold_detect.analyzeRaster(i_raster);
+ this._threshold=(this._threshold+this._threshold_detect.getThreshold())/2;
+ }
}

/**マーカの継続認識 現在認識中のマーカを優先して認識します。
@@ -255,7 +269,7 @@
int square_index = 0;
TResult_selectARCodeIndex detect_result = this.__detect_X_Marker_detect_result;
for (int i = 0; i < number_of_square; i++) {
- if (!selectARCodeIndexFromList(i_raster, (NyARSquare) i_stack.getItem(i), detect_result)) {
+ if (!selectARCodeIndexFromList(i_raster,i_stack.getItem(i), detect_result)) {
// 見つからない。
return;
}
@@ -277,19 +291,28 @@
square_index = i;
}
// 認識状態を更新
- updateStatus((NyARSquare) this._square_list.getItem(square_index), code_index, cf, dir);
+ final boolean is_id_found=updateStatus(this._square_list.getItem(square_index), code_index, cf, dir);
+ //閾値フィードバック(detectExistMarkerにもあるよ)
+ if(!is_id_found){
+ //マーカがなければ、探索+DualPTailで基準輝度検索
+ this._threshold_detect.analyzeRaster(i_raster);
+ this._threshold=(this._threshold+this._threshold_detect.getThreshold())/2;
+ }
+
}

private NyARTransMatResult __NyARSquare_result = new NyARTransMatResult();

- /**オブジェクトのステータスを更新し、必要に応じてハンドル関数を駆動します。
+ /** オブジェクトのステータスを更新し、必要に応じてハンドル関数を駆動します。
+ * 戻り値は、「実際にマーカを発見する事ができたか」です。クラスの状態とは異なります。
*/
- private void updateStatus(NyARSquare i_square, int i_code_index, double i_cf, int i_dir) throws NyARException
+ private boolean updateStatus(NyARSquare i_square, int i_code_index, double i_cf, int i_dir) throws NyARException
{
NyARTransMatResult result = this.__NyARSquare_result;
if (this._current_arcode_index < 0) {// 未認識中
if (i_code_index < 0) {// 未認識から未認識の遷移
// なにもしないよーん。
+ return false;
} else {// 未認識から認識の遷移
this._current_arcode_index = i_code_index;
// イベント生成
@@ -300,6 +323,7 @@
// OnUpdate
this.onUpdateHandler(i_square, result);
this._lost_delay_count = 0;
+ return true;
}
} else {// 認識中
if (i_code_index < 0) {// 認識から未認識の遷移
@@ -309,6 +333,7 @@
this._current_arcode_index = -1;
this.onLeaveHandler();
}
+ return false;
} else if (i_code_index == this._current_arcode_index) {// 同じARCodeの再認識
// イベント生成
// 変換行列を作成
@@ -316,11 +341,11 @@
// OnUpdate
this.onUpdateHandler(i_square, result);
this._lost_delay_count = 0;
+ return true;
} else {// 異なるコードの認識→今はサポートしない。
throw new NyARException();
}
}
- return;
}

protected abstract void onEnterHandler(int i_code);
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/processor/SingleNyIdMarkerProcesser.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/processor/SingleNyIdMarkerProcesser.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/processor/SingleNyIdMarkerProcesser.java (revision 302)
@@ -1,31 +1,30 @@
/*
- * Capture Test NyARToolkitCSサンプルプログラム
+ * Capture Test NyARToolkitサンプルプログラム
* --------------------------------------------------------------------------------
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.processor;

import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.*;
import jp.nyatla.nyartoolkit.core.param.*;
import jp.nyatla.nyartoolkit.core.raster.*;
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
@@ -35,6 +34,7 @@
import jp.nyatla.nyartoolkit.nyidmarker.*;
import jp.nyatla.nyartoolkit.nyidmarker.data.*;
import jp.nyatla.nyartoolkit.core2.rasteranalyzer.threshold.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.*;

public abstract class SingleNyIdMarkerProcesser
{
@@ -49,8 +49,8 @@
private int _lost_delay_count = 0;
private int _lost_delay = 5;

- private NyARSquareDetector _square_detect;
- protected NyARTransMat _transmat;
+ private NyARSquareDetector_Rle _square_detect;
+ protected INyARTransMat _transmat;
private double _marker_width=100;

private NyARSquareStack _square_list = new NyARSquareStack(100);
@@ -63,16 +63,20 @@
// [AR]検出結果の保存用
private NyARBinRaster _bin_raster;

- private NyARRasterFilter_ARToolkitThreshold _tobin_filter = new NyARRasterFilter_ARToolkitThreshold(110);
+ private NyARRasterFilter_ARToolkitThreshold _tobin_filter;

private NyIdMarkerPickup _id_pickup = new NyIdMarkerPickup();


- protected SingleNyIdMarkerProcesser(NyARParam i_param,INyIdMarkerDataEncoder i_encoder,int i_raster_format) throws NyARException
+ protected SingleNyIdMarkerProcesser()
{
+ return;
+ }
+ protected void initInstance(NyARParam i_param,INyIdMarkerDataEncoder i_encoder,int i_raster_format) throws NyARException
+ {
NyARIntSize scr_size = i_param.getScreenSize();
// 解析オブジェクトを作る
- this._square_detect = new NyARSquareDetector(i_param.getDistortionFactor(), scr_size);
+ this._square_detect = new NyARSquareDetector_Rle(i_param.getDistortionFactor(), scr_size);
this._transmat = new NyARTransMat(i_param);
this._encoder=i_encoder;

@@ -82,8 +86,10 @@
this._is_active=false;
this._data_temp=i_encoder.createDataInstance();
this._data_current=i_encoder.createDataInstance();
+ this._tobin_filter = new NyARRasterFilter_ARToolkitThreshold(110,i_raster_format);
this._threshold_detect=new NyARRasterThresholdAnalyzer_SlidePTile(15,i_raster_format,4);
return;
+
}

public void setMarkerWidth(int i_width)
@@ -130,7 +136,7 @@

private final NyIdMarkerPattern _marker_data=new NyIdMarkerPattern();
private final NyIdMarkerParam _marker_param=new NyIdMarkerParam();
- private final NyARRasterThresholdAnalyzer_SlidePTile _threshold_detect;
+ private NyARRasterThresholdAnalyzer_SlidePTile _threshold_detect;

/**新規マーカ検索 現在認識中のマーカがないものとして、最も認識しやすいマーカを1個認識します。
*/
@@ -143,7 +149,7 @@
INyIdMarkerData marker_id=null;
for (int i = 0; i < number_of_square; i++) {
// 評価基準になるパターンをイメージから切り出す
- current_square=(NyARSquare) i_stack.getItem(i);
+ current_square=i_stack.getItem(i);
if (!this._id_pickup.pickFromRaster(i_raster,current_square, patt_data, param)) {
continue;
}
@@ -184,7 +190,7 @@
INyIdMarkerData marker_id=null;
for (int i = 0; i < number_of_square; i++){
//idマーカを認識
- current_square=(NyARSquare) i_stack.getItem(i);
+ current_square=i_stack.getItem(i);
if (!this._id_pickup.pickFromRaster(i_raster, current_square, patt_data, param)) {
continue;
}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/sample/NyIdTest.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/sample/NyIdTest.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/sample/NyIdTest.java (revision 302)
@@ -0,0 +1,146 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.sample;
+
+import java.io.*;
+
+
+import jp.nyatla.nyartoolkit.core.param.NyARParam;
+import jp.nyatla.nyartoolkit.core.raster.rgb.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.transmat.*;
+import jp.nyatla.nyartoolkit.nyidmarker.data.*;
+import jp.nyatla.nyartoolkit.processor.*;
+
+/**
+ * 320x240のBGRA32で記録されたIdmarkerを撮影したRAWイメージから、
+ * Idマーカを認識します。
+ *
+ */
+public class NyIdTest
+{
+ public class MarkerProcessor extends SingleNyIdMarkerProcesser
+ {
+ private Object _sync_object = new Object();
+ public NyARTransMatResult transmat = null;
+ public int current_id = -1;
+
+ public MarkerProcessor(NyARParam i_cparam, int i_raster_format) throws Exception
+ {
+ super();//
+ initInstance(i_cparam, new NyIdMarkerDataEncoder_RawBit(), i_raster_format);
+ //アプリケーションフレームワークの初期化
+ return;
+ }
+ /**
+ * アプリケーションフレームワークのハンドラ(マーカ出現)
+ */
+ protected void onEnterHandler(INyIdMarkerData i_code)
+ {
+ synchronized (this._sync_object)
+ {
+ NyIdMarkerData_RawBit code = (NyIdMarkerData_RawBit)i_code;
+ if (code.length > 4)
+ {
+ //4バイト以上の時はint変換しない。
+ this.current_id = -1;//undefined_id
+ }
+ else
+ {
+ this.current_id = 0;
+ //最大4バイト繋げて1個のint値に変換
+ for (int i = 0; i < code.length; i++)
+ {
+ this.current_id = (this.current_id << 8) | code.packet[i];
+ }
+ }
+ this.transmat = null;
+ }
+ }
+ /**
+ * アプリケーションフレームワークのハンドラ(マーカ消滅)
+ */
+ protected void onLeaveHandler()
+ {
+ synchronized (this._sync_object)
+ {
+ this.current_id = -1;
+ this.transmat = null;
+ }
+ return;
+ }
+ /**
+ * アプリケーションフレームワークのハンドラ(マーカ更新)
+ */
+ protected void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result)
+ {
+ synchronized (this._sync_object)
+ {
+ this.transmat = result;
+ }
+ }
+ }
+ private final String data_file = "../Data/320x240NyId.raw";
+ private final String camera_file = "../Data/camera_para.dat";
+ public NyIdTest()
+ {
+ }
+ public void Test() throws Exception
+ {
+ //AR用カメラパラメタファイルをロード
+ NyARParam ap = new NyARParam();
+ ap.loadARParamFromFile(camera_file);
+ ap.changeScreenSize(320, 240);
+
+ // 試験イメージの読み出し(320x240 BGRAのRAWデータ)
+ File f = new File(data_file);
+ FileInputStream fs = new FileInputStream(data_file);
+ byte[] buf = new byte[(int) f.length()];
+ fs.read(buf);
+
+ NyARRgbRaster_RGB ra = NyARRgbRaster_RGB.wrap(buf, 320, 240);
+
+ MarkerProcessor pr = new MarkerProcessor(ap, ra.getBufferReader().getBufferType());
+ pr.detectMarker(ra);
+ return;
+ }
+ public static void main(String[] args)
+ {
+
+ try {
+ NyIdTest t = new NyIdTest();
+ // t.Test_arGetVersion();
+ t.Test();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/sample/SingleARMarkerTest.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/sample/SingleARMarkerTest.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/sample/SingleARMarkerTest.java (revision 302)
@@ -0,0 +1,122 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.sample;
+
+import java.io.*;
+
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.param.NyARParam;
+import jp.nyatla.nyartoolkit.core.raster.rgb.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.transmat.*;
+import jp.nyatla.nyartoolkit.core.*;
+import jp.nyatla.nyartoolkit.processor.*;
+
+public class SingleARMarkerTest
+{
+ class MarkerProcessor extends SingleARMarkerProcesser
+ {
+ private Object _sync_object=new Object();
+ public NyARTransMatResult transmat=null;
+ public int current_code=-1;
+
+ public MarkerProcessor(NyARParam i_cparam,int i_raster_format) throws NyARException
+ {
+ //アプリケーションフレームワークの初期化
+ super();
+ initInstance(i_cparam,i_raster_format);
+ return;
+ }
+ protected void onEnterHandler(int i_code)
+ {
+ synchronized(this._sync_object){
+ current_code=i_code;
+ }
+ }
+ protected void onLeaveHandler()
+ {
+ synchronized(this._sync_object){
+ current_code=-1;
+ this.transmat=null;
+ }
+ return;
+ }
+
+ protected void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result)
+ {
+ synchronized(this._sync_object){
+ this.transmat=result;
+ }
+ }
+ }
+ private final static String CARCODE_FILE = "../Data/patt.hiro";
+ private final static String PARAM_FILE = "../Data/camera_para.dat";
+ private final String data_file = "../Data/320x240ABGR.raw";
+
+ public SingleARMarkerTest()
+ {
+ }
+ public void Test() throws Exception
+ {
+ //AR用カメラパラメタファイルをロード
+ NyARParam ap = new NyARParam();
+ ap.loadARParamFromFile(PARAM_FILE);
+ ap.changeScreenSize(320, 240);
+
+ // 試験イメージの読み出し(320x240 BGRAのRAWデータ)
+ File f = new File(data_file);
+ FileInputStream fs = new FileInputStream(data_file);
+ byte[] buf = new byte[(int) f.length()];
+ fs.read(buf);
+
+ NyARRgbRaster_BGRA ra = NyARRgbRaster_BGRA.wrap(buf, 320, 240);
+
+ MarkerProcessor pr = new MarkerProcessor(ap, ra.getBufferReader().getBufferType());
+ NyARCode[] codes=new NyARCode[1];
+ codes[0]=new NyARCode(16,16);
+ codes[0].loadARPattFromFile(CARCODE_FILE);
+ pr.setARCodeTable(codes,16,80.0);
+ pr.detectMarker(ra);
+ return;
+ }
+ public static void main(String[] args)
+ {
+
+ try {
+ SingleARMarkerTest t = new SingleARMarkerTest();
+ // t.Test_arGetVersion();
+ t.Test();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/sample/RawFileTest.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/sample/RawFileTest.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/sample/RawFileTest.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.sample;
@@ -39,8 +38,8 @@
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
import jp.nyatla.nyartoolkit.core.transmat.*;
import jp.nyatla.nyartoolkit.detector.NyARSingleDetectMarker;
+import jp.nyatla.nyartoolkit.core.types.*;

-
/**
* 320x240のBGRA32で記録されたRAWイメージから、1種類のパターンを認識し、
* その変換行列を1000回求め、それにかかったミリ秒時間を表示します。
@@ -79,7 +78,8 @@
// Blank_Raster ra=new Blank_Raster(320, 240);

// 1パターンのみを追跡するクラスを作成
- NyARSingleDetectMarker ar = new NyARSingleDetectMarker(ap, code, 80.0);
+ NyARSingleDetectMarker ar = new NyARSingleDetectMarker(
+ ap, code, 80.0,ra.getBufferReader().getBufferType());
NyARTransMatResult result_mat = new NyARTransMatResult();
ar.setContinueMode(false);
ar.detectMarkerLite(ra, 100);
@@ -93,6 +93,8 @@
ar.getTransmationMatrix(result_mat);
}
Date d = new Date();
+ NyARDoublePoint3d ang=new NyARDoublePoint3d();
+ result_mat.getZXYAngle(ang);
System.out.println(d.getTime() - d2.getTime());
}

Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerPickup.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerPickup.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerPickup.java (revision 302)
@@ -1,40 +1,33 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.nyidmarker;

import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.NyARSquare;
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
import jp.nyatla.nyartoolkit.core.rasterreader.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.core.utils.*;

@@ -53,19 +46,12 @@
private NyARPerspectiveParamGenerator _param_gen=new NyARPerspectiveParamGenerator_O1(1,1,100,100);
private double[] _cparam=new double[8];

- private INyARRgbRaster _raster;
- private NyARIntSize _raster_size;

public PerspectivePixelReader()
{
return;
}
- public void setSourceRaster(INyARRgbRaster i_raster)
- {
- this._raster=i_raster;
- this._raster_size=i_raster.getSize();
- return;
- }
+
public boolean setSourceSquare(NyARIntPoint2d[] i_vertex)throws NyARException
{
return this._param_gen.getParam(i_vertex, this._cparam);
@@ -84,15 +70,14 @@
* @param o_pixel
* @throws NyARException
*/
- private boolean rectPixels(int i_lt_x,int i_lt_y,int i_step_x,int i_step_y,int i_width,int i_height,int i_out_st,int[] o_pixel)throws NyARException
+ private boolean rectPixels(INyARRgbPixelReader i_reader,NyARIntSize i_raster_size,int i_lt_x,int i_lt_y,int i_step_x,int i_step_y,int i_width,int i_height,int i_out_st,int[] o_pixel)throws NyARException
{
final double[] cpara=this._cparam;
- final INyARRgbPixelReader reader=this._raster.getRgbPixelReader();
final int[] ref_x=this._ref_x;
final int[] ref_y=this._ref_y;
final int[] pixcel_temp=this._pixcel_temp;
- final int raster_width=this._raster_size.w;
- final int raster_height=this._raster_size.h;
+ final int raster_width=i_raster_size.w;
+ final int raster_height=i_raster_size.h;

int out_index=i_out_st;
final double cpara_6=cpara[6];
@@ -121,7 +106,7 @@
pt++;
}
//1行分のピクセルを取得(場合によっては専用アクセサを書いた方がいい)
- reader.getPixelSet(ref_x,ref_y,i_width,pixcel_temp);
+ i_reader.getPixelSet(ref_x,ref_y,i_width,pixcel_temp);
//グレースケールにしながら、line→mapへの転写
for(int i2=0;i2<i_width;i2++){
int index=i2*3;
@@ -217,7 +202,7 @@
* @return
* @throws NyARException
*/
- public int getRowFrequency(int i_y1,int i_th_h,int i_th_l,int[] o_edge_index)throws NyARException
+ public int getRowFrequency(INyARRgbPixelReader i_reader,NyARIntSize i_raster_size,int i_y1,int i_th_h,int i_th_l,int[] o_edge_index)throws NyARException
{
//3,4,5,6,7,8,9,10
final int[] freq_count_table=this._freq_count_table;
@@ -225,7 +210,7 @@
final int freq_table[]=this._freq_table;
//初期化
final double[] cpara=this._cparam;
- final INyARRgbPixelReader reader=this._raster.getRgbPixelReader();
+// final INyARRgbPixelReader reader=this._raster.getRgbPixelReader();
final int[] ref_x=this._ref_x;
final int[] ref_y=this._ref_y;
final int[] pixcel_temp=this._pixcel_temp;
@@ -235,8 +220,8 @@
for(int i=0;i<110;i++){
freq_table[i]=0;
}
- final int raster_width=this._raster_size.w;
- final int raster_height=this._raster_size.h;
+ final int raster_width=i_raster_size.w;
+ final int raster_height=i_raster_size.h;

final double cpara_0=cpara[0];
final double cpara_3=cpara[3];
@@ -267,7 +252,7 @@
}

//ピクセルを取得(入力画像を多様化するならここから先を調整すること)
- reader.getPixelSet(ref_x,ref_y,FRQ_POINTS,pixcel_temp);
+ i_reader.getPixelSet(ref_x,ref_y,FRQ_POINTS,pixcel_temp);

//o_edge_indexを一時的に破壊して調査する
final int freq_t=getFreqInfo(pixcel_temp,i_th_h,i_th_l,o_edge_index);
@@ -290,10 +275,10 @@
return getMaxFreq(freq_count_table,freq_table,o_edge_index);
}

- public int getColFrequency(int i_x1,int i_th_h,int i_th_l,int[] o_edge_index)throws NyARException
+ public int getColFrequency(INyARRgbPixelReader i_reader,NyARIntSize i_raster_size,int i_x1,int i_th_h,int i_th_l,int[] o_edge_index)throws NyARException
{
final double[] cpara=this._cparam;
- final INyARRgbPixelReader reader=this._raster.getRgbPixelReader();
+// final INyARRgbPixelReader reader=this._raster.getRgbPixelReader();
final int[] ref_x=this._ref_x;
final int[] ref_y=this._ref_y;
final int[] pixcel_temp=this._pixcel_temp;
@@ -307,8 +292,8 @@
for(int i=0;i<110;i++){
freq_table[i]=0;
}
- final int raster_width=this._raster_size.w;
- final int raster_height=this._raster_size.h;
+ final int raster_width=i_raster_size.w;
+ final int raster_height=i_raster_size.h;


final double cpara7=cpara[7];
@@ -340,7 +325,7 @@
}

//ピクセルを取得(入力画像を多様化するならここを調整すること)
- reader.getPixelSet(ref_x,ref_y,FRQ_POINTS,pixcel_temp);
+ i_reader.getPixelSet(ref_x,ref_y,FRQ_POINTS,pixcel_temp);

final int freq_t=getFreqInfo(pixcel_temp,i_th_h,i_th_l,o_edge_index);
//周期は3-10であること
@@ -500,21 +485,21 @@
* @return
* @throws NyARException
*/
- public void detectThresholdValue(INyARRgbPixelReader i_reader,int i_x,int i_y,TThreshold o_threshold)throws NyARException
+ public void detectThresholdValue(INyARRgbPixelReader i_reader,NyARIntSize i_raster_size,TThreshold o_threshold)throws NyARException
{
final int[] th_pixels=this._th_pixels;

//左上のピックアップ領域からピクセルを得る(00-24)
- rectPixels(THRESHOLD_SAMPLE_LT,THRESHOLD_SAMPLE_LT,THRESHOLD_STEP,THRESHOLD_STEP,THRESHOLD_PIXEL,THRESHOLD_PIXEL,0,th_pixels);
+ rectPixels(i_reader,i_raster_size,THRESHOLD_SAMPLE_LT,THRESHOLD_SAMPLE_LT,THRESHOLD_STEP,THRESHOLD_STEP,THRESHOLD_PIXEL,THRESHOLD_PIXEL,0,th_pixels);

//左下のピックアップ領域からピクセルを得る(25-49)
- rectPixels(THRESHOLD_SAMPLE_LT,THRESHOLD_SAMPLE_RB,THRESHOLD_STEP,THRESHOLD_STEP,THRESHOLD_PIXEL,THRESHOLD_PIXEL,THRESHOLD_SAMPLE,th_pixels);
+ rectPixels(i_reader,i_raster_size,THRESHOLD_SAMPLE_LT,THRESHOLD_SAMPLE_RB,THRESHOLD_STEP,THRESHOLD_STEP,THRESHOLD_PIXEL,THRESHOLD_PIXEL,THRESHOLD_SAMPLE,th_pixels);

//右上のピックアップ領域からピクセルを得る(50-74)
- rectPixels(THRESHOLD_SAMPLE_RB,THRESHOLD_SAMPLE_LT,THRESHOLD_STEP,THRESHOLD_STEP,THRESHOLD_PIXEL,THRESHOLD_PIXEL,THRESHOLD_SAMPLE*2,th_pixels);
+ rectPixels(i_reader,i_raster_size,THRESHOLD_SAMPLE_RB,THRESHOLD_SAMPLE_LT,THRESHOLD_STEP,THRESHOLD_STEP,THRESHOLD_PIXEL,THRESHOLD_PIXEL,THRESHOLD_SAMPLE*2,th_pixels);

//右下のピックアップ領域からピクセルを得る(75-99)
- rectPixels(THRESHOLD_SAMPLE_RB,THRESHOLD_SAMPLE_RB,THRESHOLD_STEP,THRESHOLD_STEP,THRESHOLD_PIXEL,THRESHOLD_PIXEL,THRESHOLD_SAMPLE*3,th_pixels);
+ rectPixels(i_reader,i_raster_size,THRESHOLD_SAMPLE_RB,THRESHOLD_SAMPLE_RB,THRESHOLD_STEP,THRESHOLD_STEP,THRESHOLD_PIXEL,THRESHOLD_PIXEL,THRESHOLD_SAMPLE*3,th_pixels);

final THighAndLow hl=this.__detectThresholdValue_hl;
//Ptailで求めたピクセル平均
@@ -601,15 +586,14 @@
}
private int[] __detectDataBitsIndex_freq_index1=new int[FRQ_POINTS];
private int[] __detectDataBitsIndex_freq_index2=new int[FRQ_POINTS];
- private int detectDataBitsIndex(PerspectivePixelReader.TThreshold i_th,double[] o_index_row,double[] o_index_col) throws NyARException
+ private int detectDataBitsIndex(INyARRgbPixelReader i_reader,NyARIntSize i_raster_size,PerspectivePixelReader.TThreshold i_th,double[] o_index_row,double[] o_index_col) throws NyARException
{
//周波数を測定
final int[] freq_index1=this.__detectDataBitsIndex_freq_index1;
final int[] freq_index2=this.__detectDataBitsIndex_freq_index2;

-
- int frq_t=getRowFrequency(i_th.lt_y,i_th.th_h,i_th.th_l,freq_index1);
- int frq_b=getRowFrequency(i_th.rb_y,i_th.th_h,i_th.th_l,freq_index2);
+ int frq_t=getRowFrequency(i_reader,i_raster_size,i_th.lt_y,i_th.th_h,i_th.th_l,freq_index1);
+ int frq_b=getRowFrequency(i_reader,i_raster_size,i_th.rb_y,i_th.th_h,i_th.th_l,freq_index2);
//周波数はまとも?
if((frq_t<0 && frq_b<0) || frq_t==frq_b){
return -1;
@@ -630,8 +614,8 @@
}


- final int frq_l=getColFrequency(i_th.lt_x,i_th.th_h,i_th.th_l,freq_index1);
- final int frq_r=getColFrequency(i_th.rb_x,i_th.th_h,i_th.th_l,freq_index2);
+ final int frq_l=getColFrequency(i_reader,i_raster_size,i_th.lt_x,i_th.th_h,i_th.th_l,freq_index1);
+ final int frq_r=getColFrequency(i_reader,i_raster_size,i_th.rb_x,i_th.th_h,i_th.th_l,freq_index2);
//周波数はまとも?
if((frq_l<0 && frq_r<0) || frq_l==frq_r){
return -1;
@@ -665,12 +649,14 @@
private double[] __readDataBits_index_bit_x=new double[MAX_DATA_BITS*2];
private double[] __readDataBits_index_bit_y=new double[MAX_DATA_BITS*2];

- public boolean readDataBits(PerspectivePixelReader.TThreshold i_th,MarkerPattEncoder o_bitbuffer)throws NyARException
+ public boolean readDataBits(INyARRgbPixelReader i_reader,NyARIntSize i_raster_size,PerspectivePixelReader.TThreshold i_th,MarkerPattEncoder o_bitbuffer)throws NyARException
{
final double[] index_x=this.__readDataBits_index_bit_x;
final double[] index_y=this.__readDataBits_index_bit_y;
+
+
//読み出し位置を取得
- final int size=detectDataBitsIndex(i_th,index_x,index_y);
+ final int size=detectDataBitsIndex(i_reader,i_raster_size,i_th,index_x,index_y);
final int resolution=size+size-1;
if(size<0){
return false;
@@ -682,7 +668,6 @@
final double[] cpara=this._cparam;
final int[] ref_x=this._ref_x;
final int[] ref_y=this._ref_y;
- final INyARRgbPixelReader reader=this._raster.getRgbPixelReader();
final int[] pixcel_temp=this._pixcel_temp;

final double cpara_0=cpara[0];
@@ -741,7 +726,7 @@
pt++;
}
//1行分のピクセルを取得(場合によっては専用アクセサを書いた方がいい)
- reader.getPixelSet(ref_x,ref_y,resolution*4,pixcel_temp);
+ i_reader.getPixelSet(ref_x,ref_y,resolution*4,pixcel_temp);
//グレースケールにしながら、line→mapへの転写
for(int i2=0;i2<resolution;i2++){
int index=i2*3*4;
@@ -1060,22 +1045,23 @@
*/
public boolean pickFromRaster(INyARRgbRaster image, NyARSquare i_square,NyIdMarkerPattern o_data,NyIdMarkerParam o_param)throws NyARException
{
- this._perspective_reader.setSourceRaster(image);

//遠近法のパラメータを計算
if(!this._perspective_reader.setSourceSquare(i_square.imvertex)){
return false;
};

- final INyARRgbPixelReader reader=image.getRgbPixelReader();
+ INyARRgbPixelReader reader=image.getRgbPixelReader();
+ NyARIntSize raster_size=image.getSize();
+


final PerspectivePixelReader.TThreshold th=this.__pickFromRaster_th;
final MarkerPattEncoder encoder=this.__pickFromRaster_encoder;
//マーカパラメータを取得
- this._perspective_reader.detectThresholdValue(reader,10,10,th);
+ this._perspective_reader.detectThresholdValue(reader,raster_size,th);

- if(!this._perspective_reader.readDataBits(th, encoder)){
+ if(!this._perspective_reader.readDataBits(reader,raster_size,th, encoder)){
return false;
}
final int d=encoder.encode(o_data);
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerPattern.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerPattern.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerPattern.java (revision 302)
@@ -1,32 +1,25 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.nyidmarker;
@@ -42,5 +35,5 @@
public int ctrl_domain;
public int ctrl_mask;
public int check;
- public int[] data=new int[32];
+ public final int[] data=new int[32];
}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerParam.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerParam.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerParam.java (revision 302)
@@ -1,32 +1,25 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.nyidmarker;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/NyIdMarkerDataEncoder_RawBit.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/NyIdMarkerDataEncoder_RawBit.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/NyIdMarkerDataEncoder_RawBit.java (revision 302)
@@ -1,32 +1,25 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.nyidmarker.data;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/NyIdMarkerData_RawBit.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/NyIdMarkerData_RawBit.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/NyIdMarkerData_RawBit.java (revision 302)
@@ -1,32 +1,25 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.nyidmarker.data;
@@ -37,7 +30,7 @@
*/
public class NyIdMarkerData_RawBit implements INyIdMarkerData
{
- public int[] packet=new int[22];
+ public final int[] packet=new int[22];
public int length;
public boolean isEqual(INyIdMarkerData i_target)
{
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/INyIdMarkerData.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/INyIdMarkerData.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/INyIdMarkerData.java (revision 302)
@@ -1,32 +1,25 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.nyidmarker.data;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/INyIdMarkerDataEncoder.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/INyIdMarkerDataEncoder.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/INyIdMarkerDataEncoder.java (revision 302)
@@ -1,32 +1,25 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.nyidmarker.data;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/NyARException.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/NyARException.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/NyARException.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARVertexCounter.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARVertexCounter.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARVertexCounter.java (revision 302)
@@ -1,72 +0,0 @@
-package jp.nyatla.nyartoolkit.core;
-
-/**
- * get_vertex関数を切り離すためのクラス
- *
- */
-final public class NyARVertexCounter
-{
- public final int[] vertex = new int[10];// 6まで削れる
-
- public int number_of_vertex;
-
- private double thresh;
-
- private int[] x_coord;
-
- private int[] y_coord;
-
- public boolean getVertex(int[] i_x_coord, int[] i_y_coord, int st, int ed, double i_thresh)
- {
- this.number_of_vertex = 0;
- this.thresh = i_thresh;
- this.x_coord = i_x_coord;
- this.y_coord = i_y_coord;
- return get_vertex(st, ed);
- }
-
- /**
- * static int get_vertex( int x_coord[], int y_coord[], int st, int ed,double thresh, int vertex[], int *vnum) 関数の代替関数
- *
- * @param x_coord
- * @param y_coord
- * @param st
- * @param ed
- * @param thresh
- * @return
- */
- private boolean get_vertex(int st, int ed)
- {
- //メモ:座標値は65536を超えなければint32で扱って大丈夫なので変更。
- //dmaxは4乗なのでやるとしてもint64じゃないとマズイ
- int v1 = 0;
- final int[] lx_coord = this.x_coord;
- final int[] ly_coord = this.y_coord;
- final int a = ly_coord[ed] - ly_coord[st];
- final int b = lx_coord[st] - lx_coord[ed];
- final int c = lx_coord[ed] * ly_coord[st] - ly_coord[ed] * lx_coord[st];
- double dmax = 0;
- for (int i = st + 1; i < ed; i++) {
- final double d = a * lx_coord[i] + b * ly_coord[i] + c;
- if (d * d > dmax) {
- dmax = d * d;
- v1 = i;
- }
- }
- if (dmax / (double)(a * a + b * b) > thresh) {
- if (!get_vertex(st, v1)) {
- return false;
- }
- if (number_of_vertex > 5) {
- return false;
- }
- vertex[number_of_vertex] = v1;// vertex[(*vnum)] = v1;
- number_of_vertex++;// (*vnum)++;
-
- if (!get_vertex(v1, ed)) {
- return false;
- }
- }
- return true;
- }
-}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARSquareStack.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARSquareStack.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARSquareStack.java (revision 302)
@@ -1,50 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core;
-
-import jp.nyatla.utils.*;
-
-public class NyARSquareStack extends NyObjectStack
-{
- public NyARSquareStack(int i_length)
- {
- super(new NyARSquare[i_length]);
-
- }
-
- protected void onReservRequest(int i_start, int i_end, Object[] i_buffer)
- {
- for (int i = i_start; i < i_end; i++) {
- i_buffer[i] = new NyARSquare();
- }
- }
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARSquareDetector.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARSquareDetector.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARSquareDetector.java (revision 302)
@@ -1,459 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core;
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.labeling.*;
-import jp.nyatla.nyartoolkit.core.raster.*;
-import jp.nyatla.nyartoolkit.core.types.*;
-import jp.nyatla.nyartoolkit.core.param.*;
-import jp.nyatla.nyartoolkit.core.pca2d.NyARPca2d_MatrixPCA_O2;
-import jp.nyatla.nyartoolkit.core.types.matrix.*;
-import jp.nyatla.nyartoolkit.core.pca2d.*;
-
-
-
-
-/**
- * イメージから正方形候補を検出するクラス。
- * このクラスは、arDetectMarker2.cとの置き換えになります。
- *
- */
-public class NyARSquareDetector implements INyARSquareDetector
-{
- private static final double VERTEX_FACTOR = 1.0;// 線検出のファクタ
- private static final int AR_AREA_MAX = 100000;// #define AR_AREA_MAX 100000
- private static final int AR_AREA_MIN = 70;// #define AR_AREA_MIN 70
- private final int _width;
- private final int _height;
-
- private final NyARLabeling_ARToolKit _labeling;
-
- private final NyARLabelingImage _limage;
-
- private final OverlapChecker _overlap_checker = new OverlapChecker();
- private final NyARObserv2IdealMap _dist_factor;
-
- private final double[] _xpos;
- private final double[] _ypos;
-
- /**
- * 最大i_squre_max個のマーカーを検出するクラスを作成する。
- *
- * @param i_param
- */
- public NyARSquareDetector(NyARCameraDistortionFactor i_dist_factor_ref,NyARIntSize i_size) throws NyARException
- {
- this._width = i_size.w;
- this._height = i_size.h;
- //歪み計算テーブルを作ると、8*width/height*2の領域を消費します。
- //領域を取りたくない場合は、i_dist_factor_refの値をそのまま使ってください。
- this._dist_factor = new NyARObserv2IdealMap(i_dist_factor_ref,i_size);
- this._labeling = new NyARLabeling_ARToolKit();
- this._limage = new NyARLabelingImage(this._width, this._height);
- this._labeling.attachDestination(this._limage);
-
- // 輪郭の最大長は画面に映りうる最大の長方形サイズ。
- int number_of_coord = (this._width + this._height) * 2;
-
- // 輪郭バッファは頂点変換をするので、輪郭バッファの2倍取る。
- this._max_coord = number_of_coord;
- this._xcoord = new int[number_of_coord * 2];
- this._ycoord = new int[number_of_coord * 2];
- this._pca=new NyARPca2d_MatrixPCA_O2();
- this._xpos=new double[this._width+this._height];//最大辺長はthis._width+this._height
- this._ypos=new double[this._width+this._height];//最大辺長はthis._width+this._height
- return;
- }
-
- private final int _max_coord;
- private final int[] _xcoord;
- private final int[] _ycoord;
-
- private void normalizeCoord(int[] i_coord_x, int[] i_coord_y, int i_index, int i_coord_num)
- {
- // vertex1を境界にして、後方に配列を連結
- System.arraycopy(i_coord_x, 1, i_coord_x, i_coord_num, i_index);
- System.arraycopy(i_coord_y, 1, i_coord_y, i_coord_num, i_index);
- }
-
- private final int[] __detectMarker_mkvertex = new int[5];
-
- /**
- * arDetectMarker2を基にした関数
- * この関数はNyARSquare要素のうち、directionを除くパラメータを取得して返します。
- * directionの確定は行いません。
- * @param i_raster
- * 解析する2値ラスタイメージを指定します。
- * @param o_square_stack
- * 抽出した正方形候補を格納するリスト
- * @throws NyARException
- */
- public final void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException
- {
- final NyARLabelingImage limage = this._limage;
-
- // 初期化
-
- // マーカーホルダをリセット
- o_square_stack.clear();
-
- // ラベリング
- this._labeling.labeling(i_raster);
-
- // ラベル数が0ならここまで
- final int label_num = limage.getLabelStack().getLength();
- if (label_num < 1) {
- return;
- }
-
- final NyARLabelingLabelStack stack = limage.getLabelStack();
- final NyARLabelingLabel[] labels = (NyARLabelingLabel[])stack.getArray();
-
-
- // ラベルを大きい順に整列
- stack.sortByArea();
-
- // デカいラベルを読み飛ばし
- int i;
- for (i = 0; i < label_num; i++) {
- // 検査対象内のラベルサイズになるまで無視
- if (labels[i].area <= AR_AREA_MAX) {
- break;
- }
- }
-
- final int xsize = this._width;
- final int ysize = this._height;
- final int[] xcoord = this._xcoord;
- final int[] ycoord = this._ycoord;
- final int coord_max = this._max_coord;
- final int[] mkvertex = this.__detectMarker_mkvertex;
- final OverlapChecker overlap = this._overlap_checker;
- int coord_num;
- int label_area;
- NyARLabelingLabel label_pt;
-
- //重なりチェッカの最大数を設定
- overlap.reset(label_num);
-
- for (; i < label_num; i++) {
- label_pt = labels[i];
- label_area = label_pt.area;
- // 検査対象サイズよりも小さくなったら終了
- if (label_area < AR_AREA_MIN) {
- break;
- }
- // クリップ領域が画面の枠に接していれば除外
- if (label_pt.clip_l == 1 || label_pt.clip_r == xsize - 2) {// if(wclip[i*4+0] == 1 || wclip[i*4+1] ==xsize-2){
- continue;
- }
- if (label_pt.clip_t == 1 || label_pt.clip_b == ysize - 2) {// if( wclip[i*4+2] == 1 || wclip[i*4+3] ==ysize-2){
- continue;
- }
- // 既に検出された矩形との重なりを確認
- if (!overlap.check(label_pt)) {
- // 重なっているようだ。
- continue;
- }
-
- // 輪郭を取得
- coord_num = limage.getContour(i, coord_max, xcoord, ycoord);
- if (coord_num == coord_max) {
- // 輪郭が大きすぎる。
- continue;
- }
- //頂点候補のインデクスを取得
- final int vertex1 = scanVertex(xcoord, ycoord, coord_num);
-
- // 頂点候補(vertex1)を先頭に並べなおした配列を作成する。
- normalizeCoord(xcoord, ycoord, vertex1, coord_num);
-
- // 領域を準備する。
- NyARSquare square_ptr = (NyARSquare)o_square_stack.prePush();
-
- // 頂点情報を取得
- if (!getSquareVertex(xcoord, ycoord, vertex1, coord_num, label_area, mkvertex)) {
- o_square_stack.pop();// 頂点の取得が出来なかったので破棄
- continue;
- }
- // マーカーを検出
- if (!getSquareLine(mkvertex, xcoord, ycoord, square_ptr)) {
- // 矩形が成立しなかった。
- o_square_stack.pop();
- continue;
- }
- // 検出済の矩形の属したラベルを重なりチェックに追加する。
- overlap.push(label_pt);
- }
- return;
- }
-
- /**
- * 辺からの対角線が最長になる点を対角線候補として返す。
- *
- * @param i_xcoord
- * @param i_ycoord
- * @param i_coord_num
- * @return
- */
- private int scanVertex(int[] i_xcoord, int[] i_ycoord, int i_coord_num)
- {
- final int sx = i_xcoord[0];
- final int sy = i_ycoord[0];
- int d = 0;
- int w, x, y;
- int ret = 0;
- for (int i = 1; i < i_coord_num; i++) {
- x = i_xcoord[i] - sx;
- y = i_ycoord[i] - sy;
- w = x * x + y * y;
- if (w > d) {
- d = w;
- ret = i;
- }
- // ここでうまく終了条件入れられないかな。
- }
- return ret;
- }
-
- private final NyARVertexCounter __getSquareVertex_wv1 = new NyARVertexCounter();
-
- private final NyARVertexCounter __getSquareVertex_wv2 = new NyARVertexCounter();
-
- /**
- * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor ) 関数の代替関数 OPTIMIZED STEP [450->415] o_squareに頂点情報をセットします。
- *
- * @param i_x_coord
- * @param i_y_coord
- * @param i_vertex1_index
- * @param i_coord_num
- * @param i_area
- * @param o_vertex
- * 要素数はint[4]である事
- * @return
- */
- private boolean getSquareVertex(int[] i_x_coord, int[] i_y_coord, int i_vertex1_index, int i_coord_num, int i_area, int[] o_vertex)
- {
- final NyARVertexCounter wv1 = this.__getSquareVertex_wv1;
- final NyARVertexCounter wv2 = this.__getSquareVertex_wv2;
- final int end_of_coord = i_vertex1_index + i_coord_num - 1;
- final int sx = i_x_coord[i_vertex1_index];// sx = marker_info2->x_coord[0];
- final int sy = i_y_coord[i_vertex1_index];// sy = marker_info2->y_coord[0];
- int dmax = 0;
- int v1 = i_vertex1_index;
- for (int i = 1 + i_vertex1_index; i < end_of_coord; i++) {// for(i=1;i<marker_info2->coord_num-1;i++)
- // {
- final int d = (i_x_coord[i] - sx) * (i_x_coord[i] - sx) + (i_y_coord[i] - sy) * (i_y_coord[i] - sy);
- if (d > dmax) {
- dmax = d;
- v1 = i;
- }
- }
- final double thresh = (i_area / 0.75) * 0.01 * VERTEX_FACTOR;
-
- o_vertex[0] = i_vertex1_index;
-
- if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v1, thresh)) { // if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,0,v1,thresh,wv1,&wvnum1)<
- // 0 ) {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v1, end_of_coord, thresh)) {// if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,v1,marker_info2->coord_num-1,thresh,wv2,&wvnum2)
- // < 0) {
- return false;
- }
-
- int v2;
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {// if(wvnum1 == 1 && wvnum2== 1) {
- o_vertex[1] = wv1.vertex[0];
- o_vertex[2] = v1;
- o_vertex[3] = wv2.vertex[0];
- } else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0) {// }else if( wvnum1 > 1 && wvnum2== 0) {
- //頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。
- v2 = (v1-i_vertex1_index)/2+i_vertex1_index;
- if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v2, thresh)) {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v2, v1, thresh)) {
- return false;
- }
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
- o_vertex[1] = wv1.vertex[0];
- o_vertex[2] = wv2.vertex[0];
- o_vertex[3] = v1;
- } else {
- return false;
- }
- } else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1) {
- //v2 = (v1-i_vertex1_index+ end_of_coord-i_vertex1_index) / 2+i_vertex1_index;
- v2 = (v1+ end_of_coord)/2;
-
- if (!wv1.getVertex(i_x_coord, i_y_coord, v1, v2, thresh)) {
- return false;
- }
- if (!wv2.getVertex(i_x_coord, i_y_coord, v2, end_of_coord, thresh)) {
- return false;
- }
- if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
- o_vertex[1] = v1;
- o_vertex[2] = wv1.vertex[0];
- o_vertex[3] = wv2.vertex[0];
- } else {
- return false;
- }
- } else {
- return false;
- }
- o_vertex[4] = end_of_coord;
- return true;
- }
-
- private final INyARPca2d _pca;
- private final NyARDoubleMatrix22 __getSquareLine_evec=new NyARDoubleMatrix22();
- private final NyARDoublePoint2d __getSquareLine_mean=new NyARDoublePoint2d();
- private final NyARDoublePoint2d __getSquareLine_ev=new NyARDoublePoint2d();
- /**
- * arGetLine(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[4][3], double v[4][2]) arGetLine2(int x_coord[], int y_coord[], int
- * coord_num,int vertex[], double line[4][3], double v[4][2], double *dist_factor) の2関数の合成品です。 マーカーのvertex,lineを計算して、結果をo_squareに保管します。
- * Optimize:STEP[424->391]
- *
- * @param i_cparam
- * @return
- * @throws NyARException
- */
- private boolean getSquareLine(int[] i_mkvertex, int[] i_xcoord, int[] i_ycoord, NyARSquare o_square) throws NyARException
- {
- final NyARLinear[] l_line = o_square.line;
- final NyARDoubleMatrix22 evec=this.__getSquareLine_evec;
- final NyARDoublePoint2d mean=this.__getSquareLine_mean;
- final NyARDoublePoint2d ev=this.__getSquareLine_ev;
-
-
- for (int i = 0; i < 4; i++) {
- final double w1 = (double) (i_mkvertex[i + 1] - i_mkvertex[i] + 1) * 0.05 + 0.5;
- final int st = (int) (i_mkvertex[i] + w1);
- final int ed = (int) (i_mkvertex[i + 1] - w1);
- final int n = ed - st + 1;
- if (n < 2) {
- // nが2以下でmatrix.PCAを計算することはできないので、エラー
- return false;
- }
- //配列作成
- this._dist_factor.observ2IdealBatch(i_xcoord, i_ycoord, st, n,this._xpos,this._ypos);
-
- //主成分分析する。
- this._pca.pca(this._xpos,this._ypos,n,evec, ev,mean);
- final NyARLinear l_line_i = l_line[i];
- l_line_i.run = evec.m01;// line[i][0] = evec->m[1];
- l_line_i.rise = -evec.m00;// line[i][1] = -evec->m[0];
- l_line_i.intercept = -(l_line_i.run * mean.x + l_line_i.rise * mean.y);// line[i][2] = -(line[i][0]*mean->v[0] + line[i][1]*mean->v[1]);
- }
-
- final NyARDoublePoint2d[] l_sqvertex = o_square.sqvertex;
- final NyARIntPoint2d[] l_imvertex = o_square.imvertex;
- for (int i = 0; i < 4; i++) {
- final NyARLinear l_line_i = l_line[i];
- final NyARLinear l_line_2 = l_line[(i + 3) % 4];
- final double w1 = l_line_2.run * l_line_i.rise - l_line_i.run * l_line_2.rise;
- if (w1 == 0.0) {
- return false;
- }
- l_sqvertex[i].x = (l_line_2.rise * l_line_i.intercept - l_line_i.rise * l_line_2.intercept) / w1;
- l_sqvertex[i].y = (l_line_i.run * l_line_2.intercept - l_line_2.run * l_line_i.intercept) / w1;
- // 頂点インデクスから頂点座標を得て保存
- l_imvertex[i].x = i_xcoord[i_mkvertex[i]];
- l_imvertex[i].y = i_ycoord[i_mkvertex[i]];
- }
- return true;
- }
-}
-
-
-
-/**
- * ラベル同士の重なり(内包関係)を調べるクラスです。
- * ラベルリストに内包するラベルを蓄積し、それにターゲットのラベルが内包されているか を確認します。
- */
-class OverlapChecker
-{
- private NyARLabelingLabel[] _labels = new NyARLabelingLabel[32];
-
- private int _length;
-
- /**
- * 最大i_max_label個のラベルを蓄積できるようにオブジェクトをリセットする
- *
- * @param i_max_label
- */
- public void reset(int i_max_label)
- {
- if (i_max_label > this._labels.length) {
- this._labels = new NyARLabelingLabel[i_max_label];
- }
- this._length = 0;
- }
-
- /**
- * チェック対象のラベルを追加する。
- *
- * @param i_label_ref
- */
- public void push(NyARLabelingLabel i_label_ref)
- {
- this._labels[this._length] = i_label_ref;
- this._length++;
- }
-
- /**
- * 現在リストにあるラベルと重なっているかを返す。
- *
- * @param i_label
- * @return 何れかのラベルの内側にあるならばfalse,独立したラベルである可能性が高ければtrueです.
- */
- public boolean check(NyARLabelingLabel i_label)
- {
- // 重なり処理かな?
- final NyARLabelingLabel[] label_pt = this._labels;
- final int px1 = (int) i_label.pos_x;
- final int py1 = (int) i_label.pos_y;
- for (int i = this._length - 1; i >= 0; i--) {
- final int px2 = (int) label_pt[i].pos_x;
- final int py2 = (int) label_pt[i].pos_y;
- final int d = (px1 - px2) * (px1 - px2) + (py1 - py2) * (py1 - py2);
- if (d < label_pt[i].area / 4) {
- // 対象外
- return false;
- }
- }
- // 対象
- return true;
- }
-}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARSquare.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARSquare.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARSquare.java (revision 302)
@@ -1,57 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core;
-
-import jp.nyatla.nyartoolkit.core.types.*;
-/**
- * ARMarkerInfoに相当するクラス。 矩形情報を保持します。
- *
- * directionは方角を表します。
- * 決定しないときはDIRECTION_UNKNOWNを設定してください。
- *
- */
-public class NyARSquare
-{
- public final static int DIRECTION_UNKNOWN=-1;
- public int direction;
- public NyARLinear[] line = NyARLinear.createArray(4);
- public NyARDoublePoint2d[] sqvertex = NyARDoublePoint2d.createArray(4);
- public NyARIntPoint2d[] imvertex = NyARIntPoint2d.createArray(4);
- public NyARSquare()
- {
- for (int i = 0; i < 4; i++)
- {
- this.line[i] = new NyARLinear();
- }
- }
-
-}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/INyARSquareDetector.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/INyARSquareDetector.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/INyARSquareDetector.java (revision 302)
@@ -1,40 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core;
-
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.raster.NyARBinRaster;
-
-public interface INyARSquareDetector
-{
- public void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException;
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_INT1D_GLAY_8.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_INT1D_GLAY_8.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_INT1D_GLAY_8.java (revision 302)
@@ -1,63 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core.rasterreader;
-
-import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
-
-public class NyARRgbPixelReader_INT1D_GLAY_8 implements INyARRgbPixelReader
-{
- protected int[] _ref_buf;
-
- private NyARIntSize _size;
-
- public NyARRgbPixelReader_INT1D_GLAY_8(int[] i_buf, NyARIntSize i_size)
- {
- this._ref_buf = i_buf;
- this._size = i_size;
- }
-
- public void getPixel(int i_x, int i_y, int[] o_rgb)
- {
- o_rgb[0] = o_rgb[1]=o_rgb[2]=this._ref_buf[i_x + i_y * this._size.w];
- return;
- }
-
- public void getPixelSet(int[] i_x, int[] i_y, int i_num, int[] o_rgb)
- {
- final int width = this._size.w;
- final int[] ref_buf = this._ref_buf;
- for (int i = i_num - 1; i >= 0; i--){
- o_rgb[i * 3 + 0] = o_rgb[i * 3 + 1]=o_rgb[i * 3 + 2]=ref_buf[i_x[i] + i_y[i] * width];
- }
- return;
- }
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARBufferReader.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARBufferReader.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARBufferReader.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.rasterreader;
@@ -66,6 +65,10 @@
* byte[]で、R8G8B8X8の32ビットで画素が格納されている。
*/
public static final int BUFFERFORMAT_BYTE1D_B8G8R8X8_32 = BYTE1D|0x0101;
+ /**
+ * byte[]で、X8R8G8B8の32ビットで画素が格納されている。
+ */
+ public static final int BUFFERFORMAT_BYTE1D_X8R8G8B8_32 = BYTE1D|0x0102;

/**
* byte[]で、RGB565の16ビット(little/big endian)で画素が格納されている。
@@ -86,7 +89,7 @@
/**
* int[][]で0-255のグレイスケール画像
*/
- public static final int BUFFERFORMAT_INT2D_GLAY_8 = INT2D|0x0001;
+ public static final int BUFFERFORMAT_INT2D_GRAY_8 = INT2D|0x0001;
/**
* int[][]で0/1の2値画像
*/
@@ -99,11 +102,13 @@
/**
* int[]で0-255のグレイスケール画像
*/
- public static final int BUFFERFORMAT_INT1D_GLAY_8 = INT1D|0x0001;
+ public static final int BUFFERFORMAT_INT1D_GRAY_8 = INT1D|0x0001;
/**
* int[]で0/1の2値画像
*/
public static final int BUFFERFORMAT_INT1D_BIN_8 = INT1D|0x0002;
+
+
/**
* int[]で、XRGB32の32ビットで画素が格納されている。
*/
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_INT1D_GRAY_8.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_INT1D_GRAY_8.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_INT1D_GRAY_8.java (revision 302)
@@ -0,0 +1,72 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.rasterreader;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
+
+public class NyARRgbPixelReader_INT1D_GRAY_8 implements INyARRgbPixelReader
+{
+ protected int[] _ref_buf;
+
+ private NyARIntSize _size;
+
+ public NyARRgbPixelReader_INT1D_GRAY_8(int[] i_buf, NyARIntSize i_size)
+ {
+ this._ref_buf = i_buf;
+ this._size = i_size;
+ }
+
+ public void getPixel(int i_x, int i_y, int[] o_rgb)
+ {
+ o_rgb[0] = o_rgb[1]=o_rgb[2]=this._ref_buf[i_x + i_y * this._size.w];
+ return;
+ }
+
+ public void getPixelSet(int[] i_x, int[] i_y, int i_num, int[] o_rgb)
+ {
+ final int width = this._size.w;
+ final int[] ref_buf = this._ref_buf;
+ for (int i = i_num - 1; i >= 0; i--){
+ o_rgb[i * 3 + 0] = o_rgb[i * 3 + 1]=o_rgb[i * 3 + 2]=ref_buf[i_x[i] + i_y[i] * width];
+ }
+ return;
+ }
+ public void setPixel(int i_x, int i_y, int[] i_rgb) throws NyARException
+ {
+ NyARException.notImplement();
+ }
+ public void setPixels(int[] i_x, int[] i_y, int i_num, int[] i_intrgb) throws NyARException
+ {
+ NyARException.notImplement();
+ }
+
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARRgbPixelReader.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARRgbPixelReader.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARRgbPixelReader.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.rasterreader;
@@ -58,4 +57,23 @@
* yのインデックス配列
*/
public void getPixelSet(int[] i_x, int[] i_y, int i_num, int[] i_intrgb) throws NyARException;
+
+ /**
+ * 1ピクセルを設定します。
+ * @param i_x
+ * @param i_y
+ * @param i_rgb
+ * @throws NyARException
+ */
+ public void setPixel(int i_x, int i_y, int[] i_rgb) throws NyARException;
+ /**
+ * 複数のピクセル値をint配列から設定します。
+ * @param i_x
+ * @param i_y
+ * @param i_num
+ * @param i_intrgb
+ * @throws NyARException
+ */
+ public void setPixels(int[] i_x, int[] i_y, int i_num, int[] i_intrgb) throws NyARException;
+
}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARBufferReader.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARBufferReader.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARBufferReader.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.rasterreader;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_BYTE1D_X8R8G8B8_32.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_BYTE1D_X8R8G8B8_32.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_BYTE1D_X8R8G8B8_32.java (revision 302)
@@ -0,0 +1,84 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.rasterreader;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.types.*;
+/**
+ * byte[]配列に、パディング無しの8bit画素値が、XRGBXRGBの順で並んでいる
+ * バッファに使用できるピクセルリーダー
+ *
+ */
+public class NyARRgbPixelReader_BYTE1D_X8R8G8B8_32 implements INyARRgbPixelReader
+{
+ protected byte[] _ref_buf;
+
+ private NyARIntSize _size;
+
+ public NyARRgbPixelReader_BYTE1D_X8R8G8B8_32(byte[] i_buf, NyARIntSize i_size)
+ {
+ this._ref_buf = i_buf;
+ this._size = i_size;
+ }
+
+ public void getPixel(int i_x, int i_y, int[] o_rgb)
+ {
+ final byte[] ref_buf = this._ref_buf;
+ final int bp = (i_x + i_y * this._size.w) * 4;
+ o_rgb[0] = (ref_buf[bp + 1] & 0xff);// R
+ o_rgb[1] = (ref_buf[bp + 2] & 0xff);// G
+ o_rgb[2] = (ref_buf[bp + 3] & 0xff);// B
+ return;
+ }
+
+ public void getPixelSet(int[] i_x, int[] i_y, int i_num, int[] o_rgb)
+ {
+ int bp;
+ final int width = this._size.w;
+ final byte[] ref_buf = this._ref_buf;
+ for (int i = i_num - 1; i >= 0; i--) {
+ bp = (i_x[i] + i_y[i] * width) * 4;
+ o_rgb[i * 3 + 0] = (ref_buf[bp + 1] & 0xff);// R
+ o_rgb[i * 3 + 1] = (ref_buf[bp + 2] & 0xff);// G
+ o_rgb[i * 3 + 2] = (ref_buf[bp + 3] & 0xff);// B
+ }
+ return;
+ }
+ public void setPixel(int i_x, int i_y, int[] i_rgb) throws NyARException
+ {
+ NyARException.notImplement();
+ }
+ public void setPixels(int[] i_x, int[] i_y, int i_num, int[] i_intrgb) throws NyARException
+ {
+ NyARException.notImplement();
+ }
+
+}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_RGB24.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_RGB24.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_RGB24.java (revision 302)
@@ -7,30 +7,30 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.rasterreader;

+import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.types.*;
/**
* byte[]配列に、パディング無しの8bit画素値が、RGBRGBの順で並んでいる
@@ -71,5 +71,14 @@
o_rgb[i * 3 + 2] = (ref_buf[bp + 2] & 0xff);// B
}
return;
- }
+ }
+ public void setPixel(int i_x, int i_y, int[] i_rgb) throws NyARException
+ {
+ NyARException.notImplement();
+ }
+ public void setPixels(int[] i_x, int[] i_y, int i_num, int[] i_intrgb) throws NyARException
+ {
+ NyARException.notImplement();
+ }
+
}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_INT1D_X8R8G8B8_32.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_INT1D_X8R8G8B8_32.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_INT1D_X8R8G8B8_32.java (revision 302)
@@ -7,30 +7,30 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.rasterreader;

+import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.types.NyARIntSize;

public class NyARRgbPixelReader_INT1D_X8R8G8B8_32 implements INyARRgbPixelReader
@@ -66,4 +66,13 @@
}
return;
}
+ public void setPixel(int i_x, int i_y, int[] i_rgb) throws NyARException
+ {
+ this._ref_buf[i_x + i_y * this._size.w]=((i_rgb[0]<<16)&0xff)|((i_rgb[1]<<8)&0xff)|((i_rgb[2])&0xff);
+ }
+ public void setPixels(int[] i_x, int[] i_y, int i_num, int[] i_intrgb) throws NyARException
+ {
+ NyARException.notImplement();
+ }
+
}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARCode.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARCode.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARCode.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARVec.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARVec.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARVec.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pca2d/NyARPca2d_MatrixPCA.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pca2d/NyARPca2d_MatrixPCA.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pca2d/NyARPca2d_MatrixPCA.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.pca2d;
@@ -67,7 +66,7 @@
o_evec.m10=evec_array[1][0];
o_evec.m11=evec_array[1][1];
o_ev.x=ev_array[0];
- o_ev.x=ev_array[1];
+ o_ev.y=ev_array[1];
o_mean.x=mean_array[0];
o_mean.y=mean_array[1];
return;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pca2d/NyARPca2d_MatrixPCA_O2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pca2d/NyARPca2d_MatrixPCA_O2.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pca2d/NyARPca2d_MatrixPCA_O2.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.pca2d;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pca2d/INyARPca2d.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pca2d/INyARPca2d.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pca2d/INyARPca2d.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.pca2d;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARSquareStack.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARSquareStack.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARSquareStack.java (revision 302)
@@ -0,0 +1,47 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.squaredetect;
+
+
+import jp.nyatla.utils.*;
+
+public class NyARSquareStack extends NyObjectStack<NyARSquare>
+{
+ public NyARSquareStack(int i_length)
+ {
+ super(i_length,NyARSquare.class);
+
+ }
+ protected NyARSquare createElement()
+ {
+ return new NyARSquare();
+ }
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/SquareContourDetector.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/SquareContourDetector.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/SquareContourDetector.java (revision 302)
@@ -0,0 +1,242 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.squaredetect;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.param.NyARCameraDistortionFactor;
+import jp.nyatla.nyartoolkit.core.param.NyARObserv2IdealMap;
+import jp.nyatla.nyartoolkit.core.pca2d.INyARPca2d;
+import jp.nyatla.nyartoolkit.core.pca2d.NyARPca2d_MatrixPCA_O2;
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
+import jp.nyatla.nyartoolkit.core.types.NyARIntPoint2d;
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
+import jp.nyatla.nyartoolkit.core.types.NyARLinear;
+import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix22;
+
+public class SquareContourDetector
+{
+ private static final double VERTEX_FACTOR = 1.0;// 線検出のファクタ
+ private final double[] _xpos;
+ private final double[] _ypos;
+ private final int[] __detectMarker_mkvertex = new int[5];
+ private final NyARVertexCounter __getSquareVertex_wv1 = new NyARVertexCounter();
+ private final NyARVertexCounter __getSquareVertex_wv2 = new NyARVertexCounter();
+ private final INyARPca2d _pca;
+ private final NyARDoubleMatrix22 __getSquareLine_evec=new NyARDoubleMatrix22();
+ private final NyARDoublePoint2d __getSquareLine_mean=new NyARDoublePoint2d();
+ private final NyARDoublePoint2d __getSquareLine_ev=new NyARDoublePoint2d();
+ private final NyARObserv2IdealMap _dist_factor;
+ public SquareContourDetector(NyARIntSize i_size,NyARCameraDistortionFactor i_distfactor_ref)
+ {
+ //歪み計算テーブルを作ると、8*width/height*2の領域を消費します。
+ //領域を取りたくない場合は、i_dist_factor_refの値をそのまま使ってください。
+ this._dist_factor = new NyARObserv2IdealMap(i_distfactor_ref,i_size);
+
+
+ // 輪郭バッファは頂点変換をするので、輪郭バッファの2倍取る。
+ this._pca=new NyARPca2d_MatrixPCA_O2();
+ this._xpos=new double[i_size.w+i_size.h];//最大辺長はthis._width+this._height
+ this._ypos=new double[i_size.w+i_size.h];//最大辺長はthis._width+this._height
+ return;
+ }
+
+ public boolean coordToSquare(int[] i_xcoord,int[] i_ycoord,int i_st_index,int i_coord_num,int i_label_area,NyARSquare o_square) throws NyARException
+ {
+
+ final int[] mkvertex = this.__detectMarker_mkvertex;
+
+ // 頂点情報を取得
+ if (!getSquareVertex(i_xcoord, i_ycoord, i_st_index, i_coord_num, i_label_area, mkvertex)) {
+ // 頂点の取得が出来なかったので破棄
+ return false;
+ }
+ // マーカーを検出
+ if (!getSquareLine(mkvertex, i_xcoord, i_ycoord, o_square)){
+ // 矩形が成立しなかった。
+ return false;
+ }
+ return true;
+ }
+
+ private boolean getSquareLine(int[] i_mkvertex, int[] i_xcoord, int[] i_ycoord, NyARSquare o_square) throws NyARException
+ {
+ final NyARLinear[] l_line = o_square.line;
+ final NyARDoubleMatrix22 evec=this.__getSquareLine_evec;
+ final NyARDoublePoint2d mean=this.__getSquareLine_mean;
+ final NyARDoublePoint2d ev=this.__getSquareLine_ev;
+
+
+ for (int i = 0; i < 4; i++) {
+ final double w1 = (double) (i_mkvertex[i + 1] - i_mkvertex[i] + 1) * 0.05 + 0.5;
+ final int st = (int) (i_mkvertex[i] + w1);
+ final int ed = (int) (i_mkvertex[i + 1] - w1);
+ final int n = ed - st + 1;
+ if (n < 2) {
+ // nが2以下でmatrix.PCAを計算することはできないので、エラー
+ return false;
+ }
+ //配列作成
+ this._dist_factor.observ2IdealBatch(i_xcoord, i_ycoord, st, n,this._xpos,this._ypos);
+
+ //主成分分析する。
+ this._pca.pca(this._xpos,this._ypos,n,evec, ev,mean);
+ final NyARLinear l_line_i = l_line[i];
+ l_line_i.run = evec.m01;// line[i][0] = evec->m[1];
+ l_line_i.rise = -evec.m00;// line[i][1] = -evec->m[0];
+ l_line_i.intercept = -(l_line_i.run * mean.x + l_line_i.rise * mean.y);// line[i][2] = -(line[i][0]*mean->v[0] + line[i][1]*mean->v[1]);
+ }
+
+ final NyARDoublePoint2d[] l_sqvertex = o_square.sqvertex;
+ final NyARIntPoint2d[] l_imvertex = o_square.imvertex;
+ for (int i = 0; i < 4; i++) {
+ final NyARLinear l_line_i = l_line[i];
+ final NyARLinear l_line_2 = l_line[(i + 3) % 4];
+ final double w1 = l_line_2.run * l_line_i.rise - l_line_i.run * l_line_2.rise;
+ if (w1 == 0.0) {
+ return false;
+ }
+ l_sqvertex[i].x = (l_line_2.rise * l_line_i.intercept - l_line_i.rise * l_line_2.intercept) / w1;
+ l_sqvertex[i].y = (l_line_i.run * l_line_2.intercept - l_line_2.run * l_line_i.intercept) / w1;
+ // 頂点インデクスから頂点座標を得て保存
+ l_imvertex[i].x = i_xcoord[i_mkvertex[i]];
+ l_imvertex[i].y = i_ycoord[i_mkvertex[i]];
+ }
+ return true;
+ }
+ private boolean getSquareVertex(int[] i_x_coord, int[] i_y_coord, int i_vertex1_index, int i_coord_num, int i_area, int[] o_vertex)
+ {
+ final NyARVertexCounter wv1 = this.__getSquareVertex_wv1;
+ final NyARVertexCounter wv2 = this.__getSquareVertex_wv2;
+ final int end_of_coord = i_vertex1_index + i_coord_num - 1;
+ final int sx = i_x_coord[i_vertex1_index];// sx = marker_info2->x_coord[0];
+ final int sy = i_y_coord[i_vertex1_index];// sy = marker_info2->y_coord[0];
+ int dmax = 0;
+ int v1 = i_vertex1_index;
+ for (int i = 1 + i_vertex1_index; i < end_of_coord; i++) {// for(i=1;i<marker_info2->coord_num-1;i++)
+ // {
+ final int d = (i_x_coord[i] - sx) * (i_x_coord[i] - sx) + (i_y_coord[i] - sy) * (i_y_coord[i] - sy);
+ if (d > dmax) {
+ dmax = d;
+ v1 = i;
+ }
+ }
+ final double thresh = (i_area / 0.75) * 0.01 * VERTEX_FACTOR;
+
+ o_vertex[0] = i_vertex1_index;
+
+ if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v1, thresh)) { // if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,0,v1,thresh,wv1,&wvnum1)<
+ // 0 ) {
+ return false;
+ }
+ if (!wv2.getVertex(i_x_coord, i_y_coord, v1, end_of_coord, thresh)) {// if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,v1,marker_info2->coord_num-1,thresh,wv2,&wvnum2)
+ // < 0) {
+ return false;
+ }
+
+ int v2;
+ if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {// if(wvnum1 == 1 && wvnum2== 1) {
+ o_vertex[1] = wv1.vertex[0];
+ o_vertex[2] = v1;
+ o_vertex[3] = wv2.vertex[0];
+ } else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0) {// }else if( wvnum1 > 1 && wvnum2== 0) {
+ //頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。
+ v2 = (v1-i_vertex1_index)/2+i_vertex1_index;
+ if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v2, thresh)) {
+ return false;
+ }
+ if (!wv2.getVertex(i_x_coord, i_y_coord, v2, v1, thresh)) {
+ return false;
+ }
+ if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
+ o_vertex[1] = wv1.vertex[0];
+ o_vertex[2] = wv2.vertex[0];
+ o_vertex[3] = v1;
+ } else {
+ return false;
+ }
+ } else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1) {
+ //v2 = (v1-i_vertex1_index+ end_of_coord-i_vertex1_index) / 2+i_vertex1_index;
+ v2 = (v1+ end_of_coord)/2;
+
+ if (!wv1.getVertex(i_x_coord, i_y_coord, v1, v2, thresh)) {
+ return false;
+ }
+ if (!wv2.getVertex(i_x_coord, i_y_coord, v2, end_of_coord, thresh)) {
+ return false;
+ }
+ if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
+ o_vertex[1] = v1;
+ o_vertex[2] = wv1.vertex[0];
+ o_vertex[3] = wv2.vertex[0];
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ o_vertex[4] = end_of_coord;
+ return true;
+ }
+
+ /**
+ * 輪郭線の矩形検出開始ポイントを特定して、座標を並べ替えます。
+ * 輪郭線の先頭から、対角線が最長になる点を1点検索し、それより前の区間をバッファの後方に接続します。
+ * 戻り値は対角線が最長になった点です。関数終了後、返却値+i_coord_numの要素が有効になります。
+ * @param i_xcoord
+ * @param i_ycoord
+ * @param i_coord_num
+ * @return
+ */
+ public static int normalizeCoord(int[] i_coord_x, int[] i_coord_y,int i_coord_num)
+ {
+ //
+ final int sx = i_coord_x[0];
+ final int sy = i_coord_y[0];
+ int d = 0;
+ int w, x, y;
+ int ret = 0;
+ for (int i = 1; i < i_coord_num; i++) {
+ x = i_coord_x[i] - sx;
+ y = i_coord_y[i] - sy;
+ w = x * x + y * y;
+ if (w > d) {
+ d = w;
+ ret = i;
+ }
+ // ここでうまく終了条件入れられないかな。
+ }
+ // vertex1を境界にして、後方に配列を連結
+ System.arraycopy(i_coord_x, 1, i_coord_x, i_coord_num, ret);
+ System.arraycopy(i_coord_y, 1, i_coord_y, i_coord_num, ret);
+ return ret;
+ }
+
+}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/ContourPickup.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/ContourPickup.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/ContourPickup.java (revision 302)
@@ -0,0 +1,264 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.squaredetect;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.raster.*;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.*;
+
+public class ContourPickup
+{
+ //巡回参照できるように、テーブルを二重化
+ // 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
+ protected final static int[] _getContour_xdir = { 0, 1, 1, 1, 0,-1,-1,-1 , 0, 1, 1, 1, 0,-1,-1};
+ protected final static int[] _getContour_ydir = {-1,-1, 0, 1, 1, 1, 0,-1 ,-1,-1, 0, 1, 1, 1, 0};
+
+ /**
+ * ラスタのエントリポイントから辿れる輪郭線を配列に返します。
+ * @param i_raster
+ * @param i_entry_x
+ * @param i_entry_y
+ * @param i_array_size
+ * @param o_coord_x
+ * @param o_coord_y
+ * @return
+ * 輪郭線の長さを返します。
+ * @throws NyARException
+ */
+ public int getContour(NyARBinRaster i_raster,int i_entry_x,int i_entry_y,int i_array_size,int[] o_coord_x,int[] o_coord_y) throws NyARException
+ {
+ final int[] xdir = _getContour_xdir;// static int xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1};
+ final int[] ydir = _getContour_ydir;// static int ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1};
+
+ final int[] i_buf=(int[])i_raster.getBufferReader().getBuffer();
+ final int width=i_raster.getWidth();
+ final int height=i_raster.getHeight();
+ //クリップ領域の上端に接しているポイントを得る。
+
+
+ int coord_num = 1;
+ o_coord_x[0] = i_entry_x;
+ o_coord_y[0] = i_entry_y;
+ int dir = 5;
+
+ int c = i_entry_x;
+ int r = i_entry_y;
+ for (;;) {
+ dir = (dir + 5) % 8;//dirの正規化
+ //ここは頑張ればもっと最適化できると思うよ。
+ //4隅以外の境界接地の場合に、境界チェックを省略するとかね。
+ if(c>=1 && c<width-1 && r>=1 && r<height-1){
+ for(;;){//gotoのエミュレート用のfor文
+ //境界に接していないとき
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] == 0) {
+ break;
+ }
+ dir++;
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] == 0) {
+ break;
+ }
+ dir++;
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] == 0) {
+ break;
+ }
+ dir++;
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] == 0) {
+ break;
+ }
+ dir++;
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] == 0) {
+ break;
+ }
+ dir++;
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] == 0) {
+ break;
+ }
+ dir++;
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] == 0) {
+ break;
+ }
+ dir++;
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] == 0) {
+ break;
+ }
+/*
+ try{
+ BufferedImage b=new BufferedImage(width,height,ColorSpace.TYPE_RGB);
+ NyARRasterImageIO.copy(i_raster, b);
+ ImageIO.write(b,"png",new File("bug.png"));
+ }catch(Exception e){
+
+ }*/
+ //8方向全て調べたけどラベルが無いよ?
+ throw new NyARException();
+ }
+ }else{
+ //境界に接しているとき
+ int i;
+ for (i = 0; i < 8; i++){
+ final int x=c + xdir[dir];
+ final int y=r + ydir[dir];
+ //境界チェック
+ if(x>=0 && x<width && y>=0 && y<height){
+ if (i_buf[(y)*width+(x)] == 0) {
+ break;
+ }
+ }
+ dir++;//倍長テーブルを参照するので問題なし
+ }
+ if (i == 8) {
+ //8方向全て調べたけどラベルが無いよ?
+ throw new NyARException();// return(-1);
+ }
+ }
+
+ dir=dir% 8;//dirの正規化
+
+ // xcoordとycoordをc,rにも保存
+ c = c + xdir[dir];
+ r = r + ydir[dir];
+ o_coord_x[coord_num] = c;
+ o_coord_y[coord_num] = r;
+ // 終了条件判定
+ if (c == i_entry_x && r == i_entry_y){
+ coord_num++;
+ break;
+ }
+ coord_num++;
+ if (coord_num == i_array_size) {
+ //輪郭が末端に達した
+ return coord_num;
+ }
+ }
+ return coord_num;
+ }
+ public int getContour(NyARLabelingImage i_raster,int i_entry_x,int i_entry_y,int i_array_size,int[] o_coord_x,int[] o_coord_y) throws NyARException
+ {
+ final int[] xdir = _getContour_xdir;// static int xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1};
+ final int[] ydir = _getContour_ydir;// static int ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1};
+
+ final int[] i_buf=(int[])i_raster.getBufferReader().getBuffer();
+ final int width=i_raster.getWidth();
+ final int height=i_raster.getHeight();
+ //クリップ領域の上端に接しているポイントを得る。
+ int sx=i_entry_x;
+ int sy=i_entry_y;
+
+ int coord_num = 1;
+ o_coord_x[0] = sx;
+ o_coord_y[0] = sy;
+ int dir = 5;
+
+ int c = o_coord_x[0];
+ int r = o_coord_y[0];
+ for (;;) {
+ dir = (dir + 5) % 8;//dirの正規化
+ //ここは頑張ればもっと最適化できると思うよ。
+ //4隅以外の境界接地の場合に、境界チェックを省略するとかね。
+ if(c>=1 && c<width-1 && r>=1 && r<height-1){
+ for(;;){//gotoのエミュレート用のfor文
+ //境界に接していないとき
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] > 0) {
+ break;
+ }
+ dir++;
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] > 0) {
+ break;
+ }
+ dir++;
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] > 0) {
+ break;
+ }
+ dir++;
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] > 0) {
+ break;
+ }
+ dir++;
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] > 0) {
+ break;
+ }
+ dir++;
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] > 0) {
+ break;
+ }
+ dir++;
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] > 0) {
+ break;
+ }
+ dir++;
+ if (i_buf[(r + ydir[dir])*width+(c + xdir[dir])] > 0) {
+ break;
+ }
+ //8方向全て調べたけどラベルが無いよ?
+ throw new NyARException();
+ }
+ }else{
+ //境界に接しているとき
+ int i;
+ for (i = 0; i < 8; i++){
+ final int x=c + xdir[dir];
+ final int y=r + ydir[dir];
+ //境界チェック
+ if(x>=0 && x<width && y>=0 && y<height){
+ if (i_buf[(y)*width+(x)] > 0) {
+ break;
+ }
+ }
+ dir++;//倍長テーブルを参照するので問題なし
+ }
+ if (i == 8) {
+ //8方向全て調べたけどラベルが無いよ?
+ throw new NyARException();// return(-1);
+ }
+ }
+
+ dir=dir% 8;//dirの正規化
+
+ // xcoordとycoordをc,rにも保存
+ c = c + xdir[dir];
+ r = r + ydir[dir];
+ o_coord_x[coord_num] = c;
+ o_coord_y[coord_num] = r;
+ // 終了条件判定
+ if (c == sx && r == sy){
+ coord_num++;
+ break;
+ }
+ coord_num++;
+ if (coord_num == i_array_size) {
+ //輪郭が末端に達した
+ return coord_num;
+ }
+ }
+ return coord_num;
+ }
+
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARSquareDetector_Rle.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARSquareDetector_Rle.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARSquareDetector_Rle.java (revision 302)
@@ -0,0 +1,172 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.squaredetect;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.labeling.LabelOverlapChecker;
+import jp.nyatla.nyartoolkit.core.labeling.rlelabeling.*;
+import jp.nyatla.nyartoolkit.core.param.NyARCameraDistortionFactor;
+import jp.nyatla.nyartoolkit.core.raster.NyARBinRaster;
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
+
+
+
+public class NyARSquareDetector_Rle implements INyARSquareDetector
+{
+ private static final int AR_AREA_MAX = 100000;// #define AR_AREA_MAX 100000
+ private static final int AR_AREA_MIN = 70;// #define AR_AREA_MIN 70
+ private final int _width;
+ private final int _height;
+
+ private final NyARLabeling_Rle _labeling;
+
+ private final LabelOverlapChecker<RleLabelFragmentInfoStack.RleLabelFragmentInfo> _overlap_checker = new LabelOverlapChecker<RleLabelFragmentInfoStack.RleLabelFragmentInfo>(32,RleLabelFragmentInfoStack.RleLabelFragmentInfo.class);
+ private final SquareContourDetector _sqconvertor;
+ private final ContourPickup _cpickup=new ContourPickup();
+ private final RleLabelFragmentInfoStack _stack;
+
+ private final int _max_coord;
+ private final int[] _xcoord;
+ private final int[] _ycoord;
+ /**
+ * 最大i_squre_max個のマーカーを検出するクラスを作成する。
+ *
+ * @param i_param
+ */
+ public NyARSquareDetector_Rle(NyARCameraDistortionFactor i_dist_factor_ref,NyARIntSize i_size) throws NyARException
+ {
+ this._width = i_size.w;
+ this._height = i_size.h;
+ //ラベリングのサイズを指定したいときはsetAreaRangeを使ってね。
+ this._labeling = new NyARLabeling_Rle(this._width,this._height);
+ this._labeling.setAreaRange(AR_AREA_MAX, AR_AREA_MIN);
+ this._sqconvertor=new SquareContourDetector(i_size,i_dist_factor_ref);
+ this._stack=new RleLabelFragmentInfoStack(i_size.w*i_size.h*2048/(320*240)+32);//検出可能な最大ラベル数
+
+
+ // 輪郭の最大長は画面に映りうる最大の長方形サイズ。
+ int number_of_coord = (this._width + this._height) * 2;
+
+ // 輪郭バッファは頂点変換をするので、輪郭バッファの2倍取る。
+ this._max_coord = number_of_coord;
+ this._xcoord = new int[number_of_coord * 2];
+ this._ycoord = new int[number_of_coord * 2];
+ return;
+ }
+
+ /**
+ * arDetectMarker2を基にした関数
+ * この関数はNyARSquare要素のうち、directionを除くパラメータを取得して返します。
+ * directionの確定は行いません。
+ * @param i_raster
+ * 解析する2値ラスタイメージを指定します。
+ * @param o_square_stack
+ * 抽出した正方形候補を格納するリスト
+ * @throws NyARException
+ */
+ public final void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException
+ {
+ final RleLabelFragmentInfoStack flagment=this._stack;
+ final LabelOverlapChecker<RleLabelFragmentInfoStack.RleLabelFragmentInfo> overlap = this._overlap_checker;
+
+ // マーカーホルダをリセット
+ o_square_stack.clear();
+
+ // ラベル数が0ならここまで
+ final int label_num=this._labeling.labeling(i_raster, 0, i_raster.getHeight(), flagment);
+ if (label_num < 1) {
+ return;
+ }
+ //ラベルをソートしておく
+ flagment.sortByArea();
+ //ラベルリストを取得
+ RleLabelFragmentInfoStack.RleLabelFragmentInfo[] labels=flagment.getArray();
+
+ final int xsize = this._width;
+ final int ysize = this._height;
+ final int[] xcoord = this._xcoord;
+ final int[] ycoord = this._ycoord;
+ final int coord_max = this._max_coord;
+
+
+ //重なりチェッカの最大数を設定
+ overlap.setMaxLabels(label_num);
+
+ for (int i=0; i < label_num; i++) {
+ final RleLabelFragmentInfoStack.RleLabelFragmentInfo label_pt=labels[i];
+ final int label_area = label_pt.area;
+
+ // クリップ領域が画面の枠に接していれば除外
+ if (label_pt.clip_l == 0 || label_pt.clip_r == xsize-1){
+ continue;
+ }
+ if (label_pt.clip_t == 0 || label_pt.clip_b == ysize-1){
+ continue;
+ }
+ // 既に検出された矩形との重なりを確認
+ if (!overlap.check(label_pt)) {
+ // 重なっているようだ。
+ continue;
+ }
+
+ // 輪郭を取得
+ final int coord_num = _cpickup.getContour(i_raster,label_pt.entry_x,label_pt.clip_t, coord_max, xcoord, ycoord);
+ if (coord_num == coord_max) {
+ // 輪郭が大きすぎる。
+ continue;
+ }
+ //輪郭分析用に正規化する。
+ final int vertex1 = SquareContourDetector.normalizeCoord(xcoord, ycoord, coord_num);
+
+ //ここから先が輪郭分析
+ NyARSquare square_ptr = o_square_stack.prePush();
+ if(!this._sqconvertor.coordToSquare(xcoord,ycoord,vertex1,coord_num,label_area,square_ptr)){
+ o_square_stack.pop();// 頂点の取得が出来なかったので破棄
+ continue;
+ }
+ // 検出済の矩形の属したラベルを重なりチェックに追加する。
+ overlap.push(label_pt);
+ }
+ return;
+ }
+ /**
+ * デバック用API
+ * @return
+ */
+ public RleLabelFragmentInfoStack _getFragmentStack()
+ {
+ return this._stack;
+ }
+
+}
+
+
+
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARVertexCounter.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARVertexCounter.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARVertexCounter.java (revision 302)
@@ -0,0 +1,102 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.squaredetect;
+
+/**
+ * get_vertex関数を切り離すためのクラス
+ *
+ */
+final public class NyARVertexCounter
+{
+ public final int[] vertex = new int[10];// 6まで削れる
+
+ public int number_of_vertex;
+
+ private double thresh;
+
+ private int[] x_coord;
+
+ private int[] y_coord;
+
+ public boolean getVertex(int[] i_x_coord, int[] i_y_coord, int st, int ed, double i_thresh)
+ {
+ this.number_of_vertex = 0;
+ this.thresh = i_thresh;
+ this.x_coord = i_x_coord;
+ this.y_coord = i_y_coord;
+ return get_vertex(st, ed);
+ }
+
+ /**
+ * static int get_vertex( int x_coord[], int y_coord[], int st, int ed,double thresh, int vertex[], int *vnum) 関数の代替関数
+ *
+ * @param x_coord
+ * @param y_coord
+ * @param st
+ * @param ed
+ * @param thresh
+ * @return
+ */
+ private boolean get_vertex(int st, int ed)
+ {
+ //メモ:座標値は65536を超えなければint32で扱って大丈夫なので変更。
+ //dmaxは4乗なのでやるとしてもint64じゃないとマズイ
+ int v1 = 0;
+ final int[] lx_coord = this.x_coord;
+ final int[] ly_coord = this.y_coord;
+ final int a = ly_coord[ed] - ly_coord[st];
+ final int b = lx_coord[st] - lx_coord[ed];
+ final int c = lx_coord[ed] * ly_coord[st] - ly_coord[ed] * lx_coord[st];
+ double dmax = 0;
+ for (int i = st + 1; i < ed; i++) {
+ final double d = a * lx_coord[i] + b * ly_coord[i] + c;
+ if (d * d > dmax) {
+ dmax = d * d;
+ v1 = i;
+ }
+ }
+ if (dmax / (double)(a * a + b * b) > thresh) {
+ if (!get_vertex(st, v1)) {
+ return false;
+ }
+ if (number_of_vertex > 5) {
+ return false;
+ }
+ vertex[number_of_vertex] = v1;// vertex[(*vnum)] = v1;
+ number_of_vertex++;// (*vnum)++;
+
+ if (!get_vertex(v1, ed)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARSquare.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARSquare.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARSquare.java (revision 302)
@@ -0,0 +1,56 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.squaredetect;
+
+import jp.nyatla.nyartoolkit.core.types.*;
+/**
+ * ARMarkerInfoに相当するクラス。 矩形情報を保持します。
+ *
+ * directionは方角を表します。
+ * 決定しないときはDIRECTION_UNKNOWNを設定してください。
+ *
+ */
+public class NyARSquare
+{
+ public final static int DIRECTION_UNKNOWN=-1;
+ public int direction;
+ public NyARLinear[] line = NyARLinear.createArray(4);
+ public NyARDoublePoint2d[] sqvertex = NyARDoublePoint2d.createArray(4);
+ public NyARIntPoint2d[] imvertex = NyARIntPoint2d.createArray(4);
+ public NyARSquare()
+ {
+ for (int i = 0; i < 4; i++)
+ {
+ this.line[i] = new NyARLinear();
+ }
+ }
+
+}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARSquareDetector_ARToolKit.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARSquareDetector_ARToolKit.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARSquareDetector_ARToolKit.java (revision 302)
@@ -0,0 +1,179 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.squaredetect;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.labeling.LabelOverlapChecker;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabel;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabelStack;
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabeling_ARToolKit;
+import jp.nyatla.nyartoolkit.core.param.NyARCameraDistortionFactor;
+import jp.nyatla.nyartoolkit.core.raster.NyARBinRaster;
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
+
+
+
+public class NyARSquareDetector_ARToolKit implements INyARSquareDetector
+{
+ private static final int AR_AREA_MAX = 100000;// #define AR_AREA_MAX 100000
+ private static final int AR_AREA_MIN = 70;// #define AR_AREA_MIN 70
+ private final int _width;
+ private final int _height;
+
+ private final NyARLabeling_ARToolKit _labeling;
+
+ private final NyARLabelingImage _limage;
+
+ private final LabelOverlapChecker<NyARLabelingLabel> _overlap_checker = new LabelOverlapChecker<NyARLabelingLabel>(32,NyARLabelingLabel.class);
+ private final SquareContourDetector _sqconvertor;
+ private final ContourPickup _cpickup=new ContourPickup();
+
+ private final int _max_coord;
+ private final int[] _xcoord;
+ private final int[] _ycoord;
+ /**
+ * 最大i_squre_max個のマーカーを検出するクラスを作成する。
+ *
+ * @param i_param
+ */
+ public NyARSquareDetector_ARToolKit(NyARCameraDistortionFactor i_dist_factor_ref,NyARIntSize i_size) throws NyARException
+ {
+ this._width = i_size.w;
+ this._height = i_size.h;
+ this._labeling = new NyARLabeling_ARToolKit();
+ this._sqconvertor=new SquareContourDetector(i_size,i_dist_factor_ref);
+ this._limage = new NyARLabelingImage(this._width, this._height);
+
+ // 輪郭の最大長は画面に映りうる最大の長方形サイズ。
+ int number_of_coord = (this._width + this._height) * 2;
+
+ // 輪郭バッファは頂点変換をするので、輪郭バッファの2倍取る。
+ this._max_coord = number_of_coord;
+ this._xcoord = new int[number_of_coord * 2];
+ this._ycoord = new int[number_of_coord * 2];
+ return;
+ }
+
+ /**
+ * arDetectMarker2を基にした関数
+ * この関数はNyARSquare要素のうち、directionを除くパラメータを取得して返します。
+ * directionの確定は行いません。
+ * @param i_raster
+ * 解析する2値ラスタイメージを指定します。
+ * @param o_square_stack
+ * 抽出した正方形候補を格納するリスト
+ * @throws NyARException
+ */
+ public final void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException
+ {
+ final NyARLabelingImage limage = this._limage;
+
+ // 初期化
+
+ // マーカーホルダをリセット
+ o_square_stack.clear();
+
+ // ラベル数が0ならここまで(Labeling内部でソートするようにした。)
+ final int label_num = this._labeling.labeling(i_raster,this._limage);
+ if (label_num < 1) {
+ return;
+ }
+
+ final NyARLabelingLabelStack stack = limage.getLabelStack();
+ //ラベルをソートしておく
+ stack.sortByArea();
+ //
+ final NyARLabelingLabel[] labels = stack.getArray();
+
+ // デカいラベルを読み飛ばし
+ int i;
+ for (i = 0; i < label_num; i++) {
+ // 検査対象内のラベルサイズになるまで無視
+ if (labels[i].area <= AR_AREA_MAX) {
+ break;
+ }
+ }
+
+ final int xsize = this._width;
+ final int ysize = this._height;
+ final int[] xcoord = this._xcoord;
+ final int[] ycoord = this._ycoord;
+ final int coord_max = this._max_coord;
+ final LabelOverlapChecker<NyARLabelingLabel> overlap = this._overlap_checker;
+
+ //重なりチェッカの最大数を設定
+ overlap.setMaxLabels(label_num);
+
+ for (; i < label_num; i++) {
+ final NyARLabelingLabel label_pt = labels[i];
+ final int label_area = label_pt.area;
+ // 検査対象サイズよりも小さくなったら終了
+ if (label_area < AR_AREA_MIN) {
+ break;
+ }
+ // クリップ領域が画面の枠に接していれば除外
+ if (label_pt.clip_l == 1 || label_pt.clip_r == xsize - 2) {// if(wclip[i*4+0] == 1 || wclip[i*4+1] ==xsize-2){
+ continue;
+ }
+ if (label_pt.clip_t == 1 || label_pt.clip_b == ysize - 2) {// if( wclip[i*4+2] == 1 || wclip[i*4+3] ==ysize-2){
+ continue;
+ }
+ // 既に検出された矩形との重なりを確認
+ if (!overlap.check(label_pt)) {
+ // 重なっているようだ。
+ continue;
+ }
+ // 輪郭を取得
+ final int coord_num = _cpickup.getContour(limage,limage.getTopClipTangentX(label_pt),label_pt.clip_t, coord_max, xcoord, ycoord);
+ if (coord_num == coord_max) {
+ // 輪郭が大きすぎる。
+ continue;
+ }
+ //輪郭分析用に正規化する。
+ final int vertex1 = SquareContourDetector.normalizeCoord(xcoord, ycoord, coord_num);
+
+ //ここから先が輪郭分析
+ NyARSquare square_ptr = o_square_stack.prePush();
+ if(!this._sqconvertor.coordToSquare(xcoord,ycoord,vertex1,coord_num,label_area,square_ptr)){
+ o_square_stack.pop();// 頂点の取得が出来なかったので破棄
+ continue;
+ }
+ // 検出済の矩形の属したラベルを重なりチェックに追加する。
+ overlap.push(label_pt);
+ }
+ return;
+ }
+
+}
+
+
+
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/INyARSquareDetector.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/INyARSquareDetector.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/squaredetect/INyARSquareDetector.java (revision 302)
@@ -0,0 +1,39 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.squaredetect;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.raster.NyARBinRaster;
+
+public interface INyARSquareDetector
+{
+ public void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException;
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/INyARRotTransOptimize.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/INyARRotTransOptimize.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/INyARRotTransOptimize.java (revision 302)
@@ -1,43 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core.transmat.optimize;
-
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.transmat.fitveccalc.NyARFitVecCalculator;
-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.NyARRotMatrix;
-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;
-
-public interface INyARRotTransOptimize
-{
- public double optimize(NyARRotMatrix io_rotmat,NyARDoublePoint3d io_transvec,NyARFitVecCalculator i_calculator) throws NyARException;
-
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize_Base.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize_Base.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize_Base.java (revision 302)
@@ -1,221 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core.transmat.optimize;
-
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.param.*;
-import jp.nyatla.nyartoolkit.core.transmat.fitveccalc.NyARFitVecCalculator;
-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.NyARRotMatrix;
-import jp.nyatla.nyartoolkit.core.types.matrix.*;
-import jp.nyatla.nyartoolkit.core.types.*;
-
-/**
- * 処理構造がわかる程度に展開したNyARRotTransOptimize
- *
- */
-public class NyARRotTransOptimize_Base implements INyARRotTransOptimize
-{
- private final static int AR_GET_TRANS_MAT_MAX_LOOP_COUNT = 5;// #define AR_GET_TRANS_MAT_MAX_LOOP_COUNT 5
-
- private final static double AR_GET_TRANS_MAT_MAX_FIT_ERROR = 1.0;// #define AR_GET_TRANS_MAT_MAX_FIT_ERROR 1.0
-
- private final NyARPerspectiveProjectionMatrix _projection_mat_ref;
-
- public NyARRotTransOptimize_Base(NyARPerspectiveProjectionMatrix i_projection_mat_ref)
- {
- this._projection_mat_ref = i_projection_mat_ref;
- return;
- }
-
- final public double optimize(NyARRotMatrix io_rotmat, NyARDoublePoint3d io_transvec, NyARFitVecCalculator i_calculator) throws NyARException
- {
- final NyARDoublePoint2d[] fit_vertex = i_calculator.getFitSquare();
- final NyARDoublePoint3d[] offset_square = i_calculator.getOffsetVertex().vertex;
-
- double err = -1;
- /* ループを抜けるタイミングをARToolKitと合わせるために変なことしてます。 */
- for (int i = 0;; i++) {
- // <arGetTransMat3>
- err = modifyMatrix(io_rotmat, io_transvec, offset_square, fit_vertex);
- i_calculator.calculateTransfer(io_rotmat, io_transvec);
- err = modifyMatrix(io_rotmat, io_transvec, offset_square, fit_vertex);
- // //</arGetTransMat3>
- if (err < AR_GET_TRANS_MAT_MAX_FIT_ERROR || i == AR_GET_TRANS_MAT_MAX_LOOP_COUNT - 1) {
- break;
- }
- i_calculator.calculateTransfer(io_rotmat, io_transvec);
- }
- return err;
- }
- private double[] __createRotationMap_b_map=new double[6];
- private double[] __createRotationMap_c_map=new double[6];
- private double[] __createRotationMap_f=new double[3];
- private void createRotationMap(NyARDoublePoint3d i_angle,double i_factor,NyARDoubleMatrix33[] i_rot_matrix)
- {
- double sina,cosa,sinb,cosb,sinc,cosc;
- double CACA,SASA,SACA,SASB,CASB,SACACB,CACACB,SASACB;
-
-
- final double[] f=this.__createRotationMap_f;
- final double[] b_map=this.__createRotationMap_b_map;
- final double[] c_map=this.__createRotationMap_c_map;
- f[0]=-i_factor;
- f[1]=0;
- f[2]=i_factor;
- double ang1,ang2;
- //BとCのsinマップを先に作成
- for(int i=0;i<3;i++)
- {
- ang1=i_angle.y + f[i];
- b_map[i] =Math.sin(ang1);
- b_map[i+3]=Math.cos(ang1);
- ang2=i_angle.z + f[i];
- c_map[i] =Math.sin(ang2);
- c_map[i+3]=Math.cos(ang2);
- }
- int idx=0;
- int t1,t2,t3;
- for (t1 = 0; t1 < 3; t1++){
- ang1=i_angle.x + f[t1];
- sina = Math.sin(ang1);
- cosa = Math.cos(ang1);
- CACA = cosa * cosa;
- SASA = sina * sina;
- SACA = sina * cosa;
-
- for (t2=0;t2<3;t2++){
- sinb = b_map[t2];
- cosb = b_map[t2+3];
- SASB = sina * sinb;
- CASB = cosa * sinb;
- SACACB = SACA * cosb;
- CACACB = CACA * cosb;
- SASACB = SASA * cosb;
- for (t3=0;t3<3;t3++) {
- sinc = c_map[t3];
- cosc = c_map[t3+3];
- final NyARDoubleMatrix33 mat_ptr=i_rot_matrix[idx];
- mat_ptr.m00 = CACACB * cosc + SASA * cosc + SACACB * sinc - SACA * sinc;
- mat_ptr.m01 = -CACACB * sinc - SASA * sinc + SACACB * cosc - SACA * cosc;
- mat_ptr.m02 = CASB;
- mat_ptr.m10 = SACACB * cosc - SACA * cosc + SASACB * sinc + CACA * sinc;
- mat_ptr.m11 = -SACACB * sinc + SACA * sinc + SASACB * cosc + CACA * cosc;
- mat_ptr.m12 = SASB;
- mat_ptr.m20 = -CASB * cosc - SASB * sinc;
- mat_ptr.m21 = CASB * sinc - SASB * cosc;
- mat_ptr.m22 = cosb;
- idx++;
- }
- }
- }
- return;
- }
- private final void getNewMatrix(NyARDoubleMatrix33 i_rot, NyARDoublePoint3d i_trans, NyARDoubleMatrix34 o_combo)
- {
- double cp0,cp1,cp2,cp3;
- NyARPerspectiveProjectionMatrix cp=this._projection_mat_ref;
-
- cp3=cp.m03;
- cp0=cp.m00;cp1=cp.m01;cp2=cp.m02;
- o_combo.m00=cp0 * i_rot.m00 + cp1 * i_rot.m10 + cp2 * i_rot.m20;
- o_combo.m01=cp0 * i_rot.m01 + cp1 * i_rot.m11 + cp2 * i_rot.m21;
- o_combo.m02=cp0 * i_rot.m02 + cp1 * i_rot.m12 + cp2 * i_rot.m22;
- o_combo.m03=cp0 * i_trans.x + cp1 * i_trans.y + cp2 * i_trans.z +cp3;
-
- cp0=cp.m10;cp1=cp.m11;cp2=cp.m12;
- o_combo.m10=cp0 * i_rot.m00 + cp1 * i_rot.m10 + cp2 * i_rot.m20;
- o_combo.m11=cp0 * i_rot.m01 + cp1 * i_rot.m11 + cp2 * i_rot.m21;
- o_combo.m12=cp0 * i_rot.m02 + cp1 * i_rot.m12 + cp2 * i_rot.m22;
- o_combo.m13=cp0 * i_trans.x + cp1 * i_trans.y + cp2 * i_trans.z +cp3;
-
- cp0=cp.m20;cp1=cp.m21;cp2=cp.m22;
- o_combo.m20=cp0 * i_rot.m00 + cp1 * i_rot.m10 + cp2 * i_rot.m20;
- o_combo.m21=cp0 * i_rot.m01 + cp1 * i_rot.m11 + cp2 * i_rot.m21;
- o_combo.m22=cp0 * i_rot.m02 + cp1 * i_rot.m12 + cp2 * i_rot.m22;
- o_combo.m23=cp0 * i_trans.x + cp1 * i_trans.y + cp2 * i_trans.z +cp3;
- return;
- }
- private final NyARDoublePoint3d __modifyMatrix_angle = new NyARDoublePoint3d();
- private final NyARDoubleMatrix34 __modifyMatrix_combo=new NyARDoubleMatrix34();
- private final NyARDoubleMatrix33[] __modifyMatrix_next_rot_matrix=NyARDoubleMatrix33.createArray(27);
- public final double modifyMatrix(NyARRotMatrix io_rot, NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException
- {
- final NyARDoublePoint3d angle = this.__modifyMatrix_angle;
- final NyARDoubleMatrix34 combo=this.__modifyMatrix_combo;
- final NyARDoubleMatrix33[] next_rot_matrix=this.__modifyMatrix_next_rot_matrix;
- double factor;
- double hx, hy, h, x, y;
- double err, minerr = 0;
- int i,i2;
- int best_idx=0;
- angle.setValue(io_rot.refAngle());// arGetAngle( rot, &a, &b, &c );
- factor = 10.0 * Math.PI / 180.0;
- for (int j = 0; j < 10; j++){
- minerr = 1000000000.0;
- //評価用の角度マップ作成
- createRotationMap(angle,factor,next_rot_matrix);
- //評価して一番宜しいIDを保存
- best_idx=(1+1*3+1*9);
- for(i2=0;i2<27;i2++){
- this.getNewMatrix(next_rot_matrix[i2],trans,combo);
- err = 0.0;
- for (i = 0; i < 4; i++) {
- hx = combo.m00 * i_vertex3d[i].x + combo.m01 * i_vertex3d[i].y + combo.m02 * i_vertex3d[i].z + combo.m03;
- hy = combo.m10 * i_vertex3d[i].x + combo.m11 *i_vertex3d[i].y + combo.m12 * i_vertex3d[i].z + combo.m13;
- h = combo.m20 * i_vertex3d[i].x + combo.m21 * i_vertex3d[i].y + combo.m22 * i_vertex3d[i].z + combo.m23;
- x = i_vertex2d[i].x-(hx / h);
- y = i_vertex2d[i].y-(hy / h);
- err += x*x+y*y;
- }
- if (err < minerr){
- minerr = err;
- best_idx=i2;
- }
-
- }
- if (best_idx==(1+1*3+1*9)){
- factor *= 0.5;
- }else{
- angle.z+=factor*(best_idx%3-1);
- angle.y+=factor*((best_idx/3)%3-1);
- angle.x+=factor*((best_idx/9)%3-1);
- }
- }
- io_rot.setAngle(angle.x,angle.y,angle.z);
- /* printf("factor = %10.5f\n", factor*180.0/MD_PI); */
- return minerr / 4;
- }
-
-
-
-
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize.java (revision 302)
@@ -1,291 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core.transmat.optimize;
-
-
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.param.*;
-import jp.nyatla.nyartoolkit.core.transmat.fitveccalc.NyARFitVecCalculator;
-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.NyARRotMatrix;
-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;
-/**
- * 基本姿勢と実画像を一致するように、角度を微調整→平行移動量を再計算
- * を繰り返して、変換行列を最適化する。
- *
- */
-public class NyARRotTransOptimize implements INyARRotTransOptimize
-{
- private final static int AR_GET_TRANS_MAT_MAX_LOOP_COUNT = 5;// #define AR_GET_TRANS_MAT_MAX_LOOP_COUNT 5
- private final static double AR_GET_TRANS_MAT_MAX_FIT_ERROR = 1.0;// #define AR_GET_TRANS_MAT_MAX_FIT_ERROR 1.0
- private final NyARPerspectiveProjectionMatrix _projection_mat_ref;
- public NyARRotTransOptimize(NyARPerspectiveProjectionMatrix i_projection_mat_ref)
- {
- this._projection_mat_ref=i_projection_mat_ref;
- return;
- }
-
- final public double optimize(NyARRotMatrix io_rotmat,NyARDoublePoint3d io_transvec,NyARFitVecCalculator i_calculator) throws NyARException
- {
- final NyARDoublePoint2d[] fit_vertex=i_calculator.getFitSquare();
- final NyARDoublePoint3d[] offset_square=i_calculator.getOffsetVertex().vertex;
-
- double err = -1;
- /*ループを抜けるタイミングをARToolKitと合わせるために変なことしてます。*/
- for (int i = 0;; i++) {
- // <arGetTransMat3>
- err = modifyMatrix(io_rotmat,io_transvec,offset_square,fit_vertex);
- i_calculator.calculateTransfer(io_rotmat, io_transvec);
- err = modifyMatrix(io_rotmat,io_transvec,offset_square,fit_vertex);
- // //</arGetTransMat3>
- if (err < AR_GET_TRANS_MAT_MAX_FIT_ERROR || i == AR_GET_TRANS_MAT_MAX_LOOP_COUNT-1) {
- break;
- }
- i_calculator.calculateTransfer(io_rotmat, io_transvec);
- }
- return err;
- }
-
- private final double[][] __modifyMatrix_double1D = new double[8][3];
- /**
- * arGetRot計算を階層化したModifyMatrix 896
- *
- * @param nyrot
- * @param trans
- * @param i_vertex3d
- * [m][3]
- * @param i_vertex2d
- * [n][2]
- * @return
- * @throws NyARException
- */
- private double modifyMatrix(NyARRotMatrix io_rot,NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException
- {
- double factor;
- double a2, b2, c2;
- double ma = 0.0, mb = 0.0, mc = 0.0;
- double h, x, y;
- double err, minerr = 0;
- int t1, t2, t3;
- int s1 = 0, s2 = 0, s3 = 0;
-
- factor = 10.0 * Math.PI / 180.0;
- double rot0, rot1, rot3, rot4, rot6, rot7;
- double combo00, combo01, combo02, combo03, combo10, combo11, combo12, combo13, combo20, combo21, combo22, combo23;
- double combo02_2, combo02_5, combo02_8, combo02_11;
- double combo22_2, combo22_5, combo22_8, combo22_11;
- double combo12_2, combo12_5, combo12_8, combo12_11;
- // vertex展開
- final double VX00, VX01, VX02, VX10, VX11, VX12, VX20, VX21, VX22, VX30, VX31, VX32;
- NyARDoublePoint3d d_pt;
- d_pt = i_vertex3d[0];
- VX00 = d_pt.x;
- VX01 = d_pt.y;
- VX02 = d_pt.z;
- d_pt = i_vertex3d[1];
- VX10 = d_pt.x;
- VX11 = d_pt.y;
- VX12 = d_pt.z;
- d_pt = i_vertex3d[2];
- VX20 = d_pt.x;
- VX21 = d_pt.y;
- VX22 = d_pt.z;
- d_pt = i_vertex3d[3];
- VX30 = d_pt.x;
- VX31 = d_pt.y;
- VX32 = d_pt.z;
- final double P2D00, P2D01, P2D10, P2D11, P2D20, P2D21, P2D30, P2D31;
- NyARDoublePoint2d d_pt2;
- d_pt2 = i_vertex2d[0];
- P2D00 = d_pt2.x;
- P2D01 = d_pt2.y;
- d_pt2 = i_vertex2d[1];
- P2D10 = d_pt2.x;
- P2D11 = d_pt2.y;
- d_pt2 = i_vertex2d[2];
- P2D20 = d_pt2.x;
- P2D21 = d_pt2.y;
- d_pt2 = i_vertex2d[3];
- P2D30 = d_pt2.x;
- P2D31 = d_pt2.y;
- final NyARPerspectiveProjectionMatrix prjmat = this._projection_mat_ref;
- final double CP0, CP1, CP2, CP4, CP5, CP6, CP8, CP9, CP10;
- CP0 = prjmat.m00;
- CP1 = prjmat.m01;
- CP2 = prjmat.m02;
- CP4 = prjmat.m10;
- CP5 = prjmat.m11;
- CP6 = prjmat.m12;
- CP8 = prjmat.m20;
- CP9 = prjmat.m21;
- CP10 = prjmat.m22;
- combo03 = CP0 * trans.x + CP1 * trans.y + CP2 * trans.z + prjmat.m03;
- combo13 = CP4 * trans.x + CP5 * trans.y + CP6 * trans.z + prjmat.m13;
- combo23 = CP8 * trans.x + CP9 * trans.y + CP10 * trans.z + prjmat.m23;
- double CACA, SASA, SACA, CA, SA;
- double CACACB, SACACB, SASACB, CASB, SASB;
- double SACASC, SACACBSC, SACACBCC, SACACC;
- final double[][] double1D = this.__modifyMatrix_double1D;
-
-
- final double[] a_factor = double1D[1];
- final double[] sinb = double1D[2];
- final double[] cosb = double1D[3];
- final double[] b_factor = double1D[4];
- final double[] sinc = double1D[5];
- final double[] cosc = double1D[6];
- final double[] c_factor = double1D[7];
- double w, w2;
- double wsin, wcos;
-
- //現在の角度を確保
- final NyARDoublePoint3d angle = io_rot.refAngle();
- a2 = angle.x;
- b2 = angle.y;
- c2 = angle.z;
-
- // comboの3行目を先に計算
- for (int i = 0; i < 10; i++) {
- minerr = 1000000000.0;
- // sin-cosテーブルを計算(これが外に出せるとは…。)
- for (int j = 0; j < 3; j++) {
- w2 = factor * (j - 1);
- w = a2 + w2;
- a_factor[j] = w;
- w = b2 + w2;
- b_factor[j] = w;
- sinb[j] = Math.sin(w);
- cosb[j] = Math.cos(w);
- w = c2 + w2;
- c_factor[j] = w;
- sinc[j] = Math.sin(w);
- cosc[j] = Math.cos(w);
- }
- //
- for (t1 = 0; t1 < 3; t1++) {
- SA = Math.sin(a_factor[t1]);
- CA = Math.cos(a_factor[t1]);
- // Optimize
- CACA = CA * CA;
- SASA = SA * SA;
- SACA = SA * CA;
- for (t2 = 0; t2 < 3; t2++) {
- wsin = sinb[t2];
- wcos = cosb[t2];
- CACACB = CACA * wcos;
- SACACB = SACA * wcos;
- SASACB = SASA * wcos;
- CASB = CA * wsin;
- SASB = SA * wsin;
- // comboの計算1
- combo02 = CP0 * CASB + CP1 * SASB + CP2 * wcos;
- combo12 = CP4 * CASB + CP5 * SASB + CP6 * wcos;
- combo22 = CP8 * CASB + CP9 * SASB + CP10 * wcos;
-
- combo02_2 = combo02 * VX02 + combo03;
- combo02_5 = combo02 * VX12 + combo03;
- combo02_8 = combo02 * VX22 + combo03;
- combo02_11 = combo02 * VX32 + combo03;
- combo12_2 = combo12 * VX02 + combo13;
- combo12_5 = combo12 * VX12 + combo13;
- combo12_8 = combo12 * VX22 + combo13;
- combo12_11 = combo12 * VX32 + combo13;
- combo22_2 = combo22 * VX02 + combo23;
- combo22_5 = combo22 * VX12 + combo23;
- combo22_8 = combo22 * VX22 + combo23;
- combo22_11 = combo22 * VX32 + combo23;
- for (t3 = 0; t3 < 3; t3++) {
- wsin = sinc[t3];
- wcos = cosc[t3];
- SACASC = SACA * wsin;
- SACACC = SACA * wcos;
- SACACBSC = SACACB * wsin;
- SACACBCC = SACACB * wcos;
-
- rot0 = CACACB * wcos + SASA * wcos + SACACBSC - SACASC;
- rot3 = SACACBCC - SACACC + SASACB * wsin + CACA * wsin;
- rot6 = -CASB * wcos - SASB * wsin;
-
- combo00 = CP0 * rot0 + CP1 * rot3 + CP2 * rot6;
- combo10 = CP4 * rot0 + CP5 * rot3 + CP6 * rot6;
- combo20 = CP8 * rot0 + CP9 * rot3 + CP10 * rot6;
-
- rot1 = -CACACB * wsin - SASA * wsin + SACACBCC - SACACC;
- rot4 = -SACACBSC + SACASC + SASACB * wcos + CACA * wcos;
- rot7 = CASB * wsin - SASB * wcos;
- combo01 = CP0 * rot1 + CP1 * rot4 + CP2 * rot7;
- combo11 = CP4 * rot1 + CP5 * rot4 + CP6 * rot7;
- combo21 = CP8 * rot1 + CP9 * rot4 + CP10 * rot7;
- //
- err = 0.0;
- h = combo20 * VX00 + combo21 * VX01 + combo22_2;
- x = P2D00 - (combo00 * VX00 + combo01 * VX01 + combo02_2) / h;
- y = P2D01 - (combo10 * VX00 + combo11 * VX01 + combo12_2) / h;
- err += x * x + y * y;
- h = combo20 * VX10 + combo21 * VX11 + combo22_5;
- x = P2D10 - (combo00 * VX10 + combo01 * VX11 + combo02_5) / h;
- y = P2D11 - (combo10 * VX10 + combo11 * VX11 + combo12_5) / h;
- err += x * x + y * y;
- h = combo20 * VX20 + combo21 * VX21 + combo22_8;
- x = P2D20 - (combo00 * VX20 + combo01 * VX21 + combo02_8) / h;
- y = P2D21 - (combo10 * VX20 + combo11 * VX21 + combo12_8) / h;
- err += x * x + y * y;
- h = combo20 * VX30 + combo21 * VX31 + combo22_11;
- x = P2D30 - (combo00 * VX30 + combo01 * VX31 + combo02_11) / h;
- y = P2D31 - (combo10 * VX30 + combo11 * VX31 + combo12_11) / h;
- err += x * x + y * y;
- if (err < minerr) {
- minerr = err;
- ma = a_factor[t1];
- mb = b_factor[t2];
- mc = c_factor[t3];
- s1 = t1 - 1;
- s2 = t2 - 1;
- s3 = t3 - 1;
- }
- }
- }
- }
- if (s1 == 0 && s2 == 0 && s3 == 0) {
- factor *= 0.5;
- }
- a2 = ma;
- b2 = mb;
- c2 = mc;
- }
- io_rot.setAngle(ma, mb, mc);
- /* printf("factor = %10.5f\n", factor*180.0/MD_PI); */
- return minerr / 4;
- }
-
-
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize_O2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize_O2.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARRotTransOptimize_O2.java (revision 302)
@@ -1,262 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core.transmat.optimize;
-
-
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.param.*;
-import jp.nyatla.nyartoolkit.core.transmat.fitveccalc.NyARFitVecCalculator;
-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.NyARRotMatrix;
-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;
-/**
- * 基本姿勢と実画像を一致するように、角度を微調整→平行移動量を再計算
- * を繰り返して、変換行列を最適化する。
- *
- */
-public class NyARRotTransOptimize_O2 implements INyARRotTransOptimize
-{
- private final static int AR_GET_TRANS_MAT_MAX_LOOP_COUNT = 5;// #define AR_GET_TRANS_MAT_MAX_LOOP_COUNT 5
- private final static double AR_GET_TRANS_MAT_MAX_FIT_ERROR = 1.0;// #define AR_GET_TRANS_MAT_MAX_FIT_ERROR 1.0
- private final NyARPerspectiveProjectionMatrix _projection_mat_ref;
- public NyARRotTransOptimize_O2(NyARPerspectiveProjectionMatrix i_projection_mat_ref)
- {
- this._projection_mat_ref=i_projection_mat_ref;
- return;
- }
-
- final public double optimize(NyARRotMatrix io_rotmat,NyARDoublePoint3d io_transvec,NyARFitVecCalculator i_calculator) throws NyARException
- {
- final NyARDoublePoint2d[] fit_vertex=i_calculator.getFitSquare();
- final NyARDoublePoint3d[] offset_square=i_calculator.getOffsetVertex().vertex;
-
- double err = -1;
- /*ループを抜けるタイミングをARToolKitと合わせるために変なことしてます。*/
- for (int i = 0;; i++) {
- // <arGetTransMat3>
- err = modifyMatrix(io_rotmat,io_transvec,offset_square,fit_vertex);
- i_calculator.calculateTransfer(io_rotmat, io_transvec);
- err = modifyMatrix(io_rotmat,io_transvec,offset_square,fit_vertex);
- // //</arGetTransMat3>
- if (err < AR_GET_TRANS_MAT_MAX_FIT_ERROR || i == AR_GET_TRANS_MAT_MAX_LOOP_COUNT-1) {
- break;
- }
- i_calculator.calculateTransfer(io_rotmat, io_transvec);
- }
- return err;
- }
-
- private final double[][] __modifyMatrix_double1D = new double[8][3];
- /**
- * arGetRot計算を階層化したModifyMatrix 896
- *
- * @param trans
- * @param i_vertex3d
- * [m][3]
- * @param i_vertex2d
- * [n][2]
- * @return
- * @throws NyARException
- */
- private double modifyMatrix(NyARRotMatrix io_rot,NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException
- {
- double factor;
- double a2, b2, c2;
- double h, x, y;
- double err, minerr = 0;
- int t1, t2, t3;
- int best_idx=0;
-
- factor = 10.0 * Math.PI / 180.0;
- double rot0, rot1, rot2;
- double combo00, combo01, combo02, combo03, combo10, combo11, combo12, combo13, combo20, combo21, combo22, combo23;
- double combo02_2, combo02_5, combo02_8, combo02_11;
- double combo22_2, combo22_5, combo22_8, combo22_11;
- double combo12_2, combo12_5, combo12_8, combo12_11;
- // vertex展開
- final double VX00, VX01, VX02, VX10, VX11, VX12, VX20, VX21, VX22, VX30, VX31, VX32;
- VX00 = i_vertex3d[0].x;
- VX01 = i_vertex3d[0].y;
- VX02 = i_vertex3d[0].z;
- VX10 = i_vertex3d[1].x;
- VX11 = i_vertex3d[1].y;
- VX12 = i_vertex3d[1].z;
- VX20 = i_vertex3d[2].x;
- VX21 = i_vertex3d[2].y;
- VX22 = i_vertex3d[2].z;
- VX30 = i_vertex3d[3].x;
- VX31 = i_vertex3d[3].y;
- VX32 = i_vertex3d[3].z;
- final double P2D00, P2D01, P2D10, P2D11, P2D20, P2D21, P2D30, P2D31;
- P2D00 = i_vertex2d[0].x;
- P2D01 = i_vertex2d[0].y;
- P2D10 = i_vertex2d[1].x;
- P2D11 = i_vertex2d[1].y;
- P2D20 = i_vertex2d[2].x;
- P2D21 = i_vertex2d[2].y;
- P2D30 = i_vertex2d[3].x;
- P2D31 = i_vertex2d[3].y;
- final NyARPerspectiveProjectionMatrix prjmat = this._projection_mat_ref;
- final double CP0 = prjmat.m00,CP1 = prjmat.m01,CP2 = prjmat.m02,CP4 = prjmat.m10,CP5 = prjmat.m11,CP6 = prjmat.m12,CP8 = prjmat.m20,CP9 = prjmat.m21,CP10 = prjmat.m22;
- combo03 = CP0 * trans.x + CP1 * trans.y + CP2 * trans.z + prjmat.m03;
- combo13 = CP4 * trans.x + CP5 * trans.y + CP6 * trans.z + prjmat.m13;
- combo23 = CP8 * trans.x + CP9 * trans.y + CP10 * trans.z + prjmat.m23;
- double CACA, SASA, SACA, CA, SA;
- double CACACB, SACACB, SASACB, CASB, SASB;
- double SACASC, SACACBSC, SACACBCC, SACACC;
- final double[][] double1D = this.__modifyMatrix_double1D;
-
- final double[] a_factor = double1D[1];
- final double[] sinb = double1D[2];
- final double[] cosb = double1D[3];
- final double[] b_factor = double1D[4];
- final double[] sinc = double1D[5];
- final double[] cosc = double1D[6];
- final double[] c_factor = double1D[7];
- double w, w2;
- double wsin, wcos;
-
- final NyARDoublePoint3d angle = io_rot.refAngle();
- a2 = angle.x;
- b2 = angle.y;
- c2 = angle.z;
-
- // comboの3行目を先に計算
- for (int i = 0; i < 10; i++) {
- minerr = 1000000000.0;
- // sin-cosテーブルを計算(これが外に出せるとは…。)
- for (int j = 0; j < 3; j++) {
- w2 = factor * (j - 1);
- w = a2 + w2;
- a_factor[j] = w;
- w = b2 + w2;
- b_factor[j] = w;
- sinb[j] = Math.sin(w);
- cosb[j] = Math.cos(w);
- w = c2 + w2;
- c_factor[j] = w;
- sinc[j] = Math.sin(w);
- cosc[j] = Math.cos(w);
- }
- //
- for (t1 = 0; t1 < 3; t1++) {
- SA = Math.sin(a_factor[t1]);
- CA = Math.cos(a_factor[t1]);
- // Optimize
- CACA = CA * CA;
- SASA = SA * SA;
- SACA = SA * CA;
- for (t2 = 0; t2 < 3; t2++) {
- wsin = sinb[t2];
- wcos = cosb[t2];
- CACACB = CACA * wcos;
- SACACB = SACA * wcos;
- SASACB = SASA * wcos;
- CASB = CA * wsin;
- SASB = SA * wsin;
- // comboの計算1
- combo02 = CP0 * CASB + CP1 * SASB + CP2 * wcos;
- combo12 = CP4 * CASB + CP5 * SASB + CP6 * wcos;
- combo22 = CP8 * CASB + CP9 * SASB + CP10 * wcos;
-
- combo02_2 = combo02 * VX02 + combo03;
- combo02_5 = combo02 * VX12 + combo03;
- combo02_8 = combo02 * VX22 + combo03;
- combo02_11 = combo02 * VX32 + combo03;
- combo12_2 = combo12 * VX02 + combo13;
- combo12_5 = combo12 * VX12 + combo13;
- combo12_8 = combo12 * VX22 + combo13;
- combo12_11 = combo12 * VX32 + combo13;
- combo22_2 = combo22 * VX02 + combo23;
- combo22_5 = combo22 * VX12 + combo23;
- combo22_8 = combo22 * VX22 + combo23;
- combo22_11 = combo22 * VX32 + combo23;
- for (t3 = 0; t3 < 3; t3++) {
- wsin = sinc[t3];
- wcos = cosc[t3];
- SACASC = SACA * wsin;
- SACACC = SACA * wcos;
- SACACBSC = SACACB * wsin;
- SACACBCC = SACACB * wcos;
-
- rot0 = CACACB * wcos + SASA * wcos + SACACBSC - SACASC;
- rot1 = SACACBCC - SACACC + SASACB * wsin + CACA * wsin;
- rot2 = -CASB * wcos - SASB * wsin;
- combo00 = CP0 * rot0 + CP1 * rot1 + CP2 * rot2;
- combo10 = CP4 * rot0 + CP5 * rot1 + CP6 * rot2;
- combo20 = CP8 * rot0 + CP9 * rot1 + CP10 * rot2;
-
- rot0 = -CACACB * wsin - SASA * wsin + SACACBCC - SACACC;
- rot1 = -SACACBSC + SACASC + SASACB * wcos + CACA * wcos;
- rot2 = CASB * wsin - SASB * wcos;
- combo01 = CP0 * rot0 + CP1 * rot1 + CP2 * rot2;
- combo11 = CP4 * rot0 + CP5 * rot1 + CP6 * rot2;
- combo21 = CP8 * rot0 + CP9 * rot1 + CP10 * rot2;
- //
- err = 0.0;
- h = combo20 * VX00 + combo21 * VX01 + combo22_2;
- x = P2D00 - (combo00 * VX00 + combo01 * VX01 + combo02_2) / h;
- y = P2D01 - (combo10 * VX00 + combo11 * VX01 + combo12_2) / h;
- err += x * x + y * y;
- h = combo20 * VX10 + combo21 * VX11 + combo22_5;
- x = P2D10 - (combo00 * VX10 + combo01 * VX11 + combo02_5) / h;
- y = P2D11 - (combo10 * VX10 + combo11 * VX11 + combo12_5) / h;
- err += x * x + y * y;
- h = combo20 * VX20 + combo21 * VX21 + combo22_8;
- x = P2D20 - (combo00 * VX20 + combo01 * VX21 + combo02_8) / h;
- y = P2D21 - (combo10 * VX20 + combo11 * VX21 + combo12_8) / h;
- err += x * x + y * y;
- h = combo20 * VX30 + combo21 * VX31 + combo22_11;
- x = P2D30 - (combo00 * VX30 + combo01 * VX31 + combo02_11) / h;
- y = P2D31 - (combo10 * VX30 + combo11 * VX31 + combo12_11) / h;
- err += x * x + y * y;
- if (err < minerr) {
- minerr = err;
- a2 = a_factor[t1];
- b2 = b_factor[t2];
- c2 = c_factor[t3];
- best_idx=t1+t2*3+t3*9;
- }
- }
- }
- }
- if (best_idx==(1+3+9)) {
- factor *= 0.5;
- }
- }
- io_rot.setAngle(a2, b2, c2);
- /* printf("factor = %10.5f\n", factor*180.0/MD_PI); */
- return minerr /4;
- }
-
-
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARPartialDifferentiationOptimize.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARPartialDifferentiationOptimize.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARPartialDifferentiationOptimize.java (revision 302)
@@ -0,0 +1,388 @@
+/*
+ * PROJECT: NyARToolkit (Extension)
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.transmat.optimize;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.param.*;
+
+import jp.nyatla.nyartoolkit.core.types.*;
+import jp.nyatla.nyartoolkit.core.types.matrix.*;
+import jp.nyatla.nyartoolkit.core.utils.*;
+
+class TSinCosValue{
+ public double cos_val;
+ public double sin_val;
+ public static TSinCosValue[] createArray(int i_size)
+ {
+ TSinCosValue[] result=new TSinCosValue[i_size];
+ for(int i=0;i<i_size;i++){
+ result[i]=new TSinCosValue();
+ }
+ return result;
+ }
+}
+
+/**
+ * 基本姿勢と実画像を一致するように、角度を微調整→平行移動量を再計算 を繰り返して、変換行列を最適化する。
+ *
+ */
+public class NyARPartialDifferentiationOptimize
+{
+ private final NyARPerspectiveProjectionMatrix _projection_mat_ref;
+
+ public NyARPartialDifferentiationOptimize(NyARPerspectiveProjectionMatrix i_projection_mat_ref)
+ {
+ this._projection_mat_ref = i_projection_mat_ref;
+ return;
+ }
+
+ public final void sincos2Rotation_ZXY(TSinCosValue[] i_sincos, NyARDoubleMatrix33 i_rot_matrix)
+ {
+ final double sina = i_sincos[0].sin_val;
+ final double cosa = i_sincos[0].cos_val;
+ final double sinb = i_sincos[1].sin_val;
+ final double cosb = i_sincos[1].cos_val;
+ final double sinc = i_sincos[2].sin_val;
+ final double cosc = i_sincos[2].cos_val;
+ i_rot_matrix.m00 = cosc * cosb - sinc * sina * sinb;
+ i_rot_matrix.m01 = -sinc * cosa;
+ i_rot_matrix.m02 = cosc * sinb + sinc * sina * cosb;
+ i_rot_matrix.m10 = sinc * cosb + cosc * sina * sinb;
+ i_rot_matrix.m11 = cosc * cosa;
+ i_rot_matrix.m12 = sinc * sinb - cosc * sina * cosb;
+ i_rot_matrix.m20 = -cosa * sinb;
+ i_rot_matrix.m21 = sina;
+ i_rot_matrix.m22 = cosb * cosa;
+ }
+
+ private final void rotation2Sincos_ZXY(NyARDoubleMatrix33 i_rot_matrix, TSinCosValue[] o_out,NyARDoublePoint3d o_ang)
+ {
+ double x, y, z;
+ double sina = i_rot_matrix.m21;
+ if (sina >= 1.0) {
+ x = Math.PI / 2;
+ y = 0;
+ z = Math.atan2(-i_rot_matrix.m10, i_rot_matrix.m00);
+ } else if (sina <= -1.0) {
+ x = -Math.PI / 2;
+ y = 0;
+ z = Math.atan2(-i_rot_matrix.m10, i_rot_matrix.m00);
+ } else {
+ x = Math.asin(sina);
+ y = Math.atan2(-i_rot_matrix.m20, i_rot_matrix.m22);
+ z = Math.atan2(-i_rot_matrix.m01, i_rot_matrix.m11);
+ }
+ o_ang.x=x;
+ o_ang.y=y;
+ o_ang.z=z;
+ o_out[0].sin_val = Math.sin(x);
+ o_out[0].cos_val = Math.cos(x);
+ o_out[1].sin_val = Math.sin(y);
+ o_out[1].cos_val = Math.cos(y);
+ o_out[2].sin_val = Math.sin(z);
+ o_out[2].cos_val = Math.cos(z);
+ return;
+ }
+
+ /*
+ * 射影変換式 基本式 ox=(cosc * cosb - sinc * sina * sinb)*ix+(-sinc * cosa)*iy+(cosc * sinb + sinc * sina * cosb)*iz+i_trans.x; oy=(sinc * cosb + cosc * sina *
+ * sinb)*ix+(cosc * cosa)*iy+(sinc * sinb - cosc * sina * cosb)*iz+i_trans.y; oz=(-cosa * sinb)*ix+(sina)*iy+(cosb * cosa)*iz+i_trans.z;
+ *
+ * double ox=(cosc * cosb)*ix+(-sinc * sina * sinb)*ix+(-sinc * cosa)*iy+(cosc * sinb)*iz + (sinc * sina * cosb)*iz+i_trans.x; double oy=(sinc * cosb)*ix
+ * +(cosc * sina * sinb)*ix+(cosc * cosa)*iy+(sinc * sinb)*iz+(- cosc * sina * cosb)*iz+i_trans.y; double oz=(-cosa * sinb)*ix+(sina)*iy+(cosb *
+ * cosa)*iz+i_trans.z;
+ *
+ * sina,cosaについて解く cx=(cp00*(-sinc*sinb*ix+sinc*cosb*iz)+cp01*(cosc*sinb*ix-cosc*cosb*iz)+cp02*(iy))*sina
+ * +(cp00*(-sinc*iy)+cp01*((cosc*iy))+cp02*(-sinb*ix+cosb*iz))*cosa
+ * +(cp00*(i_trans.x+cosc*cosb*ix+cosc*sinb*iz)+cp01*((i_trans.y+sinc*cosb*ix+sinc*sinb*iz))+cp02*(i_trans.z));
+ * cy=(cp11*(cosc*sinb*ix-cosc*cosb*iz)+cp12*(iy))*sina +(cp11*((cosc*iy))+cp12*(-sinb*ix+cosb*iz))*cosa
+ * +(cp11*((i_trans.y+sinc*cosb*ix+sinc*sinb*iz))+cp12*(i_trans.z)); ch=(iy)*sina +(-sinb*ix+cosb*iz)*cosa +i_trans.z; sinb,cosb hx=(cp00*(-sinc *
+ * sina*ix+cosc*iz)+cp01*(cosc * sina*ix+sinc*iz)+cp02*(-cosa*ix))*sinb +(cp01*(sinc*ix-cosc * sina*iz)+cp00*(cosc*ix+sinc * sina*iz)+cp02*(cosa*iz))*cosb
+ * +(cp00*(i_trans.x+(-sinc*cosa)*iy)+cp01*(i_trans.y+(cosc * cosa)*iy)+cp02*(i_trans.z+(sina)*iy)); double hy=(cp11*(cosc *
+ * sina*ix+sinc*iz)+cp12*(-cosa*ix))*sinb +(cp11*(sinc*ix-cosc * sina*iz)+cp12*(cosa*iz))*cosb +(cp11*(i_trans.y+(cosc *
+ * cosa)*iy)+cp12*(i_trans.z+(sina)*iy)); double h =((-cosa*ix)*sinb +(cosa*iz)*cosb +i_trans.z+(sina)*iy); パラメータ返還式 L=2*Σ(d[n]*e[n]+a[n]*b[n])
+ * J=2*Σ(d[n]*f[n]+a[n]*c[n])/L K=2*Σ(-e[n]*f[n]+b[n]*c[n])/L M=Σ(-e[n]^2+d[n]^2-b[n]^2+a[n]^2)/L 偏微分式 +J*cos(x) +K*sin(x) -sin(x)^2 +cos(x)^2
+ * +2*M*cos(x)*sin(x)
+ */
+ private double optimizeParamX(TSinCosValue i_angle_y, TSinCosValue i_angle_z, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d, int i_number_of_vertex, double i_hint_angle) throws NyARException
+ {
+ NyARPerspectiveProjectionMatrix cp = this._projection_mat_ref;
+ final double sinb = i_angle_y.sin_val;
+ final double cosb = i_angle_y.cos_val;
+ final double sinc = i_angle_z.sin_val;
+ final double cosc = i_angle_z.cos_val;
+ double L, J, K, M, N, O;
+ L = J = K = M = N = O = 0;
+ for (int i = 0; i < i_number_of_vertex; i++) {
+ double ix, iy, iz;
+ ix = i_vertex3d[i].x;
+ iy = i_vertex3d[i].y;
+ iz = i_vertex3d[i].z;
+
+ final double cp00 = cp.m00;
+ final double cp01 = cp.m01;
+ final double cp02 = cp.m02;
+ final double cp11 = cp.m11;
+ final double cp12 = cp.m12;
+
+ double X0 = (cp00 * (-sinc * sinb * ix + sinc * cosb * iz) + cp01 * (cosc * sinb * ix - cosc * cosb * iz) + cp02 * (iy));
+ double X1 = (cp00 * (-sinc * iy) + cp01 * ((cosc * iy)) + cp02 * (-sinb * ix + cosb * iz));
+ double X2 = (cp00 * (i_trans.x + cosc * cosb * ix + cosc * sinb * iz) + cp01 * ((i_trans.y + sinc * cosb * ix + sinc * sinb * iz)) + cp02 * (i_trans.z));
+ double Y0 = (cp11 * (cosc * sinb * ix - cosc * cosb * iz) + cp12 * (iy));
+ double Y1 = (cp11 * ((cosc * iy)) + cp12 * (-sinb * ix + cosb * iz));
+ double Y2 = (cp11 * ((i_trans.y + sinc * cosb * ix + sinc * sinb * iz)) + cp12 * (i_trans.z));
+ double H0 = (iy);
+ double H1 = (-sinb * ix + cosb * iz);
+ double H2 = i_trans.z;
+
+ double VX = i_vertex2d[i].x;
+ double VY = i_vertex2d[i].y;
+
+ double a, b, c, d, e, f;
+ a = (VX * H0 - X0);
+ b = (VX * H1 - X1);
+ c = (VX * H2 - X2);
+ d = (VY * H0 - Y0);
+ e = (VY * H1 - Y1);
+ f = (VY * H2 - Y2);
+
+ L += d * e + a * b;
+ N += d * d + a * a;
+ J += d * f + a * c;
+ M += e * e + b * b;
+ K += e * f + b * c;
+ O += f * f + c * c;
+
+ }
+ L *=2;
+ J *=2;
+ K *=2;
+
+ return getMinimumErrorAngleFromParam(L,J, K, M, N, O, i_hint_angle);
+
+
+ }
+
+ private double optimizeParamY(TSinCosValue i_angle_x, TSinCosValue i_angle_z, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d, int i_number_of_vertex, double i_hint_angle) throws NyARException
+ {
+ NyARPerspectiveProjectionMatrix cp = this._projection_mat_ref;
+ final double sina = i_angle_x.sin_val;
+ final double cosa = i_angle_x.cos_val;
+ final double sinc = i_angle_z.sin_val;
+ final double cosc = i_angle_z.cos_val;
+ double L, J, K, M, N, O;
+ L = J = K = M = N = O = 0;
+ for (int i = 0; i < i_number_of_vertex; i++) {
+ double ix, iy, iz;
+ ix = i_vertex3d[i].x;
+ iy = i_vertex3d[i].y;
+ iz = i_vertex3d[i].z;
+
+ final double cp00 = cp.m00;
+ final double cp01 = cp.m01;
+ final double cp02 = cp.m02;
+ final double cp11 = cp.m11;
+ final double cp12 = cp.m12;
+
+ double X0 = (cp00 * (-sinc * sina * ix + cosc * iz) + cp01 * (cosc * sina * ix + sinc * iz) + cp02 * (-cosa * ix));
+ double X1 = (cp01 * (sinc * ix - cosc * sina * iz) + cp00 * (cosc * ix + sinc * sina * iz) + cp02 * (cosa * iz));
+ double X2 = (cp00 * (i_trans.x + (-sinc * cosa) * iy) + cp01 * (i_trans.y + (cosc * cosa) * iy) + cp02 * (i_trans.z + (sina) * iy));
+ double Y0 = (cp11 * (cosc * sina * ix + sinc * iz) + cp12 * (-cosa * ix));
+ double Y1 = (cp11 * (sinc * ix - cosc * sina * iz) + cp12 * (cosa * iz));
+ double Y2 = (cp11 * (i_trans.y + (cosc * cosa) * iy) + cp12 * (i_trans.z + (sina) * iy));
+ double H0 = (-cosa * ix);
+ double H1 = (cosa * iz);
+ double H2 = i_trans.z + (sina) * iy;
+
+ double VX = i_vertex2d[i].x;
+ double VY = i_vertex2d[i].y;
+
+ double a, b, c, d, e, f;
+ a = (VX * H0 - X0);
+ b = (VX * H1 - X1);
+ c = (VX * H2 - X2);
+ d = (VY * H0 - Y0);
+ e = (VY * H1 - Y1);
+ f = (VY * H2 - Y2);
+
+ L += d * e + a * b;
+ N += d * d + a * a;
+ J += d * f + a * c;
+ M += e * e + b * b;
+ K += e * f + b * c;
+ O += f * f + c * c;
+
+ }
+ L *= 2;
+ J *= 2;
+ K *= 2;
+ return getMinimumErrorAngleFromParam(L,J, K, M, N, O, i_hint_angle);
+
+ }
+
+ private double optimizeParamZ(TSinCosValue i_angle_x, TSinCosValue i_angle_y, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d, int i_number_of_vertex, double i_hint_angle) throws NyARException
+ {
+ NyARPerspectiveProjectionMatrix cp = this._projection_mat_ref;
+ final double sina = i_angle_x.sin_val;
+ final double cosa = i_angle_x.cos_val;
+ final double sinb = i_angle_y.sin_val;
+ final double cosb = i_angle_y.cos_val;
+ double L, J, K, M, N, O;
+ L = J = K = M = N = O = 0;
+ for (int i = 0; i < i_number_of_vertex; i++) {
+ double ix, iy, iz;
+ ix = i_vertex3d[i].x;
+ iy = i_vertex3d[i].y;
+ iz = i_vertex3d[i].z;
+
+ final double cp00 = cp.m00;
+ final double cp01 = cp.m01;
+ final double cp02 = cp.m02;
+ final double cp11 = cp.m11;
+ final double cp12 = cp.m12;
+
+ double X0 = (cp00 * (-sina * sinb * ix - cosa * iy + sina * cosb * iz) + cp01 * (ix * cosb + sinb * iz));
+ double X1 = (cp01 * (sina * ix * sinb + cosa * iy - sina * iz * cosb) + cp00 * (cosb * ix + sinb * iz));
+ double X2 = cp00 * i_trans.x + cp01 * (i_trans.y) + cp02 * (-cosa * sinb) * ix + cp02 * (sina) * iy + cp02 * ((cosb * cosa) * iz + i_trans.z);
+ double Y0 = cp11 * (ix * cosb + sinb * iz);
+ double Y1 = cp11 * (sina * ix * sinb + cosa * iy - sina * iz * cosb);
+ double Y2 = (cp11 * i_trans.y + cp12 * (-cosa * sinb) * ix + cp12 * ((sina) * iy + (cosb * cosa) * iz + i_trans.z));
+ double H0 = 0;
+ double H1 = 0;
+ double H2 = ((-cosa * sinb) * ix + (sina) * iy + (cosb * cosa) * iz + i_trans.z);
+
+ double VX = i_vertex2d[i].x;
+ double VY = i_vertex2d[i].y;
+
+ double a, b, c, d, e, f;
+ a = (VX * H0 - X0);
+ b = (VX * H1 - X1);
+ c = (VX * H2 - X2);
+ d = (VY * H0 - Y0);
+ e = (VY * H1 - Y1);
+ f = (VY * H2 - Y2);
+
+ L += d * e + a * b;
+ N += d * d + a * a;
+ J += d * f + a * c;
+ M += e * e + b * b;
+ K += e * f + b * c;
+ O += f * f + c * c;
+
+ }
+ L *=2;
+ J *=2;
+ K *=2;
+
+ return getMinimumErrorAngleFromParam(L,J, K, M, N, O, i_hint_angle);
+ }
+ private TSinCosValue[] __angles_in=TSinCosValue.createArray(3);
+ private NyARDoublePoint3d __ang=new NyARDoublePoint3d();
+ public void modifyMatrix(NyARDoubleMatrix33 io_rot, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d, int i_number_of_vertex) throws NyARException
+ {
+ TSinCosValue[] angles_in = this.__angles_in;// x,y,z
+ NyARDoublePoint3d ang = this.__ang;
+
+ // ZXY系のsin/cos値を抽出
+ rotation2Sincos_ZXY(io_rot, angles_in,ang);
+ ang.x += optimizeParamX(angles_in[1], angles_in[2], i_trans, i_vertex3d, i_vertex2d, i_number_of_vertex, ang.x);
+ ang.y += optimizeParamY(angles_in[0], angles_in[2], i_trans, i_vertex3d, i_vertex2d, i_number_of_vertex, ang.y);
+ ang.z += optimizeParamZ(angles_in[0], angles_in[1], i_trans, i_vertex3d, i_vertex2d, i_number_of_vertex, ang.z);
+ io_rot.setZXYAngle(ang.x, ang.y, ang.z);
+ return;
+ }
+ private double[] __sin_table= new double[4];
+ /**
+ * エラーレートが最小になる点を得る。
+ */
+ private double getMinimumErrorAngleFromParam(double iL,double iJ, double iK, double iM, double iN, double iO, double i_hint_angle) throws NyARException
+ {
+ double[] sin_table = this.__sin_table;
+
+ double M = (iN - iM)/iL;
+ double J = iJ/iL;
+ double K = -iK/iL;
+
+ // パラメータからsinテーブルを作成
+ // (- 4*M^2-4)*x^4 + (4*K- 4*J*M)*x^3 + (4*M^2 -(K^2- 4)- J^2)*x^2 +(4*J*M- 2*K)*x + J^2-1 = 0
+ int number_of_sin = NyAREquationSolver.solve4Equation(-4 * M * M - 4, 4 * K - 4 * J * M, 4 * M * M - (K * K - 4) - J * J, 4 * J * M - 2 * K, J * J - 1, sin_table);
+
+
+ // 最小値2個を得ておく。
+ double min_ang_0 = Double.MAX_VALUE;
+ double min_ang_1 = Double.MAX_VALUE;
+ double min_err_0 = Double.MAX_VALUE;
+ double min_err_1 = Double.MAX_VALUE;
+ for (int i = 0; i < number_of_sin; i++) {
+ // +-cos_v[i]が頂点候補
+ double sin_rt = sin_table[i];
+ double cos_rt = Math.sqrt(1 - (sin_rt * sin_rt));
+ // cosを修復。微分式で0に近い方が正解
+ // 0 = 2*cos(x)*sin(x)*M - sin(x)^2 + cos(x)^2 + sin(x)*K + cos(x)*J
+ double a1 = 2 * cos_rt * sin_rt * M + sin_rt * (K - sin_rt) + cos_rt * (cos_rt + J);
+ double a2 = 2 * (-cos_rt) * sin_rt * M + sin_rt * (K - sin_rt) + (-cos_rt) * ((-cos_rt) + J);
+ // 絶対値になおして、真のcos値を得ておく。
+ a1 = a1 < 0 ? -a1 : a1;
+ a2 = a2 < 0 ? -a2 : a2;
+ cos_rt = (a1 < a2) ? cos_rt : -cos_rt;
+ double ang = Math.atan2(sin_rt, cos_rt);
+ // エラー値を計算
+ double err = iN * sin_rt * sin_rt + (iL*cos_rt + iJ) * sin_rt + iM * cos_rt * cos_rt + iK * cos_rt + iO;
+ // 最小の2個を獲得する。
+ if (min_err_0 > err) {
+ min_err_1 = min_err_0;
+ min_ang_1 = min_ang_0;
+ min_err_0 = err;
+ min_ang_0 = ang;
+ } else if (min_err_1 > err) {
+ min_err_1 = err;
+ min_ang_1 = ang;
+ }
+ }
+ // [0]をテスト
+ double gap_0;
+ gap_0 = min_ang_0 - i_hint_angle;
+ if (gap_0 > Math.PI) {
+ gap_0 = (min_ang_0 - Math.PI * 2) - i_hint_angle;
+ } else if (gap_0 < -Math.PI) {
+ gap_0 = (min_ang_0 + Math.PI * 2) - i_hint_angle;
+ }
+ // [1]をテスト
+ double gap_1;
+ gap_1 = min_ang_1 - i_hint_angle;
+ if (gap_1 > Math.PI) {
+ gap_1 = (min_ang_1 - Math.PI * 2) - i_hint_angle;
+ } else if (gap_1 < -Math.PI) {
+ gap_1 = (min_ang_1 + Math.PI * 2) - i_hint_angle;
+ }
+ return Math.abs(gap_1) < Math.abs(gap_0) ? gap_1 : gap_0;
+ }
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize.java (revision 302)
@@ -0,0 +1,286 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit;
+
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.param.*;
+import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;
+import jp.nyatla.nyartoolkit.core.transmat.solver.INyARTransportVectorSolver;
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;
+/**
+ * 基本姿勢と実画像を一致するように、角度を微調整→平行移動量を再計算
+ * を繰り返して、変換行列を最適化する。
+ *
+ */
+public class NyARRotMatrixOptimize implements INyARRotMatrixOptimize
+{
+ private final static int AR_GET_TRANS_MAT_MAX_LOOP_COUNT = 5;// #define AR_GET_TRANS_MAT_MAX_LOOP_COUNT 5
+ private final static double AR_GET_TRANS_MAT_MAX_FIT_ERROR = 1.0;// #define AR_GET_TRANS_MAT_MAX_FIT_ERROR 1.0
+ private final NyARPerspectiveProjectionMatrix _projection_mat_ref;
+ public NyARRotMatrixOptimize(NyARPerspectiveProjectionMatrix i_projection_mat_ref)
+ {
+ this._projection_mat_ref=i_projection_mat_ref;
+ return;
+ }
+ final public double optimize(NyARRotMatrix_ARToolKit io_rotmat,NyARDoublePoint3d io_transvec,INyARTransportVectorSolver i_solver,NyARDoublePoint3d[] i_offset_3d,NyARDoublePoint2d[] i_2d_vertex) throws NyARException
+ {
+ double err = -1;
+ /*ループを抜けるタイミングをARToolKitと合わせるために変なことしてます。*/
+ for (int i = 0;; i++) {
+ // <arGetTransMat3>
+ err = modifyMatrix(io_rotmat,io_transvec,i_offset_3d,i_2d_vertex);
+ i_solver.solveTransportVector(i_offset_3d, io_transvec);
+ err = modifyMatrix(io_rotmat,io_transvec,i_offset_3d,i_2d_vertex);
+ // //</arGetTransMat3>
+ if (err < AR_GET_TRANS_MAT_MAX_FIT_ERROR || i == AR_GET_TRANS_MAT_MAX_LOOP_COUNT-1) {
+ break;
+ }
+ i_solver.solveTransportVector(i_offset_3d, io_transvec);
+ }
+ return err;
+ }
+
+ private final double[][] __modifyMatrix_double1D = new double[8][3];
+ /**
+ * arGetRot計算を階層化したModifyMatrix 896
+ *
+ * @param nyrot
+ * @param trans
+ * @param i_vertex3d
+ * [m][3]
+ * @param i_vertex2d
+ * [n][2]
+ * @return
+ * @throws NyARException
+ */
+ public double modifyMatrix(NyARRotMatrix_ARToolKit io_rot,NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException
+ {
+ double factor;
+ double a2, b2, c2;
+ double ma = 0.0, mb = 0.0, mc = 0.0;
+ double h, x, y;
+ double err, minerr = 0;
+ int t1, t2, t3;
+ int s1 = 0, s2 = 0, s3 = 0;
+
+ factor = 10.0 * Math.PI / 180.0;
+ double rot0, rot1, rot3, rot4, rot6, rot7;
+ double combo00, combo01, combo02, combo03, combo10, combo11, combo12, combo13, combo20, combo21, combo22, combo23;
+ double combo02_2, combo02_5, combo02_8, combo02_11;
+ double combo22_2, combo22_5, combo22_8, combo22_11;
+ double combo12_2, combo12_5, combo12_8, combo12_11;
+ // vertex展開
+ final double VX00, VX01, VX02, VX10, VX11, VX12, VX20, VX21, VX22, VX30, VX31, VX32;
+ NyARDoublePoint3d d_pt;
+ d_pt = i_vertex3d[0];
+ VX00 = d_pt.x;
+ VX01 = d_pt.y;
+ VX02 = d_pt.z;
+ d_pt = i_vertex3d[1];
+ VX10 = d_pt.x;
+ VX11 = d_pt.y;
+ VX12 = d_pt.z;
+ d_pt = i_vertex3d[2];
+ VX20 = d_pt.x;
+ VX21 = d_pt.y;
+ VX22 = d_pt.z;
+ d_pt = i_vertex3d[3];
+ VX30 = d_pt.x;
+ VX31 = d_pt.y;
+ VX32 = d_pt.z;
+ final double P2D00, P2D01, P2D10, P2D11, P2D20, P2D21, P2D30, P2D31;
+ NyARDoublePoint2d d_pt2;
+ d_pt2 = i_vertex2d[0];
+ P2D00 = d_pt2.x;
+ P2D01 = d_pt2.y;
+ d_pt2 = i_vertex2d[1];
+ P2D10 = d_pt2.x;
+ P2D11 = d_pt2.y;
+ d_pt2 = i_vertex2d[2];
+ P2D20 = d_pt2.x;
+ P2D21 = d_pt2.y;
+ d_pt2 = i_vertex2d[3];
+ P2D30 = d_pt2.x;
+ P2D31 = d_pt2.y;
+ final NyARPerspectiveProjectionMatrix prjmat = this._projection_mat_ref;
+ final double CP0, CP1, CP2, CP4, CP5, CP6, CP8, CP9, CP10;
+ CP0 = prjmat.m00;
+ CP1 = prjmat.m01;
+ CP2 = prjmat.m02;
+ CP4 = prjmat.m10;
+ CP5 = prjmat.m11;
+ CP6 = prjmat.m12;
+ CP8 = prjmat.m20;
+ CP9 = prjmat.m21;
+ CP10 = prjmat.m22;
+ combo03 = CP0 * trans.x + CP1 * trans.y + CP2 * trans.z + prjmat.m03;
+ combo13 = CP4 * trans.x + CP5 * trans.y + CP6 * trans.z + prjmat.m13;
+ combo23 = CP8 * trans.x + CP9 * trans.y + CP10 * trans.z + prjmat.m23;
+ double CACA, SASA, SACA, CA, SA;
+ double CACACB, SACACB, SASACB, CASB, SASB;
+ double SACASC, SACACBSC, SACACBCC, SACACC;
+ final double[][] double1D = this.__modifyMatrix_double1D;
+
+
+ final double[] a_factor = double1D[1];
+ final double[] sinb = double1D[2];
+ final double[] cosb = double1D[3];
+ final double[] b_factor = double1D[4];
+ final double[] sinc = double1D[5];
+ final double[] cosc = double1D[6];
+ final double[] c_factor = double1D[7];
+ double w, w2;
+ double wsin, wcos;
+
+ //現在の角度を確保
+ final NyARDoublePoint3d angle = io_rot.refAngle();
+ a2 = angle.x;
+ b2 = angle.y;
+ c2 = angle.z;
+
+ // comboの3行目を先に計算
+ for (int i = 0; i < 10; i++) {
+ minerr = 1000000000.0;
+ // sin-cosテーブルを計算(これが外に出せるとは…。)
+ for (int j = 0; j < 3; j++) {
+ w2 = factor * (j - 1);
+ w = a2 + w2;
+ a_factor[j] = w;
+ w = b2 + w2;
+ b_factor[j] = w;
+ sinb[j] = Math.sin(w);
+ cosb[j] = Math.cos(w);
+ w = c2 + w2;
+ c_factor[j] = w;
+ sinc[j] = Math.sin(w);
+ cosc[j] = Math.cos(w);
+ }
+ //
+ for (t1 = 0; t1 < 3; t1++) {
+ SA = Math.sin(a_factor[t1]);
+ CA = Math.cos(a_factor[t1]);
+ // Optimize
+ CACA = CA * CA;
+ SASA = SA * SA;
+ SACA = SA * CA;
+ for (t2 = 0; t2 < 3; t2++) {
+ wsin = sinb[t2];
+ wcos = cosb[t2];
+ CACACB = CACA * wcos;
+ SACACB = SACA * wcos;
+ SASACB = SASA * wcos;
+ CASB = CA * wsin;
+ SASB = SA * wsin;
+ // comboの計算1
+ combo02 = CP0 * CASB + CP1 * SASB + CP2 * wcos;
+ combo12 = CP4 * CASB + CP5 * SASB + CP6 * wcos;
+ combo22 = CP8 * CASB + CP9 * SASB + CP10 * wcos;
+
+ combo02_2 = combo02 * VX02 + combo03;
+ combo02_5 = combo02 * VX12 + combo03;
+ combo02_8 = combo02 * VX22 + combo03;
+ combo02_11 = combo02 * VX32 + combo03;
+ combo12_2 = combo12 * VX02 + combo13;
+ combo12_5 = combo12 * VX12 + combo13;
+ combo12_8 = combo12 * VX22 + combo13;
+ combo12_11 = combo12 * VX32 + combo13;
+ combo22_2 = combo22 * VX02 + combo23;
+ combo22_5 = combo22 * VX12 + combo23;
+ combo22_8 = combo22 * VX22 + combo23;
+ combo22_11 = combo22 * VX32 + combo23;
+ for (t3 = 0; t3 < 3; t3++) {
+ wsin = sinc[t3];
+ wcos = cosc[t3];
+ SACASC = SACA * wsin;
+ SACACC = SACA * wcos;
+ SACACBSC = SACACB * wsin;
+ SACACBCC = SACACB * wcos;
+
+ rot0 = CACACB * wcos + SASA * wcos + SACACBSC - SACASC;
+ rot3 = SACACBCC - SACACC + SASACB * wsin + CACA * wsin;
+ rot6 = -CASB * wcos - SASB * wsin;
+
+ combo00 = CP0 * rot0 + CP1 * rot3 + CP2 * rot6;
+ combo10 = CP4 * rot0 + CP5 * rot3 + CP6 * rot6;
+ combo20 = CP8 * rot0 + CP9 * rot3 + CP10 * rot6;
+
+ rot1 = -CACACB * wsin - SASA * wsin + SACACBCC - SACACC;
+ rot4 = -SACACBSC + SACASC + SASACB * wcos + CACA * wcos;
+ rot7 = CASB * wsin - SASB * wcos;
+ combo01 = CP0 * rot1 + CP1 * rot4 + CP2 * rot7;
+ combo11 = CP4 * rot1 + CP5 * rot4 + CP6 * rot7;
+ combo21 = CP8 * rot1 + CP9 * rot4 + CP10 * rot7;
+ //
+ err = 0.0;
+ h = combo20 * VX00 + combo21 * VX01 + combo22_2;
+ x = P2D00 - (combo00 * VX00 + combo01 * VX01 + combo02_2) / h;
+ y = P2D01 - (combo10 * VX00 + combo11 * VX01 + combo12_2) / h;
+ err += x * x + y * y;
+ h = combo20 * VX10 + combo21 * VX11 + combo22_5;
+ x = P2D10 - (combo00 * VX10 + combo01 * VX11 + combo02_5) / h;
+ y = P2D11 - (combo10 * VX10 + combo11 * VX11 + combo12_5) / h;
+ err += x * x + y * y;
+ h = combo20 * VX20 + combo21 * VX21 + combo22_8;
+ x = P2D20 - (combo00 * VX20 + combo01 * VX21 + combo02_8) / h;
+ y = P2D21 - (combo10 * VX20 + combo11 * VX21 + combo12_8) / h;
+ err += x * x + y * y;
+ h = combo20 * VX30 + combo21 * VX31 + combo22_11;
+ x = P2D30 - (combo00 * VX30 + combo01 * VX31 + combo02_11) / h;
+ y = P2D31 - (combo10 * VX30 + combo11 * VX31 + combo12_11) / h;
+ err += x * x + y * y;
+ if (err < minerr) {
+ minerr = err;
+ ma = a_factor[t1];
+ mb = b_factor[t2];
+ mc = c_factor[t3];
+ s1 = t1 - 1;
+ s2 = t2 - 1;
+ s3 = t3 - 1;
+ }
+ }
+ }
+ }
+ if (s1 == 0 && s2 == 0 && s3 == 0) {
+ factor *= 0.5;
+ }
+ a2 = ma;
+ b2 = mb;
+ c2 = mc;
+ }
+ io_rot.setAngle(ma, mb, mc);
+ /* printf("factor = %10.5f\n", factor*180.0/MD_PI); */
+ return minerr / 4;
+ }
+
+
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize_O2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize_O2.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize_O2.java (revision 302)
@@ -0,0 +1,236 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit;
+
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.param.*;
+import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;
+/**
+ * 基本姿勢と実画像を一致するように、角度を微調整→平行移動量を再計算
+ * を繰り返して、変換行列を最適化する。
+ *
+ */
+public class NyARRotMatrixOptimize_O2 implements INyARRotMatrixOptimize
+{
+ private final NyARPerspectiveProjectionMatrix _projection_mat_ref;
+ public NyARRotMatrixOptimize_O2(NyARPerspectiveProjectionMatrix i_projection_mat_ref)
+ {
+ this._projection_mat_ref=i_projection_mat_ref;
+ return;
+ }
+ private final double[][] __modifyMatrix_double1D = new double[8][3];
+ /**
+ * arGetRot計算を階層化したModifyMatrix 896
+ *
+ * @param trans
+ * @param i_vertex3d
+ * [m][3]
+ * @param i_vertex2d
+ * [n][2]
+ * @return
+ * @throws NyARException
+ */
+ public double modifyMatrix(NyARRotMatrix_ARToolKit io_rot,NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException
+ {
+ double factor;
+ double a2, b2, c2;
+ double h, x, y;
+ double err, minerr = 0;
+ int t1, t2, t3;
+ int best_idx=0;
+
+ factor = 10.0 * Math.PI / 180.0;
+ double rot0, rot1, rot2;
+ double combo00, combo01, combo02, combo03, combo10, combo11, combo12, combo13, combo20, combo21, combo22, combo23;
+ double combo02_2, combo02_5, combo02_8, combo02_11;
+ double combo22_2, combo22_5, combo22_8, combo22_11;
+ double combo12_2, combo12_5, combo12_8, combo12_11;
+ // vertex展開
+ final double VX00, VX01, VX02, VX10, VX11, VX12, VX20, VX21, VX22, VX30, VX31, VX32;
+ VX00 = i_vertex3d[0].x;
+ VX01 = i_vertex3d[0].y;
+ VX02 = i_vertex3d[0].z;
+ VX10 = i_vertex3d[1].x;
+ VX11 = i_vertex3d[1].y;
+ VX12 = i_vertex3d[1].z;
+ VX20 = i_vertex3d[2].x;
+ VX21 = i_vertex3d[2].y;
+ VX22 = i_vertex3d[2].z;
+ VX30 = i_vertex3d[3].x;
+ VX31 = i_vertex3d[3].y;
+ VX32 = i_vertex3d[3].z;
+ final double P2D00, P2D01, P2D10, P2D11, P2D20, P2D21, P2D30, P2D31;
+ P2D00 = i_vertex2d[0].x;
+ P2D01 = i_vertex2d[0].y;
+ P2D10 = i_vertex2d[1].x;
+ P2D11 = i_vertex2d[1].y;
+ P2D20 = i_vertex2d[2].x;
+ P2D21 = i_vertex2d[2].y;
+ P2D30 = i_vertex2d[3].x;
+ P2D31 = i_vertex2d[3].y;
+ final NyARPerspectiveProjectionMatrix prjmat = this._projection_mat_ref;
+ final double CP0 = prjmat.m00,CP1 = prjmat.m01,CP2 = prjmat.m02,CP4 = prjmat.m10,CP5 = prjmat.m11,CP6 = prjmat.m12,CP8 = prjmat.m20,CP9 = prjmat.m21,CP10 = prjmat.m22;
+ combo03 = CP0 * trans.x + CP1 * trans.y + CP2 * trans.z + prjmat.m03;
+ combo13 = CP4 * trans.x + CP5 * trans.y + CP6 * trans.z + prjmat.m13;
+ combo23 = CP8 * trans.x + CP9 * trans.y + CP10 * trans.z + prjmat.m23;
+ double CACA, SASA, SACA, CA, SA;
+ double CACACB, SACACB, SASACB, CASB, SASB;
+ double SACASC, SACACBSC, SACACBCC, SACACC;
+ final double[][] double1D = this.__modifyMatrix_double1D;
+
+ final double[] a_factor = double1D[1];
+ final double[] sinb = double1D[2];
+ final double[] cosb = double1D[3];
+ final double[] b_factor = double1D[4];
+ final double[] sinc = double1D[5];
+ final double[] cosc = double1D[6];
+ final double[] c_factor = double1D[7];
+ double w, w2;
+ double wsin, wcos;
+
+ final NyARDoublePoint3d angle = io_rot.refAngle();
+ a2 = angle.x;
+ b2 = angle.y;
+ c2 = angle.z;
+
+ // comboの3行目を先に計算
+ for (int i = 0; i < 10; i++) {
+ minerr = 1000000000.0;
+ // sin-cosテーブルを計算(これが外に出せるとは…。)
+ for (int j = 0; j < 3; j++) {
+ w2 = factor * (j - 1);
+ w = a2 + w2;
+ a_factor[j] = w;
+ w = b2 + w2;
+ b_factor[j] = w;
+ sinb[j] = Math.sin(w);
+ cosb[j] = Math.cos(w);
+ w = c2 + w2;
+ c_factor[j] = w;
+ sinc[j] = Math.sin(w);
+ cosc[j] = Math.cos(w);
+ }
+ //
+ for (t1 = 0; t1 < 3; t1++) {
+ SA = Math.sin(a_factor[t1]);
+ CA = Math.cos(a_factor[t1]);
+ // Optimize
+ CACA = CA * CA;
+ SASA = SA * SA;
+ SACA = SA * CA;
+ for (t2 = 0; t2 < 3; t2++) {
+ wsin = sinb[t2];
+ wcos = cosb[t2];
+ CACACB = CACA * wcos;
+ SACACB = SACA * wcos;
+ SASACB = SASA * wcos;
+ CASB = CA * wsin;
+ SASB = SA * wsin;
+ // comboの計算1
+ combo02 = CP0 * CASB + CP1 * SASB + CP2 * wcos;
+ combo12 = CP4 * CASB + CP5 * SASB + CP6 * wcos;
+ combo22 = CP8 * CASB + CP9 * SASB + CP10 * wcos;
+
+ combo02_2 = combo02 * VX02 + combo03;
+ combo02_5 = combo02 * VX12 + combo03;
+ combo02_8 = combo02 * VX22 + combo03;
+ combo02_11 = combo02 * VX32 + combo03;
+ combo12_2 = combo12 * VX02 + combo13;
+ combo12_5 = combo12 * VX12 + combo13;
+ combo12_8 = combo12 * VX22 + combo13;
+ combo12_11 = combo12 * VX32 + combo13;
+ combo22_2 = combo22 * VX02 + combo23;
+ combo22_5 = combo22 * VX12 + combo23;
+ combo22_8 = combo22 * VX22 + combo23;
+ combo22_11 = combo22 * VX32 + combo23;
+ for (t3 = 0; t3 < 3; t3++) {
+ wsin = sinc[t3];
+ wcos = cosc[t3];
+ SACASC = SACA * wsin;
+ SACACC = SACA * wcos;
+ SACACBSC = SACACB * wsin;
+ SACACBCC = SACACB * wcos;
+
+ rot0 = CACACB * wcos + SASA * wcos + SACACBSC - SACASC;
+ rot1 = SACACBCC - SACACC + SASACB * wsin + CACA * wsin;
+ rot2 = -CASB * wcos - SASB * wsin;
+ combo00 = CP0 * rot0 + CP1 * rot1 + CP2 * rot2;
+ combo10 = CP4 * rot0 + CP5 * rot1 + CP6 * rot2;
+ combo20 = CP8 * rot0 + CP9 * rot1 + CP10 * rot2;
+
+ rot0 = -CACACB * wsin - SASA * wsin + SACACBCC - SACACC;
+ rot1 = -SACACBSC + SACASC + SASACB * wcos + CACA * wcos;
+ rot2 = CASB * wsin - SASB * wcos;
+ combo01 = CP0 * rot0 + CP1 * rot1 + CP2 * rot2;
+ combo11 = CP4 * rot0 + CP5 * rot1 + CP6 * rot2;
+ combo21 = CP8 * rot0 + CP9 * rot1 + CP10 * rot2;
+ //
+ err = 0.0;
+ h = combo20 * VX00 + combo21 * VX01 + combo22_2;
+ x = P2D00 - (combo00 * VX00 + combo01 * VX01 + combo02_2) / h;
+ y = P2D01 - (combo10 * VX00 + combo11 * VX01 + combo12_2) / h;
+ err += x * x + y * y;
+ h = combo20 * VX10 + combo21 * VX11 + combo22_5;
+ x = P2D10 - (combo00 * VX10 + combo01 * VX11 + combo02_5) / h;
+ y = P2D11 - (combo10 * VX10 + combo11 * VX11 + combo12_5) / h;
+ err += x * x + y * y;
+ h = combo20 * VX20 + combo21 * VX21 + combo22_8;
+ x = P2D20 - (combo00 * VX20 + combo01 * VX21 + combo02_8) / h;
+ y = P2D21 - (combo10 * VX20 + combo11 * VX21 + combo12_8) / h;
+ err += x * x + y * y;
+ h = combo20 * VX30 + combo21 * VX31 + combo22_11;
+ x = P2D30 - (combo00 * VX30 + combo01 * VX31 + combo02_11) / h;
+ y = P2D31 - (combo10 * VX30 + combo11 * VX31 + combo12_11) / h;
+ err += x * x + y * y;
+ if (err < minerr) {
+ minerr = err;
+ a2 = a_factor[t1];
+ b2 = b_factor[t2];
+ c2 = c_factor[t3];
+ best_idx=t1+t2*3+t3*9;
+ }
+ }
+ }
+ }
+ if (best_idx==(1+3+9)) {
+ factor *= 0.5;
+ }
+ }
+ io_rot.setAngle(a2, b2, c2);
+ /* printf("factor = %10.5f\n", factor*180.0/MD_PI); */
+ return minerr /4;
+ }
+
+
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/INyARRotMatrixOptimize.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/INyARRotMatrixOptimize.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/INyARRotMatrixOptimize.java (revision 302)
@@ -0,0 +1,55 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;
+import jp.nyatla.nyartoolkit.core.types.*;
+
+public interface INyARRotMatrixOptimize
+{
+ /**
+ * @param io_rot
+ * 初期回転行列
+ * @param i_trans
+ * 初期並進ベクトル
+ * @param i_vertex3d
+ * 初期3次元座標
+ * @param i_vertex2d
+ * 画面上の頂点群
+ * @return
+ * エラーレート
+ * @throws NyARException
+ */
+// public double optimize(NyARRotMatrix io_rotmat,NyARDoublePoint3d io_transvec,INyARTransportVectorSolver i_solver,NyARDoublePoint3d[] i_offset_3d,NyARDoublePoint2d[] i_2d_vertex) throws NyARException;
+ public double modifyMatrix(NyARRotMatrix_ARToolKit io_rot, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException;
+
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize_Base.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize_Base.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize_Base.java (revision 302)
@@ -0,0 +1,194 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.param.*;
+import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;
+import jp.nyatla.nyartoolkit.core.types.matrix.*;
+import jp.nyatla.nyartoolkit.core.types.*;
+
+/**
+ * 処理構造がわかる程度に展開したNyARRotTransOptimize
+ *
+ */
+public class NyARRotMatrixOptimize_Base implements INyARRotMatrixOptimize
+{
+ private final NyARPerspectiveProjectionMatrix _projection_mat_ref;
+
+ public NyARRotMatrixOptimize_Base(NyARPerspectiveProjectionMatrix i_projection_mat_ref)
+ {
+ this._projection_mat_ref = i_projection_mat_ref;
+ return;
+ }
+ private double[] __createRotationMap_b_map=new double[6];
+ private double[] __createRotationMap_c_map=new double[6];
+ private double[] __createRotationMap_f=new double[3];
+ private void createRotationMap(NyARDoublePoint3d i_angle,double i_factor,NyARDoubleMatrix33[] i_rot_matrix)
+ {
+ double sina,cosa,sinb,cosb,sinc,cosc;
+ double CACA,SASA,SACA,SASB,CASB,SACACB,CACACB,SASACB;
+
+
+ final double[] f=this.__createRotationMap_f;
+ final double[] b_map=this.__createRotationMap_b_map;
+ final double[] c_map=this.__createRotationMap_c_map;
+ f[0]=-i_factor;
+ f[1]=0;
+ f[2]=i_factor;
+ double ang1,ang2;
+ //BとCのsinマップを先に作成
+ for(int i=0;i<3;i++)
+ {
+ ang1=i_angle.y + f[i];
+ b_map[i] =Math.sin(ang1);
+ b_map[i+3]=Math.cos(ang1);
+ ang2=i_angle.z + f[i];
+ c_map[i] =Math.sin(ang2);
+ c_map[i+3]=Math.cos(ang2);
+ }
+ int idx=0;
+ int t1,t2,t3;
+ for (t1 = 0; t1 < 3; t1++){
+ ang1=i_angle.x + f[t1];
+ sina = Math.sin(ang1);
+ cosa = Math.cos(ang1);
+ CACA = cosa * cosa;
+ SASA = sina * sina;
+ SACA = sina * cosa;
+
+ for (t2=0;t2<3;t2++){
+ sinb = b_map[t2];
+ cosb = b_map[t2+3];
+ SASB = sina * sinb;
+ CASB = cosa * sinb;
+ SACACB = SACA * cosb;
+ CACACB = CACA * cosb;
+ SASACB = SASA * cosb;
+ for (t3=0;t3<3;t3++) {
+ sinc = c_map[t3];
+ cosc = c_map[t3+3];
+ final NyARDoubleMatrix33 mat_ptr=i_rot_matrix[idx];
+ mat_ptr.m00 = CACACB * cosc + SASA * cosc + SACACB * sinc - SACA * sinc;
+ mat_ptr.m01 = -CACACB * sinc - SASA * sinc + SACACB * cosc - SACA * cosc;
+ mat_ptr.m02 = CASB;
+ mat_ptr.m10 = SACACB * cosc - SACA * cosc + SASACB * sinc + CACA * sinc;
+ mat_ptr.m11 = -SACACB * sinc + SACA * sinc + SASACB * cosc + CACA * cosc;
+ mat_ptr.m12 = SASB;
+ mat_ptr.m20 = -CASB * cosc - SASB * sinc;
+ mat_ptr.m21 = CASB * sinc - SASB * cosc;
+ mat_ptr.m22 = cosb;
+ idx++;
+ }
+ }
+ }
+ return;
+ }
+ private final void getNewMatrix(NyARDoubleMatrix33 i_rot, NyARDoublePoint3d i_trans, NyARDoubleMatrix34 o_combo)
+ {
+ double cp0,cp1,cp2,cp3;
+ NyARPerspectiveProjectionMatrix cp=this._projection_mat_ref;
+
+ cp3=cp.m03;
+ cp0=cp.m00;cp1=cp.m01;cp2=cp.m02;
+ o_combo.m00=cp0 * i_rot.m00 + cp1 * i_rot.m10 + cp2 * i_rot.m20;
+ o_combo.m01=cp0 * i_rot.m01 + cp1 * i_rot.m11 + cp2 * i_rot.m21;
+ o_combo.m02=cp0 * i_rot.m02 + cp1 * i_rot.m12 + cp2 * i_rot.m22;
+ o_combo.m03=cp0 * i_trans.x + cp1 * i_trans.y + cp2 * i_trans.z +cp3;
+
+ cp0=cp.m10;cp1=cp.m11;cp2=cp.m12;
+ o_combo.m10=cp0 * i_rot.m00 + cp1 * i_rot.m10 + cp2 * i_rot.m20;
+ o_combo.m11=cp0 * i_rot.m01 + cp1 * i_rot.m11 + cp2 * i_rot.m21;
+ o_combo.m12=cp0 * i_rot.m02 + cp1 * i_rot.m12 + cp2 * i_rot.m22;
+ o_combo.m13=cp0 * i_trans.x + cp1 * i_trans.y + cp2 * i_trans.z +cp3;
+
+ cp0=cp.m20;cp1=cp.m21;cp2=cp.m22;
+ o_combo.m20=cp0 * i_rot.m00 + cp1 * i_rot.m10 + cp2 * i_rot.m20;
+ o_combo.m21=cp0 * i_rot.m01 + cp1 * i_rot.m11 + cp2 * i_rot.m21;
+ o_combo.m22=cp0 * i_rot.m02 + cp1 * i_rot.m12 + cp2 * i_rot.m22;
+ o_combo.m23=cp0 * i_trans.x + cp1 * i_trans.y + cp2 * i_trans.z +cp3;
+ return;
+ }
+ private final NyARDoublePoint3d __modifyMatrix_angle = new NyARDoublePoint3d();
+ private final NyARDoubleMatrix34 __modifyMatrix_combo=new NyARDoubleMatrix34();
+ private final NyARDoubleMatrix33[] __modifyMatrix_next_rot_matrix=NyARDoubleMatrix33.createArray(27);
+ public double modifyMatrix(NyARRotMatrix_ARToolKit io_rot, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException
+ {
+ final NyARDoublePoint3d angle = this.__modifyMatrix_angle;
+ final NyARDoubleMatrix34 combo=this.__modifyMatrix_combo;
+ final NyARDoubleMatrix33[] next_rot_matrix=this.__modifyMatrix_next_rot_matrix;
+ double factor;
+ double hx, hy, h, x, y;
+ double err, minerr = 0;
+ int i,i2;
+ int best_idx=0;
+ angle.setValue(io_rot.refAngle());// arGetAngle( rot, &a, &b, &c );
+ factor = 10.0 * Math.PI / 180.0;
+ for (int j = 0; j < 10; j++){
+ minerr = 1000000000.0;
+ //評価用の角度マップ作成
+ createRotationMap(angle,factor,next_rot_matrix);
+ //評価して一番宜しいIDを保存
+ best_idx=(1+1*3+1*9);
+ for(i2=0;i2<27;i2++){
+ this.getNewMatrix(next_rot_matrix[i2],i_trans,combo);
+ err = 0.0;
+ for (i = 0; i < 4; i++) {
+ hx = combo.m00 * i_vertex3d[i].x + combo.m01 * i_vertex3d[i].y + combo.m02 * i_vertex3d[i].z + combo.m03;
+ hy = combo.m10 * i_vertex3d[i].x + combo.m11 *i_vertex3d[i].y + combo.m12 * i_vertex3d[i].z + combo.m13;
+ h = combo.m20 * i_vertex3d[i].x + combo.m21 * i_vertex3d[i].y + combo.m22 * i_vertex3d[i].z + combo.m23;
+ x = i_vertex2d[i].x-(hx / h);
+ y = i_vertex2d[i].y-(hy / h);
+ err += x*x+y*y;
+ }
+ if (err < minerr){
+ minerr = err;
+ best_idx=i2;
+ }
+
+ }
+ if (best_idx==(1+1*3+1*9)){
+ factor *= 0.5;
+ }else{
+ angle.z+=factor*(best_idx%3-1);
+ angle.y+=factor*((best_idx/3)%3-1);
+ angle.x+=factor*((best_idx/9)%3-1);
+ }
+ }
+ io_rot.setAngle(angle.x,angle.y,angle.z);
+ /* printf("factor = %10.5f\n", factor*180.0/MD_PI); */
+ return minerr / 4;
+ }
+
+
+
+
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMatResult.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMatResult.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMatResult.java (revision 302)
@@ -7,33 +7,32 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.transmat;


+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;
import jp.nyatla.nyartoolkit.core.types.matrix.*;
-import jp.nyatla.nyartoolkit.core.types.*;

/**
* NyARTransMat戻り値専用のNyARMat
@@ -42,5 +41,25 @@
public class NyARTransMatResult extends NyARDoubleMatrix34
{
public boolean has_value = false;
- public NyARDoublePoint3d angle=new NyARDoublePoint3d();
+ /**
+ * この関数は、0-PIの間で値を返します。
+ * @param o_out
+ */
+ public final void getZXYAngle(NyARDoublePoint3d o_out)
+ {
+ double sina = this.m21;
+ if (sina >= 1.0) {
+ o_out.x = Math.PI / 2;
+ o_out.y = 0;
+ o_out.z = Math.atan2(-this.m10, this.m00);
+ } else if (sina <= -1.0) {
+ o_out.x = -Math.PI / 2;
+ o_out.y = 0;
+ o_out.z = Math.atan2(-this.m10, this.m00);
+ } else {
+ o_out.x = Math.asin(sina);
+ o_out.z = Math.atan2(-this.m01, this.m11);
+ o_out.y = Math.atan2(-this.m20, this.m22);
+ }
+ }
}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat.java (revision 302)
@@ -1,240 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core.transmat;
-
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.NyARSquare;
-import jp.nyatla.nyartoolkit.core.param.*;
-import jp.nyatla.nyartoolkit.core.transmat.fitveccalc.NyARFitVecCalculator;
-import jp.nyatla.nyartoolkit.core.transmat.optimize.*;
-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;
-import jp.nyatla.nyartoolkit.core.types.*;
-
-
-/**
- * This class calculates ARMatrix from square information and holds it. --
- * 変換行列を計算して、結果を保持するクラス。
- *
- */
-public class NyARTransMat implements INyARTransMat
-{
- private final static double AR_GET_TRANS_CONT_MAT_MAX_FIT_ERROR = 1.0;
-
- private final NyARDoublePoint2d _center=new NyARDoublePoint2d(0,0);
- private final NyARTransOffset _offset=new NyARTransOffset();
- protected NyARRotMatrix _rotmatrix;
- protected NyARFitVecCalculator _calculator;
- protected INyARRotTransOptimize _mat_optimize;
-
- /**
- * 派生クラスで自分でメンバオブジェクトを指定したい場合はこちらを使う。
- *
- */
- protected NyARTransMat()
- {
- //_calculator,_rotmatrix,_mat_optimizeをコンストラクタの終了後に
- //作成して割り当ててください。
- return;
- }
- public NyARTransMat(NyARParam i_param) throws NyARException
- {
- final NyARCameraDistortionFactor dist=i_param.getDistortionFactor();
- final NyARPerspectiveProjectionMatrix pmat=i_param.getPerspectiveProjectionMatrix();
- this._calculator=new NyARFitVecCalculator(pmat,dist);
- //互換性が重要な時は、NyARRotMatrix_ARToolKitを使うこと。
- //理屈はNyARRotMatrix_NyARToolKitもNyARRotMatrix_ARToolKitも同じだけど、少しだけ値がずれる。
- this._rotmatrix = new NyARRotMatrix_NyARToolKit(pmat);
-// this._rotmatrix = new NyARRotMatrix_ARToolKit(pmat);
- this._mat_optimize=new NyARRotTransOptimize_O2(pmat);
- }
-
- public void setCenter(double i_x, double i_y)
- {
- this._center.x= i_x;
- this._center.y= i_y;
- }
-
-
-
-
- /**
- * 頂点順序をi_directionに対応して並べ替えます。
- * @param i_square
- * @param i_direction
- * @param o_sqvertex_ref
- * @param o_liner_ref
- */
- private final void initVertexOrder(NyARSquare i_square, int i_direction, NyARDoublePoint2d[] o_sqvertex_ref, NyARLinear[] o_liner_ref)
- {
- //頂点順序を考慮した矩形の頂点情報
- o_sqvertex_ref[0]= i_square.sqvertex[(4 - i_direction) % 4];
- o_sqvertex_ref[1]= i_square.sqvertex[(5 - i_direction) % 4];
- o_sqvertex_ref[2]= i_square.sqvertex[(6 - i_direction) % 4];
- o_sqvertex_ref[3]= i_square.sqvertex[(7 - i_direction) % 4];
- o_liner_ref[0]=i_square.line[(4 - i_direction) % 4];
- o_liner_ref[1]=i_square.line[(5 - i_direction) % 4];
- o_liner_ref[2]=i_square.line[(6 - i_direction) % 4];
- o_liner_ref[3]=i_square.line[(7 - i_direction) % 4];
- return;
- }
-
-
- private final NyARDoublePoint2d[] __transMat_sqvertex_ref = new NyARDoublePoint2d[4];
- private final NyARLinear[] __transMat_linear_ref=new NyARLinear[4];
- private final NyARDoublePoint3d __transMat_trans=new NyARDoublePoint3d();
- /**
- * double arGetTransMat( ARMarkerInfo *marker_info,double center[2], double width, double conv[3][4] )
- *
- * @param i_square
- * 計算対象のNyARSquareオブジェクト
- * @param i_direction
- * @param i_width
- * @return
- * @throws NyARException
- */
- public void transMat(final NyARSquare i_square, int i_direction, double i_width, NyARTransMatResult o_result_conv) throws NyARException
- {
- final NyARDoublePoint2d[] sqvertex_ref = __transMat_sqvertex_ref;
- final NyARLinear[] linear_ref=__transMat_linear_ref;
- final NyARDoublePoint3d trans=this.__transMat_trans;
-
- //計算用に頂点情報を初期化(順番調整)
- initVertexOrder(i_square, i_direction, sqvertex_ref,linear_ref);
-
- //基準矩形を設定
- this._offset.setSquare(i_width,this._center);
-
- // rotationを矩形情報から計算
- this._rotmatrix.initRotBySquare(linear_ref,sqvertex_ref);
-
- //平行移動量計算機にオフセット頂点をセット
- this._calculator.setOffsetSquare(this._offset);
-
- //平行移動量計算機に適応先矩形の情報をセット
- this._calculator.setFittedSquare(sqvertex_ref);
-
- //回転行列の平行移動量の計算
- this._calculator.calculateTransfer(this._rotmatrix,trans);
-
- //計算結果の最適化(this._rotmatrix,trans)
- this._mat_optimize.optimize(this._rotmatrix,trans,this._calculator);
-
- // マトリクスの保存
- this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);
- return;
- }
-
- /*
- * (non-Javadoc)
- * @see jp.nyatla.nyartoolkit.core.transmat.INyARTransMat#transMatContinue(jp.nyatla.nyartoolkit.core.NyARSquare, int, double, jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult)
- */
- public void transMatContinue(NyARSquare i_square, int i_direction, double i_width, NyARTransMatResult io_result_conv) throws NyARException
- {
- final NyARDoublePoint2d[] sqvertex_ref = __transMat_sqvertex_ref;
- final NyARLinear[] linear_ref=__transMat_linear_ref;
- final NyARDoublePoint3d trans=this.__transMat_trans;
-
- // io_result_convが初期値なら、transMatで計算する。
- if (!io_result_conv.has_value) {
- this.transMat(i_square, i_direction, i_width, io_result_conv);
- return;
- }
-
- //計算用に頂点情報を初期化(順番調整)
- initVertexOrder(i_square, i_direction, sqvertex_ref,linear_ref);
-
- //基準矩形を設定
- this._offset.setSquare(i_width,this._center);
-
- // rotationを矩形情報を一つ前の変換行列で初期化
- this._rotmatrix.initRotByPrevResult(io_result_conv);
-
- //平行移動量計算機に、オフセット頂点をセット
- this._calculator.setOffsetSquare(this._offset);
-
- //平行移動量計算機に、適応先矩形の情報をセット
- this._calculator.setFittedSquare(sqvertex_ref);
-
- //回転行列の平行移動量の計算
- this._calculator.calculateTransfer(this._rotmatrix,trans);
-
- //計算結果の最適化(this._rotmatrix,trans)
- final double err=this._mat_optimize.optimize(this._rotmatrix,trans,this._calculator);
-
- //計算結果を保存
- this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,io_result_conv);
-
- // エラー値が許容範囲でなければTransMatをやり直し
- if (err > AR_GET_TRANS_CONT_MAT_MAX_FIT_ERROR) {
- // rotationを矩形情報で初期化
- this._rotmatrix.initRotBySquare(linear_ref,sqvertex_ref);
- //回転行列の平行移動量の計算
- this._calculator.calculateTransfer(this._rotmatrix,trans);
- //計算結果の最適化(this._rotmatrix,trans)
- final double err2=this._mat_optimize.optimize(this._rotmatrix,trans,this._calculator);
- //エラー値が低かったら値を差換え
- if (err2 < err) {
- // 良い値が取れたら、差換え
- this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,io_result_conv);
- }
- }
- return;
- }
- /**
- * パラメータで変換行列を更新します。
- *
- * @param i_rot
- * @param i_off
- * @param i_trans
- */
- public void updateMatrixValue(NyARRotMatrix i_rot, NyARDoublePoint3d i_off, NyARDoublePoint3d i_trans,NyARTransMatResult o_result)
- {
- o_result.m00=i_rot.m00;
- o_result.m01=i_rot.m01;
- o_result.m02=i_rot.m02;
- o_result.m03=i_rot.m00 * i_off.x + i_rot.m01 * i_off.y + i_rot.m02 * i_off.z + i_trans.x;
-
- o_result.m10 = i_rot.m10;
- o_result.m11 = i_rot.m11;
- o_result.m12 = i_rot.m12;
- o_result.m13 = i_rot.m10 * i_off.x + i_rot.m11 * i_off.y + i_rot.m12 * i_off.z + i_trans.y;
-
- o_result.m20 = i_rot.m20;
- o_result.m21 = i_rot.m21;
- o_result.m22 = i_rot.m22;
- o_result.m23 = i_rot.m20 * i_off.x + i_rot.m21 * i_off.y + i_rot.m22 * i_off.z + i_trans.z;
-
- o_result.angle.setValue(i_rot.refAngle());
- o_result.has_value = true;
- return;
- }
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat.java (revision 302)
@@ -0,0 +1,324 @@
+/*
+ * PROJECT: NyARToolkit (Extension)
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.transmat;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.param.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.transmat.solver.*;
+import jp.nyatla.nyartoolkit.core.transmat.optimize.*;
+import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;
+import jp.nyatla.nyartoolkit.core.types.*;
+import jp.nyatla.nyartoolkit.core.types.matrix.*;
+
+/**
+ * This class calculates ARMatrix from square information and holds it. --
+ * 変換行列を計算して、結果を保持するクラス。
+ *
+ */
+public class NyARTransMat implements INyARTransMat
+{
+ private final static double FIT_DIFF_THRESHOLD = 1.0;
+ private final static double FIT_DIFF_THRESHOLD_CONT = 1.0;
+
+ private final NyARDoublePoint2d _center=new NyARDoublePoint2d(0,0);
+ private final NyARTransOffset _offset=new NyARTransOffset();
+ private NyARPerspectiveProjectionMatrix _projection_mat_ref;
+ protected NyARRotMatrix _rotmatrix;
+ protected INyARTransportVectorSolver _transsolver;
+ protected NyARPartialDifferentiationOptimize _mat_optimize;
+
+
+ private NyARCameraDistortionFactor _ref_dist_factor;
+
+ /**
+ * 派生クラスで自分でメンバオブジェクトを指定したい場合はこちらを使う。
+ *
+ */
+ protected NyARTransMat()
+ {
+ //_calculator,_rotmatrix,_mat_optimizeをコンストラクタの終了後に
+ //作成して割り当ててください。
+ return;
+ }
+ public NyARTransMat(NyARParam i_param) throws NyARException
+ {
+ final NyARCameraDistortionFactor dist=i_param.getDistortionFactor();
+ final NyARPerspectiveProjectionMatrix pmat=i_param.getPerspectiveProjectionMatrix();
+ this._transsolver=new NyARTransportVectorSolver(pmat,4);
+ //互換性が重要な時は、NyARRotMatrix_ARToolKitを使うこと。
+ //理屈はNyARRotMatrix_NyARToolKitもNyARRotMatrix_ARToolKitも同じだけど、少しだけ値がずれる。
+ this._rotmatrix = new NyARRotMatrix(pmat);
+ this._mat_optimize=new NyARPartialDifferentiationOptimize(pmat);
+ this._ref_dist_factor=dist;
+ this._projection_mat_ref=pmat;
+ }
+
+ public void setCenter(double i_x, double i_y)
+ {
+ this._center.x= i_x;
+ this._center.y= i_y;
+ }
+
+
+
+
+ /**
+ * 頂点順序をi_directionに対応して並べ替えます。
+ * @param i_square
+ * @param i_direction
+ * @param o_sqvertex_ref
+ * @param o_liner_ref
+ */
+ private final void initVertexOrder(NyARSquare i_square, int i_direction, NyARDoublePoint2d[] o_sqvertex_ref, NyARLinear[] o_liner_ref)
+ {
+ //頂点順序を考慮した矩形の頂点情報
+ o_sqvertex_ref[0]= i_square.sqvertex[(4 - i_direction) % 4];
+ o_sqvertex_ref[1]= i_square.sqvertex[(5 - i_direction) % 4];
+ o_sqvertex_ref[2]= i_square.sqvertex[(6 - i_direction) % 4];
+ o_sqvertex_ref[3]= i_square.sqvertex[(7 - i_direction) % 4];
+ o_liner_ref[0]=i_square.line[(4 - i_direction) % 4];
+ o_liner_ref[1]=i_square.line[(5 - i_direction) % 4];
+ o_liner_ref[2]=i_square.line[(6 - i_direction) % 4];
+ o_liner_ref[3]=i_square.line[(7 - i_direction) % 4];
+ return;
+ }
+
+
+ private final NyARDoublePoint2d[] __transMat_sqvertex_ref = new NyARDoublePoint2d[4];
+ private final NyARDoublePoint2d[] __transMat_vertex_2d = NyARDoublePoint2d.createArray(4);
+ private final NyARDoublePoint3d[] __transMat_vertex_3d = NyARDoublePoint3d.createArray(4);
+ private final NyARLinear[] __transMat_linear_ref=new NyARLinear[4];
+ private final NyARDoublePoint3d __transMat_trans=new NyARDoublePoint3d();
+ /**
+ * double arGetTransMat( ARMarkerInfo *marker_info,double center[2], double width, double conv[3][4] )
+ *
+ * @param i_square
+ * 計算対象のNyARSquareオブジェクト
+ * @param i_direction
+ * @param i_width
+ * @return
+ * @throws NyARException
+ */
+ public void transMat(final NyARSquare i_square, int i_direction, double i_width, NyARTransMatResult o_result_conv) throws NyARException
+ {
+ final NyARDoublePoint2d[] sqvertex_ref = __transMat_sqvertex_ref;
+ final NyARLinear[] linear_ref=__transMat_linear_ref;
+ final NyARDoublePoint3d trans=this.__transMat_trans;
+
+ //計算用に頂点情報を初期化(順番調整)
+ initVertexOrder(i_square, i_direction, sqvertex_ref,linear_ref);
+
+ //平行移動量計算機に、2D座標系をセット
+ NyARDoublePoint2d[] vertex_2d=this.__transMat_vertex_2d;
+ NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;
+ this._ref_dist_factor.ideal2ObservBatch(sqvertex_ref, vertex_2d,4);
+ this._transsolver.set2dVertex(vertex_2d,4);
+
+ //基準矩形の3D座標系を作成
+ this._offset.setSquare(i_width,this._center);
+
+ //回転行列を計算
+ this._rotmatrix.initRotBySquare(linear_ref,sqvertex_ref);
+
+ //回転後の3D座標系から、平行移動量を計算
+ this._rotmatrix.getPoint3dBatch(this._offset.vertex,vertex_3d,4);
+ this._transsolver.solveTransportVector(vertex_3d,trans);
+
+ //計算結果の最適化(平行移動量と回転行列の最適化)
+ this.optimize(this._rotmatrix, trans, this._transsolver,this._offset.vertex, vertex_2d);
+
+ // マトリクスの保存
+ this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);
+ return;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see jp.nyatla.nyartoolkit.core.transmat.INyARTransMat#transMatContinue(jp.nyatla.nyartoolkit.core.NyARSquare, int, double, jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult)
+ */
+ public void transMatContinue(NyARSquare i_square, int i_direction, double i_width, NyARTransMatResult o_result_conv) throws NyARException
+ {
+ final NyARDoublePoint2d[] sqvertex_ref = __transMat_sqvertex_ref;
+ final NyARLinear[] linear_ref=__transMat_linear_ref;
+ final NyARDoublePoint3d trans=this.__transMat_trans;
+
+ // io_result_convが初期値なら、transMatで計算する。
+ if (!o_result_conv.has_value) {
+ this.transMat(i_square, i_direction, i_width, o_result_conv);
+ return;
+ }
+
+ //計算用に頂点情報を初期化(順番調整)
+ initVertexOrder(i_square, i_direction, sqvertex_ref,linear_ref);
+
+
+ //平行移動量計算機に、2D座標系をセット
+ NyARDoublePoint2d[] vertex_2d=this.__transMat_vertex_2d;
+ NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;
+ this._ref_dist_factor.ideal2ObservBatch(sqvertex_ref, vertex_2d,4);
+ this._transsolver.set2dVertex(vertex_2d,4);
+
+ //基準矩形の3D座標系を作成
+ this._offset.setSquare(i_width,this._center);
+
+ //回転行列を計算
+ this._rotmatrix.initRotByPrevResult(o_result_conv);
+
+ //回転後の3D座標系から、平行移動量を計算
+ this._rotmatrix.getPoint3dBatch(this._offset.vertex,vertex_3d,4);
+ this._transsolver.solveTransportVector(vertex_3d,trans);
+
+ //現在のエラーレートを計算しておく
+ double min_err=errRate(this._rotmatrix,trans, this._offset.vertex, vertex_2d,4,vertex_3d);
+ NyARDoubleMatrix33 rot=this.__rot;
+ //エラーレートが閾値超えてたらアゲイン
+ if(min_err<FIT_DIFF_THRESHOLD_CONT){
+ rot.setValue(this._rotmatrix);
+ //最適化してみる。
+ for (int i = 0;i<5; i++) {
+ //変換行列の最適化
+ this._mat_optimize.modifyMatrix(rot, trans, this._offset.vertex, vertex_2d, 4);
+ double err=errRate(rot,trans,this._offset.vertex, vertex_2d,4,vertex_3d);
+ //System.out.println("E:"+err);
+ if(min_err-err<FIT_DIFF_THRESHOLD){
+ //System.out.println("BREAK");
+ break;
+ }
+ this._transsolver.solveTransportVector(vertex_3d, trans);
+ this._rotmatrix.setValue(rot);
+ min_err=err;
+ }
+ this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);
+ }else{
+ //回転行列を計算
+ this._rotmatrix.initRotBySquare(linear_ref,sqvertex_ref);
+
+ //回転後の3D座標系から、平行移動量を計算
+ this._rotmatrix.getPoint3dBatch(this._offset.vertex,vertex_3d,4);
+ this._transsolver.solveTransportVector(vertex_3d,trans);
+
+ //計算結果の最適化(平行移動量と回転行列の最適化)
+ this.optimize(this._rotmatrix, trans, this._transsolver,this._offset.vertex, vertex_2d);
+ this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);
+ }
+ return;
+ }
+ private NyARDoubleMatrix33 __rot=new NyARDoubleMatrix33();
+ private double optimize(NyARRotMatrix io_rotmat,NyARDoublePoint3d io_transvec,INyARTransportVectorSolver i_solver,NyARDoublePoint3d[] i_offset_3d,NyARDoublePoint2d[] i_2d_vertex) throws NyARException
+ {
+ //System.out.println("START");
+ NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;
+ //初期のエラー値を計算
+ double min_err=errRate(io_rotmat, io_transvec, i_offset_3d, i_2d_vertex,4,vertex_3d);
+ NyARDoubleMatrix33 rot=this.__rot;
+ rot.setValue(io_rotmat);
+ for (int i = 0;i<5; i++) {
+ //変換行列の最適化
+ this._mat_optimize.modifyMatrix(rot, io_transvec, i_offset_3d, i_2d_vertex, 4);
+ double err=errRate(rot,io_transvec, i_offset_3d, i_2d_vertex,4,vertex_3d);
+ //System.out.println("E:"+err);
+ if(min_err-err<FIT_DIFF_THRESHOLD){
+ //System.out.println("BREAK");
+ break;
+ }
+ i_solver.solveTransportVector(vertex_3d, io_transvec);
+ io_rotmat.setValue(rot);
+ min_err=err;
+ }
+ //System.out.println("END");
+ return min_err;
+ }
+
+ //エラーレート計算機
+ 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
+ {
+ NyARPerspectiveProjectionMatrix cp = this._projection_mat_ref;
+ final double cp00=cp.m00;
+ final double cp01=cp.m01;
+ final double cp02=cp.m02;
+ final double cp11=cp.m11;
+ final double cp12=cp.m12;
+
+ double err=0;
+ for(int i=0;i<i_number_of_vertex;i++){
+ double x3d,y3d,z3d;
+ 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;
+ 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;
+ 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;
+ x3d+=i_trans.x;
+ y3d+=i_trans.y;
+ z3d+=i_trans.z;
+
+ //射影変換
+ double x2d=x3d*cp00+y3d*cp01+z3d*cp02;
+ double y2d=y3d*cp11+z3d*cp12;
+ double h2d=z3d;
+
+ //エラーレート計算
+ double t1=i_vertex2d[i].x-x2d/h2d;
+ double t2=i_vertex2d[i].y-y2d/h2d;
+ err+=t1*t1+t2*t2;
+
+ }
+ return err/i_number_of_vertex;
+ }
+
+
+
+ /**
+ * パラメータで変換行列を更新します。
+ *
+ * @param i_rot
+ * @param i_off
+ * @param i_trans
+ */
+ public void updateMatrixValue(NyARRotMatrix i_rot, NyARDoublePoint3d i_off, NyARDoublePoint3d i_trans,NyARTransMatResult o_result)
+ {
+ o_result.m00=i_rot.m00;
+ o_result.m01=i_rot.m01;
+ o_result.m02=i_rot.m02;
+ o_result.m03=i_rot.m00 * i_off.x + i_rot.m01 * i_off.y + i_rot.m02 * i_off.z + i_trans.x;
+
+ o_result.m10 = i_rot.m10;
+ o_result.m11 = i_rot.m11;
+ o_result.m12 = i_rot.m12;
+ o_result.m13 = i_rot.m10 * i_off.x + i_rot.m11 * i_off.y + i_rot.m12 * i_off.z + i_trans.y;
+
+ o_result.m20 = i_rot.m20;
+ o_result.m21 = i_rot.m21;
+ o_result.m22 = i_rot.m22;
+ o_result.m23 = i_rot.m20 * i_off.x + i_rot.m21 * i_off.y + i_rot.m22 * i_off.z + i_trans.z;
+
+ o_result.has_value = true;
+ return;
+ }
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransOffset.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransOffset.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransOffset.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.transmat;
@@ -36,8 +35,8 @@

final public class NyARTransOffset
{
- public NyARDoublePoint3d[] vertex=NyARDoublePoint3d.createArray(4);
- public NyARDoublePoint3d point=new NyARDoublePoint3d();
+ public final NyARDoublePoint3d[] vertex=NyARDoublePoint3d.createArray(4);
+ public final NyARDoublePoint3d point=new NyARDoublePoint3d();
/**
* 中心位置と辺長から、オフセット情報を作成して設定する。
* @param i_width
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_NyARToolKit.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_NyARToolKit.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_NyARToolKit.java (revision 302)
@@ -1,86 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core.transmat.rotmatrix;
-
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.param.*;
-/**
- * 回転行列計算用の、3x3行列
- * 計算方法はARToolKitと同じだが、ARToolKitにある不要な行列から角度を逆算する
- * 処理を省略しているため、下位12桁目の計算値が異なる。
- *
- */
-public class NyARRotMatrix_NyARToolKit extends NyARRotMatrix_ARToolKit
-{
- /**
- * インスタンスを準備します。
- *
- * @param i_param
- */
- public NyARRotMatrix_NyARToolKit(NyARPerspectiveProjectionMatrix i_matrix) throws NyARException
- {
- super(i_matrix);
- return;
- }
- public final void setAngle(final double i_x, final double i_y, final double i_z)
- {
- final double sina = Math.sin(i_x);
- final double cosa = Math.cos(i_x);
- final double sinb = Math.sin(i_y);
- final double cosb = Math.cos(i_y);
- final double sinc = Math.sin(i_z);
- final double cosc = Math.cos(i_z);
- // Optimize
- final double CACA = cosa * cosa;
- final double SASA = sina * sina;
- final double SACA = sina * cosa;
- final double SASB = sina * sinb;
- final double CASB = cosa * sinb;
- final double SACACB = SACA * cosb;
-
- this.m00 = CACA * cosb * cosc + SASA * cosc + SACACB * sinc - SACA * sinc;
- this.m01 = -CACA * cosb * sinc - SASA * sinc + SACACB * cosc - SACA * cosc;
- this.m02 = CASB;
- this.m10 = SACACB * cosc - SACA * cosc + SASA * cosb * sinc + CACA * sinc;
- this.m11 = -SACACB * sinc + SACA * sinc + SASA * cosb * cosc + CACA * cosc;
- this.m12 = SASB;
- this.m20 = -CASB * cosc - SASB * sinc;
- this.m21 = CASB * sinc - SASB * cosc;
- this.m22 = cosb;
- //angleを逆計算せずに直接代入
- this._angle.x=i_x;
- this._angle.y=i_y;
- this._angle.z=i_z;
- return;
- }
-
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotVector.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotVector.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotVector.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.transmat.rotmatrix;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix.java (revision 302)
@@ -7,31 +7,31 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.transmat.rotmatrix;

import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.param.NyARPerspectiveProjectionMatrix;
import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix33;
@@ -39,38 +39,115 @@
* 回転行列計算用の、3x3行列
*
*/
-public abstract class NyARRotMatrix extends NyARDoubleMatrix33
-{
+public class NyARRotMatrix extends NyARDoubleMatrix33
+{
/**
+ * インスタンスを準備します。
+ *
+ * @param i_param
+ */
+ public NyARRotMatrix(NyARPerspectiveProjectionMatrix i_matrix) throws NyARException
+ {
+ this.__initRot_vec1=new NyARRotVector(i_matrix);
+ this.__initRot_vec2=new NyARRotVector(i_matrix);
+ return;
+ }
+ final private NyARRotVector __initRot_vec1;
+ final private NyARRotVector __initRot_vec2;
+ /**
* NyARTransMatResultの内容からNyARRotMatrixを復元します。
* @param i_prev_result
*/
- public abstract void initRotByPrevResult(NyARTransMatResult i_prev_result);
- public abstract void initRotBySquare(final NyARLinear[] i_linear,final NyARDoublePoint2d[] i_sqvertex) throws NyARException;
+ public final void initRotByPrevResult(NyARTransMatResult i_prev_result)
+ {
+
+ this.m00=i_prev_result.m00;
+ this.m01=i_prev_result.m01;
+ this.m02=i_prev_result.m02;
+
+ this.m10=i_prev_result.m10;
+ this.m11=i_prev_result.m11;
+ this.m12=i_prev_result.m12;
+
+ this.m20=i_prev_result.m20;
+ this.m21=i_prev_result.m21;
+ this.m22=i_prev_result.m22;
+ return;
+ }
/**
- * 格納しているAngleの参照値を返します。
- * 返したオブジェクトはクラスに所有し続けられ、内容が変わることがあります。
- * @return
+ *
+ * @param i_linear
+ * @param i_sqvertex
+ * @throws NyARException
*/
- public abstract NyARDoublePoint3d refAngle();
+ public void initRotBySquare(final NyARLinear[] i_linear,final NyARDoublePoint2d[] i_sqvertex) throws NyARException
+ {
+ final NyARRotVector vec1=this.__initRot_vec1;
+ final NyARRotVector vec2=this.__initRot_vec2;
+
+ //向かい合った辺から、2本のベクトルを計算
+
+ //軸1
+ vec1.exteriorProductFromLinear(i_linear[0], i_linear[2]);
+ vec1.checkVectorByVertex(i_sqvertex[0], i_sqvertex[1]);
+
+ //軸2
+ vec2.exteriorProductFromLinear(i_linear[1], i_linear[3]);
+ vec2.checkVectorByVertex(i_sqvertex[3], i_sqvertex[0]);
+
+ //回転の最適化?
+ NyARRotVector.checkRotation(vec1,vec2);
+
+ this.m00 =vec1.v1;
+ this.m10 =vec1.v2;
+ this.m20 =vec1.v3;
+ this.m01 =vec2.v1;
+ this.m11 =vec2.v2;
+ this.m21 =vec2.v3;
+
+ //最後の軸を計算
+ final double w02 = vec1.v2 * vec2.v3 - vec1.v3 * vec2.v2;
+ final double w12 = vec1.v3 * vec2.v1 - vec1.v1 * vec2.v3;
+ final double w22 = vec1.v1 * vec2.v2 - vec1.v2 * vec2.v1;
+ final double w = Math.sqrt(w02 * w02 + w12 * w12 + w22 * w22);
+ this.m02 = w02/w;
+ this.m12 = w12/w;
+ this.m22 = w22/w;
+ return;
+ }
/**
- * 回転角から回転行列を計算してセットします。
- * @param i_x
- * @param i_y
- * @param i_z
- */
- public abstract void setAngle(final double i_x, final double i_y, final double i_z);
- /**
* i_in_pointを変換行列で座標変換する。
* @param i_in_point
* @param i_out_point
- */
- public abstract void getPoint3d(final NyARDoublePoint3d i_in_point,final NyARDoublePoint3d i_out_point);
+ */
+ public final void getPoint3d(final NyARDoublePoint3d i_in_point,final NyARDoublePoint3d i_out_point)
+ {
+ final double x=i_in_point.x;
+ final double y=i_in_point.y;
+ final double z=i_in_point.z;
+ i_out_point.x=this.m00 * x + this.m01 * y + this.m02 * z;
+ i_out_point.y=this.m10 * x + this.m11 * y + this.m12 * z;
+ i_out_point.z=this.m20 * x + this.m21 * y + this.m22 * z;
+ return;
+ }
/**
* 複数の頂点を一括して変換する
* @param i_in_point
* @param i_out_point
* @param i_number_of_vertex
*/
- public abstract void getPoint3dBatch(final NyARDoublePoint3d[] i_in_point,NyARDoublePoint3d[] i_out_point,int i_number_of_vertex);
+ public final void getPoint3dBatch(final NyARDoublePoint3d[] i_in_point,NyARDoublePoint3d[] i_out_point,int i_number_of_vertex)
+ {
+ for(int i=i_number_of_vertex-1;i>=0;i--){
+ final NyARDoublePoint3d out_ptr=i_out_point[i];
+ final NyARDoublePoint3d in_ptr=i_in_point[i];
+ final double x=in_ptr.x;
+ final double y=in_ptr.y;
+ final double z=in_ptr.z;
+ out_ptr.x=this.m00 * x + this.m01 * y + this.m02 * z;
+ out_ptr.y=this.m10 * x + this.m11 * y + this.m12 * z;
+ out_ptr.z=this.m20 * x + this.m21 * y + this.m22 * z;
+ }
+ return;
+ }
}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit.java (revision 302)
@@ -7,32 +7,30 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.transmat.rotmatrix;

import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.core.param.*;
/**
@@ -48,69 +46,17 @@
*/
public NyARRotMatrix_ARToolKit(NyARPerspectiveProjectionMatrix i_matrix) throws NyARException
{
- this.__initRot_vec1=new NyARRotVector(i_matrix);
- this.__initRot_vec2=new NyARRotVector(i_matrix);
+ super(i_matrix);
this._angle=new NyARDoublePoint3d();
return;
}
- final private NyARRotVector __initRot_vec1;
- final private NyARRotVector __initRot_vec2;
final protected NyARDoublePoint3d _angle;



-
- public final void initRotByPrevResult(NyARTransMatResult i_prev_result)
- {
-
- this.m00=i_prev_result.m00;
- this.m01=i_prev_result.m01;
- this.m02=i_prev_result.m02;
-
- this.m10=i_prev_result.m10;
- this.m11=i_prev_result.m11;
- this.m12=i_prev_result.m12;
-
- this.m20=i_prev_result.m20;
- this.m21=i_prev_result.m21;
- this.m22=i_prev_result.m22;
- return;
- }
-
-
public final void initRotBySquare(final NyARLinear[] i_linear,final NyARDoublePoint2d[] i_sqvertex) throws NyARException
{
- final NyARRotVector vec1=this.__initRot_vec1;
- final NyARRotVector vec2=this.__initRot_vec2;
-
- //向かい合った辺から、2本のベクトルを計算
-
- //軸1
- vec1.exteriorProductFromLinear(i_linear[0], i_linear[2]);
- vec1.checkVectorByVertex(i_sqvertex[0], i_sqvertex[1]);
-
- //軸2
- vec2.exteriorProductFromLinear(i_linear[1], i_linear[3]);
- vec2.checkVectorByVertex(i_sqvertex[3], i_sqvertex[0]);
-
- //回転の最適化?
- NyARRotVector.checkRotation(vec1,vec2);
-
- this.m00 =vec1.v1;
- this.m10 =vec1.v2;
- this.m20 =vec1.v3;
- this.m01 =vec2.v1;
- this.m11 =vec2.v2;
- this.m21 =vec2.v3;
-
- //最後の軸を計算
- final double w02 = vec1.v2 * vec2.v3 - vec1.v3 * vec2.v2;
- final double w12 = vec1.v3 * vec2.v1 - vec1.v1 * vec2.v3;
- final double w22 = vec1.v1 * vec2.v2 - vec1.v2 * vec2.v1;
- final double w = Math.sqrt(w02 * w02 + w12 * w12 + w22 * w22);
- this.m02 = w02/w;
- this.m12 = w12/w;
- this.m22 = w22/w;
+ super.initRotBySquare(i_linear,i_sqvertex);
//Matrixからangleをロード
this.updateAngleFromMatrix();
return;
@@ -154,41 +100,6 @@
return;
}
/**
- * i_in_pointを変換行列で座標変換する。
- * @param i_in_point
- * @param i_out_point
- */
- public final void getPoint3d(final NyARDoublePoint3d i_in_point,final NyARDoublePoint3d i_out_point)
- {
- final double x=i_in_point.x;
- final double y=i_in_point.y;
- final double z=i_in_point.z;
- i_out_point.x=this.m00 * x + this.m01 * y + this.m02 * z;
- i_out_point.y=this.m10 * x + this.m11 * y + this.m12 * z;
- i_out_point.z=this.m20 * x + this.m21 * y + this.m22 * z;
- return;
- }
- /**
- * 複数の頂点を一括して変換する
- * @param i_in_point
- * @param i_out_point
- * @param i_number_of_vertex
- */
- public final void getPoint3dBatch(final NyARDoublePoint3d[] i_in_point,NyARDoublePoint3d[] i_out_point,int i_number_of_vertex)
- {
- for(int i=i_number_of_vertex-1;i>=0;i--){
- final NyARDoublePoint3d out_ptr=i_out_point[i];
- final NyARDoublePoint3d in_ptr=i_in_point[i];
- final double x=in_ptr.x;
- final double y=in_ptr.y;
- final double z=in_ptr.z;
- out_ptr.x=this.m00 * x + this.m01 * y + this.m02 * z;
- out_ptr.y=this.m10 * x + this.m11 * y + this.m12 * z;
- out_ptr.z=this.m20 * x + this.m21 * y + this.m22 * z;
- }
- return;
- }
- /**
* 現在のMatrixからangkeを復元する。
* @param o_angle
*/
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit_O2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit_O2.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit_O2.java (revision 302)
@@ -0,0 +1,85 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.transmat.rotmatrix;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.param.*;
+/**
+ * 回転行列計算用の、3x3行列
+ * 計算方法はARToolKitと同じだが、ARToolKitにある不要な行列から角度を逆算する
+ * 処理を省略しているため、下位12桁目の計算値が異なる。
+ *
+ */
+public class NyARRotMatrix_ARToolKit_O2 extends NyARRotMatrix_ARToolKit
+{
+ /**
+ * インスタンスを準備します。
+ *
+ * @param i_param
+ */
+ public NyARRotMatrix_ARToolKit_O2(NyARPerspectiveProjectionMatrix i_matrix) throws NyARException
+ {
+ super(i_matrix);
+ return;
+ }
+ public final void setAngle(final double i_x, final double i_y, final double i_z)
+ {
+ final double sina = Math.sin(i_x);
+ final double cosa = Math.cos(i_x);
+ final double sinb = Math.sin(i_y);
+ final double cosb = Math.cos(i_y);
+ final double sinc = Math.sin(i_z);
+ final double cosc = Math.cos(i_z);
+ // Optimize
+ final double CACA = cosa * cosa;
+ final double SASA = sina * sina;
+ final double SACA = sina * cosa;
+ final double SASB = sina * sinb;
+ final double CASB = cosa * sinb;
+ final double SACACB = SACA * cosb;
+
+ this.m00 = CACA * cosb * cosc + SASA * cosc + SACACB * sinc - SACA * sinc;
+ this.m01 = -CACA * cosb * sinc - SASA * sinc + SACACB * cosc - SACA * cosc;
+ this.m02 = CASB;
+ this.m10 = SACACB * cosc - SACA * cosc + SASA * cosb * sinc + CACA * sinc;
+ this.m11 = -SACACB * sinc + SACA * sinc + SASA * cosb * cosc + CACA * cosc;
+ this.m12 = SASB;
+ this.m20 = -CASB * cosc - SASB * sinc;
+ this.m21 = CASB * sinc - SASB * cosc;
+ this.m22 = cosb;
+ //angleを逆計算せずに直接代入
+ this._angle.x=i_x;
+ this._angle.y=i_y;
+ this._angle.z=i_z;
+ return;
+ }
+
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/solver/NyARTransportVectorSolver.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/solver/NyARTransportVectorSolver.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/solver/NyARTransportVectorSolver.java (revision 302)
@@ -0,0 +1,161 @@
+/*
+ * PROJECT: NyARToolkit(Extension)
+ * --------------------------------------------------------------------------------
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.transmat.solver;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.param.NyARPerspectiveProjectionMatrix;
+import jp.nyatla.nyartoolkit.core.types.*;
+
+/**
+ * 並進ベクトル[T]を3次元座標[b]と基点の回転済行列[M]から計算します。
+ *
+ * アルゴリズムは、ARToolKit 拡張現実プログラミング入門 の、P207のものです。
+ *
+ * 計算手順
+ * [A]*[T]=bを、[A]T*[A]*[T]=[A]T*[b]にする。
+ * set2dVertexで[A]T*[A]=[M]を計算して、Aの3列目の情報だけ保存しておく。
+ * getTransportVectorで[M]*[T]=[A]T*[b]を連立方程式で解いて、[T]を得る。
+ */
+public class NyARTransportVectorSolver implements INyARTransportVectorSolver
+{
+ private double[] _cx;
+ private double[] _cy;
+ private final NyARPerspectiveProjectionMatrix _projection_mat;
+ private int _nmber_of_vertex;
+ public NyARTransportVectorSolver(final NyARPerspectiveProjectionMatrix i_projection_mat_ref,int i_max_vertex)
+ {
+ this._projection_mat=i_projection_mat_ref;
+ this._cx=new double[i_max_vertex];
+ this._cy=new double[i_max_vertex];
+ return;
+ }
+ private double _a00,_a01_10,_a02_20,_a11,_a12_21,_a22;
+ /**
+ * 画面上の座標群を指定します。
+ * @param i_ref_vertex_2d
+ * 歪み矯正済の画面上の頂点座標群への参照値を指定します。
+ * @throws NyARException
+ *
+ */
+ public void set2dVertex(NyARDoublePoint2d[] i_ref_vertex_2d,int i_number_of_vertex) throws NyARException
+ {
+ //3x2nと2n*3の行列から、最小二乗法計算するために3x3マトリクスを作る。
+ //行列[A]の3列目のキャッシュ
+ final double[] cx=this._cx;
+ final double[] cy=this._cy;
+
+ double m22;
+ double p00=this._projection_mat.m00;
+ double p01=this._projection_mat.m01;
+ double p11=this._projection_mat.m11;
+ double p12=this._projection_mat.m12;
+ double p02=this._projection_mat.m02;
+ double w1,w2,w3,w4;
+
+ this._a00=i_number_of_vertex*p00*p00;
+ this._a01_10=i_number_of_vertex*p00*p01;
+ this._a11=i_number_of_vertex*(p01*p01+p11*p11);
+
+ //[A]T*[A]の計算
+ m22=0;
+ w1=w2=0;
+ for(int i=0;i<i_number_of_vertex;i++){
+ //座標を保存しておく。
+ w3=p02-(cx[i]=i_ref_vertex_2d[i].x);
+ w4=p12-(cy[i]=i_ref_vertex_2d[i].y);
+ w1+=w3;
+ w2+=w4;
+ m22+=w3*w3+w4*w4;
+ }
+ this._a02_20=w1*p00;
+ this._a12_21=p01*w1+p11*w2;
+ this._a22=m22;
+
+ this._nmber_of_vertex=i_number_of_vertex;
+ return;
+ }
+
+ /**
+ * 画面座標群と3次元座標群から、平行移動量を計算します。
+ * 2d座標系は、直前に実行したset2dVertexのものを使用します。
+ * @param i_vertex_2d
+ * 直前のset2dVertexコールで指定したものと同じものを指定してください。
+ * @param i_vertex3d
+ * 3次元空間の座標群を設定します。頂点の順番は、画面座標群と同じ順序で格納してください。
+ * @param o_transfer
+ * @throws NyARException
+ */
+ public void solveTransportVector(NyARDoublePoint3d[] i_vertex3d,NyARDoublePoint3d o_transfer) throws NyARException
+ {
+ final int number_of_vertex=this._nmber_of_vertex;
+ final double p00=this._projection_mat.m00;
+ final double p01=this._projection_mat.m01;
+ final double p02=this._projection_mat.m02;
+ final double p11=this._projection_mat.m11;
+ final double p12=this._projection_mat.m12;
+ //行列[A]の3列目のキャッシュ
+ final double[] cx=this._cx;
+ final double[] cy=this._cy;
+
+ //回転行列を元座標の頂点群に適応
+ //[A]T*[b]を計算
+ double b1=0,b2=0,b3=0;
+ for(int i=0;i<number_of_vertex;i++)
+ {
+ double w1=i_vertex3d[i].z*cx[i]-p00*i_vertex3d[i].x-p01*i_vertex3d[i].y-p02*i_vertex3d[i].z;
+ double w2=i_vertex3d[i].z*cy[i]-p11*i_vertex3d[i].y-p12*i_vertex3d[i].z;
+ b1+=w1;
+ b2+=w2;
+ b3+=cx[i]*w1+cy[i]*w2;
+ }
+ //[A]T*[b]を計算
+ b3=p02*b1+p12*b2-b3;//順番変えたらダメよ
+ b2=p01*b1+p11*b2;
+ b1=p00*b1;
+ //([A]T*[A])*[T]=[A]T*[b]を方程式で解く。
+ //a01とa10を0と仮定しても良いんじゃないかな?
+ double a00=this._a00;
+ double a01=this._a01_10;
+ double a02=this._a02_20;
+ double a11=this._a11;
+ double a12=this._a12_21;
+ double a22=this._a22;
+
+ double t1=a22*b2-a12*b3;
+ double t2=a12*b2-a11*b3;
+ double t3=a01*b3-a02*b2;
+ double t4=a12*a12-a11*a22;
+ double t5=a02*a12-a01*a22;
+ double t6=a02*a11-a01*a12;
+ double det=a00*t4-a01*t5 + a02*t6;
+ o_transfer.x= (a01*t1 - a02*t2 +b1*t4)/det;
+ o_transfer.y=-(a00*t1 + a02*t3 +b1*t5)/det;
+ o_transfer.z= (a00*t2 + a01*t3 +b1*t6)/det;
+
+
+ return;
+ }
+}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/solver/NyARTransportVectorSolver_ARToolKit.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/solver/NyARTransportVectorSolver_ARToolKit.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/solver/NyARTransportVectorSolver_ARToolKit.java (revision 302)
@@ -0,0 +1,133 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.transmat.solver;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.NyARMat;
+import jp.nyatla.nyartoolkit.core.param.NyARPerspectiveProjectionMatrix;
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;
+
+/**
+ * 並進ベクトル[T]を3次元座標[b]と基点の回転済行列[M]から計算します。
+ * ARToolKit互換の数値を計算します。
+ *
+ */
+public class NyARTransportVectorSolver_ARToolKit implements INyARTransportVectorSolver
+{
+ private final NyARMat _mat_at = new NyARMat(3,8);//3,NUMBER_OF_VERTEX*2
+ private final NyARMat _mat_a = new NyARMat(8,3);//NUMBER_OF_VERTEX,3
+ private final NyARMat _mat_t = new NyARMat(3,3);//NUMBER_OF_VERTEX,3
+ private final NyARMat _mat_c = new NyARMat(8,1);//NUMBER_OF_VERTEX * 2, 1
+ private final NyARMat _mat_e = new NyARMat(3,1);
+ private final NyARMat _mat_f = new NyARMat(3,1);
+ private double[] _cx=new double[4];
+ private double[] _cy=new double[4];
+
+ private final NyARPerspectiveProjectionMatrix _projection_mat;
+ public NyARTransportVectorSolver_ARToolKit(final NyARPerspectiveProjectionMatrix i_projection_mat_ref)
+ {
+ this._projection_mat=i_projection_mat_ref;
+ //aとb(aの転置行列)の固定部分を設定。
+ final double[][] mata = this._mat_a.getArray();
+ final double[][] matat = this._mat_at.getArray();
+
+ //変換用行列のcpara部分を先に作成
+ for (int i = 0; i < 4; i++) {
+ final int x2 = i * 2;
+ 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];
+ 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];
+ 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;
+ 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];
+ }
+ return;
+ }
+ public void set2dVertex(NyARDoublePoint2d[] i_ref_vertex_2d,int i_number_of_vertex) throws NyARException
+ {
+ assert(i_number_of_vertex==4);
+ final double[] cx=this._cx;
+ final double[] cy=this._cy;
+ final double cpara02=this._projection_mat.m02;
+ final double cpara12=this._projection_mat.m12;
+ final NyARMat mat_t=this._mat_t;
+ final double[][] mata = this._mat_a.getArray();
+ final double[][] matat= this._mat_at.getArray();
+ for (int i = 0; i < 4; i++){
+ cx[i]=i_ref_vertex_2d[i].x;
+ cy[i]=i_ref_vertex_2d[i].y;
+ final int x2 = i * 2;
+ 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];
+ 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];
+ }
+ //T(3x3行列)の作成
+ mat_t.matrixMul(this._mat_at, this._mat_a);
+ mat_t.matrixSelfInv();
+ return;
+ }
+ /**
+ * 画面座標群と3次元座標群から、平行移動量を計算します。
+ * 2d座標系は、直前に実行したset2dVertexのものを使用します。
+ * @param i_vertex_2d
+ * 直前のset2dVertexコールで指定したものと同じものを指定してください。
+ * @param i_vertex3d
+ * 3次元空間の座標群を設定します。頂点の順番は、画面座標群と同じ順序で格納してください。
+ * @param o_transfer
+ * @throws NyARException
+ */
+ public void solveTransportVector(NyARDoublePoint3d[] i_vertex3d,NyARDoublePoint3d o_transfer) throws NyARException
+ {
+ final double[][] matc = this._mat_c.getArray();
+ final double cpara00=this._projection_mat.m00;
+ final double cpara01=this._projection_mat.m01;
+ final double cpara02=this._projection_mat.m02;
+ final double cpara11=this._projection_mat.m11;
+ final double cpara12=this._projection_mat.m12;
+ final double[] cx=this._cx;
+ final double[] cy=this._cy;
+
+ //(3D座標?)を一括請求
+ for (int i = 0; i < 4; i++) {
+ final int x2 = i+i;
+ final NyARDoublePoint3d point3d_ptr=i_vertex3d[i];
+ //透視変換?
+ 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;
+ 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;
+ }
+ this._mat_e.matrixMul(this._mat_at,this._mat_c);
+ this._mat_f.matrixMul(this._mat_t, this._mat_e);
+
+ final double[][] matf = this._mat_f.getArray();
+ o_transfer.x= matf[0][0];// trans[0] = mat_f->m[0];
+ o_transfer.y= matf[1][0];
+ o_transfer.z= matf[2][0];// trans[2] = mat_f->m[2];
+ return;
+ }
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/solver/INyARTransportVectorSolver.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/solver/INyARTransportVectorSolver.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/solver/INyARTransportVectorSolver.java (revision 302)
@@ -0,0 +1,56 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.transmat.solver;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;
+
+/**
+ * 並進ベクトル[T]を3次元座標[b]と基点の回転済行列[M]から計算するインタフェイスです。
+ * [M][T]=[b]
+ *
+ */
+public interface INyARTransportVectorSolver
+{
+ public void set2dVertex(NyARDoublePoint2d[] i_ref_vertex_2d,int i_number_of_vertex) throws NyARException;
+ /**
+ * 画面座標群と3次元座標群から、平行移動量を計算します。
+ * 2d座標系は、直前に実行したset2dVertexのものを使用します。
+ * @param i_vertex_2d
+ * 直前のset2dVertexコールで指定したものと同じものを指定してください。
+ * @param i_vertex3d
+ * 3次元空間の座標群を設定します。頂点の順番は、画面座標群と同じ順序で格納してください。
+ * @param o_transfer
+ * @throws NyARException
+ */
+ public void solveTransportVector(NyARDoublePoint3d[] i_vertex3d,NyARDoublePoint3d o_transfer) throws NyARException;
+}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat_ARToolKit.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat_ARToolKit.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat_ARToolKit.java (revision 302)
@@ -0,0 +1,270 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.transmat;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.param.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.transmat.solver.*;
+import jp.nyatla.nyartoolkit.core.transmat.optimize.*;
+import jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit.INyARRotMatrixOptimize;
+import jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit.NyARRotMatrixOptimize_O2;
+import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;
+import jp.nyatla.nyartoolkit.core.types.*;
+
+
+/**
+ * This class calculates ARMatrix from square information and holds it. --
+ * 変換行列を計算して、結果を保持するクラス。
+ *
+ */
+public class NyARTransMat_ARToolKit implements INyARTransMat
+{
+ private final static int AR_GET_TRANS_MAT_MAX_LOOP_COUNT = 5;// #define AR_GET_TRANS_MAT_MAX_LOOP_COUNT 5
+ private final static double AR_GET_TRANS_MAT_MAX_FIT_ERROR = 1.0;// #define AR_GET_TRANS_MAT_MAX_FIT_ERROR 1.0
+ private final static double AR_GET_TRANS_CONT_MAT_MAX_FIT_ERROR = 1.0;
+
+ private final NyARDoublePoint2d _center=new NyARDoublePoint2d(0,0);
+ private final NyARTransOffset _offset=new NyARTransOffset();
+ protected NyARRotMatrix_ARToolKit _rotmatrix;
+ protected INyARTransportVectorSolver _transsolver;
+ protected INyARRotMatrixOptimize _mat_optimize;
+ private NyARCameraDistortionFactor _ref_dist_factor;
+
+ /**
+ * 派生クラスで自分でメンバオブジェクトを指定したい場合はこちらを使う。
+ *
+ */
+ protected NyARTransMat_ARToolKit()
+ {
+ //_calculator,_rotmatrix,_mat_optimizeをコンストラクタの終了後に
+ //作成して割り当ててください。
+ return;
+ }
+ public NyARTransMat_ARToolKit(NyARParam i_param) throws NyARException
+ {
+ final NyARCameraDistortionFactor dist=i_param.getDistortionFactor();
+ final NyARPerspectiveProjectionMatrix pmat=i_param.getPerspectiveProjectionMatrix();
+ this._transsolver=new NyARTransportVectorSolver_ARToolKit(pmat);
+ //互換性が重要な時は、NyARRotMatrix_ARToolKitを使うこと。
+ //理屈はNyARRotMatrix_NyARToolKitもNyARRotMatrix_ARToolKitも同じだけど、少しだけ値がずれる。
+ this._rotmatrix = new NyARRotMatrix_ARToolKit_O2(pmat);
+ this._mat_optimize=new NyARRotMatrixOptimize_O2(pmat);
+ this._ref_dist_factor=dist;
+ }
+
+ public void setCenter(double i_x, double i_y)
+ {
+ this._center.x= i_x;
+ this._center.y= i_y;
+ }
+
+
+
+
+ /**
+ * 頂点順序をi_directionに対応して並べ替えます。
+ * @param i_square
+ * @param i_direction
+ * @param o_sqvertex_ref
+ * @param o_liner_ref
+ */
+ private final void initVertexOrder(NyARSquare i_square, int i_direction, NyARDoublePoint2d[] o_sqvertex_ref, NyARLinear[] o_liner_ref)
+ {
+ //頂点順序を考慮した矩形の頂点情報
+ o_sqvertex_ref[0]= i_square.sqvertex[(4 - i_direction) % 4];
+ o_sqvertex_ref[1]= i_square.sqvertex[(5 - i_direction) % 4];
+ o_sqvertex_ref[2]= i_square.sqvertex[(6 - i_direction) % 4];
+ o_sqvertex_ref[3]= i_square.sqvertex[(7 - i_direction) % 4];
+ o_liner_ref[0]=i_square.line[(4 - i_direction) % 4];
+ o_liner_ref[1]=i_square.line[(5 - i_direction) % 4];
+ o_liner_ref[2]=i_square.line[(6 - i_direction) % 4];
+ o_liner_ref[3]=i_square.line[(7 - i_direction) % 4];
+ return;
+ }
+
+
+ private final NyARDoublePoint2d[] __transMat_sqvertex_ref = new NyARDoublePoint2d[4];
+ private final NyARDoublePoint2d[] __transMat_vertex_2d = NyARDoublePoint2d.createArray(4);
+ private final NyARDoublePoint3d[] __transMat_vertex_3d = NyARDoublePoint3d.createArray(4);
+ private final NyARLinear[] __transMat_linear_ref=new NyARLinear[4];
+ private final NyARDoublePoint3d __transMat_trans=new NyARDoublePoint3d();
+ /**
+ * double arGetTransMat( ARMarkerInfo *marker_info,double center[2], double width, double conv[3][4] )
+ *
+ * @param i_square
+ * 計算対象のNyARSquareオブジェクト
+ * @param i_direction
+ * @param i_width
+ * @return
+ * @throws NyARException
+ */
+ public void transMat(final NyARSquare i_square, int i_direction, double i_width, NyARTransMatResult o_result_conv) throws NyARException
+ {
+ final NyARDoublePoint2d[] sqvertex_ref = __transMat_sqvertex_ref;
+ final NyARLinear[] linear_ref=__transMat_linear_ref;
+ final NyARDoublePoint3d trans=this.__transMat_trans;
+
+ //計算用に頂点情報を初期化(順番調整)
+ initVertexOrder(i_square, i_direction, sqvertex_ref,linear_ref);
+
+ //平行移動量計算機に、2D座標系をセット
+ NyARDoublePoint2d[] vertex_2d=this.__transMat_vertex_2d;
+ NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;
+ this._ref_dist_factor.ideal2ObservBatch(sqvertex_ref, vertex_2d,4);
+ this._transsolver.set2dVertex(vertex_2d,4);
+
+ //基準矩形の3D座標系を作成
+ this._offset.setSquare(i_width,this._center);
+
+ //回転行列を計算
+ this._rotmatrix.initRotBySquare(linear_ref,sqvertex_ref);
+
+ //回転後の3D座標系から、平行移動量を計算
+ this._rotmatrix.getPoint3dBatch(this._offset.vertex,vertex_3d,4);
+ this._transsolver.solveTransportVector(vertex_3d,trans);
+
+ //計算結果の最適化(平行移動量と回転行列の最適化)
+ this.optimize(this._rotmatrix, trans, this._transsolver,this._offset.vertex, vertex_2d);
+
+ // マトリクスの保存
+ this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);
+ return;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see jp.nyatla.nyartoolkit.core.transmat.INyARTransMat#transMatContinue(jp.nyatla.nyartoolkit.core.NyARSquare, int, double, jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult)
+ */
+ public void transMatContinue(NyARSquare i_square, int i_direction, double i_width, NyARTransMatResult o_result_conv) throws NyARException
+ {
+ final NyARDoublePoint2d[] sqvertex_ref = __transMat_sqvertex_ref;
+ final NyARLinear[] linear_ref=__transMat_linear_ref;
+ final NyARDoublePoint3d trans=this.__transMat_trans;
+
+ // io_result_convが初期値なら、transMatで計算する。
+ if (!o_result_conv.has_value) {
+ this.transMat(i_square, i_direction, i_width, o_result_conv);
+ return;
+ }
+
+ //計算用に頂点情報を初期化(順番調整)
+ initVertexOrder(i_square, i_direction, sqvertex_ref,linear_ref);
+
+
+ //平行移動量計算機に、2D座標系をセット
+ NyARDoublePoint2d[] vertex_2d=this.__transMat_vertex_2d;
+ NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;
+ this._ref_dist_factor.ideal2ObservBatch(sqvertex_ref, vertex_2d,4);
+ this._transsolver.set2dVertex(vertex_2d,4);
+
+ //基準矩形の3D座標系を作成
+ this._offset.setSquare(i_width,this._center);
+
+ //回転行列を計算
+ this._rotmatrix.initRotByPrevResult(o_result_conv);
+
+ //回転後の3D座標系から、平行移動量を計算
+ this._rotmatrix.getPoint3dBatch(this._offset.vertex,vertex_3d,4);
+ this._transsolver.solveTransportVector(vertex_3d,trans);
+
+ //計算結果の最適化(平行移動量と回転行列の最適化)
+ double err=this.optimize(this._rotmatrix, trans, this._transsolver, this._offset.vertex, vertex_2d);
+
+ // マトリクスの保存
+ this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);
+
+ // エラー値が許容範囲でなければTransMatをやり直し
+ if (err > AR_GET_TRANS_CONT_MAT_MAX_FIT_ERROR) {
+ // rotationを矩形情報で初期化
+ this._rotmatrix.initRotBySquare(linear_ref,sqvertex_ref);
+ //回転行列の平行移動量の計算
+ this._rotmatrix.getPoint3dBatch(this._offset.vertex,vertex_3d,4);
+ this._transsolver.solveTransportVector(vertex_3d,trans);
+ //計算結果の最適化(this._rotmatrix,trans)
+ final double err2=this.optimize(this._rotmatrix, trans, this._transsolver, this._offset.vertex, vertex_2d);
+ //エラー値が低かったら値を差換え
+ if (err2 < err) {
+ // 良い値が取れたら、差換え
+ this.updateMatrixValue(this._rotmatrix, this._offset.point, trans,o_result_conv);
+ }
+ }
+ return;
+ }
+ private double optimize(NyARRotMatrix_ARToolKit io_rotmat,NyARDoublePoint3d io_transvec,INyARTransportVectorSolver i_solver,NyARDoublePoint3d[] i_offset_3d,NyARDoublePoint2d[] i_2d_vertex) throws NyARException
+ {
+ NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;
+ double err = -1;
+ // ループを抜けるタイミングをARToolKitと合わせるために変なことしてます。
+ for (int i = 0;; i++) {
+ // <arGetTransMat3>
+ err = this._mat_optimize.modifyMatrix(io_rotmat, io_transvec, i_offset_3d, i_2d_vertex);
+ io_rotmat.getPoint3dBatch(i_offset_3d,vertex_3d,4);
+ i_solver.solveTransportVector(vertex_3d, io_transvec);
+
+ err = this._mat_optimize.modifyMatrix(io_rotmat, io_transvec, i_offset_3d, i_2d_vertex);
+ // //</arGetTransMat3>
+ if (err < AR_GET_TRANS_MAT_MAX_FIT_ERROR || i == AR_GET_TRANS_MAT_MAX_LOOP_COUNT - 1) {
+ break;
+ }
+ io_rotmat.getPoint3dBatch(i_offset_3d,vertex_3d,4);
+ i_solver.solveTransportVector(vertex_3d, io_transvec);
+ }
+ return err;
+ }
+ /**
+ * パラメータで変換行列を更新します。
+ *
+ * @param i_rot
+ * @param i_off
+ * @param i_trans
+ */
+ public void updateMatrixValue(NyARRotMatrix i_rot, NyARDoublePoint3d i_off, NyARDoublePoint3d i_trans,NyARTransMatResult o_result)
+ {
+ o_result.m00=i_rot.m00;
+ o_result.m01=i_rot.m01;
+ o_result.m02=i_rot.m02;
+ o_result.m03=i_rot.m00 * i_off.x + i_rot.m01 * i_off.y + i_rot.m02 * i_off.z + i_trans.x;
+
+ o_result.m10 = i_rot.m10;
+ o_result.m11 = i_rot.m11;
+ o_result.m12 = i_rot.m12;
+ o_result.m13 = i_rot.m10 * i_off.x + i_rot.m11 * i_off.y + i_rot.m12 * i_off.z + i_trans.y;
+
+ o_result.m20 = i_rot.m20;
+ o_result.m21 = i_rot.m21;
+ o_result.m22 = i_rot.m22;
+ o_result.m23 = i_rot.m20 * i_off.x + i_rot.m21 * i_off.y + i_rot.m22 * i_off.z + i_trans.z;
+
+ o_result.has_value = true;
+ return;
+ }
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/INyARTransMat.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/INyARTransMat.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/transmat/INyARTransMat.java (revision 302)
@@ -7,32 +7,31 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.transmat;

import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.NyARSquare;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;


/**
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARMat.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARMat.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARMat.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_O1.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_O1.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_O1.java (revision 302)
@@ -7,37 +7,35 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.pickup;

import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.NyARMat;
-import jp.nyatla.nyartoolkit.core.NyARSquare;
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
import jp.nyatla.nyartoolkit.core.rasterreader.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
import jp.nyatla.nyartoolkit.core.types.*;
-import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
/**
* 24ビットカラーのマーカーを保持するために使うクラスです。 このクラスは、ARToolkitのパターンと、ラスタから取得したパターンを保持します。
* 演算順序以外の最適化をしたもの
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_O3.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_O3.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_O3.java (revision 302)
@@ -7,35 +7,34 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.pickup;

import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.NyARMat;
-import jp.nyatla.nyartoolkit.core.NyARSquare;
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
import jp.nyatla.nyartoolkit.core.rasterreader.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
import jp.nyatla.nyartoolkit.core.types.*;
/**
* 24ビットカラーのマーカーを保持するために使うクラスです。 このクラスは、ARToolkitのパターンと、ラスタから取得したパターンを保持します。
@@ -212,6 +211,8 @@
this.__updateExtpat_xw=new double[i_xdiv];
this.__updateExtpat_yw=new double[i_ydiv];
this.__updateExtpat_rgbset=new int[i_xdiv*i_ydiv*3];
+ this._last_pix_resolution_x=i_xdiv;
+ this._last_pix_resolution_y=i_ydiv;
}
return;
}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_PseudoAffine.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_PseudoAffine.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_PseudoAffine.java (revision 302)
@@ -1,40 +1,39 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.pickup;


import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.NyARSquare;
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
import jp.nyatla.nyartoolkit.core.rasterreader.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.core.types.matrix.*;
-import jp.nyatla.nyartoolkit.core.utils.NyARDoubleMatrixProcessor;


+
/**
* 疑似アフィン変換を使用して、ラスタ上の四角形から任意解像度
* の矩形パターンを作成します。
@@ -101,7 +100,7 @@
mat.m31=0;
mat.m32=i_height-1;
mat.m33=1.0;
- NyARDoubleMatrixProcessor.inverse(mat,mat);
+ mat.inverse(mat);
return;
}

Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/INyARColorPatt.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/INyARColorPatt.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/INyARColorPatt.java (revision 302)
@@ -7,33 +7,32 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.pickup;

import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.NyARSquare;
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;

public interface INyARColorPatt extends INyARRgbRaster
{
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_Perspective.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_Perspective.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_Perspective.java (revision 302)
@@ -1,40 +1,33 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.pickup;

import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.NyARSquare;
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
import jp.nyatla.nyartoolkit.core.rasterreader.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.nyartoolkit.core.utils.NyARPerspectiveParamGenerator_O1;

@@ -46,30 +39,38 @@
*/
public class NyARColorPatt_Perspective implements INyARColorPatt
{
- private int[] _patdata;
- private NyARBufferReader _buf_reader;
+ protected int[] _patdata;
+ protected NyARIntPoint2d _pickup_lt=new NyARIntPoint2d();
+ protected int _resolution;
+ protected NyARBufferReader _buf_reader;
+ protected NyARIntSize _size;
+ protected NyARPerspectiveParamGenerator_O1 _perspective_gen;
private NyARRgbPixelReader_INT1D_X8R8G8B8_32 _pixelreader;
- private NyARIntSize _size;
- NyARPerspectiveParamGenerator_O1 _perspective_gen;
private static final int LOCAL_LT=1;
- private NyARIntPoint2d _pickup_lt=new NyARIntPoint2d();
+
+ private void initializeInstance(int i_width, int i_height,int i_point_per_pix)
+ {
+ assert i_width>2 && i_height>2;
+ this._resolution=i_point_per_pix;
+ this._size=new NyARIntSize(i_width,i_height);
+ this._patdata = new int[i_height*i_width];
+ this._buf_reader=new NyARBufferReader(this._patdata,NyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32);
+ this._pixelreader=new NyARRgbPixelReader_INT1D_X8R8G8B8_32(this._patdata,this._size);
+ return;
+ }
/**
* 例えば、64
* @param i_width
* 取得画像の解像度幅
* @param i_height
* 取得画像の解像度高さ
+ * @param i_point_per_pix
+ * 1ピクセルあたりの縦横サンプリング数。2なら2x2=4ポイントをサンプリングする。
*/
- public NyARColorPatt_Perspective(int i_width, int i_height)
+ public NyARColorPatt_Perspective(int i_width, int i_height,int i_point_per_pix)
{
- //入力制限
- assert i_width>2 && i_height>2;
-
- this._size=new NyARIntSize(i_width,i_height);
- this._patdata = new int[i_height*i_width];
- this._buf_reader=new NyARBufferReader(this._patdata,NyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32);
- this._pixelreader=new NyARRgbPixelReader_INT1D_X8R8G8B8_32(this._patdata,this._size);
- setEdgeSize(0,0);
+ initializeInstance(i_width,i_height,i_point_per_pix);
+ setEdgeSize(0,0,i_point_per_pix);
return;
}
/**
@@ -81,16 +82,11 @@
* @param i_edge_percentage
* エッジ幅の割合(ARToolKit標準と同じなら、25)
*/
- public NyARColorPatt_Perspective(int i_width, int i_height,int i_edge_percentage)
+ public NyARColorPatt_Perspective(int i_width, int i_height,int i_resolution,int i_edge_percentage)
{
//入力制限
- assert i_width>2 && i_height>2;
-
- this._size=new NyARIntSize(i_width,i_height);
- this._patdata = new int[i_height*i_width];
- this._buf_reader=new NyARBufferReader(this._patdata,NyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32);
- this._pixelreader=new NyARRgbPixelReader_INT1D_X8R8G8B8_32(this._patdata,this._size);
- setEdgeSizeByPercent(i_edge_percentage,i_edge_percentage);
+ initializeInstance(i_width,i_height,i_resolution);
+ setEdgeSizeByPercent(i_edge_percentage,i_edge_percentage,i_resolution);
return;
}
/**
@@ -104,22 +100,25 @@
* @param i_x_edge
* @param i_y_edge
*/
- public void setEdgeSize(int i_x_edge,int i_y_edge)
+ public void setEdgeSize(int i_x_edge,int i_y_edge,int i_resolution)
{
assert(i_x_edge>=0);
assert(i_y_edge>=0);
//Perspectiveパラメタ計算器を作成
- this._perspective_gen=new NyARPerspectiveParamGenerator_O1(LOCAL_LT,LOCAL_LT,i_x_edge*2+this._size.w,i_y_edge*2+this._size.h);
+ this._perspective_gen=new NyARPerspectiveParamGenerator_O1(
+ LOCAL_LT,LOCAL_LT,
+ (i_x_edge*2+this._size.w)*i_resolution,
+ (i_y_edge*2+this._size.h)*i_resolution);
//ピックアップ開始位置を計算
- this._pickup_lt.x=i_x_edge+LOCAL_LT;
- this._pickup_lt.y=i_y_edge+LOCAL_LT;
+ this._pickup_lt.x=i_x_edge*i_resolution+LOCAL_LT;
+ this._pickup_lt.y=i_y_edge*i_resolution+LOCAL_LT;
return;
}
- public void setEdgeSizeByPercent(int i_x_percent,int i_y_percent)
+ public void setEdgeSizeByPercent(int i_x_percent,int i_y_percent,int i_resolution)
{
assert(i_x_percent>=0);
assert(i_y_percent>=0);
- setEdgeSize(this._size.w*i_x_percent/50,this._size.h*i_y_percent/50);
+ setEdgeSize(this._size.w*i_x_percent/50,this._size.h*i_y_percent/50,i_resolution);
return;
}

@@ -145,6 +144,7 @@
return this._pixelreader;
}
private final int[] __pickFromRaster_rgb_tmp = new int[3];
+ protected final double[] __pickFromRaster_cpara=new double[8];
/**
*
* @param image
@@ -155,35 +155,55 @@
public boolean pickFromRaster(INyARRgbRaster image, NyARSquare i_square)throws NyARException
{
//遠近法のパラメータを計算
- double[] cpara = new double[8];
+ final double[] cpara = this.__pickFromRaster_cpara;
if (!this._perspective_gen.getParam(i_square.imvertex, cpara)) {
return false;
}

- int img_x = image.getWidth();
- int img_y = image.getHeight();
+ final int resolution=this._resolution;
+ final int img_x = image.getWidth();
+ final int img_y = image.getHeight();
+ final int res_pix=resolution*resolution;

- int[] rgb_tmp = __pickFromRaster_rgb_tmp;
+ final int[] rgb_tmp = this.__pickFromRaster_rgb_tmp;

//ピクセルリーダーを取得
INyARRgbPixelReader reader=image.getRgbPixelReader();
-
- for(int iy=0;iy<this._size.h;iy++){
- for(int ix=0;ix<this._size.w;ix++){
- //1ピクセルを作成
- int cx=this._pickup_lt.x+ix;
- int cy=this._pickup_lt.y+iy;
- final double d=cpara[6]*cx+cpara[7]*cy+1.0;
- final int x=(int)((cpara[0]*cx+cpara[1]*cy+cpara[2])/d);
- final int y=(int)((cpara[3]*cx+cpara[4]*cy+cpara[5])/d);
- if (x >= 0 && x < img_x && y >= 0 && y < img_y) {
- reader.getPixel(x, y, rgb_tmp);
- this._patdata[iy*this._size.w+ix]=(((rgb_tmp[0])&0xff)<<16)|(((rgb_tmp[1])&0xff)<<8)|(((rgb_tmp[2])&0xff));
+ int p=0;
+ for(int iy=0;iy<this._size.h*resolution;iy+=resolution){
+ //解像度分の点を取る。
+ for(int ix=0;ix<this._size.w*resolution;ix+=resolution){
+ int r,g,b;
+ r=g=b=0;
+ for(int i2y=iy;i2y<iy+resolution;i2y++){
+ int cy=this._pickup_lt.y+i2y;
+ for(int i2x=ix;i2x<ix+resolution;i2x++){
+ //1ピクセルを作成
+ int cx=this._pickup_lt.x+i2x;
+ final double d=cpara[6]*cx+cpara[7]*cy+1.0;
+ int x=(int)((cpara[0]*cx+cpara[1]*cy+cpara[2])/d);
+ int y=(int)((cpara[3]*cx+cpara[4]*cy+cpara[5])/d);
+ if(x<0){x=0;}
+ if(x>=img_x){x=img_x-1;}
+ if(y<0){y=0;}
+ if(y>=img_y){y=img_y-1;}
+
+ reader.getPixel(x, y, rgb_tmp);
+ r+=rgb_tmp[0];
+ g+=rgb_tmp[1];
+ b+=rgb_tmp[2];
+ }
}
+ r/=res_pix;
+ g/=res_pix;
+ b/=res_pix;
+ this._patdata[p]=((r&0xff)<<16)|((g&0xff)<<8)|((b&0xff));
+ p++;
}
+ }
//ピクセル問い合わせ
//ピクセルセット
- }
return true;
- }
+ }
+
}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_Perspective_O2.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_Perspective_O2.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_Perspective_O2.java (revision 302)
@@ -0,0 +1,688 @@
+/*
+ * PROJECT: NyARToolkit(Extension)
+ * --------------------------------------------------------------------------------
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.pickup;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.raster.rgb.*;
+import jp.nyatla.nyartoolkit.core.rasterreader.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.types.*;
+
+
+interface IpickFromRaster_Impl
+{
+ public void pickFromRaster(double[] i_cpara,INyARRgbRaster image, int[] o_patt)throws NyARException;
+}
+
+/**
+ * 汎用ピックアップ関数
+ *
+ */
+class pickFromRaster_N implements IpickFromRaster_Impl
+{
+ protected int _resolution;
+ protected NyARIntSize _size_ref;
+ protected NyARIntPoint2d _lt_ref;
+ public pickFromRaster_N(NyARIntPoint2d i_lt,int i_resolution,NyARIntSize i_source_size)
+ {
+ this._lt_ref=i_lt;
+ this._resolution=i_resolution;
+ this._size_ref=i_source_size;
+
+ this._rgb_temp=new int[i_resolution*i_resolution*3];
+ this._rgb_px=new int[i_resolution*i_resolution];
+ this._rgb_py=new int[i_resolution*i_resolution];
+
+ this._cp1cy_cp2=new double[i_resolution];
+ this._cp4cy_cp5=new double[i_resolution];
+ this._cp7cy_1=new double[i_resolution];
+ return;
+ }
+ private int[] _rgb_temp;
+ private int[] _rgb_px;
+ private int[] _rgb_py;
+ private double[] _cp1cy_cp2;
+ private double[] _cp4cy_cp5;
+ private double[] _cp7cy_1;
+
+ public void pickFromRaster(double[] i_cpara,INyARRgbRaster image,int[] o_patt)throws NyARException
+ {
+ int i2x,i2y;//プライム変数
+ int x,y;
+ int w;
+ int r,g,b;
+
+ final int resolution=this._resolution;
+ final int res_pix=resolution*resolution;
+ final int img_x = image.getWidth();
+ final int img_y = image.getHeight();
+
+ final int[] rgb_tmp = this._rgb_temp;
+ final int[] rgb_px=this._rgb_px;
+ final int[] rgb_py=this._rgb_py;
+
+ final double[] cp1cy_cp2=this._cp1cy_cp2;
+ final double[] cp4cy_cp5=this._cp4cy_cp5;
+ final double[] cp7cy_1=this._cp7cy_1;
+
+ final double cp0=i_cpara[0];
+ final double cp3=i_cpara[3];
+ final double cp6=i_cpara[6];
+ final double cp1=i_cpara[1];
+ final double cp2=i_cpara[2];
+ final double cp4=i_cpara[4];
+ final double cp5=i_cpara[5];
+ final double cp7=i_cpara[7];
+
+
+ final int pick_y=this._lt_ref.y;
+ final int pick_x=this._lt_ref.x;
+ //ピクセルリーダーを取得
+ INyARRgbPixelReader reader=image.getRgbPixelReader();
+ int p=0;
+
+
+ for(int iy=0;iy<this._size_ref.h*resolution;iy+=resolution){
+ w=pick_y+iy;
+ cp1cy_cp2[0]=cp1*w+cp2;
+ cp4cy_cp5[0]=cp4*w+cp5;
+ cp7cy_1[0]=cp7*w+1.0;
+ for(i2y=1;i2y<resolution;i2y++){
+ cp1cy_cp2[i2y]=cp1cy_cp2[i2y-1]+cp1;
+ cp4cy_cp5[i2y]=cp4cy_cp5[i2y-1]+cp4;
+ cp7cy_1[i2y]=cp7cy_1[i2y-1]+cp7;
+ }
+ //解像度分の点を取る。
+
+ for(int ix=0;ix<this._size_ref.w*resolution;ix+=resolution){
+ int n=0;
+ w=pick_x+ix;
+ for(i2y=resolution-1;i2y>=0;i2y--){
+ double cp0cx=cp0*w+cp1cy_cp2[i2y];
+ double cp6cx=cp6*w+cp7cy_1[i2y];
+ double cp3cx=cp3*w+cp4cy_cp5[i2y];
+
+ final double m=1/(cp6cx);
+ final double d=-cp6/(cp6cx*(cp6cx+cp6));
+
+ double m2=cp0cx*m;
+ double m3=cp3cx*m;
+ double d2=cp0cx*d+cp0*(m+d);
+ double d3=cp3cx*d+cp3*(m+d);
+ for(i2x=resolution-1;i2x>=0;i2x--){
+ //1ピクセルを作成
+ x=rgb_px[n]=(int)(m2);
+ y=rgb_py[n]=(int)(m3);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[n]=0;}else if(x>=img_x){rgb_px[n]=img_x-1;}
+ if(y<0){rgb_py[n]=0;}else if(y>=img_y){rgb_py[n]=img_y-1;}
+ }
+ n++;
+ m2+=d2;
+ m3+=d3;
+ }
+ }
+ reader.getPixelSet(rgb_px, rgb_py,res_pix, rgb_tmp);
+ r=g=b=0;
+ for(int i=res_pix*3-1;i>0;){
+ b+=rgb_tmp[i--];
+ g+=rgb_tmp[i--];
+ r+=rgb_tmp[i--];
+ }
+ r/=res_pix;
+ g/=res_pix;
+ b/=res_pix;
+ o_patt[p]=((r&0xff)<<16)|((g&0xff)<<8)|((b&0xff));
+ p++;
+ }
+ }
+ return;
+ }
+}
+/**
+ * チェックデジット:4127936236942444153655776299710081208144715171590159116971715177917901890204024192573274828522936312731813388371037714083
+ *
+ */
+class pickFromRaster_1 implements IpickFromRaster_Impl
+{
+ protected NyARIntSize _size_ref;
+ protected NyARIntPoint2d _lt_ref;
+ public pickFromRaster_1(NyARIntPoint2d i_lt,NyARIntSize i_source_size)
+ {
+ this._lt_ref=i_lt;
+ this._size_ref=i_source_size;
+
+ this._rgb_temp=new int[i_source_size.w*3];
+ this._rgb_px=new int[i_source_size.w];
+ this._rgb_py=new int[i_source_size.w];
+
+ return;
+ }
+ private int[] _rgb_temp;
+ private int[] _rgb_px;
+ private int[] _rgb_py;
+
+
+ public void pickFromRaster(double[] i_cpara,INyARRgbRaster image,int[] o_patt)throws NyARException
+ {
+ double d0,m0;
+ int x,y;
+
+ final int img_x = image.getWidth();
+ final int img_y = image.getHeight();
+ final int patt_w=this._size_ref.w;
+
+ final int[] rgb_tmp = this._rgb_temp;
+ final int[] rgb_px=this._rgb_px;
+ final int[] rgb_py=this._rgb_py;
+
+
+
+ final double cp0=i_cpara[0];
+ final double cp3=i_cpara[3];
+ final double cp6=i_cpara[6];
+ final double cp1=i_cpara[1];
+ final double cp4=i_cpara[4];
+ final double cp7=i_cpara[7];
+
+
+ final int pick_y=this._lt_ref.y;
+ final int pick_x=this._lt_ref.x;
+ //ピクセルリーダーを取得
+ INyARRgbPixelReader reader=image.getRgbPixelReader();
+ int p=0;
+
+
+ double cp0cx0,cp3cx0;
+ double cp1cy_cp20=cp1*pick_y+i_cpara[2]+cp0*pick_x;
+ double cp4cy_cp50=cp4*pick_y+i_cpara[5]+cp3*pick_x;
+ double cp7cy_10=cp7*pick_y+1.0+cp6*pick_x;
+
+
+ for(int iy=this._size_ref.h-1;iy>=0;iy--){
+ m0=1/(cp7cy_10);
+ d0=-cp6/(cp7cy_10*(cp7cy_10+cp6));
+
+ cp0cx0=cp1cy_cp20;
+ cp3cx0=cp4cy_cp50;
+
+ //ピックアップシーケンス
+
+ //0番目のピクセル(検査対象)をピックアップ
+
+
+ for(int ix=patt_w-1;ix>=0;ix--){
+ //1ピクセルを作成
+ x=rgb_px[ix]=(int)(cp0cx0*m0);
+ y=rgb_py[ix]=(int)(cp3cx0*m0);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[ix]=0;}else if(x>=img_x){rgb_px[ix]=img_x-1;}
+ if(y<0){rgb_py[ix]=0;}else if(y>=img_y){rgb_py[ix]=img_y-1;}
+ }
+ cp0cx0+=cp0;
+ cp3cx0+=cp3;
+ m0+=d0;
+ }
+
+ cp1cy_cp20+=cp1;
+ cp4cy_cp50+=cp4;
+ cp7cy_10+=cp7;
+
+ reader.getPixelSet(rgb_px, rgb_py,patt_w, rgb_tmp);
+ for(int ix=patt_w-1;ix>=0;ix--){
+ final int idx=ix*3;
+ o_patt[p]=(rgb_tmp[idx]<<16)|(rgb_tmp[idx+1]<<8)|((rgb_tmp[idx+2]&0xff));
+ p++;
+ }
+ }
+
+ return;
+ }
+}
+
+/**
+ * 2x2
+ * チェックデジット:207585881161241401501892422483163713744114324414474655086016467027227327958629279571017
+ *
+ */
+class pickFromRaster_2x implements IpickFromRaster_Impl
+{
+ protected NyARIntSize _size_ref;
+ protected NyARIntPoint2d _lt_ref;
+ public pickFromRaster_2x(NyARIntPoint2d i_lt,NyARIntSize i_source_size)
+ {
+ this._lt_ref=i_lt;
+ this._size_ref=i_source_size;
+
+ this._rgb_temp=new int[i_source_size.w*4*3];
+ this._rgb_px=new int[i_source_size.w*4];
+ this._rgb_py=new int[i_source_size.w*4];
+
+
+ return;
+ }
+ private int[] _rgb_temp;
+ private int[] _rgb_px;
+ private int[] _rgb_py;
+
+
+ public void pickFromRaster(double[] i_cpara,INyARRgbRaster image,int[] o_patt)throws NyARException
+ {
+ double d0,m0,d1,m1;
+ int x,y;
+
+ final int img_x = image.getWidth();
+ final int img_y = image.getHeight();
+ final int patt_w=this._size_ref.w;
+
+ final int[] rgb_tmp = this._rgb_temp;
+ final int[] rgb_px=this._rgb_px;
+ final int[] rgb_py=this._rgb_py;
+
+
+
+ final double cp0=i_cpara[0];
+ final double cp3=i_cpara[3];
+ final double cp6=i_cpara[6];
+ final double cp1=i_cpara[1];
+ final double cp4=i_cpara[4];
+ final double cp7=i_cpara[7];
+
+
+ final int pick_y=this._lt_ref.y;
+ final int pick_x=this._lt_ref.x;
+ //ピクセルリーダーを取得
+ INyARRgbPixelReader reader=image.getRgbPixelReader();
+ int p=0;
+
+
+ double cp0cx0,cp3cx0;
+ double cp1cy_cp20=cp1*pick_y+i_cpara[2]+cp0*pick_x;
+ double cp4cy_cp50=cp4*pick_y+i_cpara[5]+cp3*pick_x;
+ double cp7cy_10=cp7*pick_y+1.0+cp6*pick_x;
+
+
+ double cp0cx1,cp3cx1;
+ double cp1cy_cp21=cp1cy_cp20+cp1;
+ double cp4cy_cp51=cp4cy_cp50+cp4;
+ double cp7cy_11=cp7cy_10+cp7;
+
+ double cw0=cp1+cp1;
+ double cw7=cp7+cp7;
+ double cw4=cp4+cp4;
+
+ for(int iy=this._size_ref.h-1;iy>=0;iy--){
+ cp0cx0=cp1cy_cp20;
+ cp3cx0=cp4cy_cp50;
+ cp0cx1=cp1cy_cp21;
+ cp3cx1=cp4cy_cp51;
+
+ m0=1/(cp7cy_10);
+ d0=-cp6/(cp7cy_10*(cp7cy_10+cp6));
+ m1=1/(cp7cy_11);
+ d1=-cp6/(cp7cy_11*(cp7cy_11+cp6));
+
+ int n=patt_w*2*2-1;
+
+ for(int ix=patt_w*2-1;ix>=0;ix--){
+ //[n,0]
+ x=rgb_px[n]=(int)(cp0cx0*m0);
+ y=rgb_py[n]=(int)(cp3cx0*m0);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[n]=0;}else if(x>=img_x){rgb_px[n]=img_x-1;}
+ if(y<0){rgb_py[n]=0;}else if(y>=img_y){rgb_py[n]=img_y-1;}
+ }
+ cp0cx0+=cp0;
+ cp3cx0+=cp3;
+ m0+=d0;
+ n--;
+ //[n,1]
+ x=rgb_px[n]=(int)(cp0cx1*m1);
+ y=rgb_py[n]=(int)(cp3cx1*m1);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[n]=0;}else if(x>=img_x){rgb_px[n]=img_x-1;}
+ if(y<0){rgb_py[n]=0;}else if(y>=img_y){rgb_py[n]=img_y-1;}
+ }
+ cp0cx1+=cp0;
+ cp3cx1+=cp3;
+ m1+=d1;
+ n--;
+ }
+ cp7cy_10+=cw7;
+ cp7cy_11+=cw7;
+
+ cp1cy_cp20+=cw0;
+ cp4cy_cp50+=cw4;
+ cp1cy_cp21+=cw0;
+ cp4cy_cp51+=cw4;
+
+
+
+ reader.getPixelSet(rgb_px, rgb_py,patt_w*4, rgb_tmp);
+ for(int ix=patt_w-1;ix>=0;ix--){
+ final int idx=ix*12;//3*2*2
+ final int r=(rgb_tmp[idx+0]+rgb_tmp[idx+3]+rgb_tmp[idx+6]+rgb_tmp[idx+ 9])/4;
+ final int g=(rgb_tmp[idx+1]+rgb_tmp[idx+4]+rgb_tmp[idx+7]+rgb_tmp[idx+10])/4;
+ final int b=(rgb_tmp[idx+2]+rgb_tmp[idx+5]+rgb_tmp[idx+8]+rgb_tmp[idx+11])/4;
+ o_patt[p]=(r<<16)|(g<<8)|((b&0xff));
+ p++;
+ }
+ }
+
+ return;
+ }
+}
+
+/**
+ * 4x4
+ *
+ */
+class pickFromRaster_4x implements IpickFromRaster_Impl
+{
+ protected NyARIntSize _size_ref;
+ protected NyARIntPoint2d _lt_ref;
+ public pickFromRaster_4x(NyARIntPoint2d i_lt,NyARIntSize i_source_size)
+ {
+ this._lt_ref=i_lt;
+ this._size_ref=i_source_size;
+
+ this._rgb_temp=new int[4*4*3];
+ this._rgb_px=new int[4*4];
+ this._rgb_py=new int[4*4];
+ return;
+ }
+ private int[] _rgb_temp;
+ private int[] _rgb_px;
+ private int[] _rgb_py;
+
+ public void pickFromRaster(double[] i_cpara,INyARRgbRaster image,int[] o_patt)throws NyARException
+ {
+ int x,y;
+ double d,m;
+ double cp6cx,cp0cx,cp3cx;
+ final int[] rgb_px=this._rgb_px;
+ final int[] rgb_py=this._rgb_py;
+
+ int r,g,b;
+ //遠近法のパラメータを計算
+
+ final int img_x = image.getWidth();
+ final int img_y = image.getHeight();
+ final int[] rgb_tmp = this._rgb_temp;
+ final double cp0=i_cpara[0];
+ final double cp3=i_cpara[3];
+ final double cp6=i_cpara[6];
+ final double cp1=i_cpara[1];
+ final double cp2=i_cpara[2];
+ final double cp4=i_cpara[4];
+ final double cp5=i_cpara[5];
+ final double cp7=i_cpara[7];
+
+
+ final int pick_lt_x=this._lt_ref.x;
+ //ピクセルリーダーを取得
+ INyARRgbPixelReader reader=image.getRgbPixelReader();
+
+
+ int p=0;
+ int py=this._lt_ref.y;
+ for(int iy=this._size_ref.h-1;iy>=0;iy--,py+=4){
+ final double cp1cy_cp2_0=cp1*py+cp2;
+ final double cp4cy_cp5_0=cp4*py+cp5;
+ final double cp7cy_1_0 =cp7*py+1.0;
+
+ final double cp1cy_cp2_1=cp1cy_cp2_0+cp1;
+ final double cp1cy_cp2_2=cp1cy_cp2_1+cp1;
+ final double cp1cy_cp2_3=cp1cy_cp2_2+cp1;
+
+ final double cp4cy_cp5_1=cp4cy_cp5_0+cp4;
+ final double cp4cy_cp5_2=cp4cy_cp5_1+cp4;
+ final double cp4cy_cp5_3=cp4cy_cp5_2+cp4;
+
+ int px=pick_lt_x;
+ //解像度分の点を取る。
+ for(int ix=this._size_ref.w-1;ix>=0;ix--,px+=4){
+
+ cp6cx=cp6*px;
+ cp0cx=cp0*px;
+ cp3cx=cp3*px;
+
+ cp6cx+=cp7cy_1_0;
+ m=1/cp6cx;
+ d=-cp7/((cp6cx+cp7)*cp6cx);
+
+ //1ピクセルを作成[0,0]
+ x=rgb_px[0]=(int)((cp0cx+cp1cy_cp2_0)*m);
+ y=rgb_py[0]=(int)((cp3cx+cp4cy_cp5_0)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[0]=0;}else if(x>=img_x){rgb_px[0]=img_x-1;}
+ if(y<0){rgb_py[0]=0;}else if(y>=img_y){rgb_py[0]=img_y-1;}
+ }
+
+ //1ピクセルを作成[0,1]
+ m+=d;
+ x=rgb_px[4]=(int)((cp0cx+cp1cy_cp2_1)*m);
+ y=rgb_py[4]=(int)((cp3cx+cp4cy_cp5_1)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[4]=0;}else if(x>=img_x){rgb_px[4]=img_x-1;}
+ if(y<0){rgb_py[4]=0;}else if(y>=img_y){rgb_py[4]=img_y-1;}
+ }
+ //1ピクセルを作成[0,2]
+ m+=d;
+ x=rgb_px[8]=(int)((cp0cx+cp1cy_cp2_2)*m);
+ y=rgb_py[8]=(int)((cp3cx+cp4cy_cp5_2)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[8]=0;}else if(x>=img_x){rgb_px[8]=img_x-1;}
+ if(y<0){rgb_py[8]=0;}else if(y>=img_y){rgb_py[8]=img_y-1;}
+ }
+
+ //1ピクセルを作成[0,3]
+ m+=d;
+ x=rgb_px[12]=(int)((cp0cx+cp1cy_cp2_3)*m);
+ y=rgb_py[12]=(int)((cp3cx+cp4cy_cp5_3)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[12]=0;}else if(x>=img_x){rgb_px[12]=img_x-1;}
+ if(y<0){rgb_py[12]=0;}else if(y>=img_y){rgb_py[12]=img_y-1;}
+ }
+
+ cp6cx+=cp6;
+ cp0cx+=cp0;
+ cp3cx+=cp3;
+
+ m=1/cp6cx;
+ d=-cp7/((cp6cx+cp7)*cp6cx);
+
+ //1ピクセルを作成[1,0]
+ x=rgb_px[1]=(int)((cp0cx+cp1cy_cp2_0)*m);
+ y=rgb_py[1]=(int)((cp3cx+cp4cy_cp5_0)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[1]=0;}else if(x>=img_x){rgb_px[1]=img_x-1;}
+ if(y<0){rgb_py[1]=0;}else if(y>=img_y){rgb_py[1]=img_y-1;}
+ }
+ //1ピクセルを作成[1,1]
+ m+=d;
+ x=rgb_px[5]=(int)((cp0cx+cp1cy_cp2_1)*m);
+ y=rgb_py[5]=(int)((cp3cx+cp4cy_cp5_1)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[5]=0;}else if(x>=img_x){rgb_px[5]=img_x-1;}
+ if(y<0){rgb_py[5]=0;}else if(y>=img_y){rgb_py[5]=img_y-1;}
+ }
+ //1ピクセルを作成[1,2]
+ m+=d;
+ x=rgb_px[9]=(int)((cp0cx+cp1cy_cp2_2)*m);
+ y=rgb_py[9]=(int)((cp3cx+cp4cy_cp5_2)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[9]=0;}else if(x>=img_x){rgb_px[9]=img_x-1;}
+ if(y<0){rgb_py[9]=0;}else if(y>=img_y){rgb_py[9]=img_y-1;}
+ }
+ //1ピクセルを作成[1,3]
+ m+=d;
+ x=rgb_px[13]=(int)((cp0cx+cp1cy_cp2_3)*m);
+ y=rgb_py[13]=(int)((cp3cx+cp4cy_cp5_3)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[13]=0;}else if(x>=img_x){rgb_px[13]=img_x-1;}
+ if(y<0){rgb_py[13]=0;}else if(y>=img_y){rgb_py[13]=img_y-1;}
+ }
+
+ cp6cx+=cp6;
+ cp0cx+=cp0;
+ cp3cx+=cp3;
+
+ m=1/cp6cx;
+ d=-cp7/((cp6cx+cp7)*cp6cx);
+
+ //1ピクセルを作成[2,0]
+ x=rgb_px[2]=(int)((cp0cx+cp1cy_cp2_0)*m);
+ y=rgb_py[2]=(int)((cp3cx+cp4cy_cp5_0)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[2]=0;}else if(x>=img_x){rgb_px[2]=img_x-1;}
+ if(y<0){rgb_py[2]=0;}else if(y>=img_y){rgb_py[2]=img_y-1;}
+ }
+ //1ピクセルを作成[2,1]
+ m+=d;
+ x=rgb_px[6]=(int)((cp0cx+cp1cy_cp2_1)*m);
+ y=rgb_py[6]=(int)((cp3cx+cp4cy_cp5_1)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[6]=0;}else if(x>=img_x){rgb_px[6]=img_x-1;}
+ if(y<0){rgb_py[6]=0;}else if(y>=img_y){rgb_py[6]=img_y-1;}
+ }
+ //1ピクセルを作成[2,2]
+ m+=d;
+ x=rgb_px[10]=(int)((cp0cx+cp1cy_cp2_2)*m);
+ y=rgb_py[10]=(int)((cp3cx+cp4cy_cp5_2)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[10]=0;}else if(x>=img_x){rgb_px[10]=img_x-1;}
+ if(y<0){rgb_py[10]=0;}else if(y>=img_y){rgb_py[10]=img_y-1;}
+ }
+ //1ピクセルを作成[2,3](ここ計算ずれします。)
+ m+=d;
+ x=rgb_px[14]=(int)((cp0cx+cp1cy_cp2_3)*m);
+ y=rgb_py[14]=(int)((cp3cx+cp4cy_cp5_3)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[14]=0;}else if(x>=img_x){rgb_px[14]=img_x-1;}
+ if(y<0){rgb_py[14]=0;}else if(y>=img_y){rgb_py[14]=img_y-1;}
+ }
+ cp6cx+=cp6;
+ cp0cx+=cp0;
+ cp3cx+=cp3;
+
+ m=1/cp6cx;
+ d=-cp7/((cp6cx+cp7)*cp6cx);
+
+ //1ピクセルを作成[3,0]
+ x=rgb_px[3]=(int)((cp0cx+cp1cy_cp2_0)*m);
+ y=rgb_py[3]=(int)((cp3cx+cp4cy_cp5_0)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[3]=0;}else if(x>=img_x){rgb_px[3]=img_x-1;}
+ if(y<0){rgb_py[3]=0;}else if(y>=img_y){rgb_py[3]=img_y-1;}
+ }
+ //1ピクセルを作成[3,1]
+ m+=d;
+ x=rgb_px[7]=(int)((cp0cx+cp1cy_cp2_1)*m);
+ y=rgb_py[7]=(int)((cp3cx+cp4cy_cp5_1)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[7]=0;}else if(x>=img_x){rgb_px[7]=img_x-1;}
+ if(y<0){rgb_py[7]=0;}else if(y>=img_y){rgb_py[7]=img_y-1;}
+ }
+ //1ピクセルを作成[3,2]
+ m+=d;
+ x=rgb_px[11]=(int)((cp0cx+cp1cy_cp2_2)*m);
+ y=rgb_py[11]=(int)((cp3cx+cp4cy_cp5_2)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[11]=0;}else if(x>=img_x){rgb_px[11]=img_x-1;}
+ if(y<0){rgb_py[11]=0;}else if(y>=img_y){rgb_py[11]=img_y-1;}
+ }
+ //1ピクセルを作成[3,3]
+ m+=d;
+ x=rgb_px[15]=(int)((cp0cx+cp1cy_cp2_3)*m);
+ y=rgb_py[15]=(int)((cp3cx+cp4cy_cp5_3)*m);
+ if(x<0||x>=img_x||y<0||y>=img_y){
+ if(x<0){rgb_px[15]=0;}else if(x>=img_x){rgb_px[15]=img_x-1;}
+ if(y<0){rgb_py[15]=0;}else if(y>=img_y){rgb_py[15]=img_y-1;}
+ }
+
+ reader.getPixelSet(rgb_px, rgb_py,4*4, rgb_tmp);
+
+ r=(rgb_tmp[ 0]+rgb_tmp[ 3]+rgb_tmp[ 6]+rgb_tmp[ 9]+rgb_tmp[12]+rgb_tmp[15]+rgb_tmp[18]+rgb_tmp[21]+rgb_tmp[24]+rgb_tmp[27]+rgb_tmp[30]+rgb_tmp[33]+rgb_tmp[36]+rgb_tmp[39]+rgb_tmp[42]+rgb_tmp[45])/16;
+ g=(rgb_tmp[ 1]+rgb_tmp[ 4]+rgb_tmp[ 7]+rgb_tmp[10]+rgb_tmp[13]+rgb_tmp[16]+rgb_tmp[19]+rgb_tmp[22]+rgb_tmp[25]+rgb_tmp[28]+rgb_tmp[31]+rgb_tmp[34]+rgb_tmp[37]+rgb_tmp[40]+rgb_tmp[43]+rgb_tmp[46])/16;
+ b=(rgb_tmp[ 2]+rgb_tmp[ 5]+rgb_tmp[ 8]+rgb_tmp[11]+rgb_tmp[14]+rgb_tmp[17]+rgb_tmp[20]+rgb_tmp[23]+rgb_tmp[26]+rgb_tmp[29]+rgb_tmp[32]+rgb_tmp[35]+rgb_tmp[38]+rgb_tmp[41]+rgb_tmp[44]+rgb_tmp[47])/16;
+ o_patt[p]=((r&0xff)<<16)|((g&0xff)<<8)|((b&0xff));
+ p++;
+
+ }
+ }
+ return;
+ }
+}
+
+
+
+
+
+
+
+
+
+/**
+ * 遠近法を使ったパースペクティブ補正をかけて、ラスタ上の四角形から
+ * 任意解像度の矩形パターンを作成します。
+ *
+ */
+public class NyARColorPatt_Perspective_O2 extends NyARColorPatt_Perspective
+{
+ private IpickFromRaster_Impl _pickup;
+ public NyARColorPatt_Perspective_O2(int i_width, int i_height,int i_resolution,int i_edge_percentage)
+ {
+ super(i_width,i_height,i_resolution,i_edge_percentage);
+ switch(i_resolution){
+ case 1:
+ this._pickup=new pickFromRaster_1(this._pickup_lt,this._size);
+ break;
+ case 2:
+ this._pickup=new pickFromRaster_2x(this._pickup_lt,this._size);
+ break;
+ case 4:
+ this._pickup=new pickFromRaster_4x(this._pickup_lt,this._size);
+ break;
+ default:
+ this._pickup=new pickFromRaster_N(this._pickup_lt,i_resolution,this._size);
+ }
+ return;
+ }
+
+ public boolean pickFromRaster(INyARRgbRaster image, NyARSquare i_square)throws NyARException
+ {
+ //遠近法のパラメータを計算
+ final double[] cpara = this.__pickFromRaster_cpara;
+ if (!this._perspective_gen.getParam(i_square.imvertex, cpara)) {
+ return false;
+ }
+ this._pickup.pickFromRaster(cpara, image,this._patdata);
+ return true;
+ }
+
+}
+
+
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java (revision 302)
@@ -7,32 +7,32 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.match;

import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;

/**
* AR_TEMPLATE_MATCHING_COLORかつAR_MATCHING_WITHOUT_PCAと同等のルールで マーカーを評価します。
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/INyARMatchPatt.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/INyARMatchPatt.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/INyARMatchPatt.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.match;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattDeviationBlackWhiteData.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattDeviationBlackWhiteData.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattDeviationBlackWhiteData.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.match;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattDeviationColorData.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattDeviationColorData.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattDeviationColorData.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.match;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java (revision 302)
@@ -7,33 +7,32 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.match;

import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.NyARCode;
-import jp.nyatla.nyartoolkit.core.NyARSquare;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;

/**
* AR_TEMPLATE_MATCHING_COLORかつAR_MATCHING_WITH_PCAと同等のルールで マーカーを評価します。
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java (revision 302)
@@ -7,32 +7,32 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.match;

import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;

/**
* AR_TEMPLATE_MATCHING_BWと同等のルールで マーカを評価します。
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattResult.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattResult.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattResult.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.match;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARVersion.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARVersion.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/NyARVersion.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/NyARCameraDistortionFactor.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/NyARCameraDistortionFactor.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/NyARCameraDistortionFactor.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.param;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/NyARPerspectiveProjectionMatrix.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/NyARPerspectiveProjectionMatrix.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/NyARPerspectiveProjectionMatrix.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.param;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/INyARCameraDistortionFactor.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/INyARCameraDistortionFactor.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/INyARCameraDistortionFactor.java (revision 302)
@@ -1,3 +1,33 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
package jp.nyatla.nyartoolkit.core.param;

import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/NyARObserv2IdealMap.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/NyARObserv2IdealMap.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/NyARObserv2IdealMap.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.param;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/NyARParam.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/NyARParam.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/param/NyARParam.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.param;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_BasicClass.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_BasicClass.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_BasicClass.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.raster;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/INyARRaster.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/INyARRaster.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/INyARRaster.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.raster;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.raster;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARGrayscaleRaster.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARGrayscaleRaster.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARGrayscaleRaster.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.raster;
@@ -45,7 +44,7 @@
{
super(new NyARIntSize(i_width,i_height));
this._ref_buf = new int[i_height*i_width];
- this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8);
+ this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8);
}
public INyARBufferReader getBufferReader()
{
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.raster;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_RGB.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_RGB.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_RGB.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.raster.rgb;
@@ -46,12 +45,12 @@
return new NyARRgbRaster_RGB(i_buffer, i_width, i_height);
}

- private NyARRgbRaster_RGB(byte[] i_buffer, int i_width, int i_height)
+ private NyARRgbRaster_RGB(byte[] i_ref_buffer, int i_width, int i_height)
{
super(new NyARIntSize(i_width,i_height));
- this._ref_buf = i_buffer;
- this._reader = new NyARRgbPixelReader_RGB24(i_buffer, this._size);
- this._buffer_reader=new NyARBufferReader(i_buffer,INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24);
+ this._ref_buf = i_ref_buffer;
+ this._reader = new NyARRgbPixelReader_RGB24(i_ref_buffer, this._size);
+ this._buffer_reader=new NyARBufferReader(i_ref_buffer,INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24);
return;
}
public INyARRgbPixelReader getRgbPixelReader()
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_BGRA.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_BGRA.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_BGRA.java (revision 302)
@@ -7,30 +7,30 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.raster.rgb;

+import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.rasterreader.*;
import jp.nyatla.nyartoolkit.core.types.*;

@@ -68,6 +68,19 @@
}
return;
}
+ public void setPixel(int i_x, int i_y, int[] i_rgb) throws NyARException
+ {
+ final byte[] ref_buf = this._parent._ref_buf;
+ final int bp = (i_x + i_y * this._parent._size.w) * 4;
+ ref_buf[bp+0] = (byte)i_rgb[0];// R
+ ref_buf[bp+1] = (byte)i_rgb[1];// G
+ ref_buf[bp+2] = (byte)i_rgb[2];// B
+ }
+ public void setPixels(int[] i_x, int[] i_y, int i_num, int[] i_intrgb) throws NyARException
+ {
+ NyARException.notImplement();
+ }
+
}

private INyARRgbPixelReader _rgb_reader;
@@ -79,12 +92,12 @@
return new NyARRgbRaster_BGRA(i_buffer, i_width, i_height);
}

- private NyARRgbRaster_BGRA(byte[] i_buffer, int i_width, int i_height)
+ private NyARRgbRaster_BGRA(byte[] i_ref_buffer, int i_width, int i_height)
{
super(new NyARIntSize(i_width,i_height));
- this._ref_buf = i_buffer;
+ this._ref_buf = i_ref_buffer;
this._rgb_reader = new PixelReader(this);
- this._buffer_reader=new NyARBufferReader(i_buffer,INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32);
+ this._buffer_reader=new NyARBufferReader(i_ref_buffer,INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32);
return;
}
public INyARRgbPixelReader getRgbPixelReader()
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_BasicClass.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_BasicClass.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_BasicClass.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.raster.rgb;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_Blank.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_Blank.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_Blank.java (revision 302)
@@ -7,30 +7,30 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.raster.rgb;

+import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;
import jp.nyatla.nyartoolkit.core.rasterreader.INyARRgbPixelReader;
import jp.nyatla.nyartoolkit.core.rasterreader.NyARBufferReader;
@@ -59,7 +59,16 @@
o_rgb[i * 3 + 1] = 0;// G
o_rgb[i * 3 + 2] = 0;// B
}
- }
+ }
+ public void setPixel(int i_x, int i_y, int[] i_rgb) throws NyARException
+ {
+ NyARException.notImplement();
+ }
+ public void setPixels(int[] i_x, int[] i_y, int i_num, int[] i_intrgb) throws NyARException
+ {
+ NyARException.notImplement();
+ }
+
}

private INyARRgbPixelReader _reader;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/INyARRgbRaster.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/INyARRgbRaster.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/INyARRgbRaster.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.raster.rgb;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyARDoubleMatrixProcessor.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyARDoubleMatrixProcessor.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyARDoubleMatrixProcessor.java (revision 302)
@@ -1,161 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008-2009 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core.utils;
-
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix22;
-import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix33;
-import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix44;
-
-public class NyARDoubleMatrixProcessor
-{
- /**
- * i_srcの逆行列を計算して、thisへ格納します。
- * @param i_src
- * @return
- */
- public static boolean inverse(NyARDoubleMatrix22 i_src,NyARDoubleMatrix22 o_dest)
- {
- final double a11,a12,a21,a22;
- a11=i_src.m00;
- a12=i_src.m01;
- a21=i_src.m10;
- a22=i_src.m11;
- double det=a11*a22-a12*a21;
- if(det==0){
- return false;
- }
- det=1/det;
- o_dest.m00=a22*det;
- o_dest.m01=-a12*det;
- o_dest.m10=a21*det;
- o_dest.m11=-a11*det;
- return true;
- }
- public static boolean inverse(NyARDoubleMatrix33 i_src,NyARDoubleMatrix33 o_dest) throws NyARException
- {
- /*i_srcの逆行列をthisへ格納するコードを書くこと。*/
- NyARException.notImplement();
- return false;
- }
- /**
- * i_srcの逆行列を計算して、結果をo_destへセットします。
- * @param i_src
- * @return
- */
- public static boolean inverse(NyARDoubleMatrix44 i_src,NyARDoubleMatrix44 o_dest)
- {
- final double a11,a12,a13,a14,a21,a22,a23,a24,a31,a32,a33,a34,a41,a42,a43,a44;
- final double b11,b12,b13,b14,b21,b22,b23,b24,b31,b32,b33,b34,b41,b42,b43,b44;
- double t1,t2,t3,t4,t5,t6;
- a11=i_src.m00;a12=i_src.m01;a13=i_src.m02;a14=i_src.m03;
- a21=i_src.m10;a22=i_src.m11;a23=i_src.m12;a24=i_src.m13;
- a31=i_src.m20;a32=i_src.m21;a33=i_src.m22;a34=i_src.m23;
- a41=i_src.m30;a42=i_src.m31;a43=i_src.m32;a44=i_src.m33;
-
- t1=a33*a44-a34*a43;
- t2=a34*a42-a32*a44;
- t3=a32*a43-a33*a42;
- t4=a34*a41-a31*a44;
- t5=a31*a43-a33*a41;
- t6=a31*a42-a32*a41;
-
- b11=a22*t1+a23*t2+a24*t3;
- b21=-(a23*t4+a24*t5+a21*t1);
- b31=a24*t6-a21*t2+a22*t4;
- b41=-(a21*t3-a22*t5+a23*t6);
-
- t1=a43*a14-a44*a13;
- t2=a44*a12-a42*a14;
- t3=a42*a13-a43*a12;
- t4=a44*a11-a41*a14;
- t5=a41*a13-a43*a11;
- t6=a41*a12-a42*a11;
-
- b12=-(a32*t1+a33*t2+a34*t3);
- b22=a33*t4+a34*t5+a31*t1;
- b32=-(a34*t6-a31*t2+a32*t4);
- b42=a31*t3-a32*t5+a33*t6;
-
- t1=a13*a24-a14*a23;
- t2=a14*a22-a12*a24;
- t3=a12*a23-a13*a22;
- t4=a14*a21-a11*a24;
- t5=a11*a23-a13*a21;
- t6=a11*a22-a12*a21;
-
- b13=a42*t1+a43*t2+a44*t3;
- b23=-(a43*t4+a44*t5+a41*t1);
- b33=a44*t6-a41*t2+a42*t4;
- b43=-(a41*t3-a42*t5+a43*t6);
-
- t1=a23*a34-a24*a33;
- t2=a24*a32-a22*a34;
- t3=a22*a33-a23*a32;
- t4=a24*a31-a21*a34;
- t5=a21*a33-a23*a31;
- t6=a21*a32-a22*a31;
-
- b14=-(a12*t1+a13*t2+a14*t3);
- b24=a13*t4+a14*t5+a11*t1;
- b34=-(a14*t6-a11*t2+a12*t4);
- b44=a11*t3-a12*t5+a13*t6;
-
- double det_1=(a11*b11+a21*b12+a31*b13+a41*b14);
- if(det_1==0){
- return false;
- }
- det_1=1/det_1;
-
- o_dest.m00=b11*det_1;
- o_dest.m01=b12*det_1;
- o_dest.m02=b13*det_1;
- o_dest.m03=b14*det_1;
-
- o_dest.m10=b21*det_1;
- o_dest.m11=b22*det_1;
- o_dest.m12=b23*det_1;
- o_dest.m13=b24*det_1;
-
- o_dest.m20=b31*det_1;
- o_dest.m21=b32*det_1;
- o_dest.m22=b33*det_1;
- o_dest.m23=b34*det_1;
-
- o_dest.m30=b41*det_1;
- o_dest.m31=b42*det_1;
- o_dest.m32=b43*det_1;
- o_dest.m33=b44*det_1;
-
- return true;
- }
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyARSystemOfLinearEquationsProcessor.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyARSystemOfLinearEquationsProcessor.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyARSystemOfLinearEquationsProcessor.java (revision 302)
@@ -1,32 +1,25 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008-2009 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.utils;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyAREquationSolver.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyAREquationSolver.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyAREquationSolver.java (revision 302)
@@ -0,0 +1,312 @@
+/*
+ * PROJECT: NyARToolkit(Extension)
+ * --------------------------------------------------------------------------------
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.utils;
+
+import jp.nyatla.nyartoolkit.*;
+/**
+ * 方程式を解く関数を定義します。
+ *
+ */
+public class NyAREquationSolver
+{
+ public static int solve2Equation(double i_a, double i_b, double i_c,double[] o_result)
+ {
+ assert i_a!=0;
+ return solve2Equation(i_b/i_a,i_c/i_a,o_result,0);
+ }
+
+ public static int solve2Equation(double i_b, double i_c,double[] o_result)
+ {
+ return solve2Equation(i_b,i_c,o_result,0);
+ }
+
+ public static int solve2Equation(double i_b, double i_c,double[] o_result,int i_result_st)
+ {
+ double t=i_b*i_b-4*i_c;
+ if(t<0){
+ //虚数根
+ return 0;
+ }
+ if(t==0){
+ //重根
+ o_result[i_result_st+0]=-i_b/(2);
+ return 1;
+ }
+ //実根2個
+ t=Math.sqrt(t);
+ o_result[i_result_st+0]=(-i_b+t)/(2);
+ o_result[i_result_st+1]=(-i_b-t)/(2);
+ return 2;
+ }
+
+ /**
+ * 3次方程式 a*x^3+b*x^2+c*x+d=0の実根を求める。
+ * http://aoki2.si.gunma-u.ac.jp/JavaScript/src/3jisiki.html
+ * のコードを基にしてます。
+ * @param i_a
+ * X^3の係数
+ * @param i_b
+ * X^2の係数
+ * @param i_c
+ * X^1の係数
+ * @param i_d
+ * X^0の係数
+ * @param o_result
+ * 実根。double[3]を指定すること。
+ * @return
+ */
+ public static int solve3Equation(double i_a, double i_b, double i_c, double i_d,double[] o_result)
+ {
+ assert (i_a != 0);
+ return solve3Equation(i_b/i_a,i_c/i_a,i_d/i_a,o_result);
+ }
+
+ /**
+ * 3次方程式 x^3+b*x^2+c*x+d=0の実根を求める。
+ * だけを求める。
+ * http://aoki2.si.gunma-u.ac.jp/JavaScript/src/3jisiki.html
+ * のコードを基にしてます。
+ * @param i_b
+ * X^2の係数
+ * @param i_c
+ * X^1の係数
+ * @param i_d
+ * X^0の係数
+ * @param o_result
+ * 実根。double[1]以上を指定すること。
+ * @return
+ */
+ public static int solve3Equation(double i_b, double i_c, double i_d,double[] o_result)
+ {
+ double tmp,b, p, q;
+ b = i_b/(3);
+ p = b * b - i_c / 3;
+ q = (b * (i_c - 2 * b * b) - i_d) / 2;
+ if ((tmp = q * q - p * p * p) == 0) {
+ // 重根
+ q = Math.cbrt(q);
+ o_result[0] = 2 * q - b;
+ o_result[1] = -q - b;
+ return 2;
+ } else if (tmp > 0) {
+ // 実根1,虚根2
+ double a3 = Math.cbrt(q + ((q > 0) ? 1 : -1) * Math.sqrt(tmp));
+ double b3 = p / a3;
+ o_result[0] = a3 + b3 - b;
+ // 虚根:-0.5*(a3+b3)-b,Math.abs(a3-b3)*Math.sqrt(3.0)/2
+ return 1;
+ } else {
+ // 実根3
+ tmp = 2 * Math.sqrt(p);
+ double t = Math.acos(q / (p * tmp / 2));
+ o_result[0] = tmp * Math.cos(t / 3) - b;
+ o_result[1] = tmp * Math.cos((t + 2 * Math.PI) / 3) - b;
+ o_result[2] = tmp * Math.cos((t + 4 * Math.PI) / 3) - b;
+ return 3;
+ }
+ }
+
+
+
+ /**
+ * 4次方程式の実根だけを求める。
+ * @param i_a
+ * X^3の係数
+ * @param i_b
+ * X^2の係数
+ * @param i_c
+ * X^1の係数
+ * @param i_d
+ * X^0の係数
+ * @param o_result
+ * 実根。double[3]を指定すること。
+ * @return
+ */
+ public static int solve4Equation(double i_a, double i_b, double i_c, double i_d,double i_e,double[] o_result) throws NyARException
+ {
+ assert (i_a != 0);
+ double A3,A2,A1,A0,B3;
+ A3=i_b/i_a;
+ A2=i_c/i_a;
+ A1=i_d/i_a;
+ A0=i_e/i_a;
+ B3=A3/4;
+ double p,q,r;
+ double B3_2=B3*B3;
+ p=A2-6*B3_2;//A2-6*B3*B3;
+ q=A1+B3*(-2*A2+8*B3_2);//A1-2*A2*B3+8*B3*B3*B3;
+ r=A0+B3*(-A1+A2*B3)-3*B3_2*B3_2;//A0-A1*B3+A2*B3*B3-3*B3*B3*B3*B3;
+ if(q==0){
+ double result_0,result_1;
+ //複二次式
+ int res=solve2Equation(p,r,o_result,0);
+ switch(res){
+ case 0:
+ //全て虚数解
+ return 0;
+ case 1:
+ //重根
+ //解は0,1,2の何れか。
+ result_0=o_result[0];
+ if(result_0<0){
+ //全て虚数解
+ return 0;
+ }
+ //実根1個
+ if(result_0==0){
+ //NC
+ o_result[0]=0-B3;
+ return 1;
+ }
+ //実根2個
+ result_0=Math.sqrt(result_0);
+ o_result[0]=result_0-B3;
+ o_result[1]=-result_0-B3;
+ return 2;
+ case 2:
+ //実根2個だからt==t2==0はありえない。(case1)
+ //解は、0,2,4の何れか。
+ result_0=o_result[0];
+ result_1=o_result[1];
+ int number_of_result=0;
+ if(result_0>0){
+ //NC
+ result_0=Math.sqrt(result_0);
+ o_result[0]= result_0-B3;
+ o_result[1]=-result_0-B3;
+ number_of_result+=2;
+ }
+ if(result_1>0)
+ {
+ //NC
+ result_1=Math.sqrt(result_1);
+ o_result[number_of_result+0]= result_1-B3;
+ o_result[number_of_result+1]=-result_1-B3;
+ number_of_result+=2;
+ }
+ return number_of_result;
+ default:
+ throw new NyARException();
+ }
+ }else{
+ //それ以外
+ //最適化ポイント:
+ //u^3 + (2*p)*u^2 +((- 4*r)+(p^2))*u -q^2= 0
+ double u=solve3Equation_1((2*p),(- 4*r)+(p*p),-q*q);
+ if(u<0){
+ //全て虚数解
+ return 0;
+ }
+ double ru=Math.sqrt(u);
+ //2次方程式を解いてyを計算(最適化ポイント)
+ int result_1st,result_2nd;
+ result_1st=solve2Equation(-ru,(p+u)/2+ru*q/(2*u),o_result,0);
+ //配列使い回しのために、変数に退避
+ switch(result_1st){
+ case 0:
+ break;
+ case 1:
+ o_result[0]=o_result[0]-B3;
+ break;
+ case 2:
+ o_result[0]=o_result[0]-B3;
+ o_result[1]=o_result[1]-B3;
+ break;
+ default:
+ throw new NyARException();
+ }
+ result_2nd=solve2Equation(ru,(p+u)/2-ru*q/(2*u),o_result,result_1st);
+ //0,1番目に格納
+ switch(result_2nd){
+ case 0:
+ break;
+ case 1:
+ o_result[result_1st+0]=o_result[result_1st+0]-B3;
+ break;
+ case 2:
+ o_result[result_1st+0]=o_result[result_1st+0]-B3;
+ o_result[result_1st+1]=o_result[result_1st+1]-B3;
+ break;
+ default:
+ throw new NyARException();
+ }
+ return result_1st+result_2nd;
+ }
+ }
+ /**
+ * 3乗根を求められないシステムで、3乗根を求めます。
+ * http://aoki2.si.gunma-u.ac.jp/JavaScript/src/3jisiki.html
+ * @param i_in
+ * @return
+ */
+ private double cuberoot(double i_in) {
+ double res = Math.pow(Math.abs(i_in), 1.0 / 3.0);
+ return (i_in >= 0) ? res : -res;
+ }
+ /**
+ * 3次方程式の実根を1個だけ求める。
+ * 4字方程式で使う。
+ * @param i_b
+ * @param i_c
+ * @param i_d
+ * @param o_result
+ * @return
+ */
+ private static double solve3Equation_1(double i_b, double i_c, double i_d)
+ {
+ double tmp,b, p, q;
+ b = i_b/(3);
+ p = b * b - i_c / 3;
+ q = (b * (i_c - 2 * b * b) - i_d) / 2;
+ if ((tmp = q * q - p * p * p) == 0) {
+ // 重根
+ q = Math.cbrt(q);
+ return 2 * q - b;
+ } else if (tmp > 0) {
+ // 実根1,虚根2
+ double a3 = Math.cbrt(q + ((q > 0) ? 1 : -1) * Math.sqrt(tmp));
+ double b3 = p / a3;
+ return a3 + b3 - b;
+ } else {
+ // 実根3
+ tmp = 2 * Math.sqrt(p);
+ double t = Math.acos(q / (p * tmp / 2));
+ return tmp * Math.cos(t / 3) - b;
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ NyAREquationSolver n = new NyAREquationSolver();
+ int l=0;
+ double[] r = new double[10];
+ try{
+ l=n.solve4Equation(1, 9, -18, -68, 120, r);
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ System.out.println(l);
+ }
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyARPerspectiveParamGenerator_O1.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyARPerspectiveParamGenerator_O1.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyARPerspectiveParamGenerator_O1.java (revision 302)
@@ -1,32 +1,25 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008-2009 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.utils;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyARPerspectiveParamGenerator.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyARPerspectiveParamGenerator.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/utils/NyARPerspectiveParamGenerator.java (revision 302)
@@ -1,32 +1,25 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008-2009 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.utils;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARIntSize.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARIntSize.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARIntSize.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.types;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARIntRect.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARIntRect.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARIntRect.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.types;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARDoublePoint2d.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARDoublePoint2d.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARDoublePoint2d.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.types;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARIntPoint2d.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARIntPoint2d.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARIntPoint2d.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.types;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARLinear.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARLinear.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARLinear.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.types;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/NyARDoubleMatrix33.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/NyARDoubleMatrix33.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/NyARDoubleMatrix33.java (revision 302)
@@ -1,37 +1,31 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.types.matrix;

import jp.nyatla.nyartoolkit.*;
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;

public class NyARDoubleMatrix33 implements INyARDoubleMatrix
{
@@ -69,6 +63,19 @@
this.m22=i_value[8];
return;
}
+ public void setValue(NyARDoubleMatrix33 i_value)
+ {
+ this.m00=i_value.m00;
+ this.m01=i_value.m01;
+ this.m02=i_value.m02;
+ this.m10=i_value.m10;
+ this.m11=i_value.m11;
+ this.m12=i_value.m12;
+ this.m20=i_value.m20;
+ this.m21=i_value.m21;
+ this.m22=i_value.m22;
+ return;
+ }
/**
* 遅いからあんまり使わないでね。
*/
@@ -85,4 +92,83 @@
o_value[8]=this.m22;
return;
}
+ public boolean inverse(NyARDoubleMatrix33 i_src)
+ {
+ final double a11,a12,a13,a21,a22,a23,a31,a32,a33;
+ final double b11,b12,b13,b21,b22,b23,b31,b32,b33;
+ a11=i_src.m00;a12=i_src.m01;a13=i_src.m02;
+ a21=i_src.m10;a22=i_src.m11;a23=i_src.m12;
+ a31=i_src.m20;a32=i_src.m21;a33=i_src.m22;
+
+ b11=a22*a33-a23*a32;
+ b12=a32*a13-a33*a12;
+ b13=a12*a23-a13*a22;
+
+ b21=a23*a31-a21*a33;
+ b22=a33*a11-a31*a13;
+ b23=a13*a21-a11*a23;
+
+ b31=a21*a32-a22*a31;
+ b32=a31*a12-a32*a11;
+ b33=a11*a22-a12*a21;
+
+ double det_1=a11*b11+a21*b12+a31*b13;
+ if(det_1==0){
+ return false;
+ }
+ det_1=1/det_1;
+
+ this.m00=b11*det_1;
+ this.m01=b12*det_1;
+ this.m02=b13*det_1;
+
+ this.m10=b21*det_1;
+ this.m11=b22*det_1;
+ this.m12=b23*det_1;
+
+ this.m20=b31*det_1;
+ this.m21=b32*det_1;
+ this.m22=b33*det_1;
+
+ return true;
+ }
+ /**
+ * この関数は、0-PIの間で値を返します。
+ * @param o_out
+ */
+ public final void getZXYAngle(NyARDoublePoint3d o_out)
+ {
+ double sina = this.m21;
+ if (sina >= 1.0) {
+ o_out.x = Math.PI / 2;
+ o_out.y = 0;
+ o_out.z = Math.atan2(-this.m10, this.m00);
+ } else if (sina <= -1.0) {
+ o_out.x = -Math.PI / 2;
+ o_out.y = 0;
+ o_out.z = Math.atan2(-this.m10, this.m00);
+ } else {
+ o_out.x = Math.asin(sina);
+ o_out.z = Math.atan2(-this.m01, this.m11);
+ o_out.y = Math.atan2(-this.m20, this.m22);
+ }
+ }
+ public final void setZXYAngle(final double i_x, final double i_y, final double i_z)
+ {
+ final double sina = Math.sin(i_x);
+ final double cosa = Math.cos(i_x);
+ final double sinb = Math.sin(i_y);
+ final double cosb = Math.cos(i_y);
+ final double sinc = Math.sin(i_z);
+ final double cosc = Math.cos(i_z);
+ this.m00 = cosc * cosb - sinc * sina * sinb;
+ this.m01 = -sinc * cosa;
+ this.m02 = cosc * sinb + sinc * sina * cosb;
+ this.m10 = sinc * cosb + cosc * sina * sinb;
+ this.m11 = cosc * cosa;
+ this.m12 = sinc * sinb - cosc * sina * cosb;
+ this.m20 = -cosa * sinb;
+ this.m21 = sina;
+ this.m22 = cosb * cosa;
+ }
}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/NyARDoubleMatrix34.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/NyARDoubleMatrix34.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/NyARDoubleMatrix34.java (revision 302)
@@ -1,32 +1,25 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.types.matrix;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/NyARDoubleMatrix44.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/NyARDoubleMatrix44.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/NyARDoubleMatrix44.java (revision 302)
@@ -1,32 +1,25 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.types.matrix;
@@ -105,4 +98,90 @@
o_value[15]=this.m33;
return;
}
+ public boolean inverse(NyARDoubleMatrix44 i_src)
+ {
+ final double a11,a12,a13,a14,a21,a22,a23,a24,a31,a32,a33,a34,a41,a42,a43,a44;
+ final double b11,b12,b13,b14,b21,b22,b23,b24,b31,b32,b33,b34,b41,b42,b43,b44;
+ double t1,t2,t3,t4,t5,t6;
+ a11=i_src.m00;a12=i_src.m01;a13=i_src.m02;a14=i_src.m03;
+ a21=i_src.m10;a22=i_src.m11;a23=i_src.m12;a24=i_src.m13;
+ a31=i_src.m20;a32=i_src.m21;a33=i_src.m22;a34=i_src.m23;
+ a41=i_src.m30;a42=i_src.m31;a43=i_src.m32;a44=i_src.m33;
+
+ t1=a33*a44-a34*a43;
+ t2=a34*a42-a32*a44;
+ t3=a32*a43-a33*a42;
+ t4=a34*a41-a31*a44;
+ t5=a31*a43-a33*a41;
+ t6=a31*a42-a32*a41;
+
+ b11=a22*t1+a23*t2+a24*t3;
+ b21=-(a23*t4+a24*t5+a21*t1);
+ b31=a24*t6-a21*t2+a22*t4;
+ b41=-(a21*t3-a22*t5+a23*t6);
+
+ t1=a43*a14-a44*a13;
+ t2=a44*a12-a42*a14;
+ t3=a42*a13-a43*a12;
+ t4=a44*a11-a41*a14;
+ t5=a41*a13-a43*a11;
+ t6=a41*a12-a42*a11;
+
+ b12=-(a32*t1+a33*t2+a34*t3);
+ b22=a33*t4+a34*t5+a31*t1;
+ b32=-(a34*t6-a31*t2+a32*t4);
+ b42=a31*t3-a32*t5+a33*t6;
+
+ t1=a13*a24-a14*a23;
+ t2=a14*a22-a12*a24;
+ t3=a12*a23-a13*a22;
+ t4=a14*a21-a11*a24;
+ t5=a11*a23-a13*a21;
+ t6=a11*a22-a12*a21;
+
+ b13=a42*t1+a43*t2+a44*t3;
+ b23=-(a43*t4+a44*t5+a41*t1);
+ b33=a44*t6-a41*t2+a42*t4;
+ b43=-(a41*t3-a42*t5+a43*t6);
+
+ t1=a23*a34-a24*a33;
+ t2=a24*a32-a22*a34;
+ t3=a22*a33-a23*a32;
+ t4=a24*a31-a21*a34;
+ t5=a21*a33-a23*a31;
+ t6=a21*a32-a22*a31;
+
+ b14=-(a12*t1+a13*t2+a14*t3);
+ b24=a13*t4+a14*t5+a11*t1;
+ b34=-(a14*t6-a11*t2+a12*t4);
+ b44=a11*t3-a12*t5+a13*t6;
+
+ double det_1=(a11*b11+a21*b12+a31*b13+a41*b14);
+ if(det_1==0){
+ return false;
+ }
+ det_1=1/det_1;
+
+ this.m00=b11*det_1;
+ this.m01=b12*det_1;
+ this.m02=b13*det_1;
+ this.m03=b14*det_1;
+
+ this.m10=b21*det_1;
+ this.m11=b22*det_1;
+ this.m12=b23*det_1;
+ this.m13=b24*det_1;
+
+ this.m20=b31*det_1;
+ this.m21=b32*det_1;
+ this.m22=b33*det_1;
+ this.m23=b34*det_1;
+
+ this.m30=b41*det_1;
+ this.m31=b42*det_1;
+ this.m32=b43*det_1;
+ this.m33=b44*det_1;
+
+ return true;
+ }
}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/INyARDoubleMatrix.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/INyARDoubleMatrix.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/INyARDoubleMatrix.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.types.matrix;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/NyARDoubleMatrix22.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/NyARDoubleMatrix22.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/matrix/NyARDoubleMatrix22.java (revision 302)
@@ -1,32 +1,25 @@
/*
- * PROJECT: NyARToolkit
+ * PROJECT: NyARToolkit(Extension)
* --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.types.matrix;
@@ -59,4 +52,22 @@
o_value[4]=this.m11;
return;
}
+ public boolean inverse(NyARDoubleMatrix22 i_src)
+ {
+ final double a11,a12,a21,a22;
+ a11=i_src.m00;
+ a12=i_src.m01;
+ a21=i_src.m10;
+ a22=i_src.m11;
+ double det=a11*a22-a12*a21;
+ if(det==0){
+ return false;
+ }
+ det=1/det;
+ this.m00=a22*det;
+ this.m01=-a12*det;
+ this.m10=a21*det;
+ this.m11=-a11*det;
+ return true;
+ }
}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARDoublePoint3d.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARDoublePoint3d.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARDoublePoint3d.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.types;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntPointStack.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntPointStack.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntPointStack.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.types.stack;
@@ -35,19 +34,15 @@
import jp.nyatla.nyartoolkit.core.types.*;
import jp.nyatla.utils.NyObjectStack;

-public class NyARIntPointStack extends NyObjectStack
+public class NyARIntPointStack extends NyObjectStack<NyARIntPoint2d>
{
public NyARIntPointStack(int i_length)
{
- super(new NyARIntPoint2d[i_length]);
-
+ super(i_length,NyARIntPoint2d.class);
+ return;
}
-
- protected void onReservRequest(int i_start, int i_end, Object[] i_buffer)
+ protected NyARIntPoint2d createElement()
{
- for (int i = i_start; i < i_end; i++) {
- i_buffer[i] = new NyARIntPoint2d();
- }
- }
-
+ return new NyARIntPoint2d();
+ }
}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntRectStack.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntRectStack.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntRectStack.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.types.stack;
@@ -35,18 +34,15 @@
import jp.nyatla.nyartoolkit.core.types.NyARIntRect;
import jp.nyatla.utils.NyObjectStack;

-public class NyARIntRectStack extends NyObjectStack
+public class NyARIntRectStack extends NyObjectStack<NyARIntRect>
{
public NyARIntRectStack(int i_length)
{
- super(new NyARIntRect[i_length]);
-
+ super(i_length,NyARIntRect.class);
}
-
- protected void onReservRequest(int i_start, int i_end, Object[] i_buffer)
+ protected NyARIntRect createElement()
{
- for (int i = i_start; i < i_end; i++) {
- i_buffer[i] = new NyARIntRect();
- }
+ return new NyARIntRect();
}
+
}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARIntPoint.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARIntPoint.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/types/NyARIntPoint.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.types;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/INyARRasterFilter_RgbToGs.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/INyARRasterFilter_RgbToGs.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/INyARRasterFilter_RgbToGs.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.rasterfilter;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2bin/INyARRasterFilter_RgbToBin.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2bin/INyARRasterFilter_RgbToBin.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2bin/INyARRasterFilter_RgbToBin.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2bin/NyARRasterFilter_ARToolkitThreshold.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2bin/NyARRasterFilter_ARToolkitThreshold.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2bin/NyARRasterFilter_ARToolkitThreshold.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin;
@@ -43,156 +42,335 @@
*/
public class NyARRasterFilter_ARToolkitThreshold implements INyARRasterFilter_RgbToBin
{
- private int _threshold;
-
- public NyARRasterFilter_ARToolkitThreshold(int i_threshold)
+ interface IdoThFilterImpl
{
- this._threshold = i_threshold;
+ public void doThFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size,int i_threshold);
}
- public void setThreshold(int i_threshold)
+ class doThFilterImpl_BUFFERFORMAT_BYTE1D_RGB_24 implements IdoThFilterImpl
{
- this._threshold = i_threshold;
+ public void doThFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size,int i_threshold)
+ {
+ int[] out_buf = (int[]) i_output.getBuffer();
+ byte[] in_buf = (byte[]) i_input.getBuffer();
+
+ final int th=i_threshold*3;
+ int bp =(i_size.w*i_size.h-1)*3;
+ int w;
+ int xy;
+ final int pix_count =i_size.h*i_size.w;
+ final int pix_mod_part=pix_count-(pix_count%8);
+ for(xy=pix_count-1;xy>=pix_mod_part;xy--){
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 3;
+ }
+ //タイリング
+ for (;xy>=0;) {
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 3;
+ xy--;
+ }
+ return;
+ }
+
}
+ class doThFilterImpl_BUFFERFORMAT_BYTE1D_B8G8R8X8_32 implements IdoThFilterImpl
+ {
+ public void doThFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size,int i_threshold)
+ {
+ int[] out_buf = (int[]) i_output.getBuffer();
+ byte[] in_buf = (byte[]) i_input.getBuffer();
+
+ final int th=i_threshold*3;
+ int bp =(i_size.w*i_size.h-1)*4;
+ int w;
+ int xy;
+ final int pix_count =i_size.h*i_size.w;
+ final int pix_mod_part=pix_count-(pix_count%8);
+ for(xy=pix_count-1;xy>=pix_mod_part;xy--){
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ }
+ //タイリング
+ for (;xy>=0;) {
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ }
+ }
+ }
+
+ class doThFilterImpl_BUFFERFORMAT_BYTE1D_X8R8G8B8_32 implements IdoThFilterImpl
+ {
+ public void doThFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size,int i_threshold)
+ {
+ int[] out_buf = (int[]) i_output.getBuffer();
+ byte[] in_buf = (byte[]) i_input.getBuffer();
+
+ final int th=i_threshold*3;
+ int bp =(i_size.w*i_size.h-1)*4;
+ int w;
+ int xy;
+ final int pix_count =i_size.h*i_size.w;
+ final int pix_mod_part=pix_count-(pix_count%8);
+ for(xy=pix_count-1;xy>=pix_mod_part;xy--){
+ w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ }
+ //タイリング
+ for (;xy>=0;) {
+ w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
+ out_buf[xy]=w<=th?0:1;
+ bp -= 4;
+ xy--;
+ }
+ return;
+ }
+
+ }
+
+ class doThFilterImpl_BUFFERFORMAT_INT1D_X8R8G8B8_32 implements IdoThFilterImpl
+ {
+ public void doThFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size,int i_threshold)
+ {
+ int[] out_buf = (int[]) i_output.getBuffer();
+ int[] in_buf = (int[]) i_input.getBuffer();
+
+ final int th=i_threshold*3;
+ int w;
+ int xy;
+ final int pix_count =i_size.h*i_size.w;
+ final int pix_mod_part=pix_count-(pix_count%8);

- public void doFilter(INyARRgbRaster i_input, NyARBinRaster i_output) throws NyARException
+ for(xy=pix_count-1;xy>=pix_mod_part;xy--){
+ w=in_buf[xy];
+ out_buf[xy]=(((w>>16)&0xff)+((w>>8)&0xff)+(w&0xff))<=th?0:1;
+ }
+ //タイリング
+ for (;xy>=0;) {
+ w=in_buf[xy];
+ out_buf[xy]=(((w>>16)&0xff)+((w>>8)&0xff)+(w&0xff))<=th?0:1;
+ xy--;
+ w=in_buf[xy];
+ out_buf[xy]=(((w>>16)&0xff)+((w>>8)&0xff)+(w&0xff))<=th?0:1;
+ xy--;
+ w=in_buf[xy];
+ out_buf[xy]=(((w>>16)&0xff)+((w>>8)&0xff)+(w&0xff))<=th?0:1;
+ xy--;
+ w=in_buf[xy];
+ out_buf[xy]=(((w>>16)&0xff)+((w>>8)&0xff)+(w&0xff))<=th?0:1;
+ xy--;
+ w=in_buf[xy];
+ out_buf[xy]=(((w>>16)&0xff)+((w>>8)&0xff)+(w&0xff))<=th?0:1;
+ xy--;
+ w=in_buf[xy];
+ out_buf[xy]=(((w>>16)&0xff)+((w>>8)&0xff)+(w&0xff))<=th?0:1;
+ xy--;
+ w=in_buf[xy];
+ out_buf[xy]=(((w>>16)&0xff)+((w>>8)&0xff)+(w&0xff))<=th?0:1;
+ xy--;
+ w=in_buf[xy];
+ out_buf[xy]=(((w>>16)&0xff)+((w>>8)&0xff)+(w&0xff))<=th?0:1;
+ xy--;
+ }
+ }
+ }
+
+ class doThFilterImpl_BUFFERFORMAT_WORD1D_R5G6B5_16LE implements IdoThFilterImpl
{
- INyARBufferReader in_buffer_reader=i_input.getBufferReader();
- INyARBufferReader out_buffer_reader=i_output.getBufferReader();
- int in_buf_type=in_buffer_reader.getBufferType();
+ public void doThFilter(INyARBufferReader i_input, INyARBufferReader i_output,NyARIntSize i_size,int i_threshold)
+ {
+ int[] out_buf = (int[]) i_output.getBuffer();
+ short[] in_buf = (short[]) i_input.getBuffer();
+
+ final int th=i_threshold*3;
+ int w;
+ int xy;
+ final int pix_count =i_size.h*i_size.w;
+ final int pix_mod_part=pix_count-(pix_count%8);

- assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));
- assert (checkInputType(in_buf_type)==true);
- assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);
+ for(xy=pix_count-1;xy>=pix_mod_part;xy--){
+ w =(int)in_buf[xy];
+ w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
+ out_buf[xy] = w <= th ? 0 : 1;
+ }
+ //タイリング
+ for (;xy>=0;) {
+ w =(int)in_buf[xy];
+ w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
+ out_buf[xy] = w <= th ? 0 : 1;
+ xy--;
+ w =(int)in_buf[xy];
+ w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
+ out_buf[xy] = w <= th ? 0 : 1;
+ xy--;
+ w =(int)in_buf[xy];
+ w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
+ out_buf[xy] = w <= th ? 0 : 1;
+ xy--;
+ w =(int)in_buf[xy];
+ w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
+ out_buf[xy] = w <= th ? 0 : 1;
+ xy--;
+ w =(int)in_buf[xy];
+ w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
+ out_buf[xy] = w <= th ? 0 : 1;
+ xy--;
+ w =(int)in_buf[xy];
+ w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
+ out_buf[xy] = w <= th ? 0 : 1;
+ xy--;
+ w =(int)in_buf[xy];
+ w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
+ out_buf[xy] = w <= th ? 0 : 1;
+ xy--;
+ w =(int)in_buf[xy];
+ w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
+ out_buf[xy] = w <= th ? 0 : 1;
+ xy--;
+ }
+ }
+ }
+
+
+
+

- int[] out_buf = (int[]) out_buffer_reader.getBuffer();
- byte[] in_buf = (byte[]) in_buffer_reader.getBuffer();
+
+
+
+
+ private int _threshold;
+ private IdoThFilterImpl _do_threshold_impl;

- NyARIntSize size = i_output.getSize();
- switch (in_buffer_reader.getBufferType()) {
+ public NyARRasterFilter_ARToolkitThreshold(int i_threshold,int i_input_raster_type) throws NyARException
+ {
+ this._threshold = i_threshold;
+ switch (i_input_raster_type) {
case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:
case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:
- convert24BitRgb(in_buf, out_buf, size);
+ this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_RGB_24();
break;
case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32:
- convert32BitRgbx(in_buf, out_buf, size);
+ this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_B8G8R8X8_32();
break;
+ case INyARBufferReader.BUFFERFORMAT_BYTE1D_X8R8G8B8_32:
+ this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_BYTE1D_X8R8G8B8_32();
+ break;
+ case INyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32:
+ this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_INT1D_X8R8G8B8_32();
+ break;
+ case INyARBufferReader.BUFFERFORMAT_WORD1D_R5G6B5_16LE:
+ this._do_threshold_impl=new doThFilterImpl_BUFFERFORMAT_WORD1D_R5G6B5_16LE();
+ break;
default:
throw new NyARException();
}
- return;
+
+
}
-
- private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size)
+ public void setThreshold(int i_threshold)
{
- final int th=this._threshold*3;
- int bp =(i_size.w*i_size.h-1)*3;
- int w;
- int xy;
- final int pix_count =i_size.h*i_size.w;
- final int pix_mod_part=pix_count-(pix_count%8);
- for(xy=pix_count-1;xy>=pix_mod_part;xy--){
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 3;
- }
- //タイリング
- for (;xy>=0;) {
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 3;
- xy--;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 3;
- xy--;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 3;
- xy--;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 3;
- xy--;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 3;
- xy--;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 3;
- xy--;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 3;
- xy--;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 3;
- xy--;
- }
- return;
+ this._threshold = i_threshold;
}
- private void convert32BitRgbx(byte[] i_in, int[] i_out, NyARIntSize i_size)
+
+ public void doFilter(INyARRgbRaster i_input, NyARBinRaster i_output) throws NyARException
{
- final int th=this._threshold*3;
- int bp =(i_size.w*i_size.h-1)*4;
- int w;
- int xy;
- final int pix_count =i_size.h*i_size.w;
- final int pix_mod_part=pix_count-(pix_count%8);
- for(xy=pix_count-1;xy>=pix_mod_part;xy--){
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 4;
- }
- //タイリング
- for (;xy>=0;) {
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 4;
- xy--;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 4;
- xy--;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 4;
- xy--;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 4;
- xy--;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 4;
- xy--;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 4;
- xy--;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 4;
- xy--;
- w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
- i_out[xy]=w<=th?0:1;
- bp -= 4;
- xy--;
- }
+ INyARBufferReader in_buffer_reader=i_input.getBufferReader();
+ INyARBufferReader out_buffer_reader=i_output.getBufferReader();
+
+ assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));
+ assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);
+ this._do_threshold_impl.doThFilter(in_buffer_reader,out_buffer_reader,i_output.getSize(), this._threshold);
return;
}
-
- private boolean checkInputType(int i_input_type) throws NyARException
- {
- switch(i_input_type){
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32:
- case INyARBufferReader.BUFFERFORMAT_BYTE1D_R5G6B5_16LE:
- return true;
- default:
- return false;
- }
- }
+
}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/INyARRasterFilter.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/INyARRasterFilter.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/INyARRasterFilter.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.rasterfilter;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/INyARRasterFilter_GsToBin.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/INyARRasterFilter_GsToBin.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/rasterfilter/INyARRasterFilter_GsToBin.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.core.rasterfilter;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabeling_ARToolKit.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabeling_ARToolKit.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabeling_ARToolKit.java (revision 302)
@@ -1,349 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core.labeling;
-
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.raster.*;
-import jp.nyatla.nyartoolkit.core.types.*;
-
-/**
- * ARToolKit互換のラベリングクラスです。 ARToolKitと同一な評価結果を返します。
- *
- */
-public class NyARLabeling_ARToolKit implements INyARLabeling
-{
- private static final int WORK_SIZE = 1024 * 32;// #define WORK_SIZE 1024*32
-
- private final NyARWorkHolder work_holder = new NyARWorkHolder(WORK_SIZE);
-
- private NyARIntSize _dest_size;
-
- private INyARLabelingImage _out_image;
-
- public void attachDestination(INyARLabelingImage i_destination_image) throws NyARException
- {
- // サイズチェック
- NyARIntSize size = i_destination_image.getSize();
- this._out_image = i_destination_image;
-
- // NyLabelingImageのイメージ初期化(枠書き)
- int[] img = (int[]) i_destination_image.getBufferReader().getBuffer();
- int bottom_ptr = (size.h - 1) * size.w;
- for (int i = 0; i < size.w; i++) {
- img[i] = 0;
- img[bottom_ptr + i] = 0;
- }
- for (int i = 0; i < size.h; i++) {
- img[i * size.w] = 0;
- img[(i + 1) * size.w - 1] = 0;
- }
-
- // サイズ(参照値)を保存
- this._dest_size = size;
- return;
- }
-
- public INyARLabelingImage getAttachedDestination()
- {
- return this._out_image;
- }
-
- /**
- * static ARInt16 *labeling2( ARUint8 *image, int thresh,int *label_num, int **area, double **pos, int **clip,int **label_ref, int LorR ) 関数の代替品
- * ラスタimageをラベリングして、結果を保存します。 Optimize:STEP[1514->1493]
- *
- * @param i_raster
- * @throws NyARException
- */
- public void labeling(NyARBinRaster i_raster) throws NyARException
- {
- int label_img_ptr1, label_pixel;
- int i, j;
- int n, k; /* work */
-
- // サイズチェック
- NyARIntSize in_size = i_raster.getSize();
- this._dest_size.isEqualSize(in_size);
-
- final int lxsize = in_size.w;// lxsize = arUtil_c.arImXsize;
- final int lysize = in_size.h;// lysize = arUtil_c.arImYsize;
- final int[] label_img = (int[]) this._out_image.getBufferReader().getBuffer();
-
- // 枠作成はインスタンスを作った直後にやってしまう。
-
- // ラベリング情報のリセット(ラベリングインデックスを使用)
- this._out_image.reset(true);
-
- int[] label_idxtbl = this._out_image.getIndexArray();
- int[] raster_buf = (int[]) i_raster.getBufferReader().getBuffer();
-
- int[] work2_pt;
- int wk_max = 0;
-
- int pixel_index;
- int[][] work2 = this.work_holder.work2;
-
- // [1,1](ptr0)と、[0,1](ptr1)のインデクス値を計算する。
- for (j = 1; j < lysize - 1; j++) {// for (int j = 1; j < lysize - 1;j++, pnt += poff*2, pnt2 += 2) {
- pixel_index = j * lxsize + 1;
- label_img_ptr1 = pixel_index - lxsize;// label_img_pt1 = label_img[j - 1];
- for (i = 1; i < lxsize - 1; i++, pixel_index++, label_img_ptr1++) {// for(int i = 1; i < lxsize-1;i++, pnt+=poff, pnt2++) {
- // RGBの合計値が閾値より小さいかな?
- if (raster_buf[pixel_index] != 0) {
- label_img[pixel_index] = 0;// label_img_pt0[i] = 0;// *pnt2 = 0;
- } else {
- // pnt1 = ShortPointer.wrap(pnt2, -lxsize);//pnt1 =&(pnt2[-lxsize]);
- if (label_img[label_img_ptr1] > 0) {// if (label_img_pt1[i] > 0) {// if( *pnt1 > 0 ) {
- label_pixel = label_img[label_img_ptr1];// label_pixel = label_img_pt1[i];// *pnt2 = *pnt1;
-
- work2_pt = work2[label_pixel - 1];
- work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
- work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
- work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
- work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
- } else if (label_img[label_img_ptr1 + 1] > 0) {// } else if (label_img_pt1[i + 1] > 0) {// }else if(*(pnt1+1) > 0 ) {
- if (label_img[label_img_ptr1 - 1] > 0) {// if (label_img_pt1[i - 1] > 0) {// if( *(pnt1-1) > 0 ) {
- label_pixel = label_idxtbl[label_img[label_img_ptr1 + 1] - 1];// m = label_idxtbl[label_img_pt1[i + 1] - 1];// m
- // =work[*(pnt1+1)-1];
- n = label_idxtbl[label_img[label_img_ptr1 - 1] - 1];// n = label_idxtbl[label_img_pt1[i - 1] - 1];// n =work[*(pnt1-1)-1];
- if (label_pixel > n) {
- // wk=IntPointer.wrap(work, 0);//wk = &(work[0]);
- for (k = 0; k < wk_max; k++) {
- if (label_idxtbl[k] == label_pixel) {// if( *wk == m )
- label_idxtbl[k] = n;// *wk = n;
- }
- }
- label_pixel = n;// *pnt2 = n;
- } else if (label_pixel < n) {
- // wk=IntPointer.wrap(work,0);//wk = &(work[0]);
- for (k = 0; k < wk_max; k++) {
- if (label_idxtbl[k] == n) {// if( *wk == n ){
- label_idxtbl[k] = label_pixel;// *wk = m;
- }
- }
- }
- work2_pt = work2[label_pixel - 1];
- work2_pt[0]++;
- work2_pt[1] += i;
- work2_pt[2] += j;
- work2_pt[6] = j;
- } else if ((label_img[pixel_index - 1]) > 0) {// } else if ((label_img_pt0[i - 1]) > 0) {// }else if(*(pnt2-1) > 0) {
- label_pixel = label_idxtbl[label_img[label_img_ptr1 + 1] - 1];// m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1];
- n = label_idxtbl[label_img[pixel_index - 1] - 1];// n = label_idxtbl[label_img_pt0[i - 1] - 1];// n =work[*(pnt2-1)-1];
- if (label_pixel > n) {
- for (k = 0; k < wk_max; k++) {
- if (label_idxtbl[k] == label_pixel) {// if( *wk == m ){
- label_idxtbl[k] = n;// *wk = n;
- }
- }
- label_pixel = n;// *pnt2 = n;
- } else if (label_pixel < n) {
- for (k = 0; k < wk_max; k++) {
- if (label_idxtbl[k] == n) {// if( *wk == n ){
- label_idxtbl[k] = label_pixel;// *wk = m;
- }
- }
- }
- work2_pt = work2[label_pixel - 1];
- work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
- work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
- work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
- } else {
-
- label_pixel = label_img[label_img_ptr1 + 1];// label_pixel = label_img_pt1[i + 1];// *pnt2 =
- // *(pnt1+1);
-
- work2_pt = work2[label_pixel - 1];
- work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
- work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
- work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
- if (work2_pt[3] > i) {// if(work2[((*pnt2)-1)*7+3] > i ){
- work2_pt[3] = i;// work2[((*pnt2)-1)*7+3] = i;
- }
- work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
- }
- } else if ((label_img[label_img_ptr1 - 1]) > 0) {// } else if ((label_img_pt1[i - 1]) > 0) {// }else if(
- // *(pnt1-1) > 0 ) {
- label_pixel = label_img[label_img_ptr1 - 1];// label_pixel = label_img_pt1[i - 1];// *pnt2 =
- // *(pnt1-1);
-
- work2_pt = work2[label_pixel - 1];
- work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
- work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
- work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
- if (work2_pt[4] < i) {// if( work2[((*pnt2)-1)*7+4] <i ){
- work2_pt[4] = i;// work2[((*pnt2)-1)*7+4] = i;
- }
- work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
- } else if (label_img[pixel_index - 1] > 0) {// } else if (label_img_pt0[i - 1] > 0) {// }else if(*(pnt2-1) > 0) {
- label_pixel = label_img[pixel_index - 1];// label_pixel = label_img_pt0[i - 1];// *pnt2 =*(pnt2-1);
-
- work2_pt = work2[label_pixel - 1];
- work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
- work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
- work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
- if (work2_pt[4] < i) {// if( work2[((*pnt2)-1)*7+4] <i ){
- work2_pt[4] = i;// work2[((*pnt2)-1)*7+4] = i;
- }
- } else {
- // 現在地までの領域を予約
- this.work_holder.reserv(wk_max);
- wk_max++;
- label_idxtbl[wk_max - 1] = wk_max;
- label_pixel = wk_max;// work[wk_max-1] = *pnt2 = wk_max;
- work2_pt = work2[wk_max - 1];
- work2_pt[0] = 1;
- work2_pt[1] = i;
- work2_pt[2] = j;
- work2_pt[3] = i;
- work2_pt[4] = i;
- work2_pt[5] = j;
- work2_pt[6] = j;
- }
- label_img[pixel_index] = label_pixel;// label_img_pt0[i] = label_pixel;
- }
- }
-
- }
- // インデックステーブルとラベル数の計算
- int wlabel_num = 1;// *label_num = *wlabel_num = j - 1;
-
- for (i = 0; i < wk_max; i++) {// for(int i = 1; i <= wk_max; i++,wk++) {
- label_idxtbl[i] = (label_idxtbl[i] == i + 1) ? wlabel_num++ : label_idxtbl[label_idxtbl[i] - 1];// *wk=(*wk==i)?j++:work[(*wk)-1];
- }
- wlabel_num -= 1;// *label_num = *wlabel_num = j - 1;
- if (wlabel_num == 0) {// if( *label_num == 0 ) {
- // 発見数0
- this._out_image.getLabelStack().clear();
- return;
- }
- // ラベル情報の保存等
- NyARLabelingLabelStack label_list = this._out_image.getLabelStack();
-
- // ラベルバッファを予約
- label_list.reserv(wlabel_num);
-
- // エリアと重心、クリップ領域を計算
- NyARLabelingLabel label_pt;
- NyARLabelingLabel[] labels = (NyARLabelingLabel[]) label_list.getArray();
- for (i = 0; i < wlabel_num; i++) {
- label_pt = labels[i];
- label_pt.id = i + 1;
- label_pt.area = 0;
- label_pt.pos_x = label_pt.pos_y = 0;
- label_pt.clip_l = lxsize;// wclip[i*4+0] = lxsize;
- label_pt.clip_t = lysize;// wclip[i*4+2] = lysize;
- label_pt.clip_r = label_pt.clip_b = 0;// wclip[i*4+3] = 0;
- }
-
- for (i = 0; i < wk_max; i++) {
- label_pt = labels[label_idxtbl[i] - 1];
- work2_pt = work2[i];
- label_pt.area += work2_pt[0];
- label_pt.pos_x += work2_pt[1];
- label_pt.pos_y += work2_pt[2];
- if (label_pt.clip_l > work2_pt[3]) {
- label_pt.clip_l = work2_pt[3];
- }
- if (label_pt.clip_r < work2_pt[4]) {
- label_pt.clip_r = work2_pt[4];
- }
- if (label_pt.clip_t > work2_pt[5]) {
- label_pt.clip_t = work2_pt[5];
- }
- if (label_pt.clip_b < work2_pt[6]) {
- label_pt.clip_b = work2_pt[6];
- }
- }
-
- for (i = 0; i < wlabel_num; i++) {// for(int i = 0; i < *label_num; i++ ) {
- label_pt = labels[i];
- label_pt.pos_x /= label_pt.area;
- label_pt.pos_y /= label_pt.area;
- }
- return;
- }
-
-}
-
-/**
- * NyARLabeling_O2のworkとwork2を可変長にするためのクラス
- *
- *
- */
-final class NyARWorkHolder
-{
- private final static int ARRAY_APPEND_STEP = 256;
-
- public final int[][] work2;
-
- private int allocate_size;
-
- /**
- * 最大i_holder_size個の動的割り当てバッファを準備する。
- *
- * @param i_holder_size
- */
- public NyARWorkHolder(int i_holder_size)
- {
- // ポインタだけははじめに確保しておく
- this.work2 = new int[i_holder_size][];
- this.allocate_size = 0;
- }
-
- /**
- * i_indexで指定した番号までのバッファを準備する。
- *
- * @param i_index
- */
- public final void reserv(int i_index) throws NyARException
- {
- // アロケート済みなら即リターン
- if (this.allocate_size > i_index) {
- return;
- }
- // 要求されたインデクスは範囲外
- if (i_index >= this.work2.length) {
- throw new NyARException();
- }
- // 追加アロケート範囲を計算
- int range = i_index + ARRAY_APPEND_STEP;
- if (range >= this.work2.length) {
- range = this.work2.length;
- }
- // アロケート
- for (int i = this.allocate_size; i < range; i++) {
- this.work2[i] = new int[7];
- }
- this.allocate_size = range;
- }
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/INyARLabeling.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/INyARLabeling.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/INyARLabeling.java (revision 302)
@@ -1,43 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core.labeling;
-
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.raster.*;
-
-public interface INyARLabeling
-{
- public void attachDestination(INyARLabelingImage i_destination_image) throws NyARException;
- public INyARLabelingImage getAttachedDestination();
-
- public void labeling(NyARBinRaster i_raster) throws NyARException;
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/INyARLabelingImage.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/INyARLabelingImage.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/INyARLabelingImage.java (revision 302)
@@ -1,40 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core.labeling;
-import jp.nyatla.nyartoolkit.core.raster.*;
-
-public interface INyARLabelingImage extends INyARRaster
-{
- public int[] getIndexArray();
- public NyARLabelingLabelStack getLabelStack();
- public void reset(boolean i_label_index_enable);
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingLabel.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingLabel.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingLabel.java (revision 302)
@@ -1,44 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core.labeling;
-
-public class NyARLabelingLabel
-{
- public int id;
- public int area;
- public int clip_r;// 0
- public int clip_l;// 1
- public int clip_b;// 2
- public int clip_t;// 3
- public double pos_x;
- public double pos_y;
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingImage.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingImage.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingImage.java (revision 302)
@@ -1,181 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core.labeling;
-
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.core.raster.*;
-import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;
-import jp.nyatla.nyartoolkit.core.rasterreader.NyARBufferReader;
-import jp.nyatla.nyartoolkit.core.types.*;
-
-/**
- *
- */
-public class NyARLabelingImage extends NyARRaster_BasicClass implements INyARLabelingImage
-{
- private final static int MAX_LABELS = 1024*32;
- protected int[] _ref_buf;
- private INyARBufferReader _buffer_reader;
- protected NyARLabelingLabelStack _label_list;
- protected int[] _index_table;
- protected boolean _is_index_table_enable;
- public NyARLabelingImage(int i_width, int i_height)
- {
- super(new NyARIntSize(i_width,i_height));
- this._ref_buf =new int[i_height*i_width];
- this._label_list = new NyARLabelingLabelStack(MAX_LABELS);
- this._index_table=new int[MAX_LABELS];
- this._is_index_table_enable=false;
- this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D);
-
- return;
- }
- public INyARBufferReader getBufferReader()
- {
- return this._buffer_reader;
- }
-
-
- /**
- * ラベリング結果がインデックステーブルを持つ場合、その配列を返します。
- * 持たない場合、nullを返します。
- *
- * 値がnullの時はラベル番号そのものがラスタに格納されていますが、
- * null以外の時はラスタに格納されているのはインデクス番号です。
- *
- * インデクス番号とラベル番号の関係は、以下の式で表されます。
- * ラベル番号:=value[インデクス番号]
- *
- */
- public int[] getIndexArray()
- {
- return this._is_index_table_enable?this._index_table:null;
- }
-
- public NyARLabelingLabelStack getLabelStack()
- {
- return this._label_list;
- }
- public void reset(boolean i_label_index_enable)
- {
- assert(i_label_index_enable==true);//非ラベルモードは未実装
- this._label_list.clear();
- this._is_index_table_enable=i_label_index_enable;
- return;
- }
-
- protected final int[] _getContour_xdir = { 0, 1, 1, 1, 0,-1,-1,-1};
- protected final int[] _getContour_ydir = {-1,-1, 0, 1, 1, 1, 0,-1};
- /**
- * i_labelのラベルの、クリップ領域が上辺に接しているx座標を返します。
- * @param i_index
- * @return
- */
- protected int getTopClipTangentX(NyARLabelingLabel i_label) throws NyARException
- {
- int pix;
- int i_label_id=i_label.id;
- int[] index_table=this._index_table;
- int[] limage=this._ref_buf;
- int limage_ptr=i_label.clip_t*this._size.w;
- final int clip1 = i_label.clip_r;
- // p1=ShortPointer.wrap(limage,j*xsize+clip.get());//p1 =&(limage[j*xsize+clip[0]]);
- for (int i = i_label.clip_l; i <= clip1; i++) {// for( i = clip[0]; i <=clip[1]; i++, p1++ ) {
- pix = limage[limage_ptr+i];
- if (pix > 0 && index_table[pix-1] == i_label_id){
- return i;
- }
- }
- //あれ?見つからないよ?
- throw new NyARException();
- }
- /**
- * i_index番目のラベルの輪郭線を配列に返します。
- * @param i_index
- * @param i_array_size
- * @param o_coord_x
- * @param o_coord_y
- * @return
- * 輪郭線の長さを返します。
- * @throws NyARException
- */
- public int getContour(int i_index,int i_array_size,int[] o_coord_x,int[] o_coord_y) throws NyARException
- {
- final int width=this._size.w;
- final int[] xdir = this._getContour_xdir;// static int xdir[8] = { 0,1, 1, 1, 0,-1,-1,-1};
- final int[] ydir = this._getContour_ydir;// static int ydir[8] = {-1,-1,0, 1, 1, 1, 0,-1};
- final NyARLabelingLabel label=(NyARLabelingLabel)this._label_list.getItem(i_index);
- int i;
- //クリップ領域の上端に接しているポイントを得る。
- int sx=getTopClipTangentX(label);
- int sy=label.clip_t;
-
- int coord_num = 1;
- o_coord_x[0] = sx;
- o_coord_y[0] = sy;
- int dir = 5;
-
- int[] limage=this._ref_buf;
- int c = o_coord_x[0];
- int r = o_coord_y[0];
- for (;;) {
- dir = (dir + 5) % 8;
- for (i = 0; i < 8; i++) {
- if (limage[(r + ydir[dir])*width+(c + xdir[dir])] > 0) {
- break;
- }
- dir = (dir + 1) % 8;
- }
- if (i == 8) {
- //8方向全て調べたけどラベルが無いよ?
- throw new NyARException();// return(-1);
- }
- // xcoordとycoordをc,rにも保存
- c = c + xdir[dir];
- r = r + ydir[dir];
- o_coord_x[coord_num] = c;
- o_coord_y[coord_num] = r;
- // 終了条件判定
- if (c == sx && r == sy){
- coord_num++;
- break;
- }
- coord_num++;
- if (coord_num == i_array_size) {
- //輪郭が末端に達した
- return coord_num;
- }
- }
- return coord_num;
-
- }
-}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingLabelStack.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingLabelStack.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingLabelStack.java (revision 302)
@@ -1,86 +0,0 @@
-/*
- * PROJECT: NyARToolkit
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- * Hirokazu Kato
- * Mark Billinghurst
- * HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information please contact.
- * http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
- *
- */
-package jp.nyatla.nyartoolkit.core.labeling;
-
-import jp.nyatla.utils.*;
-
-/**
- * NyLabelの予約型動的配列
- *
- */
-public class NyARLabelingLabelStack extends NyObjectStack
-{
- protected NyARLabelingLabelStack(NyARLabelingLabel[] i_label_array)
- {
- super(i_label_array);
- }
- public NyARLabelingLabelStack(int i_max_array_size)
- {
- super(new NyARLabelingLabel[i_max_array_size]);
- }
-
- protected void onReservRequest(int i_start, int i_end, Object[] i_buffer)
- {
- for (int i = i_start; i < i_end; i++) {
- i_buffer[i] = new NyARLabelingLabel();
- }
- }
-
- /**
- * エリアの大きい順にラベルをソートします。
- */
- final public void sortByArea()
- {
- int len=this._length;
- int h = len *13/10;
- NyARLabelingLabel[] item=(NyARLabelingLabel[])this._items;
- for(;;){
- int swaps = 0;
- for (int i = 0; i + h < len; i++) {
- if (item[i + h].area > item[i].area) {
- final NyARLabelingLabel temp = item[i + h];
- item[i + h] = item[i];
- item[i] = temp;
- swaps++;
- }
- }
- if (h == 1) {
- if (swaps == 0){
- break;
- }
- }else{
- h=h*10/13;
- }
- }
- }
-}
-
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/rlelabeling/RleLabelFragmentInfoStack.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/rlelabeling/RleLabelFragmentInfoStack.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/rlelabeling/RleLabelFragmentInfoStack.java (revision 302)
@@ -0,0 +1,50 @@
+/*
+ * PROJECT: NyARToolkit(Extension)
+ * --------------------------------------------------------------------------------
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.labeling.rlelabeling;
+
+
+import jp.nyatla.nyartoolkit.core.labeling.NyARLabelInfo;
+import jp.nyatla.nyartoolkit.core.labeling.NyARLabelInfoStack;
+
+
+public class RleLabelFragmentInfoStack extends NyARLabelInfoStack<RleLabelFragmentInfoStack.RleLabelFragmentInfo>
+{
+ public class RleLabelFragmentInfo extends NyARLabelInfo
+ {
+ //継承メンバ
+ //int area; // フラグメントラベルの領域数
+ public int entry_x; // フラグメントラベルの位置
+ }
+ public RleLabelFragmentInfoStack(int i_length)
+ {
+ super(i_length, RleLabelFragmentInfoStack.RleLabelFragmentInfo.class);
+ return;
+ }
+
+ protected RleLabelFragmentInfoStack.RleLabelFragmentInfo createElement()
+ {
+ return new RleLabelFragmentInfoStack.RleLabelFragmentInfo();
+ }
+}
\ No newline at end of file
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/rlelabeling/NyARLabeling_Rle.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/rlelabeling/NyARLabeling_Rle.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/rlelabeling/NyARLabeling_Rle.java (revision 302)
@@ -0,0 +1,372 @@
+/*
+ * PROJECT: NyARToolkit(Extension)
+ * --------------------------------------------------------------------------------
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.labeling.rlelabeling;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.raster.*;
+import jp.nyatla.utils.*;
+
+class RleInfoStack extends NyObjectStack<RleInfoStack.RleInfo>
+{
+ public class RleInfo
+ {
+ //継承メンバ
+ public int entry_x; // フラグメントラベルの位置
+ public int area;
+ public int clip_r;
+ public int clip_l;
+ public int clip_b;
+ public int clip_t;
+ public long pos_x;
+ public long pos_y;
+ }
+ public RleInfoStack(int i_length)
+ {
+ super(i_length, RleInfoStack.RleInfo.class);
+ return;
+ }
+
+ protected RleInfoStack.RleInfo createElement()
+ {
+ return new RleInfoStack.RleInfo();
+ }
+}
+/**
+ * [strage class]
+ */
+
+
+class RleElement
+{
+ int l;
+ int r;
+ int fid;
+ public static RleElement[] createArray(int i_length)
+ {
+ RleElement[] ret = new RleElement[i_length];
+ for (int i = 0; i < i_length; i++) {
+ ret[i] = new RleElement();
+ }
+ return ret;
+ }
+}
+
+// RleImageをラベリングする。
+public class NyARLabeling_Rle
+{
+ private static final int AR_AREA_MAX = 100000;// #define AR_AREA_MAX 100000
+ private static final int AR_AREA_MIN = 70;// #define AR_AREA_MIN 70
+
+ private RleInfoStack _rlestack;
+ private RleElement[] _rle1;
+ private RleElement[] _rle2;
+ private int _max_area;
+ private int _min_area;
+
+ public NyARLabeling_Rle(int i_width,int i_height)
+ {
+ this._rlestack=new RleInfoStack(i_width*i_height*2048/(320*240)+32);
+ this._rle1 = RleElement.createArray(i_width/2+1);
+ this._rle2 = RleElement.createArray(i_width/2+1);
+ setAreaRange(AR_AREA_MAX,AR_AREA_MIN);
+
+ return;
+ }
+ /**
+ * 対象サイズ
+ * @param i_max
+ * @param i_min
+ */
+ public void setAreaRange(int i_max,int i_min)
+ {
+ this._max_area=i_max;
+ this._min_area=i_min;
+ return;
+ }
+
+ /**
+ * i_bin_bufのbinイメージをREL圧縮する。
+ *
+ * @param i_bin_raster
+ */
+ private int toRel(int[] i_bin_buf, int i_st, int i_len, RleElement[] i_out)
+ {
+ int current = 0;
+ int r = -1;
+ // 行確定開始
+ int x = i_st;
+ final int right_edge = i_st + i_len - 1;
+ while (x < right_edge) {
+ // 暗点(0)スキャン
+ if (i_bin_buf[x] != 0) {
+ x++;
+ continue;
+ }
+ // 暗点発見→暗点長を調べる
+ r = (x - i_st);
+ i_out[current].l = r;
+ r++;// 暗点+1
+ x++;
+ while (x < right_edge) {
+ if (i_bin_buf[x] != 0) {
+ // 明点(1)→暗点(0)配列終了>登録
+ i_out[current].r = r;
+ current++;
+ x++;// 次点の確認。
+ r = -1;// 右端の位置を0に。
+ break;
+ } else {
+ // 暗点(0)長追加
+ r++;
+ x++;
+ }
+ }
+ }
+ // 最後の1点だけ判定方法が少し違うの。
+ if (i_bin_buf[x] != 0) {
+ // 明点→rカウント中なら暗点配列終了>登録
+ if (r >= 0) {
+ i_out[current].r = r;
+ current++;
+ }
+ } else {
+ // 暗点→カウント中でなければl1で追加
+ if (r >= 0) {
+ i_out[current].r = (r + 1);
+ } else {
+ // 最後の1点の場合
+ i_out[current].l = (i_len - 1);
+ i_out[current].r = (i_len);
+ }
+ current++;
+ }
+ // 行確定
+ return current;
+ }
+
+ private void addFragment(RleElement i_rel_img, int i_nof, int i_row_index,RleInfoStack o_stack) throws NyARException
+ {
+ int l=i_rel_img.l;
+ final int len=i_rel_img.r - l;
+ i_rel_img.fid = i_nof;// REL毎の固有ID
+ RleInfoStack.RleInfo v = o_stack.prePush();
+ v.entry_x = l;
+ v.area =len;
+ v.clip_l=l;
+ v.clip_r=i_rel_img.r-1;
+ v.clip_t=i_row_index;
+ v.clip_b=i_row_index;
+ v.pos_x=(len*(2*l+(len-1)))/2;
+ v.pos_y=i_row_index*len;
+
+ return;
+ }
+
+ //
+ public int labeling(NyARBinRaster i_bin_raster, int i_top, int i_bottom,RleLabelFragmentInfoStack o_stack) throws NyARException
+ {
+ // リセット処理
+ final RleInfoStack rlestack=this._rlestack;
+ rlestack.clear();
+
+ //
+ RleElement[] rle_prev = this._rle1;
+ RleElement[] rle_current = this._rle2;
+ int len_prev = 0;
+ int len_current = 0;
+ final int width = i_bin_raster.getWidth();
+ int[] in_buf = (int[]) i_bin_raster.getBufferReader().getBuffer();
+
+ int id_max = 0;
+ int label_count=0;
+ // 初段登録
+
+ len_prev = toRel(in_buf, i_top, width, rle_prev);
+ for (int i = 0; i < len_prev; i++) {
+ // フラグメントID=フラグメント初期値、POS=Y値、RELインデクス=行
+ addFragment(rle_prev[i], id_max, i_top,rlestack);
+ id_max++;
+ // nofの最大値チェック
+ label_count++;
+ }
+ RleInfoStack.RleInfo[] f_array = rlestack.getArray();
+ // 次段結合
+ for (int y = i_top + 1; y < i_bottom; y++) {
+ // カレント行の読込
+ len_current = toRel(in_buf, y * width, width, rle_current);
+ int index_prev = 0;
+
+ SCAN_CUR: for (int i = 0; i < len_current; i++) {
+ // index_prev,len_prevの位置を調整する
+ int id = -1;
+ // チェックすべきprevがあれば確認
+ SCAN_PREV: while (index_prev < len_prev) {
+ if (rle_current[i].l - rle_prev[index_prev].r > 0) {// 0なら8方位ラベリング
+ // prevがcurの左方にある→次のフラグメントを探索
+ index_prev++;
+ continue;
+ } else if (rle_prev[index_prev].l - rle_current[i].r > 0) {// 0なら8方位ラベリングになる
+ // prevがcur右方にある→独立フラグメント
+ addFragment(rle_current[i], id_max, y,rlestack);
+ id_max++;
+ label_count++;
+ // 次のindexをしらべる
+ continue SCAN_CUR;
+ }
+ id=rle_prev[index_prev].fid;//ルートフラグメントid
+ RleInfoStack.RleInfo id_ptr = f_array[id];
+ //結合対象(初回)->prevのIDをコピーして、ルートフラグメントの情報を更新
+ rle_current[i].fid = id;//フラグメントIDを保存
+ //
+ final int l= rle_current[i].l;
+ final int r= rle_current[i].r;
+ final int len=r-l;
+ //結合先フラグメントの情報を更新する。
+ id_ptr.area += len;
+ //tとentry_xは、結合先のを使うので更新しない。
+ id_ptr.clip_l=l<id_ptr.clip_l?l:id_ptr.clip_l;
+ id_ptr.clip_r=r>id_ptr.clip_r?r-1:id_ptr.clip_r;
+ id_ptr.clip_b=y;
+ id_ptr.pos_x+=(len*(2*l+(len-1)))/2;
+ id_ptr.pos_y+=y*len;
+ //多重結合の確認(2個目以降)
+ index_prev++;
+ while (index_prev < len_prev) {
+ if (rle_current[i].l - rle_prev[index_prev].r > 0) {// 0なら8方位ラベリング
+ // prevがcurの左方にある→prevはcurに連結していない。
+ break SCAN_PREV;
+ } else if (rle_prev[index_prev].l - rle_current[i].r > 0) {// 0なら8方位ラベリングになる
+ // prevがcurの右方にある→prevはcurに連結していない。
+ index_prev--;
+ continue SCAN_CUR;
+ }
+ // prevとcurは連結している→ルートフラグメントの統合
+
+ //結合するルートフラグメントを取得
+ final int prev_id =rle_prev[index_prev].fid;
+ RleInfoStack.RleInfo prev_ptr = f_array[prev_id];
+ if (id != prev_id){
+ label_count--;
+ //prevとcurrentのフラグメントidを書き換える。
+ for(int i2=index_prev;i2<len_prev;i2++){
+ //prevは現在のidから最後まで
+ if(rle_prev[i2].fid==prev_id){
+ rle_prev[i2].fid=id;
+ }
+ }
+ for(int i2=0;i2<i;i2++){
+ //currentは0から現在-1まで
+ if(rle_current[i2].fid==prev_id){
+ rle_current[i2].fid=id;
+ }
+ }
+
+ //現在のルートフラグメントに情報を集約
+ id_ptr.area +=prev_ptr.area;
+ id_ptr.pos_x+=prev_ptr.pos_x;
+ id_ptr.pos_y+=prev_ptr.pos_y;
+ //tとentry_xの決定
+ if (id_ptr.clip_t > prev_ptr.clip_t) {
+ // 現在の方が下にある。
+ id_ptr.clip_t = prev_ptr.clip_t;
+ id_ptr.entry_x = prev_ptr.entry_x;
+ }else if (id_ptr.clip_t < prev_ptr.clip_t) {
+ // 現在の方が上にある。prevにフィードバック
+ } else {
+ // 水平方向で小さい方がエントリポイント。
+ if (id_ptr.entry_x > prev_ptr.entry_x) {
+ id_ptr.entry_x = prev_ptr.entry_x;
+ }else{
+ }
+ }
+ //lの決定
+ if (id_ptr.clip_l > prev_ptr.clip_l) {
+ id_ptr.clip_l=prev_ptr.clip_l;
+ }else{
+ }
+ //rの決定
+ if (id_ptr.clip_r < prev_ptr.clip_r) {
+ id_ptr.clip_r=prev_ptr.clip_r;
+ }else{
+ }
+ //bの決定
+
+ //結合済のルートフラグメントを無効化する。
+ prev_ptr.area=0;
+ }
+
+
+ index_prev++;
+ }
+ index_prev--;
+ break;
+ }
+ // curにidが割り当てられたかを確認
+ // 右端独立フラグメントを追加
+ if (id < 0){
+ addFragment(rle_current[i], id_max, y,rlestack);
+ id_max++;
+ label_count++;
+ }
+ }
+ // prevとrelの交換
+ RleElement[] tmp = rle_prev;
+ rle_prev = rle_current;
+ len_prev = len_current;
+ rle_current = tmp;
+ }
+ //対象のラベルだけ転写
+ o_stack.reserv(label_count);
+ RleLabelFragmentInfoStack.RleLabelFragmentInfo[] o_dest_array=o_stack.getArray();
+ final int max=this._max_area;
+ final int min=this._min_area;
+ int active_labels=0;
+ for(int i=id_max-1;i>=0;i--){
+ final int area=f_array[i].area;
+ if(area<min || area>max){//対象外のエリア0のもminではじく
+ continue;
+ }
+ //
+ final RleInfoStack.RleInfo src_info=f_array[i];
+ final RleLabelFragmentInfoStack.RleLabelFragmentInfo dest_info=o_dest_array[active_labels];
+ dest_info.area=area;
+ dest_info.clip_b=src_info.clip_b;
+ dest_info.clip_r=src_info.clip_r;
+ dest_info.clip_t=src_info.clip_t;
+ dest_info.clip_l=src_info.clip_l;
+ dest_info.entry_x=src_info.entry_x;
+ dest_info.pos_x=src_info.pos_x/src_info.area;
+ dest_info.pos_y=src_info.pos_y/src_info.area;
+ active_labels++;
+ }
+ //ラベル数を再設定
+ o_stack.pops(label_count-active_labels);
+ //ラベル数を返却
+ return active_labels;
+ }
+}
+
+
+
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelInfo.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelInfo.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelInfo.java (revision 302)
@@ -0,0 +1,46 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.labeling;
+
+/**
+ *
+ *
+ */
+public class NyARLabelInfo
+{
+ public int area;
+ public int clip_r;
+ public int clip_l;
+ public int clip_b;
+ public int clip_t;
+ public double pos_x;
+ public double pos_y;
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/artoolkit/NyARLabeling_ARToolKit.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/artoolkit/NyARLabeling_ARToolKit.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/artoolkit/NyARLabeling_ARToolKit.java (revision 302)
@@ -0,0 +1,317 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.labeling.artoolkit;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.raster.*;
+import jp.nyatla.nyartoolkit.core.types.*;
+
+/**
+ * ARToolKit互換のラベリングクラスです。 ARToolKitと同一な評価結果を返します。
+ *
+ */
+final public class NyARLabeling_ARToolKit
+{
+ private static final int WORK_SIZE = 1024 * 32;// #define WORK_SIZE 1024*32
+
+ private final NyARWorkHolder work_holder = new NyARWorkHolder(WORK_SIZE);
+
+
+ /**
+ * static ARInt16 *labeling2( ARUint8 *image, int thresh,int *label_num, int **area, double **pos, int **clip,int **label_ref, int LorR ) 関数の代替品
+ * ラスタimageをラベリングして、結果を保存します。 Optimize:STEP[1514->1493]
+ *
+ * @param i_raster
+ * @throws NyARException
+ */
+ public int labeling(NyARBinRaster i_raster,NyARLabelingImage o_destination) throws NyARException
+ {
+ int label_img_ptr1, label_pixel;
+ int i, j;
+ int n, k; /* work */
+
+ // サイズチェック
+ NyARIntSize in_size = i_raster.getSize();
+ assert(o_destination.getSize().isEqualSize(in_size));
+
+ final int lxsize = in_size.w;// lxsize = arUtil_c.arImXsize;
+ final int lysize = in_size.h;// lysize = arUtil_c.arImYsize;
+ final int[] label_img = (int[]) o_destination.getBufferReader().getBuffer();
+
+ // 枠作成はインスタンスを作った直後にやってしまう。
+
+ // ラベリング情報のリセット(ラベリングインデックスを使用)
+ o_destination.reset(true);
+
+ int[] label_idxtbl = o_destination.getIndexArray();
+ int[] raster_buf = (int[]) i_raster.getBufferReader().getBuffer();
+
+ int[] work2_pt;
+ int wk_max = 0;
+
+ int pixel_index;
+ int[][] work2 = this.work_holder.work2;
+
+ // [1,1](ptr0)と、[0,1](ptr1)のインデクス値を計算する。
+ for (j = 1; j < lysize - 1; j++) {// for (int j = 1; j < lysize - 1;j++, pnt += poff*2, pnt2 += 2) {
+ pixel_index = j * lxsize + 1;
+ label_img_ptr1 = pixel_index - lxsize;// label_img_pt1 = label_img[j - 1];
+ for (i = 1; i < lxsize - 1; i++, pixel_index++, label_img_ptr1++) {// for(int i = 1; i < lxsize-1;i++, pnt+=poff, pnt2++) {
+ // RGBの合計値が閾値より小さいかな?
+ if (raster_buf[pixel_index] != 0) {
+ label_img[pixel_index] = 0;// label_img_pt0[i] = 0;// *pnt2 = 0;
+ } else {
+ // pnt1 = ShortPointer.wrap(pnt2, -lxsize);//pnt1 =&(pnt2[-lxsize]);
+ if (label_img[label_img_ptr1] > 0) {// if (label_img_pt1[i] > 0) {// if( *pnt1 > 0 ) {
+ label_pixel = label_img[label_img_ptr1];// label_pixel = label_img_pt1[i];// *pnt2 = *pnt1;
+
+ work2_pt = work2[label_pixel - 1];
+ work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
+ work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
+ work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
+ work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
+ } else if (label_img[label_img_ptr1 + 1] > 0) {// } else if (label_img_pt1[i + 1] > 0) {// }else if(*(pnt1+1) > 0 ) {
+ if (label_img[label_img_ptr1 - 1] > 0) {// if (label_img_pt1[i - 1] > 0) {// if( *(pnt1-1) > 0 ) {
+ label_pixel = label_idxtbl[label_img[label_img_ptr1 + 1] - 1];// m = label_idxtbl[label_img_pt1[i + 1] - 1];// m
+ // =work[*(pnt1+1)-1];
+ n = label_idxtbl[label_img[label_img_ptr1 - 1] - 1];// n = label_idxtbl[label_img_pt1[i - 1] - 1];// n =work[*(pnt1-1)-1];
+ if (label_pixel > n) {
+ // wk=IntPointer.wrap(work, 0);//wk = &(work[0]);
+ for (k = 0; k < wk_max; k++) {
+ if (label_idxtbl[k] == label_pixel) {// if( *wk == m )
+ label_idxtbl[k] = n;// *wk = n;
+ }
+ }
+ label_pixel = n;// *pnt2 = n;
+ } else if (label_pixel < n) {
+ // wk=IntPointer.wrap(work,0);//wk = &(work[0]);
+ for (k = 0; k < wk_max; k++) {
+ if (label_idxtbl[k] == n) {// if( *wk == n ){
+ label_idxtbl[k] = label_pixel;// *wk = m;
+ }
+ }
+ }
+ work2_pt = work2[label_pixel - 1];
+ work2_pt[0]++;
+ work2_pt[1] += i;
+ work2_pt[2] += j;
+ work2_pt[6] = j;
+ } else if ((label_img[pixel_index - 1]) > 0) {// } else if ((label_img_pt0[i - 1]) > 0) {// }else if(*(pnt2-1) > 0) {
+ label_pixel = label_idxtbl[label_img[label_img_ptr1 + 1] - 1];// m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1];
+ n = label_idxtbl[label_img[pixel_index - 1] - 1];// n = label_idxtbl[label_img_pt0[i - 1] - 1];// n =work[*(pnt2-1)-1];
+ if (label_pixel > n) {
+ for (k = 0; k < wk_max; k++) {
+ if (label_idxtbl[k] == label_pixel) {// if( *wk == m ){
+ label_idxtbl[k] = n;// *wk = n;
+ }
+ }
+ label_pixel = n;// *pnt2 = n;
+ } else if (label_pixel < n) {
+ for (k = 0; k < wk_max; k++) {
+ if (label_idxtbl[k] == n) {// if( *wk == n ){
+ label_idxtbl[k] = label_pixel;// *wk = m;
+ }
+ }
+ }
+ work2_pt = work2[label_pixel - 1];
+ work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
+ work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
+ work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
+ } else {
+
+ label_pixel = label_img[label_img_ptr1 + 1];// label_pixel = label_img_pt1[i + 1];// *pnt2 =
+ // *(pnt1+1);
+
+ work2_pt = work2[label_pixel - 1];
+ work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
+ work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
+ work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
+ if (work2_pt[3] > i) {// if(work2[((*pnt2)-1)*7+3] > i ){
+ work2_pt[3] = i;// work2[((*pnt2)-1)*7+3] = i;
+ }
+ work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
+ }
+ } else if ((label_img[label_img_ptr1 - 1]) > 0) {// } else if ((label_img_pt1[i - 1]) > 0) {// }else if(
+ // *(pnt1-1) > 0 ) {
+ label_pixel = label_img[label_img_ptr1 - 1];// label_pixel = label_img_pt1[i - 1];// *pnt2 =
+ // *(pnt1-1);
+
+ work2_pt = work2[label_pixel - 1];
+ work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
+ work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
+ work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
+ if (work2_pt[4] < i) {// if( work2[((*pnt2)-1)*7+4] <i ){
+ work2_pt[4] = i;// work2[((*pnt2)-1)*7+4] = i;
+ }
+ work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;
+ } else if (label_img[pixel_index - 1] > 0) {// } else if (label_img_pt0[i - 1] > 0) {// }else if(*(pnt2-1) > 0) {
+ label_pixel = label_img[pixel_index - 1];// label_pixel = label_img_pt0[i - 1];// *pnt2 =*(pnt2-1);
+
+ work2_pt = work2[label_pixel - 1];
+ work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;
+ work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;
+ work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;
+ if (work2_pt[4] < i) {// if( work2[((*pnt2)-1)*7+4] <i ){
+ work2_pt[4] = i;// work2[((*pnt2)-1)*7+4] = i;
+ }
+ } else {
+ // 現在地までの領域を予約
+ this.work_holder.reserv(wk_max);
+ wk_max++;
+ label_idxtbl[wk_max - 1] = wk_max;
+ label_pixel = wk_max;// work[wk_max-1] = *pnt2 = wk_max;
+ work2_pt = work2[wk_max - 1];
+ work2_pt[0] = 1;
+ work2_pt[1] = i;
+ work2_pt[2] = j;
+ work2_pt[3] = i;
+ work2_pt[4] = i;
+ work2_pt[5] = j;
+ work2_pt[6] = j;
+ }
+ label_img[pixel_index] = label_pixel;// label_img_pt0[i] = label_pixel;
+ }
+ }
+
+ }
+ // インデックステーブルとラベル数の計算
+ int wlabel_num = 1;// *label_num = *wlabel_num = j - 1;
+
+ for (i = 0; i < wk_max; i++) {// for(int i = 1; i <= wk_max; i++,wk++) {
+ label_idxtbl[i] = (label_idxtbl[i] == i + 1) ? wlabel_num++ : label_idxtbl[label_idxtbl[i] - 1];// *wk=(*wk==i)?j++:work[(*wk)-1];
+ }
+ wlabel_num -= 1;// *label_num = *wlabel_num = j - 1;
+ if (wlabel_num == 0) {// if( *label_num == 0 ) {
+ // 発見数0
+ o_destination.getLabelStack().clear();
+ return 0;
+ }
+ // ラベル情報の保存等
+ NyARLabelingLabelStack label_list = o_destination.getLabelStack();
+
+ // ラベルバッファを予約
+ label_list.reserv(wlabel_num);
+
+ // エリアと重心、クリップ領域を計算
+ NyARLabelingLabel label_pt;
+ NyARLabelingLabel[] labels =label_list.getArray();
+ for (i = 0; i < wlabel_num; i++) {
+ label_pt = labels[i];
+ label_pt.id = (short)(i + 1);
+ label_pt.area = 0;
+ label_pt.pos_x = label_pt.pos_y = 0;
+ label_pt.clip_l = lxsize;// wclip[i*4+0] = lxsize;
+ label_pt.clip_t = lysize;// wclip[i*4+2] = lysize;
+ label_pt.clip_r = label_pt.clip_b = 0;// wclip[i*4+3] = 0;
+ }
+
+ for (i = 0; i < wk_max; i++) {
+ label_pt = labels[label_idxtbl[i] - 1];
+ work2_pt = work2[i];
+ label_pt.area += work2_pt[0];
+ label_pt.pos_x += work2_pt[1];
+ label_pt.pos_y += work2_pt[2];
+ if (label_pt.clip_l > work2_pt[3]) {
+ label_pt.clip_l = work2_pt[3];
+ }
+ if (label_pt.clip_r < work2_pt[4]) {
+ label_pt.clip_r = work2_pt[4];
+ }
+ if (label_pt.clip_t > work2_pt[5]) {
+ label_pt.clip_t = work2_pt[5];
+ }
+ if (label_pt.clip_b < work2_pt[6]) {
+ label_pt.clip_b = work2_pt[6];
+ }
+ }
+
+ for (i = 0; i < wlabel_num; i++) {// for(int i = 0; i < *label_num; i++ ) {
+ label_pt = labels[i];
+ label_pt.pos_x /= label_pt.area;
+ label_pt.pos_y /= label_pt.area;
+ }
+ return wlabel_num;
+ }
+
+}
+
+/**
+ * NyARLabeling_O2のworkとwork2を可変長にするためのクラス
+ *
+ *
+ */
+final class NyARWorkHolder
+{
+ private final static int ARRAY_APPEND_STEP = 256;
+
+ public final int[][] work2;
+
+ private int allocate_size;
+
+ /**
+ * 最大i_holder_size個の動的割り当てバッファを準備する。
+ *
+ * @param i_holder_size
+ */
+ public NyARWorkHolder(int i_holder_size)
+ {
+ // ポインタだけははじめに確保しておく
+ this.work2 = new int[i_holder_size][];
+ this.allocate_size = 0;
+ }
+
+ /**
+ * i_indexで指定した番号までのバッファを準備する。
+ *
+ * @param i_index
+ */
+ public final void reserv(int i_index) throws NyARException
+ {
+ // アロケート済みなら即リターン
+ if (this.allocate_size > i_index) {
+ return;
+ }
+ // 要求されたインデクスは範囲外
+ if (i_index >= this.work2.length) {
+ throw new NyARException();
+ }
+ // 追加アロケート範囲を計算
+ int range = i_index + ARRAY_APPEND_STEP;
+ if (range >= this.work2.length) {
+ range = this.work2.length;
+ }
+ // アロケート
+ for (int i = this.allocate_size; i < range; i++) {
+ this.work2[i] = new int[7];
+ }
+ this.allocate_size = range;
+ }
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/artoolkit/NyARLabelingLabel.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/artoolkit/NyARLabelingLabel.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/artoolkit/NyARLabelingLabel.java (revision 302)
@@ -0,0 +1,42 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.labeling.artoolkit;
+
+import jp.nyatla.nyartoolkit.core.labeling.*;
+/**
+ * [[Strage class]]
+ *
+ */
+public class NyARLabelingLabel extends NyARLabelInfo
+{
+ public int id; // フラグメントラベルのインデクス
+
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/artoolkit/NyARLabelingImage.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/artoolkit/NyARLabelingImage.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/artoolkit/NyARLabelingImage.java (revision 302)
@@ -0,0 +1,141 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.labeling.artoolkit;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.raster.*;
+import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;
+import jp.nyatla.nyartoolkit.core.rasterreader.NyARBufferReader;
+import jp.nyatla.nyartoolkit.core.types.*;
+
+/**
+ *
+ */
+public class NyARLabelingImage extends NyARRaster_BasicClass
+{
+ private final static int MAX_LABELS = 1024*32;
+ protected int[] _ref_buf;
+ private INyARBufferReader _buffer_reader;
+ protected NyARLabelingLabelStack _label_list;
+ protected int[] _index_table;
+ protected boolean _is_index_table_enable;
+ public NyARLabelingImage(int i_width, int i_height)
+ {
+ super(new NyARIntSize(i_width,i_height));
+ this._ref_buf =new int[i_height*i_width];
+ this._label_list = new NyARLabelingLabelStack(MAX_LABELS);
+ this._index_table=new int[MAX_LABELS];
+ this._is_index_table_enable=false;
+ this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D);
+ //生成時に枠を書きます。
+ drawFrameEdge();
+ return;
+ }
+ public INyARBufferReader getBufferReader()
+ {
+ return this._buffer_reader;
+ }
+ /**
+ * エッジを書きます。
+ */
+ public void drawFrameEdge()
+ {
+ int w=this._size.w;
+ int h=this._size.h;
+ // NyLabelingImageのイメージ初期化(枠書き)
+ int[] img = (int[]) this._ref_buf;
+ int bottom_ptr = (h - 1) * w;
+ for (int i = 0; i < w; i++) {
+ img[i] = 0;
+ img[bottom_ptr + i] = 0;
+ }
+ for (int i = 0; i < h; i++) {
+ img[i * w] = 0;
+ img[(i + 1) * w - 1] = 0;
+ }
+ return;
+ }
+
+ /**
+ * ラベリング結果がインデックステーブルを持つ場合、その配列を返します。
+ * 持たない場合、nullを返します。
+ *
+ * 値がnullの時はラベル番号そのものがラスタに格納されていますが、
+ * null以外の時はラスタに格納されているのはインデクス番号です。
+ *
+ * インデクス番号とラベル番号の関係は、以下の式で表されます。
+ * ラベル番号:=value[インデクス番号]
+ *
+ */
+ public int[] getIndexArray()
+ {
+ return this._is_index_table_enable?this._index_table:null;
+ }
+
+ public NyARLabelingLabelStack getLabelStack()
+ {
+ return this._label_list;
+ }
+ public void reset(boolean i_label_index_enable)
+ {
+ assert(i_label_index_enable==true);//非ラベルモードは未実装
+ this._label_list.clear();
+ this._is_index_table_enable=i_label_index_enable;
+ return;
+ }
+ //巡回参照できるように、テーブルを二重化
+ // 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
+ protected final static int[] _getContour_xdir = { 0, 1, 1, 1, 0,-1,-1,-1 , 0, 1, 1, 1, 0,-1,-1};
+ protected final static int[] _getContour_ydir = {-1,-1, 0, 1, 1, 1, 0,-1 ,-1,-1, 0, 1, 1, 1, 0};
+ /**
+ * i_labelのラベルの、クリップ領域が上辺に接しているx座標を返します。
+ * @param i_index
+ * @return
+ */
+ public int getTopClipTangentX(NyARLabelingLabel i_label) throws NyARException
+ {
+ int pix;
+ int i_label_id=i_label.id;
+ int[] index_table=this._index_table;
+ int[] limage=this._ref_buf;
+ int limage_ptr=i_label.clip_t*this._size.w;
+ final int clip1 = i_label.clip_r;
+ // p1=ShortPointer.wrap(limage,j*xsize+clip.get());//p1 =&(limage[j*xsize+clip[0]]);
+ for (int i = i_label.clip_l; i <= clip1; i++) {// for( i = clip[0]; i <=clip[1]; i++, p1++ ) {
+ pix = limage[limage_ptr+i];
+ if (pix > 0 && index_table[pix-1] == i_label_id){
+ return i;
+ }
+ }
+ //あれ?見つからないよ?
+ throw new NyARException();
+ }
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/artoolkit/NyARLabelingLabelStack.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/artoolkit/NyARLabelingLabelStack.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/artoolkit/NyARLabelingLabelStack.java (revision 302)
@@ -0,0 +1,52 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.labeling.artoolkit;
+
+
+
+import jp.nyatla.nyartoolkit.core.labeling.*;
+
+/**
+ * NyLabelの予約型動的配列
+ *
+ */
+public class NyARLabelingLabelStack extends NyARLabelInfoStack<NyARLabelingLabel>
+{
+ public NyARLabelingLabelStack(int i_max_array_size)
+ {
+ super(i_max_array_size,NyARLabelingLabel.class);
+ }
+ protected NyARLabelingLabel createElement()
+ {
+ return new NyARLabelingLabel();
+ }
+}
+
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelInfoStack.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelInfoStack.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelInfoStack.java (revision 302)
@@ -0,0 +1,78 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.labeling;
+
+
+import jp.nyatla.utils.*;
+
+/**
+ * NyLabelの予約型動的配列
+ *
+ */
+public abstract class NyARLabelInfoStack<T extends NyARLabelInfo> extends NyObjectStack<T>
+{
+ public NyARLabelInfoStack(int i_length,Class<T> i_element_type)
+ {
+ super(i_length,i_element_type);
+ }
+
+ /**
+ * エリアの大きい順にラベルをソートします。
+ */
+ final public void sortByArea()
+ {
+ int len=this._length;
+ if(len<1){
+ return;
+ }
+ int h = len *13/10;
+ T[] item=this._items;
+ for(;;){
+ int swaps = 0;
+ for (int i = 0; i + h < len; i++) {
+ if (item[i + h].area > item[i].area) {
+ final T temp = item[i + h];
+ item[i + h] = item[i];
+ item[i] = temp;
+ swaps++;
+ }
+ }
+ if (h == 1) {
+ if (swaps == 0){
+ break;
+ }
+ }else{
+ h=h*10/13;
+ }
+ }
+ }
+}
+
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/LabelOverlapChecker.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/LabelOverlapChecker.java (revision 0)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/core/labeling/LabelOverlapChecker.java (revision 302)
@@ -0,0 +1,104 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ * http://nyatla.jp/nyatoolkit/
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ */
+package jp.nyatla.nyartoolkit.core.labeling;
+
+import java.lang.reflect.Array;
+
+
+/**
+ * ラベル同士の重なり(内包関係)を調べるクラスです。
+ * ラベルリストに内包するラベルを蓄積し、それにターゲットのラベルが内包されているか を確認します。
+ */
+public class LabelOverlapChecker<T extends NyARLabelInfo>
+{
+ private T[] _labels;
+ private int _length;
+ private Class<T> _element_type;
+ /*
+ */
+ @SuppressWarnings("unchecked")
+ public LabelOverlapChecker(int i_max_label,Class<T> i_element_type)
+ {
+ this._element_type=i_element_type;
+ this._labels = (T[])Array.newInstance(i_element_type, i_max_label);
+ }
+
+ /**
+ * チェック対象のラベルを追加する。
+ *
+ * @param i_label_ref
+ */
+ public void push(T i_label_ref)
+ {
+ this._labels[this._length] = i_label_ref;
+ this._length++;
+ }
+
+ /**
+ * 現在リストにあるラベルと重なっているかを返す。
+ *
+ * @param i_label
+ * @return 何れかのラベルの内側にあるならばfalse,独立したラベルである可能性が高ければtrueです.
+ */
+ public boolean check(T i_label)
+ {
+ // 重なり処理かな?
+ final T[] label_pt = this._labels;
+ final int px1 = (int) i_label.pos_x;
+ final int py1 = (int) i_label.pos_y;
+ for (int i = this._length - 1; i >= 0; i--) {
+ final int px2 = (int) label_pt[i].pos_x;
+ final int py2 = (int) label_pt[i].pos_y;
+ final int d = (px1 - px2) * (px1 - px2) + (py1 - py2) * (py1 - py2);
+ if (d < label_pt[i].area / 4) {
+ // 対象外
+ return false;
+ }
+ }
+ // 対象
+ return true;
+ }
+ /**
+ * 最大i_max_label個のラベルを蓄積できるようにオブジェクトをリセットする
+ *
+ * @param i_max_label
+ */
+ @SuppressWarnings("unchecked")
+ public void setMaxLabels(int i_max_label)
+ {
+ if (i_max_label > this._labels.length) {
+ this._labels = (T[])Array.newInstance(this._element_type, i_max_label);
+ }
+ this._length = 0;
+ }
+
+
+}
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.detector;
@@ -42,6 +41,7 @@
import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;
import jp.nyatla.nyartoolkit.core.types.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.*;

/**
* 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。
@@ -51,7 +51,7 @@
*
*/
public class NyARCustomSingleDetectMarker
-{
+{
private static final int AR_SQUARE_MAX = 100;

private boolean _is_continue = false;
@@ -73,40 +73,37 @@
protected INyARRasterFilter_RgbToBin _tobin_filter;

private NyARMatchPattDeviationColorData _deviation_data;
- /**
- * 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。
- *
- * @param i_param
- * カメラパラメータを指定します。
- * @param i_code
- * 検出するARCodeを指定します。
- * @param i_marker_width
- * ARコードの物理サイズを、ミリメートルで指定します。
- * @param i_filter
- * RGB→BIN変換フィルタを指定します。
- * @throws NyARException
- */
- public NyARCustomSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width,INyARRasterFilter_RgbToBin i_filter) throws NyARException
+
+ protected NyARCustomSingleDetectMarker()
{
- final NyARIntSize scr_size=i_param.getScreenSize();
+ return;
+ }
+ protected void initInstance(
+ INyARColorPatt i_patt_inst,
+ INyARSquareDetector i_sqdetect_inst,
+ INyARTransMat i_transmat_inst,
+ INyARRasterFilter_RgbToBin i_filter,
+ NyARParam i_ref_param,
+ NyARCode i_ref_code,
+ double i_marker_width) throws NyARException
+ {
+ final NyARIntSize scr_size=i_ref_param.getScreenSize();
// 解析オブジェクトを作る
- this._square_detect = new NyARSquareDetector(i_param.getDistortionFactor(),scr_size);
- this._transmat = new NyARTransMat(i_param);
+ this._square_detect = i_sqdetect_inst;
+ this._transmat = i_transmat_inst;
+ this._tobin_filter=i_filter;
// 比較コードを保存
this._marker_width = i_marker_width;
//パターンピックアップを作成
-// this._patt = new NyARColorPatt_O1(i_code.getWidth(), i_code.getHeight());
- this._patt = new NyARColorPatt_O3(i_code.getWidth(), i_code.getHeight());
-// this._patt = new NyARColorPatt_Perspective(i_code.getWidth(), i_code.getHeight(),25);
+ this._patt = i_patt_inst;
//取得パターンの差分データ器を作成
- this._deviation_data=new NyARMatchPattDeviationColorData(i_code.getWidth(),i_code.getHeight());
+ this._deviation_data=new NyARMatchPattDeviationColorData(i_ref_code.getWidth(),i_ref_code.getHeight());
//i_code用の評価器を作成
- this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA(i_code);
-
+ this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code);
//2値画像バッファを作る
this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h);
- this._tobin_filter=i_filter;
return;
+
}

private final NyARMatchPattResult __detectMarkerLite_mr=new NyARMatchPattResult();
@@ -129,8 +126,8 @@

//ラスタを2値イメージに変換する.
this._tobin_filter.doFilter(i_raster,this._bin_raster);
-
-
+
+
this._detected_square = null;
NyARSquareStack l_square_list = this._square_list;
// スクエアコードを探す
@@ -150,7 +147,7 @@
double confidence = 0;
for(int i=0;i<number_of_square;i++){
// 評価基準になるパターンをイメージから切り出す
- if (!this._patt.pickFromRaster(i_raster, (NyARSquare)l_square_list.getItem(i))){
+ if (!this._patt.pickFromRaster(i_raster, l_square_list.getItem(i))){
continue;
}
//取得パターンをカラー差分データに変換して評価する。
@@ -170,7 +167,7 @@
}

// マーカー情報を保存
- this._detected_square = (NyARSquare)l_square_list.getItem(square_index);
+ this._detected_square = l_square_list.getItem(square_index);
this._detected_direction = direction;
this._detected_confidence = confidence;
return result;
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/detector/NyARDetectMarker.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/detector/NyARDetectMarker.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/detector/NyARDetectMarker.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.detector;
@@ -40,6 +39,10 @@
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
import jp.nyatla.nyartoolkit.core.transmat.*;
import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.INyARSquareDetector;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareDetector_Rle;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;
import jp.nyatla.nyartoolkit.core.types.*;

class NyARDetectMarkerResult
@@ -112,41 +115,56 @@
* i_codeのマーカーサイズをミリメートルで指定した配列を指定します。 先頭からi_number_of_code個の要素には、有効な値を指定する必要があります。
* @param i_number_of_code
* i_codeに含まれる、ARCodeの数を指定します。
+ * @param i_input_raster_type
+ * 入力ラスタのピクセルタイプを指定します。この値は、INyARBufferReaderインタフェイスのgetBufferTypeの戻り値を指定します。
* @throws NyARException
*/
- public NyARDetectMarker(NyARParam i_param,NyARCode[] i_code,double[] i_marker_width, int i_number_of_code) throws NyARException
+ public NyARDetectMarker(NyARParam i_param,NyARCode[] i_code,double[] i_marker_width, int i_number_of_code,int i_input_raster_type) throws NyARException
{
- final NyARIntSize scr_size=i_param.getScreenSize();
+ initInstance(i_param,i_code,i_marker_width,i_number_of_code,i_input_raster_type);
+ return;
+ }
+ protected void initInstance(
+ NyARParam i_ref_param,
+ NyARCode[] i_ref_code,
+ double[] i_marker_width,
+ int i_number_of_code,
+ int i_input_raster_type) throws NyARException
+ {
+
+ final NyARIntSize scr_size=i_ref_param.getScreenSize();
// 解析オブジェクトを作る
- this._square_detect = new NyARSquareDetector(i_param.getDistortionFactor(),scr_size);
- this._transmat = new NyARTransMat(i_param);

+ this._transmat = new NyARTransMat(i_ref_param);
//各コード用の比較器を作る。
this._match_patt=new NyARMatchPatt_Color_WITHOUT_PCA[i_number_of_code];
- final int cw = i_code[0].getWidth();
- final int ch = i_code[0].getHeight();
- this._match_patt[0]=new NyARMatchPatt_Color_WITHOUT_PCA(i_code[0]);
+ final int cw = i_ref_code[0].getWidth();
+ final int ch = i_ref_code[0].getHeight();
+ this._match_patt[0]=new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code[0]);
for (int i = 1; i < i_number_of_code; i++){
//解像度チェック
- if (cw != i_code[i].getWidth() || ch != i_code[i].getHeight()) {
+ if (cw != i_ref_code[i].getWidth() || ch != i_ref_code[i].getHeight()) {
throw new NyARException();
}
- this._match_patt[i]=new NyARMatchPatt_Color_WITHOUT_PCA(i_code[i]);
- }
- // 評価パターンのホルダを作る
- this._patt = new NyARColorPatt_O3(cw, ch);
+ this._match_patt[i]=new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code[i]);
+ }
+ //NyARToolkitプロファイル
+ this._patt =new NyARColorPatt_Perspective_O2(cw, ch,4,25);
+ this._square_detect =new NyARSquareDetector_Rle(i_ref_param.getDistortionFactor(),i_ref_param.getScreenSize());
+ this._tobin_filter=new NyARRasterFilter_ARToolkitThreshold(100,i_input_raster_type);
+
//実サイズ保存
this._marker_width = i_marker_width;
//差分データインスタンスの作成
this._deviation_data=new NyARMatchPattDeviationColorData(cw,ch);
//2値画像バッファを作る
this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h);
- return;
+ return;
}
-
+
private NyARBinRaster _bin_raster;

- private NyARRasterFilter_ARToolkitThreshold _tobin_filter = new NyARRasterFilter_ARToolkitThreshold(100);
+ private INyARRasterFilter_RgbToBin _tobin_filter;
private final NyARMatchPattResult __detectMarkerLite_mr=new NyARMatchPattResult();

/**
@@ -167,7 +185,7 @@
}

// ラスタを2値イメージに変換する.
- this._tobin_filter.setThreshold(i_threshold);
+ ((NyARRasterFilter_ARToolkitThreshold)this._tobin_filter).setThreshold(i_threshold);
this._tobin_filter.doFilter(i_raster, this._bin_raster);

NyARSquareStack l_square_list = this._square_list;
@@ -186,7 +204,7 @@

// 1スクエア毎に、一致するコードを決定していく
for (int i = 0; i < number_of_square; i++) {
- NyARSquare square = (NyARSquare)l_square_list.getItem(i);
+ NyARSquare square = (l_square_list.getItem(i));

// 評価基準になるパターンをイメージから切り出す
if (!this._patt.pickFromRaster(i_raster, square)) {
Index: D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java
===================================================================
--- D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java (revision 248)
+++ D:/project.sorceforge/NyARToolkit/trunk/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java (revision 302)
@@ -7,26 +7,25 @@
* HITLab, University of Washington, Seattle
* http://www.hitl.washington.edu/artoolkit/
*
- * The NyARToolkit is Java version ARToolkit class library.
- * Copyright (C)2008 R.Iizuka
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
- * along with this framework; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For further information please contact.
* http://nyatla.jp/nyatoolkit/
- * <airmail(at)ebony.plala.or.jp>
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
*
*/
package jp.nyatla.nyartoolkit.detector;
@@ -34,15 +33,24 @@
import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.*;
import jp.nyatla.nyartoolkit.core.param.NyARParam;
+import jp.nyatla.nyartoolkit.core.pickup.INyARColorPatt;
import jp.nyatla.nyartoolkit.core.raster.rgb.*;
+
import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.NyARRasterFilter_ARToolkitThreshold;
-
+import jp.nyatla.nyartoolkit.core.squaredetect.*;
+import jp.nyatla.nyartoolkit.core.pickup.*;
+import jp.nyatla.nyartoolkit.core.transmat.*;
/**
* 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。
*
*/
public class NyARSingleDetectMarker extends NyARCustomSingleDetectMarker
{
+ public final static int PF_ARTOOLKIT_COMPATIBLE=1;
+ public final static int PF_NYARTOOLKIT=2;
+ public final static int PF_NYARTOOLKIT_ARTOOLKIT_FITTING=100;
+ public final static int PF_TEST2=201;
+
/**
* 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。
*
@@ -52,20 +60,72 @@
* 検出するARCodeを指定します。
* @param i_marker_width
* ARコードの物理サイズを、ミリメートルで指定します。
+ * @param i_input_raster_type
+ * 入力ラスタのピクセルタイプを指定します。この値は、INyARBufferReaderインタフェイスのgetBufferTypeの戻り値を指定します。
* @throws NyARException
*/
- public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width) throws NyARException
+ public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width,int i_input_raster_type,int i_profile_id) throws NyARException
{
- super(i_param,i_code,i_marker_width,new NyARRasterFilter_ARToolkitThreshold(100));
+ super();
+ initInstance(i_param,i_code,i_marker_width,i_input_raster_type,i_profile_id);
+ return;
}
+ public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width,int i_input_raster_type) throws NyARException
+ {
+ super();
+ initInstance(i_param,i_code,i_marker_width,i_input_raster_type,PF_NYARTOOLKIT);
+ return;
+ }
+ /**
+ * コンストラクタから呼び出す関数です。
+ * @param i_ref_param
+ * @param i_ref_code
+ * @param i_marker_width
+ * @param i_input_raster_type
+ * @param i_profile_id
+ * @throws NyARException
+ */
+ protected void initInstance(
+ NyARParam i_ref_param,
+ NyARCode i_ref_code,
+ double i_marker_width,
+ int i_input_raster_type,
+ int i_profile_