AGX Dynamics  2.35.0.1
LookupTables.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 #ifndef AGX_LOOKUP_TABLES_H
18 #define AGX_LOOKUP_TABLES_H
19 
20 #include <agx/agxPhysics_export.h>
21 #include <agx/Referenced.h>
22 #include <agx/List.h>
23 #include <agxStream/Serializable.h>
25 
26 namespace agx
27 {
30 
31 
41  {
42  public:
47 
51  virtual void clear();
52 
58  virtual void insertValue( const agx::Real x, const agx::Real y );
59 
63  size_t getNumValues() const;
64 
65 
69  virtual agx::Real lookup( const agx::Real x ) const = 0;
70 
74  void setDefaultValue( agx::Real defaultValue );
75 
80 
84  virtual void setValues( RealPairVector const& values );
85 
91 
92 
93  RealPairList::const_iterator getValueIterator() const;
94  RealPairList::const_iterator getValueEndIterator() const;
95 
96  protected:
97  virtual ~LookupTable();
100  };
101 
102 
107  class AGXPHYSICS_EXPORT LinearLookupTable : virtual public LookupTable // virtual inheritance due to diamond
108  {
109  public:
114 
118  virtual agx::Real lookup( const agx::Real x ) const override;
119 
121  protected:
123  };
125 
126  class Point2D : public agx::Vec3
127  {
128  public:
129  Point2D() {}
131  {
132  x() = xxx;
133  y() = yyy;
134  z() = dy;
135  }
137  {
138  x() = point.x();
139  y() = point.y();
140  z() = point.z();
141  }
142  agx::Real yp() { return z(); }
143  };
145 
147  {
148  public:
150 
151  virtual void add(agx::Real x, agx::Real y, agx::Real dy);
152 
154 
156 
157  virtual void clear() { m_points.clear(); }
158 
159  virtual const Point2DVector& getPoints() { return m_points; }
160 
162 
163  private:
164  Point2DVector::iterator getIteratorAfter(const agx::Real x);
165  Point2DVector m_points;
166  };
168 
173  {
174  public:
176 
180  virtual agx::Real lookup(const agx::Real x) const override;
181 
182  virtual agx::Real lookupDerivative(const agx::Real x) const;
183 
184  virtual void insertValue(const agx::Real x, const agx::Real y) override;
185 
186  virtual void clear() override;
187 
188 
192  virtual bool store(agxStream::StorageStream& str) const;
193 
197  virtual bool restore(agxStream::StorageStream& str);
198 
200  protected:
203  };
205 
206 }
207 
208 #endif // AGX_LOOKUP_TABLES_H
#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
#define AGXPHYSICS_EXPORT
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:49
virtual void add(agx::Real x, agx::Real y, agx::Real dy)
virtual agx::Real evaluateDerivative(agx::Real x)
virtual const Point2DVector & getPoints()
Definition: LookupTables.h:159
virtual void clear()
Definition: LookupTables.h:157
virtual agx::Real evaluate(agx::Real x)
Base class for spline interpolation between the inserted variable/value pairs.
Definition: LookupTables.h:173
CubicFunction2DRef m_spline
Definition: LookupTables.h:202
virtual void insertValue(const agx::Real x, const agx::Real y) override
insert a value to the lookup table.
virtual void clear() override
clear all data
virtual agx::Real lookupDerivative(const agx::Real x) const
virtual agx::Real lookup(const agx::Real x) const override
Lookup a specific value.
virtual bool store(agxStream::StorageStream &str) const
Stores internal data into stream.
virtual bool restore(agxStream::StorageStream &str)
Restores internal data from stream.
Linear interpolation between the inserted variable/value pairs.
Definition: LookupTables.h:108
virtual ~LinearLookupTable()
virtual agx::Real lookup(const agx::Real x) const override
Lookup a specific value.
LinearLookupTable()
Constructor.
Return a value of y given any value of x.
Definition: LookupTables.h:41
virtual agx::Real lookup(const agx::Real x) const =0
Lookup a specific value.
LookupTable()
Create a lookup table.
void setDefaultValue(agx::Real defaultValue)
Set the default return value, if the table has been cleared.
agx::Real getDefaultValue() const
RealPairList m_xyPair
Definition: LookupTables.h:99
virtual agx::Real resultScalerFunction() const
Scale the found value.
RealPairList::const_iterator getValueIterator() const
virtual void clear()
clear all data
agx::Real m_defaultValue
Definition: LookupTables.h:98
RealPairList::const_iterator getValueEndIterator() const
virtual ~LookupTable()
virtual void insertValue(const agx::Real x, const agx::Real y)
insert a value to the lookup table.
size_t getNumValues() const
return the number of values in the lookup table
virtual void setValues(RealPairVector const &values)
Set all lookup values at the same time (all previous will be removed.)
Point2D(agx::Real xxx, agx::Real yyy, agx::Real dy)
Definition: LookupTables.h:130
agx::Real yp()
Definition: LookupTables.h:142
Point2D(agx::Vec3 point)
Definition: LookupTables.h:136
Base class providing referencing counted objects.
Definition: Referenced.h:114
Templated vector class.
Definition: agx/Vector.h:53
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
agx::List< std::pair< agx::Real, agx::Real > > RealPairList
Definition: LookupTables.h:28
agx::Vector< std::pair< agx::Real, agx::Real > > RealPairVector
Definition: LookupTables.h:29
agx::ref_ptr< LinearLookupTable > LinearLookupTableRef
Definition: LookupTables.h:124
agx::ref_ptr< CubicFunction2D > CubicFunction2DRef
Definition: LookupTables.h:167
agx::Vector< Point2D > Point2DVector
Definition: LookupTables.h:144
double Real
Definition: Real.h:42
agx::ref_ptr< CubicSplineLookupTable > CubicSplineLookupTableRef
Definition: LookupTables.h:204