# File IO¶

This tutorial shows how basic geometries are read and written by Open3D.

## Point cloud¶

This code below reads and writes a point cloud.

:

print("Testing IO for point cloud ...")
print(pcd)
o3d.io.write_point_cloud("copy_of_fragment.pcd", pcd)

Testing IO for point cloud ...
geometry::PointCloud with 113662 points.

:

True


print() can be used for displaying a summary of pcd.

By default, Open3D tries to infer the file type by the filename extension. Below is a list of supported point cloud file types.

Format

Description

xyz

Each line contains [x, y, z], where x, y, z are the 3D coordinates

xyzn

Each line contains [x, y, z, nx, ny, nz], where nx, ny, nz are the normals

xyzrgb

Each line contains [x, y, z, r, g, b], where r, g, b are in floats of range [0, 1]

pts

The first line is an integer representing the number of points. Each subsequent line contains [x, y, z, i, r, g, b], where r, g, b are in uint8

ply

See Polygon File Format, the ply file can contain both point cloud and mesh data

pcd

It’s also possible to specify the file type explicitly. In this case, the file extension will be ignored.

:

pcd = o3d.io.read_point_cloud("../../TestData/my_points.txt", format='xyz')


## Mesh¶

This code below reads and writes a mesh.

:

print("Testing IO for meshes ...")
print(mesh)
o3d.io.write_triangle_mesh("copy_of_knot.ply", mesh)

Testing IO for meshes ...
geometry::TriangleMesh with 1440 points and 2880 triangles.

:

True


Compared to the data structure of point cloud, mesh has triangles that define the 3D surface.

By default, Open3D tries to infer the file type by the filename extension. Below is a list of supported triangle mesh file types.

Format

Description

ply

See Polygon File Format, the ply file can contain both point cloud and mesh data

stl

obj

See Object Files

off

gltf

## Image¶

The code below reads and writes an image.

:

print("Testing IO for images ...")

Testing IO for images ...

:

True

The size of the image is readily displayed using print(img).