チェンジセット 1832

差分発生行の前後
無視リスト:
コミット日時:
2008/11/14 18:44:07 (2 ヶ月前)
コミッタ:
tarotarorg
ログメッセージ:

マーカ動的生成用の関数を、バージョン1のコードからサルベージしてみた

ファイル:

凡例:

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

    r1640 r1832  
    3030 
    3131package org.libspark.flartoolkit.core { 
     32        import org.libspark.flartoolkit.core.pickup.IFLARColorPatt; 
    3233        import org.libspark.flartoolkit.utils.ArrayUtil;         
    3334 
     
    200201//                      } 
    201202                } 
     203 
     204                /** 
     205                 * FLARColorPatt_O3インスタンスからパターンを作る 
     206                 * @param       pattern 
     207                 * @see IFLARColorPatt 
     208                 */ 
     209                public function fromPattern(pattern:IFLARColorPatt):void 
     210                { 
     211                        var patArray:Array = pattern.getPatArray(); 
     212                        var l:int; 
     213                        var m:int; 
     214                        var mbw:int; 
     215 
     216                        l = 0; 
     217                        m = 0; 
     218                        mbw = 0; 
     219 
     220                        //幅・高さのチェック 
     221                        if (this.height != patArray.length || this.width != patArray[0].length) { 
     222                                throw new ArgumentError("パターンの幅・高さが、Codeの幅・高さと異なっています"); 
     223                        } 
     224                        if (this.height != this.width) { 
     225                                throw new ArgumentError("正方形のインスタンスのみ有効です。"); 
     226                        } 
     227                        for (var y:int = 0; y < this.height; y++) {//y : 行方向の添え字 
     228                                for (var x:int = this.width - 1; x >= 0 ; x--) {//x : 列方向の添え字 
     229                                        patBW[0][this.height - 1 - x][y] = 0; 
     230                                        patBW[1][this.height - 1 - y][this.width -1 - x] = 0; 
     231                                        patBW[2][x][this.width - 1 - y] = 0; 
     232                                        patBW[3][y][x] = 0; 
     233                                        for (var c:int = 0; c < 3; c++) {//c : 色情報(0:R/1:G/2:B) 
     234                                                //傾き情報(0:上/1:左/2:下/3:右) 
     235                                                //全方向に1度に値を代入している 
     236                                                var j:int = 255 - int(patArray[y][x][c]); 
     237 
     238                                                pat[0][this.height - 1 - x][y][c] = j; 
     239                                                pat[1][this.height - 1 - y][this.width - 1 - x][c] = j; 
     240                                                pat[2][x][this.width - 1 - y][c] = j; 
     241                                                pat[3][y][x][c] = j 
     242                                                patBW[0][this.height - 1 - x][y] += j; 
     243                                                patBW[1][this.height - 1 - y][this.width -1 - x] += j; 
     244                                                patBW[2][x][this.width - 1 - y] += j; 
     245                                                patBW[3][y][x] += j; 
     246                                                l += j; 
     247                                        } 
     248                                        patBW[0][this.height - 1 - x][y] /= 3; 
     249                                        patBW[1][this.height - 1 - y][this.width -1 - x] /= 3; 
     250                                        patBW[2][x][this.width - 1 - y] /= 3; 
     251                                        patBW[3][y][x] /= 3; 
     252                                } 
     253                        } 
     254                        l /= (this.width * this.height * 3); 
     255                        for (y = 0; y < this.height; y++) { 
     256                                for (x = 0; x < this.width; x++) { 
     257                                        patBW[0][this.height - 1 - x][y] -= l; 
     258                                        patBW[1][this.height - 1 - y][this.width - 1 - x] -= l; 
     259                                        patBW[2][x][this.width - 1 - y] -= l; 
     260                                        patBW[3][y][x] -= l; 
     261                                        mbw += (patBW[3][y][x] * patBW[3][y][x]); 
     262                                        for (c = 0; c < 3;c++) { 
     263                                                pat[0][this.height - 1 - x][y][c] -= l; 
     264                                                pat[1][this.height - 1 - y][this.width - 1 - x][c] -= l; 
     265                                                pat[2][x][this.width - 1 - y][c] -= l; 
     266                                                pat[3][y][x][c] -= l; 
     267                                                m += (pat[3][y][x][c] * pat[3][y][x][c]); 
     268                                        } 
     269                                } 
     270                        } 
     271                        patpow[0] = patpow[1] = patpow[2] = patpow[3] = m == 0 ? 0.0000001 : Math.sqrt(m); 
     272                        patpowBW[0] = patpowBW[1] = patpowBW[2] = patpowBW[3] = mbw == 0 ? 0.0000001 : Math.sqrt(mbw); 
     273                } 
     274 
    202275        } 
    203276}