opensurgsim
Vertex.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_VERTEX_H
17 #define SURGSIM_DATASTRUCTURES_VERTEX_H
18 
19 #include "SurgSim/Math/Vector.h"
20 
21 #include <memory>
22 
23 namespace SurgSim
24 {
25 
26 namespace DataStructures
27 {
28 
43 template <class Data>
44 struct Vertex
45 {
48  {
49  }
50 
54  explicit Vertex(const SurgSim::Math::Vector3d& position, const Data& data = Data()) :
55  position(position),
56  data(data)
57  {
58  }
59 
64  template <class T>
65  explicit Vertex(const Vertex<T>& other) :
66  position(other.position)
67  {
68  }
69 
74  template <class T>
76  {
77  position = other.position;
78  return *this;
79  }
80 
84  Data data;
85 
89  bool operator==(const Vertex<Data>& vertex) const
90  {
91  return data == vertex.data && position == vertex.position;
92  }
93 
97  bool operator!=(const Vertex<Data>& vertex) const
98  {
99  return ! ((*this) == vertex);
100  }
101 };
102 
105 template <>
106 struct Vertex<void>
107 {
110  explicit Vertex(const SurgSim::Math::Vector3d& position) : position(position)
111  {
112  }
113 
116 
120  bool operator==(const Vertex<void>& vertex) const
121  {
122  return position == vertex.position;
123  }
124 
128  bool operator!=(const Vertex<void>& vertex) const
129  {
130  return ! ((*this) == vertex);
131  }
132 };
133 
134 }; // namespace DataStructures
135 
136 }; // namespace SurgSim
137 
138 #endif // SURGSIM_DATASTRUCTURES_VERTEX_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
SurgSim::Math::Vector3d position
Position of the vertex.
Definition: Vertex.h:82
Vertex< Data > & operator=(const Vertex< T > &other)
Assignment when the template data is a different type In this case, no data will be copied...
Definition: Vertex.h:75
bool operator==(const Vertex< void > &vertex) const
Compare the vertex to another one (equality)
Definition: Vertex.h:120
bool operator==(const Vertex< Data > &vertex) const
Compare the vertex to another one (equality)
Definition: Vertex.h:89
Specialization of Vertex with no data.
Definition: Vertex.h:106
SurgSim::Math::Vector3d position
Position of the vertex.
Definition: Vertex.h:115
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
bool operator!=(const Vertex< void > &vertex) const
Compare the vertex to another one (inequality)
Definition: Vertex.h:128
Vertex()
Constructor.
Definition: Vertex.h:47
Vertex structure for meshes.
Definition: Vertex.h:44
Vertex(const Vertex< T > &other)
Copy constructor when the template data is a different type In this case, no data will be copied...
Definition: Vertex.h:65
Vertex(const SurgSim::Math::Vector3d &position, const Data &data=Data())
Constructor.
Definition: Vertex.h:54
Definitions of small fixed-size vector types.
Data data
Extra vertex data.
Definition: Vertex.h:84
Vertex(const SurgSim::Math::Vector3d &position)
Constructor.
Definition: Vertex.h:110
bool operator!=(const Vertex< Data > &vertex) const
Compare the vertex to another one (inequality)
Definition: Vertex.h:97