def main(): ti.deactivate_all_snodes() activate() gui = ti.GUI('bitmasked', (n, n)) for frame in range(10000): color = math.sin(frame * 0.05) * 0.5 + 0.5 paint_active_pixels(color) #paint_all_pixels(color) # try this and compare the difference! gui.set_image(x) gui.show()
def main(self): gui = ti.GUI('Marching cube') while gui.running and not gui.get_event(gui.ESCAPE): if self.use_sparse: ti.deactivate_all_snodes() else: self.m.fill(0) self.touch(*gui.get_cursor_pos()) ret_len = self.march() ret = self.r.to_numpy()[:ret_len] / self.N if self.dim == 2: self.compute_grad() gui.set_image(ti.tools.imresize(self.g, *gui.res) * 0.5 + 0.5) gui.lines(ret[:, 0], ret[:, 1], color=0xff66cc, radius=1.5) else: gui.triangles(ret[:, 0, 0:2], ret[:, 1, 0:2], ret[:, 2, 0:2], color=0xffcc66) gui.lines(ret[:, 0, 0:2], ret[:, 1, 0:2], color=0xff66cc, radius=0.5) gui.lines(ret[:, 1, 0:2], ret[:, 2, 0:2], color=0xff66cc, radius=0.5) gui.lines(ret[:, 2, 0:2], ret[:, 0, 0:2], color=0xff66cc, radius=0.5) gui.text(f'Press space to save mesh to PLY ({len(ret)} faces)', (0, 1)) if gui.is_pressed(gui.SPACE): num = ret.shape[0] writer = ti.tools.PLYWriter(num_vertices=num * 3, num_faces=num) vertices = ret.reshape(num * 3, 3) * 2 - 1 writer.add_vertex_pos(vertices[:, 0], vertices[:, 1], vertices[:, 2]) indices = np.arange(0, num * 3) writer.add_faces(indices) writer.export('mciso_output.ply') print('Mesh saved to mciso_output.ply') gui.show()
# output: nothing for i, j in block1: print('Active block1: [{}, {}]'.format(i, j)) # output: Active block1: [0, 1] print(ti.rescale_index(x, block1, ti.Vector([9, 17]))) # output = [2, 4] # Note: ti.Vector is optional in ti.rescale_index. print(ti.rescale_index(x, block1, [9, 17])) # output = [2, 4] ti.activate(block2, [1, 2]) sparse_api_demo() @ti.kernel def check_activity(snode: ti.template(), i: ti.i32, j: ti.i32): print(ti.is_active(snode, [i, j])) check_activity(block2, 1, 2) # output = 1 block2.deactivate_all() check_activity(block2, 1, 2) # output = 0 check_activity(block1, 0, 1) # output = 1 ti.deactivate_all_snodes() check_activity(block1, 0, 1) # output = 0
def deactivate_all(): warning( """'ti.root.deactivate_all()' would deactivate all finalized snodes.""" ) ti.deactivate_all_snodes()