チェンジセット 3788

差分発生行の前後
無視リスト:
コミット日時:
2010/04/14 00:59:09 (3 年前)
コミッタ:
rokubou
ログメッセージ:

internal クラスをファイル化

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/FLARToolKit/trunk/libs/NyARToolKitAS3/src/jp/nyatla/nyartoolkit/as3/detector/NyARDetectMarker.as

    r3718 r3788  
    5050        { 
    5151 
    52                 private var _detect_cb:DetectSquareCB; 
     52                private var _detect_cb:NyARDetectSquareCB; 
    5353                public static const AR_SQUARE_MAX:int = 300; 
    5454                private var _is_continue:Boolean = false; 
     
    9494 
    9595                        //detectMarkerのコールバック関数 
    96                         this._detect_cb=new DetectSquareCB( 
     96                        this._detect_cb=new NyARDetectSquareCB( 
    9797                                new NyARColorPatt_Perspective_O2(cw, ch,4,25), 
    9898                                i_ref_code,i_number_of_code,i_ref_param); 
     
    203203        } 
    204204} 
    205  
    206 import jp.nyatla.nyartoolkit.as3.core.match.*; 
    207 import jp.nyatla.nyartoolkit.as3.core.pickup.*; 
    208 import jp.nyatla.nyartoolkit.as3.core.squaredetect.*; 
    209 import jp.nyatla.nyartoolkit.as3.core.*; 
    210 import jp.nyatla.nyartoolkit.as3.*; 
    211 import jp.nyatla.nyartoolkit.as3.core.types.stack.*; 
    212 import jp.nyatla.nyartoolkit.as3.core.match.*; 
    213 import jp.nyatla.nyartoolkit.as3.core.param.*; 
    214 import jp.nyatla.nyartoolkit.as3.core.raster.rgb.*; 
    215 import jp.nyatla.nyartoolkit.as3.detector.*; 
    216 import jp.nyatla.nyartoolkit.as3.core.types.*; 
    217 /** 
    218  * detectMarkerのコールバック関数 
    219  */ 
    220 class DetectSquareCB implements NyARSquareContourDetector_IDetectMarkerCallback 
    221 { 
    222         //公開プロパティ 
    223         public var result_stack:NyARDetectMarkerResultStack=new NyARDetectMarkerResultStack(NyARDetectMarker.AR_SQUARE_MAX); 
    224         //参照インスタンス 
    225         public var _ref_raster:INyARRgbRaster; 
    226         //所有インスタンス 
    227         private var _inst_patt:INyARColorPatt; 
    228         private var _deviation_data:NyARMatchPattDeviationColorData; 
    229         private var _match_patt:Vector.<NyARMatchPatt_Color_WITHOUT_PCA>; 
    230         private var __detectMarkerLite_mr:NyARMatchPattResult=new NyARMatchPattResult(); 
    231         private var _coordline:NyARCoord2Linear; 
    232          
    233         public function DetectSquareCB(i_inst_patt:INyARColorPatt, i_ref_code:Vector.<NyARCode>, i_num_of_code:int, i_param:NyARParam) 
    234         { 
    235                 var cw:int = i_ref_code[0].getWidth(); 
    236                 var ch:int = i_ref_code[0].getHeight(); 
    237  
    238                 this._inst_patt=i_inst_patt; 
    239                 this._coordline=new NyARCoord2Linear(i_param.getScreenSize(),i_param.getDistortionFactor()); 
    240                 this._deviation_data=new NyARMatchPattDeviationColorData(cw,ch); 
    241  
    242                 //NyARMatchPatt_Color_WITHOUT_PCA[]の作成 
    243                 this._match_patt=new Vector.<NyARMatchPatt_Color_WITHOUT_PCA>(i_num_of_code); 
    244                 this._match_patt[0]=new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code[0]); 
    245                 for (var i:int = 1; i < i_num_of_code; i++){ 
    246                         //解像度チェック 
    247                         if (cw != i_ref_code[i].getWidth() || ch != i_ref_code[i].getHeight()) { 
    248                                 throw new NyARException(); 
    249                         } 
    250                         this._match_patt[i]=new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code[i]); 
    251                 } 
    252                 return; 
    253         } 
    254         private var __tmp_vertex:Vector.<NyARIntPoint2d>=NyARIntPoint2d.createArray(4); 
    255         /** 
    256          * 矩形が見付かるたびに呼び出されます。 
    257          * 発見した矩形のパターンを検査して、方位を考慮した頂点データを確保します。 
    258          */ 
    259         public function onSquareDetect(i_sender:NyARSquareContourDetector,i_coordx:Vector.<int>,i_coordy:Vector.<int>,i_coor_num:int ,i_vertex_index:Vector.<int>):void 
    260         { 
    261                 var mr:NyARMatchPattResult=this.__detectMarkerLite_mr; 
    262                 //輪郭座標から頂点リストに変換 
    263                 var vertex:Vector.<NyARIntPoint2d>=this.__tmp_vertex; 
    264                 vertex[0].x=i_coordx[i_vertex_index[0]]; 
    265                 vertex[0].y=i_coordy[i_vertex_index[0]]; 
    266                 vertex[1].x=i_coordx[i_vertex_index[1]]; 
    267                 vertex[1].y=i_coordy[i_vertex_index[1]]; 
    268                 vertex[2].x=i_coordx[i_vertex_index[2]]; 
    269                 vertex[2].y=i_coordy[i_vertex_index[2]]; 
    270                 vertex[3].x=i_coordx[i_vertex_index[3]]; 
    271                 vertex[3].y=i_coordy[i_vertex_index[3]]; 
    272          
    273                 //画像を取得 
    274                 if (!this._inst_patt.pickFromRaster(this._ref_raster,vertex)){ 
    275                         return; 
    276                 } 
    277                 //取得パターンをカラー差分データに変換して評価する。 
    278                 this._deviation_data.setRaster(this._inst_patt); 
    279  
    280                 //最も一致するパターンを割り当てる。 
    281                 var square_index:int,direction:int; 
    282                 var confidence:Number; 
    283                 this._match_patt[0].evaluate(this._deviation_data,mr); 
    284                 square_index=0; 
    285                 direction=mr.direction; 
    286                 confidence=mr.confidence; 
    287                 //2番目以降 
    288                 var i:int; 
    289                 for(i=1;i<this._match_patt.length;i++){ 
    290                         this._match_patt[i].evaluate(this._deviation_data,mr); 
    291                         if (confidence > mr.confidence) { 
    292                                 continue; 
    293                         } 
    294                         // もっと一致するマーカーがあったぽい 
    295                         square_index = i; 
    296                         direction = mr.direction; 
    297                         confidence = mr.confidence; 
    298                 } 
    299                 //最も一致したマーカ情報を、この矩形の情報として記録する。 
    300                 var result:NyARDetectMarkerResult = this.result_stack.prePush(); 
    301                 result.arcode_id = square_index; 
    302                 result.confidence = confidence; 
    303  
    304                 var sq:NyARSquare=result.square; 
    305                 //directionを考慮して、squareを更新する。 
    306                 for(i=0;i<4;i++){ 
    307                         var idx:int=(i+4 - direction) % 4; 
    308                         this._coordline.coord2Line(i_vertex_index[idx],i_vertex_index[(idx+1)%4],i_coordx,i_coordy,i_coor_num,sq.line[i]); 
    309                 } 
    310                 for (i = 0; i < 4; i++) { 
    311                         //直線同士の交点計算 
    312                         if(!NyARLinear.crossPos(sq.line[i],sq.line[(i + 3) % 4],sq.sqvertex[i])){ 
    313                                 throw new NyARException();//ここのエラー復帰するならダブルバッファにすればOK 
    314                         } 
    315                 } 
    316         } 
    317         public function init(i_raster:INyARRgbRaster):void 
    318         { 
    319                 this._ref_raster=i_raster; 
    320                 this.result_stack.clear(); 
    321                  
    322         } 
    323 } 
    324  
    325  
    326 class NyARDetectMarkerResult 
    327 { 
    328         public var arcode_id:int; 
    329         public var confidence:Number; 
    330  
    331         public var square:NyARSquare=new NyARSquare(); 
    332 } 
    333  
    334  
    335 class NyARDetectMarkerResultStack extends NyARObjectStack 
    336 { 
    337         public function NyARDetectMarkerResultStack(i_length:int) 
    338         { 
    339                 super(i_length); 
    340         } 
    341         protected override function createArray(i_length:int):Vector.<Object> 
    342         { 
    343                 var ret:Vector.<NyARDetectMarkerResult>= new Vector.<NyARDetectMarkerResult>(i_length); 
    344                 for (var i:int =0; i < i_length; i++){ 
    345                         ret[i] = new NyARDetectMarkerResult(); 
    346                 } 
    347                 return Vector.<Object>(ret); 
    348         }        
    349 }