AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
EntityData.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 AGXDATA_ENTITYDATA_H
18#define AGXDATA_ENTITYDATA_H
19
20#include <agx/Object.h>
21#include <agx/GlobalResult.h>
22#include <agxData/EntityPtr.h>
24#include <agxData/Array.h>
25#include <agxData/Buffer.h>
26
27namespace agx
28{
29 class TiXmlElement;
30 class EntityDataParameter;
31}
32
33
34namespace 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;
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:254
#define AGXCORE_EXPORT
Abstract representation of a value.
Definition: Value.h:49
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
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:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
#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:152
AGXTERRAIN_EXPORT TimingStorage & getStorage()
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:32
uint64_t UInt
Definition: Integer.h:27
AGXCORE_EXPORT Model * getModel(const Path &path, const Path &_namespace=Path())
UInt32 Index
Definition: Integer.h:44