AGX Dynamics  2.37.2.0
agxVehicle/Track.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 <agxVehicle/TrackWheel.h>
20 #include <agxVehicle/TrackRoute.h>
25 
26 #include <agxSDK/LinkedStructure.h>
27 
28 namespace agxVehicle
29 {
32 
37  {
38  public:
44  using OnNodeInitializeCallback = std::function<void( const TrackNode& )>;
45 
46  public:
51  static Track* get( agx::RigidBody* rb );
52 
57  static const Track* get( const agx::RigidBody* rb );
58 
63  static Track* get( Wheel* wheel );
64 
69  static const Track* get( const Wheel* wheel );
70 
77  static Track* find( agxSDK::Simulation* simulation, const agx::Name& name );
78 
85  static Track* find( agxSDK::Simulation* simulation, const agx::Uuid& uuid );
86 
92  static agxVehicle::TrackPtrVector findAll( agxSDK::Simulation* simulation );
93 
100  static agxVehicle::TrackPtrVector findAll( agxSDK::Simulation* simulation, const agx::Name& name );
101 
102  public:
114  Track( agx::UInt numberOfNodes, agx::Real width, agx::Real thickness, agx::Real initialDistanceTension = agx::Real( 0 ) );
115 
120  Track( agxVehicle::TrackRoute* route );
121 
128 
134  agx::Bool remove( agxVehicle::TrackWheelRef wheel );
135 
139 #ifndef SWIG // for the work-around until SWIG upgrade to work
140  const agxVehicle::Track::TrackWheelContainer& getWheels() const;
141 #endif
142 
149  agxVehicle::TrackWheel* findReferenceWheel() const;
150 
154  agxVehicle::TrackRoute* getRoute() const;
155 
159 #ifndef SWIG // for the work-around until SWIG upgrade to work
160  NodeRange nodes() const;
161 
165  NodeRange nodes( IndexRange range ) const;
166 #endif
167 
171  agxVehicle::TrackWheel* getWheel( const agx::RigidBody* rb ) const;
172 
176  agx::UInt getNumNodes() const;
177 
181  agxVehicle::TrackNode* getNode( agx::UInt index ) const;
182 
187  template<typename T>
188  agxVehicle::TrackNode* getNode( const T* obj ) const;
189 
193  agx::UInt getNodeIndex( const agx::RigidBody* rb ) const;
194 
198  Iterator getIterator( agx::UInt index ) const;
199 
204  template<typename T>
205  Iterator getIterator( const T* obj ) const;
206 
210  agxVehicle::TrackInternalMergeProperties* getInternalMergeProperties() const;
211 
215  agxVehicle::TrackProperties* getProperties() const;
216 
221  void setProperties( agxVehicle::TrackProperties* properties );
222 
223  agx::UInt32Vector onPreGetNodeContacts( const agxVehicle::TrackWheel* wheel ) const;
224 
225  public:
226 #ifndef SWIG
227 
238  virtual agx::Bool initialize( OnNodeInitializeCallback onInitializeCallback );
239 #endif
240 
252  virtual agx::Bool initialize( TrackNodeOnInitializeCallback* onInitializeCallback = nullptr );
253 
268  virtual agx::Bool reinitialize( agx::UInt numberOfNodes,
269  agx::Real width,
270  agx::Real thickness,
271  agx::Real initialDistanceTension = agx::Real( 0 ) );
273 
274  public:
276 
277  virtual void handleGeometryContact( agxCollide::GeometryContact* gc );
278 
279  protected:
281  {
282  INITIALIZED = 1 << 0, // After add notification and route successfully initialized.
283  };
284  using State = agx::BitState<StateEnum, agx::UInt32>;
285 
286  protected:
287  Track();
288  virtual ~Track();
289 
290  virtual void onAddNotification( agxSDK::Simulation* simulation ) override;
291  virtual void onRemoveNotification( agxSDK::Simulation* simulation ) override;
292  virtual void onPreCollideStep() override;
293  virtual void onPreStep() override;
294  virtual void onPostStep() override;
295 
296  private:
297  struct ContactData
298  {
299  using GeometryContactContainer = agx::Vector<agx::Physics::GeometryContactPtr>;
301  using WheelNodeContacts = agx::HashTable<const TrackWheel*, NodeContacts>;
302 
303  WheelNodeContacts wheelNodeContacts;
304  NodeContacts nodeContacts;
305  };
306 
307  struct TrackNodeTriplet
308  {
309  agx::Bool isValid() const { return prev != nullptr && node != nullptr && next != nullptr; }
310 
311  TrackNode* prev;
312  TrackNode* node;
313  TrackNode* next;
314 
316  agx::UInt nodeIndex;
318  };
319 
320  private:
321  TrackNodeTriplet findTrackNodeTriplet( agx::UInt nodeIndex ) const;
322  TrackNodeTriplet findTrackNodeTriplet( const agx::RigidBody* nodeRb ) const;
323 
324  void onPreStepMergeNodes( TrackWheel& wheel, const ContactData::NodeContacts* contacts, agx::UIntVector& mergedNodeIndices );
325  void onPreStepHandleNonMergedNodes( TrackWheel& wheel, agx::UIntVector& mergedNodeIndices );
326  void onPreStepSplitWheelMergedNodes( TrackWheel& wheel, agx::UIntVector& mergedNodeIndices );
327  void onPreInternalMergeNodes( const TrackInternalMergeProperties& properties );
328 
329  void addAndConstrain( TrackNodeRef node, TrackNodeRef prev );
330  void constrain( TrackNode& curr, TrackNode& prev );
331  void merge( TrackWheel& wheel, TrackNode& node );
332  void merge( TrackNode& node1, TrackNode& node2, agx::MergedBody& mergedBody );
333  void split( TrackNode& node );
334  void transformToWheel( TrackNode& node, const TrackWheel& wheel ) const;
335 
336  private:
337  TrackWheelContainer m_wheels;
338  RigidBodyTrackWheelTable m_rbWheelTable;
339  TrackRouteRef m_route;
340  ContactData m_contactData;
341  State m_state;
342  TrackInternalMergeProperties m_internalMergeProperties;
343  TrackPropertiesRef m_properties;
344  };
345 
347  {
348  return LinkedStructure::getT<Track>( rb );
349  }
350 
351  inline const Track* Track::get( const agx::RigidBody* rb )
352  {
353  return LinkedStructure::getT<Track>( rb );
354  }
355 
356  inline Track::TrackNodeTriplet Track::findTrackNodeTriplet( agx::UInt nodeIndex ) const
357  {
358  if ( nodeIndex == agx::InvalidIndex )
359  return { nullptr, nullptr, nullptr, agx::InvalidIndex, agx::InvalidIndex, agx::InvalidIndex };
360 
361  Iterator nodeIt = getIterator( nodeIndex );
362  agxAssert( nodeIt.index() < getNumNodes() );
363  Iterator prevIt = nodeIt - 1ul;
364  Iterator nextIt = nodeIt + 1ul;
365  return
366  {
367  *prevIt, *nodeIt, *nextIt,
368  prevIt.index(), nodeIt.index(), nextIt.index()
369  };
370  }
371 
372  inline Track::TrackNodeTriplet Track::findTrackNodeTriplet( const agx::RigidBody* nodeRb ) const
373  {
374  return findTrackNodeTriplet( getNodeIndex( nodeRb ) );
375  }
376 
377  inline TrackWheel* Track::getWheel( const agx::RigidBody* rb ) const
378  {
379  return m_rbWheelTable.get_or_return_default( rb );
380  }
381 
383  {
384  return getNumSegments();
385  }
386 
387  inline TrackNode* Track::getNode( agx::UInt index ) const
388  {
389  return getSegment( index )->as<TrackNode>();
390  }
391 
392  template<>
393  inline TrackNode* Track::getNode( const agx::RigidBody* obj ) const
394  {
395  auto node = LinkedStructure::getSegment( obj );
396  return node != nullptr ? node->as<TrackNode>() : nullptr;
397  }
398 
399  inline agx::UInt Track::getNodeIndex( const agx::RigidBody* rb ) const
400  {
401  return LinkedStructure::getSegmentIndex( rb );
402  }
403 
405  {
406  return LinkedStructure::getSegmentIterator<TrackNode>( index, true );
407  }
408 
409  template<>
411  {
412  return LinkedStructure::getSegmentIterator<TrackNode>( obj, true );
413  }
414 
415  template<>
416  inline Track::Iterator Track::getIterator( const TrackNode* obj ) const
417  {
418  if ( obj == nullptr )
419  return Iterator::end( getSegmentsContainer() );
420  return getIterator( obj->getRigidBody() );
421  }
422 }
Object containing properties of an agxVehicle::Track.
Abstraction of a wheel of arbitrary geometry.
Definition: Wheel.h:37
Basic implementation of any structure where bodies are linked/constrained together in a well defined ...
#define AGXVEHICLE_EXPORT
static Track * get(agx::RigidBody *rb)
Wheel used in tracked vehicles.
Definition: TrackWheel.h:31
agxVehicle::TrackWheel * getWheel(const agx::RigidBody *rb) const
Track route object to initialize tracks.
Definition: TrackRoute.h:33
bool Bool
Definition: Integer.h:48
Segment range object for linked structure.
This namespace consists of a set of classes for handling geometric intersection tests including boole...
agxSDK::LinkedSegmentRange< TrackNode > TrackNodeRange
Node range object for tracks.
agx::UInt prevIndex(agx::UInt index, agx::UInt size)
Definition: TrackUtils.h:107
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
Node/segment/shoe object in agxVehicle::Track.
Definition: TrackNode.h:46
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Track node initialize callback, called when a track node has been created and is about to be added to...
Representation of a name string.
Definition: Name.h:32
T * as()
Subclass casting.
Structure holding several "normal" rigid bodies.
Definition: MergedBody.h:55
uint32_t UInt
Definition: Integer.h:34
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
const Node * getNode(const IteratorCompatibleContainer &container, agx::Real distanceFromStart)
Finds the wire node given current distance from the start of the wire (wire defined to be iterator co...
Definition: WireUtils.h:392
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
agx::UInt getNodeIndex(const agx::RigidBody *rb) const
std::function< void(const TrackNode &)> OnNodeInitializeCallback
agxVehicle::TrackNode * getNode(agx::UInt index) const
agx::UInt getNumNodes() const
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agx::RigidBody * getRigidBody() const
Properties and thresholds for internal merging of nodes in agxVehicle::Track.
#define agxAssert(expr)
Definition: debug.h:143
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
Iterator getIterator(agx::UInt index) const
Optionally unbounded linked structure segment iterator object to iterate segments in a SegmentStructu...
This namespace contains classes related to vehicles dynamics.
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:41
agx::UInt nextIndex(agx::UInt index, agx::UInt size)
Definition: TrackUtils.h:116
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
agx::BitState< StateEnum, agx::UInt32 > State
agxSDK::LinkedSegmentIterator< TrackNode > TrackNodeIterator
Optionally unbounded track node iterator object to iterate nodes in a track.
double Real
Definition: Real.h:42
Inheritance with partial specialization due to bug with ref_ptr containers.
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
Assembly object representing a continuous track with a given number of shoes (nodes).