33#ifndef DART_MATH_DETAIL_TRIMESH_IMPL_HPP_
34#define DART_MATH_DETAIL_TRIMESH_IMPL_HPP_
36#include <Eigen/Geometry>
58 this->mVertices = vertices;
59 mTriangles = triangles;
66 computeTriangleNormals();
68 this->mVertexNormals.clear();
69 this->mVertexNormals.resize(this->mVertices.size(), Vector3::Zero());
71 for (
auto i = 0u; i < mTriangles.size(); ++i)
73 auto& triangle = mTriangles[i];
74 this->mVertexNormals[triangle[0]] += mTriangleNormals[i];
75 this->mVertexNormals[triangle[1]] += mTriangleNormals[i];
76 this->mVertexNormals[triangle[2]] += mTriangleNormals[i];
79 this->normalizeVertexNormals();
86 return !mTriangles.empty();
93 return hasTriangles() && mTriangles.size() == mTriangleNormals.size();
107 return mTriangleNormals;
115 mTriangleNormals.clear();
123 return (
TriMesh(*
this) += other);
133 const auto oldNumVertices = this->mVertices.size();
134 const auto oldNumTriangles = mTriangles.size();
136 Base::operator+=(other);
142 mTriangleNormals.insert(
143 mTriangleNormals.end(),
149 mTriangleNormals.clear();
152 const Triangle offset = Triangle::Constant(oldNumVertices);
153 mTriangles.resize(mTriangles.size() + other.
mTriangles.size());
154 for (
auto i = 0u; i < other.
mTriangles.size(); ++i)
156 mTriangles[i + oldNumTriangles] = other.
mTriangles[i] + offset;
168 std::tie(vertices, triangles)
169 = computeConvexHull3D<S, Index>(this->mVertices, optimize);
171 auto mesh = std::make_shared<TriMesh<S>>();
172 mesh->setTriangles(vertices, triangles);
181 mTriangleNormals.resize(mTriangles.size());
183 for (
auto i = 0u; i < mTriangles.size(); ++i)
185 auto& triangle = mTriangles[i];
187 = this->mVertices[triangle[1]] - this->mVertices[triangle[0]];
189 = this->mVertices[triangle[2]] - this->mVertices[triangle[0]];
190 mTriangleNormals[i] = v01.cross(v02);
193 normalizeTriangleNormals();
200 for (
auto& normal : mTriangleNormals)
bool isEmpty() const
Returns true if the mesh has no vertices.
Definition Mesh-impl.hpp:86
This class represents triangle meshes.
Definition TriMesh.hpp:46
std::vector< Triangle > Triangles
Definition TriMesh.hpp:56
TriMesh & operator+=(const TriMesh &other)
Addition assignment operator.
Definition TriMesh-impl.hpp:128
void clear() override
Clears all the data in the trimesh.
Definition TriMesh-impl.hpp:112
const Triangles & getTriangles() const
Returns the triangles of the mesh.
Definition TriMesh-impl.hpp:98
TriMesh operator+(const TriMesh &other) const
Addition operator.
Definition TriMesh-impl.hpp:121
void computeTriangleNormals()
Computes triangle normals.
Definition TriMesh-impl.hpp:179
void normalizeTriangleNormals()
Normalizes triangle normals.
Definition TriMesh-impl.hpp:198
Triangles mTriangles
Triangle indices of the mesh.
Definition TriMesh.hpp:105
void setTriangles(const Vertices &vertices, const Triangles &triangles)
Sets vertices and triangles.
Definition TriMesh-impl.hpp:53
const Normals & getTriangleNormals() const
Returns the triangle normals of the mesh.
Definition TriMesh-impl.hpp:105
typename Base::Vertices Vertices
Definition TriMesh.hpp:54
bool hasTriangles() const
Returns true if the mesh contains triangles.
Definition TriMesh-impl.hpp:84
std::shared_ptr< TriMesh< S > > generateConvexHull(bool optimize=true) const
Generates a convex hull that encloses the trimesh.
Definition TriMesh-impl.hpp:164
typename Base::Normals Normals
Definition TriMesh.hpp:55
TriMesh()
Default constructor.
Definition TriMesh-impl.hpp:46
Normals mTriangleNormals
Triangle normals of the mesh.
Definition TriMesh.hpp:108
bool hasTriangleNormals() const
Returns true if the mesh contains triangle normals.
Definition TriMesh-impl.hpp:91
void computeVertexNormals()
Computes vertex normals.
Definition TriMesh-impl.hpp:64
typename Base::Vector3 Vector3
Definition TriMesh.hpp:52
Eigen::Matrix< Index, 3, 1 > Triangle
Definition TriMesh.hpp:53
Definition BulletCollisionDetector.cpp:60