AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
MergeSplitProperties.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
25
26#include <agx/ICloneable.h>
27#include <agx/BitState.h>
28
29
30namespace 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
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
109
114 void removeGroup(const agx::Name& group);
115
121
126
131
135 agxSDK::GeometryContactMergeSplitThresholds* getContactThresholds() const;
136
141
146
150 agxSDK::ConstraintMergeSplitThresholds* getConstraintThresholds() const;
151
156
161
165 agxSDK::WireMergeSplitThresholds* getWireThresholds() const;
166
171
176
181
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:
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;
212 typedef agx::Vector<MergeSplitThresholdsRef> ThresholdsContainer;
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 {
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}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXPHYSICS_EXPORT
Specific thresholds used to split and merge objects given constraints.
Specific thresholds used to merge and split given geometry contacts.
A collection of merge ignore groups, some named and some not.
void setEnableSerialization(agx::Bool flag)
Enable/disable native serialization of this object.
void setEnableMerge(agx::Bool enable)
Enable/disable merge for this object.
const agx::NameVector & getGroupNames() const
void setContactThresholds(agxSDK::GeometryContactMergeSplitThresholds *contactThresholds)
Assign contact thresholds.
static agx::UInt findCallbackIndex(agxSDK::MergeSplitAlgorithm::Callback callback)
Maps given callback to an index (0, 1, 2, ...).
agxSDK::GeometryContactMergeSplitThresholds * getContactThresholds() const
agx::Bool getEnableSerialization() const
void removeGroup(const agx::Name &group)
Remove the given merge ignore group from this MergeSplitProperty.
MergeSplitProperties()
Default constructor, sets default values to all thresholds and merge + split disabled.
void setConstraintThresholds(agxSDK::ConstraintMergeSplitThresholds *constraintThresholds)
Assign constraint thresholds.
agxSDK::GeometryContactMergeSplitThresholds * getOrCreateContactThresholds()
agxSDK::WireMergeSplitThresholds * getWireThresholds() const
void addGroup(agx::UInt32 group)
Add all rigid bodies with this MergeSplitProperty to the given merge ignore group.
agxSDK::ConstraintMergeSplitThresholds * getOrCreateConstraintThresholds()
agxSDK::ConstraintMergeSplitThresholds * getConstraintThresholds() const
void setWireThresholds(agxSDK::WireMergeSplitThresholds *wireThresholds)
Assign wire thresholds.
void removeGroup(agx::UInt32 group)
Remove the given merge ignore group from this MergeSplitProperty.
agxSDK::WireMergeSplitThresholds * getOrCreateWireThresholds()
void addGroup(const agx::Name &group)
Add all rigid bodies with this MergeSplitProperty to the given merge ignore group.
const agx::UInt32Vector & getGroupIds() const
void setEnableSplit(agx::Bool enable)
Enable/disable split for this object.
void setEnableMergeSplit(agx::Bool enable)
Enable/disable both merge and split for the object.
Specific thresholds used to split and merge objects given wires.
size_t size() const
Definition: Container.h:134
Interface class for a cloneable reference counted object.
Definition: ICloneable.h:30
Representation of a name string.
Definition: Name.h:33
Templated vector class.
Definition: agx/Vector.h:53
void resize(size_t size)
Resize the vector, which then enables direct addressing using the bracket '[]' operator.
Definition: agx/Vector.h:540
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
#define agxAssert(expr)
Definition: debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:32
bool Bool
Definition: Integer.h:40
uint64_t UInt
Definition: Integer.h:27
agx::UInt32 pow2Exponent(T value)
Finds and returns n given value = 2^n.
Definition: Math.h:663