import time
import numpy as np
from stl import mesh

# create a dummy huge point cloud
vertices = np.random.rand(1000000, 3) * 100
min_v = vertices.min(axis=0)
g_size = 2.0

v_idx = np.round((vertices - min_v) / g_size).astype(np.int32)

t0 = time.time()
_, unique_idx, inv_idx = np.unique(v_idx, axis=0, return_index=True, return_inverse=True)
print("axis=0 time:", time.time() - t0)

v_idx = v_idx.astype(np.int64)
t0 = time.time()
max_idx = v_idx.max(axis=0) + 1
v_1d = v_idx[:, 0] + v_idx[:, 1] * max_idx[0] + v_idx[:, 2] * max_idx[0] * max_idx[1]
_, unique_idx, inv_idx = np.unique(v_1d, return_index=True, return_inverse=True)
print("1D hash time:", time.time() - t0)
