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 <GA/GA_Types.h>
37 #include <UT/UT_Matrix4.h>
38 #include <UT/UT_BoundingBox.h>
39 #include <GT/GT_DataArray.h>
40 #include <GT/GT_Handles.h>
41 #include <Alembic/Abc/IObject.h>
43 
44 class GA_Detail;
45 class UT_StringArray;
46 
47 namespace GABC_NAMESPACE
48 {
49 
51 {
55 };
56 
57 /// This class wraps an Alembic IObject and provides convenience methods that
58 /// allow thread-safe access to its data.
59 ///
60 /// Do not grab and hold onto the contained IObject as this may cause
61 /// referencing issues on archives.
63 {
64 public:
73 
74  GABC_IObject();
76  GABC_IObject(const GABC_IArchivePtr &arch, const IObject &obj);
77  ~GABC_IObject() override;
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
100  const ObjectHeader &getHeader() const
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  void purge() override;
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  /// Query the type of a child node
133  GABC_NodeType getChildNodeType(exint i) const;
134 
135  /// Query whether the node is a Maya locator
136  bool isMayaLocator() const;
137 
138  /// Query visibility
139  GABC_VisibilityType visibility(bool &animated, fpreal t,
140  bool check_parent=false) const;
141 
142  /// Get animation type for this node.
143  /// @note This only checks animation types of intrinsic properties
144  GEO_AnimationType getAnimationType(bool include_transform) const;
145 
146  /// Get the bounding box. Returns false if there are no bounds defined
147  bool getBoundingBox(UT_BoundingBox &box, fpreal t,
148  bool &isConstant) const;
149 
150  /// Get the bounding box for rendering (includes the "width" attribute for
151  /// curves and points).
152  bool getRenderingBoundingBox(UT_BoundingBox &box,
153  fpreal t) const;
154 
155  enum
156  {
157  GABC_LOAD_LEAN_AND_MEAN = 0x00, // Only load intrinsic attributes
158  GABC_LOAD_ARBS = 0x01, // Load arbitrary attributes
159  GABC_LOAD_FACESETS = 0x02, // Load face sets
160  GABC_LOAD_HOUDINI = 0x04, // Load houdini attributes too
161  GABC_LOAD_FULL = 0xff, // Load full geometry
162 
163  // Forcibly load geometry untransformed
164  GABC_LOAD_FORCE_UNTRANSFORMED = 0x1000,
165  // Load regardless of visibility
166  GABC_LOAD_IGNORE_VISIBILITY = 0x2000,
167  // Load an optimized version for GL (single attrib freq, triangulated)
168  GABC_LOAD_GL_OPTIMIZED = 0x4000,
169  GABC_LOAD_USE_GL_CACHE = 0x8000,
170  // Don't bake attributes on the packed prim into the geometry
171  GABC_LOAD_NO_PACKED_ATTRIBS = 0x10000
172  };
173 
174  UT_StringHolder getAttributes(const GEO_PackedNameMapPtr &namemap,
175  int load_style,
176  GT_Owner owner) const;
177 
178  UT_StringHolder getFaceSets(const UT_StringHolder &attrib, fpreal t, int load_style) const;
179 
180  /// Get a representation of the shape. If the @c GA_Detail pointer is
181  /// non-NULL, the primitive attributes will be added as GT arrays.
182  GT_PrimitiveHandle getPrimitive(
183  const GA_Detail *gdp,
184  const GA_Offset primoff,
185  fpreal t,
186  GEO_AnimationType &atype,
187  const GEO_PackedNameMapPtr &namemap,
188  const UT_StringHolder &facesetAttrib,
189  int load_style=GABC_LOAD_FULL) const;
190 
191  /// Update primitive time. Given a primitive created by @c getPrimitive(),
192  /// update the transform/attribute arrays with values from the new time.
193  GT_PrimitiveHandle updatePrimitive(
194  const GT_PrimitiveHandle &src,
195  const GA_Detail *gdp,
196  const GA_Offset primoff,
197  fpreal new_time,
198  const GEO_PackedNameMapPtr &namemap,
199  const UT_StringHolder &facesetAttrib,
200  int load_style=GABC_LOAD_FULL) const;
201 
202  /// Get a representation of the point cloud. This doesn't include any
203  /// attributes.
204  GT_PrimitiveHandle getPointCloud(fpreal t, GEO_AnimationType &a) const;
205 
206  /// Get a representation of the bounding box. This doesn't include any
207  /// attributes.
208  GT_PrimitiveHandle getBoxGeometry(fpreal t, GEO_AnimationType &a) const;
209 
210  /// Get a point for the centroid of the bounding box. This doesn't include
211  /// any attributes.
212  GT_PrimitiveHandle getCentroidGeometry(fpreal t, GEO_AnimationType &a) const;
213 
214  /// Check whether the transform (or parent transforms) is animated
215  bool isTransformAnimated() const;
216 
217  /// Query the number of geometry properties
218  exint getNumGeometryProperties() const;
219  /// Lookup the data array for the Nth geometry property at the given time.
220  /// - The @c name parameter is filled out with the property name
221  /// - The @c scope parameter is filled out with the property scope
222  /// - The @c atype parameter is filled out with the animation type
223  GT_DataArrayHandle getGeometryProperty(exint index, fpreal t,
224  std::string &name,
225  GeometryScope &scope,
226  GEO_AnimationType &atype) const;
227 
228  /// Convert an arbitrary property to a GT_DataArray. This handles indexed
229  /// array types as well as straight data types.
230  ///
231  /// This is a convenience method to extract an array given the compound
232  /// property and the property header.
233  ///
234  /// If supplied, the animation type is filled out.
235  GT_DataArrayHandle convertIProperty(ICompoundProperty &arb,
236  const PropertyHeader &head,
237  fpreal time,
238  const GEO_PackedNameMapPtr &namemap,
239  GEO_AnimationType *atype=NULL,
240  exint expected_size=-1) const;
241 
242  /// Get position property from shape node
243  GT_DataArrayHandle getPosition(fpreal t, GEO_AnimationType &atype) const;
244  /// Get velocity property from shape node
245  GT_DataArrayHandle getVelocity(fpreal t, GEO_AnimationType &atype) const;
246  /// Get the width property from the shape node (curves/points)
247  GT_DataArrayHandle getWidth(fpreal t, GEO_AnimationType &atype) const;
248 
249  /// Lookup the data array for the named geometry property at the given time.
250  /// - The @c scope parameter is filled out with the property scope
251  /// - The @c atype parameter is filled out with the animation type
252  GT_DataArrayHandle getGeometryProperty(const std::string &name, fpreal t,
253  GeometryScope &scope,
254  GEO_AnimationType &atype) const;
255 
256  /// Get number of user properties for this node
257  exint getNumUserProperties() const;
258  /// Lookup the data array for the Nth geometry property at the given time.
259  /// - The @c name parameter is filled out with the property name
260  /// - The @c atype parameter is filled out with the animation type
261  GT_DataArrayHandle getUserProperty(exint index, fpreal t,
262  std::string &name,
263  GEO_AnimationType &atype) const;
264  /// Lookup the data array for the Nth geometry property at the given time.
265  /// - The @c name parameter is filled out with the property name
266  /// - The @c atype parameter is filled out with the animation type
267  GT_DataArrayHandle getUserProperty(const std::string &name, fpreal t,
268  GEO_AnimationType &atype) const;
269 
270  /// Access the time sampling pointer
271  TimeSamplingPtr timeSampling() const;
272 
273  exint numSamples() const;
274 
275  /// Clamp the time to the animated time range
276  fpreal clampTime(fpreal input_time) const;
277 
278  /// @{
279  /// Get the local transform for the node. This is an identity matrix
280  bool localTransform(fpreal t,
281  UT_Matrix4D &xform,
282  bool &isConstant,
283  bool &inheritsXform) const;
284  bool localTransform(fpreal t,
285  M44d &xform,
286  bool &isConstant,
287  bool &inheritsXform) const;
288  /// @}
289 
290  /// Alembic's 128b prop hash wang'hashed to 64b. Returns false if no hash
291  /// exists (getPropertiesHash() returns false, such as for HDF5).
292  bool getPropertiesHash(int64 &hash) const;
293 
294  /// @{
295  /// Member data access
296  const IObject &object() const { return myObject; }
297  /// @}
298 
299  /// Get the user properties for this node
300  ICompoundProperty getUserProperties() const;
301 
302  /// Get the aggregated child objects hash if it exists
303  std::string getChildrenHash() const;
304 
305 private:
306  ICompoundProperty getArbGeomParams() const;
307  void setObject(const IObject &o) { myObject = o; }
308 
309  std::string myObjectPath;
310  IObject myObject;
311 
312  friend class GABC_IArchive;
313 };
314 }
315 
316 #endif
GLenum src
Definition: glew.h:2410
GLuint const GLchar * name
Definition: glew.h:1814
GT_API const UT_StringHolder time
GLuint index
Definition: glew.h:1814
Alembic::Abc::TimeSamplingPtr TimeSamplingPtr
Definition: GABC_IObject.h:70
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
int64 exint
Definition: SYS_Types.h:125
GLhandleARB obj
Definition: glew.h:6236
Alembic::Abc::CompoundPropertyReaderPtr CompoundPropertyReaderPtr
Definition: GABC_IObject.h:72
Matrix44< double > M44d
Definition: ImathMatrix.h:866
#define GABC_NAMESPACE
Definition: GABC_API.h:42
GA_Size GA_Offset
Definition: GA_Types.h:639
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
GU_API GA_Offset getParent(GU_Detail *gdp, const GA_Offset &node)
GEO_AnimationType
GLuint object
Definition: glew.h:8986
long long int64
Definition: SYS_Types.h:116
const IObject & object() const
Definition: GABC_IObject.h:296
Alembic::Abc::M44d M44d
Definition: GABC_IObject.h:65
const std::string & getFullName() const
Get the full name of the object.
Definition: GABC_IObject.h:110
GT_Owner
Definition: GT_Types.h:76
GLsizei const GLchar *const * string
Definition: glew.h:1844
fpreal64 fpreal
Definition: SYS_Types.h:277
#define GABC_API
Definition: GABC_API.h:37
Container class for all geometry.
Definition: GA_Detail.h:95
const ObjectHeader & getHeader() const
Get my header.
Definition: GABC_IObject.h:100
const ObjectHeader & getChildHeader(exint i) const
Get the child header.
Definition: GABC_IObject.h:103
GABC_IObject getParent() const
Get the parent.
Definition: GABC_IObject.h:92
GLdouble GLdouble t
Definition: glew.h:1398