33#ifndef DART_MATH_DETAIL_TRIMESH_IMPL_HPP_
34#define DART_MATH_DETAIL_TRIMESH_IMPL_HPP_
38#include <Eigen/Geometry>
59 this->mVertices = vertices;
60 mTriangles = triangles;
67 computeTriangleNormals();
69 this->mVertexNormals.clear();
70 this->mVertexNormals.resize(this->mVertices.size(), Vector3::Zero());
72 for (
auto i = 0u; i < mTriangles.size(); ++i)
74 auto& triangle = mTriangles[i];
75 this->mVertexNormals[triangle[0]] += mTriangleNormals[i];
76 this->mVertexNormals[triangle[1]] += mTriangleNormals[i];
77 this->mVertexNormals[triangle[2]] += mTriangleNormals[i];
80 this->normalizeVertexNormals();
87 return !mTriangles.empty();
94 return hasTriangles() && mTriangles.size() == mTriangleNormals.size();
108 return mTriangleNormals;
116 mTriangleNormals.clear();
124 return (
TriMesh(*
this) += other);
134 const auto oldNumVertices = this->mVertices.size();
135 const auto oldNumTriangles = mTriangles.size();
137 Base::operator+=(other);
143 mTriangleNormals.insert(
144 mTriangleNormals.end(),
150 mTriangleNormals.clear();
153 const Triangle offset = Triangle::Constant(oldNumVertices);
154 mTriangles.resize(mTriangles.size() + other.
mTriangles.size());
155 for (
auto i = 0u; i < other.
mTriangles.size(); ++i)
157 mTriangles[i + oldNumTriangles] = other.
mTriangles[i] + offset;
169 std::tie(vertices, triangles)
170 = computeConvexHull3D<S, Index>(this->mVertices, optimize);
172 auto mesh = std::make_shared<TriMesh<S>>();
173 mesh->setTriangles(vertices, triangles);
182 mTriangleNormals.resize(mTriangles.size());
184 for (
auto i = 0u; i < mTriangles.size(); ++i)
186 auto& triangle = mTriangles[i];
188 = this->mVertices[triangle[1]] - this->mVertices[triangle[0]];
190 = this->mVertices[triangle[2]] - this->mVertices[triangle[0]];
191 mTriangleNormals[i] = v01.cross(v02);
194 normalizeTriangleNormals();
201 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:129
void clear() override
Clears all the data in the trimesh.
Definition TriMesh-impl.hpp:113
const Triangles & getTriangles() const
Returns the triangles of the mesh.
Definition TriMesh-impl.hpp:99
TriMesh operator+(const TriMesh &other) const
Addition operator.
Definition TriMesh-impl.hpp:122
void computeTriangleNormals()
Computes triangle normals.
Definition TriMesh-impl.hpp:180
void normalizeTriangleNormals()
Normalizes triangle normals.
Definition TriMesh-impl.hpp:199
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:54
const Normals & getTriangleNormals() const
Returns the triangle normals of the mesh.
Definition TriMesh-impl.hpp:106
typename Base::Vertices Vertices
Definition TriMesh.hpp:54
bool hasTriangles() const
Returns true if the mesh contains triangles.
Definition TriMesh-impl.hpp:85
std::shared_ptr< TriMesh< S > > generateConvexHull(bool optimize=true) const
Generates a convex hull that encloses the trimesh.
Definition TriMesh-impl.hpp:165
typename Base::Normals Normals
Definition TriMesh.hpp:55
TriMesh()
Default constructor.
Definition TriMesh-impl.hpp:47
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:92
void computeVertexNormals()
Computes vertex normals.
Definition TriMesh-impl.hpp:65
typename Base::Vector3 Vector3
Definition TriMesh.hpp:52
Eigen::Matrix< Index, 3, 1 > Triangle
Definition TriMesh.hpp:53
Definition BulletCollisionDetector.cpp:65