opensurgsim
Vertices.h
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_DATASTRUCTURES_VERTICES_H
17 #define SURGSIM_DATASTRUCTURES_VERTICES_H
18 
19 #include <vector>
20 
21 #include "SurgSim/DataStructures/EmptyData.h"
22 #include "SurgSim/DataStructures/Vertex.h"
24 #include "SurgSim/Math/Vector.h"
25 
26 
27 namespace SurgSim
28 {
29 
30 namespace DataStructures
31 {
32 
50 template <class VertexData>
51 class Vertices
52 {
53 public:
56 
58  Vertices();
59 
64  template <class V>
65  explicit Vertices(const Vertices<V>& other);
66 
71  template <class V>
73 
75  virtual ~Vertices();
76 
78  void clear();
79 
83  bool update();
84 
91  size_t addVertex(const VertexType& vertex);
92 
94  size_t getNumVertices() const;
95 
97  const VertexType& getVertex(size_t id) const;
98 
100  VertexType& getVertex(size_t id);
101 
103  const std::vector<VertexType>& getVertices() const;
104 
106  std::vector<VertexType>& getVertices();
107 
111  void setVertexPosition(size_t id, const SurgSim::Math::Vector3d& position);
112 
116  const SurgSim::Math::Vector3d& getVertexPosition(size_t id) const;
117 
121  void setVertexPositions(const std::vector<SurgSim::Math::Vector3d>& positions, bool doUpdate = true);
122 
125  void transform(const Math::RigidTransform3d& pose);
126 
130  bool operator==(const Vertices& mesh) const;
131 
135  bool operator!=(const Vertices& mesh) const;
136 
137 protected:
139  virtual void doClearVertices();
140 
145  virtual bool isEqual(const Vertices& mesh) const;
146 
147 private:
149  virtual void doClear();
150 
155  virtual bool doUpdate();
156 
158  std::vector<VertexType> m_vertices;
159 };
160 
162 
163 }; // namespace DataStructures
164 }; // namespace SurgSim
165 
166 #include "SurgSim/DataStructures/Vertices-inl.h"
167 
168 #endif // SURGSIM_DATASTRUCTURES_VERTICES_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
void transform(const Math::RigidTransform3d &pose)
Apply a rigid transform to each vertex.
Definition: Vertices-inl.h:157
size_t getNumVertices() const
Returns the number of vertices in this mesh.
Definition: Vertices-inl.h:99
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
virtual ~Vertices()
Destructor.
Definition: Vertices-inl.h:75
Vertices< VertexData > & operator=(const Vertices< V > &other)
Assignment when the template data is a different type In this case, no data will be copied...
Definition: Vertices-inl.h:47
bool operator==(const Vertices &mesh) const
Compares the mesh with another one (equality)
Definition: Vertices-inl.h:166
Vertices()
Constructor.
Definition: Vertices-inl.h:30
bool update()
Performs any updates that are required when the vertices are modified.
Definition: Vertices-inl.h:86
const VertexType & getVertex(size_t id) const
Returns the specified vertex.
Definition: Vertices-inl.h:105
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
void setVertexPositions(const std::vector< SurgSim::Math::Vector3d > &positions, bool doUpdate=true)
Sets the position of each vertex.
Definition: Vertices-inl.h:141
Vertex structure for meshes.
Definition: Vertex.h:44
const std::vector< VertexType > & getVertices() const
Returns a vector containing the position of each vertex.
Definition: Vertices-inl.h:117
void setVertexPosition(size_t id, const SurgSim::Math::Vector3d &position)
Sets the position of a vertex.
Definition: Vertices-inl.h:129
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
Definitions of small fixed-size vector types.
size_t addVertex(const VertexType &vertex)
Adds a vertex to the mesh.
Definition: Vertices-inl.h:92
void clear()
Clear mesh to return to an empty state (no vertices).
Definition: Vertices-inl.h:80
Vertex< VertexData > VertexType
Vertex type for convenience.
Definition: Vertices.h:55
virtual bool isEqual(const Vertices &mesh) const
Internal comparison of meshes of the same type: returns true if equal, false if not equal...
Definition: Vertices-inl.h:184
virtual void doClearVertices()
Remove all vertices from the mesh.
Definition: Vertices-inl.h:178
const SurgSim::Math::Vector3d & getVertexPosition(size_t id) const
Returns the position of a vertex.
Definition: Vertices-inl.h:135
Base class for mesh structures, handling basic vertex functionality.
Definition: Vertices.h:51
bool operator!=(const Vertices &mesh) const
Compares the mesh with another one (inequality)
Definition: Vertices-inl.h:172