AGX Dynamics  2.37.2.0
PropertyFilters.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 #ifndef AGXSDK_PROPERTYFILTERS_H
18 #define AGXSDK_PROPERTYFILTERS_H
19 
20 #include <agx/agxPhysics_export.h>
21 #include <agx/stdint.h>
22 #include <agx/Referenced.h>
24 #include <agxCollide/Contacts.h>
25 #include <agxSDK/ExecuteFilter.h>
26 
27 
28 namespace agx
29 {
30  class PropertyContainer;
31 }
32 
33 namespace agxSDK
34 {
35 
43  {
44  public:
45 
49  PropertyFilter( );
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 
129  virtual ~LongPropertyFilter();
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 
149  virtual ~IntPropertyFilter();
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 
168  virtual ~FloatPropertyFilter();
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 
189  virtual ~DoublePropertyFilter();
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 
210  virtual ~BoolPropertyFilter();
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 
229  virtual ~StringPropertyFilter();
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 
bool Bool
Definition: Integer.h:48
Abstract base class that implements a filter that selects which events should trigger a Listener...
Definition: ExecuteFilter.h:33
Class for matching bool properties.
Class for matching float properties.
#define AGXPHYSICS_EXPORT
AgXString< std::string > String
Definition: String.h:427
int32_t Int
Definition: Integer.h:35
bool hasPropertyContainer() const
Definition: Geometry.h:998
Class for matching bool properties.
#define MATCH_IMPLEMENTATION(TYPENAME, TYPE)
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Class that is a container of named properties.
Definition: Property.h:158
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
Class for matching Long int properties.
agx::ref_ptr< PropertyFilter > PropertyFilterRef
Class for matching double properties.
agx::PropertyContainer * getPropertyContainer()
Definition: Geometry.h:991
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
A class for filtering contacts based on the geometries&#39; properties (as in: their property container)...
Class for matching int properties.