AGX Dynamics  2.35.0.1
EntityData.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 #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 
60  EntityStorage *getStorage();
61 
65  EntityModel *getModel();
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 AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXCORE_EXPORT
Abstract representation of a value.
Definition: Value.h:43
Entity parameter.
Definition: Parameter.h:483
T CallbackType
Definition: Event.h:37
Transactions are used to reserve exclusive memory areas in which the threads can write their data.
Definition: GlobalResult.h:73
GlobalResult is used by kernels to generate result data from different threads.
Definition: GlobalResult.h:52
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:41
agx::Path getPath() const
Templated vector class.
Definition: agx/Vector.h:53
#define agxAssertN(expr, format,...)
Definition: debug.h:145
#define agxVerifyN(expr, format,...)
Definition: debug.h:133
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
#define AGX_FORCE_INLINE
Definition: macros.h:58
Contains classes for low level data storage for AGX.
Definition: Container.h:23
Array< agx::Index > IndexArray
Definition: agxData.h:50
agxData::EntityData * EntityDataPtr
Definition: EntityData.h:36
AGXTERRAIN_EXPORT TimingStorage & getStorage()
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:40
uint32_t UInt
Definition: Integer.h:34
AGXCORE_EXPORT Model * getModel(const Path &path, const Path &_namespace=Path())
Definition: Object.h:364
UInt32 Index
Definition: Integer.h:52