DHART
Loading...
Searching...
No Matches
HF::Geometry::MeshInfo< numeric_type > Class Template Reference

A collection of vertices and indices representing geometry. More...

#include <meshinfo.h>

+ Collaboration diagram for HF::Geometry::MeshInfo< numeric_type >:

Public Member Functions

 MeshInfo ()
 Construct an empty instance of MeshInfo. More...
 
 MeshInfo (const std::vector< std::array< numeric_type, 3 > > &vertices, int id, std::string name="")
 Construct a new MeshInfo object from an unindexed vector of vertices, an ID, and a name. More...
 
 MeshInfo (const std::vector< numeric_type > &in_vertices, const std::vector< int > &in_indexes, int id, std::string name="")
 Construct a new MeshInfo object from an indexed vector of vertices. More...
 
void AddVerts (const std::vector< std::array< numeric_type, 3 > > &verts)
 Add more vertices to this mesh. More...
 
int NumVerts () const
 Determine how many vertices are in this mesh. More...
 
int NumTris () const
 Calculate the total number of triangles in this mesh. More...
 
void ConvertToRhinoCoordinates ()
 Convert a mesh from Y-Up to Z-Up. More...
 
void ConvertToOBJCoordinates ()
 Convert a mesh from Z-Up to Y-Up. More...
 
void PerformRotation (numeric_type rx, numeric_type ry, numeric_type rz)
 Rotate this mesh by x, y, z rotations in degrees (pitch, yaw, roll). More...
 
int GetMeshID () const
 Get the ID of this mesh. More...
 
std::vector< numeric_type > GetIndexedVertices () const
 
Returns
A copy of every vertex in this array.
More...
 
std::vector< int > getRawIndices () const
 Retrieve a copy of this mesh's index buffer as a 1D array. More...
 
std::vector< std::array< numeric_type, 3 > > GetUnindexedVertices () const
 Retrieve an unindexed array of this mesh's vertices. More...
 
void SetMeshID (int new_id)
 Change the ID of this mesh. More...
 
bool operator== (const MeshInfo &M2) const
 Compare the vertices of two MeshInfo objects. More...
 
std::array< numeric_type, 3 > operator[] (int i) const
 Get vertex at a specific index in the mesh. More...
 
const array_and_size< numeric_type > GetVertexPointer () const
 Get a pointer to the vertex array of this mesh. More...
 
const array_and_size< int > GetIndexPointer () const
 Get a pointer to the index array of this mesh. More...
 

Public Attributes

int meshid
 Identifier for this mesh. More...
 
std::string name = ""
 A human-readable title. More...
 

Private Types

using VertMatrix = Eigen::Matrix3X< numeric_type >
 

Private Member Functions

void SetVert (int index, numeric_type x, numeric_type y, numeric_type z)
 Change the position of the vertex at index. More...
 
void VectorsToBuffers (const std::vector< std::array< numeric_type, 3 > > &vertices)
 Index vertices then insert them into verts and indices. More...
 

Private Attributes

VertMatrix verts
 3 by X matrix of vertices More...
 
Eigen::Matrix3X< int > indices
 3 by X matrix of indices for triangles. More...
 

Detailed Description

template<typename numeric_type = float>
class HF::Geometry::MeshInfo< numeric_type >

A collection of vertices and indices representing geometry.

Internally stored as a 3 by X matrix of vertices and a 3 by X matrix for indices. Eigen is used to manage all matricies and perform quick transformations such as RotateMesh. More details on Eigen are available here: https://eigen.tuxfamily.org/dox/group__Geometry__Module.html

Invariant
Will always hold a valid mesh with finite members.
MeshInfo

Definition at line 124 of file meshinfo.h.

Member Typedef Documentation

◆ VertMatrix

template<typename numeric_type = float>
using HF::Geometry::MeshInfo< numeric_type >::VertMatrix = Eigen::Matrix3X<numeric_type>
private

Definition at line 130 of file meshinfo.h.

Constructor & Destructor Documentation

◆ MeshInfo() [1/3]

template<typename numeric_type = float>
HF::Geometry::MeshInfo< numeric_type >::MeshInfo ( )
inline

Construct an empty instance of MeshInfo.

// be sure to #include "meshinfo.h"
HF::Geometry::MeshInfo mesh; // meshid == 0; verts is given 3 rows, 0 cols; name == "INVALID"
A collection of vertices and indices representing geometry.
Definition: meshinfo.h:124

Definition at line 177 of file meshinfo.h.

References HF::Geometry::MeshInfo< numeric_type >::meshid, HF::Geometry::MeshInfo< numeric_type >::name, and HF::Geometry::MeshInfo< numeric_type >::verts.

◆ MeshInfo() [2/3]

template<typename numeric_type = float>
HF::Geometry::MeshInfo< numeric_type >::MeshInfo ( const std::vector< std::array< numeric_type, 3 > > &  vertices,
int  id,
std::string  name = "" 
)

Construct a new MeshInfo object from an unindexed vector of vertices, an ID, and a name.

Parameters
verticesAn ordered list of vertices where every 3 vertices comprise single a triangle in the mesh.
idA unique identifier.
nameA human-readable title.
Exceptions
HF::Exceptions::InvalidOBJthe input vertices don't represent a valid mesh.
std::exceptionthe input array had one or more NAN values.
Todo:

Change the std::exception to also be an InvalidOBJ exception.

Check for a number of vertices that aren't a multiple of 3 like the other functions.

// be sure to #include "meshinfo.h", and #include <vector>
// Prepare the vertices
std::array<numeric_type, 3> vertex_0 = { 34.1, 63.9, 16.5 };
std::array<numeric_type, 3> vertex_1 = { 23.5, 85.7, 45.2 };
std::array<numeric_type, 3> vertex_2 = { 12.0, 24.6, 99.4 };
// Create an array of vertices
std::vector<std::array<numeric_type, 3>> vertices{ vertex_0, vertex_1, vertex_2 };
// This mesh contains a triangle (due to having 3 vertices), id == 3451, name ==
// "My Mesh" Note that vertices is passed by reference. Also, passing a
// std::vector<std::array<numeric_type, 3>> with (size < 1) will cause
// HF::Exceptions::InvalidOBJ to be thrown.
HF::Geometry::MeshInfo mesh(vertices, 3451, "My Mesh");
// Display the vertices for mesh
std::cout << "Vertices in mesh with ID " << mesh.GetMeshID() << ": " << std::endl;
for (auto vertex : mesh.GetVertsAsArrays()) {
std::cout << "(" << vertex[0] << ", " << vertex[1] << ", " << vertex[2] << ")" << std::endl;
}

◆ MeshInfo() [3/3]

template<typename numeric_type = float>
HF::Geometry::MeshInfo< numeric_type >::MeshInfo ( const std::vector< numeric_type > &  in_vertices,
const std::vector< int > &  in_indexes,
int  id,
std::string  name = "" 
)

Construct a new MeshInfo object from an indexed vector of vertices.

Parameters
verticesAn ordered list of numeric_types with every 3 numeric_types representing the x,y, and z coordinates for a single vertex.
indexesA vector of indices with each index matching up with a vertex in vertices.
idA unique identifier.
nameA human readable title.
Exceptions
HF::Exceptions::InvalidOBJinput indices and vertices don't represent a valid mesh.
// be sure to #include "meshinfo.h", and #include <vector>
// Prepare the vertices. Every three numeric_types represents one vertex.
std::vector<numeric_type> vertices = { 34.1, 63.9, 16.5, 23.5, 85.7, 45.2, 12.0, 24.6, 99.4 };
// 0 1 2
// If indices.size() == 3, this means that vertices.size() == 9, and each member
// of indices represents a std::array<numeric_type, 3> i.e. indices[0] represents the
// 0th set of (x, y, z) coordinates, {34.1, 63.9, 16.5} indices[1] represents
// the 1st set of (x, y, z) coordinates, {23.5, 85.7, 45.2} indices[2]
// represents the 2nd set of (x, y, z) coordinates, {12.0, 24.6, 99.4}
std::vector<int> indices = { 0, 1, 2 };
// Note that vertices and indices are passed by reference. Also, passing a
// std::vector<numeric_type> with a size that is not a multiple of 3, or passing a
// std::vector<int> with a size that is not a multiple of 3 -- will cause
// HF::Exceptions::InvalidOBJ to be thrown. Also, indices.size() ==
// (vertices.size() / 3), because all members of indices must correspond to the
// index of the first member representing the initial coordinate within a vertex.
HF::Geometry::MeshInfo mesh(vertices, indices, 5901, "This Mesh");
// Display the vertices for mesh
std::cout << "Vertices in mesh with ID " << mesh.GetMeshID() << ": " << std::endl;
for (auto vertex : mesh.GetVertsAsArrays()) {
std::cout << "(" << vertex[0] << ", " << vertex[1] << ", " << vertex[2] << ")" << std::endl;
}
Eigen::Matrix3X< int > indices
3 by X matrix of indices for triangles.
Definition: meshinfo.h:132

Member Function Documentation

◆ AddVerts()

template<typename numeric_type = float>
void HF::Geometry::MeshInfo< T >::AddVerts ( const std::vector< std::array< numeric_type, 3 > > &  verts)

Add more vertices to this mesh.

Parameters
vertsVertices to add to this mesh, with each 3 belonging to a new triangle.

Index the vertices in verts, then insert the new indices and vertices into their respective arrays.

Remarks
This function can effectively be used to "Merge" another mesh into this one.
Exceptions
HF::Exceptions::InvalidOBJin_vertices did not contain a valid set of triangles.
Todo:
Change std::exception to DHARTAPI::InvalidOBJ.
// be sure to #include "meshinfo.h", and #include <vector>
// Prepare the vertices
std::array<numeric_type, 3> vertex_0 = { 34.1, 63.9, 16.5 };
std::array<numeric_type, 3> vertex_1 = { 23.5, 85.7, 45.2 };
std::array<numeric_type, 3> vertex_2 = { 12.0, 24.6, 99.4 };
// Create a vector of vertices
std::vector<std::array<numeric_type, 3>> vertices{ vertex_0, vertex_1, vertex_2 };
// Create the MeshInfo instance - this example uses the no-arg constructor
HF::Geometry::MeshInfo mesh; // meshid == 0; verts is given 3 rows, 0 cols; name == "INVALID"
// Append the vertices to the mesh
mesh.AddVerts(vertices);
std::cout << "size: " << mesh.getRawVertices().size() << std::endl;
// Display the vertices for mesh
std::cout << "Vertices in mesh with ID " << mesh.GetMeshID() << ": " << std::endl;
for (auto vertex : mesh.GetVertsAsArrays()) {
std::cout << "(" << vertex[0] << ", " << vertex[1] << ", " << vertex[2] << ")" << std::endl;
}
void AddVerts(const std::vector< std::array< numeric_type, 3 > > &verts)
Add more vertices to this mesh.
Definition: meshinfo.cpp:162
int GetMeshID() const
Get the ID of this mesh.
Definition: meshinfo.cpp:241

Definition at line 162 of file meshinfo.cpp.

◆ ConvertToOBJCoordinates()

template<typename T >
void HF::Geometry::MeshInfo< T >::ConvertToOBJCoordinates

Convert a mesh from Z-Up to Y-Up.

Todo:

Rename this to ConvertToYup.

Just use the RotateMesh function.

See also
ConvertToRhinoCoordinates for the inverse operation.
// be sure to #include "meshinfo.h", and #include <vector>
// Prepare the vertices
std::array<numeric_type, 3> vertex_0 = { 34.1, 63.9, 16.5 };
std::array<numeric_type, 3> vertex_1 = { 23.5, 85.7, 45.2 };
std::array<numeric_type, 3> vertex_2 = { 12.0, 24.6, 99.4 };
// Create an array of vertices
std::vector<std::array<numeric_type, 3>> vertices{ vertex_0, vertex_1, vertex_2 };
// Create the MeshInfo
HF::Geometry::MeshInfo mesh(vertices, 3451, "My Mesh");
// Convert the coordinates
mesh.ConvertToOBJCoordinates();
// Note: Program will abort if any coordinate is NaN
// Display the vertices for mesh
std::cout << "Vertices in mesh with ID " << mesh.GetMeshID() << ": " << std::endl;
for (auto vertex : mesh.GetVertsAsArrays()) {
std::cout << "(" << vertex[0] << ", " << vertex[1] << ", " << vertex[2] << ")" << std::endl;
}

Definition at line 196 of file meshinfo.cpp.

◆ ConvertToRhinoCoordinates()

template<typename T >
void HF::Geometry::MeshInfo< T >::ConvertToRhinoCoordinates

Convert a mesh from Y-Up to Z-Up.

Todo:

Rename this to ConvertToZUp.

Just use the RotateMesh function.

Change exception to an assertion since it shouldn't happen in production code.

See also
ConvertToOBJCoordinates for the inverse operation.
// be sure to #include "meshinfo.h", and #include <vector>
// Prepare the vertices
std::array<numeric_type, 3> vertex_0 = { 34.1, 63.9, 16.5 };
std::array<numeric_type, 3> vertex_1 = { 23.5, 85.7, 45.2 };
std::array<numeric_type, 3> vertex_2 = { 12.0, 24.6, 99.4 };
// Create an array of vertices
std::vector<std::array<numeric_type, 3>> vertices{ vertex_0, vertex_1, vertex_2 };
// Create the MeshInfo
HF::Geometry::MeshInfo mesh(vertices, 3451, "My Mesh");
// Convert the coordinates
mesh.ConvertToRhinoCoordinates();
// Note: If vertices contain NaN or +/- infinity values, std::exception is thrown
// Display the vertices for mesh
std::cout << "Vertices in mesh with ID " << mesh.GetMeshID() << ": " << std::endl;
for (auto vertex : mesh.GetVertsAsArrays()) {
std::cout << "(" << vertex[0] << ", " << vertex[1] << ", " << vertex[2] << ")" << std::endl;
}

Definition at line 184 of file meshinfo.cpp.

◆ GetIndexedVertices()

template<typename T >
vector< T > HF::Geometry::MeshInfo< T >::GetIndexedVertices

Returns
A copy of every vertex in this array.

Copy this mesh's vertices as a 1D array.

The vertices are copied directly from this mesh's underlying eigen matrix. The index of each vertex matches the index used for this mesh's index array. For Example the first element is the vertex at index 0, the second is the vertex for index 1, etc.

Todo:
Make a version of this function that just returns a const reference or pointer to the data. There's not much reason to do a copy here.
// be sure to #include "meshinfo.h", and #include <vector>
// Prepare the vertices. Every three numeric_types represents one vertex.
std::vector<numeric_type> vertices = { 34.1, 63.9, 16.5, 23.5, 85.7, 45.2, 12.0, 24.6, 99.4 };
// 0 1 2
// If indices.size() == 3, this means that vertices.size() == 9, and each member
// of indices represents a std::array<numeric_type, 3> i.e. indices[0] represents the
// 0th set of (x, y, z) coordinates, {34.1, 63.9, 16.5} indices[1] represents
// the 1st set of (x, y, z) coordinates, {23.5, 85.7, 45.2} indices[2]
// represents the 2nd set of (x, y, z) coordinates, {12.0, 24.6, 99.4}
std::vector<int> indices = { 0, 1, 2 };
// Create the mesh.
HF::Geometry::MeshInfo mesh(vertices, indices, 5901, "This Mesh");
// Retrieve copies of mesh's vertices.
std::vector<numeric_type> vertices_copy_0 = mesh.getRawVertices();
std::vector<numeric_type> vertices_copy_1 = mesh.getRawVertices();
// Uses std::vector<numeric_type>'s operator== to determine member equality
if (vertices_copy_0 == vertices_copy_1) {
std::cout << "vertices_copy_0 and vertices_copy_1 share the same elements/permutation." << std::endl;
}
// This will demonstrate that vertices_copy_0 and vertices_copy_1 are different
// container instances
// Output: vertices_copy_0 and vertices_copy_1 share the same elements/permutation.
// vertices_copy_0 and vertices_copy_1 are different container instances.
if (&vertices_copy_0 != &vertices_copy_1) {
std::cout << "vertices_copy_0 and vertices_copy_1 are different container instances." << std::endl;
}
// Output all coordinates
const int total = mesh.NumTris() * 3;
int offset = 0;
for (int i = 0; i < total; i++) {
auto y_offset = static_cast<int64_t>(offset) + 1;
auto z_offset = static_cast<int64_t>(offset) + 2;
std::cout << "(" << vertices_copy_0[offset] << ", "
<< vertices_copy_0[y_offset] << ", "
<< vertices_copy_0[z_offset] << ")" << std::endl;
offset += 3;
}

Definition at line 244 of file meshinfo.cpp.

Referenced by HF::RayTracer::EmbreeRayTracer::AddMesh().

+ Here is the caller graph for this function:

◆ GetIndexPointer()

template<typename T >
const array_and_size< int > HF::Geometry::MeshInfo< T >::GetIndexPointer

Get a pointer to the index array of this mesh.

Returns
A pointer to the index array of this mesh, and the number of elements it contains

Definition at line 326 of file meshinfo.cpp.

References HF::Geometry::array_and_size< ptr_type >::data, and HF::Geometry::array_and_size< ptr_type >::size.

Referenced by HF::RayTracer::NanoRTRayTracer::NanoRTRayTracer(), and GetVertsAndTris().

+ Here is the caller graph for this function:

◆ GetMeshID()

template<typename T >
int HF::Geometry::MeshInfo< T >::GetMeshID

Get the ID of this mesh.

Returns
The member field meshid, by value.
// be sure to #include "meshinfo.h", and #include <vector>
// Prepare the vertices
std::array<numeric_type, 3> vertex_0 = { 34.1, 63.9, 16.5 };
std::array<numeric_type, 3> vertex_1 = { 23.5, 85.7, 45.2 };
std::array<numeric_type, 3> vertex_2 = { 12.0, 24.6, 99.4 };
// Create an array of vertices
std::vector<std::array<numeric_type, 3>> vertices(vertex_0, vertex_1, vertex_2);
// Create the MeshInfo
HF::Geometry::MeshInfo mesh(vertices, 3451, "My Mesh");
// Use GetMeshID to do an ID match
int mesh_id = -1;
if ((mesh_id = mesh.GetMeshID()) == 3451) {
std::cout << "Retrieved 'My Mesh'" << std::endl;
}

Definition at line 241 of file meshinfo.cpp.

◆ getRawIndices()

template<typename T >
vector< int > HF::Geometry::MeshInfo< T >::getRawIndices

Retrieve a copy of this mesh's index buffer as a 1D array.

Returns
A copy of this mesh's index buffer containing every index in this mesh.
Todo:
Version of this function that just returns a const reference to the data. There's not much reason to do a copy here.
// be sure to #include "meshinfo.h", and #include <vector>
// Prepare the vertices. Every three numeric_types represents one vertex.
std::vector<numeric_type> vertices = { 34.1, 63.9, 16.5, 23.5, 85.7, 45.2, 12.0, 24.6, 99.4 };
// 0 1 2
// If indices.size() == 3, this means that vertices.size() == 9, and each member
// of indices represents a std::array<numeric_type, 3> i.e. indices[0] represents the
// 0th set of (x, y, z) coordinates, {34.1, 63.9, 16.5} indices[1] represents
// the 1st set of (x, y, z) coordinates, {23.5, 85.7, 45.2} indices[2]
// represents the 2nd set of (x, y, z) coordinates, {12.0, 24.6, 99.4}
std::vector<int> indices = { 0, 1, 2 };
// Create the mesh.
HF::Geometry::MeshInfo mesh(vertices, indices, 5901, "This Mesh");
// Retrieve a copy of mesh's index vector
std::vector<int> indices_copy_0 = mesh.getRawIndices();
std::vector<int> indices_copy_1 = mesh.getRawIndices();
// Uses std::vector<int>'s operator== to determine member equality
if (indices_copy_0 == indices_copy_1) {
std::cout << "indices_copy_0 and indices_copy_1 share the same elements/permutation." << std::endl;
}
// This will demonstrate that indices_copy_0 and indices_copy_1 are different
// container instances
// Output: indices_copy_0 and indices_copy_1 share the same elements/permutation.
// indices_copy_0 and indices_copy_1 are different container instances.
if (&indices_copy_0 != &indices_copy_1) {
std::cout << "indices_copy_0 and indices_copy_1 are different container instances." << std::endl;
}
// Output the indices
for (auto i : indices_copy_0) {
std::cout << i << std::endl;
}

Definition at line 256 of file meshinfo.cpp.

Referenced by HF::RayTracer::EmbreeRayTracer::AddMesh().

+ Here is the caller graph for this function:

◆ GetUnindexedVertices()

template<typename T >
vector< std::array< T, 3 > > HF::Geometry::MeshInfo< T >::GetUnindexedVertices

Retrieve an unindexed array of this mesh's vertices.

Returns
An array of vertices to match this mesh's array of indices.

For every index in this mesh's indices array, copy the matching vertex into the return array. This will result in vertexes being repeated multiple times. For example, the first element is the vertex pointed to by the first index in indices, the second element is the vertex pointed to by the second index in indices etc.

Remarks
The output of this function should match the input for MeshInfo() to create this mesh. This function is not really useful outside of testing, since it's essentially uncompressing the mesh and repeating a lot of data.
See also
getRawVertices() for a more efficent way of reading this mesh's vertices.
getRawIndices() for an ordered list of indices for each vertex in the return array.
// be sure to #include "meshinfo.h", and #include <vector>
// Prepare the vertices. Every three numeric_types represents one vertex.
std::vector<numeric_type> vertices = { 34.1, 63.9, 16.5, 23.5, 85.7, 45.2, 12.0, 24.6, 99.4 };
// 0 1 2
// If indices.size() == 3, this means that vertices.size() == 9, and each member
// of indices represents a std::array<numeric_type, 3> i.e. indices[0] represents the
// 0th set of (x, y, z) coordinates, {34.1, 63.9, 16.5} indices[1] represents
// the 1st set of (x, y, z) coordinates, {23.5, 85.7, 45.2} indices[2]
// represents the 2nd set of (x, y, z) coordinates, {12.0, 24.6, 99.4}
std::vector<int> indices = { 0, 1, 2 };
// Create the mesh.
HF::Geometry::MeshInfo mesh(vertices, indices, 5901, "This Mesh");
// Retrieve vertices as a vector of coordinates (x, y, z) Useful if your
// vertices were prepared from a one-dimensional container c, of numeric_type (such
// that c.size() % 3 == 0)
std::vector<std::array<numeric_type, 3>> vert_container = mesh.GetVertsAsArrays();

Definition at line 264 of file meshinfo.cpp.

◆ GetVertexPointer()

template<typename T >
const array_and_size< T > HF::Geometry::MeshInfo< T >::GetVertexPointer

Get a pointer to the vertex array of this mesh.

Returns
A pointer to the vertex array of this mesh, and the number of elements it contains

Definition at line 336 of file meshinfo.cpp.

References HF::Geometry::array_and_size< ptr_type >::data, and HF::Geometry::array_and_size< ptr_type >::size.

Referenced by HF::RayTracer::NanoRTRayTracer::NanoRTRayTracer(), and GetVertsAndTris().

+ Here is the caller graph for this function:

◆ NumTris()

template<typename T >
int HF::Geometry::MeshInfo< T >::NumTris

Calculate the total number of triangles in this mesh.

Returns
The number of triangles in this mesh.

The number of triangles in the mesh is equal to the number of columns in the indices matrix.

Remarks
Used to equal num_verts/3, but now that does not since indexed buffers are used.
// be sure to #include "meshinfo.h", and #include <vector>
// Prepare the vertices
std::array<numeric_type, 3> vertex_0 = { 34.1, 63.9, 16.5 };
std::array<numeric_type, 3> vertex_1 = { 23.5, 85.7, 45.2 };
std::array<numeric_type, 3> vertex_2 = { 12.0, 24.6, 99.4 };
// Create an array of vertices
std::vector<std::array<numeric_type, 3>> vertices(vertex_0, vertex_1, vertex_2);
// Create the MeshInfo
HF::Geometry::MeshInfo mesh(vertices, 3451, "My Mesh");
int tri_count = 0;
if ((tri_count = mesh.NumTris()) == 0) {
std::cout << "This mesh has no triangles." << std::endl;
} else {
std::cout << "Triangle count: " << tri_count << std::endl;
}
// Output is: 'Triangle count: 1' Note that (mesh.NumVerts() / 3 &&
// mesh.NumTris()) will always be true, since three vertices compose a single triangle.

Definition at line 181 of file meshinfo.cpp.

Referenced by HF::RayTracer::EmbreeRayTracer::AddMesh().

+ Here is the caller graph for this function:

◆ NumVerts()

template<typename T >
int HF::Geometry::MeshInfo< T >::NumVerts

Determine how many vertices are in this mesh.

Returns
Total number of vertices for this mesh.

The number of vertices in the mesh is equal to the number of columns in the verts matrix.

Remarks
Useful for testing correctness.
// be sure to #include "meshinfo.h", and #include <vector>
// Prepare the vertices
std::array<numeric_type, 3> vertex_0 = { 34.1, 63.9, 16.5 };
std::array<numeric_type, 3> vertex_1 = { 23.5, 85.7, 45.2 };
std::array<numeric_type, 3> vertex_2 = { 12.0, 24.6, 99.4 };
// Create an array of vertices
std::vector<std::array<numeric_type, 3>> vertices{ vertex_0, vertex_1, vertex_2 };
// Create the MeshInfo
HF::Geometry::MeshInfo mesh(vertices, 3451, "My Mesh");
int vert_count = 0;
if ((vert_count = mesh.NumVerts()) == 0) {
std::cout << "This mesh has no vertices." << std::endl;
} else {
std::cout << "Vertex count: " << vert_count << std::endl;
}
// Output is: 'Vertex count: 3'

Definition at line 178 of file meshinfo.cpp.

Referenced by HF::RayTracer::EmbreeRayTracer::AddMesh(), and HF::Geometry::MeshInfo< numeric_type >::operator==().

+ Here is the caller graph for this function:

◆ operator==()

template<typename T >
bool HF::Geometry::MeshInfo< T >::operator== ( const MeshInfo< numeric_type > &  M2) const

Compare the vertices of two MeshInfo objects.

Parameters
M2The desired MeshInfo to compare.
Returns
True if all vertices are equal within a certain tolerance, false otherwise.

First check that the size of both mesh's vertex arrays are the same size, then compare the distance between every vertex one by one.

Warning
This does not compare indices at all and will return false if both meshes contain the same vertices but in a different order.
// be sure to #include "meshinfo.h", and #include <vector>
// Prepare the vertices. Every three numeric_types represents one vertex.
std::vector<numeric_type> vertices_0 = { 11.0, 22.0, 33.0, 44.0, 55.0, 66.0, 77.0, 88.0, 99.0 };
// 0 1 2
std::vector<numeric_type> vertices_1 = { 11.0, 22.0, 33.0, 44.0, 55.0, 66.0, 77.0, 88.0, 99.0 };
// 0 1 2
// If indices_0.size() == 3, this means that vertices_0.size() == 9, and each
// member of indices represents a std::array<numeric_type, 3> i.e. indices[0]
// represents the 0th set of (x, y, z) coordinates, {34.1, 63.9, 16.5}
// indices[1] represents the 1st set of (x, y, z) coordinates, {23.5, 85.7,
// 45.2} indices[2] represents the 2nd set of (x, y, z) coordinates, {12.0,
// 24.6, 99.4}
//
// The same is true for vertices_1 and indices_1.
std::vector<int> indices_0 = { 0, 1, 2 };
std::vector<int> indices_1 = { 0, 1, 2 };
HF::Geometry::MeshInfo mesh_0(vertices_0, indices_0, 5901, "This Mesh");
HF::Geometry::MeshInfo mesh_1(vertices_1, indices_0, 4790, "That Mesh");
bool equivalent = mesh_0 == mesh_1; // returns true
// operator== will determine if two MeshInfo are equal if the Euclidean distance
// between each matching element in mesh_0 and mesh_1 is within 0.001. This
// means that for all i between vertices_0 and vertices_1 -- each x, y, z within
// vertices_0[i] and vertices_1[i] must be within 0.001 to be considered equivalent.
// Of course, this also means that if mesh_0.NumVerts() != mesh_1.NumVerts(),
// mesh_0 and mesh_1 are not equivalent at all.

Definition at line 310 of file meshinfo.cpp.

References HF::Geometry::arrayDist(), and HF::Geometry::MeshInfo< numeric_type >::NumVerts().

+ Here is the call graph for this function:

◆ operator[]()

template<typename T >
array< T, 3 > HF::Geometry::MeshInfo< T >::operator[] ( int  i) const

Get vertex at a specific index in the mesh.

Parameters
iIndex of the vertex to retrieve.
Returns
The x, y, and z coordinates for the vertex at index i.
Exceptions
std::exceptioni is out of the bounds of the vertex array.
// be sure to #include "meshinfo.h", and #include <vector>
// Prepare the vertices. Every three numeric_types represents one vertex.
std::vector<numeric_type> vertices = { 34.1, 63.9, 16.5, 23.5, 85.7, 45.2, 12.0, 24.6, 99.4 };
// 0 1 2
// If indices.size() == 3, this means that vertices.size() == 9, and each member
// of indices represents a std::array<numeric_type, 3> i.e. indices[0] represents the
// 0th set of (x, y, z) coordinates, {34.1, 63.9, 16.5} indices[1] represents
// the 1st set of (x, y, z) coordinates, {23.5, 85.7, 45.2} indices[2]
// represents the 2nd set of (x, y, z) coordinates, {12.0, 24.6, 99.4}
std::vector<int> indices = { 0, 1, 2 };
// Create the mesh
HF::Geometry::MeshInfo mesh(vertices, indices, 5901, "This Mesh");
// Retrieve the desired vertex
int index = 1;
// vertex consists of { 44.0, 55.0, 66.0 }, which is the second triplet of
// coordinates within vertices_0.
auto vertex = mesh[index];
std::cout << "Retrieved at index << " << index << ": (" << vertex[0] << ", "
<< vertex[1] << ", "
<< vertex[2] << ")" << std::endl;

Definition at line 285 of file meshinfo.cpp.

◆ PerformRotation()

template<typename numeric_type = float>
void HF::Geometry::MeshInfo< T >::PerformRotation ( numeric_type  rx,
numeric_type  ry,
numeric_type  rz 
)

Rotate this mesh by x, y, z rotations in degrees (pitch, yaw, roll).

Parameters
rxPitch to rotate by in degrees.
ryYaw to rotate by in degrees.
rzRoll to rotate by in degrees.

[snippet_objloader_assert]

[snippet_objloader_assert]

Definition at line 209 of file meshinfo.cpp.

Referenced by RotateMesh().

+ Here is the caller graph for this function:

◆ SetMeshID()

template<typename T >
void HF::Geometry::MeshInfo< T >::SetMeshID ( int  new_id)

Change the ID of this mesh.

Parameters
new_idNew ID to assign to this mesh.
// be sure to #include "meshinfo.h", and #include <vector>
// Prepare the vertices. Every three numeric_types represents one vertex.
std::vector<numeric_type> vertices = { 34.1, 63.9, 16.5, 23.5, 85.7, 45.2, 12.0, 24.6, 99.4 };
// 0 1 2
// If indices.size() == 3, this means that vertices.size() == 9, and each member
// of indices represents a std::array<numeric_type, 3> i.e. indices[0] represents the
// 0th set of (x, y, z) coordinates, {34.1, 63.9, 16.5} indices[1] represents
// the 1st set of (x, y, z) coordinates, {23.5, 85.7, 45.2} indices[2]
// represents the 2nd set of (x, y, z) coordinates, {12.0, 24.6, 99.4}
std::vector<int> indices = { 0, 1, 2 };
// Create the mesh.
HF::Geometry::MeshInfo mesh(vertices, indices, 5901, "This Mesh");
// Prepare a new mesh ID.
int new_mesh_id = 9999;
// Assign new_mesh_id to mesh.
mesh.SetMeshID(new_mesh_id);
// Test for value equality. Will return true.
if (new_mesh_id == mesh.GetMeshID()) {
std::cout << "ID assignment successful." << std::endl;
}

Definition at line 282 of file meshinfo.cpp.

◆ SetVert()

template<typename numeric_type = float>
void HF::Geometry::MeshInfo< T >::SetVert ( int  index,
numeric_type  x,
numeric_type  y,
numeric_type  z 
)
inlineprivate

Change the position of the vertex at index.

Parameters
indexIndex of the vertex to change,
xX coordinate
yY coordinate
zZ coordinate
// TODO: this is a private member function of MeshInfo, but it is not used by any other member function within MeshInfo

Definition at line 40 of file meshinfo.cpp.

◆ VectorsToBuffers()

template<typename numeric_type = float>
void HF::Geometry::MeshInfo< T >::VectorsToBuffers ( const std::vector< std::array< numeric_type, 3 > > &  vertices)
private

Index vertices then insert them into verts and indices.

Parameters
verticesAn ordered list of vertices; every 3 vertices form a triangle in the mesh.

Calls IndexRawVertices to index the input vertices then fill verts and indices.

Postcondition
This class's verts and indices are filled with the indexed vertices from vertices.
Exceptions
HF::Exceptions::InvalidOBJvertices did not contain the vertices of a valid mesh.
// TODO: this is a private member function of MeshInfo, but it is not used by any other member function with MeshInfo.

Definition at line 122 of file meshinfo.cpp.

References HF::Geometry::IndexRawVertices().

+ Here is the call graph for this function:

Member Data Documentation

◆ indices

template<typename numeric_type = float>
Eigen::Matrix3X<int> HF::Geometry::MeshInfo< numeric_type >::indices
private

3 by X matrix of indices for triangles.

Definition at line 132 of file meshinfo.h.

◆ meshid

template<typename numeric_type = float>
int HF::Geometry::MeshInfo< numeric_type >::meshid

◆ name

template<typename numeric_type = float>
std::string HF::Geometry::MeshInfo< numeric_type >::name = ""

A human-readable title.

Definition at line 127 of file meshinfo.h.

Referenced by HF::Geometry::MeshInfo< numeric_type >::MeshInfo(), and GetMeshName().

◆ verts

template<typename numeric_type = float>
VertMatrix HF::Geometry::MeshInfo< numeric_type >::verts
private

3 by X matrix of vertices

Definition at line 131 of file meshinfo.h.

Referenced by HF::Geometry::MeshInfo< numeric_type >::MeshInfo().


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