AGX Dynamics 2.41.2.0
Loading...
Searching...
No Matches
PropertyFilters.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#ifndef AGXSDK_PROPERTYFILTERS_H
18#define AGXSDK_PROPERTYFILTERS_H
19
21#include <agx/stdint.h>
22#include <agx/Referenced.h>
24#include <agxCollide/Contacts.h>
26
27
28namespace agx
29{
30 class PropertyContainer;
31}
32
33namespace agxSDK
34{
35
43 {
44 public:
45
50
55 virtual bool matches(const agx::PropertyContainer* c1, const agx::PropertyContainer* c2) const = 0;
56
58 virtual bool match(const agxCollide::Geometry* geo0, const agxCollide::Geometry* geo1) const override;
59 using ExecuteFilter::match;
60
61 protected:
62
64 virtual ~PropertyFilter();
65
66 std::string m_property_id[2];
67
68 bool m_is_set[2];
69 bool m_has_data[2];
70 };
71
73
74
75#define MATCH_IMPLEMENTATION( TYPENAME, TYPE ) \
76 int checkMatch( const agx::PropertyContainer* c, size_t numMatch) const \
77 { \
78 if (!c) \
79 return 0; \
80 size_t i=0; \
81 TYPE data; \
82 int match1=0; \
83 \
84 do { \
85 if ( m_is_set[i] && c && c->getProperty ## TYPENAME ( m_property_id[i], data )) \
86 { \
87 match1 = (m_property_data[i] == data) ? ( i ? 1 : -1) : 0; \
88 } \
89 i++; \
90 } while( !match1 && i < numMatch); \
91 return match1; \
92 } \
93 \
94 bool matches(const agx::PropertyContainer* c1, const agx::PropertyContainer* c2) const \
95 { \
96 size_t n1 = c1 ? c1->getNumberOfProperties ## TYPENAME () : 0; \
97 size_t n2 = c2 ? c2->getNumberOfProperties ## TYPENAME () : 0; \
98 \
99 size_t numRequiredMatches = (m_is_set[0] ? 1 : 0) + (m_is_set[1] ? 1 : 0); \
100 \
101 /* No properties what so ever, bail out*/ \
102 if (!n1 && !n2) \
103 return false; \
104 \
105 int match1 = 0, match2 = 0; \
106 match1 = checkMatch( c1, numRequiredMatches ); \
107 match2 = checkMatch( c2, numRequiredMatches ); \
108 \
109 bool result = (numRequiredMatches == 1 && (match1 || match2) ) || \
110 (numRequiredMatches == 2 && (match1 && match2) && (match1 != match2) ); \
111 \
112 return result; \
113 }
114
117 {
118 public:
119 LongPropertyFilter( const std::string& property_id, const int64_t& data );
120
121 LongPropertyFilter( const std::string& property_id0, const int64_t& data0,
122 const std::string& property_id1, const int64_t& data1);
123
124 MATCH_IMPLEMENTATION( Long, int64_t );
125
126 protected:
127
130
131 int64_t m_property_data[2];
132 };
133
134
137 {
138 public:
139 IntPropertyFilter( const std::string& property_id, const int32_t& data );
140
141 IntPropertyFilter( const std::string& property_id0, const int32_t& data0,
142 const std::string& property_id1, const int32_t& data1);
143
144 MATCH_IMPLEMENTATION( Int, int32_t );
145
146 protected:
147
150
151 int32_t m_property_data[2];
152 };
153
156 {
157 public:
158 FloatPropertyFilter( const std::string& property_id, const float& data );
159
160 FloatPropertyFilter( const std::string& property_id0, const float& data0,
161 const std::string& property_id1, const float& data1);
162
163 MATCH_IMPLEMENTATION( Float, float );
164
165 protected:
166
169
170
171 float m_property_data[2];
172 };
173
174
177 {
178 public:
179 DoublePropertyFilter( const std::string& property_id, const double& data );
180
181 DoublePropertyFilter( const std::string& property_id0, const double& data0,
182 const std::string& property_id1, const double& data1);
183
184 MATCH_IMPLEMENTATION( Double, double );
185
186 protected:
187
190
191 double m_property_data[2];
192 };
193
194
197 {
198 public:
199 BoolPropertyFilter( const std::string& property_id, const bool& data );
200
201 BoolPropertyFilter( const std::string& property_id0, const bool& data0,
202 const std::string& property_id1, const bool& data1);
203
204 MATCH_IMPLEMENTATION( Bool, bool );
205
206
207 protected:
208
211
212 bool m_property_data[2];
213 };
214
217 {
218 public:
219 StringPropertyFilter( const std::string& property_id, const std::string& data );
220
221 StringPropertyFilter( const std::string& property_id0, const std::string& data0,
222 const std::string& property_id1, const std::string& data1);
223
224 MATCH_IMPLEMENTATION( String, std::string );
225
226 protected:
227
230
231 std::string m_property_data[2];
232 };
233
234
235 inline bool PropertyFilter::match(const agxCollide::Geometry* geo0, const agxCollide::Geometry* geo1) const
236 {
237 const agx::PropertyContainer* c0 = geo0->hasPropertyContainer() ? geo0->getPropertyContainer() : nullptr;
238 const agx::PropertyContainer* c1 = geo1->hasPropertyContainer() ? geo1->getPropertyContainer() : nullptr;
239 return matches(c0, c1);
240 }
241
242} // namespace agxSDK
243
244#endif
245
246
#define AGXPHYSICS_EXPORT
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
agx::PropertyContainer * getPropertyContainer()
Definition: Geometry.h:901
bool hasPropertyContainer() const
Definition: Geometry.h:908
Class for matching bool properties.
virtual ~BoolPropertyFilter()
Destructor.
BoolPropertyFilter(const std::string &property_id0, const bool &data0, const std::string &property_id1, const bool &data1)
BoolPropertyFilter(const std::string &property_id, const bool &data)
MATCH_IMPLEMENTATION(Bool, bool)
Class for matching double properties.
DoublePropertyFilter(const std::string &property_id0, const double &data0, const std::string &property_id1, const double &data1)
virtual ~DoublePropertyFilter()
Destructor.
MATCH_IMPLEMENTATION(Double, double)
DoublePropertyFilter(const std::string &property_id, const double &data)
Abstract base class that implements a filter that selects which events should trigger a Listener.
Definition: ExecuteFilter.h:34
Class for matching float properties.
FloatPropertyFilter(const std::string &property_id0, const float &data0, const std::string &property_id1, const float &data1)
FloatPropertyFilter(const std::string &property_id, const float &data)
virtual ~FloatPropertyFilter()
Destructor.
MATCH_IMPLEMENTATION(Float, float)
Class for matching int properties.
MATCH_IMPLEMENTATION(Int, int32_t)
IntPropertyFilter(const std::string &property_id, const int32_t &data)
IntPropertyFilter(const std::string &property_id0, const int32_t &data0, const std::string &property_id1, const int32_t &data1)
virtual ~IntPropertyFilter()
Destructor.
Class for matching Long int properties.
MATCH_IMPLEMENTATION(Long, int64_t)
virtual ~LongPropertyFilter()
Destructor.
LongPropertyFilter(const std::string &property_id0, const int64_t &data0, const std::string &property_id1, const int64_t &data1)
LongPropertyFilter(const std::string &property_id, const int64_t &data)
A class for filtering contacts based on the geometries' properties (as in: their property container).
PropertyFilter()
This filter will select contacts that contain a string property of value p data.
virtual ~PropertyFilter()
Destructor.
virtual bool matches(const agx::PropertyContainer *c1, const agx::PropertyContainer *c2) const =0
Called when two PropertyContainers should be compared.
virtual bool match(const agxCollide::Geometry *geo0, const agxCollide::Geometry *geo1) const override
This is the function called to filter contacts.
Class for matching bool properties.
virtual ~StringPropertyFilter()
Destructor.
StringPropertyFilter(const std::string &property_id, const std::string &data)
StringPropertyFilter(const std::string &property_id0, const std::string &data0, const std::string &property_id1, const std::string &data1)
MATCH_IMPLEMENTATION(String, std::string)
Class that is a container of named properties.
Definition: Property.h:129
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
agx::ref_ptr< PropertyFilter > PropertyFilterRef
The agx namespace contains the dynamics/math part of the AGX Dynamics API.