SaveModel

Saves the meshes or point clouds of the specified cameras into a file using PLY, STL or PCD format.

PLY Format

The PLY format allows to specify arbitrary data streams. NxLib outputs an array of vertices first, containing the coordinates ‘x’, ‘y’ and ‘z’ as floats.

If the Texture parameter was set to true each vertex additionally contains an unsigned char value for its red, green and blue color component; these values are named ‘red’, ‘green’, and ‘blue’ respectively in the header definition.

If the Normals parameter was true, each vertex will additionally have ‘nx’, ‘ny’, ‘nz’ properties, indicating the surface normal direction at the vertex.

If the PointCloud parameter is false, a list of triangles is appended to the output. Each triangle is defined via a list of vertex indices forming the triangle. The list size is written into the file as unsigned char (which is always 3 for triangles!). Then the three vertex indices follow as unsigned integers.

The full PLY header with texture and normals will then look like this:

ply
format binary_little_endian 1.0
element vertex <NumVertices>
property float x
property float y
property float z
property float nx
property float ny
property float nz
property uchar red
property uchar green
property uchar blue
element face <NumTriangles>
property list uchar uint vertex_indices
end_header

After the header the following values will be found in binary form in the file (texture is included in this example):

Values

Data Type

Description

x0, y0, z0,

float, float, float

Coordinates of the first vertex

nx0, ny0, nz0,

float, float, float

Normal direction at first vertex

r0, g0, b0,

uchar, uchar, uchar

Color at first vertex

x1, y1, z1,

float, float, float

Coordinates of second vertex

nx1, ny1, nz1,

float, float, float

Normal direction at second vertex

r1, g1, b1,

uchar, uchar, uchar

Color at second vertex

…

cnt0

uchar

Size of index list for first triangle (always equal to 3)

i00, i01, i02

uint, uint, uint

Indices of vertices forming the first triangle

cnt1

uchar

Size of index list for second triangle (always equal to 3)

i10, i11, i12

uint, uint, uint

Indices of vertices forming the second triangle

…

Note

The number of vertices and triangles must always be read from the header and is not contained in binary form.

PCD Format

Note

Compared to PLY the PCD format cannot export faces.

The Normals parameter controls the export of the ‘normal_x’, ‘’normal_y’, ‘’normal_z’ fields. If it is false, the fields will not be included and ‘SIZE’, ‘TYPE’ and ‘COUNT’ will be reduced accordingly.

The Texture parameter controls the export of the ‘rgb’ field. If it is false, the fields will not be included and ‘SIZE’, ‘TYPE’ and ‘COUNT’ will be reduced accordingly. ‘rgb’ is exported as unsigned 32-bit value, containing ones in the upper byte and red, green and blue in the remaining bytes (ARGB format).

The Order parameter controls whether invalid values will be left out. If the parameter is true, invalid points will be exported as NaN float values, and the order of the point cloud in the original camera image dimensions will be kept. If the parameter is false, invalid points will be left out, and the resulting point cloud will be unstructured.

The CompressModel parameter controls whether the data block is a raw binary (‘DATA’ header set to ‘binary’), or uses LZF compression with the structure-of-arrays layout (‘DATA’ header set to ‘binary_compressed’), as specified in https://pointclouds.org/documentation/tutorials/pcd_file_format.html.

The full PCD header will look as follows:

VERSION .7
FIELDS x y z normal_x normal_y normal_z rgb
COUNT 1 1 1 1 1 1 1
TYPE F F F F F F U
SIZE 4 4 4 4 4 4 4
WIDTH <width>
HEIGHT <height>
VIEWPOINT <tx> <ty> <tz> <rw> <rx> <ry> <rz>
POINTS <point-count>
DATA {binary,binary_compressed}

Note

The ‘HEIGHT’ field will be 1, if exporting points from multiple cameras or Order was specified as false.

Note

The ‘VIEWPOINT’ field contains the pose (translation and quaternion rotation) of the first camera in the export, relative to the point cloud / world origin.

STL Format

The STL format has no options and simply exports all faces, without color or normals.