ContactDetection.h 4.3 KB
Newer Older
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
//======================================================================================================================
//
//  This file is part of waLBerla. waLBerla is free software: you can
//  redistribute it and/or modify it under the terms of the GNU General Public
//  License as published by the Free Software Foundation, either version 3 of
//  the License, or (at your option) any later version.
//
//  waLBerla is distributed in the hope that it will be useful, but WITHOUT
//  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
//  for more details.
//
//  You should have received a copy of the GNU General Public License along
//  with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file ContactDetection.h
//! \author Sebastian Eibl <sebastian.eibl@fau.de>
//
//======================================================================================================================

#pragma once

#include <mesa_pd/collision_detection/AnalyticContactDetection.h>
#include <mesa_pd/collision_detection/AnalyticCollisionFunctions.h>
#include <mesa_pd/data/DataTypes.h>
#include <mesa_pd/data/shape/BaseShape.h>
#include <mesa_pd/data/shape/HalfSpace.h>
#include <mesa_pd/data/shape/Sphere.h>

#include <core/logging/Logging.h>

namespace walberla {
namespace mesa_pd {

35
class ContactDetection : public collision_detection::AnalyticContactDetection
36
37
{
public:
38
39
   ///import all collision detection functions from AnalyticContactDetection
   using AnalyticContactDetection::operator();
40

41
   ///overwrite functions that should be different
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
   template <typename Accessor>
   bool operator()( const size_t idx1,
                    const size_t idx2,
                    const data::Sphere& geo1,
                    const data::Sphere& geo2,
                    Accessor& ac);

   template <typename Accessor>
   bool operator()( const size_t idx1,
                    const size_t idx2,
                    const data::Sphere& s,
                    const data::HalfSpace& p,
                    Accessor& ac );
};

template <typename Accessor>
inline bool ContactDetection::operator()( const size_t idx1,
                                          const size_t idx2,
                                          const data::Sphere& geo1,
                                          const data::Sphere& geo2,
                                          Accessor& ac)
{
   using namespace collision_detection::analytic;
   WALBERLA_ASSERT_UNEQUAL(idx1, idx2, "colliding with itself!");

   //ensure collision order idx2 has to be larger than idx1
   if (ac.getUid(idx2) < ac.getUid(idx1))
      return operator()(idx2, idx1, geo2, geo1, ac);

   getIdx1() = idx1;
   getIdx2() = idx2;
   return detectSphereSphereCollision(ac.getPosition(getIdx1()),
74
                                      ac.getRadiusAtTemperature(getIdx1()),
75
                                      ac.getPosition(getIdx2()),
76
                                      ac.getRadiusAtTemperature(getIdx2()),
77
78
79
80
81
82
83
84
85
                                      getContactPoint(),
                                      getContactNormal(),
                                      getPenetrationDepth(),
                                      getContactThreshold());
}

template <typename Accessor>
inline bool ContactDetection::operator()( const size_t idx1,
                                          const size_t idx2,
86
                                          const data::Sphere& /*s*/,
87
88
89
90
91
92
93
94
95
                                          const data::HalfSpace& p,
                                          Accessor& ac )
{
   using namespace collision_detection::analytic;
   WALBERLA_ASSERT_UNEQUAL(idx1, idx2, "colliding with itself!");

   getIdx1() = idx1;
   getIdx2() = idx2;
   return detectSphereHalfSpaceCollision(ac.getPosition(getIdx1()),
96
                                         ac.getRadiusAtTemperature(getIdx1()),
97
98
99
100
101
102
103
104
105
106
                                         ac.getPosition(getIdx2()),
                                         p.getNormal(),
                                         getContactPoint(),
                                         getContactNormal(),
                                         getPenetrationDepth(),
                                         getContactThreshold());
}

} //namespace mesa_pd
} //namespace walberla