AGX Dynamics  2.37.3.2
MergeSplitProperties.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 
25 
26 #include <agx/ICloneable.h>
27 #include <agx/BitState.h>
28 
29 
30 namespace agxSDK
31 {
32  class GeometryContactMergeSplitThresholds;
33  class ConstraintMergeSplitThresholds;
34  class WireMergeSplitThresholds;
35 
37 
39  {
40  public:
44  static agx::UInt findCallbackIndex( agxSDK::MergeSplitAlgorithm::Callback callback );
45 
46  public:
52 
57  void setEnableMergeSplit( agx::Bool enable );
58 
62  agx::Bool getEnableMergeSplit() const;
63 
68  void setEnableMerge( agx::Bool enable );
69 
73  agx::Bool getEnableMerge() const;
74 
79  void setEnableSplit( agx::Bool enable );
80 
84  agx::Bool getEnableSplit() const;
85 
96  void addGroup(const agx::Name& group);
97 
108  void addGroup(agx::UInt32 group);
109 
114  void removeGroup(const agx::Name& group);
115 
120  void removeGroup(agx::UInt32 group);
121 
125  const agx::UInt32Vector& getGroupIds() const;
126 
130  const agx::NameVector& getGroupNames() const;
131 
135  agxSDK::GeometryContactMergeSplitThresholds* getContactThresholds() const;
136 
140  agxSDK::GeometryContactMergeSplitThresholds* getOrCreateContactThresholds();
141 
145  void setContactThresholds( agxSDK::GeometryContactMergeSplitThresholds* contactThresholds );
146 
150  agxSDK::ConstraintMergeSplitThresholds* getConstraintThresholds() const;
151 
155  agxSDK::ConstraintMergeSplitThresholds* getOrCreateConstraintThresholds();
156 
160  void setConstraintThresholds( agxSDK::ConstraintMergeSplitThresholds* constraintThresholds );
161 
165  agxSDK::WireMergeSplitThresholds* getWireThresholds() const;
166 
170  agxSDK::WireMergeSplitThresholds* getOrCreateWireThresholds();
171 
175  void setWireThresholds( agxSDK::WireMergeSplitThresholds* wireThresholds );
176 
180  void setEnableSerialization( agx::Bool flag );
181 
185  agx::Bool getEnableSerialization() const;
186 
187  public:
189  virtual agx::ICloneableRef clone( agx::ICloneable* child = nullptr ) override;
190  void store( agxStream::OutputArchive& out ) const;
191  void restore( agxStream::InputArchive& in );
192  void storeLightData( agxStream::StorageStream& str ) const;
193  void restoreLightData( agxStream::StorageStream& str );
194 
195  template<typename T>
196  T* getMergeSplitThresholds( const agx::UInt index ) const;
198 
199  protected:
200  virtual ~MergeSplitProperties();
201 
202  private:
203  enum EState
204  {
205  MERGE_ENABLED = 1 << 0,
206  SPLIT_ENABLED = 1 << 1,
207  SERIALIZATION_ENABLED = 1 << 2
208  };
209 
210  private:
211  typedef agx::BitState< EState, agx::Int32 > State;
213 
214  private:
215  template<typename T>
216  T* getOrCreateMergeSplitThresholds( const agx::UInt index );
217 
218  template<typename T>
219  T* setMergeSplitThresholds( const agx::UInt index, agx::ref_ptr<T> thresholds );
220 
221  private:
222  State m_state;
223  ThresholdsContainer m_thresholds;
224  agxSDK::MergeIgnoreGroups m_mergeIgnoreGroups;
225  };
226 
228  {
229  return getEnableMerge() && getEnableSplit();
230  }
231 
233  {
234  return m_state.Is( MERGE_ENABLED );
235  }
236 
238  {
239  return m_state.Is( SPLIT_ENABLED );
240  }
241 
243  {
244  return getMergeSplitThresholds<GeometryContactMergeSplitThresholds>( MergeSplitProperties::findCallbackIndex( MergeSplitAlgorithm::CONTACTS ) );
245  }
246 
248  {
249  return getMergeSplitThresholds<ConstraintMergeSplitThresholds>( MergeSplitProperties::findCallbackIndex( MergeSplitAlgorithm::CONSTRAINTS ) );
250  }
251 
253  {
254  return getMergeSplitThresholds<WireMergeSplitThresholds>( MergeSplitProperties::findCallbackIndex( MergeSplitAlgorithm::WIRES ) );
255  }
256 
258  {
259  agxAssert( callback != MergeSplitAlgorithm::NONE );
260  return agx::pow2Exponent( callback );
261  }
262 
263  template<typename T>
264  inline T* MergeSplitProperties::getMergeSplitThresholds( const agx::UInt index ) const
265  {
266  agxAssert( index >= m_thresholds.size() || m_thresholds[ index ] == nullptr || m_thresholds[ index ]->is<T>() );
267 
268  return index < m_thresholds.size() ? (T*)m_thresholds[ index ].get() : nullptr;
269  }
270 
271  template<typename T>
272  T* MergeSplitProperties::getOrCreateMergeSplitThresholds( const agx::UInt index )
273  {
274  if ( index < m_thresholds.size() && m_thresholds[ index ] != nullptr ) {
275  agxAssert( m_thresholds[ index ]->is<T>() );
276  return (T*)m_thresholds[ index ].get();
277  }
278 
279  return setMergeSplitThresholds<T>( index, new T() );
280  }
281 
282  template<typename T>
283  T* MergeSplitProperties::setMergeSplitThresholds( const agx::UInt index, agx::ref_ptr<T> thresholds )
284  {
285  if ( index >= m_thresholds.size() )
286  m_thresholds.resize( index + 1 );
287 
288  return (T*)( m_thresholds[ index ] = thresholds ).get();
289  }
290 }
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
agx::UInt32 pow2Exponent(T value)
Finds and returns n given value = 2^n.
Definition: Math.h:611
Specific thresholds used to split and merge objects given constraints.
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
A collection of merge ignore groups, some named and some not.
agxSDK::GeometryContactMergeSplitThresholds * getContactThresholds() const
#define AGXPHYSICS_EXPORT
agxSDK::ConstraintMergeSplitThresholds * getConstraintThresholds() const
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Representation of a name string.
Definition: Name.h:32
#define AGX_FORCE_INLINE
Definition: Object.h:59
AGXPHYSICS_EXPORT void addGroup(const agx::RigidBody *body, unsigned id)
For the specified body, add the collision group ID to its geometries.
Templated vector class.
Definition: Vector.h:52
agxSDK::WireMergeSplitThresholds * getWireThresholds() const
uint32_t UInt
Definition: Integer.h:34
Specific thresholds used to merge and split given geometry contacts.
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
Specific thresholds used to split and merge objects given wires.
#define agxAssert(expr)
Definition: debug.h:143
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:48
AGXPHYSICS_EXPORT void removeGroup(const agx::RigidBody *body, unsigned id)
For the specified body, remove the collision group ID to its geometries.
static agx::UInt findCallbackIndex(agxSDK::MergeSplitAlgorithm::Callback callback)
Maps given callback to an index (0, 1, 2, ...).
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
Interface class for a cloneable reference counted object.
Definition: ICloneable.h:29
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97