AGX Dynamics  2.37.2.0
WireController.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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 #pragma once
18 
19 #include <agxWire/Wire.h>
20 #include <agxWire/WireHandler.h>
22 
23 #include <agxSDK/Simulation.h>
24 
25 #include <agx/agxPhysics_export.h>
26 #include <agx/Singleton.h>
27 
28 namespace agxWire
29 {
55  {
56  public:
63  typedef std::pair< agxSDK::SimulationObserver, WireParallelCallbacksHandlerRef > SimulationObsWireParallelCallbacksHandlerRefPair;
64  typedef std::pair< agxSDK::SimulationObserver, WirePtrContainer > SimulationObsWirePtrContainerPair;
67 
68  public:
72  enum State
73  {
74  EXPLICIT_ENABLE = (1<<0),
75  ALL_ENABLE = (1<<1),
76  USE_DYNAMIC_CONTACTS = (1<<2),
77  DEFAULT = EXPLICIT_ENABLE
78  };
79 
80  public:
84  static WireController* instance();
85 
90  bool isWireWireActive() const;
91 
100  bool setEnableCollisions( agxWire::Wire* wire1, agxWire::Wire* wire2, bool enable );
101 
107  bool getEnableCollisions( const agxWire::Wire* wire1, const agxWire::Wire* wire2 ) const;
108 
121  agx::Bool setEnableDynamicWireContacts( agxCollide::Geometry* geometry, agx::Bool enable );
122 
135  agx::Bool setEnableDynamicWireContacts( agx::RigidBody* rb, agx::Bool enable );
136 
140  void setEnableDynamicWireContactsGlobally( agx::Bool enable);
141 
145  agx::Bool getEnableDynamicWireContacts( const agxCollide::Geometry* geometry ) const;
146 
150  agx::Bool getEnableDynamicWireContacts( const agx::RigidBody* rb ) const;
151 
155  agx::Bool getEnableDynamicWireContactsGlobally() const;
156 
160  agxWire::WireHandler* getOrCreateWireHandler( agxSDK::Simulation* simulation );
161 
165  agxWire::WireParallelCallbacksHandler* getOrCreateWireParallelCallbacksHandler( agxSDK::Simulation* simulation );
166 
170  void removeParallelCallbackHandler( agxSDK::Simulation* simulation );
171 
175  agxWire::WireHandler* find( const agxSDK::Simulation* simulation );
176 
180  agxSDK::Simulation* find( agxWire::WireHandler* handler ) const;
181 
186  WireIterator getBeginWireIterator() const;
187 
191  WireIterator getEndWireIterator() const;
192 
197  agx::UInt getNumWires() const;
198 
202  agxWire::Wire* getWire( agx::UInt index ) const;
203 
207  const WireWireContainer& getEnabledWireWirePairs() const;
208 
210 
211 
215  agxWire::Wire* findWire(agx::UInt32 id) const;
216 
221  agxWire::Wire* findWire(const agxCollide::Geometry* geometry) const;
222 
226  bool add(agxSDK::Simulation* simulation, agxWire::WireHandler* wireHandler);
227 
231  bool remove(agxWire::WireHandler* wireHandler);
232 
236  agx::UInt getStateMask() const;
237 
241  void setStateMask( agx::UInt stateMask );
242 
247  void addState( State state );
248 
253  void removeState( State state );
254 
259  agx::Bool hasState( State state ) const;
260 
264  const agxWire::WireController::IdWireContainer& getIdWireContainer() const;
265 
269  agxWire::WireController::WirePtrContainer getSimplifiedWires(const agxSDK::Simulation* simulation) const;
270 
274  void registerParallelHandlerFactory(agxWire::WireParallelCallbacksHandlerFactory* factory);
275 
279  agxWire::WireParallelCallbacksHandlerFactory* getParallelHandlerFactory() const;
280 
284  agx::ReentrantMutex& getMutex();
285 
287 
291  const agxWire::WireController::WirePtrContainer& getAllWires() const;
292 
293 
294  protected:
295  WireController();
296  virtual ~WireController();
297 
298  virtual void shutdown() override;
299 
300  friend class Wire;
301  friend class WireGeometryController;
302  friend class WireSimplifyController;
303 
307  void onCreate( agxWire::Wire* wire );
308 
312  void onAddNotification( agxWire::Wire* wire );
313 
317  void onDelete( agxWire::Wire* wire );
318 
322  void onRemoveNotification( agxWire::Wire* wire );
323 
327  void updateId( agxWire::Wire* wire );
328 
332  void onSimplify( agxSDK::Simulation* simulation, agxWire::Wire* wire );
333 
337  void onUnsimplify( agxSDK::Simulation* simulation, agxWire::Wire* wire );
338 
339  SINGLETON_CLASSNAME_METHOD();
340 
341  protected:
342  WirePtrContainer m_wires;
343  WireWireContainer m_enabledWires;
344  IdWireContainer m_idWire;
345  WireHandlerContainer m_wireHandlers;
346  WireParallelCallbacksHandlerFactoryRef m_parallelCallbacksFactory;
347  WireParallelCallbacksHandlerContainer m_parallelCallbacksHandlers;
348  SimplifiedWiresContainer m_simplifiedWires;
349  agx::UInt m_state;
350  agx::ReentrantMutex m_mutex;
351  private:
352  static WireController* s_instance;
353  };
354 
355  AGX_FORCE_INLINE WireController::WireIterator WireController::getBeginWireIterator() const
356  {
357  return m_wires.begin();
358  }
359 
361  {
362  return m_wires.end();
363  }
364 }
365 
agx::HashVector< agx::UInt32, agx::observer_ptr< agxWire::Wire > > IdWireContainer
void AGXPHYSICS_EXPORT shutdown()
Shutdown of the AGX Dynamics API will be done when the number of shutdown matches the number of calls...
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a) ...
Definition: SymmetricPair.h:31
bool Bool
Definition: Integer.h:48
This namespace consists of a set of classes for handling geometric intersection tests including boole...
agx::Vector< SimulationObsWireParallelCallbacksHandlerRefPair > WireParallelCallbacksHandlerContainer
#define AGXPHYSICS_EXPORT
agx::Vector< WireHandlerRef > WireHandlerContainer
agx::SetVector< agxWire::Wire *> WirePtrContainer
State
Internal state handling.
#define AGX_FORCE_INLINE
Definition: Object.h:59
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:40
agx::SymmetricPair< agx::observer_ptr< agxWire::Wire > > WireWireSymmetricPair
Interface and placeholder of controllers/helpers for wires.
Definition: Wire.h:61
uint32_t UInt
Definition: Integer.h:34
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Implements a Wire model with adaptive resolution.
Definition: MergedBody.h:39
std::pair< agxSDK::SimulationObserver, WirePtrContainer > SimulationObsWirePtrContainerPair
iterator begin()
Definition: SetVector.h:276
Overlaying object handling wires.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
AGXPHYSICS_EXPORT bool setEnableCollisions(agx::RigidBody *rb1, agx::RigidBody *rb2, bool enable)
Enable or disable the collision between all geometries in RigidBody rb1 and RigidBody rb2...
std::recursive_mutex ReentrantMutex
Definition: Object.h:48
std::pair< agxSDK::SimulationObserver, WireParallelCallbacksHandlerRef > SimulationObsWireParallelCallbacksHandlerRefPair
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
WirePtrContainer::const_iterator WireIterator
WireIterator getEndWireIterator() const
agx::Vector< SimulationObsWirePtrContainerPair > SimplifiedWiresContainer
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...
Definition: Singleton.h:30
agx::Vector< WireWireSymmetricPair > WireWireContainer