AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
TrackUtils.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
19#include <agxVehicle/Track.h>
20
21#include <agxCollide/Box.h>
22
23namespace agxVehicle
24{
25 namespace utils
26 {
27 inline void createGeometryBox( const TrackNode& node )
28 {
31 geometry->setLocalTransform( transform );
32 node.getRigidBody()->add( geometry );
33 }
34
41 template<typename ContainerT>
42 IndexRangeContainer splitNonconsecutive( const ContainerT& container )
43 {
44 if ( container.size() < 2 )
45 return IndexRangeContainer{ IndexRange( 0, container.size() ) };
46
47 agxAssert( std::is_sorted( container.begin(), container.end() ) );
48
49 IndexRangeContainer result{ IndexRange( 0, 1 ) };
50 for ( agx::UInt i = 1; i < container.size(); ++i ) {
51 if ( container[ i ] == container[ i - 1 ] + typename ContainerT::value_type( 1 ) )
52 ++result.back().end();
53 else
54 result.push_back( agx::IndexRange( i, i + 1 ) );
55 }
56
57 return result;
58 }
59
69 template<typename ContainerT>
70 IndexRangeContainer splitNonconsecutive( const Track& track, const ContainerT& container )
71 {
72 auto result = splitNonconsecutive( container );
73
74 agxAssert( !result.empty() );
75 if ( result.size() == 1 && result.front().empty() )
76 return IndexRangeContainer{};
77
78 // Transform ranges from indices to container values. E.g.,
79 // 2 4 7 [9 10 11 12] 18
80 // index: 3 ... 6
81 // range original: begin = 3, end = 7
82 // range transformed: begin = 9, end = 13
83 for ( agx::UInt i = 0; i < result.size(); ++i ) {
84 auto& range = result[ i ];
85 const auto size = range.size();
86 range.begin() = container[ range.begin() ];
87 range.end() = range.begin() + size;
88 }
89
90 if ( result.size() < 2 )
91 return result;
92
93 // Including the last range in the first if the first node belongs
94 // to the first range and the last node to the last.
95 const auto numNodes = track.nodes().size();
96 if ( result.front().begin() == agx::UInt( 0 ) && result.back().end() == numNodes ) {
97 result.front().begin() = result.back().begin();
98 result.pop_back();
99 }
100
101 return result;
102 }
103
108 {
109 agxAssert( size > 0 && index != agx::InvalidIndex );
110 return index == 0 ? size - 1 : index - 1;
111 }
112
117 {
118 agxAssert( size > 0 && index != agx::InvalidIndex );
119 return ( index + 1 ) % size;
120 }
121
128 inline TrackNodeRange createRangeExcludingNodeIndex( const Track& track, agx::UInt nodeIndex, agx::Int signedNumNodes )
129 {
130 const auto totalNumNodes = track.nodes().size();
131 if ( totalNumNodes < 1 )
132 return track.nodes();
133
134 const agx::UInt numNodes = signedNumNodes < 0 ?
135 (agx::UInt)-signedNumNodes :
136 (agx::UInt)signedNumNodes;
137 agx::UInt beginIndex = agx::InvalidIndex;
138 agx::UInt endIndex = agx::InvalidIndex;
139 if ( signedNumNodes < 0 ) {
140 beginIndex = nodeIndex > numNodes ?
141 nodeIndex - numNodes :
142 nodeIndex + totalNumNodes - numNodes;
143 endIndex = nodeIndex;
144 }
145 else {
146 beginIndex = ( nodeIndex + 1 ) % totalNumNodes;
147 endIndex = ( nodeIndex + numNodes + 1 ) % totalNumNodes;
148 }
149
150 return TrackNodeRange( track.getIterator( beginIndex ), track.getIterator( endIndex ) );
151 }
152 }
153}
A box shape for geometric intersection tests.
Definition Box.h:33
The geometry representation used by the collision detection engine.
Definition Geometry.h:92
Segment range object for linked structure.
const agx::Vec3 & getHalfExtents() const
agx::RigidBody * getRigidBody() const
Node/segment/shoe object in agxVehicle::Track.
Definition TrackNode.h:47
Assembly object representing a continuous track with a given number of shoes (nodes).
NodeRange nodes() const
Iterator getIterator(agx::UInt index) const
static AffineMatrix4x4T< Real > translate(const Vec3T< Real > &dv)
Return a matrix which translates according to dv.
size_t size() const
Definition Container.h:134
bool add(agxCollide::Geometry *geometry, const agx::AffineMatrix4x4 &localTransform, bool incrementalMassCalculation=false)
Connect a geometry to this rigid body.
#define agxAssert(expr)
Definition debug.h:143
TrackNodeRange createRangeExcludingNodeIndex(const Track &track, agx::UInt nodeIndex, agx::Int signedNumNodes)
Creates a node range where nodeIndex is excluded and number of nodes to include is signed.
Definition TrackUtils.h:128
IndexRangeContainer splitNonconsecutive(const ContainerT &container)
Given a sorted container this function will split the content into ranges where the elements are cons...
Definition TrackUtils.h:42
void createGeometryBox(const TrackNode &node)
Definition TrackUtils.h:27
agx::UInt nextIndex(agx::UInt index, agx::UInt size)
Definition TrackUtils.h:116
agx::UInt prevIndex(agx::UInt index, agx::UInt size)
Definition TrackUtils.h:107
This namespace contains classes related to vehicles dynamics.
agx::IndexRangeT< agx::UInt > IndexRange
Definition TrackNode.h:35
agxSDK::LinkedSegmentRange< TrackNode > TrackNodeRange
Node range object for tracks.
uint64_t UInt
Definition Integer.h:27
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
int64_t Int
Definition Integer.h:28