HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_AgentDefinition.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GU_AgentDefinition.h (GU Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_AgentDefinition__
12 #define __GU_AgentDefinition__
13 
14 #include "GU_API.h"
15 #include "GU_AgentClip.h"
16 #include "GU_AgentCustomDataItem.h"
17 #include "GU_AgentLayer.h"
18 #include "GU_AgentMetadata.h"
19 #include "GU_AgentRig.h"
20 #include "GU_AgentShapeLib.h"
21 #include "GU_AgentTransformGroup.h"
22 
23 #include <UT/UT_Array.h>
24 #include <UT/UT_Function.h>
25 #include <UT/UT_IntrusivePtr.h>
26 #include <UT/UT_StringMap.h>
27 
28 
32 
33 /// An agent definition contains a rig, a shape library, a set of available
34 /// clips, a set of available layers, and a set of transform groups.
36  : public UT_IntrusiveRefCounter<GU_AgentDefinition>
37 {
38 public:
40 
42  const GU_AgentShapeLibConstPtr &shapelib);
43 
44  /// Create a copy of the given agent definition, but referencing a new
45  /// version of the shape library and/or rig.
46  GU_AgentDefinition(const GU_AgentDefinition &src_defn,
47  const GU_AgentShapeLibConstPtr &new_shapelib,
48  const GU_AgentRigConstPtr &new_rig = nullptr);
49 
50  int64 getMemoryUsage(bool inclusive) const;
51 
52  /// Loads the agent definition from JSON. Used when loading agent
53  /// primitives from a geometry file.
54  bool load(UT_JSONParser &p);
55 
56  /// Saves the agent definition to JSON. Used when saving agent primitives
57  /// to a geometry file.
58  bool save(UT_JSONWriter &w) const;
59 
60  const GU_AgentRigConstPtr &rig() const { return myRig; }
61  const GU_AgentShapeLibConstPtr &shapeLibrary() const { return myShapeLib; }
62 
63  /// Add a layer to the agent definition. Replaces any pre-existing layer of
64  /// the same name.
65  void addLayer(const GU_AgentLayerConstPtr &layer);
66 
67  /// Remove a layer from the agent definition by name.
68  void removeLayer(const UT_StringRef &name);
69 
70  /// Return the list of layers.
71  const UT_Array<GU_AgentLayerConstPtr> &layers() const { return myLayers; }
72 
73  /// Get a pointer to a specfic layer. This may be a NULL pointer.
74  const GU_AgentLayer *layer(const UT_StringRef &name) const;
75 
76  /// Get the index of a layer, or -1 if it does not exist.
78  { return myLayersIndex.get(name, -1); }
79 
80  /// Get a reference to the ith layer.
81  const GU_AgentLayer &layer(exint i) const { return *myLayers(i); }
82 
83  /// Return the layer count.
84  exint numLayers() const { return myLayers.size(); }
85 
86  /// Sorts the layers by name, if any layers have been added or removed since
87  /// the last sort.
88  void sortLayersIfNeeded();
89 
90  /// Add a clip to the agent definition. Replaces any pre-existing clip of
91  /// the same name.
92  void addClip(const GU_AgentClipConstPtr &clip);
93 
94  /// Remove a clip from the agent definition by name.
95  void removeClip(const UT_StringRef &name);
96 
97  /// Return the list of clips.
98  const UT_Array<GU_AgentClipConstPtr> &clips() const { return myClips; }
99 
100  /// Get a pointer to a specfic clip. This may be a NULL pointer.
101  const GU_AgentClip *clip(const UT_StringRef &name) const;
102 
103  /// Get the index of a clip, or -1 if it does not exist.
105  { return myClipsIndex.get(name, -1); }
106 
107  /// Get a reference to the ith clip.
108  const GU_AgentClip &clip(exint i) const { return *myClips(i); }
109 
110  /// Return the clip count.
111  exint numClips() const { return myClips.size(); }
112 
113  /// Sorts the clips by name, if any clips have been added or removed since
114  /// the last sort.
115  void sortClipsIfNeeded();
116 
117  /// Add a transform group to the agent definition. Replaces any
118  /// pre-existing group of the same name.
119  void addTransformGroup(const GU_AgentTransformGroupConstPtr &group);
120 
121  /// Remove a transform group from the agent definition by name.
122  void removeTransformGroup(const UT_StringRef &name);
123 
124  /// Return the list of groups.
126  { return myTransformGroups; }
127 
128  /// Get a pointer to a specfic group. This may be a NULL pointer.
129  const GU_AgentTransformGroup *transformGroup(const UT_StringRef &name) const;
130 
131  /// Get the index of a transform group, or -1 if it does not exist.
133  { return myTransformGroupsIndex.get(name, -1); }
134 
135  /// Get the default transform group, which contains all transforms in the
136  /// rig.
138  { return *myDefaultTransformGroup; }
139 
140  /// Get a reference to the ith group.
142  { return *myTransformGroups(i); }
143 
144  /// Return the transform group count.
145  exint numTransformGroups() const { return myTransformGroups.size(); }
146 
147  /// Sorts the transform groups by name, if any groups have been added or
148  /// removed since the last sort.
149  void sortTransformGroupsIfNeeded();
150 
151  /// Return the metadata dictionary. This may be a nullptr.
152  const GU_AgentMetadataConstPtr &metadata() const { return myMetadata; }
153 
154  /// Replace the metadata dictionary.
156  { myMetadata = data; }
157 
158  /// Add a custom data item to the agent definition. Replaces any
159  /// pre-existing item of the same name.
160  void addCustomDataItem(const GU_AgentCustomDataItemConstPtr &data);
161 
162  /// Remove a custom data item from the agent definition by name.
163  void removeCustomDataItem(const UT_StringRef &name);
164 
165  /// Return the list of custom data items.
167  { return myCustomDataItems; }
168 
169  /// Get a pointer to a specfic data item by name. This may be a NULL
170  /// pointer.
171  const GU_AgentCustomDataItem *customDataItem(const UT_StringRef &name) const;
172 
173  /// Get a reference to the ith custom data item.
175  { return *myCustomDataItems[i]; }
176 
177  /// Return the number of custom data items.
178  exint numCustomDataItems() const { return myCustomDataItems.size(); }
179 
180  /// Sorts the custom data items by name, if any items have been added or
181  /// removed since the last sort.
182  void sortCustomDataItemsIfNeeded();
183 
184  /// Constructs a new instance of a GU_AgentCustomDataItem. The provided
185  /// agent definition can be used if the data item requires references to
186  /// the rig, shape library, etc.
187  using CustomDataItemConstructor =
189 
190  /// Register a new custom data item type.
191  static void registerCustomDataItemType(
192  const UT_StringHolder &dataitemtype,
193  CustomDataItemConstructor constructor);
194 
195  /// Called by GU_Agent during startup to register custom data item types.
196  static void installCustomDataItemTypes();
197 
198  /// Sorts the clips, layers, transform groups, and custom data items by
199  /// name, if any items have been added or removed since the last sort.
200  /// This is equivalent to individually calling sortClipsIfNeeded() and
201  /// similar methods.
202  void sortItemsIfNeeded();
203 
204 private:
205  /// Constructs the default transform group that contains all of the joints.
206  void addDefaultTransformGroup();
207 
208 private:
209  GU_AgentRigConstPtr myRig;
210  GU_AgentShapeLibConstPtr myShapeLib;
211 
213  UT_StringMap<exint> myLayersIndex;
214 
216  UT_StringMap<exint> myClipsIndex;
217 
219  UT_StringMap<exint> myTransformGroupsIndex;
220  GU_AgentTransformGroupConstPtr myDefaultTransformGroup;
221 
222  GU_AgentMetadataConstPtr myMetadata;
223 
225  UT_StringMap<exint> myCustomDataItemsIndex;
226 
227  bool myAreLayersSorted;
228  bool myAreClipsSorted;
229  bool myAreTransformGroupsSorted;
230  bool myAreCustomDataItemsSorted;
231 };
232 
233 inline const GU_AgentLayer *
235 {
236  const exint idx = layerIndex(name);
237  return (idx >= 0) ? myLayers[idx].get() : nullptr;
238 }
239 
240 inline const GU_AgentClip *
242 {
243  const exint idx = clipIndex(name);
244  return (idx >= 0) ? myClips[idx].get() : nullptr;
245 }
246 
247 inline const GU_AgentTransformGroup *
249 {
250  const exint idx = transformGroupIndex(name);
251  return (idx >= 0) ? myTransformGroups[idx].get() : nullptr;
252 }
253 
254 inline const GU_AgentCustomDataItem *
256 {
257  const exint idx = myCustomDataItemsIndex.get(name, -1);
258  return (idx >= 0) ? myCustomDataItems[idx].get() : nullptr;
259 }
260 
261 extern "C" {
262  /// Entry point for registering custom data item types.
264 };
265 
266 #endif
const GU_AgentLayer * layer(const UT_StringRef &name) const
Get a pointer to a specfic layer. This may be a NULL pointer.
exint transformGroupIndex(const UT_StringRef &name) const
Get the index of a transform group, or -1 if it does not exist.
UT_Function< GU_AgentCustomDataItemPtr(const GU_AgentDefinition &)> CustomDataItemConstructor
const GU_AgentMetadataConstPtr & metadata() const
Return the metadata dictionary. This may be a nullptr.
exint numTransformGroups() const
Return the transform group count.
const GU_AgentTransformGroup & defaultTransformGroup() const
#define SYS_VISIBILITY_EXPORT
GLboolean * data
Definition: glcorearb.h:131
const UT_Array< GU_AgentClipConstPtr > & clips() const
Return the list of clips.
const UT_Array< GU_AgentLayerConstPtr > & layers() const
Return the list of layers.
int64 exint
Definition: SYS_Types.h:125
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
A reference counter base class for use with UT_IntrusivePtr.
const GU_AgentShapeLibConstPtr & shapeLibrary() const
UT_IntrusivePtr< GU_AgentDefinition > GU_AgentDefinitionPtr
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
exint numLayers() const
Return the layer count.
const GU_AgentRigConstPtr & rig() const
const GU_AgentLayer & layer(exint i) const
Get a reference to the ith layer.
const GU_AgentTransformGroup & transformGroup(exint i) const
Get a reference to the ith group.
SYS_VISIBILITY_EXPORT void GUregisterAgentCustomDataItemType()
Entry point for registering custom data item types.
exint numClips() const
Return the clip count.
const GU_AgentCustomDataItem * customDataItem(const UT_StringRef &name) const
const GU_AgentCustomDataItem & customDataItem(exint i) const
Get a reference to the ith custom data item.
void setMetadata(const GU_AgentMetadataConstPtr &data)
Replace the metadata dictionary.
long long int64
Definition: SYS_Types.h:116
const GU_AgentClip & clip(exint i) const
Get a reference to the ith clip.
#define GU_API
Definition: GU_API.h:14
const GU_AgentClip * clip(const UT_StringRef &name) const
Get a pointer to a specfic clip. This may be a NULL pointer.
GLuint const GLchar * name
Definition: glcorearb.h:786
std::function< T > UT_Function
Definition: UT_Function.h:37
const GU_AgentTransformGroup * transformGroup(const UT_StringRef &name) const
Get a pointer to a specfic group. This may be a NULL pointer.
const UT_Array< GU_AgentTransformGroupConstPtr > & transformGroups() const
Return the list of groups.
SYS_FORCE_INLINE ITEM_T get(const UT_StringRef &key, const ITEM_T &defval) const
Definition: UT_StringMap.h:64
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
const UT_Array< GU_AgentCustomDataItemConstPtr > & customDataItems() const
Return the list of custom data items.
exint layerIndex(const UT_StringRef &name) const
Get the index of a layer, or -1 if it does not exist.
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T clip(const T &p, const Box< T > &box) IMATH_NOEXCEPT
Definition: ImathBoxAlgo.h:29
exint clipIndex(const UT_StringRef &name) const
Get the index of a clip, or -1 if it does not exist.
exint numCustomDataItems() const
Return the number of custom data items.
Definition: format.h:895
UT_IntrusivePtr< const GU_AgentDefinition > GU_AgentDefinitionConstPtr