AGX Dynamics  2.37.3.2
MergeSplitThresholds.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 <agx/ICloneable.h>
20 #include <agx/BitState.h>
21 #include <agx/agx_vector_types.h>
22 
23 #include <agxStream/Serializable.h>
24 
25 namespace agxSDK
26 {
28 
34  {
35  public:
39  using MixFunction = std::function<agx::Real( agx::Real, agx::Real )>;
40 
41  public:
45  void set( const agx::UInt index, agx::Real value );
46 
50  agx::Real get( const agx::UInt index ) const;
51 
55  agx::UInt getNumValues() const;
56 
60  agx::Bool isGlobal() const;
61 
66  agx::Real get( const agx::UInt index, const MergeSplitThresholds* other, MergeSplitThresholds::MixFunction mixFunc ) const;
67 
68  public:
72  virtual void resetToDefault() = 0;
73 
76 
80  virtual void store( agxStream::OutputArchive& out ) const override;
81 
85  virtual void restore( agxStream::InputArchive& in ) override;
86 
90  virtual void storeLightData( agxStream::StorageStream& str ) const override;
91 
95  virtual void restoreLightData( agxStream::StorageStream& str ) override;
97 
98  protected:
102  MergeSplitThresholds( const agx::UInt numValues );
103 
107  virtual ~MergeSplitThresholds();
108 
113  void cloneValuesTo( MergeSplitThresholds& target ) const;
114 
115  private:
116  friend class MergeSplitHandler;
117 
118  enum BitOptions
119  {
120  GLOBAL_THRESHOLDS = 1 << 0
121  };
122 
123  using Options = agx::BitState<BitOptions, agx::Int32>;
124 
125  Options& getOptions();
126  const Options& getOptions() const;
127 
128  private:
129  agx::RealVector m_values;
130  Options m_options;
131  };
132 
134  {
135  agxAssert( index < m_values.size() );
136  return m_values[ index ];
137  }
138 
140  {
141  return (agx::UInt)m_values.size();
142  }
143 
145  {
146  return m_options.Is( GLOBAL_THRESHOLDS );
147  }
148 
149  inline MergeSplitThresholds::Options& MergeSplitThresholds::getOptions()
150  {
151  return m_options;
152  }
153 
154  inline const MergeSplitThresholds::Options& MergeSplitThresholds::getOptions() const
155  {
156  return m_options;
157  }
158 
160  {
161  // Value from this if:
162  // 1. other is not given
163  // 2. this is identical to other
164  // 3. other is global - i.e., this may contain unique values which overrides global
165  return other == nullptr || this == other || other->isGlobal() ?
166  get( index ) :
167  // Value from other if:
168  // 1. other is given (implicit)
169  // 2. this is global
170  this->isGlobal() ?
171  other->get( index ) :
172  // Mix values if both are given and none is global.
173  mixFunc( get( index ), other->get( index ) );
174  }
175 }
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive...
bool Bool
Definition: Integer.h:48
Base class for a merge split algorithm handling a set of merged bodies.
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGX_FORCE_INLINE
Definition: Object.h:59
uint32_t UInt
Definition: Integer.h:34
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
agx::Real get(const agx::UInt index) const
#define agxAssert(expr)
Definition: debug.h:143
Base class for thresholds/constants/values used in agxSDK::MergeSplitAlgorithm.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Interface class for a cloneable reference counted object.
Definition: ICloneable.h:29
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
Definition: Serializable.h:221
double Real
Definition: Real.h:42
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
std::function< agx::Real(agx::Real, agx::Real)> MixFunction
Mixing two values function signature given two values and the return value is the mix...
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97