def test_performance(): # warmup run for mem allocation lengthscale = 0.03 n = 300000 points = np.random.rand(n, 3).astype(np.float32) spec = spatial.Spec3d(points, lengthscale) start = time.clock() grid = spatial.Grid3d(spec, points) warmup = time.clock() - start # run on unsorted data points = np.random.rand(n, 3).astype(np.float32) start = time.clock() grid = spatial.Grid3d(spec, points) unsorted = time.clock() - start # update from existing start = time.clock() grid = grid.update(points) update = time.clock() - start # sort data points = points[grid.permutation] # run on sorted data start = time.clock() grid = spatial.Grid3d(spec, points) sorted = time.clock() - start print(warmup, unsorted, update, sorted)
def collision_prepare(self): # self.spatial_grid = self.spatial_grid.update(self.position) # bounds = np.array([[-10]*3, [10]*3]).astype(np.float32) self.spec = spatial.Spec3d(self.position, self.scale) self.offsets = self.spec.stencil(self.stencil).astype(np.int32) self.spatial_grid = spatial.Grid3d(self.spec, self.position, self.offsets)
def test_collision(): meshes = [ icosphere(0.5, refinement=3), icosphere(0.5, [0.95, 0, 0], refinement=3) ] lengthscale = 0.2 grids = [spatial.Grid3d(m.vertices, lengthscale) for m in meshes] ctmeshes = [ spatial.Mesh(m.vertices, m.vertex_normals(), m.faces, 0.1, 0) for m in meshes ] for i, mi in enumerate(meshes): for j, mj in enumerate(meshes): print(i, j) info = spatial.Info(grids[i], ctmeshes[j], i == j) mask = info.triangle != -1 print(info.triangle[mask]) print(info.depth[mask])
def get_spatial_grid(self): stencil = np.zeros((1), np.int32) return spatial.Grid3d( spatial.Spec3d(self.position, self.length_scale * 2), self.position, stencil)