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