Mesh.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_GRAPHICS_MESH_H
17 #define SURGSIM_GRAPHICS_MESH_H
18 
19 #include <vector>
20 
24 #include "SurgSim/Math/Vector.h"
25 
26 namespace SurgSim
27 {
28 
29 namespace Graphics
30 {
31 
32 struct VertexData
33 {
36 
41  {
42  return texture == rhs.texture &&
43  color == rhs.color;
44  }
45 
50  {
51  return !((*this) == rhs);
52  }
53 };
54 
55 SURGSIM_STATIC_REGISTRATION(Mesh);
56 
57 class Mesh : public SurgSim::DataStructures::TriangleMesh<VertexData, SurgSim::DataStructures::EmptyData,
58  SurgSim::DataStructures::EmptyData>
59 {
60 public:
62  Mesh();
63 
64  typedef TriangleMesh<VertexData, DataStructures::EmptyData, DataStructures::EmptyData> BaseType;
65 
72  template <class V, class E, class T>
73  explicit Mesh(const TriangleMesh<V, E, T>& other);
74 
77  Mesh(const Mesh& other);
78 
81  Mesh(Mesh&& other);
82 
85  Mesh& operator=(const Mesh& other);
86 
89  Mesh& operator=(Mesh&& other);
90 
99  void initialize(const std::vector<SurgSim::Math::Vector3d>& vertices,
100  const std::vector<SurgSim::Math::Vector4d>& colors,
101  const std::vector<SurgSim::Math::Vector2d>& textures,
102  const std::vector<size_t>& triangles);
103 
106  void dirty();
107 
109  size_t getUpdateCount() const;
110 
111 
112 protected:
113  bool doLoad(const std::string& fileName) override;
114 
117 };
118 
119 
120 }; // Graphics
121 }; // SurgSim
122 
124 
125 #endif // SURGSIM_GRAPHICS_MESH_H
SurgSim::DataStructures::TriangleMesh
Basic class for storing Triangle Meshes, handling basic vertex, edge, and triangle functionality.
Definition: TriangleMesh.h:62
Mesh-inl.h
SurgSim::Graphics::VertexData::color
SurgSim::DataStructures::OptionalValue< SurgSim::Math::Vector4d > color
Definition: Mesh.h:35
Vector.h
SurgSim::DataStructures::OptionalValue< SurgSim::Math::Vector2d >
SurgSim::Graphics::VertexData::operator==
bool operator==(const SurgSim::Graphics::VertexData &rhs) const
Equality operator.
Definition: Mesh.h:40
SurgSim::Graphics::Mesh::m_updateCount
size_t m_updateCount
For checking whether the mesh has changed.
Definition: Mesh.h:116
EmptyData.h
OptionalValue.h
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::VertexData::operator!=
bool operator!=(const SurgSim::Graphics::VertexData &rhs) const
Inequality operator.
Definition: Mesh.h:49
SurgSim::Graphics::Mesh::BaseType
TriangleMesh< VertexData, DataStructures::EmptyData, DataStructures::EmptyData > BaseType
Definition: Mesh.h:64
SurgSim::Graphics::Mesh
Definition: Mesh.h:57
SurgSim::Graphics::Mesh::getUpdateCount
size_t getUpdateCount() const
Return the update count, please note that it will silently roll over when the range of size_t has bee...
Definition: Mesh.cpp:134
TriangleMesh.h
SurgSim::Graphics::Mesh::initialize
void initialize(const std::vector< SurgSim::Math::Vector3d > &vertices, const std::vector< SurgSim::Math::Vector4d > &colors, const std::vector< SurgSim::Math::Vector2d > &textures, const std::vector< size_t > &triangles)
Utility function to initialize a mesh with plain data,.
Definition: Mesh.cpp:51
SurgSim::Graphics::VertexData
Definition: Mesh.h:32
SurgSim::Graphics::VertexData::texture
SurgSim::DataStructures::OptionalValue< SurgSim::Math::Vector2d > texture
Definition: Mesh.h:34
SurgSim::Graphics::Mesh::doLoad
bool doLoad(const std::string &fileName) override
Derived classes will overwrite this method to do actual loading.
Definition: Mesh.cpp:108
SurgSim::Graphics::Mesh::dirty
void dirty()
Increase the update count, this indicates that the mesh has been changed, if used in a mesh represent...
Definition: Mesh.cpp:129
SurgSim::Graphics::Mesh::Mesh
Mesh()
Default constructor.
Definition: Mesh.cpp:36
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
SurgSim::Graphics::Mesh::operator=
Mesh & operator=(const Mesh &other)
Copy Assignment.
Definition: Mesh.cpp:139