Mesh Class Reference

Class representing a mesh and containing the geometric (and optionally texture) data of the scene captured by the spatial mapping module. More...

Types

typedef std::vector< size_t > chunkList
 Vector of chunks id. More...
 

Functions

 Mesh ()
 Default constructor. More...
 
 ~Mesh ()
 Default destructor. More...
 
Chunkoperator[] (int index)
 Defines the [] operator to directly access the desired chunk. More...
 
size_t getNumberOfTriangles ()
 Computes the total number of triangles stored in all chunks. More...
 
void updateMeshFromChunkList (chunkList IDs=chunkList())
 Updates vertices / normals / triangles / uv from chunk data pointed by the given sl::Mesh::chunkList. More...
 
chunkList getVisibleList (Transform camera_pose)
 Computes the sl::Mesh::chunkList of visible chunks from a specific point of view. More...
 
chunkList getSurroundingList (Transform camera_pose, float radius)
 Computes the sl::Mesh::chunkList of chunks close to a specific point of view. More...
 
bool filter (MeshFilterParameters mesh_filter_params=MeshFilterParameters(), bool update_chunk_only=false)
 Filters the mesh. More...
 
bool applyTexture (MESH_TEXTURE_FORMAT texture_format=MESH_TEXTURE_FORMAT::RGB)
 Applies a texture to the mesh. More...
 
void mergeChunks (int faces_per_chunk)
 Merges current chunks. More...
 
sl::float3 getGravityEstimate ()
 Estimates the gravity vector. More...
 
std::vector< int > getBoundaries ()
 Compute the indices of boundary vertices. More...
 
bool save (String filename, MESH_FILE_FORMAT type=MESH_FILE_FORMAT::OBJ, chunkList IDs=chunkList())
 Saves the current sl::Mesh into a file. More...
 
bool load (String filename, bool update_chunk_only=false)
 Loads the mesh from a file. More...
 
void clear ()
 Clears all the data. More...
 

Attributes

std::vector< Chunkchunks
 Vector of chunks constituting the sl::Mesh. More...
 
std::vector< float3vertices
 Vector of vertices. More...
 
std::vector< uint3triangles
 Vector of triangles/faces. More...
 
std::vector< float3normals
 Vector of normals. More...
 
std::vector< uchar3colors
 Vector of colors. More...
 
std::vector< float2uv
 UVs defines the 2D projection of each vertices onto the texture. More...
 
Mat texture
 Texture of the sl::Mesh. More...
 

Detailed Description

Class representing a mesh and containing the geometric (and optionally texture) data of the scene captured by the spatial mapping module.

By default the mesh is defined as a set of chunks.
This way we update only the data that has to be updated avoiding a time consuming remapping process every time a small part of the sl::Mesh is updated.

Member Typedef Documentation

◆ chunkList

typedef std::vector<size_t> chunkList

Vector of chunks id.

Constructor and Destructor

◆ Mesh()

Mesh ( )

Default constructor.

Creates an empty sl::Mesh.

◆ ~Mesh()

~Mesh ( )

Default destructor.

Functions

◆ operator[]()

Chunk& operator[] ( int  index)

Defines the [] operator to directly access the desired chunk.

◆ getNumberOfTriangles()

size_t getNumberOfTriangles ( )

Computes the total number of triangles stored in all chunks.

Returns
The number of triangles stored in all chunks.

◆ updateMeshFromChunkList()

void updateMeshFromChunkList ( chunkList  IDs = chunkList())

Updates vertices / normals / triangles / uv from chunk data pointed by the given sl::Mesh::chunkList.

Parameters
IDs: Indices of chunks which will be concatenated. Default: (empty).
Note
If the given sl::Mesh::chunkList is empty, all chunks will be used to update the current sl::Mesh.

◆ getVisibleList()

chunkList getVisibleList ( Transform  camera_pose)

Computes the sl::Mesh::chunkList of visible chunks from a specific point of view.

Parameters
camera_pose: Point of view (given in the same reference as the vertices).
Returns
The list of id of visible chunks.

◆ getSurroundingList()

chunkList getSurroundingList ( Transform  camera_pose,
float  radius 
)

Computes the sl::Mesh::chunkList of chunks close to a specific point of view.

Parameters
camera_pose: Point of view (given in the same reference as the vertices).
radius: Radius determining closeness (given in the same unit as the mesh).
Returns
The list of id of chunks close to the given point.

◆ filter()

bool filter ( MeshFilterParameters  mesh_filter_params = MeshFilterParameters(),
bool  update_chunk_only = false 
)

Filters the mesh.

The resulting mesh is smoothed, small holes are filled, and small blobs of non-connected triangles are deleted.

Parameters
mesh_filter_params: Filtering parameters. Default: a preset of sl::MeshFilterParameters.
update_chunk_only: Whether to only update chunks (and not vertices / normals / triangles).
Default: false.
Returns
True if the mesh was successfully filtered, otherwise false.
Note
The filtering is a costly operation.
It is not recommended to call it every time you retrieve a mesh but only at the end of your spatial mapping process.

◆ applyTexture()

bool applyTexture ( MESH_TEXTURE_FORMAT  texture_format = MESH_TEXTURE_FORMAT::RGB)

Applies a texture to the mesh.

By using this method you will get access to uv, and texture.
The number of triangles in the mesh may slightly differ before and after calling this method due to missing texture information.
There is only one texture for the mesh, the uv of each chunk are expressed for it in its entirety.
Vectors of vertices / normals and uv have now the same size.

Parameters
texture_format: Number of channels desired for the computed texture.
Default: sl::MESH_TEXTURE_FORMAT::RGB.
Returns
True if the mesh was successfully textured, otherwise false.
Note
This method can be called as long as you do not start a new spatial mapping process (due to shared memory).
This method can require a lot of computation time depending on the number of triangles in the mesh.
It is recommended to call it once at the end of your spatial mapping process.
Warning
The sl::SpatialMappingParameters.save_texture parameter must be set to true when enabling the spatial mapping to be able to apply the textures.
The mesh should be filtered before calling this method since filter() will erase the textures.
The texturing is also significantly slower on non-filtered meshes.

◆ mergeChunks()

void mergeChunks ( int  faces_per_chunk)

Merges current chunks.

This method can be used to merge chunks into bigger sets to improve rendering process.

Parameters
faces_per_chunk: Number of faces per chunk.
Note
This method is useful for Unity, which does not handle chunks with more than 65K vertices.
Warning
This method should not be called during spatial mapping process since mesh updates will revert this changes.

◆ getGravityEstimate()

sl::float3 getGravityEstimate ( )

Estimates the gravity vector.

This method looks for a dominant plane in the whole mesh considering that it is the floor (or a horizontal plane).

Returns
The estimated gravity vector.
Note
This can be used to find the gravity to create realistic physical interactions.

◆ getBoundaries()

std::vector<int> getBoundaries ( )

Compute the indices of boundary vertices.

Returns
The indices of boundary vertices.

◆ save()

bool save ( String  filename,
MESH_FILE_FORMAT  type = MESH_FILE_FORMAT::OBJ,
chunkList  IDs = chunkList() 
)

Saves the current sl::Mesh into a file.

Parameters
filename: Path of the file to store the mesh in.
type: File extension type. Default: sl::MESH_FILE_FORMAT::OBJ.
IDs: Set of chunks to be saved. Default: (empty) (all chunks are saved)
Returns
True if the file was successfully saved, otherwise false.
Note
Only sl::MESH_FILE_FORMAT::OBJ support textures data.
This method operates on the sl.Mesh not on chunks.
This way you can save different parts of your sl.Mesh by updating it with updateMeshFromChunkList().

◆ load()

bool load ( String  filename,
bool  update_chunk_only = false 
)

Loads the mesh from a file.

Parameters
filename: Path of the file to load the mesh from.
update_chunk_only: Whether to only load data in chunks (and not vertices / normals / triangles).
Default: false.
Returns
True if the mesh was successfully loaded, otherwise false.
Note
Updating a sl::Mesh is time consuming. Consider using only chunks for better performances.

◆ clear()

void clear ( )

Clears all the data.

Variables

◆ chunks

std::vector<Chunk> chunks

Vector of chunks constituting the sl::Mesh.

◆ vertices

std::vector<float3> vertices

Vector of vertices.

Vertices are defined by a 3D point {x, y, z}.

◆ triangles

std::vector<uint3> triangles

Vector of triangles/faces.

Triangles are defined as a set of three vertices indexes {v1, v2, v3}.

◆ normals

std::vector<float3> normals

Vector of normals.

Normals are defined by three components {nx, ny, nz}.

Note
A normal is defined for each vertex.

◆ colors

std::vector<uchar3> colors

Vector of colors.

Colors are defined by three components {b, g, r}.

Note
A color is defined for each vertex.

◆ uv

std::vector<float2> uv

UVs defines the 2D projection of each vertices onto the texture.

Values are normalized [0, 1] and start from the bottom left corner of the texture (as requested by OpenGL). In order to display a textured mesh you need to bind the texture and then draw each triangle by picking its uv values.

Note
Contains data only if your mesh has textures (by loading it or calling sl::Mesh.applyTexture()).

◆ texture

Mat texture

Texture of the sl::Mesh.

Note
Contains data only if your mesh has textures (by loading it or calling sl::Mesh.applyTexture()).