DART 6.12.2
Loading...
Searching...
No Matches
Mesh-impl.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2021, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef DART_MATH_DETAIL_MESH_IMPL_HPP_
34#define DART_MATH_DETAIL_MESH_IMPL_HPP_
35
36#include "dart/math/Mesh.hpp"
37
38namespace dart {
39namespace math {
40
41//==============================================================================
42template <typename S>
44{
45 // Do nothing
46}
47
48//==============================================================================
49template <typename S>
51{
52 return !mVertices.empty();
53}
54
55//==============================================================================
56template <typename S>
58{
59 return hasVertices() && mVertices.size() == mVertexNormals.size();
60}
61
62//==============================================================================
63template <typename S>
65{
66 return this->mVertices;
67}
68
69//==============================================================================
70template <typename S>
72{
73 return this->mVertexNormals;
74}
75
76//==============================================================================
77template <typename S>
79{
80 mVertices.clear();
81 mVertexNormals.clear();
82}
83
84//==============================================================================
85template <typename S>
86bool Mesh<S>::isEmpty() const
87{
88 return !(this->hasVertices());
89}
90
91//==============================================================================
92template <typename S>
94{
95 for (auto& vertex : mVertices)
96 {
98 }
99}
100
101//==============================================================================
102template <typename S>
104{
105 return (Mesh(*this) += other);
106}
107
108//==============================================================================
109template <typename S>
111{
112 if (other.isEmpty())
113 return *this;
114
115 // Insert vertex normals if both meshes have normals. Otherwise, clean the
116 // vertex normals.
117 if ((isEmpty() || hasVertexNormals()) && other.hasVertexNormals())
118 {
119 mVertexNormals.insert(
120 mVertexNormals.end(),
121 other.mVertexNormals.begin(),
122 other.mVertexNormals.end());
123 }
124 else
125 {
126 mVertexNormals.clear();
127 }
128
129 // Insert vertices
130 mVertices.insert(
131 mVertices.end(), other.mVertices.begin(), other.mVertices.end());
132
133 return *this;
134}
135
136//==============================================================================
137template <typename S>
139{
140 // Do nothing
141}
142
143//==============================================================================
144template <typename S>
146{
147 for (auto& normal : mVertexNormals)
148 {
149 normal.normalize();
150 }
151}
152
153} // namespace math
154} // namespace dart
155
156#endif // DART_MATH_DETAIL_MESH_IMPL_HPP_
Base class for meshes.
Definition Mesh.hpp:46
const Vertices & getVertices() const
Returns the vertices of the mesh.
Definition Mesh-impl.hpp:64
Eigen::Matrix< S, 3, 1 > Vector3
Definition Mesh.hpp:51
Mesh operator+(const Mesh &other) const
Addition operator.
Definition Mesh-impl.hpp:103
bool isEmpty() const
Returns true if the mesh has no vertices.
Definition Mesh-impl.hpp:86
std::vector< Vector3 > Normals
Definition Mesh.hpp:53
virtual ~Mesh()
Destructor.
Definition Mesh-impl.hpp:43
std::vector< Vector3 > Vertices
Definition Mesh.hpp:52
bool hasVertices() const
Returns true if the mesh contains vertices.
Definition Mesh-impl.hpp:50
virtual void clear()
Clears all the vertices and vertex normals.
Definition Mesh-impl.hpp:78
Mesh()
Default constructor.
Definition Mesh-impl.hpp:138
void normalizeVertexNormals()
Normalizes the vertex normals.
Definition Mesh-impl.hpp:145
bool hasVertexNormals() const
Returns true if the mesh contains vertex normals.
Definition Mesh-impl.hpp:57
void translate(const Vector3 &translation)
Translates the mesh vertices by adding translation to the vertices.
Definition Mesh-impl.hpp:93
const Normals & getVertexNormals() const
Returns the vertex normals of the mesh.
Definition Mesh-impl.hpp:71
Mesh & operator+=(const Mesh &other)
Addition assignment operator.
Definition Mesh-impl.hpp:110
Definition BulletCollisionDetector.cpp:60