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  };
169 
170  UT_StringHolder getAttributes(const GEO_PackedNameMapPtr &namemap,
171  int load_style,
172  GT_Owner owner) const;
173 
174  UT_StringHolder getFaceSets(const UT_StringHolder &attrib, fpreal t, int load_style) const;
175 
176  /// Get a representation of the shape. If the @c GEO_Primitive pointer is
177  /// non-NULL, the primitive attributes will be added as GT arrays.
178  GT_PrimitiveHandle getPrimitive(const GEO_Primitive *prim,
179  fpreal t,
180  GEO_AnimationType &atype,
181  const GEO_PackedNameMapPtr &namemap,
182  const UT_StringHolder &facesetAttrib,
183  int load_style=GABC_LOAD_FULL) const;
184 
185  /// Update primitive time. Given a primitive created by @c getPrimitive(),
186  /// update the transform/attribute arrays with values from the new time.
187  GT_PrimitiveHandle updatePrimitive(const GT_PrimitiveHandle &src,
188  const GEO_Primitive *prim,
189  fpreal new_time,
190  const GEO_PackedNameMapPtr &namemap,
191  const UT_StringHolder &facesetAttrib,
192  int load_style=GABC_LOAD_FULL) const;
193 
194  /// Get a representation of the point cloud. This doesn't include any
195  /// attributes.
196  GT_PrimitiveHandle getPointCloud(fpreal t, GEO_AnimationType &a) const;
197 
198  /// Get a representation of the bounding box. This doesn't include any
199  /// attributes.
200  GT_PrimitiveHandle getBoxGeometry(fpreal t, GEO_AnimationType &a) const;
201 
202  /// Get a point for the centroid of the bounding box. This doesn't include
203  /// any attributes.
204  GT_PrimitiveHandle getCentroidGeometry(fpreal t, GEO_AnimationType &a) const;
205 
206  /// Get local transform for the object. For shape objects, this will
207  /// return an identity transform. The animation type only considers the
208  /// local transform (not all the parent transforms).
209  ///
210  /// The transform will be blended between samples if the time doesn't align
211  /// perfectly with a sample point.
212  bool getLocalTransform(UT_Matrix4D &xform, fpreal t,
213  GEO_AnimationType &atype,
214  bool &inherits) const;
215 
216  /// Get world transform for the object. The animation type includes all
217  /// parent transforms.
218  ///
219  /// The transform will be blended between samples if the time doesn't align
220  /// perfectly with a sample point.
221  bool getWorldTransform(UT_Matrix4D &xform, fpreal t,
222  GEO_AnimationType &atype) const;
223 
224  /// Check whether the transform (or parent transforms) is animated
225  bool isTransformAnimated() const;
226 
227  /// Query the number of geometry properties
228  exint getNumGeometryProperties() const;
229  /// Lookup the data array for the Nth geometry property at the given time.
230  /// - The @c name parameter is filled out with the property name
231  /// - The @c scope parameter is filled out with the property scope
232  /// - The @c atype parameter is filled out with the animation type
233  GT_DataArrayHandle getGeometryProperty(exint index, fpreal t,
234  std::string &name,
235  GeometryScope &scope,
236  GEO_AnimationType &atype) const;
237 
238  /// Convert an arbitrary property to a GT_DataArray. This handles indexed
239  /// array types as well as straight data types.
240  ///
241  /// This is a convenience method to extract an array given the compound
242  /// property and the property header.
243  ///
244  /// If supplied, the animation type is filled out.
245  GT_DataArrayHandle convertIProperty(ICompoundProperty &arb,
246  const PropertyHeader &head,
247  fpreal time,
248  const GEO_PackedNameMapPtr &namemap,
249  GEO_AnimationType *atype=NULL,
250  exint expected_size=-1) const;
251 
252  /// Get position property from shape node
253  GT_DataArrayHandle getPosition(fpreal t, GEO_AnimationType &atype) const;
254  /// Get velocity property from shape node
255  GT_DataArrayHandle getVelocity(fpreal t, GEO_AnimationType &atype) const;
256  /// Get the width property from the shape node (curves/points)
257  GT_DataArrayHandle getWidth(fpreal t, GEO_AnimationType &atype) const;
258 
259  /// Lookup the data array for the named geometry property at the given time.
260  /// - The @c scope parameter is filled out with the property scope
261  /// - The @c atype parameter is filled out with the animation type
262  GT_DataArrayHandle getGeometryProperty(const std::string &name, fpreal t,
263  GeometryScope &scope,
264  GEO_AnimationType &atype) const;
265 
266  /// Get number of user properties for this node
267  exint getNumUserProperties() const;
268  /// Lookup the data array for the Nth geometry property at the given time.
269  /// - The @c name parameter is filled out with the property name
270  /// - The @c atype parameter is filled out with the animation type
271  GT_DataArrayHandle getUserProperty(exint index, fpreal t,
272  std::string &name,
273  GEO_AnimationType &atype) const;
274  /// Lookup the data array for the Nth geometry property at the given time.
275  /// - The @c name parameter is filled out with the property name
276  /// - The @c atype parameter is filled out with the animation type
277  GT_DataArrayHandle getUserProperty(const std::string &name, fpreal t,
278  GEO_AnimationType &atype) const;
279 
280  /// Access the time sampling pointer
281  TimeSamplingPtr timeSampling() const;
282 
283  exint numSamples() const;
284 
285  /// Clamp the time to the animated time range
286  fpreal clampTime(fpreal input_time) const;
287 
288  /// @{
289  /// Get the world transform for the node. This includes all it's parent
290  /// transforms.
291  bool worldTransform(fpreal t,
292  UT_Matrix4D &xform,
293  bool &isConstant,
294  bool &inheritsXform) const;
295  bool worldTransform(fpreal t,
296  M44d &xform,
297  bool &isConstant,
298  bool &inheritsXform) const;
299  /// @}
300 
301  /// @{
302  /// Get the local transform for the node. This is an identity matrix
303  bool localTransform(fpreal t,
304  UT_Matrix4D &xform,
305  bool &isConstant,
306  bool &inheritsXform) const;
307  bool localTransform(fpreal t,
308  M44d &xform,
309  bool &isConstant,
310  bool &inheritsXform) const;
311  /// @}
312 
313  /// Alembic's 128b prop hash wang'hashed to 64b. Returns false if no hash
314  /// exists (getPropertiesHash() returns false, such as for HDF5).
315  bool getPropertiesHash(int64 &hash) const;
316 
317  /// @{
318  /// Member data access
319  const std::string &objectPath() const { return myObjectPath; }
320  const IObject &object() const { return myObject; }
321  /// @}
322 
323  /// Get the user properties for this node
324  ICompoundProperty getUserProperties() const;
325 
326 private:
327  ICompoundProperty getArbGeomParams() const;
328  void setObject(const IObject &o) { myObject = o; }
329 
330  std::string myObjectPath;
331  IObject myObject;
332 
333  friend class GABC_IArchive;
334 };
335 }
336 
337 #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:320
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:319
GABC_IObject getParent() const
Get the parent.
Definition: GABC_IObject.h:92
GLenum src
Definition: glcorearb.h:1792