Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit e22a89c

Browse files
committed
remove CollisionBase class
1 parent 450a1d5 commit e22a89c

File tree

4 files changed

+23
-90
lines changed

4 files changed

+23
-90
lines changed

src/ipc/collisions/normal/normal_collisions.hpp

Lines changed: 5 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,72 +15,14 @@
1515

1616
namespace ipc {
1717

18-
class CollisionsBase {
19-
public:
20-
CollisionsBase() = default;
21-
virtual ~CollisionsBase() = default;
22-
23-
virtual std::shared_ptr<CollisionsBase> deepcopy() const = 0;
24-
25-
/// @brief Get the number of collisions.
26-
virtual size_t size() const = 0;
27-
28-
/// @brief Get if the collision set are empty.
29-
virtual bool empty() const = 0;
30-
31-
/// @brief Clear the collision set.
32-
virtual void clear() = 0;
33-
34-
/// @brief Computes the minimum distance between any non-adjacent elements.
35-
/// @param mesh The collision mesh.
36-
/// @param vertices Vertices of the collision mesh.
37-
/// @returns The minimum distance between any non-adjacent elements.
38-
virtual double compute_minimum_distance(
39-
const CollisionMesh& mesh, Eigen::ConstRef<Eigen::MatrixXd> vertices) const = 0;
40-
41-
/// @brief Get if the collision set are using the convergent formulation.
42-
/// @note If not empty, this is the current value not necessarily the value used to build the collisions.
43-
/// @return If the collision set are using the convergent formulation.
44-
bool are_shape_derivatives_enabled() const
45-
{
46-
return m_are_shape_derivatives_enabled;
47-
}
48-
49-
/// @brief Set if the collision set should enable shape derivative computation.
50-
/// @warning This must be set before the collisions are built.
51-
/// @param are_shape_derivatives_enabled If the collision set should enable shape derivative computation.
52-
void
53-
set_are_shape_derivatives_enabled(const bool are_shape_derivatives_enabled)
54-
{
55-
if (!empty()
56-
&& are_shape_derivatives_enabled
57-
!= m_are_shape_derivatives_enabled) {
58-
logger().warn(
59-
"Setting enable_shape_derivatives after building collisions. "
60-
"Re-build collisions for this to have an effect.");
61-
}
62-
63-
m_are_shape_derivatives_enabled = are_shape_derivatives_enabled;
64-
}
65-
66-
protected:
67-
bool m_use_convergent_formulation = false;
68-
bool m_are_shape_derivatives_enabled = false;
69-
};
70-
71-
class NormalCollisions : public CollisionsBase {
18+
class NormalCollisions {
7219
public:
7320
/// @brief The type of the collisions.
7421
using value_type = NormalCollision;
7522

7623
public:
7724
NormalCollisions() = default;
7825

79-
std::shared_ptr<CollisionsBase> deepcopy() const override
80-
{
81-
return std::make_shared<NormalCollisions>(*this);
82-
}
83-
8426
/// @brief Initialize the set of collisions used to compute the barrier potential.
8527
/// @param mesh The collision mesh.
8628
/// @param vertices Vertices of the collision mesh.
@@ -116,18 +58,18 @@ class NormalCollisions : public CollisionsBase {
11658
/// @returns The minimum distance between any non-adjacent elements.
11759
double compute_minimum_distance(
11860
const CollisionMesh& mesh,
119-
Eigen::ConstRef<Eigen::MatrixXd> vertices) const override;
61+
Eigen::ConstRef<Eigen::MatrixXd> vertices) const;
12062

12163
// ------------------------------------------------------------------------
12264

12365
/// @brief Get the number of collisions.
124-
size_t size() const override;
66+
size_t size() const;
12567

12668
/// @brief Get if the collision set are empty.
127-
bool empty() const override;
69+
bool empty() const;
12870

12971
/// @brief Clear the collision set.
130-
void clear() override;
72+
void clear();
13173

13274
/// @brief Get a reference to collision at index i.
13375
/// @param i The index of the collision.

src/ipc/smooth_contact/smooth_collisions.hpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
#pragma once
22

3-
#include <ipc/collisions/normal/normal_collisions.hpp>
43
#include <ipc/smooth_contact/collisions/smooth_collision.hpp>
54

6-
namespace ipc {
5+
#include <ipc/collision_mesh.hpp>
6+
#include <ipc/candidates/candidates.hpp>
7+
#include <ipc/collisions/normal/edge_edge.hpp>
8+
#include <ipc/collisions/normal/edge_vertex.hpp>
9+
#include <ipc/collisions/normal/face_vertex.hpp>
10+
#include <ipc/collisions/normal/normal_collision.hpp>
11+
#include <ipc/collisions/normal/plane_vertex.hpp>
12+
#include <ipc/collisions/normal/vertex_vertex.hpp>
13+
14+
#include <Eigen/Core>
715

8-
template <int dim> class SmoothCollisions : public CollisionsBase {
16+
#include <vector>
17+
18+
namespace ipc {
19+
template <int dim> class SmoothCollisions {
920
public:
10-
using Super = CollisionsBase;
1121
/// @brief The type of the collisions.
1222
using value_type = SmoothCollision<MaxVertices<dim>::value>;
1323

1424
public:
1525
SmoothCollisions() = default;
1626

17-
std::shared_ptr<CollisionsBase> deepcopy() const override
18-
{
19-
std::shared_ptr<SmoothCollisions<dim>> ptr =
20-
std::make_shared<SmoothCollisions<dim>>();
21-
ptr->candidates = this->candidates;
22-
ptr->vert_adaptive_dhat = this->vert_adaptive_dhat;
23-
ptr->edge_adaptive_dhat = this->edge_adaptive_dhat;
24-
ptr->face_adaptive_dhat = this->face_adaptive_dhat;
25-
for (const auto& cc : this->collisions)
26-
ptr->collisions.push_back(cc);
27-
return ptr;
28-
}
29-
3027
void compute_adaptive_dhat(
3128
const CollisionMesh& mesh,
3229
Eigen::ConstRef<Eigen::MatrixXd> vertices,
@@ -60,13 +57,13 @@ template <int dim> class SmoothCollisions : public CollisionsBase {
6057
// ------------------------------------------------------------------------
6158

6259
/// @brief Get the number of collisions.
63-
size_t size() const override;
60+
size_t size() const;
6461

6562
/// @brief Get if the collision set are empty.
66-
bool empty() const override;
63+
bool empty() const;
6764

6865
/// @brief Clear the collision set.
69-
void clear() override;
66+
void clear();
7067

7168
/// @brief Get a reference to collision at index i.
7269
/// @param i The index of the collision.
@@ -80,7 +77,7 @@ template <int dim> class SmoothCollisions : public CollisionsBase {
8077

8178
double compute_minimum_distance(
8279
const CollisionMesh& mesh,
83-
Eigen::ConstRef<Eigen::MatrixXd> vertices) const override;
80+
Eigen::ConstRef<Eigen::MatrixXd> vertices) const;
8481

8582
double compute_active_minimum_distance(
8683
const CollisionMesh& mesh,

tests/src/tests/friction/friction_data_generator.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ SmoothFrictionData<3> smooth_friction_data_generator_3d()
157157
data;
158158

159159
double& dhat = param.dhat;
160-
collisions.set_are_shape_derivatives_enabled(true);
161160

162161
mu = 1.; // GENERATE(range(0.0, 1.0, 0.2));
163162
#ifdef NDEBUG
@@ -325,7 +324,6 @@ SmoothFrictionData<2> smooth_friction_data_generator_2d()
325324
data;
326325

327326
double& dhat = param.dhat;
328-
collisions.set_are_shape_derivatives_enabled(true);
329327

330328
mu = 1.; // GENERATE(range(0.0, 1.0, 0.2));
331329
#ifdef NDEBUG

tests/src/tests/friction/test_force_jacobian.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,6 @@ void check_smooth_friction_force_jacobian(
356356
const double barrier_stiffness,
357357
const bool recompute_collisions)
358358
{
359-
REQUIRE(collisions.are_shape_derivatives_enabled());
360-
361359
const double dhat = params.dhat;
362360
const Eigen::MatrixXd& X = mesh.rest_positions();
363361
double distance_t0 = collisions.compute_minimum_distance(mesh, X + Ut);
@@ -606,7 +604,6 @@ TEST_CASE(
606604
SmoothFrictionData<2> data = smooth_friction_data_generator_2d();
607605
const auto& [V0, V1, E, F, collisions, mu, epsv_times_h, param, barrier_stiffness] =
608606
data;
609-
REQUIRE(collisions.are_shape_derivatives_enabled());
610607

611608
Eigen::MatrixXd X, Ut, U;
612609
X = V0;
@@ -626,7 +623,6 @@ TEST_CASE(
626623
SmoothFrictionData<3> data = smooth_friction_data_generator_3d();
627624
const auto& [V0, V1, E, F, collisions, mu, epsv_times_h, param, barrier_stiffness] =
628625
data;
629-
REQUIRE(collisions.are_shape_derivatives_enabled());
630626

631627
Eigen::MatrixXd X, Ut, U;
632628
X = V0;

0 commit comments

Comments
 (0)