Material Clustering Benchmark
samples.py
Go to the documentation of this file.
1"""
2This script generates csharp code with jittered sampling offsets.
3
4usage: samples.py [grid size]
5"""
6
7import sys
8
9
10def main():
11 if len(sys.argv) != 2:
12 print(
13 "usage: samples.py [grid size]"
14 )
15 return
16
17 size = int(sys.argv[1])
18
19 def gen(n: int) -> list[tuple[int, int]]:
20 assert(
21 n & (n - 1) == False
22 )
23 assert(n > 1)
24
25 if n == 2:
26 return [
27 (0, 0),
28 (1, 0),
29 (1, 1),
30 (0, 1)
31 ]
32
33 return [
34 (
35 pos[0] + offset_x * n // 2,
36 pos[1] + offset_y * n // 2
37 )
38 for pos in gen(n // 2) for offset_y in [0, 1] for offset_x in [0, 1]
39 ]
40
41 list_offsets = gen(size)
42
43 print("int[][] offsets = new int[][] { ", end="")
44
45 for offset in list_offsets:
46 print(
47 f"new int[] {'{'} {offset[0]}, {offset[1]} {'}'},",
48 end=" "
49 )
50 print("};")
51
52
53if __name__ == '__main__':
54 main()
def main()
Definition: samples.py:10