16 #ifndef SURGSIM_DATASTRUCTURES_UNITTESTS_MOCKOBJECTS_H 17 #define SURGSIM_DATASTRUCTURES_UNITTESTS_MOCKOBJECTS_H 22 #include "SurgSim/DataStructures/Grid.h" 23 #include "SurgSim/DataStructures/TetrahedronMesh.h" 24 #include "SurgSim/DataStructures/TriangleMesh.h" 25 #include "SurgSim/DataStructures/Vertices.h" 36 explicit ElementTest(
int i) : m_number(i) { std::stringstream s; s << i; m_string = s.str(); }
42 return m_number == e.m_number && m_string.compare(e.m_string) == 0;
61 return (hash<string>()(k.m_string) ^ (hash<int>()(k.m_number) << 1));
82 m_buffer(height*depth*width)
86 T
get(
int i,
int j,
int k)
88 return m_buffer[getIndex(i,j,k)];
91 void set(
int i,
int j,
int k, T value)
93 m_buffer[getIndex(i,j,k)] = value;
97 int getIndex(
int i,
int j,
int k)
99 return i + j*m_width + k*m_width*m_height;
105 std::vector<T> m_buffer;
148 return m_id == data.m_id && (m_normal - data.m_normal).norm() < 1.0e-10;
189 return m_id == data.m_id;
236 return m_id == data.m_id && m_edges == data.m_edges;
242 std::array<size_t, 3> m_edges = {};
254 const std::array<size_t, 6>& edges,
255 const std::array<size_t, 4>& triangles) :
256 m_id(id), m_edges(edges), m_triangles(triangles)
288 return m_id == data.m_id && m_edges == data.m_edges && m_triangles == data.m_triangles;
296 std::array<size_t, 6> m_edges;
299 std::array<size_t, 4> m_triangles;
325 VertexType vertex(position,
MockVertexData(getNumVertices(), normal));
327 return addVertex(vertex);
333 return getVertex(
id).data.getNormal();
344 bool doUpdate()
override 356 MockTriangleData, MockTetrahedronData>
391 return addVertex(vertex);
401 return addEdge(edge);
408 size_t createTriangle(
const std::array<size_t, 3>& vertices,
const std::array<size_t, 3>& edges)
412 return addTriangle(triangle);
421 const std::array<size_t, 6>& edges,
422 const std::array<size_t, 4>& triangles)
426 return addTetrahedron(tetrahedron);
432 return getVertex(
id).data.getNormal();
443 bool doUpdate()
override 453 template <
typename T,
size_t N>
461 MockGrid(
const Eigen::Matrix<double, N, 1>& cellSize,
const Eigen::AlignedBox<double, N>& bounds) :
465 std::unordered_map<NDId, CellContent, NDIdHash>& getActiveCells() {
return this->m_activeCells; }
467 std::unordered_map<T, NDId>& getCellIds() {
return this->m_cellIds; }
469 std::vector<T>& getNonConstNeighbors(
const T& element)
471 return const_cast<std::vector<T>&
>(this->getNeighbors(element));
474 Eigen::Matrix<double, N, 1> getSize()
const {
return this->m_size; }
476 Eigen::AlignedBox<double, N> getAABB()
const {
return this->m_aabb; }
481 template <
typename IteratorType>
485 formatIterator(IteratorType begin, IteratorType end,
const std::string& separator)
486 : m_begin(begin), m_end(end), m_separator(separator)
492 if (formatIterator.m_begin == formatIterator.m_end)
497 IteratorType start = formatIterator.m_begin;
498 IteratorType penultimate = formatIterator.m_end - 1;
499 while (start != penultimate)
501 stream << *start++ << formatIterator.m_separator;
509 IteratorType m_begin;
511 const std::string& m_separator;
515 template <
typename IterableType>
517 const std::string& separator)
520 iterable.cbegin(), iterable.cend(), separator);
523 template <
typename IteratorType>
526 const std::string& separator)
531 #endif // SURGSIM_DATASTRUCTURES_UNITTESTS_MOCKOBJECTS_H bool operator==(const MockTriangleData &data) const
Compare the triangle data to another one (equality)
Definition: MockObjects.h:234
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Definition: MockObjects.h:67
int getNumUpdates() const
Returns the number of updates performed on the mesh.
Definition: MockObjects.h:436
MockTriangleData(size_t id, const std::array< size_t, 3 > &edges)
Constructor.
Definition: MockObjects.h:203
bool operator==(const MockVertexData &data) const
Compare the vertex data to another one (equality)
Definition: MockObjects.h:146
MeshElement< 4, MockTetrahedronData > TetrahedronType
Tetrahedron type for convenience (Ids of the 4 vertices)
Definition: TetrahedronMesh.h:68
size_t createVertex(const SurgSim::Math::Vector3d &position, const SurgSim::Math::Vector3d &normal)
Create a new vertex in the mesh.
Definition: MockObjects.h:323
Definition: MockObjects.h:479
Basic class for storing Tetrahedron Meshes, handling basic vertex, edge, triangle and tetrahedron fun...
Definition: TetrahedronMesh.h:60
MockVertexData(size_t id, const SurgSim::Math::Vector3d &normal)
Constructor.
Definition: MockObjects.h:115
TetrahedronMesh< MockVertexData, MockEdgeData, MockTriangleData, MockTetrahedronData >::VertexType VertexType
Vertex type for convenience.
Definition: MockObjects.h:361
MockVertexData()
Constructor.
Definition: MockObjects.h:122
Mesh for testing using MockVertexData.
Definition: MockObjects.h:303
Definition: MockObjects.h:47
const SurgSim::Math::Vector3d & getVertexNormal(size_t id) const
Returns the normal of a vertex.
Definition: MockObjects.h:430
MockTriangleData()
Constructor.
Definition: MockObjects.h:210
const SurgSim::Math::Vector3d & getNormal() const
Gets the vertex surface normal.
Definition: MockObjects.h:138
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
virtual ~MockTetrahedronMesh()
Destructor.
Definition: MockObjects.h:379
const SurgSim::Math::Vector3d & getVertexNormal(size_t id) const
Returns the normal of a vertex.
Definition: MockObjects.h:331
Definition: MockObjects.h:28
size_t createEdge(const std::array< size_t, 2 > &vertices)
Create a new edge in the mesh.
Definition: MockObjects.h:397
Vertex data for testing, storing ID and surface normal.
Definition: MockObjects.h:109
MockTetrahedronMesh()
Constructor. Start out with no vertices and 0 updates.
Definition: MockObjects.h:373
const std::array< size_t, 4 > & getTriangles() const
Gets the IDs of the tetrahedron's triangles in its mesh.
Definition: MockObjects.h:278
Data structure for a cell's content (the list of elements and the list of all the neighbors) ...
Definition: Grid.h:81
const std::array< size_t, 6 > & getEdges() const
Gets the IDs of the tetrahedron's edges in its mesh.
Definition: MockObjects.h:272
const std::array< size_t, 3 > & getEdges() const
Gets the IDs of the triangle's edges in its mesh.
Definition: MockObjects.h:226
Tetrahedron data for testing, storing ID and edge IDs, triangle IDs.
Definition: MockObjects.h:246
Tetrahedron Mesh for testing using MockVertexData, MockEdgeData, MockTriangleData and MockTetrahedron...
Definition: MockObjects.h:355
size_t createTriangle(const std::array< size_t, 3 > &vertices, const std::array< size_t, 3 > &edges)
Create a new triangle in the mesh.
Definition: MockObjects.h:408
MockMesh()
Constructor. Start out with no vertices and 0 updates.
Definition: MockObjects.h:310
size_t createVertex(const SurgSim::Math::Vector3d &position, const SurgSim::Math::Vector3d &normal)
Create a new vertex in the mesh.
Definition: MockObjects.h:387
virtual ~MockMesh()
Destructor.
Definition: MockObjects.h:315
MockEdgeData()
Constructor.
Definition: MockObjects.h:169
size_t getId() const
Gets the triangle's unique ID in its mesh.
Definition: MockObjects.h:220
MeshElement< 2, MockEdgeData > EdgeType
Edge type for convenience (Ids of the 2 vertices)
Definition: TetrahedronMesh.h:64
size_t getId() const
Gets the tetrahedron's unique ID in its mesh.
Definition: MockObjects.h:266
Enable the NDId to be used as a key in an unordered map.
Definition: Grid.h:91
TetrahedronMesh< MockVertexData, MockEdgeData, MockTriangleData, MockTetrahedronData >::EdgeType EdgeType
Edge type for convenience.
Definition: MockObjects.h:364
Edge data for testing, storing ID.
Definition: MockObjects.h:158
virtual ~MockEdgeData()
Destructor.
Definition: MockObjects.h:174
bool operator==(const MockEdgeData &data) const
Compare the edge data to another one (equality)
Definition: MockObjects.h:187
TetrahedronMesh< MockVertexData, MockEdgeData, MockTriangleData, MockTetrahedronData >::TriangleType TriangleType
Triangle type for convenience.
Definition: MockObjects.h:367
Definitions of small fixed-size vector types.
virtual ~MockVertexData()
Destructor.
Definition: MockObjects.h:127
virtual ~MockTriangleData()
Destructor.
Definition: MockObjects.h:215
size_t getId() const
Gets the edge's unique ID in its mesh.
Definition: MockObjects.h:179
Vertices< MockVertexData >::VertexType VertexType
Vertex type for convenience.
Definition: MockObjects.h:307
size_t getId() const
Gets the vertex's unique ID in its mesh.
Definition: MockObjects.h:132
Definition: MockObjects.h:454
Vertex< MockVertexData > VertexType
Vertex type for convenience.
Definition: Vertices.h:55
n-dimensional grid structure with uniform non-cubic cells This data structure is useful to search for...
Definition: Grid.h:47
int getNumUpdates() const
Returns the number of updates performed on the mesh.
Definition: MockObjects.h:337
Eigen::Matrix< int, N, 1 > NDId
The type of the n-dimensional cell Id.
Definition: Grid.h:88
MeshElement< 3, MockTriangleData > TriangleType
Triangle type for convenience (Ids of the 3 vertices)
Definition: TetrahedronMesh.h:66
TetrahedronMesh< MockVertexData, MockEdgeData, MockTriangleData, MockTetrahedronData >::TetrahedronType TetrahedronType
Tetrahedron type for convenience.
Definition: MockObjects.h:370
bool operator==(const MockTetrahedronData &data) const
Compare the tetrahedron data (equality)
Definition: MockObjects.h:286
virtual ~MockTetrahedronData()
Destructor.
Definition: MockObjects.h:261
Triangle data for testing, storing ID and edge IDs.
Definition: MockObjects.h:197
MockEdgeData(size_t id)
Constructor.
Definition: MockObjects.h:163
Base class for mesh structures, handling basic vertex functionality.
Definition: Vertices.h:51
MockTetrahedronData(size_t id, const std::array< size_t, 6 > &edges, const std::array< size_t, 4 > &triangles)
Constructor.
Definition: MockObjects.h:253
size_t createTetrahedron(const std::array< size_t, 4 > &vertices, const std::array< size_t, 6 > &edges, const std::array< size_t, 4 > &triangles)
Create a new tetrahedron in the mesh.
Definition: MockObjects.h:420