AGXDynamics  2.35.0.3
MergeSplitThresholds.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 #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 }
agx::Real
double Real
Definition: Real.h:42
agxStream::out
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.
Definition: OutputArchive.h:412
BitState.h
agx::Container::size
size_t size() const
Definition: Container.h:134
agxStream::Serializable
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agxAssert
#define agxAssert(expr)
Definition: debug.h:143
AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE
#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
agx::ICloneable
Interface class for a cloneable reference counted object.
Definition: ICloneable.h:29
agx::VectorPOD< Real >
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agxStream::in
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
agxSDK::MergeSplitHandler
Base class for a merge split algorithm handling a set of merged bodies.
Definition: MergeSplitHandler.h:34
agxSDK::MergeSplitThresholds
Base class for thresholds/constants/values used in agxSDK::MergeSplitAlgorithm.
Definition: MergeSplitThresholds.h:33
ICloneable.h
agxSDK::MergeSplitThresholds::getNumValues
agx::UInt getNumValues() const
Definition: MergeSplitThresholds.h:139
Serializable.h
agxSDK::MergeSplitThresholds::get
agx::Real get(const agx::UInt index) const
Definition: MergeSplitThresholds.h:133
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agx::UInt
uint32_t UInt
Definition: Integer.h:34
agx::Bool
bool Bool
Definition: Integer.h:48
agxStream
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
Definition: ElementaryConstraint.h:31
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agxSDK::MergeSplitThresholds::isGlobal
agx::Bool isGlobal() const
Definition: MergeSplitThresholds.h:144
agx_vector_types.h
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agxSDK::MergeSplitThresholds::MixFunction
std::function< agx::Real(agx::Real, agx::Real)> MixFunction
Mixing two values function signature given two values and the return value is the mix.
Definition: MergeSplitThresholds.h:39