HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_SaveMap.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: GA_SaveMap.h ( GA Library, C++)
7  *
8  * COMMENTS: Contains options used for load/save
9  */
10 
11 #ifndef __GA_SaveMap__
12 #define __GA_SaveMap__
13 
14 #include "GA_API.h"
15 #include "GA_Types.h"
16 #include "GA_Range.h"
17 #include "GA_SharedLoadData.h"
18 #include "GA_SaveOptions.h"
19 
20 #include <UT/UT_Assert.h>
21 #include <UT/UT_Options.h>
22 #include <UT/UT_String.h>
23 #include <UT/UT_ValArray.h>
24 #include <UT/UT_VectorTypes.h>
25 #include <UT/UT_StringSet.h>
26 
27 #include <SYS/SYS_Types.h>
28 #include <stddef.h>
29 
30 class GA_Detail;
31 class GA_Primitive;
33 class GA_IndexMap;
35 class UT_JSONParser;
36 
37 
38 // This is used by GA_LoadMap
39 #define GA_SAVEMAP_END_TOKEN ":end"
40 
41 
42 /// @brief Used to pass options and map offset values during saving.
43 ///
44 /// This class is a container which stores iterators that iterate over the
45 /// points/primitives/vertices to be saved. It also stores keyword arguments
46 /// in the form of a UT_Options.
47 /// @see UT_JSONWriter
49 {
50 public:
51  /// Generic save map used when saving geometry
52  GA_SaveMap(const GA_Detail &detail, const GA_SaveOptions *options);
53 
54  /// Destructor
55  ~GA_SaveMap();
56 
57  /// The options in the save map are used to control behaviour during
58  /// saving/loading of the geometry. The user can pass any arbitrary
59  /// key/value pairs. Common options (used in the baseline GA library) are:
60  ///
61  /// - @b bool @b geo:primrun -- Enable primitive run compression
62  /// - @b int @b geo:primrunqueue -- Size of primitives run queue [4]
63  /// - @b bool @b geo:savepointgroups -- Save point groups [true]
64  /// - @b bool @b geo:saveprimitivegroups -- Save primitive groups [true]
65  /// - @b bool @b geo:savevertexgroups -- Save vertex groups [true]
66  /// - @b bool @b geo:saveedgegroups -- Save edge groups [true]
67  /// - @b bool @b geo:savegroups -- Save all groups [true]
68  /// - @b bool @b geo:saveinternal -- Saving of internal groups [false]
69  /// - @b bool @b geo:houdini10format -- Save in Houdini10 format [false]
70  /// - @b bool @b geo:rlebits -- Run length encoding of bit arrays [true]
71  /// - @b bool @b geo:ignoreattribscope -- Save private attribs by default
72  // [false]
73  ///
74  /// Additional options for controlling the JSON stream can be found in
75  /// UT_JSONWriter::setOptions() (i.e. json:precision).
76  /// @see UT_JSONWriter
77  const GA_SaveOptions &getOptions() const { return myOptions; }
78 
79  /// During the loading process, the file version may be set
80  void setFileVersion(const char *v) { myFVersion.harden(v);}
81  const char *getFileVersion() const { return myFVersion; }
82 
83  /// Get the geometry being loaded
84  const GA_Detail &getDetail() const { return myDetail; }
85 
86  /// Return the iterator for the points to be saved
87  const GA_Range &getPointRange() const
88  { return myI[GA_ATTRIB_POINT]; }
89  /// Return the iterator for the vertices to be saved
90  const GA_Range &getVertexRange() const
91  {
92  if (!myI[GA_ATTRIB_VERTEX].isValid())
93  lazyMakeVertexRange();
94  return myI[GA_ATTRIB_VERTEX];
95  }
96  /// Return the iterator for the primitives to be saved
97  const GA_Range &getPrimitiveRange() const
98  { return myI[GA_ATTRIB_PRIMITIVE]; }
99  /// Return the detail iterator
100  const GA_Range &getGlobalRange() const
101  { return myI[GA_ATTRIB_GLOBAL]; }
102  /// Return an arbitrary iterator based on the owner type
104  {
105  if (i == GA_ATTRIB_VERTEX && !myI[i].isValid())
106  lazyMakeVertexRange();
107  return myI[i];
108  }
109 
110  /// Take a point offset and returns its offset(index) in the save file.
111  GA_Index getPointIndex(GA_Offset point_offset) const;
112  /// Take a vertex offset and returns its offset(index) in the save file.
113  GA_Index getVertexIndex(GA_Offset vertex_offset) const;
114  /// Take a primitive offset and returns its offset(index) in the save file.
115  GA_Index getPrimitiveIndex(GA_Offset primitive_offset) const;
116 
117  /// Return the save index associated with an element
119  {
120  switch (o)
121  {
122  case GA_ATTRIB_VERTEX:
123  return getVertexIndex(offset);
124  case GA_ATTRIB_POINT:
125  return getPointIndex(offset);
126  case GA_ATTRIB_PRIMITIVE:
127  return getPrimitiveIndex(offset);
128  case GA_ATTRIB_DETAIL:
129  UT_ASSERT(offset == GA_Offset(0));
130  return GA_Index(0);
131  default:
132  break;
133  }
134  UT_ASSERT(0 && "Invalid attribute owner");
135  return GA_INVALID_INDEX;
136  }
137 
138  // Returns true if all offsets of this owner would be mapped to themselves.
139  bool isTrivialMap(GA_AttributeOwner owner) const;
140 
141  /// Check the save options. Return @c defvalue if token isn't defined.
142  bool getDefaultedBool(const char *name, bool defvalue) const;
143  /// Check the save options. Return @c defvalue if token isn't defined.
144  exint getDefaultedInt(const char *name, exint defvalue) const;
145  /// Check the save options. Return @c defvalue if the token isn't defined
146  const char *getDefaultedString(const char *name, UT_String &storage,
147  const char *defvalue) const;
148 
149  /// Convert the secondary primitives offsets in the given lookup object
150  /// into indices.
151  bool getSecondaryIndices(GA_Offset primary_offset,
152  const GA_SecondaryLookupInfo &info,
153  UT_Int64Array &secondary_prim_indices) const;
154 
155  // -------------------------------------------------------------------
156  // Methods to query save options. These methods provide a common
157  // interface to querying the UT_Options which are passed to the save/load
158  // methods.
159  /// "bool geo:saveinfo" @n Whether to save info block
160  bool optionSaveInfo() const
161  { return getDefaultedBool("geo:saveinfo", true); }
162 
163  /// "string info:artist" @n String containing the artist's name
164  const char *optionArtistName(UT_String &s) const
165  { return getDefaultedString("info:artist", s, NULL); }
166  /// "string info:hostname" @n String containing the host name
167  const char *optionHostname(UT_String &s) const
168  { return getDefaultedString("info:hostname", s, NULL); }
169  /// "string info:date" @n Current date (default: %Y-%m-%d %T)
170  const char *optionDate(UT_String &s) const
171  { return getDefaultedString("info:date", s, NULL); }
172  /// "string info:software" @n Software (and version)
173  const char *optionSoftware(UT_String &s) const
174  { return getDefaultedString("info:software", s, NULL); }
175 
176  /// "bool info:savebounds" @n Whether to compute and save bounding
177  /// box in the info block.
178  bool optionSaveBounds() const
179  { return getDefaultedBool("info:savebounds", true); }
180 
181  /// "bool info:saveprimcounts" @n Whether to compute and save the counts of
182  /// each primitive type into the info block.
183  bool optionSavePrimCount() const
184  { return getDefaultedBool("info:saveprimcounts", true); }
185 
186  /// "bool info:savevolumesummary" @n Whether to compute and save the
187  /// volume info into the info block.
189  { return getDefaultedBool("info:savevolumesummary", true); }
190 
191  /// "bool info:saveattributesummary" @n Whether to save a summary of
192  /// attributes in the info block.
194  { return getDefaultedBool("info:saveattributesummary", true); }
195 
196  /// "bool info:saverenderattributeranges" @n
197  /// Will save the ranges for velocity attributes ("v" as point/primitive)
198  /// and the "width" attribute (point, primitive, detail) if they exist.
199  /// These can be used by rendering procedurals to adjust the bounds to
200  /// include velocity and width attributes.
201  ///
202  /// This is included in the attribute summary, so for this option to work,
203  /// you need to have @c info:saveattributesummary enabled.
205  {
206  return getDefaultedBool("info:saverenderattributeranges",
207  true);
208  }
209 
210  /// "bool info:savegroupsummary" @n Whether to save a summary of
211  /// groups in the info block.
213  { return getDefaultedBool("info:savegroupsummary", true); }
214 
215  /// "bool geo:savepointgroups" @n Whether to save point groups
216  /// @note This will returns the intersection with "bool geo:savegroups"
218  {
219  return getDefaultedBool("geo:savegroups", true) &&
220  getDefaultedBool("geo:savepointgroups", true);
221  }
222  /// "bool geo:saveprimitivegroups" @n Whether to save primitive groups
223  /// @note This will returns the intersection with "bool geo:savegroups"
225  {
226  return getDefaultedBool("geo:savegroups", true) &&
227  getDefaultedBool("geo:saveprimitivegroups", true);
228  }
229  /// "bool geo:savevertexgroups" @n Whether to save vertex groups
230  /// @note This will returns the intersection with "bool geo:savegroups"
232  {
233  return getDefaultedBool("geo:savegroups", true) &&
234  getDefaultedBool("geo:savevertexgroups", true);
235  }
236  /// "bool geo:saveedgegroups" @n Whether to save edge groups
237  /// @note This will returns the intersection with "bool geo:savegroups"
238  bool optionSaveEdgeGroups() const
239  {
240  return getDefaultedBool("geo:savegroups", true) &&
241  getDefaultedBool("geo:saveedgegroups", true);
242  }
243  /// "bool geo:savebreakpointgroups" @n Whether to save breakpoint groups
244  /// @note This will returns the intersection with "bool geo:savegroups"
246  {
247  return getDefaultedBool("geo:savegroups", true) &&
248  getDefaultedBool("geo:savebreakpointgroups", true);
249  }
250 
251  /// "bool geo:ignoreattribscope" @n
252  /// When saving, private attributes are not typically saved. If
253  /// this option is set, the scope of attributes should be ignored
254  /// The GA_OPTION_EXPORT_ON_SAVE should override this option.
256  { return getDefaultedBool("geo:ignoreattributescope", false); }
257 
258  /// "string geo:attributesavemask" @n
259  /// Specify the "mask" for attributes which should be saved. This
260  /// mask is in the form used by UT_String::multiMatch().
261  ///
263  const char *default_mask="*") const
264  {
265  return getDefaultedString(
266  "geo:attributesavemask", storage, default_mask);
267  }
268 
269  /// "string geo:groupsavemask" @n
270  /// Specify the "mask" for groups which should be saved. This
271  /// mask is in the form used by UT_String::multiMatch()
273  const char *default_mask="*") const
274  {
275  return getDefaultedString(
276  "geo:groupsavemask", storage, default_mask);
277  }
278  // End of common save options
279  // -------------------------------------------------------------------
280 
281  /// Test if the data associated with the unique key has been saved
282  /// The key specified should be something which is guaranteed to be unique
283  /// for the given data. However, it should be the same key for each shared
284  /// instance. For example, given a shared pointer to data, you might
285  /// consider: @code
286  /// sprintf(key, "%s:%s:%p",
287  /// getTypeName(), // Primitive type name
288  /// "data_type",
289  /// shared_ptr.get());
290  /// @endcode
291  bool hasSavedSharedData(const UT_StringRef &key) const;
292  /// Indicate the given data has been shared
293  void setSavedSharedData(const UT_StringHolder &key);
294 
295 private:
296  void lazyMakeVertexRange() const;
297  void reallyMakeVertexRange();
298  const GA_Detail &myDetail;
299  GA_SaveOptions myOptions;
300  GA_Range myI[4];
301  UT_String myFVersion;
302  GA_ListType<GA_Offset, GA_Index> myVertexIndexFromOffset;
303  UT_StringSet mySharedDataKeys;
304 };
305 
306 #endif
bool optionSaveInfo() const
"bool geo:saveinfo" Whether to save info block
Definition: GA_SaveMap.h:160
A class to manage an ordered array which has fixed offset handles.
Definition: GA_IndexMap.h:63
bool optionIgnoreAttributeScope() const
Definition: GA_SaveMap.h:255
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
const GA_Range & getVertexRange() const
Return the iterator for the vertices to be saved.
Definition: GA_SaveMap.h:90
const GA_Detail & getDetail() const
Get the geometry being loaded.
Definition: GA_SaveMap.h:84
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
const GLdouble * v
Definition: glcorearb.h:837
const char * optionDate(UT_String &s) const
"string info:date" Current date (default: Y-m-d T)
Definition: GA_SaveMap.h:170
GA_Index getIndex(GA_Offset offset, GA_AttributeOwner o) const
Return the save index associated with an element.
Definition: GA_SaveMap.h:118
bool optionSavePrimitiveGroups() const
Definition: GA_SaveMap.h:224
int64 exint
Definition: SYS_Types.h:125
GLdouble s
Definition: glad.h:3009
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
void setFileVersion(const char *v)
During the loading process, the file version may be set.
Definition: GA_SaveMap.h:80
bool optionSaveVolumeSummary() const
Definition: GA_SaveMap.h:188
#define GA_API
Definition: GA_API.h:14
Information necessary to lookup a secondary primitive.
const GA_Range & getPointRange() const
Return the iterator for the points to be saved.
Definition: GA_SaveMap.h:87
bool optionSavePrimCount() const
Definition: GA_SaveMap.h:183
A range of elements in an index-map.
Definition: GA_Range.h:42
bool optionSaveBounds() const
Definition: GA_SaveMap.h:178
GA_Size GA_Offset
Definition: GA_Types.h:646
GLintptr offset
Definition: glcorearb.h:665
const GA_Range & getGlobalRange() const
Return the detail iterator.
Definition: GA_SaveMap.h:100
bool optionSaveAttributeSummary() const
Definition: GA_SaveMap.h:193
const char * optionSoftware(UT_String &s) const
"string info:software" Software (and version)
Definition: GA_SaveMap.h:173
bool optionSaveVertexGroups() const
Definition: GA_SaveMap.h:231
GLuint const GLchar * name
Definition: glcorearb.h:786
const char * optionGroupSaveMask(UT_String &storage, const char *default_mask="*") const
Definition: GA_SaveMap.h:272
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:640
bool optionSaveBreakpointGroups() const
Definition: GA_SaveMap.h:245
bool optionSavePointGroups() const
Definition: GA_SaveMap.h:217
const char * getFileVersion() const
Definition: GA_SaveMap.h:81
const char * optionAttributeSaveMask(UT_String &storage, const char *default_mask="*") const
Definition: GA_SaveMap.h:262
bool optionSaveRenderAttributeRanges() const
Definition: GA_SaveMap.h:204
bool optionSaveGroupSummary() const
Definition: GA_SaveMap.h:212
GA_AttributeOwner
Definition: GA_Types.h:35
const char * optionArtistName(UT_String &s) const
"string info:artist" String containing the artist's name
Definition: GA_SaveMap.h:164
const GA_SaveOptions & getOptions() const
Definition: GA_SaveMap.h:77
#define GA_INVALID_INDEX
Definition: GA_Types.h:686
Container class for all geometry.
Definition: GA_Detail.h:96
const GA_Range & getPrimitiveRange() const
Return the iterator for the primitives to be saved.
Definition: GA_SaveMap.h:97
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
const char * optionHostname(UT_String &s) const
"string info:hostname" String containing the host name
Definition: GA_SaveMap.h:167
const GA_Range & getRange(GA_AttributeOwner i) const
Return an arbitrary iterator based on the owner type.
Definition: GA_SaveMap.h:103
bool optionSaveEdgeGroups() const
Definition: GA_SaveMap.h:238