23 #include <type_traits> 35 template <
class T>
class Mesh {
37 static_assert(std::is_floating_point<T>::value,
38 "Scalar must be a floating point type");
55 using VertexData = std::vector<Scalar>;
57 using IndexData = std::vector<Index>;
59 using LabelData = std::vector<Label>;
61 using NormalData = VertexData;
68 inline Mesh() noexcept(noexcept(VertexData()) && noexcept(IndexData()) &&
69 noexcept(LabelData()) && noexcept(VertexData())) {}
72 inline Mesh(std::size_t nVertices, std::size_t nTriangles) noexcept(
73 noexcept(VertexData(3 * nVertices, T{0})) &&
74 noexcept(IndexData(3 * nTriangles,
Index{0})) &&
75 noexcept(LabelData(nVertices,
Label{0})) &&
76 noexcept(NormalData(3 * nVertices, T{0})))
77 : vertexData_(3 * nVertices, T{0}), indexData_(3 * nTriangles,
Index{0}),
78 labelData_(nVertices,
Label{0}), normalData_(3 * nVertices, T{0}) {}
119 std::string
const &labelFilename);
140 ColorToLabelMaps::defaultMap<Label, double>);
158 std::string
const &labelFilename)
const;
181 LabelToColorMaps::defaultMap<double, Label>)
const;
213 template <
class InputIterator,
class OutputIterator>
215 OutputIterator out)
const;
226 using Cartesian = std::array<T, 3>;
227 std::vector<Cartesian> cartPoints(points.size());
229 auto const out =
reinterpret_cast<T *
>(cartPoints.data());
235 #pragma clang diagnostic push 236 #pragma clang diagnostic ignored "-Wdocumentation" 267 template <
class PtIter,
class AttrIter,
class OutputIterator>
269 AttrIter attributesBegin, OutputIterator out,
270 std::size_t attributeDimension = 1)
const;
271 #pragma clang diagnostic pop 273 #pragma clang diagnostic push 274 #pragma clang diagnostic ignored "-Wdocumentation" 289 template <
class InputIterator,
class OutputIterator>
291 OutputIterator intersectionsOut)
const;
307 #pragma clang diagnostic pop 350 noexcept(noexcept(f(
std::declval<const VertexData>().data()))) {
351 return f(vertexData_.data());
356 noexcept(f(std::declval<VertexData>().data()))) {
357 return f(vertexData_.data());
373 noexcept(noexcept(f(
std::declval<const IndexData>().data()))) {
374 return f(indexData_.data());
379 noexcept(f(std::declval<IndexData>().data()))) {
380 return f(indexData_.data());
396 noexcept(noexcept(f(LabelData().data()))) {
397 return f(labelData_.data());
403 return f(labelData_.data());
421 noexcept(noexcept(f(
std::declval<const NormalData>().data()))) {
422 return f(normalData_.data());
427 noexcept(f(std::declval<NormalData>().data()))) {
428 return f(normalData_.data());
434 void ensurePostconditions()
const;
437 VertexData vertexData_;
439 IndexData indexData_;
441 LabelData labelData_;
443 NormalData normalData_;
Name namespace for CortidQCT library.
Definition: CortidQCT.h:23
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.
Definition: Mesh.h:372
This finle contains definitions for color to index map types.
std::ptrdiff_t Index
Index type.
Definition: Mesh.h:45
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.
Definition: Mesh.h:349
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.
Definition: Mesh.cpp:502
void writeToFile(std::string const &meshFilename, std::string const &labelFilename) const
Writes mesh to ASCII file using format auto detection.
Definition: Mesh.cpp:299
A triangle mesh class.
Definition: BarycentricPoint.h:20
std::function< std::array< Scalar, 3 >(Label)> LabelToColorMap
Label to color map.
Definition: LabelToColorMap.h:30
std::array< T, 3 > cartesianRepresentation(BarycentricPoint< T, Index > const &point) const
Returns the cartesian coordinate of a point in barycentric coordinates.
void rayIntersections(InputIterator raysBegin, InputIterator raysEnd, OutputIterator intersectionsOut) const
Computes the intersection of a set of rays with the mesh.
Definition: Mesh.cpp:561
void updatePerVertexNormals()
Re-computes per-vertex normals.
Definition: Mesh.cpp:706
Definition: ColorToLabelMap.h:27
Mesh & loadFromFile(std::string const &meshFilename, std::string const &labelFilename)
Load mesh and labels from ASCII file using format auto detection.
Definition: Mesh.cpp:100
This finle contains definitions for label to color map types.
std::function< Label(Scalar, Scalar, Scalar)> ColorToLabelMap
Color to label map.
Definition: ColorToLabelMap.h:59
unsigned int Label
Label type.
Definition: Mesh.h:51
A basic ray datatype.
Definition: Ray.h:22
float Scalar
Scalar type of the vector space the embedding.
Definition: Mesh.h:42
Size triangleCount() const noexcept
Number of triangles.
Definition: Mesh.h:89
Definition: matlab-addons.c:7
This header contains the definition of the BarycentricPoint data type.
Definition: RayMeshIntersection.h:21
std::vector< std::array< T, 3 > > cartesianRepresentation(std::vector< BarycentricPoint< T, Index >> const &points) const
Converts a sequence of barycentric coordinates into caresian coordinates.
Definition: Mesh.h:224
Size vertexCount() const noexcept
Number of vertices.
Definition: Mesh.h:86
This file contains the definition of the RayMeshIntersection type.
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.
Definition: Mesh.h:420
auto withUnsafeLabelPointer(F &&f) const noexcept(noexcept(f(LabelData().data())))
Calls the given functional with an unsafe pointer to the raw label storage.
Definition: Mesh.h:395
RayMeshIntersection< T > rayIntersection(Ray< T > const &ray) const
Computes intersection with the given ray and the mesh.
Definition: Mesh.cpp:550
Mesh< T > & upsample(std::size_t nTimes=1)
Upsample the mesh without touching the original vertices.
Definition: Mesh.cpp:627
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.
Definition: Mesh.h:72
Definition of Ray data structure.
Mesh() noexcept(noexcept(VertexData())&&noexcept(IndexData())&&noexcept(LabelData())&&noexcept(VertexData()))
Constructs an empty mesh.
Definition: Mesh.h:68
BarycentricPoint data type. Represents a points on triangulation in barycentric coordinates.
Definition: BarycentricPoint.h:26
bool isEmpty() const noexcept
true iff the mesh is empty
Definition: Mesh.h:94