Revert "remove global var"
Browse filesThis reverts commit d11e8f6af052e11cb6e88159b9a1290d0caee6cd.
step1x3d_texture/texture_sync/voronoi.py
CHANGED
|
@@ -13,6 +13,12 @@ x_dim = 512
|
|
| 13 |
y_dim = 512
|
| 14 |
noSeeds = 1024
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
import torch
|
| 17 |
import time
|
| 18 |
|
|
@@ -72,6 +78,26 @@ def voronoi_solve(texture, mask, device="cuda"):
|
|
| 72 |
return voronoi_texture
|
| 73 |
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
displayKernel = cp.ElementwiseKernel(
|
| 77 |
"int64 x", "int64 y", f"y = (x < 0) ? x : x % 103", "displayTransform"
|
|
@@ -127,6 +153,7 @@ voronoiKernel = cp.RawKernel(
|
|
| 127 |
|
| 128 |
|
| 129 |
def JFAVoronoiDiagram(ping, pong):
|
|
|
|
| 130 |
# compute initial step size
|
| 131 |
x_dim, y_dim = ping.shape
|
| 132 |
step = max(x_dim, y_dim) // 2
|
|
|
|
| 13 |
y_dim = 512
|
| 14 |
noSeeds = 1024
|
| 15 |
|
| 16 |
+
# diagram is represented as a 2d array where each element is
|
| 17 |
+
# x coord of source * y_dim + y coord of source
|
| 18 |
+
ping = cp.full((x_dim, y_dim), -1, dtype=int)
|
| 19 |
+
pong = None
|
| 20 |
+
|
| 21 |
+
|
| 22 |
import torch
|
| 23 |
import time
|
| 24 |
|
|
|
|
| 78 |
return voronoi_texture
|
| 79 |
|
| 80 |
|
| 81 |
+
def generateRandomSeeds(n):
|
| 82 |
+
"""
|
| 83 |
+
Function to generate n random seeds.
|
| 84 |
+
|
| 85 |
+
@param n The number of seeds to generate.
|
| 86 |
+
"""
|
| 87 |
+
global ping, pong
|
| 88 |
+
|
| 89 |
+
if n > x_dim * y_dim:
|
| 90 |
+
print("Error: Number of seeds greater than number of pixels.")
|
| 91 |
+
return
|
| 92 |
+
|
| 93 |
+
# take sample of cartesian product
|
| 94 |
+
coords = [(x, y) for x in range(x_dim) for y in range(y_dim)]
|
| 95 |
+
seeds = sample(coords, n)
|
| 96 |
+
for i in range(n):
|
| 97 |
+
x, y = seeds[i]
|
| 98 |
+
ping[x, y] = x * y_dim + y
|
| 99 |
+
pong = cp.copy(ping)
|
| 100 |
+
|
| 101 |
|
| 102 |
displayKernel = cp.ElementwiseKernel(
|
| 103 |
"int64 x", "int64 y", f"y = (x < 0) ? x : x % 103", "displayTransform"
|
|
|
|
| 153 |
|
| 154 |
|
| 155 |
def JFAVoronoiDiagram(ping, pong):
|
| 156 |
+
# global ping, pong
|
| 157 |
# compute initial step size
|
| 158 |
x_dim, y_dim = ping.shape
|
| 159 |
step = max(x_dim, y_dim) // 2
|