Repository navigation
Expand file tree
/
Copy pathnormal_collisions.hpp
More file actions
169 lines (137 loc) · 6.92 KB
/
Copy pathnormal_collisions.hpp
File metadata and controls
169 lines (137 loc) · 6.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#pragma once
#include <ipc/collision_mesh.hpp>
#include <ipc/candidates/candidates.hpp>
#include <ipc/collisions/normal/edge_edge.hpp>
#include <ipc/collisions/normal/edge_vertex.hpp>
#include <ipc/collisions/normal/face_vertex.hpp>
#include <ipc/collisions/normal/normal_collision.hpp>
#include <ipc/collisions/normal/plane_vertex.hpp>
#include <ipc/collisions/normal/vertex_vertex.hpp>
#include <Eigen/Core>
#include <vector>
namespace ipc {
class NormalCollisions {
public:
/// @brief The type of the collisions.
using value_type = NormalCollision;
public:
NormalCollisions() = default;
/// @brief Initialize the set of collisions used to compute the barrier potential.
/// @param mesh The collision mesh.
/// @param vertices Vertices of the collision mesh.
/// @param dhat The activation distance of the barrier.
/// @param dmin Minimum distance.
/// @param broad_phase Broad-phase method to use.
void build(
const CollisionMesh& mesh,
Eigen::ConstRef<Eigen::MatrixXd> vertices,
const double dhat,
const double dmin = 0,
const std::shared_ptr<BroadPhase> broad_phase =
make_default_broad_phase());
/// @brief Initialize the set of collisions used to compute the barrier potential.
/// @param candidates Distance candidates from which the collision set is built.
/// @param mesh The collision mesh.
/// @param vertices Vertices of the collision mesh.
/// @param dhat The activation distance of the barrier.
/// @param dmin Minimum distance.
void build(
const Candidates& candidates,
const CollisionMesh& mesh,
Eigen::ConstRef<Eigen::MatrixXd> vertices,
const double dhat,
const double dmin = 0);
// ------------------------------------------------------------------------
/// @brief Computes the minimum distance between any non-adjacent elements.
/// @param mesh The collision mesh.
/// @param vertices Vertices of the collision mesh.
/// @returns The minimum distance between any non-adjacent elements.
double compute_minimum_distance(
const CollisionMesh& mesh,
Eigen::ConstRef<Eigen::MatrixXd> vertices) const;
/// @returns The avg distance between any non-adjacent elements less than dhat.
double compute_avg_distance(
const CollisionMesh& mesh, Eigen::ConstRef<Eigen::MatrixXd> vertices, const double dhat) const;
// ------------------------------------------------------------------------
/// @brief Get the number of collisions.
size_t size() const;
/// @brief Get if the collision set are empty.
bool empty() const;
/// @brief Clear the collision set.
void clear();
/// @brief Get a reference to collision at index i.
/// @param i The index of the collision.
/// @return A reference to the collision.
NormalCollision& operator[](size_t i);
/// @brief Get a const reference to collision at index i.
/// @param i The index of the collision.
/// @return A const reference to the collision.
const NormalCollision& operator[](size_t i) const;
/// @brief Get if the collision at i is a vertex-vertex collision.
/// @param i The index of the collision.
/// @return If the collision at i is a vertex-vertex collision.
bool is_vertex_vertex(size_t i) const;
/// @brief Get if the collision at i is an edge-vertex collision.
/// @param i The index of the collision.
/// @return If the collision at i is an edge-vertex collision.
bool is_edge_vertex(size_t i) const;
/// @brief Get if the collision at i is an edge-edge collision.
/// @param i The index of the collision.
/// @return If the collision at i is an edge-edge collision.
bool is_edge_edge(size_t i) const;
/// @brief Get if the collision at i is an face-vertex collision.
/// @param i The index of the collision.
/// @return If the collision at i is an face-vertex collision.
bool is_face_vertex(size_t i) const;
/// @brief Get if the collision at i is an plane-vertex collision.
/// @param i The index of the collision.
/// @return If the collision at i is an plane-vertex collision.
bool is_plane_vertex(size_t i) const;
/// @brief Get if the collision set should use area weighting.
/// @note If not empty, this is the current value not necessarily the value used to build the collisions.
/// @return If the collision set should use area weighting.
bool use_area_weighting() const { return m_use_area_weighting; }
/// @brief Set if the collision set should use area weighting.
/// @warning This must be set before the collisions are built.
/// @param use_area_weighting If the collision set should use area weighting.
void set_use_area_weighting(const bool use_area_weighting);
/// @brief Get if the collision set should use the improved max approximator.
/// @note If not empty, this is the current value not necessarily the value used to build the collisions.
/// @return If the collision set should use the improved max approximator.
bool use_improved_max_approximator() const
{
return m_use_improved_max_approximator;
}
/// @brief Set if the collision set should use the improved max approximator.
/// @warning This must be set before the collisions are built.
/// @param use_improved_max_approximator If the collision set should use the improved max approximator.
void
set_use_improved_max_approximator(const bool use_improved_max_approximator);
/// @brief Get if the collision set are using the convergent formulation.
/// @note If not empty, this is the current value not necessarily the value used to build the collisions.
/// @return If the collision set are using the convergent formulation.
bool enable_shape_derivatives() const { return m_enable_shape_derivatives; }
/// @brief Set if the collision set should enable shape derivative computation.
/// @warning This must be set before the collisions are built.
/// @param enable_shape_derivatives If the collision set should enable shape derivative computation.
void set_enable_shape_derivatives(const bool enable_shape_derivatives);
std::string to_string(
const CollisionMesh& mesh,
Eigen::ConstRef<Eigen::MatrixXd> vertices) const;
public:
/// @brief Vertex-vertex normal collisions.
std::vector<VertexVertexNormalCollision> vv_collisions;
/// @brief Edge-vertex normal collisions.
std::vector<EdgeVertexNormalCollision> ev_collisions;
/// @brief Edge-edge normal collisions.
std::vector<EdgeEdgeNormalCollision> ee_collisions;
/// @brief Face-vertex normal collisions.
std::vector<FaceVertexNormalCollision> fv_collisions;
/// @brief Plane-vertex normal collisions.
std::vector<PlaneVertexNormalCollision> pv_collisions;
protected:
bool m_use_area_weighting = false;
bool m_use_improved_max_approximator = false;
bool m_enable_shape_derivatives = false;
};
} // namespace ipc