taichi.tools#

class taichi.tools.PLYWriter(num_vertices: int, num_faces=0, face_type='tri', comment='created by PLYWriter')#
add_face_channel(self, key: str, data_type: str, data: numpy.array)#
add_face_id(self)#
add_face_piece(self, piece: numpy.array)#
add_faces(self, indices: numpy.array)#
add_vertex_alpha(self, alpha: numpy.array)#
add_vertex_channel(self, key: str, data_type: str, data: numpy.array)#
add_vertex_color(self, r: numpy.array, g: numpy.array, b: numpy.array)#
add_vertex_id(self)#
add_vertex_normal(self, nx: numpy.array, ny: numpy.array, nz: numpy.array)#
add_vertex_piece(self, piece: numpy.array)#
add_vertex_pos(self, x: numpy.array, y: numpy.array, z: numpy.array)#
add_vertex_rgba(self, r: numpy.array, g: numpy.array, b: numpy.array, a: numpy.array)#
export(self, path)#
export_ascii(self, path)#
export_frame(self, series_num: int, path: str)#
export_frame_ascii(self, series_num: int, path: str)#
print_header(self, path: str, _format: str)#
sanity_check(self)#
class taichi.tools.VideoManager(output_dir, width=None, height=None, post_processor=None, framerate=24, automatic_build=True)#

Utility class for exporting results to mp4 and gif formats. This class relies on ffmpeg.

Parameters
  • output_dir (str) – directory to save the frames.

  • width (int) – resolution of the video.

  • height (int) – resolution of the video.

  • post_processor (object) – any object that implements the process(img) method, which accepts an image as a numpy.ndarray and returns the process image.

  • framerate (int) – frame rate of the video.

  • automatic_build (bool) – automatically generate the resulting video or not.

Example:

>>> video_manager = ti.tools.VideoManager(output_dir="./output", framerate=24, automatic_build=False)
>>> for i in range(50):
>>> render()
>>> img = pixels.to_numpy()
>>> video_manager.write_frame(img)
>>>
>>> video_manager.make_video(gif=True, mp4=True)
Returns

An instance of taichi.tools.VideoManager class.

clean_frames(self)#
get_frame_directory(self)#
get_output_filename(self, suffix)#
make_video(self, mp4=True, gif=True)#
write_frame(self, img)#
write_frames(self, images)#
taichi.tools.imread(filename, channels=0)#

Load image from a specific file.

Parameters
  • filename (str) – An image filename to load from.

  • channels (int, optinal) – The channels hint of input image, Default to 0.

Returns

An output image loaded from given filename.

Return type

np.ndarray

taichi.tools.imresize(img, w, h=None)#

Resize an image to a specific size.

Parameters
  • img (Union[ti.field, np.ndarray]) – A field of of array with shape (width, height, …)

  • w (int) – The output width after resize.

  • h (int, optional) – The output height after resize, will be the same as width if not set. Default to None.

Returns

An output image after resize input.

Return type

np.ndarray

taichi.tools.imshow(img, title='imshow')#

Display a taichi.field or a numpy.ndarray in a Taichi GUI window or an interactive Ipython notebook. For an interactive Ipython environment, the image will be shown in the notebook.

Parameters
  • img (Union[ti.field, np.ndarray]) – A field of of array with shape (width, height) or (height, width, 3) or (height, width, 4).

  • title (str, optional) – The title of GUI window. Default to imshow.

taichi.tools.imwrite(img, filename)#

Save a field to a a specific file.

Parameters
  • img (Union[ti.field, np.ndarray]) – A field of shape (height, width) or (height, width, 3) or (height, width, 4), if dtype is float-type (ti.f16, ti.f32, np.float32 etc), the value of each pixel should be float between [0.0, 1.0]. Otherwise ti.imwrite will first clip them into [0.0, 1.0] if dtype is int-type (ti.u8, ti.u16, np.uint8 etc), , the value of each pixel can be any valid integer in its own bounds. These integers in this field will be scaled to [0, 255] by being divided over the upper bound of its basic type accordingly.

  • filename (str) – The filename to save to.