HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GABC_IObject.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_IObject__
29 #define __GABC_IObject__
30 
31 #include "GABC_API.h"
32 #include "GABC_Include.h"
33 #include "GABC_Types.h"
34 #include "GABC_IItem.h"
35 #include <GEO/GEO_PackedNameMap.h>
36 #include <UT/UT_Matrix4.h>
37 #include <UT/UT_BoundingBox.h>
38 #include <GT/GT_DataArray.h>
39 #include <GT/GT_Handles.h>
40 #include <Alembic/Abc/IObject.h>
42 
43 class GEO_Primitive;
44 class UT_StringArray;
45 
46 namespace GABC_NAMESPACE
47 {
48 
50 {
54 };
55 
56 /// This class wraps an Alembic IObject and provides convenience methods that
57 /// allow thread-safe access to its data.
58 ///
59 /// Do not grab and hold onto the contained IObject as this may cause
60 /// referencing issues on archives.
62 {
63 public:
72 
73  GABC_IObject();
74  GABC_IObject(const GABC_IObject &obj);
75  GABC_IObject(const GABC_IArchivePtr &arch, const IObject &obj);
76  virtual ~GABC_IObject();
77 
78  /// Initialize (called by GABC_IArchive)
79  static void init();
80 
81  /// Return the number of children
82  exint getNumChildren() const;
83 
84  /// @{
85  /// Get the given child
86  GABC_IObject getChild(exint index) const;
87  GABC_IObject getChild(const std::string &name) const;
88  /// @}
89 
90  /// Get the parent
92  {
93  if (!valid())
94  return GABC_IObject();
95  return GABC_IObject(archive(),object().getParent());
96  }
97 
98  /// Get my header
99  const ObjectHeader &getHeader() const
100  { return object().getHeader(); }
101  /// Get the child header
103  { return object().getChildHeader(i); }
104 
105  /// Get the name of the object
106  std::string getName() const { return myObject.getName(); }
107 
108  /// Get the full name of the object
109  const std::string &getFullName() const { return myObjectPath; }
110 
111  /// Get the source of instanced geometry. The path to this object is
112  /// returned if the geometry is not instanced.
113  std::string getSourcePath() const;
114 
115  /// Get the number of points in the shape
116  exint getPointCount(fpreal t) const;
117 
118  /// @{
119  /// Interface from GABC_IItem
120  virtual void purge();
121  /// @}
122 
123  /// Test validity
124  bool valid() const { return myObject.valid(); }
125 
126  /// Assignment operator
127  GABC_IObject &operator=(const GABC_IObject &src);
128 
129  /// Query the type of this node
130  GABC_NodeType nodeType() const;
131  /// Query the type of a child node
132  GABC_NodeType getChildNodeType(exint i) const;
133 
134  /// Query whether the node is a Maya locator
135  bool isMayaLocator() const;
136 
137  /// Query visibility
138  GABC_VisibilityType visibility(bool &animated, fpreal t,
139  bool check_parent=false) const;
140 
141  /// Get animation type for this node.
142  /// @note This only checks animation types of intrinsic properties
143  GEO_AnimationType getAnimationType(bool include_transform) const;
144 
145  /// Get the bounding box. Returns false if there are no bounds defined
146  bool getBoundingBox(UT_BoundingBox &box, fpreal t,
147  bool &isConstant) const;
148 
149  /// Get the bounding box for rendering (includes the "width" attribute for
150  /// curves and points).
151  bool getRenderingBoundingBox(UT_BoundingBox &box,
152  fpreal t) const;
153 
154  enum
155  {
156  GABC_LOAD_LEAN_AND_MEAN = 0x00, // Only load intrinsic attributes
157  GABC_LOAD_ARBS = 0x01, // Load arbitrary attributes
158  GABC_LOAD_FACESETS = 0x02, // Load face sets
159  GABC_LOAD_HOUDINI = 0x04, // Load houdini attributes too
160  GABC_LOAD_FULL = 0xff, // Load full geometry
161 
162  // Forcibly load geometry untransformed
163  GABC_LOAD_FORCE_UNTRANSFORMED = 0x1000,
164  // Load regardless of visibility
165  GABC_LOAD_IGNORE_VISIBILITY = 0x2000,
166  // Load an optimized version for GL (single attrib freq, triangulated)
167  GABC_LOAD_GL_OPTIMIZED = 0x4000,
168  GABC_LOAD_USE_GL_CACHE = 0x8000,
169  // Don't bake attributes on the packed prim into the geometry
170  GABC_LOAD_NO_PACKED_ATTRIBS = 0x10000
171  };
172 
173  UT_StringHolder getAttributes(const GEO_PackedNameMapPtr &namemap,
174  int load_style,
175  GT_Owner owner) const;
176 
177  UT_StringHolder getFaceSets(const UT_StringHolder &attrib, fpreal t, int load_style) const;
178 
179  /// Get a representation of the shape. If the @c GEO_Primitive pointer is
180  /// non-NULL, the primitive attributes will be added as GT arrays.
181  GT_PrimitiveHandle getPrimitive(const GEO_Primitive *prim,
182  fpreal t,
183  GEO_AnimationType &atype,
184  const GEO_PackedNameMapPtr &namemap,
185  const UT_StringHolder &facesetAttrib,
186  int load_style=GABC_LOAD_FULL) const;
187 
188  /// Update primitive time. Given a primitive created by @c getPrimitive(),
189  /// update the transform/attribute arrays with values from the new time.
190  GT_PrimitiveHandle updatePrimitive(const GT_PrimitiveHandle &src,
191  const GEO_Primitive *prim,
192  fpreal new_time,
193  const GEO_PackedNameMapPtr &namemap,
194  const UT_StringHolder &facesetAttrib,
195  int load_style=GABC_LOAD_FULL) const;
196 
197  /// Get a representation of the point cloud. This doesn't include any
198  /// attributes.
199  GT_PrimitiveHandle getPointCloud(fpreal t, GEO_AnimationType &a) const;
200 
201  /// Get a representation of the bounding box. This doesn't include any
202  /// attributes.
203  GT_PrimitiveHandle getBoxGeometry(fpreal t, GEO_AnimationType &a) const;
204 
205  /// Get a point for the centroid of the bounding box. This doesn't include
206  /// any attributes.
207  GT_PrimitiveHandle getCentroidGeometry(fpreal t, GEO_AnimationType &a) const;
208 
209  /// Check whether the transform (or parent transforms) is animated
210  bool isTransformAnimated() const;
211 
212  /// Query the number of geometry properties
213  exint getNumGeometryProperties() const;
214  /// Lookup the data array for the Nth geometry property at the given time.
215  /// - The @c name parameter is filled out with the property name
216  /// - The @c scope parameter is filled out with the property scope
217  /// - The @c atype parameter is filled out with the animation type
218  GT_DataArrayHandle getGeometryProperty(exint index, fpreal t,
219  std::string &name,
220  GeometryScope &scope,
221  GEO_AnimationType &atype) const;
222 
223  /// Convert an arbitrary property to a GT_DataArray. This handles indexed
224  /// array types as well as straight data types.
225  ///
226  /// This is a convenience method to extract an array given the compound
227  /// property and the property header.
228  ///
229  /// If supplied, the animation type is filled out.
230  GT_DataArrayHandle convertIProperty(ICompoundProperty &arb,
231  const PropertyHeader &head,
232  fpreal time,
233  const GEO_PackedNameMapPtr &namemap,
234  GEO_AnimationType *atype=NULL,
235  exint expected_size=-1) const;
236 
237  /// Get position property from shape node
238  GT_DataArrayHandle getPosition(fpreal t, GEO_AnimationType &atype) const;
239  /// Get velocity property from shape node
240  GT_DataArrayHandle getVelocity(fpreal t, GEO_AnimationType &atype) const;
241  /// Get the width property from the shape node (curves/points)
242  GT_DataArrayHandle getWidth(fpreal t, GEO_AnimationType &atype) const;
243 
244  /// Lookup the data array for the named geometry property at the given time.
245  /// - The @c scope parameter is filled out with the property scope
246  /// - The @c atype parameter is filled out with the animation type
247  GT_DataArrayHandle getGeometryProperty(const std::string &name, fpreal t,
248  GeometryScope &scope,
249  GEO_AnimationType &atype) const;
250 
251  /// Get number of user properties for this node
252  exint getNumUserProperties() const;
253  /// Lookup the data array for the Nth geometry property at the given time.
254  /// - The @c name parameter is filled out with the property name
255  /// - The @c atype parameter is filled out with the animation type
256  GT_DataArrayHandle getUserProperty(exint index, fpreal t,
257  std::string &name,
258  GEO_AnimationType &atype) const;
259  /// Lookup the data array for the Nth geometry property at the given time.
260  /// - The @c name parameter is filled out with the property name
261  /// - The @c atype parameter is filled out with the animation type
262  GT_DataArrayHandle getUserProperty(const std::string &name, fpreal t,
263  GEO_AnimationType &atype) const;
264 
265  /// Access the time sampling pointer
266  TimeSamplingPtr timeSampling() const;
267 
268  exint numSamples() const;
269 
270  /// Clamp the time to the animated time range
271  fpreal clampTime(fpreal input_time) const;
272 
273  /// @{
274  /// Get the local transform for the node. This is an identity matrix
275  bool localTransform(fpreal t,
276  UT_Matrix4D &xform,
277  bool &isConstant,
278  bool &inheritsXform) const;
279  bool localTransform(fpreal t,
280  M44d &xform,
281  bool &isConstant,
282  bool &inheritsXform) const;
283  /// @}
284 
285  /// Alembic's 128b prop hash wang'hashed to 64b. Returns false if no hash
286  /// exists (getPropertiesHash() returns false, such as for HDF5).
287  bool getPropertiesHash(int64 &hash) const;
288 
289  /// @{
290  /// Member data access
291  const IObject &object() const { return myObject; }
292  /// @}
293 
294  /// Get the user properties for this node
295  ICompoundProperty getUserProperties() const;
296 
297 private:
298  ICompoundProperty getArbGeomParams() const;
299  void setObject(const IObject &o) { myObject = o; }
300 
301  std::string myObjectPath;
302  IObject myObject;
303 
304  friend class GABC_IArchive;
305 };
306 }
307 
308 #endif
GT_API const UT_StringHolder time
Alembic::Abc::TimeSamplingPtr TimeSamplingPtr
Definition: GABC_IObject.h:69
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
Alembic::Abc::CompoundPropertyReaderPtr CompoundPropertyReaderPtr
Definition: GABC_IObject.h:71
png_uint_32 i
Definition: png.h:2877
Matrix44< double > M44d
Definition: ImathMatrix.h:866
#define GABC_NAMESPACE
Definition: GABC_API.h:42
long long int64
Definition: SYS_Types.h:107
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
std::string getName() const
Get the name of the object.
Definition: GABC_IObject.h:106
bool valid() const
Test validity.
Definition: GABC_IObject.h:124
Alembic::Util::shared_ptr< CompoundPropertyReader > CompoundPropertyReaderPtr
int64 exint
Definition: SYS_Types.h:116
GEO_AnimationType
const IObject & object() const
Definition: GABC_IObject.h:291
GLuint const GLchar * name
Definition: glcorearb.h:785
Alembic::Abc::M44d M44d
Definition: GABC_IObject.h:64
const std::string & getFullName() const
Get the full name of the object.
Definition: GABC_IObject.h:109
GT_Owner
Definition: GT_Types.h:75
double fpreal
Definition: SYS_Types.h:270
GLuint index
Definition: glcorearb.h:785
#define GABC_API
Definition: GABC_API.h:37
const ObjectHeader & getHeader() const
Get my header.
Definition: GABC_IObject.h:99
const ObjectHeader & getChildHeader(exint i) const
Get the child header.
Definition: GABC_IObject.h:102
IMF_EXPORT int numSamples(int s, int a, int b)
GABC_IObject getParent() const
Get the parent.
Definition: GABC_IObject.h:91
GLenum src
Definition: glcorearb.h:1792