チェンジセット 1629

差分発生行の前後
無視リスト:
コミット日時:
2008/10/17 03:03:40 (3 ヶ月前)
コミッタ:
saqoosha
ログメッセージ:

NyARToolkit 2.0.0 ベースに移行。

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/FLARToolKit/trunk/src/org/libspark/flartoolkit/FLARException.as

    • 属性の設定値: svn:executable (削除)
    r1203 r1629  
    11/*  
    2  * PROJECT: FLARToolKit 
     2 * PROJECT: FLARToolkit 
    33 * -------------------------------------------------------------------------------- 
    4  * This work is based on the NyARToolKit developed by 
    5  *   R.Iizuka (nyatla) 
    6  * http://nyatla.jp/nyatoolkit/ 
     4 * This work is based on the original ARToolKit developed by 
     5 *   Hirokazu Kato 
     6 *   Mark Billinghurst 
     7 *   HITLab, University of Washington, Seattle 
     8 * http://www.hitl.washington.edu/artoolkit/ 
    79 * 
    8  * The FLARToolKit is ActionScript 3.0 version ARToolkit class library. 
    9  * Copyright (C)2008 Saqoosh
     10 * The FLARToolkit is Java version ARToolkit class library. 
     11 * Copyright (C)2008 R.Iizuk
    1012 * 
    1113 * This program is free software; you can redistribute it and/or 
     
    2426 *  
    2527 * For further information please contact. 
    26  *      http://www.libspark.org/wiki/saqoosha/FLARToolKit 
    27  *      <saq(at)saqoosha.net
     28 *      http://nyatla.jp/nyatoolkit/ 
     29 *      <airmail(at)ebony.plala.or.jp
    2830 *  
    2931 */ 
    30   
    3132package org.libspark.flartoolkit { 
    3233 
    3334        public class FLARException extends Error { 
    34                  
    35                 private static const serialVersionUID:int = 1; 
    36                  
    37                 public function FLARException(m:String = ''):void { 
    38                     super(m); 
     35 
     36//              private static const serialVersionUID:int = 1; 
     37// 
     38//              public function FLARException() 
     39//              { 
     40//                      super(); 
     41//              } 
     42//       
     43//              public function FLARException(e:FLARException) { 
     44//                              super(e); 
     45//              } 
     46 
     47                public function FLARException(m:String = '') { 
     48                        super(m); 
    3949                } 
    40                  
     50 
    4151                public static function trap(m:String):void { 
    42                     throw new FLARException("トラップ:" + m); 
     52                       throw new FLARException("トラップ:" + m); 
    4353                } 
    44                  
     54 
     55                public static function notImplement():void { 
     56                        throw new FLARException("Not Implement!"); 
     57                } 
    4558        } 
    46  
    4759} 
  • as3/FLARToolKit/trunk/src/org/libspark/flartoolkit/core/FLARCode.as

    • 属性の設定値: svn:executable (削除)
    r1203 r1629  
    11/*  
    2  * PROJECT: FLARToolKit 
     2 * PROJECT: FLARToolkit 
    33 * -------------------------------------------------------------------------------- 
    4  * This work is based on the NyARToolKit developed by 
    5  *   R.Iizuka (nyatla) 
    6  * http://nyatla.jp/nyatoolkit/ 
     4 * This work is based on the original ARToolKit developed by 
     5 *   Hirokazu Kato 
     6 *   Mark Billinghurst 
     7 *   HITLab, University of Washington, Seattle 
     8 * http://www.hitl.washington.edu/artoolkit/ 
    79 * 
    8  * The FLARToolKit is ActionScript 3.0 version ARToolkit class library. 
    9  * Copyright (C)2008 Saqoosh
     10 * The FLARToolkit is Java version ARToolkit class library. 
     11 * Copyright (C)2008 R.Iizuk
    1012 * 
    1113 * This program is free software; you can redistribute it and/or 
     
    2426 *  
    2527 * For further information please contact. 
    26  *      http://www.libspark.org/wiki/saqoosha/FLARToolKit 
    27  *      <saq(at)saqoosha.net
     28 *      http://nyatla.jp/nyatoolkit/ 
     29 *      <airmail(at)ebony.plala.or.jp
    2830 *  
    2931 */ 
     32package org.libspark.flartoolkit.core { 
     33        import org.libspark.flartoolkit.utils.ArrayUtil;         
    3034 
    31 package org.libspark.flartoolkit.core { 
    32          
    33         import org.libspark.flartoolkit.util.ArrayUtil; 
    34          
    35         import flash.events.Event; 
    36         import flash.events.EventDispatcher; 
    37         import flash.events.IOErrorEvent; 
    38         import flash.events.SecurityErrorEvent; 
    39         import flash.net.URLLoader; 
    40         import flash.net.URLLoaderDataFormat; 
    41         import flash.net.URLRequest; 
    42  
    43         [Event(name="complete",type="flash.events.Event")] 
    44         [Event(name="ioError",type="flash.events.IOErrorEvent")] 
    45         [Event(name="securityError",type="flash.events.SecurityErrorEvent")] 
    46          
    4735        /** 
    4836         * ARToolKitのマーカーコードを1個保持します。 
    49          * 
     37         *  
    5038         */ 
    51         public class FLARCode extends EventDispatcher { 
    52                  
    53                 private var pat:Array;//private int[][][][]     pat;//static int    pat[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; 
    54                 private var patpow:Array;//private double[]             patpow=new double[4];//static double patpow[AR_PATT_NUM_MAX][4]; 
    55                 private var patBW:Array;//private short[][][]   patBW;//static int    patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; 
    56                 private var patpowBW:Array;//private double[]           patpowBW=new double[4];//static double patpowBW[AR_PATT_NUM_MAX][4];     
    57                 private var width:int;//private int width,height; 
     39        public class FLARCode { 
     40 
     41                //      private int[][][][] pat;// static int 
     42                // pat[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; 
     43                private var pat:Array; 
     44 
     45                //      private double[] patpow = new double[4];// static double patpow[AR_PATT_NUM_MAX][4]; 
     46                private var patpow:Array = new Array(4); 
     47 
     48                //      private short[][][] patBW;// static int patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; 
     49                private var patBW:Array; 
     50 
     51                //      private double[] patpowBW = new double[4];// static double patpowBW[AR_PATT_NUM_MAX][4]; 
     52                private var patpowBW:Array = new Array(4); 
     53 
     54                private var width:int; 
    5855                private var height:int; 
    59                  
     56 
    6057                public function getPat():Array { 
    6158                        return pat; 
    6259                } 
    63                  
     60 
    6461                public function getPatPow():Array { 
    6562                        return patpow; 
    6663                } 
    67                  
     64 
    6865                public function getPatBW():Array { 
    6966                        return patBW; 
    7067                } 
    71                  
     68 
    7269                public function getPatPowBW():Array { 
    7370                        return patpowBW; 
    7471                } 
    75                  
     72 
    7673                public function getWidth():int { 
    7774                        return width; 
    7875                } 
    79                  
     76 
    8077                public function getHeight():int { 
    8178                        return height; 
    8279                } 
    83              
     80 
    8481                public function FLARCode(i_width:int, i_height:int) { 
    8582                        width = i_width; 
    8683                        height = i_height; 
    87                         pat = ArrayUtil.createMultidimensionalArray(4, height, width, 3);//new int[4][height][width][3];//static int    pat[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; 
    88                         patpow = new Array(4); 
    89                         patBW = ArrayUtil.createMultidimensionalArray(4, height, width);//new short[4][height][width];//static int    patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; 
    90                         patpowBW = new Array(4); 
     84                        //             pat = new int[4][height][width][3];// static int pat[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; 
     85                        pat = ArrayUtil.createJaggedArray(4, height, width, 3); 
     86                        //             patBW = new short[4][height][width];// static int patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; 
     87                        patBW = ArrayUtil.createJaggedArray(4, height, width); 
    9188                } 
    92          
    93          
     89 
    9490                /** 
    95                  * int arLoadPatt(const char *filename); 
    96                  * ARToolKitのパターンファイルをロードする。 
     91                 * int arLoadPatt( const char *filename ); ARToolKitのパターンファイルをロードする。 
     92                 * ファイル形式はBGR形式で記録されたパターンファイルであること。 
     93                 *  
    9794                 * @param filename 
    9895                 * @return 
    9996                 * @throws Exception 
    10097                 */ 
    101                 public function loadFromARFile(filedata:String):void { 
    102                         var i:int, i1:int, i2:int, i3:int; 
    103                         var token:Array = filedata.match(/\d+/g); 
    104                         for (var h:int = 0; h < 4; h++) { 
     98                //              public function loadARPattFromFile(filename:String):void { 
     99                //                      try { 
     100                //                              loadARPatt(new FileInputStream(filename)); 
     101                //                      } catch (e:Error) { 
     102                //                              // throw new FLARException(e); 
     103                //                              throw e; 
     104                //                      } 
     105                //              } 
     106 
     107                /** 
     108                 *  
     109                 * @param i_stream 
     110                 * @throws FLARException 
     111                 */ 
     112                public function loadARPatt(i_stream:String):void { 
     113                        //                      try { 
     114                        //                              var st:StreamTokenizer = new StreamTokenizer(new InputStreamReader(i_stream)); 
     115                        var token:Array = i_stream.match(/\d+/g); 
     116                        // パターンデータはGBRAで並んでる。 
     117                        for (var h:int = 0;h < 4; h++) { 
    105118                                var l:int = 0; 
    106                                 for (i3 = 0; i3 < 3; i3++) { 
    107                                         for (i2 = 0; i2 < height; i2++) { 
    108                                                 for (i1 = 0; i1 < width; i1++) { 
    109                                                         //数値のみ読み出す 
     119                                for (var i3:int = 0;i3 < 3; i3++) { 
     120                                        for (var i2:int = 0;i2 < height; i2++) { 
     121                                                for (var i1:int = 0;i1 < width; i1++) { 
     122                                                        // 数値のみ読み出す 
    110123                                                        var val:int = parseInt(token.shift()); 
    111124                                                        if (isNaN(val)) { 
    112125                                                                throw new Error(); 
    113126                                                        } 
     127                                                        //                                                              switch (st.nextToken()) {// if( fscanf(fp, "%d",&j) != 1 ) { 
     128                                                        //                                                                      case StreamTokenizer.TT_NUMBER: 
     129                                                        //                                                                              break; 
     130                                                        //                                                                      default: 
     131                                                        //                                                                              throw new FLARException(); 
     132                                                        //                                                              } 
    114133                                                        var j:int = 255 - val; 
    115                                                         //標準ファイルのパターンはBGRでならんでるからRGBに並べなおす 
     134                                                        // j = 255-j; 
     135                                                        // 標準ファイルのパターンはBGRでならんでるからRGBに並べなおす 
    116136                                                        switch (i3) { 
    117                                                                 case 0: pat[h][i2][i1][2] = j; break; 
    118                                                                 case 1: pat[h][i2][i1][1] = j; break; 
    119                                                                 case 2: pat[h][i2][i1][0] = j; break; 
     137                                                                case 0: 
     138                                                                        pat[h][i2][i1][2] = j; 
     139                                                                        break;// pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+2]= j;break; 
     140                                                                case 1: 
     141                                                                        pat[h][i2][i1][1] = j; 
     142                                                                        break;// pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+1]= j;break; 
     143                                                                case 2: 
     144                                                                        pat[h][i2][i1][0] = j; 
     145                                                                        break;// pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+0]= j;break; 
    120146                                                        } 
     147                                                        // pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+i3]= j; 
    121148                                                        if (i3 == 0) { 
    122                                                                 patBW[h][i2][i1] = j; 
     149                                                                patBW[h][i2][i1] = j;// patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1] = j; 
    123150                                                        } else { 
    124                                                                 patBW[h][i2][i1] += j; 
     151                                                                patBW[h][i2][i1] += j;// patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1] += j; 
    125152                                                        } 
    126153                                                        if (i3 == 2) { 
    127                                                                 patBW[h][i2][i1] /= 3; 
     154                                                                patBW[h][i2][i1] /= 3;// patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1]/= 3; 
    128155                                                        } 
    129156                                                        l += j; 
     
    131158                                        } 
    132159                                } 
    133                            
     160 
    134161                                l /= (height * width * 3); 
    135                                     
     162 
    136163                                var m:int = 0; 
    137                                 for (i = 0; i < height; i++) { 
    138                                         for (i2 = 0; i2 < width; i2++) { 
    139                                                 for (i3 = 0; i3 < 3; i3++) { 
     164                                for (var i:int = 0;i < height; i++) { 
     165                                        // for( i = 0; i < AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3;i++ ) { 
     166                                        for (i2 = 0;i2 < width; i2++) { 
     167                                                for (i3 = 0;i3 < 3; i3++) { 
    140168                                                        pat[h][i][i2][i3] -= l; 
    141169                                                        m += (pat[h][i][i2][i3] * pat[h][i][i2][i3]); 
     
    147175                                        patpow[h] = 0.0000001; 
    148176                                } 
    149                                  
     177 
    150178                                m = 0; 
    151                                 for (i = 0; i < height; i++) { 
    152                                         for (i2 = 0; i2 < width; i2++) { 
     179                                for (i = 0;i < height; i++) { 
     180                                        for (i2 = 0;i2 < width; i2++) { 
    153181                                                patBW[h][i][i2] -= l; 
    154                                                 m += (patBW[h][i][i2]*patBW[h][i][i2]); 
     182                                                m += (patBW[h][i][i2] * patBW[h][i][i2]); 
    155183                                        } 
    156184                                } 
     
    160188                                } 
    161189                        } 
    162             } 
    163              
    164                 /** 
    165                  * FLARColorPatt_O3インスタンスからパターンを作る 
    166                  * @param       pattern 
    167                  * @see FLARColorPatt_03 
    168                  */ 
    169                 public function fromPattern(pattern:FLARColorPatt_O3):void  
    170                 { 
    171                         var patArray:Array = pattern.getPatArray(); 
    172                         var l:int; 
    173                         var m:int; 
    174                         var mbw:int; 
    175  
    176                         l = 0; 
    177                         m = 0; 
    178                         mbw = 0; 
    179  
    180                         //幅・高さのチェック 
    181                         if (this.height != patArray.length || this.width != patArray[0].length) { 
    182                                 throw new ArgumentError("パターンの幅・高さが、Codeの幅・高さと異なっています"); 
    183                         } 
    184                         if (this.height != this.width) { 
    185                                 throw new ArgumentError("正方形のインスタンスのみ有効です。"); 
    186                         } 
    187                         for (var y:int = 0; y < this.height; y++) {//y : 行方向の添え字 
    188                                 for (var x:int = this.width - 1; x >= 0 ; x--) {//x : 列方向の添え字 
    189                                         patBW[0][this.height - 1 - x][y] = 0; 
    190                                         patBW[1][this.height - 1 - y][this.width -1 - x] = 0; 
    191                                         patBW[2][x][this.width - 1 - y] = 0; 
    192                                         patBW[3][y][x] = 0; 
    193                                         for (var c:int = 0; c < 3; c++) {//c : 色情報(0:R/1:G/2:B) 
    194                                                 //傾き情報(0:上/1:左/2:下/3:右) 
    195                                                 //全方向に1度に値を代入している 
    196                                                 var j:int = 255 - int(patArray[y][x][c]); 
    197  
    198                                                 pat[0][this.height - 1 - x][y][c] = j; 
    199                                                 pat[1][this.height - 1 - y][this.width - 1 - x][c] = j; 
    200                                                 pat[2][x][this.width - 1 - y][c] = j; 
    201                                                 pat[3][y][x][c] = j 
    202                                                 patBW[0][this.height - 1 - x][y] += j; 
    203                                                 patBW[1][this.height - 1 - y][this.width -1 - x] += j; 
    204                                                 patBW[2][x][this.width - 1 - y] += j; 
    205                                                 patBW[3][y][x] += j; 
    206                                                 l += j; 
    207                                         } 
    208                                         patBW[0][this.height - 1 - x][y] /= 3; 
    209                                         patBW[1][this.height - 1 - y][this.width -1 - x] /= 3; 
    210                                         patBW[2][x][this.width - 1 - y] /= 3; 
    211                                         patBW[3][y][x] /= 3; 
    212                                 } 
    213                         } 
    214                         l /= (this.width * this.height * 3); 
    215                         for (y = 0; y < this.height; y++) { 
    216                                 for (x = 0; x < this.width; x++) { 
    217                                         patBW[0][this.height - 1 - x][y] -= l; 
    218                                         patBW[1][this.height - 1 - y][this.width - 1 - x] -= l; 
    219                                         patBW[2][x][this.width - 1 - y] -= l; 
    220                                         patBW[3][y][x] -= l; 
    221                                         mbw += (patBW[3][y][x] * patBW[3][y][x]); 
    222                                         for (c = 0; c < 3;c++) { 
    223                                                 pat[0][this.height - 1 - x][y][c] -= l; 
    224                                                 pat[1][this.height - 1 - y][this.width - 1 - x][c] -= l; 
    225                                                 pat[2][x][this.width - 1 - y][c] -= l; 
    226                                                 pat[3][y][x][c] -= l; 
    227                                                 m += (pat[3][y][x][c] * pat[3][y][x][c]); 
    228