Vertices-inl.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_DATASTRUCTURES_VERTICES_INL_H
#define SURGSIM_DATASTRUCTURES_VERTICES_INL_H
#include <typeinfo>
#include "SurgSim/Framework/Assert.h"
namespace SurgSim
{
namespace DataStructures
{
template <class VertexData>
Vertices<VertexData>::Vertices()
{
}
template <class VertexData>
template <class V>
Vertices<VertexData>::Vertices(const Vertices<V>& other)
{
m_vertices.reserve(other.getVertices().size());
for (auto& otherVertex : other.getVertices())
{
addVertex(VertexType(otherVertex));
}
}
template <class VertexData>
template <class V>
Vertices<VertexData>& Vertices<VertexData>::operator=(const Vertices<V>& other)
{
auto& otherVertices = other.getVertices();
if (otherVertices.size() < m_vertices.size())
{
m_vertices.resize(otherVertices.size());
}
else
{
m_vertices.reserve(otherVertices.size());
}
auto vertex = m_vertices.begin();
auto otherVertex = otherVertices.begin();
for (; vertex != m_vertices.end(); ++vertex, ++otherVertex)
{
*vertex = *otherVertex;
}
for (; otherVertex != otherVertices.end(); ++otherVertex)
{
addVertex(VertexType(*otherVertex));
}
return *this;
}
template <class VertexData>
Vertices<VertexData>::~Vertices()
{
}
template <class VertexData>
void Vertices<VertexData>::clear()
{
doClear();
}
template <class VertexData>
bool Vertices<VertexData>::update()
{
return doUpdate();
}
template <class VertexData>
size_t Vertices<VertexData>::addVertex(const VertexType& vertex)
{
m_vertices.push_back(vertex);
return m_vertices.size() - 1;
}
template <class VertexData>
size_t Vertices<VertexData>::getNumVertices() const
{
return m_vertices.size();
}
template <class VertexData>
const typename Vertices<VertexData>::VertexType& Vertices<VertexData>::getVertex(size_t id) const
{
return m_vertices[id];
}
template <class VertexData>
typename Vertices<VertexData>::VertexType& Vertices<VertexData>::getVertex(size_t id)
{
return m_vertices[id];
}
template <class VertexData>
const std::vector<typename Vertices<VertexData>::VertexType>& Vertices<VertexData>::getVertices() const
{
return m_vertices;
}
template <class VertexData>
std::vector<typename Vertices<VertexData>::VertexType>& Vertices<VertexData>::getVertices()
{
return m_vertices;
}
template <class VertexData>
void Vertices<VertexData>::setVertexPosition(size_t id, const SurgSim::Math::Vector3d& position)
{
m_vertices[id].position = position;
}
template <class VertexData>
const SurgSim::Math::Vector3d& Vertices<VertexData>::getVertexPosition(size_t id) const
{
return m_vertices[id].position;
}
template <class VertexData>
void Vertices<VertexData>::setVertexPositions(const std::vector<SurgSim::Math::Vector3d>& positions, bool doUpdate)
{
SURGSIM_ASSERT(m_vertices.size() == positions.size()) << "Number of positions must match number of vertices.";
for (size_t i = 0; i < m_vertices.size(); ++i)
{
m_vertices[i].position = positions[i];
}
if (doUpdate)
{
update();
}
}
template <class VertexData>
void Vertices<VertexData>::transform(const Math::RigidTransform3d& pose)
{
for (auto& vertex : m_vertices)
{
vertex.position = pose * vertex.position;
}
}
template <class VertexData>
bool Vertices<VertexData>::operator==(const Vertices& mesh) const
{
return (typeid(*this) == typeid(mesh)) && isEqual(mesh);
}
template <class VertexData>
bool Vertices<VertexData>::operator!=(const Vertices& mesh) const
{
return (typeid(*this) != typeid(mesh)) || ! isEqual(mesh);
}
template <class VertexData>
void Vertices<VertexData>::doClearVertices()
{
m_vertices.clear();
}
template <class VertexData>
bool Vertices<VertexData>::isEqual(const Vertices& mesh) const
{
return m_vertices == mesh.m_vertices;
}
template <class VertexData>
void Vertices<VertexData>::doClear()
{
doClearVertices();
}
template <class VertexData>
bool Vertices<VertexData>::doUpdate()
{
return true;
}
};
};
#endif //SURGSIM_DATASTRUCTURES_VERTICES_INL_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::DataStructures::Vertices::transform
void transform(const Math::RigidTransform3d &pose)
Apply a rigid transform to each vertex.
Definition: Vertices-inl.h:157
SurgSim::DataStructures::Vertices::m_vertices
std::vector< VertexType > m_vertices
Vertices.
Definition: Vertices.h:158
SurgSim::DataStructures::Vertices::getNumVertices
size_t getNumVertices() const
Returns the number of vertices in this mesh.
Definition: Vertices-inl.h:99
SurgSim::DataStructures::Vertices::~Vertices
virtual ~Vertices()
Destructor.
Definition: Vertices-inl.h:75
SurgSim::DataStructures::Vertices::operator=
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
SurgSim::DataStructures::Vertices::operator==
bool operator==(const Vertices &mesh) const
Compares the mesh with another one (equality)
Definition: Vertices-inl.h:166
SurgSim::DataStructures::Vertices::Vertices
Vertices()
Constructor.
Definition: Vertices-inl.h:30
SurgSim::DataStructures::Vertices::doUpdate
virtual bool doUpdate()
Performs any updates that are required when the vertices are modified.
Definition: Vertices-inl.h:196
SurgSim::DataStructures::Vertices::update
bool update()
Performs any updates that are required when the vertices are modified.
Definition: Vertices-inl.h:86
SurgSim::DataStructures::Vertices::getVertex
const VertexType & getVertex(size_t id) const
Returns the specified vertex.
Definition: Vertices-inl.h:105
SURGSIM_ASSERT
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77
SurgSim::DataStructures::Vertices::setVertexPositions
void setVertexPositions(const std::vector< SurgSim::Math::Vector3d > &positions, bool doUpdate=true)
Sets the position of each vertex.
Definition: Vertices-inl.h:141
SurgSim::DataStructures::Vertex
Vertex structure for meshes.
Definition: Vertex.h:44
SurgSim::DataStructures::Vertices::getVertices
const std::vector< VertexType > & getVertices() const
Returns a vector containing the position of each vertex.
Definition: Vertices-inl.h:117
SurgSim::DataStructures::Vertices::setVertexPosition
void setVertexPosition(size_t id, const SurgSim::Math::Vector3d &position)
Sets the position of a vertex.
Definition: Vertices-inl.h:129
SurgSim::Math::RigidTransform3d
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
Assert.h
The header that provides the assertion API.
SurgSim::DataStructures::Vertices::addVertex
size_t addVertex(const VertexType &vertex)
Adds a vertex to the mesh.
Definition: Vertices-inl.h:92
SurgSim::DataStructures::Vertices::clear
void clear()
Clear mesh to return to an empty state (no vertices).
Definition: Vertices-inl.h:80
SurgSim::DataStructures::Vertices::isEqual
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
SurgSim::DataStructures::Vertices::doClearVertices
virtual void doClearVertices()
Remove all vertices from the mesh.
Definition: Vertices-inl.h:178
SurgSim::DataStructures::Vertices::getVertexPosition
const SurgSim::Math::Vector3d & getVertexPosition(size_t id) const
Returns the position of a vertex.
Definition: Vertices-inl.h:135
SurgSim::Math::Vector3d
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
SurgSim::DataStructures::Vertices
Base class for mesh structures, handling basic vertex functionality.
Definition: Vertices.h:51
SurgSim::DataStructures::Vertices::doClear
virtual void doClear()
Clear mesh to return to an empty state (no vertices).
Definition: Vertices-inl.h:190
SurgSim::DataStructures::Vertices::operator!=
bool operator!=(const Vertices &mesh) const
Compares the mesh with another one (inequality)
Definition: Vertices-inl.h:172