AGXDynamics  2.35.0.3
MergeSplitProperties.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 
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 }
agx::Vector::resize
void resize(size_t size)
Resize the vector, which then enables direct addressing using the bracket '[]' operator.
Definition: Vector.h:540
agxSDK::MergeSplitProperties::getWireThresholds
agxSDK::WireMergeSplitThresholds * getWireThresholds() const
Definition: MergeSplitProperties.h:252
agxSDK::MergeSplitAlgorithm::CONSTRAINTS
@ CONSTRAINTS
Definition: MergeSplitAlgorithm.h:39
agxSDK::MergeSplitProperties
Definition: MergeSplitProperties.h:38
agx::Vector
Templated vector class.
Definition: Vector.h:52
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
agxSDK::MergeIgnoreGroups
A collection of merge ignore groups, some named and some not.
Definition: MergeIgnoreGroups.h:39
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
agxSDK::GeometryContactMergeSplitThresholds
Specific thresholds used to merge and split given geometry contacts.
Definition: GeometryContactMergeSplitThresholds.h:28
agxSDK::MergeSplitProperties::getEnableMerge
agx::Bool getEnableMerge() const
Definition: MergeSplitProperties.h:232
agxSDK::MergeSplitProperties::findCallbackIndex
static agx::UInt findCallbackIndex(agxSDK::MergeSplitAlgorithm::Callback callback)
Maps given callback to an index (0, 1, 2, ...).
Definition: MergeSplitProperties.h:257
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agx::pow2Exponent
agx::UInt32 pow2Exponent(T value)
Finds and returns n given value = 2^n.
Definition: Math.h:611
agxAssert
#define agxAssert(expr)
Definition: debug.h:143
agxStream::StorageStream
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:48
agxUtil::addGroup
AGXPHYSICS_EXPORT void addGroup(const agx::RigidBody *body, unsigned id)
For the specified body, add the collision group ID to its geometries.
agx::ICloneable
Interface class for a cloneable reference counted object.
Definition: ICloneable.h:29
agxSDK::MergeSplitAlgorithm::NONE
@ NONE
Definition: MergeSplitAlgorithm.h:37
agx::VectorPOD< UInt32 >
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
agx::ref_ptr
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
ICloneable.h
ConstraintMergeSplitThresholds.h
agx::Name
Representation of a name string.
Definition: Name.h:32
agxStream::OutputArchive
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
agxSDK::MergeSplitProperties::getEnableSplit
agx::Bool getEnableSplit() const
Definition: MergeSplitProperties.h:237
agxSDK::ConstraintMergeSplitThresholds
Specific thresholds used to split and merge objects given constraints.
Definition: ConstraintMergeSplitThresholds.h:28
agxSDK::MergeSplitAlgorithm::Callback
Callback
Definition: MergeSplitAlgorithm.h:35
agxStream::InputArchive
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
agx::GraphNode::State
State
Definition: GraphNode.h:39
WireMergeSplitThresholds.h
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agxUtil::removeGroup
AGXPHYSICS_EXPORT void removeGroup(const agx::RigidBody *body, unsigned id)
For the specified body, remove the collision group ID to its geometries.
agxSDK::MergeSplitAlgorithm::CONTACTS
@ CONTACTS
Definition: MergeSplitAlgorithm.h:38
agx::UInt
uint32_t UInt
Definition: Integer.h:34
agx::Bool
bool Bool
Definition: Integer.h:48
MergeIgnoreFilter.h
agxSDK::MergeSplitProperties::getConstraintThresholds
agxSDK::ConstraintMergeSplitThresholds * getConstraintThresholds() const
Definition: MergeSplitProperties.h:247
agxSDK::MergeSplitProperties::getEnableMergeSplit
agx::Bool getEnableMergeSplit() const
Definition: MergeSplitProperties.h:227
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
MergeSplitAlgorithm.h
agxSDK::MergeSplitProperties::getContactThresholds
agxSDK::GeometryContactMergeSplitThresholds * getContactThresholds() const
Definition: MergeSplitProperties.h:242
GeometryContactMergeSplitThresholds.h
agxSDK::WireMergeSplitThresholds
Specific thresholds used to split and merge objects given wires.
Definition: WireMergeSplitThresholds.h:28
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40
agxSDK::MergeSplitAlgorithm::WIRES
@ WIRES
Definition: MergeSplitAlgorithm.h:40
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
MergeIgnoreGroups.h