HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  // Returns the index in the token list that is currently associated with
124  // the specified attribute, and -1 if none. There may be several tokens
125  // in the list associated with a given attribute name, but only one will
126  // be bound to an attribute at any given time. Only call this method if
127  // the attribute binding is up to date.
128  int getBoundAttributeIndex(const UT_String &name) const;
129 
130  const GA_Attribute *getBoundAttribute(int i) const;
131 
132  // Adds an attribute and returns its index in the array
133  unsigned int appendAttribute(const UT_String &name,
134  const UT_String &type,
135  const UT_Options &creation_options,
136  const GA_Defaults &defaults);
137  unsigned int appendAttribute(const GA_Attribute &attrib);
138 
139  GDT_Attribute *attribs(unsigned int i) { return myAttributes(i); }
140  const GDT_Attribute *attribs(unsigned int i) const
141  { return myAttributes(i); }
142  int numAttribs() const { return myAttributes.entries(); }
143 
144 private:
145  // Attribute deltas.
146  UT_ValArray<GDT_Attribute *> myAttributes;
147 
148  // Temporary attribute references for use during beginAttributeChange()/
149  // endAttributeChange() blocks. We don't use GA_ROAttributeRefs here as
150  // those increment reference counts on the GA_Attribute objects, and we
151  // have no API for undoing the setAttribDict() call.
152  UT_ValArray<const GA_Attribute *> myAttributeRefs;
153 };
154 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
#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:72
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
png_uint_32 i
Definition: png.h:2877
GLsizeiptr size
Definition: glcorearb.h:663
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...
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:106
GA_API const UT_StringHolder scale
void appendAttribute(PointDataTree &tree, const Name &name, const NamePair &type, const Index strideOrTotalSize=1, const bool constantStride=true, Metadata::Ptr metaDefaultValue=Metadata::Ptr(), const bool hidden=false, const bool transient=false)
Appends a new attribute to the VDB tree (this method does not require a templated AttributeType) ...
GDT_Attribute * attribs(unsigned int i)
double fpreal64
Definition: SYS_Types.h:191
GLuint const GLchar * name
Definition: glcorearb.h:785
unsigned int uint
Definition: SYS_Types.h:39
A map of string to various well defined value types.
Definition: UT_Options.h:42
void renameAttribute(PointDataTree &tree, const Name &oldName, const Name &newName)
Rename an attribute in a VDB tree.
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
const GDT_Attribute * attribs(unsigned int i) const
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1296
Class for mapping between an index and an attribute data offset.
Definition: GA_AIFEdit.h:48