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_Types.h"
33 #include "GABC_IItem.h"
34 #include <GEO/GEO_PackedNameMap.h>
35 #include <GA/GA_Types.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 GA_Detail;
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() override;
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  void purge() override;
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 GA_Detail pointer is
180  /// non-NULL, the primitive attributes will be added as GT arrays.
181  GT_PrimitiveHandle getPrimitive(
182  const GA_Detail *gdp,
183  const GA_Offset primoff,
184  fpreal t,
185  GEO_AnimationType &atype,
186  const GEO_PackedNameMapPtr &namemap,
187  const UT_StringHolder &facesetAttrib,
188  int load_style=GABC_LOAD_FULL) const;
189 
190  /// Update primitive time. Given a primitive created by @c getPrimitive(),
191  /// update the transform/attribute arrays with values from the new time.
192  GT_PrimitiveHandle updatePrimitive(
193  const GT_PrimitiveHandle &src,
194  const GA_Detail *gdp,
195  const GA_Offset primoff,
196  fpreal new_time,
197  const GEO_PackedNameMapPtr &namemap,
198  const UT_StringHolder &facesetAttrib,
199  int load_style=GABC_LOAD_FULL) const;
200 
201  /// Get a representation of the point cloud. This doesn't include any
202  /// attributes.
203  GT_PrimitiveHandle getPointCloud(fpreal t, GEO_AnimationType &a) const;
204 
205  /// Get a representation of the bounding box. This doesn't include any
206  /// attributes.
207  GT_PrimitiveHandle getBoxGeometry(fpreal t, GEO_AnimationType &a) const;
208 
209  /// Get a point for the centroid of the bounding box. This doesn't include
210  /// any attributes.
211  GT_PrimitiveHandle getCentroidGeometry(fpreal t, GEO_AnimationType &a) const;
212 
213  /// Check whether the transform (or parent transforms) is animated
214  bool isTransformAnimated() const;
215 
216  /// Query the number of geometry properties
217  exint getNumGeometryProperties() const;
218  /// Lookup the data array for the Nth geometry property at the given time.
219  /// - The @c name parameter is filled out with the property name
220  /// - The @c scope parameter is filled out with the property scope
221  /// - The @c atype parameter is filled out with the animation type
222  GT_DataArrayHandle getGeometryProperty(exint index, fpreal t,
223  std::string &name,
224  GeometryScope &scope,
225  GEO_AnimationType &atype) const;
226 
227  /// Convert an arbitrary property to a GT_DataArray. This handles indexed
228  /// array types as well as straight data types.
229  ///
230  /// This is a convenience method to extract an array given the compound
231  /// property and the property header.
232  ///
233  /// If supplied, the animation type is filled out.
234  GT_DataArrayHandle convertIProperty(ICompoundProperty &arb,
235  const PropertyHeader &head,
236  fpreal time,
237  const GEO_PackedNameMapPtr &namemap,
238  GEO_AnimationType *atype=NULL,
239  exint expected_size=-1) const;
240 
241  /// Get position property from shape node
242  GT_DataArrayHandle getPosition(fpreal t, GEO_AnimationType &atype) const;
243  /// Get velocity property from shape node
244  GT_DataArrayHandle getVelocity(fpreal t, GEO_AnimationType &atype) const;
245  /// Get the width property from the shape node (curves/points)
246  GT_DataArrayHandle getWidth(fpreal t, GEO_AnimationType &atype) const;
247 
248  /// Lookup the data array for the named geometry property at the given time.
249  /// - The @c scope parameter is filled out with the property scope
250  /// - The @c atype parameter is filled out with the animation type
251  GT_DataArrayHandle getGeometryProperty(const std::string &name, fpreal t,
252  GeometryScope &scope,
253  GEO_AnimationType &atype) const;
254 
255  /// Get number of user properties for this node
256  exint getNumUserProperties() const;
257  /// Lookup the data array for the Nth geometry property at the given time.
258  /// - The @c name parameter is filled out with the property name
259  /// - The @c atype parameter is filled out with the animation type
260  GT_DataArrayHandle getUserProperty(exint index, fpreal t,
261  std::string &name,
262  GEO_AnimationType &atype) const;
263  /// Lookup the data array for the Nth geometry property at the given time.
264  /// - The @c name parameter is filled out with the property name
265  /// - The @c atype parameter is filled out with the animation type
266  GT_DataArrayHandle getUserProperty(const std::string &name, fpreal t,
267  GEO_AnimationType &atype) const;
268 
269  /// Access the time sampling pointer
270  TimeSamplingPtr timeSampling() const;
271 
272  exint numSamples() const;
273 
274  /// Clamp the time to the animated time range
275  fpreal clampTime(fpreal input_time) const;
276 
277  /// @{
278  /// Get the local transform for the node. This is an identity matrix
279  bool localTransform(fpreal t,
280  UT_Matrix4D &xform,
281  bool &isConstant,
282  bool &inheritsXform) const;
283  bool localTransform(fpreal t,
284  M44d &xform,
285  bool &isConstant,
286  bool &inheritsXform) const;
287  /// @}
288 
289  /// Alembic's 128b prop hash wang'hashed to 64b. Returns false if no hash
290  /// exists (getPropertiesHash() returns false, such as for HDF5).
291  bool getPropertiesHash(int64 &hash) const;
292 
293  /// @{
294  /// Member data access
295  const IObject &object() const { return myObject; }
296  /// @}
297 
298  /// Get the user properties for this node
299  ICompoundProperty getUserProperties() const;
300 
301  /// Get the aggregated child objects hash if it exists
302  std::string getChildrenHash() const;
303 
304 private:
305  ICompoundProperty getArbGeomParams() const;
306  void setObject(const IObject &o) { myObject = o; }
307 
308  std::string myObjectPath;
309  IObject myObject;
310 
311  friend class GABC_IArchive;
312 };
313 }
314 
315 #endif
GT_API const UT_StringHolder time
Alembic::Abc::TimeSamplingPtr TimeSamplingPtr
Definition: GABC_IObject.h:69
UT_StringArray JOINTS head
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
int64 exint
Definition: SYS_Types.h:125
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
Alembic::Abc::CompoundPropertyReaderPtr CompoundPropertyReaderPtr
Definition: GABC_IObject.h:71
GU_API GA_Offset getParent(const GU_Detail *gdp, const GA_Offset &node)
Matrix44< double > M44d
4x4 matrix of double
Definition: ImathMatrix.h:1140
#define GABC_NAMESPACE
Definition: GABC_API.h:42
GA_Size GA_Offset
Definition: GA_Types.h:641
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
GEO_AnimationType
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
const IObject & object() const
Definition: GABC_IObject.h:295
Alembic::Abc::M44d M44d
Definition: GABC_IObject.h:64
GLdouble t
Definition: glad.h:2397
const std::string & getFullName() const
Get the full name of the object.
Definition: GABC_IObject.h:109
GT_Owner
Definition: GT_Types.h:90
fpreal64 fpreal
Definition: SYS_Types.h:277
GLuint index
Definition: glcorearb.h:786
#define GABC_API
Definition: GABC_API.h:37
Container class for all geometry.
Definition: GA_Detail.h:96
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
GABC_IObject getParent() const
Get the parent.
Definition: GABC_IObject.h:91
GLenum src
Definition: glcorearb.h:1793