1

デカルト座標が 0 から 100 (100x100x100 グリッド) に正規化され、その中の各データ ポイントの「強度」が 0 から 256 に正規化されるグリッドにランダムにデータを入力しています。これは、perl のコードからの抜粋です。

open(FILE,$file);
while(sysread(FILE,$data,16)) {
    @row=unpack("f>4",$data);   # input file is binary so I had to convert here
    $x=int((($row[0] - $xmin)/($xmax - $xmin)*10) + 0.5); # max and min variables
    $y=int((($row[1] - $ymin)/($ymax - $ymin)*10) + 0.5); # are previously defined
    $z=int((($row[2] - $zmin)/($zmax - $zmin)*10) + 0.5);
    $i=int(($row[3]/62*256) + 0.5);
    $i=255 if ($i>255);

    $out[$x][$y][$z]=$i;   # simply assigns an intensity for each data
                           # point (in random order), only 1 point can be
                           # added to each 1x1x1 cell
}

いくつかのポイントが近すぎて、同じ 1x1x1 セルに配置されています。これが発生すると、追加された各強度が前の強度を上書きします。複数のポイントがセルに配置された回数をカウントするにはどうすればよいですか?

前もって感謝します!

4

3 に答える 3

1

これは、別のハッシュを使用して非常に簡単に行うことができます。すべてのキー ( $x$y、 ) を 1 つのキーに結合し、値を挿入するたび$zにハッシュ値をtrueに設定するだけです。

my %visited_points; 

open(FILE,$file);
while(sysread(FILE,$data,16)) {
    @row=unpack("f>4",$data);   # input file is binary so I had to convert here
    $x=int((($row[0] - $xmin)/($xmax - $xmin)*10) + 0.5); # max and min variables
    $y=int((($row[1] - $ymin)/($ymax - $ymin)*10) + 0.5); # are
    $z=int((($row[2] - $zmin)/($zmax - $zmin)*10) + 0.5);
    $i=int(($row[3]/62*256) + 0.5);
    $i=255 if ($i>255);

    my $key = "$x$y$z";
    # check if something already occupies this cell
    if( exists( $visited_points{$key} ) ) {
        # take some other action
    }

    $out[$x][$y][$z]=$i;   # simply assigns an intensity for each data
                           # point (in random order), only 1 point can be
                           # added to each 1x1x1 cell

    # mark that there is something in this cell
    $visited_points{$key} = 1;
}

カウントしたい場合は、値をインクリメントするだけで簡単にカウントできます。

于 2013-06-20T20:27:00.367 に答える