indexing description: "Objects that ..." author: "" date: "$Date$" revision: "$Revision$" deferred class EM_VORONOI feature make is -- Set some default values do poisson_count := << 4,3,1,1,1,2,4,2,2,2,5,1,0,2,1,2,2,0,4,3,2,1,2,1,3,2,2,4,2,2,5,1,2,3,2,2,2,2,2,3, 2,4,2,5,3,2,2,2,5,3,3,5,2,1,3,3,4,4,2,3,0,4,2,2,2,1,3,2,2,2,3,3,3,1,2,0,2,1,1,2, 2,2,2,5,3,2,3,2,3,2,2,1,0,2,1,1,2,1,2,2,1,3,4,2,2,2,5,4,2,4,2,2,5,4,3,2,2,5,4,3, 3,3,5,2,2,2,2,2,3,1,1,4,2,1,3,3,4,3,2,4,3,3,3,4,5,1,4,2,4,3,1,2,3,5,3,2,1,3,1,3, 3,3,2,3,1,5,5,4,2,2,4,1,3,4,1,5,3,3,5,3,4,3,2,2,1,1,1,1,1,2,4,5,4,5,4,2,1,5,1,1, 2,3,3,3,2,5,2,3,3,2,0,2,1,1,4,2,1,3,2,1,2,2,3,2,5,5,3,4,5,5,2,4,4,5,3,2,2,2,1,4, 2,3,3,4,2,5,4,2,4,2,2,2,4,5,3,2 >> set_max_points_per_cell(5) order := 1 set_manhatten_metric(false) random_size := 256 create random_array.make (random_size) create perm_array.make (random_size) set_seed (12345) end order: INTEGER set_order(an_order: INTEGER) is -- Set the order -- 1 means the distance to the closest point is evaluated -- 2 means the distance to the second closest point is evaluated -- and so on. A higher number means bigger computation time do order := an_order end max_points_per_cell: INTEGER set_max_points_per_cell(a_max: INTEGER) is -- set the maximal number of points per cell -- Default is 5 require valid_max: a_max > 0 do max_points_per_cell := a_max max_points_factor := 1.0 / 5 * max_points_per_cell end set_seed (a_seed: INTEGER) is -- set the seed for voronoi local random: RANDOM i: INTEGER do create random.set_seed(a_seed) from i := 0 until i >= random_array.count loop random.forth random_array.put ((random.item \\ random_size) / random_size, i) random.forth perm_array.put (random.item \\ random_size, i) i := i + 1 end end manhatten_metric: BOOLEAN set_manhatten_metric (use_manhatten: BOOLEAN) is -- specify if you want to use manhatten metric do manhatten_metric := use_manhatten end feature {NONE} get_random(a_val: INTEGER): DOUBLE is -- returns an integer value between 0.0 and 1.0 do Result := random_array.item (permute(a_val)) end permute (a_val: INTEGER): INTEGER is -- get a permuted value do Result := perm_array.item ( modulo((modulo(a_val, random_size) + random_size), random_size)) ensure Result >= 0 and Result <= 255 end modulo(a_number: INTEGER; a_modulo: INTEGER): INTEGER is -- compute a valid (postive) modulo -- return 'number' if modulo is 0 do if a_modulo = 0 then Result := a_number else Result := ((a_number \\ a_modulo) + a_modulo) \\ a_modulo end ensure return_number_when_modulo_0: a_modulo = 0 implies Result = a_number result_in_range: a_modulo /= 0 implies Result >= 0 and Result < a_modulo end feature {NONE} random_array: SPECIAL[DOUBLE] perm_array: SPECIAL[INTEGER] poisson_count: ARRAY[INTEGER] random_size: INTEGER max_points_factor: DOUBLE distances: ARRAY[DOUBLE] invariant random_size_set: random_size >= 0 random_array_created: random_array /= void perm_array_created: perm_array /= void end