Mesh Class Reference

A mesh contains the geometric (and optionally texture) data of the scene captured by spatial mapping. More...

Types

typedef std::vector< size_t > chunkList
 

Functions

 Mesh ()
 Default constructor which creates an empty Mesh. More...
 
 ~Mesh ()
 Mesh 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 chunkList. More...
 
chunkList getVisibleList (Transform camera_pose)
 Computes the list of visible chunks from a specific point of view. More...
 
chunkList getSurroundingList (Transform camera_pose, float radius)
 Computes the list of chunks which are 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 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 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
 
std::vector< float3vertices
 
std::vector< uint3triangles
 
std::vector< float3normals
 
std::vector< float2uv
 
Mat texture
 

Detailed Description

A mesh contains the geometric (and optionally texture) data of the scene captured by spatial mapping.

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 Mesh is updated.

Member Typedef Documentation

◆ chunkList

typedef std::vector<size_t> chunkList

Constructor and Destructor

◆ Mesh()

Mesh ( )

Default constructor which creates an empty Mesh.

◆ ~Mesh()

~Mesh ( )

Mesh 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 chunkList.

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

◆ getVisibleList()

chunkList getVisibleList ( Transform  camera_pose)

Computes the list of visible chunks from a specific point of view.

Parameters
camera_pose: the point of view, given in world reference.
Returns
The list of visible chunks.

◆ getSurroundingList()

chunkList getSurroundingList ( Transform  camera_pose,
float  radius 
)

Computes the list of chunks which are close to a specific point of view.

Parameters
camera_pose: the point of view, given in world reference.
radius: the radius in defined UNIT.
Returns
The list 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 in smoothed, small holes are filled and small blobs of non connected triangles are deleted.

Parameters
mesh_filter_params: defines the filtering parameters, for more info checkout the MeshFilterParameters documentation. default : preset.
update_chunk_only: if set to false the mesh data (vertices/normals/triangles) is updated otherwise only the chunk data is updated. default : false.
Returns
True if the filtering was successful, false otherwise.
Note
The filtering is a costly operation, its not recommended to call it every time you retrieve a mesh but at the end of your spatial mapping process.

◆ applyTexture()

bool applyTexture ( MESH_TEXTURE_FORMAT  texture_format = MESH_TEXTURE_FORMAT::RGB)

Applies texture to the mesh.

By using this function you will get access to uv, and texture. The number of triangles in the mesh may slightly differ before and after calling this function 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: defines the number of channels desired for the computed texture. default : MESH_TEXTURE_FORMAT::RGB.
Returns
True if the texturing was successful, false otherwise.
Note
This function can be called as long as you do not start a new spatial mapping process, due to shared memory.
This function can require a lot of computation time depending on the number of triangles in the mesh. It's recommended to call it once at the end of your spatial mapping process.
Warning
The save_texture parameter in SpatialMappingParameters must be set as true when enabling the spatial mapping to be able to apply the textures.
The mesh should be filtered before calling this function 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 can be used to merge chunks into bigger sets to improve rendering process.

Parameters
faces_per_chunk: defines the new number of faces per chunk (useful for Unity that doesn't handle chunks over 65K vertices).
Warning
You should not use this function during spatial mapping process because mesh updates will revert this changes.

◆ getGravityEstimate()

sl::float3 getGravityEstimate ( )

Estimates the gravity vector.

This function looks for a dominant plane in the whole mesh considering that it is the floor (or a horizontal plane). This can be used to find the gravity and then create realistic physical interactions.

Returns
The gravity vector.

◆ 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 Mesh into a file.

Parameters
filename: the path and filename of the mesh.
type: defines the file type (extension). default : MESH_FILE_FORMAT::OBJ.
IDs: (by default empty) Specify a set of chunks to be saved, if none provided all chunks are saved. default : (empty).
Returns
True if the file was successfully saved, false otherwise.
Note
Only MESH_FILE_FORMAT::OBJ support textures data.
This function operates on the Mesh not on the chunks. This way you can save different parts of your Mesh (update your Mesh with updateMeshFromChunkList).

◆ load()

bool load ( String  filename,
bool  update_chunk_only = false 
)

Loads the mesh from a file.

Parameters
filename: the path and filename of the mesh (do not forget the extension).
update_chunk_only: if set to false the mesh data (vertices/normals/triangles) is updated otherwise only the chunk data is updated. default : false.
Returns
True if the loading was successful, false otherwise.
Note
Updating the Mesh is time consuming, consider using only Chunks for better performances.

◆ clear()

void clear ( )

Clears all the data.

Variables

◆ chunks

std::vector<Chunk> chunks

contains the list of chunks

◆ vertices

std::vector<float3> vertices

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

◆ triangles

std::vector<uint3> triangles

Vector of triangles, defined as a set of three vertices {v1, v2, v3}.

◆ normals

std::vector<float3> normals

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

◆ uv

std::vector<float2> uv

UVs define the 2D projection of each vertex onto the Texture.
Values are normalized [0;1], starting 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 applyTexture).

◆ texture

Mat texture

Texture of the Mesh.

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