HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_LoadMap.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_LoadMap.h
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef GA_LOADMAP_H_
12 #define GA_LOADMAP_H_
13 
14 #include "GA_API.h"
15 #include "GA_Types.h"
16 #include "GA_Range.h"
17 #include "GA_SharedLoadData.h"
18 #include "GA_LoadOptions.h"
19 #include "GA_GeometryIndex.h"
20 #include "GA_SharedDataHandle.h"
21 
22 #include <UT/UT_Assert.h>
23 #include <UT/UT_String.h>
24 #include <UT/UT_StringSet.h>
25 #include <UT/UT_ValArray.h>
26 #include <UT/UT_VectorTypes.h>
27 #include <UT/UT_Set.h>
28 #include <UT/UT_SharedPtr.h>
29 
30 #include <SYS/SYS_Types.h>
31 
32 #include <stddef.h>
33 
34 class GA_Detail;
35 class GA_Primitive;
37 class GA_IndexMap;
39 class UT_JSONParser;
40 
41 /// @brief Options during loading
43 {
44 public:
45 
48 
49  // Class used to call the constructor that builds a map for loading into
50  // an existing, possibility fragmented, detail.
51  class nontrivialmap {};
52 
53  GA_LoadMap(GA_Detail &gdp, const GA_LoadOptions *options,
54  GA_Offset vtxoff, GA_Offset ptoff, GA_Offset primoff);
55  GA_LoadMap(GA_Detail &gdp, const GA_LoadOptions *options, nontrivialmap);
56  ~GA_LoadMap();
57 
58  /// Get the geometry being loaded
59  GA_Detail &getDetail() const { return myDetail; }
60 
61  /// Read only version of options. Options which callers might set that the
62  /// loading code can examine:
63  /// - @b bool @b geo:readonly @n
64  /// This indicates that the geometry will be loaded as read-only geometry
65  /// and will never be modified (no new points, no new attributes, no
66  /// modification of data). This can be used to perform things like
67  /// on-demand/deferred loading of data.
68  /// - @b string @b fileversion @n
69  /// This is set to the "fileversion" tag in the JSON file.
70  const GA_LoadOptions &getOptions() const { return myOptions; }
71 
72  /// Set/get the file version
73  void setFileVersion(const char *version)
74  { myOptions.setOptionS("fileversion", version); }
75  const char *getFileVersion(UT_String &storage) const
76  { return getDefaultedString("fileversion", storage, ""); }
77  /// Test to see whether the file version is at least the given version
78  bool isFileAtLeastVersion(const char *version) const;
79 
80  /// Set a string option
81  void setOptionS(const char *key, const char *value)
82  { myOptions.setOptionS(key, value); }
83  /// Set an integer option
84  void setOptionI(const char *key, int v)
85  { myOptions.setOptionI(key, v); }
86  /// Set a real/float option
87  void setOptionF(const char *key, fpreal v)
88  { myOptions.setOptionF(key, v); }
89 
90  /// Return the index map used to map the load offset to the real offset,
91  /// if any. An active map is present when loading a fragmented block.
93  { return myPointMap; }
94  /// Return the index map used to map the load offset to the real offset,
95  /// if any. An active map is present when loading a fragmented block.
97  { return myVertexMap; }
98  /// Return the index map used to map the load offset to the real offset,
99  /// if any. An active map is present when loading a fragmented block.
101  { return myPrimitiveMap; }
102  /// Return the index map used to map the load offset to the real offset,
103  /// if any. An active map is present when loading a fragmented block.
105  {
106  switch (owner)
107  {
108  case GA_ATTRIB_POINT:
109  return myPointMap;
110  case GA_ATTRIB_VERTEX:
111  return myVertexMap;
112  case GA_ATTRIB_PRIMITIVE:
113  return myPrimitiveMap;
114  default:
115  break;
116  }
117  UT_ASSERT(owner == GA_ATTRIB_DETAIL);
118  return nullptr;
119  }
120 
121  /// Return the mapping of the load offset to the real offset
123  { return GA_Offset(getLoadOffset(o) + load_index); }
124  /// Map the load_index to the actual point number in the detail
125  GA_Offset getPointOffset(GA_Size load_index) const
126  {
127  if (myPointMap)
128  return offsetFromIndex(myPointMap,
129  myPointOffset + load_index);
130  else
131  return GA_Offset(myPointOffset + load_index);
132  }
133  /// Map the load_index to the actual vertex number in the detail
135  {
136  if (myVertexMap)
137  return offsetFromIndex(myVertexMap,
138  myVertexOffset + load_index);
139  else
140  return GA_Offset(myVertexOffset + load_index);
141  }
142  /// Map the load_index to the actual primitive number in the detail
144  {
145  if (myPrimitiveMap)
146  return offsetFromIndex(myPrimitiveMap,
147  myPrimitiveOffset + load_index);
148  else
149  return GA_Offset(myPrimitiveOffset + load_index);
150  }
151 
152  /// Elements are loaded at a fixed offset (usually 0) in the index maps.
153  /// This method returns the load offset for a particular owner type.
155  {
156  switch (owner)
157  {
158  case GA_ATTRIB_POINT:
159  return myPointOffset;
160  case GA_ATTRIB_VERTEX:
161  return myVertexOffset;
162  case GA_ATTRIB_PRIMITIVE:
163  return myPrimitiveOffset;
164  default:
165  break;
166  }
167  UT_ASSERT(owner == GA_ATTRIB_DETAIL);
168  return GA_Offset(0);
169  }
170  // Return the offset of the loaded points
171  GA_Offset getPointOffset() const { return myPointOffset; }
172  // Return the offset of the loaded vertices
173  GA_Offset getVertexOffset() const { return myVertexOffset; }
174  // Return the offset of the loaded primitives
175  GA_Offset getPrimitiveOffset() const { return myPrimitiveOffset; }
176 
177  /// This method returns the number of elements being loaded of each type.
178  GA_Size getLoadCount(GA_AttributeOwner owner) const;
179 
180  /// Warn about unknown primitive types in the load process
181  void badPrimitive(UT_JSONParser &p, const char *type);
182 
183  /// Returns true if this is the time this type of primitive was added to
184  /// bad primitive table.
185  bool addBadPrimitive(const char *type);
186 
187  /// Convert the given secondary primitive indices into data offsets.
188  bool getSecondaryOffsets(GA_Offset primary_offset,
189  const UT_Int64Array &secondary_detail_indices,
190  const UT_Int64Array &secondary_prim_indices,
191  UT_Int64Array &secondary_prim_offsets) const;
192 
193 
194  /// Check the load options. Return @c defvalue if token isn't defined.
195  bool getDefaultedBool(const char *name, bool defvalue) const;
196  /// Check the load options. Return @c defvalue if token isn't defined.
197  exint getDefaultedInt(const char *name, exint defvalue) const;
198  /// Check the load options. Return @c defvalue if the token isn't defined
199  const char *getDefaultedString(const char *name, UT_String &storage,
200  const char *defvalue) const;
201  // -------------------------------------------------------------------
202  // Methods to query load options. These methods provide a common
203  // interface to querying the GA_LoadOptions which are passed to the load
204  // methods.
205  /// "string geo:attributeloadmask" @n
206  /// Specify the "mask" for attributes which should be loaded. This
207  /// mask is in the form used by UT_String::multiMatch().
208  ///
210  const char *default_mask="*") const
211  {
212  return getDefaultedString(
213  "geo:attributeloadmask", storage, default_mask);
214  }
215 
216  /// "string geo:grouploadmask" @n
217  /// Specify the "mask" for groups which should be loaded. This
218  /// mask is in the form used by UT_String::multiMatch()
220  const char *default_mask="*") const
221  {
222  return getDefaultedString(
223  "geo:grouploadmask", storage, default_mask);
224  }
225 
226  /// "bool geo:loadprimitives" @n
227  /// Load vertex & primitive data.
228  ///
229  /// Turning this off will perform early termination when loading JSON files
230  /// (which may affect reading from streamed data).
231  bool optionLoadPrimitives() const
232  {
233  return getDefaultedBool("geo:loadprimitives", true);
234  }
235  /// "bool geo:loadprimitiveshared" @n
236  /// Load primitive shared data. This is data which can be shared between
237  /// multiple primitives and is optionally loaded.
238  ///
239  /// Turning this off will perform early termination when loading JSON files
240  /// (which may affect reading from streamed data).
242  {
243  return getDefaultedBool("geo:loadprimitiveshared", true);
244  }
245 
246 
247  // End of common load options
248  // -------------------------------------------------------------------
249 
250  /// When a primitive is being loaded, and it has a reference to shared
251  /// data, it needs to call this method to retrieve a handle to the shared
252  /// data so it can be loaded upon request.
253  GA_SharedDataHandlePtr needSharedData(const UT_StringHolder &key,
254  const UT_StringRef &typekey,
255  GA_Primitive* caller_prim) const;
256 
257  /// This method is called internally to resolve shared data when
258  /// there is no index.
259  void resolveSharedData(GA_SharedLoadData *data);
260 
261  /// Called by the loader to parse the shared load data.
262  /// Not used when the geomentry has an index
263  bool forceLoadSharedData(UT_JSONParser &p,
264  const GA_PrimitiveFactory &factory);
265 
266  /// Retrieves a random primitive that needs the shared data
267  /// with the given key.
268  GA_Primitive* getRandomPrimitive(const char* key);
269 
270  /// Set's the filename to load shared data from
271  void setFilename(const char* filename);
272 
273  /// Loads the index from given stream into this load map
274  /// @return true on sucsess false on failure
275  bool loadIndex(UT_IStream* json_istream, const char* index_pos_key,
276  bool should_swap);
277 
278  GA_GeometryIndex* getIndex() { return &myIndex; }
279 
280 private:
281  static GA_Offset offsetFromIndex(const GA_IndexMap *map, GA_Size index);
282 
283  GA_Detail &myDetail;
284  GA_LoadOptions myOptions;
285  GA_Offset myPointOffset;
286  GA_Offset myVertexOffset;
287  GA_Offset myPrimitiveOffset;
288  const GA_IndexMap *myPointMap;
289  const GA_IndexMap *myVertexMap;
290  const GA_IndexMap *myPrimitiveMap;
291  UT_StringSet myBadPrimitives;
292  GA_GeometryIndex myIndex;
293  bool myHaveIndex;
294  SharedDataHandleMapType mySharedDataHandles;
295  PrimitiveStorageMapType myTemporaryPrimitiveStorage;
296  const char* myFilename;
297 };
298 
299 #endif // GA_LOADMAP_H_
A class to manage an ordered array which has fixed offset handles.
Definition: GA_IndexMap.h:63
const GA_IndexMap * getActivePrimitiveMap() const
Definition: GA_LoadMap.h:100
GT_API const UT_StringHolder filename
GA_Offset getPointOffset(GA_Size load_index) const
Map the load_index to the actual point number in the detail.
Definition: GA_LoadMap.h:125
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
const GLdouble * v
Definition: glcorearb.h:837
UT_StringMap< GA_SharedDataHandlePtr > SharedDataHandleMapType
Definition: GA_LoadMap.h:46
GA_Offset getOffset(GA_Size load_index, GA_AttributeOwner o) const
Return the mapping of the load offset to the real offset.
Definition: GA_LoadMap.h:122
bool optionLoadPrimitives() const
Definition: GA_LoadMap.h:231
const GA_LoadOptions & getOptions() const
Definition: GA_LoadMap.h:70
int64 exint
Definition: SYS_Types.h:125
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
UT_StringMap< GA_Primitive * > PrimitiveStorageMapType
Definition: GA_LoadMap.h:47
#define GA_API
Definition: GA_API.h:14
const char * optionAttributeLoadMask(UT_String &storage, const char *default_mask="*") const
Definition: GA_LoadMap.h:209
Information necessary to lookup a secondary primitive.
void setOptionF(const char *key, fpreal v)
Set a real/float option.
Definition: GA_LoadMap.h:87
UT_SharedPtr< GA_SharedDataHandle > GA_SharedDataHandlePtr
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
GA_Size GA_Offset
Definition: GA_Types.h:646
void setOptionI(const char *key, int v)
Set an integer option.
Definition: GA_LoadMap.h:84
const char * optionGroupLoadMask(UT_String &storage, const char *default_mask="*") const
Definition: GA_LoadMap.h:219
const GA_IndexMap * getActiveVertexMap() const
Definition: GA_LoadMap.h:96
GA_Offset getPointOffset() const
Definition: GA_LoadMap.h:171
GA_GeometryIndex * getIndex()
Definition: GA_LoadMap.h:278
Options during loading.
Definition: GA_LoadMap.h:42
GA_Offset getVertexOffset(GA_Size load_index) const
Map the load_index to the actual vertex number in the detail.
Definition: GA_LoadMap.h:134
GLuint const GLchar * name
Definition: glcorearb.h:786
GA_Offset getPrimitiveOffset() const
Definition: GA_LoadMap.h:175
void setFileVersion(const char *version)
Set/get the file version.
Definition: GA_LoadMap.h:73
GA_Detail & getDetail() const
Get the geometry being loaded.
Definition: GA_LoadMap.h:59
bool optionLoadPrimitiveSharedData() const
Definition: GA_LoadMap.h:241
GT_API const UT_StringHolder version
GA_AttributeOwner
Definition: GA_Types.h:35
const GA_IndexMap * getActiveIndexMap(GA_AttributeOwner owner) const
Definition: GA_LoadMap.h:104
void setOptionS(const char *key, const char *value)
Set a string option.
Definition: GA_LoadMap.h:81
const char * getFileVersion(UT_String &storage) const
Definition: GA_LoadMap.h:75
fpreal64 fpreal
Definition: SYS_Types.h:277
GA_Offset getLoadOffset(GA_AttributeOwner owner) const
Definition: GA_LoadMap.h:154
GLuint index
Definition: glcorearb.h:786
GA_Offset getPrimitiveOffset(GA_Size load_index) const
Map the load_index to the actual primitive number in the detail.
Definition: GA_LoadMap.h:143
Container class for all geometry.
Definition: GA_Detail.h:96
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
Definition: core.h:1131
type
Definition: core.h:1059
Class to specify options for loading geometry.
GA_Offset getVertexOffset() const
Definition: GA_LoadMap.h:173
Definition: format.h:895
const GA_IndexMap * getActivePointMap() const
Definition: GA_LoadMap.h:92