|
libfs
Header-only C++11 library for accessing FreeSurfer neuroimaging data
|
Models a triangular mesh, used for brain surface meshes. More...
#include <libfs.h>

Classes | |
| struct | _tupleHashFunction |
Hash function for 2-tuples of <size_t, sizt_t>, used to hash an edge of a graph or mesh. | |
Public Types | |
| typedef std::unordered_set< std::tuple< size_t, size_t >, _tupleHashFunction > | edge_set |
| Datastructure for storing, and quickly querying the existence of, mesh edges. More... | |
Public Member Functions | |
| Mesh (std::vector< float > cvertices, std::vector< int32_t > cfaces) | |
| Construct a Mesh from the given vertices and faces. | |
| Mesh (std::vector< std::vector< float >> cvertices, std::vector< std::vector< int32_t >> cfaces) | |
| Mesh () | |
| Construct an empty Mesh. | |
| std::string | to_obj () const |
| Return string representing the mesh in Wavefront Object (.obj) format. More... | |
| std::vector< std::vector< bool > > | as_adjmatrix () const |
| Return adjacency matrix representation of this mesh. More... | |
| edge_set | as_edgelist () const |
| Return edge list representation of this mesh. More... | |
| std::vector< std::vector< size_t > > | as_adjlist (const bool via_matrix=true) const |
| Return adjacency list representation of this mesh. More... | |
| std::vector< float > | smooth_pvd_nn (const std::vector< float > pvd, const size_t num_iter=1, const bool via_matrix=true, const bool with_nan=true, const bool detect_nan=true) const |
| Smooth given per-vertex data using nearest neighbor smoothing. More... | |
| void | to_obj_file (const std::string &filename) const |
| Export this mesh to a file in Wavefront OBJ format. More... | |
| std::pair< std::unordered_map< int32_t, int32_t >, fs::Mesh > | submesh_vertex (const std::vector< int32_t > &old_vertex_indices, const bool mapdir_fulltosubmesh=false) const |
| Compute a new mesh that is a submesh of this mesh, based on a subset of the vertices of this mesh. More... | |
| size_t | num_vertices () const |
| Return the number of vertices in this mesh. More... | |
| size_t | num_faces () const |
| Return the number of faces in this mesh. More... | |
| const int32_t & | fm_at (const size_t i, const size_t j) const |
| Retrieve a vertex index of a face, treating the faces vector as an nx3 matrix. More... | |
| std::vector< int32_t > | face_vertices (const size_t face) const |
| Get all vertex indices of the face, given by its index. More... | |
| std::vector< float > | vertex_coords (const size_t vertex) const |
| Get all coordinates of the vertex, given by its index. More... | |
| const float & | vm_at (const size_t i, const size_t j) const |
| Retrieve a single (x, y, or z) coordinate of a vertex, treating the vertices vector as an nx3 matrix. More... | |
| std::string | to_ply () const |
| Return string representing the mesh in PLY format. Overload that works without passing a color vector. More... | |
| std::string | to_ply (const std::vector< uint8_t > col) const |
| Return string representing the mesh in PLY format. More... | |
| void | to_ply_file (const std::string &filename) const |
| Export this mesh to a file in Stanford PLY format. More... | |
| void | to_ply_file (const std::string &filename, const std::vector< uint8_t > col) const |
| Export this mesh to a file in Stanford PLY format with vertex colors. More... | |
| std::string | to_off () const |
| Return string representing the mesh in OFF format. Overload that works without passing a color vector. More... | |
| std::string | to_off (const std::vector< uint8_t > col) const |
| Return string representing the mesh in PLY format. More... | |
| void | to_off_file (const std::string &filename) const |
| Export this mesh to a file in OFF format. More... | |
| void | to_off_file (const std::string &filename, const std::vector< uint8_t > col) const |
| Export this mesh to a file in OFF format with vertex colors (COFF). More... | |
Static Public Member Functions | |
| static fs::Mesh | construct_cube () |
| Construct and return a simple cube mesh. More... | |
| static fs::Mesh | construct_pyramid () |
| Construct and return a simple pyramidal mesh. More... | |
| static fs::Mesh | construct_grid (const size_t nx=4, const size_t ny=5, const float distx=1.0, const float disty=1.0) |
| Construct and return a simple planar grid mesh. More... | |
| static std::vector< float > | smooth_pvd_nn (const std::vector< std::vector< size_t >> mesh_adj, const std::vector< float > pvd, const size_t num_iter=1, const bool with_nan=true, const bool detect_nan=true) |
| Smooth given per-vertex data using nearest neighbor smoothing based on adjacency list mesh represenation. More... | |
| static std::vector< std::vector< size_t > > | extend_adj (const std::vector< std::vector< size_t >> mesh_adj, const size_t extend_by=1, std::vector< std::vector< size_t >> mesh_adj_ext=std::vector< std::vector< size_t >>()) |
| Extend mesh neighborhoods based on mesh adjacency representation. More... | |
| static std::vector< float > | curv_data_for_orig_mesh (const std::vector< float > data_submesh, const std::unordered_map< int32_t, int32_t > submesh_to_orig_mapping, const int32_t orig_mesh_num_vertices, const float fill_value=std::numeric_limits< float >::quiet_NaN()) |
| Given per-vertex data for a submesh, add NAN values inbetween to restore the original mesh size. More... | |
| static void | from_obj (Mesh *mesh, std::istream *is) |
| Read a brainmesh from a Wavefront object format stream. More... | |
| static void | from_obj (Mesh *mesh, const std::string &filename) |
| Read a brainmesh from a Wavefront object format mesh file. More... | |
| static void | from_off (Mesh *mesh, std::istream *is, const std::string &source_filename="") |
| Read a brainmesh from an Object File format (OFF) stream. More... | |
| static void | from_off (Mesh *mesh, const std::string &filename) |
| Read a brainmesh from an OFF format mesh file. More... | |
| static void | from_ply (Mesh *mesh, std::istream *is) |
| Read a brainmesh from a Stanford PLY format stream. More... | |
| static void | from_ply (Mesh *mesh, const std::string &filename) |
| Read a brainmesh from a Stanford PLY format mesh file. More... | |
Public Attributes | |
| std::vector< float > | vertices |
| n x 3 vector of the x,y,z coordinates for the n vertices. The x,y,z coordinates for a single vertex form consecutive entries. | |
| std::vector< int32_t > | faces |
| n x 3 vector of the 3 vertex indices for the n triangles or faces. The 3 vertices of a single face form consecutive entries. | |
Models a triangular mesh, used for brain surface meshes.
Represents a vertex-indexed mesh. The n vertices are stored as 3D point coordinates (x,y,z) in a vector of length 3n, in which 3 consecutive values represent the x, y and z coordinate of the same vertex. The m faces are stored as a vector of 3m integers, where 3 consecutive values represent the 3 vertices (by index) making up the respective face. Vertex indices are 0-based.
| typedef std::unordered_set<std::tuple<size_t, size_t>, _tupleHashFunction> fs::Mesh::edge_set |
Datastructure for storing, and quickly querying the existence of, mesh edges.
This is an unordered set of 2-tuples, where each tuple represents an edge, given as a pair of vertex indices. Each edge occurs twice in the list, once as make_tuple(i,j) and once as make_tuple(j,i). Use the API of std::unordered_set to interact with it.
|
inline |
Return adjacency list representation of this mesh.
| via_matrix | whether the computation should be done via an step involving an adjacency matrix, or via an edge set. Leaving this at true temporarily requires a lot of memory for large meshes, but is faster. |
|
inline |
Return adjacency matrix representation of this mesh.
|
inline |
Return edge list representation of this mesh.
fs::Mesh::edge_set, i.e., an unordered set of 2-tuples, where each tuple represents an edge, given as a pair of vertex indices. Each edge occurs twice in the list, once as make_tuple(i,j) and once as make_tuple(j,i).
|
inlinestatic |
Construct and return a simple cube mesh.
|
inlinestatic |
Construct and return a simple planar grid mesh.
This is a 2D rectangular grid embedded in 3D. Each rectangular cell consists of 2 triangular faces. The height (z coordinate) for all vertices is 0.0.
| nx | number of vertices in x direction |
| ny | number of vertices in y direction |
| distx | distance between vertices in x direction |
| disty | distance between vertices in y direction |
| std::invalid_argument | error if nx or ny are < 2. |
|
inlinestatic |
Construct and return a simple pyramidal mesh.
This constructs a right square pyramid with base edge length 1 and height 1. Think of the Great Pyramid of Giza.
|
inlinestatic |
Given per-vertex data for a submesh, add NAN values inbetween to restore the original mesh size.
| data_submesh | vector of per-vertex data values, one value per mesh vertex of the submesh. |
| submesh_to_orig_mapping | map<int, int>, mapping vertex indices of the submesh to vertex indices of the original, full mesh. |
| orig_mesh_num_vertices | number of vertices of the original, full mesh. |
fs::Mesh::submesh_vertex for how to get the submesh_to_orig_mapping parameter.
|
inlinestatic |
Extend mesh neighborhoods based on mesh adjacency representation.
This function is mainly extended to extend a source neighborhood representation (typically the mesh's k=1 neighborhood, i.e., the adjacency list of the mesh) to a higher k. In a k=3 neighborhood, the neighorhood around a source vertex includes all vertices in edge distance up to 3 from the source vertex (but not the source vertex itself).
| mesh_adj | The adjacency list representation of the underlying mesh, the outer vector must have size N for a mesh with N vertices. |
| extend_by | the number of edges to hop to extend the neighborhoods. |
| mesh_adj_ext | the starting neighborhoods to extend, same representation as mesh_adj. The outer vector must have size N or 0. If passed as an empty vector, this will be ignored and a copy of the mesh_adj is used as the start_neighborhoods. |
|
inline |
Get all vertex indices of the face, given by its index.
| face | the face index |
| std::range_error | on invalid index |
|
inline |
Retrieve a vertex index of a face, treating the faces vector as an nx3 matrix.
| i | the row index, valid values are 0..num_faces-1. |
| j | the column index, valid values are 0..2 (for the 3 vertices of a face). |
| std::range_error | on invalid index |
j of face i
|
inlinestatic |
Read a brainmesh from a Wavefront object format stream.
This only reads the geometry, optional format extensions like materials are ignored (but files including them should parse fine).
| mesh | pointer to fs:Mesh instance to be filled. |
| is | stream holding a text representation of a mesh in Wavefront object format. |
| std::domain_error | if the file format is invalid. |
|
inlinestatic |
Read a brainmesh from a Wavefront object format mesh file.
This only reads the geometry, optional format extensions like materials are ignored (but files including them should parse fine).
| mesh | pointer to fs:Mesh instance to be filled. |
| filename | path to input wavefront obj mesh to be read. |
| std::runtime_error | if the file cannot be read. |
| std::domain_error | if the file format is invalid. |
|
inlinestatic |
Read a brainmesh from an Object File format (OFF) stream.
| mesh | pointer to fs:Mesh instance to be filled. |
| is | An open std::istream or derived class stream from which to read the data, e.g., std::ifstream or std::istringstream. |
| source_filename | optional, used in error messages only. The source file name, if any. |
| std::domain_error | if the file format is invalid. |
|
inlinestatic |
Read a brainmesh from an OFF format mesh file.
The OFF is the Object File Format (file extension .off) is a simple text-based mesh file format. Not to be confused with the Wavefront Object format (.obj).
| mesh | pointer to fs:Mesh instance to be filled. |
| filename | path to input wavefront obj mesh to be read. |
| std::runtime_error | if the file cannot be read. |
| std::domain_error | if the file format is invalid. |
|
inlinestatic |
Read a brainmesh from a Stanford PLY format stream.
| mesh | pointer to fs:Mesh instance to be filled. |
| is | An open std::istream or derived class stream from which to read the data, e.g., std::ifstream or std::istringstream. |
| std::domain_error | if the file format is invalid. |
|
inlinestatic |
Read a brainmesh from a Stanford PLY format mesh file.
The PLY format exists in text and binary forms, and the binary form can be little endian or big endian. This file reads the ASCII text format version.
| mesh | pointer to fs:Mesh instance to be filled. |
| filename | path to input wavefront obj mesh to be read. |
| std::runtime_error | if the file cannot be read. |
| std::domain_error | if the file format is invalid. |
|
inline |
Return the number of faces in this mesh.
|
inline |
Return the number of vertices in this mesh.
|
inline |
Smooth given per-vertex data using nearest neighbor smoothing.
| pvd | vector of per-vertex data values, one value per mesh vertex. |
| num_iter | number of iterations of smoothing to perform. |
| via_matrix | passed on to this->as_asjlist(), whether to construct the adjacency list of the mesh using an intermediate step involving an adjacency matrix, as opposed to using an edge set. The latter is slower but requires less memory. |
| with_nan | whether you need support for NAN values in pvd. A bit slower if active. Ignored if detectnan is true. |
| detect_nan | whether to auto-detect presence of NAN values, ignoring the setting of with_nan. |
pvd param.
|
inlinestatic |
Smooth given per-vertex data using nearest neighbor smoothing based on adjacency list mesh represenation.
| mesh_adj | the mesh, given as an adjacency list. The outer vector has size num_vertices, and the inner vectors sizes are the number of neighbors of the respective vertex. |
| pvd | vector of per-vertex data values, one value per mesh vertex. Must not include NAN values. See smooth_pvd_nn_nan if you need support for NAN values. |
| num_iter | number of iterations of smoothing to perform. |
| with_nan | whether you need support for NAN values in pvd. A bit slower if active. Ignored if detectnan is true. |
| detect_nan | whether to auto-detect presence of NAN values, ignoring the setting of with_nan. |
pvd param.
|
inline |
Compute a new mesh that is a submesh of this mesh, based on a subset of the vertices of this mesh.
| old_vertex_indices | vector of vertex indices of this mesh, which should be included in the submesh. |
| mapdir_fulltosubmesh | whether to return a map from the old (full mesh) to the new (submesh) vertex indices (true), or the other way around (false, the default) as the first element of the returned pair. |
|
inline |
Return string representing the mesh in Wavefront Object (.obj) format.
|
inline |
Export this mesh to a file in Wavefront OBJ format.
| filename | path to the output file, will be overwritten if existing. |
| std::runtime_error | if the target file cannot be opened. |
|
inline |
Return string representing the mesh in OFF format. Overload that works without passing a color vector.
|
inline |
Return string representing the mesh in PLY format.
| col | u_char vector of RGB color values, 3 per vertex. They must appear by vertex, i.e. in order v0_red, v0_green, v0_blue, v1_red, v1_green, v1_blue. Leave empty if you do not want colors. |
| std::invalid_argument | if the number of vertex colors does not match the number of vertices. |
|
inline |
Export this mesh to a file in OFF format.
| std::runtime_error | if the target file cannot be opened. |
|
inline |
Export this mesh to a file in OFF format with vertex colors (COFF).
| std::runtime_error | if the target file cannot be opened, std::invalid_argument if the number of vertex colors does not match the number of vertices. |
|
inline |
Return string representing the mesh in PLY format. Overload that works without passing a color vector.
|
inline |
Return string representing the mesh in PLY format.
| col | u_char vector of RGB color values, 3 per vertex. They must appear by vertex, i.e. in order v0_red, v0_green, v0_blue, v1_red, v1_green, v1_blue. Leave empty if you do not want colors. |
| std::invalid_argument | if the number of vertex colors does not match the number of vertices. |
|
inline |
Export this mesh to a file in Stanford PLY format.
| std::runtime_error | if the target file cannot be opened. |
|
inline |
Export this mesh to a file in Stanford PLY format with vertex colors.
| std::runtime_error | if the target file cannot be opened, std::invalid_argument if the number of vertex colors does not match the number of vertices. |
|
inline |
Get all coordinates of the vertex, given by its index.
| vertex | the vertex index |
| std::range_error | on invalid index |
|
inline |
Retrieve a single (x, y, or z) coordinate of a vertex, treating the vertices vector as an nx3 matrix.
| i | the row index, valid values are 0..num_vertices. |
| j | the column index, valid values are 0..2 (for the x,y,z coordinates). |
| std::range_error | on invalid index |
1.8.13