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
 

General 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(0))
 Updates vertices / normals / triangles / uv from chunks' data pointed by the given chunkList. More...
 
chunkList getVisibleList (Transform camera_pose)
 Computes the list of visible chunk 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_RGB)
 Applies texture to the mesh. More...
 
void mergeChunks (int faces_per_chunk)
 Merges currents chunks. More...
 
sl::float3 getGravityEstimate ()
 Estimates the gravity vector. More...
 
std::vector< int > getBoundaries ()
 Compute the indices of boundaries vertices. More...
 
bool save (String filename, MESH_FILE_FORMAT type=MESH_FILE_OBJ, chunkList IDs=chunkList(0))
 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
 
Texture 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

typedef std::vector<size_t> chunkList

Constructor and Destructor

Mesh ( )

Default constructor which creates an empty Mesh.

~Mesh ( )

Mesh destructor.

Functions

Chunk& operator[] ( int  index)

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

size_t getNumberOfTriangles ( )

Computes the total number of triangles stored in all chunks.

Returns
The number of triangles stored in all chunks.
void updateMeshFromChunkList ( chunkList  IDs = chunkList(0))

Updates vertices / normals / triangles / uv from chunks' data pointed by the given chunkList.

Parameters
IDs: the index 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.
chunkList getVisibleList ( Transform  camera_pose)

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

Parameters
world_reference_pose: the point of view, given in world reference.
Returns
The list of visible chunks.
chunkList getSurroundingList ( Transform  camera_pose,
float  radius 
)

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

Parameters
world_reference_position: the point of view, given in world reference.
radius: the radius in defined UNIT.
Returns
The list of chunks close to the given point.
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) are updated otherwise only the chunk's data are 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.
bool applyTexture ( MESH_TEXTURE_FORMAT  texture_format = MESH_TEXTURE_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 functions due to missing texture information. There is only one texture for the mesh, the uv of each chunks are expressed for it in its globality. Vectors of vertices/normals and uv have now the same size.

Parameters
texture_format: define the number of channels desired for the computed texture. default : MESH_TEXTURE_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. Its recommended to call it once a 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.
void mergeChunks ( int  faces_per_chunk)

Merges currents chunks.

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

Parameters
faces_per_chunk: define 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.
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.
std::vector<int> getBoundaries ( )

Compute the indices of boundaries vertices.

Returns
The indices of boundaries vertices.
bool save ( String  filename,
MESH_FILE_FORMAT  type = MESH_FILE_OBJ,
chunkList  IDs = chunkList(0) 
)

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_OBJ.
IDs: (by default empty) Specify a set of chunks to be saved, if none provided alls chunks are saved. default : (empty).
Returns
True if the file was successfully saved, false otherwise.
Note
Only MESH_FILE_OBJ support textures data.
This function operate on the Mesh not on the chunks. This way you can save different parts of your Mesh (update your Mesh with updateMeshFromChunkList).
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) are updated otherwise only the chunk's data are 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.
void clear ( )

Clears all the data.

Variables

std::vector<Chunk> chunks

contains the list of chunks

std::vector<float3> vertices

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

std::vector<uint3> triangles

Triangles (or faces) contains the index of its three vertices. It corresponds to the 3 vertices of the triangle {v1, v2, v3}.

std::vector<float3> normals

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

std::vector<float2> uv

UVs defines the 2D projection of each vertices 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 triangles by picking its uv values.

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

Texture of the Mesh.

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