AGX Dynamics  2.37.3.2
EntityData.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 AGXDATA_ENTITYDATA_H
18 #define AGXDATA_ENTITYDATA_H
19 
20 #include <agx/Object.h>
21 #include <agx/GlobalResult.h>
22 #include <agxData/EntityPtr.h>
23 #include <agxData/EntityInstance.h>
24 #include <agxData/Array.h>
25 #include <agxData/Buffer.h>
26 
27 namespace agx
28 {
29  class TiXmlElement;
30  class EntityDataParameter;
31 }
32 
33 
34 namespace agxData
35 {
36  class EntityModel;
37 
39 
40  AGX_DECLARE_POINTER_TYPES(EntityData);
41 
45  class AGXCORE_EXPORT EntityData : public agx::Object
46  {
47  public:
48  static agx::Model *ClassModel();
49 
50  public:
51 
55  agx::UInt numElements();
56 
61 
66 
70  agx::GlobalResult *getGlobalResult();
71 
76  agx::Index getGlobalOrder(size_t index);
77 
78 
82  size_t idToIndex(size_t id) const;
83 
87  size_t indexToId(size_t index) const;
88 
92  void sync();
93 
94 
95  // Global result convenience wrapper
96  agx::GlobalResult::Transaction allocateResult(size_t numElements);
97 
98 
99  // Access to the instance attribute
100  Array< EntityPtr > instance;
101 
102 
103 
104  // Create a new instance
105  agx::Index createInstance();
106  agx::Index createInstances(agx::Index numInstances);
107  void presize(agx::Index size);
108 
109  // Set the batch size for creating instances
110  void setInstanceBatchSize(agx::Index size);
111 
112  // Commit the created instances, automatically done when a task/kernel completes
113  void commitInstanceBatch();
114 
115  protected:
116  friend class EntityStorage;
117  friend class EntityModel;
118  friend class agx::EntityDataParameter;
119  friend class agx::GlobalResultStorage;
120 
121  EntityData(EntityStorage *storage);
122  EntityData();
123  virtual ~EntityData();
124 
125  void setGlobalResult(agx::GlobalResult *globalResult);
126  void setGlobalOrderBuffer(Buffer *buffer);
127 
128  void bind(const Attribute *attribute, Buffer *buffer);
129  void bind(const SharedAttribute *, agxData::Value *value);
130  void realloactionCallback(Buffer *buffer);
131  void registerArray(const Attribute *attribute, AbstractArray *array);
132  void unregisterArray(const Attribute *attribute);
133 
134  virtual void setNumElements(agx::UInt32 numElements);
135  virtual void synchronizeSharedAttribute(agxData::Value *) {};
136 
137  private:
138  agx::UInt m_numElements;
139  EntityStorage *m_storage;
140  agx::GlobalResult *m_globalResult;
141  agx::Vector<AbstractArray *> m_bindings;
142  agxData::Value::Event::CallbackType m_sharedAttributeUpdateCallback;
143  Buffer::Event::CallbackType m_bufferReallocationCallback;
144  IndexArray m_globalOrder;
145  agx::Index m_instanceBatchSize;
146  bool m_hasBatchInstances;
147  };
148 
150 
151 
152  typedef agxData::EntityData *EntityDataPtr;
153 
154 
155  /* Implementation */
157 
158  AGX_FORCE_INLINE agx::UInt EntityData::numElements() { return m_numElements; }
159  AGX_FORCE_INLINE EntityStorage *EntityData::getStorage() { return m_storage; }
160  AGX_FORCE_INLINE agx::GlobalResult *EntityData::getGlobalResult() { return m_globalResult; }
161  AGX_FORCE_INLINE void EntityData::setGlobalResult(agx::GlobalResult *globalResult) { m_globalResult = globalResult; }
162  AGX_FORCE_INLINE agx::GlobalResult::Transaction EntityData::allocateResult(size_t numElements)
163  {
164  agxVerifyN(m_globalResult, "%s: No global result is active", getPath().c_str());
165  return m_globalResult->allocateResult(numElements);
166  }
167 
168  AGX_FORCE_INLINE agx::Index EntityData::getGlobalOrder(size_t index)
169  {
170  agxAssertN(m_globalOrder.buffer(), "%s: Data set does not have a global ordering buffer", getPath().c_str());
171  return m_globalOrder[index];
172  }
174 
175  // indexToId, idToIndex, and createInstance implemented in EntityStorage.h due to include loop
176 }
177 
178 
179 #endif /* AGXDATA_ENTITYDATA_H */
#define agxVerifyN(expr, format,...)
Definition: debug.h:133
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:40
Abstract representation of a value.
Definition: Value.h:48
#define agxAssertN(expr, format,...)
Definition: debug.h:145
AGXCORE_EXPORT Model * getModel(const Path &path, const Path &_namespace=Path())
Definition: Object.h:363
Transactions are used to reserve exclusive memory areas in which the threads can write their data...
Definition: GlobalResult.h:72
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGX_FORCE_INLINE
Definition: Object.h:59
Arrays are fast accessors into the data, or a portion of it, held by a Buffer.
Definition: Array.h:36
Type-specific Array used for fast access into the data held by a Buffer.
Definition: agxData.h:30
Templated vector class.
Definition: Vector.h:52
const char * c_str() const
uint32_t UInt
Definition: Integer.h:34
GlobalResult is used by kernels to generate result data from different threads.
Definition: GlobalResult.h:51
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Templated callback with one argument.
Definition: Callback.h:100
An abstract attribute description, part of an Entity.
Definition: Attribute.h:57
Abstract representation of a data buffer.
Definition: Buffer.h:55
Contains classes for low level data storage for AGX.
Definition: Container.h:23
UInt32 Index
Definition: Integer.h:52
An abstract description of a data entity stored using SOA (structure of arrays) pattern in a EntitySt...
Definition: EntityModel.h:63
Entity parameter.
Definition: Parameter.h:482
AGXTERRAIN_EXPORT TimingStorage & getStorage()
A shared attribute.
Definition: Attribute.h:174
agxData::EntityData * EntityDataPtr
Definition: EntityData.h:36
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define AGXCORE_EXPORT
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
agx::Path getPath() const