AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
agxVehicle/Track.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
25
27
28namespace 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
93
101
102 public:
114 Track( agx::UInt numberOfNodes, agx::Real width, agx::Real thickness, agx::Real initialDistanceTension = agx::Real( 0 ) );
115
121
128
135
139#ifndef SWIG // for the work-around until SWIG upgrade to work
141#endif
142
150
155
159#ifndef SWIG // for the work-around until SWIG upgrade to work
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
211
216
222
224
225 public:
226#ifndef SWIG
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:
280 enum StateEnum : agx::UInt32
281 {
282 INITIALIZED = 1 << 0, // After add notification and route successfully initialized.
283 };
284 using State = agx::BitState<StateEnum, agx::UInt32>;
285
286 protected:
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
315 agx::UInt prevIndex;
316 agx::UInt nodeIndex;
317 agx::UInt nextIndex;
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 agx::Bool 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
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<>
417 {
418 if ( obj == nullptr )
420 return getIterator( obj->getRigidBody() );
421 }
422}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
#define AGXVEHICLE_EXPORT
Optionally unbounded linked structure segment iterator object to iterate segments in a SegmentStructu...
static LinkedSegmentIterator end(const agxSDK::LinkedSegmentContainer &segments)
Segment range object for linked structure.
agx::RigidBody * getRigidBody() const
Basic implementation of any structure where bodies are linked/constrained together in a well defined ...
const agxSDK::LinkedSegmentContainer & getSegmentsContainer() const
LinkedSegment * getSegment(agx::UInt index) const
agx::UInt getNumSegments() const
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
Properties and thresholds for internal merging of nodes in agxVehicle::Track.
Track node initialize callback, called when a track node has been created and is about to be added to...
Node/segment/shoe object in agxVehicle::Track.
Definition TrackNode.h:47
Object containing properties of an agxVehicle::Track.
Track route object to initialize tracks.
Definition TrackRoute.h:34
Wheel used in tracked vehicles.
Definition TrackWheel.h:32
Assembly object representing a continuous track with a given number of shoes (nodes).
agxVehicle::TrackNode * getNode(const T *obj) const
NodeRange nodes() const
agxVehicle::TrackInternalMergeProperties * getInternalMergeProperties() const
agxVehicle::TrackProperties * getProperties() const
void setProperties(agxVehicle::TrackProperties *properties)
Assign properties to this track.
agx::UInt getNumNodes() const
virtual void onPreStep() override
Called on simulation pre step event - after user preStep.
static agxVehicle::TrackPtrVector findAll(agxSDK::Simulation *simulation, const agx::Name &name)
Finds all track instances given simulation and name.
Track(agxVehicle::TrackRoute *route)
Construct given a track route.
virtual agx::Bool initialize(TrackNodeOnInitializeCallback *onInitializeCallback=nullptr)
Initialize this track given already assigned route, added wheels, number of nodes and an initialize n...
virtual void onPostStep() override
Called on simulation post step event - after user postStep.
agx::UInt getNodeIndex(const agx::RigidBody *rb) const
static const Track * get(const Wheel *wheel)
agx::Bool add(agxVehicle::TrackWheelRef wheel)
Add track wheel to this track before this track has been initialized.
static Track * find(agxSDK::Simulation *simulation, const agx::Uuid &uuid)
Find track instance given simulation and unique id.
static Track * find(agxSDK::Simulation *simulation, const agx::Name &name)
Find track instance given simulation and name.
agx::Bool remove(agxVehicle::TrackWheelRef wheel)
Remove track wheel.
Track(agx::UInt numberOfNodes, agx::Real width, agx::Real thickness, agx::Real initialDistanceTension=agx::Real(0))
Construct track given number of nodes, size and initial tension distance.
TrackNodeIterator Iterator
virtual void onAddNotification(agxSDK::Simulation *simulation) override
Called when addNotification is executed when this linked structure is added to the simulation.
Iterator getIterator(const T *obj) const
agxVehicle::TrackWheel * findReferenceWheel() const
Reference wheel's rotation axis is defining the plane in which this track will be created.
std::function< void(const TrackNode &)> OnNodeInitializeCallback
agxVehicle::TrackWheel * getWheel(const agx::RigidBody *rb) const
Iterator getIterator(agx::UInt index) const
const agxVehicle::Track::TrackWheelContainer & getWheels() const
agx::UInt32Vector onPreGetNodeContacts(const agxVehicle::TrackWheel *wheel) const
agxVehicle::TrackNode * getNode(agx::UInt index) const
static Track * get(agx::RigidBody *rb)
static agxVehicle::TrackPtrVector findAll(agxSDK::Simulation *simulation)
Finds all agxVehicle::Track instances in the given simulation.
NodeRange nodes(IndexRange range) const
virtual void onRemoveNotification(agxSDK::Simulation *simulation) override
Called when removeNotification is executed when this linked structure is removed from the simulation.
virtual agx::Bool initialize(OnNodeInitializeCallback onInitializeCallback)
Initialize this track given already assigned route, added wheels, number of nodes and an initialize n...
static Track * get(Wheel *wheel)
agx::BitState< StateEnum, agx::UInt32 > State
agxVehicle::TrackRoute * getRoute() const
virtual void onPreCollideStep() override
Called on simulation pre-collide step event - after user preCollide.
Abstraction of a wheel of arbitrary geometry.
Definition Wheel.h:38
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition HashVector.h:41
const ValueT get_or_return_default(const KeyT &k) const
Inheritance with partial specialization due to bug with ref_ptr containers.
Structure holding several "normal" rigid bodies.
Definition MergedBody.h:56
Representation of a name string.
Definition Name.h:33
T * as()
Subclass casting.
The rigid body class, combining a geometric model and a frame of reference.
Definition RigidBody.h:52
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition Uuid.h:42
Vector containing 'raw' data.
Definition agx/Vector.h:246
Smart pointer for handling referenced counted objects.
Definition ref_ptr.h:30
#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...
This namespace contains classes related to vehicles dynamics.
agx::ref_ptr< TrackRoute > TrackRouteRef
Definition TrackRoute.h:28
agx::ref_ptr< TrackProperties > TrackPropertiesRef
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
bool Bool
Definition Integer.h:40
uint64_t UInt
Definition Integer.h:27
double Real
Definition Real.h:42
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex