HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_AIFFileH9.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_AIFFileH9.h ( GA Library, C++)
7  *
8  * COMMENTS: Attribute Interface for .geo/.bgeo file I/O
9  */
10 
11 #ifndef __GA_AIFFileH9__
12 #define __GA_AIFFileH9__
13 
14 #include "GA_API.h"
15 
16 #include "GA_AttributeType.h"
17 #include "GA_Types.h"
18 
19 #include <UT/UT_String.h>
20 #include <UT/UT_ValArray.h>
21 #include <UT/UT_VectorTypes.h>
22 
23 #include <iosfwd>
24 
25 
26 class GA_Attribute;
27 class GA_Defaults;
28 class GA_AIFTuple;
30 class GA_AIFIndexPair;
31 class UT_IStream;
32 
33 
34 /// @brief Attribute Interface for file I/O
35 ///
36 /// This class provides an interface used to save and load attributes to and
37 /// from files.
38 ///
39 /// In H9, the attributes stored their data interleaved for each element. GA
40 /// prefers to process data in arrays rather than interleaved. This class
41 /// contains SaveInfo and LoadInfo which help with the
42 /// interleaving/de-interleaving process.
43 ///
45 {
46 public:
48 
50  ~GA_AIFFileH9() override {}
51 
52  /// Data types stored in Houdini 9 data files
54  {
55  ATTRIB_FLOAT = 0,
56  ATTRIB_INT = 1,
57  ATTRIB_STRING = 2,
58  ATTRIB_MIXED = 3, // Impossible to save and load
59  ATTRIB_INDEX = 4, // Index of strings
60  ATTRIB_VECTOR = 5 // Same as float, but gets transformed
61  // when geometry is transformed.
62  // the vector type is always 3 floats
63  };
64 
65  /// Attribute type modifiers stored in Houdini 9 data files
67  {
68  ATTRIB_INFO_NONE = 0, // no info available
69  ATTRIB_INFO_INDEX_PAIR = 1, // data are index-value pairs
70  ATTRIB_NUM_INFO // sentinel
71  };
72 
73  // TODO: Support saving multiple H9 attributes when a single one will not
74  // capture all the data.
75  /// Class used to cache information during the H9 save process
77  {
78  public:
80  : myType(ATTRIB_MIXED), myTypeInfo(ATTRIB_INFO_NONE),
81  myTupleSize(0), myComponent(0), myTupleAIF(0),
82  myStringTupleAIF(0), myIndexPairAIF(0)
83  {}
85  : myType(src.myType),
86  myTypeInfo(src.myTypeInfo),
87  myTupleSize(src.myTupleSize),
88  myStringMap(src.myStringMap),
89  myComponent(src.myComponent),
90  myTupleAIF(src.myTupleAIF),
91  myStringTupleAIF(src.myStringTupleAIF),
92  myIndexPairAIF(src.myIndexPairAIF)
93 
94  {}
95  SaveInfo(AttribType type, AttribTypeInfo type_info, int tuple_size,
96  const GA_AIFTuple *tuple, const GA_AIFSharedStringTuple *sindex,
97  const GA_AIFIndexPair *ipair, int component)
98  : myType(type), myTypeInfo(type_info), myTupleSize(tuple_size),
99  myComponent(component), myTupleAIF(tuple),
100  myStringTupleAIF(sindex), myIndexPairAIF(ipair)
101  {}
103  {
104  myType = src.myType;
105  myTypeInfo = src.myTypeInfo;
106  myTupleSize = src.myTupleSize;
107  myStringMap = src.myStringMap;
108  myComponent = src.myComponent;
109  myTupleAIF = src.myTupleAIF;
110  myStringTupleAIF = src.myStringTupleAIF;
111  myIndexPairAIF = src.myIndexPairAIF;
112  return *this;
113  }
114 
115  AttribType getType() const { return myType; }
116  AttribTypeInfo getTypeInfo() const { return myTypeInfo; }
117  int getTupleSize() const { return myTupleSize; }
118  const UT_IntArray &getStringMap() const { return myStringMap; }
119  UT_IntArray &getStringMap() { return myStringMap; }
120  int getComponent() const { return myComponent; }
121 
122  const GA_AIFTuple *getTupleAIF() const
123  { return myTupleAIF; }
125  { return myStringTupleAIF; }
127  { return myIndexPairAIF; }
128  private:
129  AttribType myType;
130  AttribTypeInfo myTypeInfo;
131  int myTupleSize;
132  UT_IntArray myStringMap;
133  int myComponent;
134 
135  const GA_AIFTuple *myTupleAIF;
136  const GA_AIFSharedStringTuple *myStringTupleAIF;
137  const GA_AIFIndexPair *myIndexPairAIF;
138  };
139 
140  // TODO: Consolidate with SaveInfo?
141  /// Class used to cache information during the H9 save process
142  class LoadInfo
143  {
144  public:
146  : myType(ATTRIB_MIXED), myTypeInfo(ATTRIB_INFO_NONE),
147  myTupleSize(0), myTupleAIF(0), myStringTupleAIF(0),
148  myIndexPairAIF(0)
149  { }
151  : myType(src.myType),
152  myTypeInfo(src.myTypeInfo),
153  myTupleSize(src.myTupleSize),
154  myStringMap(src.myStringMap),
155  myTupleAIF(src.myTupleAIF),
156  myStringTupleAIF(src.myStringTupleAIF),
157  myIndexPairAIF(src.myIndexPairAIF)
158 
159  { }
160  LoadInfo(AttribType type, AttribTypeInfo type_info, int tuple_size,
161  const GA_AIFTuple *tuple, const GA_AIFSharedStringTuple *sindex,
162  const GA_AIFIndexPair *ipair)
163  : myType(type), myTypeInfo(type_info), myTupleSize(tuple_size),
164  myTupleAIF(tuple), myStringTupleAIF(sindex),
165  myIndexPairAIF(ipair)
166  { }
168  { }
169 
170  AttribType getType() const { return myType; }
171  AttribTypeInfo getTypeInfo() const { return myTypeInfo; }
172  int getTupleSize() const { return myTupleSize; }
173  const UT_IntArray &getStringMap() const { return myStringMap; }
174  UT_IntArray &getStringMap() { return myStringMap; }
175 
176  const GA_AIFTuple *getTupleAIF() const
177  { return myTupleAIF; }
179  { return myStringTupleAIF; }
181  { return myIndexPairAIF; }
183  {
184  myType = src.myType;
185  myTypeInfo = src.myTypeInfo;
186  myTupleSize = src.myTupleSize;
187  myStringMap = src.myStringMap;
188  myTupleAIF = src.myTupleAIF;
189  myStringTupleAIF = src.myStringTupleAIF;
190  myIndexPairAIF = src.myIndexPairAIF;
191  return *this;
192  }
193  private:
194  AttribType myType;
195  AttribTypeInfo myTypeInfo;
196  int myTupleSize;
197  UT_IntArray myStringMap;
198 
199  const GA_AIFTuple *myTupleAIF;
200  const GA_AIFSharedStringTuple *myStringTupleAIF;
201  const GA_AIFIndexPair *myIndexPairAIF;
202  };
203 
204  /// Create save information for a given GA attribute
205  virtual SaveInfo getSaveInfo(const GA_Attribute *attrib, int component=0) const;
206 
207  /// Save the attribute defaults to the output stream.
208  /// @param attrib The attribute to save
209  /// @param info SaveInfo class helper
210  /// @param os The output stream
211  /// @param binary Save as ASCII (false) or binary (true)
212  virtual bool saveDefaults(const GA_Attribute *attrib,
213  const SaveInfo &info, std::ostream &os,
214  bool binary) const;
215 
216  /// Save the string table to the output stream. This method should only
217  /// be called when getSaveInfo(attrib).getType() == ATTRIB_INDEX.
218  /// @param attrib The attribute
219  /// @param os The output stream
220  /// @param binary Save as ASCII (false) or binary (true)
221  /// @param stringmap A mapping of string handles to their in-order indices.
222  virtual bool saveStrings(const GA_Attribute *attrib,
223  std::ostream &os,
224  bool binary,
225  UT_IntArray &stringmap) const;
226 
227  /// Save the element data for a given attribute
228  virtual bool saveData(const GA_Attribute *attrib,
229  const SaveInfo &info, GA_Offset offset,
230  std::ostream &os, bool binary) const;
231 
232  /// Create load information for an H9 attribute
233  virtual LoadInfo getLoadInfo(const GA_Attribute *attrib,
234  AttribType type, AttribTypeInfo type_info,
235  int tuple_size) const;
236 
237  /// Load the attribute data for a given element
238  virtual bool loadData(GA_Attribute *attrib, UT_IStream &is,
239  const LoadInfo &info, GA_Offset offset) const;
240 
241  /// Call once finished loading the attribute data for all the elements to
242  /// perform any clean up or finalization that may be needed.
243  virtual bool finishLoad(GA_Attribute *attrib,
244  const LoadInfo &info) const;
245 
246  /// Skip data unsupported data in the input stream
247  static bool skipData(UT_IStream &is, const LoadInfo &info);
248 
249  /// Query the definition for this custom AIF. The first call will register
250  /// this AIF in a thread-safe manner.
251  static Definition getDefinition();
252 
253 protected:
254  bool saveDefaultsImpl(const GA_Defaults *defs,
255  const SaveInfo &info,
256  std::ostream &os,
257  bool binary, char lead_ch = ' ')
258  const;
259 };
260 
261 /// Class used to map the GA attribute into a form for H9 geometry files
263 {
264 public:
266 
267  GA_AttribSaveDataH9() : myAttrib(0), myFileAIF(0), myIndexPairAIF(0) {}
269  : myName(src.myName, 1),
270  myAttrib(src.myAttrib),
271  myFileAIF(src.myFileAIF),
272  myIndexPairAIF(src.myIndexPairAIF),
273  myIndex(src.myIndex),
274  mySet(src.mySet),
275  myInfo(src.myInfo)
276  { }
277  GA_AttribSaveDataH9(const GA_Attribute *attrib, const GA_AIFFileH9 *aif, const char *name, int component=0)
278  : myName(name, 1), myAttrib(attrib), myFileAIF(aif), myIndexPairAIF(0), myIndex(), mySet(0), myInfo(aif->getSaveInfo(attrib, component))
279  { }
280  GA_AttribSaveDataH9(const GA_Attribute *attrib, const GA_AIFIndexPair *aif, int idx, int s);
281 
283  {
284  myName.harden(src.myName);
285  myAttrib = src.myAttrib;
286  myFileAIF = src.myFileAIF;
287  myIndexPairAIF = src.myIndexPairAIF;
288  myIndex = src.myIndex;
289  mySet = src.mySet;
290  myInfo = src.myInfo;
291  return *this;
292  }
293 
294  const SaveInfo &getInfo() const { return myInfo; }
295  const char *getName() const { return myName; }
296  bool saveData(
298  std::ostream &os,
299  bool binary) const;
300  bool saveStrings(
301  std::ostream &os,
302  bool binary) const;
303  bool saveDefaults(
304  std::ostream &os,
305  bool binary) const;
306 
307 private:
308  UT_String myName;
309  const GA_Attribute *myAttrib;
310  const GA_AIFFileH9 *myFileAIF;
311  const GA_AIFIndexPair *myIndexPairAIF;
312  int myIndex;
313  int mySet;
314  SaveInfo myInfo;
315 };
316 
317 /// Class used to map H9 geometry files to a form used by GA
319 {
320 public:
322 
323  GA_AttribLoadDataH9() : myAttrib(0), myFileAIF(0)
324  { }
326  : myAttrib(src.myAttrib),
327  myFileAIF(src.myFileAIF),
328  myInfo(src.myInfo)
329  { }
331  const LoadInfo &info)
332  : myAttrib(attrib), myFileAIF(aif), myInfo(info)
333  { }
335  { }
336 
338  {
339  myAttrib = src.myAttrib;
340  myFileAIF = src.myFileAIF;
341  myInfo = src.myInfo;
342  return *this;
343  }
344 
345  GA_Attribute *getAttribute() const { return myAttrib; }
346  const GA_AIFFileH9 *getFileAIF() const { return myFileAIF; }
347  const LoadInfo &getInfo() const { return myInfo; }
348  UT_IntArray &getStringMap() { return myInfo.getStringMap();}
349 
350 private:
351  GA_Attribute *myAttrib;
352  const GA_AIFFileH9 *myFileAIF;
353  LoadInfo myInfo;
354 };
355 
356 #endif
AttribType getType() const
Definition: GA_AIFFileH9.h:115
GA_Attribute * getAttribute() const
Definition: GA_AIFFileH9.h:345
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
Class used to cache information during the H9 save process.
Definition: GA_AIFFileH9.h:142
Generic Attribute Interface class to get/set data as index pairs.
SaveInfo(const SaveInfo &src)
Definition: GA_AIFFileH9.h:84
const GA_AIFIndexPair * getIndexPairAIF() const
Definition: GA_AIFFileH9.h:126
Class which stores the default values for a GA_Attribute.
Definition: GA_Defaults.h:35
const GA_AIFSharedStringTuple * getStringTupleAIF() const
Definition: GA_AIFFileH9.h:178
AttribTypeInfo getTypeInfo() const
Definition: GA_AIFFileH9.h:116
GA_AIFDefinition< GA_AIFFileH9 > Definition
Definition: GA_AIFFileH9.h:47
UT_IntArray & getStringMap()
Definition: GA_AIFFileH9.h:348
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
UT_IntArray & getStringMap()
Definition: GA_AIFFileH9.h:119
GA_AttribSaveDataH9 & operator=(const GA_AttribSaveDataH9 &src)
Definition: GA_AIFFileH9.h:282
const GA_AIFTuple * getTupleAIF() const
Definition: GA_AIFFileH9.h:176
~GA_AIFFileH9() override
Definition: GA_AIFFileH9.h:50
const GA_AIFIndexPair * getIndexPairAIF() const
Definition: GA_AIFFileH9.h:180
GA_AIFFileH9::SaveInfo SaveInfo
Definition: GA_AIFFileH9.h:265
LoadInfo(const LoadInfo &src)
Definition: GA_AIFFileH9.h:150
GLdouble s
Definition: glad.h:3009
Class used to map H9 geometry files to a form used by GA.
Definition: GA_AIFFileH9.h:318
const GA_AIFSharedStringTuple * getStringTupleAIF() const
Definition: GA_AIFFileH9.h:124
#define GA_API
Definition: GA_API.h:14
const UT_IntArray & getStringMap() const
Definition: GA_AIFFileH9.h:173
AttribTypeInfo getTypeInfo() const
Definition: GA_AIFFileH9.h:171
const SaveInfo & getInfo() const
Definition: GA_AIFFileH9.h:294
GA_Size GA_Offset
Definition: GA_Types.h:646
LoadInfo(AttribType type, AttribTypeInfo type_info, int tuple_size, const GA_AIFTuple *tuple, const GA_AIFSharedStringTuple *sindex, const GA_AIFIndexPair *ipair)
Definition: GA_AIFFileH9.h:160
int getComponent() const
Definition: GA_AIFFileH9.h:120
GLintptr offset
Definition: glcorearb.h:665
A common base class for all client-registered AIF classes.
GA_AttribSaveDataH9(const GA_AttribSaveDataH9 &src)
Definition: GA_AIFFileH9.h:268
GA_AttribLoadDataH9(GA_Attribute *attrib, const GA_AIFFileH9 *aif, const LoadInfo &info)
Definition: GA_AIFFileH9.h:330
GA_AttribLoadDataH9(const GA_AttribLoadDataH9 &src)
Definition: GA_AIFFileH9.h:325
GA_AIFFileH9::LoadInfo LoadInfo
Definition: GA_AIFFileH9.h:321
const LoadInfo & getInfo() const
Definition: GA_AIFFileH9.h:347
GLuint const GLchar * name
Definition: glcorearb.h:786
AttribType getType() const
Definition: GA_AIFFileH9.h:170
GA_AttribSaveDataH9(const GA_Attribute *attrib, const GA_AIFFileH9 *aif, const char *name, int component=0)
Definition: GA_AIFFileH9.h:277
Attribute Interface for file I/O.
Definition: GA_AIFFileH9.h:44
AttribType
Data types stored in Houdini 9 data files.
Definition: GA_AIFFileH9.h:53
const GA_AIFTuple * getTupleAIF() const
Definition: GA_AIFFileH9.h:122
const char * getName() const
Definition: GA_AIFFileH9.h:295
Class to allow custom AIF interfaces to be built.
int getTupleSize() const
Definition: GA_AIFFileH9.h:117
A specialization of GA_AIFStringTuple to access "shared strings".
UT_IntArray & getStringMap()
Definition: GA_AIFFileH9.h:174
int getTupleSize() const
Definition: GA_AIFFileH9.h:172
Class used to map the GA attribute into a form for H9 geometry files.
Definition: GA_AIFFileH9.h:262
const UT_IntArray & getStringMap() const
Definition: GA_AIFFileH9.h:118
AttribTypeInfo
Attribute type modifiers stored in Houdini 9 data files.
Definition: GA_AIFFileH9.h:66
Class used to cache information during the H9 save process.
Definition: GA_AIFFileH9.h:76
SaveInfo(AttribType type, AttribTypeInfo type_info, int tuple_size, const GA_AIFTuple *tuple, const GA_AIFSharedStringTuple *sindex, const GA_AIFIndexPair *ipair, int component)
Definition: GA_AIFFileH9.h:95
LoadInfo & operator=(const LoadInfo &src)
Definition: GA_AIFFileH9.h:182
type
Definition: core.h:1059
Generic Attribute Interface class to access an attribute as a tuple.
Definition: GA_AIFTuple.h:32
GA_AttribLoadDataH9 & operator=(const GA_AttribLoadDataH9 &src)
Definition: GA_AIFFileH9.h:337
const GA_AIFFileH9 * getFileAIF() const
Definition: GA_AIFFileH9.h:346
SaveInfo & operator=(const SaveInfo &src)
Definition: GA_AIFFileH9.h:102
GLenum src
Definition: glcorearb.h:1793