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