HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GDT_TokenList.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: GDT Library. (Geo Delta)
7  *
8  * COMMENTS: GDT_TokenList is an abstract class for a list of attribute
9  * tokens.
10  *
11  */
12 
13 #ifndef __GDT_TokenList_h__
14 #define __GDT_TokenList_h__
15 
16 #include "GDT_API.h"
17 #include <UT/UT_ValArray.h>
18 #include <UT/UT_IntArray.h>
19 #include <UT/UT_Array.h>
20 #include <GA/GA_Types.h>
21 
22 class GA_AttributeDict;
23 class GA_AttributeFilter;
24 class GA_Attribute;
25 class GA_Defaults;
26 class GA_Range;
27 class GA_AIFEditDeltaMap;
28 class GDT_Attribute;
29 class GDT_JSON;
30 class GEO_Detail;
31 class UT_String;
32 class UT_IStream;
33 class UT_Options;
34 class UT_JSONWriter;
35 class UT_JSONParser;
36 
38 {
39 public:
40 
41  GDT_TokenList();
42  GDT_TokenList(const GDT_TokenList &other);
43  virtual ~GDT_TokenList() = 0;
44 
45  virtual int64 getMemoryUsage(bool inclusive=false) const;
46 
47  // Apply the stored deltas to the given gdp
48  virtual void applyDeltas(GEO_Detail &gdp, bool inverse=0) const = 0;
49 
50  // Zero (but don't destroy) the attribute deltas
51  virtual void zeroDeltas();
52  // Destroy the attribute delta lists
53  virtual void clearDeltas();
54  // Destroy the attribute delta lists and attributes
55  virtual void destroy();
56 
57 
58  // Make sure the attributes in the dictionary exist in this
59  // token list, in preparation for attribute changes using
60  // beginAttributeChange/endAttributeChange. Any begin/end calls
61  // will be working on elements with the given attribute dictionary.
62  void setAttribDict(const GA_AttributeDict &dict,
63  const GA_AttributeFilter &filter);
64 
65  // Refresh attributes added from setAttribDict.
66  // This function assumes that your geometry topology has not changed,
67  // but attributes may have been added, deleted, or changed. Observe
68  // that this function will NOT add missing attribute tokens.
69  void refreshAttribDict(const GA_AttributeDict &dict,
70  const GA_AttributeFilter &filter);
71 
72  // Begin and end a change to the element specified by index.
73  // The delta is computed and stored based on the attributes in the
74  // dictionary given in the call to addAttributesFromDict.
75  void beginAttributeChange(GA_Offset element);
76  // Begin and end a change to a range of elements.
77  // The deltas for all the elements in the range are computed and stored
78  // based on the attributes in the dictionary given in the call to
79  // addAttributesFromDict.
80  void beginAttributeChange(const GA_Range &elements);
81  void endAttributeChange(const GA_AIFEditDeltaMap &map);
82 
83  // Get the attribute dictionary associated with this list
84  virtual const GA_AttributeDict &getAttributeDict(
85  const GEO_Detail &gdp) const=0;
86 
87  // Returns true if this list will have an effect on the gdp if its deltas
88  // are applied, false otherwise.
89  // This is useful because if you need to know if the list
90  // has anything worth saving or applying, then knowing the number of
91  // attributes isn't enough (all the attributes might be empty).
92  virtual bool hasChange() const;
93 
94  // I/O Methods
95  virtual bool legacyLoadAttribs(UT_IStream &is, uint size);
96  bool saveAttribs(UT_JSONWriter &w,
97  const GDT_JSON &json) const;
98  bool loadAttribs(UT_JSONParser &p,
99  const GDT_JSON &json);
100 
101  // Searches through myAttributes and finds the attribute named
102  // oldname and sets its name to newname.
103  void renameAttribute(const UT_String &oldname,
104  const UT_String &newname);
105 
106 protected:
107  // Called by subclasses in function applyDeltas
108  void applyAttributeDeltas(GEO_Detail &gdp,
109  const GA_AIFEditDeltaMap &map,
110  bool inverse = false) const;
111 
112  // Called by subclasses to scale and apply our stored attribute deltas
113  void applyScaledAttributeDeltas(GEO_Detail &gdp,
114  fpreal64 scale,
115  const GA_AIFEditDeltaMap &,
116  const UT_Int64Array *subset,
117  bool inverse = false) const;
118 
119  // Called by subclasses in function mergeDeltas
120  void mergeAttributeDeltas(const GDT_TokenList &other,
121  bool inverse = false);
122 
123  // Called by subclasses to reset elements with deltas to the values from
124  // the source detail.
125  void resetAttributeElementsFromSource(GEO_Detail &gdp,
126  const GA_AIFEditDeltaMap &map,
127  const GEO_Detail &src_gdp,
128  const GA_AIFEditDeltaMap &src_map) const;
129 
130  // Called by subclasses in function applyIntersectionDeltas
131  void applyIntersectionAttributeDeltas(GEO_Detail &gdp,
132  const GA_AIFEditDeltaMap &map,
133  const GDT_TokenList &other) const;
134 
135  // Returns the index in the token list that is currently associated with
136  // the specified attribute, and -1 if none. There may be several tokens
137  // in the list associated with a given attribute name, but only one will
138  // be bound to an attribute at any given time. Only call this method if
139  // the attribute binding is up to date.
140  int getBoundAttributeIndex(const UT_String &name) const;
141 
142  const GA_Attribute *getBoundAttribute(int i) const;
143 
144  // Adds an attribute and returns its index in the array
145  unsigned int appendAttribute(const UT_String &name,
146  const UT_String &type,
147  const UT_Options &creation_options,
148  const GA_Defaults &defaults);
149  unsigned int appendAttribute(const GA_Attribute &attrib);
150 
151  GDT_Attribute *attribs(unsigned int i) { return myAttributes(i); }
152  const GDT_Attribute *attribs(unsigned int i) const
153  { return myAttributes(i); }
154  int numAttribs() const { return myAttributes.entries(); }
155 
156 private:
157  // Attribute deltas.
158  UT_ValArray<GDT_Attribute *> myAttributes;
159 
160  // Temporary attribute references for use during beginAttributeChange()/
161  // endAttributeChange() blocks. We don't use GA_ROAttributeRefs here as
162  // those increment reference counts on the GA_Attribute objects, and we
163  // have no API for undoing the setAttribDict() call.
164  UT_ValArray<const GA_Attribute *> myAttributeRefs;
165 };
166 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
#define GDT_API
Definition: GDT_API.h:10
Class which stores the default values for a GA_Attribute.
Definition: GA_Defaults.h:35
int numAttribs() const
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 range of elements in an index-map.
Definition: GA_Range.h:42
A string map of attributes to ease backward compatibility In the GB/GEO/GU library code would often p...
double fpreal64
Definition: SYS_Types.h:201
GA_Size GA_Offset
Definition: GA_Types.h:641
GA_API const UT_StringHolder scale
void appendAttribute(PointDataTreeT &tree, const Name &name, const NamePair &type, const Index strideOrTotalSize, const bool constantStride, const Metadata *defaultValue, const bool hidden, const bool transient)
Appends a new attribute to the VDB tree (this method does not require a templated AttributeType) ...
GDT_Attribute * attribs(unsigned int i)
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
GLsizeiptr size
Definition: glcorearb.h:664
A map of string to various well defined value types.
Definition: UT_Options.h:84
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
const GDT_Attribute * attribs(unsigned int i) const
type
Definition: core.h:1059
void renameAttribute(PointDataTreeT &tree, const Name &oldName, const Name &newName)
Rename an attribute in a VDB tree.
unsigned int uint
Definition: SYS_Types.h:45
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297
Class for mapping between an index and an attribute data offset.
Definition: GA_AIFEdit.h:48