HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GABC_IArray.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) COPYRIGHTYEAR
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  */
27 
28 #ifndef __GABC_IArray__
29 #define __GABC_IArray__
30 
31 #include "GABC_API.h"
32 #include "GABC_Include.h"
33 #include "GABC_IItem.h"
34 #include "GABC_IArchive.h"
35 #include "GABC_GTUtil.h"
36 #include <UT/UT_Assert.h>
37 #include <GT/GT_Types.h>
38 #include <Alembic/Abc/IArchive.h>
39 
40 namespace GABC_NAMESPACE
41 {
42 
43 /// This class wraps an Alembic data array and provides convenience methods
44 /// that allow thread-safe access to its data.
45 ///
46 /// Do not grab and hold onto the contained data array as this may cause
47 /// referencing issues on archives.
49 {
50 public:
57 
58  /// Create an array wrapper for the given array sample with the specified
59  /// GT_Type as the interpretation.
60  static GABC_IArray getSample(GABC_IArchive &arch,
61  const ArraySamplePtr &sample, GT_Type type, int array_extent,
62  bool is_constant);
63 
65  const IArrayProperty &prop, index_t index,
67  {
68  return getSample(arch, prop, ISampleSelector(index), type);
69  }
71  const IArrayProperty &prop, chrono_t time,
73  {
74  return getSample(arch, prop, ISampleSelector(time), type);
75  }
76  // If a type is specified, the implicit array type will be overridden
77  static GABC_IArray getSample(GABC_IArchive &arch,
78  const IArrayProperty &prop, const ISampleSelector &iss,
79  GT_Type type);
80 
82  : GABC_IItem()
83  , myContainer()
84  , mySize(0)
85  , myTupleSize(0)
86  , myType(GT_TYPE_NONE)
87  , myIsConstant(false)
88  {
89  }
91  : GABC_IItem(src)
92  , myContainer(src.myContainer)
93  , mySize(src.mySize)
94  , myTupleSize(src.myTupleSize)
95  , myType(src.myType)
96  , myIsConstant(src.myIsConstant)
97  {
98  }
100  const ArraySamplePtr &array,
101  GT_Size size,
102  int tuple_size,
104  GT_Type tinfo,
105  bool is_constant)
106  : GABC_IItem(&archive)
107  , myContainer(array)
108  , mySize(size)
109  , myTupleSize(tuple_size)
110  , myType(tinfo)
111  , myIsConstant(is_constant)
112  {
113  }
114  virtual ~GABC_IArray();
115 
117  {
119  myContainer = src.myContainer;
120  mySize = src.mySize;
121  myTupleSize = src.myTupleSize;
122  myType = src.myType;
123  return *this;
124  }
125 
126  bool valid() const { return myContainer.valid(); }
127 
128  class Container
129  {
130  public:
132  : myArray()
133  {
134  }
135  Container(const ArraySamplePtr &array)
136  : myArray(array)
137  {
138  }
139  bool valid() const
140  {
141  return myArray && myArray->valid();
142  }
144  {
145  myArray = src.myArray;
146  return *this;
147  }
148  const void *data() const
149  {
150  UT_ASSERT(myArray);
151  return myArray->getData();
152  }
154  {
155  UT_ASSERT(myArray);
156  return myArray->getDataType().getPod();
157  }
158  private:
159  ArraySamplePtr myArray;
160  };
161 
162  const void *data() const { return myContainer.data(); }
163  PlainOldDataType abcType() const { return myContainer.abcType(); }
164  int tupleSize() const
165  { return myTupleSize; }
166  GT_Size entries() const { return mySize; }
167  GT_Type gtType() const { return myType; }
168  bool isConstant() const { return myIsConstant; }
169 
170  /// @{
171  virtual void purge();
172  /// @}
173 
174 private:
175  Container myContainer;
176  GT_Size mySize;
177  int myTupleSize;
178  GT_Type myType;
179  bool myIsConstant;
180 };
181 
182 }
183 
184 #endif
GT_Storage
Definition: GT_Types.h:17
PlainOldDataType abcType() const
Definition: GABC_IArray.h:163
GT_API const UT_StringHolder time
Alembic::Abc::ArraySamplePtr ArraySamplePtr
Definition: GABC_IArray.h:53
GT_Type
Definition: GT_Types.h:33
Container(const ArraySamplePtr &array)
Definition: GABC_IArray.h:135
const void * data() const
Definition: GABC_IArray.h:162
GLsizeiptr size
Definition: glcorearb.h:663
#define GABC_NAMESPACE
Definition: GABC_API.h:42
Alembic::Util::shared_ptr< ArraySample > ArraySamplePtr
Definition: ArraySample.h:138
Alembic::Abc::index_t index_t
Definition: GABC_IArray.h:51
Alembic::Abc::chrono_t chrono_t
Definition: GABC_IArray.h:52
GT_Size entries() const
Definition: GABC_IArray.h:166
static GABC_IArray getSample(GABC_IArchive &arch, const IArrayProperty &prop, chrono_t time, GT_Type type=GT_TYPE_NONE)
Definition: GABC_IArray.h:70
GT_Type gtType() const
Definition: GABC_IArray.h:167
static GABC_IArray getSample(GABC_IArchive &arch, const IArrayProperty &prop, index_t index, GT_Type type=GT_TYPE_NONE)
Definition: GABC_IArray.h:64
Container & operator=(const Container &src)
Definition: GABC_IArray.h:143
GABC_IItem & operator=(const GABC_IItem &src)
Definition: GABC_IItem.h:53
GABC_IArray & operator=(const GABC_IArray &src)
Definition: GABC_IArray.h:116
PlainOldDataType abcType() const
Definition: GABC_IArray.h:153
GLuint index
Definition: glcorearb.h:785
#define GABC_API
Definition: GABC_API.h:37
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:126
GABC_IArray(GABC_IArchive &archive, const ArraySamplePtr &array, GT_Size size, int tuple_size, GT_Storage storage, GT_Type tinfo, bool is_constant)
Definition: GABC_IArray.h:99
int64 GT_Size
Definition: GT_Types.h:112
Alembic::Abc::PlainOldDataType PlainOldDataType
Definition: GABC_IArray.h:56
GABC_IArray(const GABC_IArray &src)
Definition: GABC_IArray.h:90
GLenum src
Definition: glcorearb.h:1792