AKTIVE

gauss.tcl at trunk
Login

gauss.tcl at trunk

File etc/generator/virtual/noise/gauss.tcl artifact 173d44f0fa on branch trunk


     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
## -*- mode: tcl ; fill-column: 90 -*-
# # ## ### ##### ######## ############# #####################
## Generators -- Virtual Image - Gaussian noise

operator image::noise::gauss {
    section generator virtual

    # fixed seed to keep the examples identical across runs
    example {width 256 height 256 depth 1 seed 703011174}
    example {width 256 height 256 depth 3 seed 703011174}

    note Returns image where pixels are set to random values \
	drawn from a gaussian distribution with mean and \
	sigma over +/-sigma. The defaults are 0 and 1.

    uint      width   Width of the returned image
    uint      height  Height of the returned image
    uint      depth   Depth of the returned image

    double? 0 mean    Mean of the desired gauss distribution.
    double? 1 sigma   Sigma of the desired gauss distribution.

    uint? {[expr {int(4294967296*rand())}]}  seed    \
	Randomizer seed. Needed only to force fixed results.

    state -fields {
	aktive_uint seed;
    } -setup {
	aktive_geometry_set (domain, 0, 0, param->width, param->height, param->depth);

	state->seed = param->seed;
	// Merge w, h, d into seed ? No. Does not make things more random.
    }

    blit gausssampling {
	{AH {y AY 1 up} {y SY 1 up}}
	{AW {x AX 1 up} {x SX 1 up}}
	{DD {z  0 1 up} {z  0 1 up}}
    } {point {
	mean + (sigma * GAUSS (MERGE3 (istate->seed, x, y, z)))
    }}

    pixels {
	double mean  = param->mean;
	double sigma = param->sigma;

	#define GAUSS  aktive_fnv_gauss
	#define MERGE aktive_fnv_merge_uint32
	#define MERGE3(s,a,b,c) MERGE (MERGE (MERGE (s, a), b), c)
	#define SD (idomain->depth)
	#define SH (idomain->height)
	#define SW (idomain->width)
	#define SX (request->x)
	#define SY (request->y)
	@@gausssampling@@
	#undef STEP
	#undef MERGE3
	#undef MERGE
    }
}

##
# # ## ### ##### ######## ############# #####################
::return