AGX Dynamics  2.35.0.1
ColliderUnitTestUtils.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXUNIT_COLLIDERUNITTESTUTILS_H
18 #define AGXUNIT_COLLIDERUNITTESTUTILS_H
19 
20 #include <agx/agxPhysics_export.h>
21 #include <agx/agx_vector_types.h>
22 #include <agxUnit/UnitMacros.h>
23 #include <agx/Referenced.h>
24 #include <agxCollide/Contacts.h>
25 
27 
28 namespace agx
29 {
30  class RigidBody;
31 }
32 
33 namespace agxSDK {
34  class Simulation;
35 }
36 
37 namespace agxCollide {
38 
39  AGX_DECLARE_POINTER_TYPES(ContactTester);
40  class AGXPHYSICS_EXPORT ContactTester : public agx::Referenced
41  {
42  public:
43  virtual void testContacts(agxCollide::LocalGeometryContact* result, bool inversedOrder)=0;
44 
45  };
46 
47 
48  AGX_DECLARE_POINTER_TYPES(AnyContactTester);
49  class AGXPHYSICS_EXPORT AnyContactTester : public ContactTester
50  {
51  public:
52  AnyContactTester(size_t numAppearances = 1) :
53  m_numAppearances(numAppearances)
54  {
55  }
56 
57  virtual void testContacts(agxCollide::LocalGeometryContact* result, bool inversedOrder) override;
58 
59  protected:
60  size_t m_numAppearances;
61  };
62 
63  AGX_DECLARE_POINTER_TYPES(NormalAndDepthContainedTester);
64  class AGXPHYSICS_EXPORT NormalAndDepthContainedTester : public ContactTester
65  {
66  public:
67  NormalAndDepthContainedTester(const agx::Vec3& normal, agx::Real depth,
68  size_t numAppearances = 1) :
69  m_normal(normal), m_depth(depth),
70  m_numAppearances(numAppearances)
71  {
72  m_normal.normalize();
73  }
74 
75  virtual void testContacts(agxCollide::LocalGeometryContact* result, bool inversedOrder) override;
76 
77  protected:
78  agx::Vec3 m_normal;
79  agx::Real m_depth;
80  size_t m_numAppearances;
81  };
82 
83 
84  AGX_DECLARE_POINTER_TYPES(NormalTester);
85  class AGXPHYSICS_EXPORT NormalTester : public ContactTester
86  {
87  public:
88  NormalTester(const agx::Vec3& normal, size_t numAppearances = 1) :
89  m_normal(normal), m_numAppearances(numAppearances)
90  {
91  m_normal.normalize();
92  }
93 
94  virtual void testContacts(agxCollide::LocalGeometryContact* result, bool inversedOrder) override;
95 
96  protected:
97  agx::Vec3 m_normal;
98  size_t m_numAppearances;
99  };
100 
101 
102  AGX_DECLARE_POINTER_TYPES(NormalDotProductTester);
104  class AGXPHYSICS_EXPORT NormalDotProductTester : public ContactTester
105  {
106  public:
107  NormalDotProductTester(const agx::Vec3& normal, agx::Real dotProduct, size_t numAppearances = 1) :
108  m_normal(normal), m_dotProduct(dotProduct), m_numAppearances(numAppearances)
109  {
110  m_normal.normalize();
111  }
112 
113  virtual void testContacts(agxCollide::LocalGeometryContact* result, bool inversedOrder) override;
114 
115  protected:
116  agx::Vec3 m_normal;
117  agx::Real m_dotProduct;
118  size_t m_numAppearances;
119  };
120 
121 
122  AGX_DECLARE_POINTER_TYPES(AllNormalDotProductTester);
123  class AGXPHYSICS_EXPORT AllNormalDotProductTester : public ContactTester
124  {
125  public:
126  AllNormalDotProductTester(const agx::Vec3& normal, agx::Real dotProduct) :
127  m_normal(normal), m_dotProduct(dotProduct)
128  {
129  m_normal.normalize();
130  }
131 
132  virtual void testContacts(agxCollide::LocalGeometryContact* result, bool inversedOrder) override;
133 
134  protected:
135  agx::Vec3 m_normal;
136  agx::Real m_dotProduct;
137  };
138 
139 
140  AGX_DECLARE_POINTER_TYPES(AllSameNormalsTester);
141  class AGXPHYSICS_EXPORT AllSameNormalsTester : public ContactTester
142  {
143  public:
144  AllSameNormalsTester(const agx::Vec3& normal) :
145  m_normal(normal)
146  {
147  m_normal.normalize();
148  }
149 
150  virtual void testContacts(agxCollide::LocalGeometryContact* result, bool inversedOrder) override;
151 
152  protected:
153  agx::Vec3 m_normal;
154  };
155 
156 
157  AGX_DECLARE_POINTER_TYPES(NoContactTester);
158  class AGXPHYSICS_EXPORT NoContactTester : public ContactTester
159  {
160  public:
161  NoContactTester(){}
162 
163  virtual void testContacts(agxCollide::LocalGeometryContact* result, bool inversedOrder) override;
164  };
165 
166 
167  AGX_DECLARE_POINTER_TYPES(AllTester);
168  class AGXPHYSICS_EXPORT AllTester : public ContactTester {
169  public:
170  AllTester(const agx::Vec3& point, const agx::Vec3& normal, agx::Real depth) :
171  m_point(point), m_normal(normal), m_depth(depth)
172  {
173  m_normal.normalize();
174  }
175 
176  virtual void testContacts(agxCollide::LocalGeometryContact* result, bool inversedOrder) override;
177 
178  protected:
179  agx::Vec3 m_point;
180  agx::Vec3 m_normal;
181  agx::Real m_depth;
182  };
183 
184 
185  AGX_DECLARE_POINTER_TYPES(NormalOrOppositeAndDepthContainedTester);
186  class AGXPHYSICS_EXPORT NormalOrOppositeAndDepthContainedTester : public ContactTester {
187  public:
188  NormalOrOppositeAndDepthContainedTester(const agx::Vec3& normal, agx::Real depth,
189  size_t numAppearances = 1) :
190  m_normal(normal), m_depth(depth),
191  m_numAppearances(numAppearances)
192  {
193  m_normal.normalize();
194  }
195 
196  virtual void testContacts(agxCollide::LocalGeometryContact* result, bool inversedOrder) override;
197 
198  protected:
199  agx::Vec3 m_normal;
200  agx::Real m_depth;
201  size_t m_numAppearances;
202  };
203 
204 
205  AGX_DECLARE_POINTER_TYPES(OrthoNormalAndDepthContainedTester);
206  class AGXPHYSICS_EXPORT OrthoNormalAndDepthContainedTester : public ContactTester {
207  public:
208  OrthoNormalAndDepthContainedTester(const agx::Vec3& normal, agx::Real depth,
209  size_t numAppearances = 1) :
210  m_normal(normal), m_depth(depth),
211  m_numAppearances(numAppearances)
212  {
213  m_normal.normalize();
214  }
215 
216  virtual void testContacts(agxCollide::LocalGeometryContact* result, bool inversedOrder) override;
217 
218  protected:
219  agx::Vec3 m_normal;
220  agx::Real m_depth;
221  size_t m_numAppearances;
222  };
223 
224 
225 
226 
227  AGX_DECLARE_POINTER_TYPES(MeshTriangleTester);
228  class AGXPHYSICS_EXPORT MeshTriangleTester : public ContactTester {
229  public:
230  enum ContactsToTest {TEST_FOR_ONE, TEST_FOR_ALL};
231 
232  MeshTriangleTester( ContactsToTest toTest) :
233  m_toTest(toTest)
234  {}
235 
241  void addContact(agx::UInt32 triangleNr, agx::UInt8 voronoiRegion, agx::UInt8 shapeNr)
242  {
243  m_triangleNrs.push_back(triangleNr);
244  m_voronoiRegions.push_back(voronoiRegion);
245  agxAssert( shapeNr < 2);
246  m_shapeNumbers.push_back(shapeNr);
247  }
248 
249  virtual void testContacts(agxCollide::LocalGeometryContact* result, bool inversedOrder) override;
250 
251  protected:
252  agx::UInt32Vector m_triangleNrs;
253  agx::UInt8Vector m_voronoiRegions;
254  agx::UInt8Vector m_shapeNumbers;
255  ContactsToTest m_toTest;
256  };
257 
258 
260  agxSDK::Simulation* simulation,
261  const agx::RigidBodyPtrVector& bodies,
262  const char* groupName,
263  const char* testName,
264  agx::Real preTestingTime = agx::Real(1.0),
265  bool onlyForDoublePrecision = false);
266 
267  inline void testResting(
268  agxSDK::Simulation* simulation,
269  agx::RigidBody* body,
270  const char* groupName,
271  const char* testName,
272  agx::Real preTestingTime = agx::Real(1.0),
273  bool onlyForDoublePrecision = false)
274  {
276  bodies.push_back( body );
277  testResting( simulation, bodies, groupName, testName, preTestingTime, onlyForDoublePrecision );
278  }
279 
280 
281  AGXPHYSICS_EXPORT void testContacts(
282  agxSDK::Simulation* simulation,
283  const char* groupName,
284  const char* testName,
285  ContactTester* tester,
286  bool onlyForDoublePrecision = false);
287 
297  AGXPHYSICS_EXPORT void testColliderRespectsOtherResults(
299 }
300 
302 
303 #endif
#define AGXPHYSICS_EXPORT
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
Base class providing referencing counted objects.
Definition: Referenced.h:114
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
void push_back(const T &value)
Definition: agx/Vector.h:1362
#define agxAssert(expr)
Definition: debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
This namespace consists of a set of classes for handling geometric intersection tests including boole...
AGX_DECLARE_POINTER_TYPES(SpaceListener)
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
AGXOSG_EXPORT osg::Group * testResting(agxSDK::Simulation *simulation, agxOSG::ExampleApplication *application, OneBodyRestingScenePtr restingScene, const char *groupName, const char *testName, agx::Real preTestingTime=agx::Real(1))
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:40
double Real
Definition: Real.h:42
uint8_t UInt8
Definition: Integer.h:38