CortidQCT  1.2.2.52
Public Types | Public Member Functions | List of all members
CortidQCT::Mesh< T > Class Template Reference

A triangle mesh class. More...

#include <Mesh.h>

Public Types

using Scalar = T
 Scalar type of the vector space the embedding.
 
using Index = std::ptrdiff_t
 Index type.
 
using Size = std::size_t
 Size type.
 
using Label = unsigned int
 Label type.
 

Public Member Functions

template<class T>
std::array< T, 3 > cartesianRepresentation (BarycentricPoint< T, Mesh< T >::Index > const &point) const
 

Construction

 Mesh () noexcept(noexcept(VertexData())&&noexcept(IndexData())&&noexcept(LabelData())&&noexcept(VertexData()))
 Constructs an empty mesh.
 
 Mesh (std::size_t nVertices, std::size_t nTriangles) noexcept(noexcept(VertexData(3 *nVertices, T{0}))&&noexcept(IndexData(3 *nTriangles, Index{0}))&&noexcept(LabelData(nVertices, Label{0}))&&noexcept(NormalData(3 *nVertices, T{0})))
 Constructs an uninitialized mesh with the given vertex and triangle count.
 

Accessors

Size vertexCount () const noexcept
 Number of vertices.
 
Size triangleCount () const noexcept
 Number of triangles.
 
bool isEmpty () const noexcept
 true iff the mesh is empty More...
 

IO

MeshloadFromFile (std::string const &meshFilename, std::string const &labelFilename)
 Load mesh and labels from ASCII file using format auto detection. More...
 
MeshloadFromFile (std::string const &meshFilename, ColorToLabelMap< Label, double > const &colorMap=ColorToLabelMaps::defaultMap< Label, double >)
 Load mesh from ASCII file using format auto detection and extract labels from per-vertex colors. More...
 
void writeToFile (std::string const &meshFilename, std::string const &labelFilename) const
 Writes mesh to ASCII file using format auto detection. More...
 
void writeToFile (std::string const &meshFilename, LabelToColorMap< double, Label > const &labelMap=LabelToColorMaps::defaultMap< double, Label >) const
 Writes mesh to ASCII file using format auto detection and encode labels as colors. More...
 

Queries

std::array< T, 3 > cartesianRepresentation (BarycentricPoint< T, Index > const &point) const
 Returns the cartesian coordinate of a point in barycentric coordinates. More...
 
template<class InputIterator , class OutputIterator >
void cartesianRepresentation (InputIterator begin, InputIterator end, OutputIterator out) const
 Converts a sequence of barycentric coordinates into caresian coordinates. More...
 
std::vector< std::array< T, 3 > > cartesianRepresentation (std::vector< BarycentricPoint< T, Index >> const &points) const
 Converts a sequence of barycentric coordinates into caresian coordinates. More...
 
template<class PtIter , class AttrIter , class OutputIterator >
void barycentricInterpolation (PtIter pointsBegin, PtIter pointsEnd, AttrIter attributesBegin, OutputIterator out, std::size_t attributeDimension=1) const
 Interpolates per-vertex values for points inside a triangle. More...
 
template<class InputIterator , class OutputIterator >
void rayIntersections (InputIterator raysBegin, InputIterator raysEnd, OutputIterator intersectionsOut) const
 Computes the intersection of a set of rays with the mesh. More...
 
RayMeshIntersection< T > rayIntersection (Ray< T > const &ray) const
 Computes intersection with the given ray and the mesh. More...
 
void updatePerVertexNormals ()
 Re-computes per-vertex normals.
 

Modifyers

Mesh< T > & upsample (std::size_t nTimes=1)
 Upsample the mesh without touching the original vertices. More...
 

Raw Data Access

The methods in this section all call a functional with a pointer to raw data as its argument. The pointer only guaranteed to be valid within the call to the given functional.

Attention
Do not return the raw data pointer or save it in any other way!
template<class F >
auto withUnsafeVertexPointer (F &&f) const noexcept(noexcept(f(std::declval< const VertexData >().data())))
 Calls the given functional with an unsafe pointer to the raw vertex storage. More...
 
template<class F >
auto withUnsafeVertexPointer (F &&f) noexcept(noexcept(f(std::declval< VertexData >().data())))
 
template<class F >
auto withUnsafeIndexPointer (F &&f) const noexcept(noexcept(f(std::declval< const IndexData >().data())))
 Calls the given functional with an unsafe pointer to the raw index storage. More...
 
template<class F >
auto withUnsafeIndexPointer (F &&f) noexcept(noexcept(f(std::declval< IndexData >().data())))
 
template<class F >
auto withUnsafeLabelPointer (F &&f) const noexcept(noexcept(f(LabelData().data())))
 Calls the given functional with an unsafe pointer to the raw label storage. More...
 
template<class F >
auto withUnsafeLabelPointer (F &&f) noexcept(noexcept(f(LabelData().data())))
 
template<class F >
auto withUnsafeVertexNormalPointer (F &&f) const noexcept(noexcept(f(std::declval< const NormalData >().data())))
 Calls the given functional with an unsafe pointer to the raw per vertex normal storage. More...
 
template<class F >
auto withUnsafeVertexNormalPointer (F &&f) noexcept(noexcept(f(std::declval< NormalData >().data())))
 

Detailed Description

template<class T>
class CortidQCT::Mesh< T >

A triangle mesh class.

Template Parameters
TScalar type of the vector space of the embedding, must be a floating point type

Member Function Documentation

template<class T >
template<class PtIter , class AttrIter , class OutputIterator >
template void CortidQCT::Mesh< T >::barycentricInterpolation ( PtIter  pointsBegin,
PtIter  pointsEnd,
AttrIter  attributesBegin,
OutputIterator  out,
std::size_t  attributeDimension = 1 
) const

Interpolates per-vertex values for points inside a triangle.

This input of this function are some points on the surfac of the mesh in barycentric representation and a vector of per-vertex attributes/values that are to be interpolated. The per-vertex attributes/values do not have to be scalar, vector values attributes can be used by setting the attributeDimension paremter. The attributes must be in row major order, i.e. a full attribute vector is stored in consecutively in the underlying container.

Template Parameters
PtIterInputIterator of BarycentricPoint type
AttrIterRandomAccessIterator of scalar type
OutputIteratoroutput iterator acceptiong scalar of the same type as AttrIter
Parameters
[in]pointsBegininput iterator pointing to the first barycentric point
[in]pointsEndinput iterator pointing one element past the last barycentric point
[in]attributesBeginrandom access iterator pointing to the first attribute vector
[out]outoutput iterator
[in]attributeDimensionnumber of attribute dimensions, defaults to 1
Exceptions
std::out_of_rangeif a trinagle index is out of range In case of an exception out is only untouched if and only if PtIter conforms to ForwardIterator. If PtIter only conforms to IputIterator, all values up to the one where the exception happened will be written to out.
template<class T>
std::array<T, 3> CortidQCT::Mesh< T >::cartesianRepresentation ( BarycentricPoint< T, Index > const &  point) const

Returns the cartesian coordinate of a point in barycentric coordinates.

Parameters
[in]pointpoint in barycentric coodinate representation
Returns
vartesian coordinates of the point
Exceptions
std::out_of_rangeif the triangle index of the point is invalid.
template<class T >
template<class InputIterator , class OutputIterator >
void CortidQCT::Mesh< T >::cartesianRepresentation ( InputIterator  begin,
InputIterator  end,
OutputIterator  out 
) const

Converts a sequence of barycentric coordinates into caresian coordinates.

The implementation uses barycetnricInterpolation. OutputIterator's value_type must be T.

Parameters
[in]beginiterator that points to the first cartesian point
[in]endinterator that points right after the last point
[out]outoutput iterator
Exceptions
std::out_of_rangeif a triangle index is out of range
See also
barycentricInterpolation
template<class T>
std::vector<std::array<T, 3> > CortidQCT::Mesh< T >::cartesianRepresentation ( std::vector< BarycentricPoint< T, Index >> const &  points) const
inline

Converts a sequence of barycentric coordinates into caresian coordinates.

Parameters
[in]pointsstd::vector of barycentric points
Returns
a std::vector of cartesian points
Exceptions
std::out_of_rangeif a triangle index is out of range
template<class T>
bool CortidQCT::Mesh< T >::isEmpty ( ) const
inlinenoexcept

true iff the mesh is empty

The mesh is empty iff the triangle or the vertex count is zero

template<class T >
Mesh< T > & CortidQCT::Mesh< T >::loadFromFile ( std::string const &  meshFilename,
std::string const &  labelFilename 
)

Load mesh and labels from ASCII file using format auto detection.

Supported file formats are: obj, off, stl, wrl, ply, mesh, SIMesh. If a .off file with color data (COFF) is given and the labels should be extracted from the color data, use the overload loadFromFile(std::string const &, ColorToLabelMap<Label, double> const &).

Parameters
meshFilenamePath to the file to load the mesh from
labelFilenameOptional path to the file to load the vertex labels from.
Returns
Reference to the loaded mesh
Exceptions
std::invalid_argumentif the mesh or the labels could not be loaded from the given filename
std::invalid_argumentif the file file format could not be recognized
template<class T >
Mesh< T > & CortidQCT::Mesh< T >::loadFromFile ( std::string const &  meshFilename,
ColorToLabelMap< Label, double > const &  colorMap = ColorToLabelMaps::defaultMap<Label, double> 
)

Load mesh from ASCII file using format auto detection and extract labels from per-vertex colors.

Supported file formats are: off (COFF), SIMesh. Per-vertex colors are converted to labels using the given colormap. For SIMesh format, the labels are directly read from the file. For other formats use the overload loadFromFile(std::string const &, std::string const &)

Parameters
meshFilenamePath to the file to load the mesh from
colorMapMapping from RGB colorspace to labels. Defaults to ColorToLabelMaps::defaultMap().
Returns
Reference to the loaded mesh
Exceptions
std::invalid_argumentif the mesh could not be loaded from the given filename
std::invalid_argumentif the file file format could not be recognized
template<class T>
RayMeshIntersection< T > CortidQCT::Mesh< T >::rayIntersection ( Ray< T > const &  ray) const

Computes intersection with the given ray and the mesh.

See also
rayIntersections
Parameters
rayQuery ray
Returns
RayMeshIntersection object describing the intersection.
template<class T >
template<class InputIterator , class OutputIterator >
template void CortidQCT::Mesh< T >::rayIntersections ( InputIterator  raysBegin,
InputIterator  raysEnd,
OutputIterator  intersectionsOut 
) const

Computes the intersection of a set of rays with the mesh.

If for any ray no intersection can be found, the corresponding RayMeshIntersection object is left with its default values (its signed distance is infinity).

Template Parameters
InputIteratorInput iterator with value_type of Ray
OutputIteratorOutput iterator with value_type of RayMeshIntersection
Parameters
raysBeginIterator poiting to the first ray
raysEndIterator pointing one element past the last ray
intersectionsOutOutput iterator for intersections
template<class T >
Mesh< T > & CortidQCT::Mesh< T >::upsample ( std::size_t  nTimes = 1)

Upsample the mesh without touching the original vertices.

Parameters
nTimesnumber of subsample iterations
Returns
Reference to *this
template<class T>
template<class F >
auto CortidQCT::Mesh< T >::withUnsafeIndexPointer ( F &&  f) const
inlinenoexcept

Calls the given functional with an unsafe pointer to the raw index storage.

Indices are stored contiguously in memory: [i_0, i_1, ...].

Template Parameters
FFunction that accepts a Index const * pointer as the only argument.
Exceptions
noexcept(conditional)iff f(Index const *) is noexcept.
Returns
The return value of the functional
template<class T>
template<class F >
auto CortidQCT::Mesh< T >::withUnsafeLabelPointer ( F &&  f) const
inlinenoexcept

Calls the given functional with an unsafe pointer to the raw label storage.

Labels are stored contiguously in memory: [l_0, l_1, ...].

Template Parameters
FFunction that accepts a Label const * pointer as the only argument.
Exceptions
noexcept(conditional)iff f(Label const *) is noexcept.
Returns
The return value of the functional
template<class T>
template<class F >
auto CortidQCT::Mesh< T >::withUnsafeVertexNormalPointer ( F &&  f) const
inlinenoexcept

Calls the given functional with an unsafe pointer to the raw per vertex normal storage.

Vertex normals are stored contiguously in memory: [dx_0, dy_0, dz_0, dx_1, dy_1, dz_1, ...].

Template Parameters
FFunction that accepts a Scalar const * pointer as the only argument.
Exceptions
noexcept(conditional)iff f(Scalar const *) is noexcept.
Returns
The return value of the functional
template<class T>
template<class F >
auto CortidQCT::Mesh< T >::withUnsafeVertexPointer ( F &&  f) const
inlinenoexcept

Calls the given functional with an unsafe pointer to the raw vertex storage.

Vertices are stored contiguously in memory: [x_0, y_0, z_0, x_1, y_1, z_1, ...].

Template Parameters
FFunction that accepts a Scalar const * pointer as the only argument.
Exceptions
noexcept(conditional)iff f(Scalar const *) is noexcept.
Returns
The return value of the functional
template<class T >
void CortidQCT::Mesh< T >::writeToFile ( std::string const &  meshFilename,
std::string const &  labelFilename 
) const

Writes mesh to ASCII file using format auto detection.

Supported file formats are: obj, off, stl, wrl, ply, mesh, SIMesh. Labels are written rowwise to labelFilename. For encoding the labels in the color attribute use the overload writeToFile(std::string const &, LabelToColorMap<double, Label> const &).

Parameters
meshFilenamepath to the file to write the mesh to
labelFilenamepath to the file to write the labels to
Exceptions
std::invalid_argumentif the mesh or the labels could not be writted to the given file
std::invalid_argumentif the file file format could not be recognized
Note
Does nothing on empty meshes
template<class T >
void CortidQCT::Mesh< T >::writeToFile ( std::string const &  meshFilename,
LabelToColorMap< double, Label > const &  labelMap = LabelToColorMaps::defaultMap<double, Label> 
) const

Writes mesh to ASCII file using format auto detection and encode labels as colors.

Supported file formats are: off (coff), SIMesh. The labels are encoded in per-vertex colors using the given label to color map. For the 'SIMesh' format the labels are written directly into the mesh file, ignoring the color encoding. For storing the labels in a separate file use the overload writeToFile(std::string const &, std::string const &).

Parameters
meshFilenamepath to the file to write the mesh to
labelMapfunction that maps labels to RGB color values. Defaults to LabelToColorMaps::defaultMap().
Exceptions
std::invalid_argumentif the mesh could not be writted to the given file
std::invalid_argumentif the file file format could not be recognized
Note
Does nothing on empty meshes

The documentation for this class was generated from the following files: