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_IItem.h"
33 #include "GABC_IArchive.h"
34 #include "GABC_GTUtil.h"
35 #include <UT/UT_Assert.h>
36 #include <GT/GT_Types.h>
37 #include <Alembic/Abc/IArchive.h>
38 
39 namespace GABC_NAMESPACE
40 {
41 
42 /// This class wraps an Alembic data array and provides convenience methods
43 /// that allow thread-safe access to its data.
44 ///
45 /// Do not grab and hold onto the contained data array as this may cause
46 /// referencing issues on archives.
48 {
49 public:
56 
57  /// Create an array wrapper for the given array sample with the specified
58  /// GT_Type as the interpretation.
59  static GABC_IArray getSample(GABC_IArchive &arch,
60  const ArraySamplePtr &sample, GT_Type type, int array_extent,
61  bool is_constant);
62 
64  const IArrayProperty &prop, index_t index,
66  {
67  return getSample(arch, prop, ISampleSelector(index), type);
68  }
70  const IArrayProperty &prop, chrono_t time,
72  {
73  return getSample(arch, prop, ISampleSelector(time), type);
74  }
75  // If a type is specified, the implicit array type will be overridden
76  static GABC_IArray getSample(GABC_IArchive &arch,
77  const IArrayProperty &prop, const ISampleSelector &iss,
78  GT_Type type);
79 
81  : GABC_IItem()
82  , myContainer()
83  , mySize(0)
84  , myTupleSize(0)
85  , myType(GT_TYPE_NONE)
86  , myIsConstant(false)
87  {
88  }
90  : GABC_IItem(src)
91  , myContainer(src.myContainer)
92  , mySize(src.mySize)
93  , myTupleSize(src.myTupleSize)
94  , myType(src.myType)
95  , myIsConstant(src.myIsConstant)
96  {
97  }
99  const ArraySamplePtr &array,
100  GT_Size size,
101  int tuple_size,
103  GT_Type tinfo,
104  bool is_constant)
105  : GABC_IItem(&archive)
106  , myContainer(array)
107  , mySize(size)
108  , myTupleSize(tuple_size)
109  , myType(tinfo)
110  , myIsConstant(is_constant)
111  {
112  }
113  ~GABC_IArray() override;
114 
116  {
118  myContainer = src.myContainer;
119  mySize = src.mySize;
120  myTupleSize = src.myTupleSize;
121  myType = src.myType;
122  return *this;
123  }
124 
125  bool valid() const { return myContainer.valid(); }
126 
127  class Container
128  {
129  public:
131  : myArray()
132  {
133  }
134  Container(const ArraySamplePtr &array)
135  : myArray(array)
136  {
137  }
138  bool valid() const
139  {
140  return myArray && myArray->valid();
141  }
142  const void *data() const
143  {
144  UT_ASSERT(myArray);
145  return myArray->getData();
146  }
148  {
149  UT_ASSERT(myArray);
150  return myArray->getDataType().getPod();
151  }
152  private:
153  ArraySamplePtr myArray;
154  };
155 
156  const void *data() const { return myContainer.data(); }
157  PlainOldDataType abcType() const { return myContainer.abcType(); }
158  int tupleSize() const
159  { return myTupleSize; }
160  GT_Size entries() const { return mySize; }
161  GT_Type gtType() const { return myType; }
162  bool isConstant() const { return myIsConstant; }
163 
164  /// @{
165  void purge() override;
166  /// @}
167 
168 private:
169  Container myContainer;
170  GT_Size mySize;
171  int myTupleSize;
172  GT_Type myType;
173  bool myIsConstant;
174 };
175 
176 }
177 
178 #endif
GT_Storage
Definition: GT_Types.h:19
PlainOldDataType abcType() const
Definition: GABC_IArray.h:157
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
GT_API const UT_StringHolder time
Alembic::Abc::ArraySamplePtr ArraySamplePtr
Definition: GABC_IArray.h:52
GT_Type
Definition: GT_Types.h:36
Container(const ArraySamplePtr &array)
Definition: GABC_IArray.h:134
const void * data() const
Definition: GABC_IArray.h:156
#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:50
Alembic::Abc::chrono_t chrono_t
Definition: GABC_IArray.h:51
GT_Size entries() const
Definition: GABC_IArray.h:160
static GABC_IArray getSample(GABC_IArchive &arch, const IArrayProperty &prop, chrono_t time, GT_Type type=GT_TYPE_NONE)
Definition: GABC_IArray.h:69
GT_Type gtType() const
Definition: GABC_IArray.h:161
static GABC_IArray getSample(GABC_IArchive &arch, const IArrayProperty &prop, index_t index, GT_Type type=GT_TYPE_NONE)
Definition: GABC_IArray.h:63
int64 GT_Size
Definition: GT_Types.h:128
GLsizeiptr size
Definition: glcorearb.h:664
GABC_IItem & operator=(const GABC_IItem &src)
Definition: GABC_IItem.h:52
GABC_IArray & operator=(const GABC_IArray &src)
Definition: GABC_IArray.h:115
PlainOldDataType abcType() const
Definition: GABC_IArray.h:147
GLuint index
Definition: glcorearb.h:786
#define GABC_API
Definition: GABC_API.h:37
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
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:98
type
Definition: core.h:1059
Alembic::Abc::PlainOldDataType PlainOldDataType
Definition: GABC_IArray.h:55
GABC_IArray(const GABC_IArray &src)
Definition: GABC_IArray.h:89
GLenum src
Definition: glcorearb.h:1793