AGX Dynamics  2.37.2.0
TrajectoryCalculator.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
9 having been advised so by Algoryx Simulation AB for a time limited evaluation,
10 or having purchased a 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 AGXTERRAIN_TRAJECTORYCALCULATOR_H
18 #define AGXTERRAIN_TRAJECTORYCALCULATOR_H
19 
20 #include <queue>
21 #include <numeric>
22 
23 #include <agxTerrain/export.h>
24 
25 #include <agx/agx_vector_types.h>
26 #include <agxData/agxData.h>
27 
28 #include <agxCollide/HeightField.h>
29 #include <agxCollide/Geometry.h>
30 #include <agxCollide/Line.h>
31 #include <agxCollide/Contacts.h>
33 
34 namespace agxTerrain
35 {
37  {
44  };
45 
47  {
48  public:
51 
52  void setTrajectorySettings(const TrajectorySettings& settings);
53  void setHeightField(agxCollide::HeightField* heightField);
54  void setCutDepth(agx::Real cutDepth);
55  void setCutAngle(agx::Real cutAngle);
56  void setBladeSpeed(agx::Real bladeSpeed);
57  void setGoalHeight(agx::Real goalHeight);
58  void setResolution(agx::Real resolution);
59  void setTimestep(agx::Real timestep);
60 
61  TrajectorySettings getTrajectorySettings() const;
62  agx::Real getCutDepth() const;
63  agx::Real getCutAngle() const;
64  agx::Real getBladeSpeed() const;
65  agx::Real getGoalHeight() const;
66  agx::Real getResolution() const;
67  agx::Real getTimestep() const;
68 
69  agx::Bool hasHeightField() const;
70  agx::Bool isValid() const;
71 
72  void createTrajectory(const agx::Vec2& startPoint, const agx::Vec2& endPoint);
73  agx::Vec3Vector getTrajectory();
74  agx::Vec3 getInitialPosition();
75  agx::Vec3 getVelocity();
76  void discardTrajectory();
77 
78  // Debug rendering methods
79  void DEBUG_drawHeightCurve();
80  void DEBUG_drawTrajectory();
81  void DEBUG_drawVelocities();
82 
83  private:
84  agx::RealVector applyFilters(const agx::RealVector& heightCurve);
85  void computeHeightCurve(const agx::Vec2& startPoint, const agx::Vec2& endPoint);
86  void computeTrajectory(const agx::RealVector& heightCurve);
87  void computeVelocities();
88 
89  agx::RealVector movingAverageStddev(const agx::RealVector& data, const size_t range);
90  agx::RealVector movingAverageFilter(const agx::RealVector& data, const size_t range);
91  agx::RealVector movingAverageFilterLowSlope(const agx::RealVector& data, size_t range, const agx::Real threshold);
92  agx::Real interpolate(agx::Real x, const agx::RealVector& xDiscrete, const agx::RealVector& yDiscrete);
93  agx::RealVector computeArcLength(const agx::RealVector& x, const agx::RealVector& y);
94  agx::Real computeInverseArcLength(agx::Real distance, const agx::RealVector& x, const agx::RealVector& arcLength);
95 
96  // Heightfield and resulting 2D heightcurve
97  agxCollide::HeightFieldRef m_heightField;
98  agx::RealVector m_heightCurve;
99  agx::RealVector m_x;
100 
101  // Settings
102  TrajectorySettings m_settings;
103 
104  // Start and endpoint in xy-plane along with rotation matrix for velocities
105  agx::Vec2 m_startPoint;
106  agx::Vec2 m_endPoint;
107  agx::Matrix4x4 m_rotateMatrix;
108 
109  // Resulting trajectory and velocities
110  agx::RealVector m_trajectory;
111  std::queue<agx::Vec3> m_velocities;
112 
113  // Boolean for valid trajectory
114  agx::Bool m_validTrajectory;
115  };
116 }
117 
118 #endif
bool Bool
Definition: Integer.h:48
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes...
Definition: Geometry.h:59
Matrix class for affine transformations.
Definition: EulerAngles.h:34
#define AGXTERRAIN_EXPORT
double Real
Definition: Real.h:42
A HeightField is a collision shape that can be created from a grid structure, like an image...