HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GABC_GEOWalker.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_GEOWalker__
29 #define __GABC_GEOWalker__
30 
31 #include "GABC_API.h"
32 #include "GABC_IError.h"
33 #include "GABC_Include.h"
34 #include "GABC_Util.h"
35 #include <GA/GA_Handle.h>
36 #include <GU/GU_Detail.h>
37 #include <stack>
38 
39 class GU_PrimPacked;
40 class UT_StringArray;
41 
42 namespace GABC_NAMESPACE
43 {
44 /// @brief Walk an Alembic tree to create Houdini geometry
45 ///
46 /// To convert an Alembic file to Houdini geometry, the code would look
47 /// something like this: @code
48 /// GU_Detail gdp;
49 /// GABC_GEOWalker walker(gdp);
50 ///
51 /// walker.setFrame(frame, fps); // Specify the time sample
52 /// // Set any other parameters you might care about
53 /// walker.setBuildAbcPrim(true);
54 ///
55 /// // Now, walker the Alembic file
56 /// if (!GABC_Util::walker(filename, walker))
57 /// addError();
58 /// @endcode
60 {
61 public:
64 
65  /// Test by loading "test.abc" in the current directory and saving
66  /// "test.geo" as output.
67  static void test();
68 
69  enum GroupMode
70  {
71  ABC_GROUP_NONE, // No geometry groups
72  ABC_GROUP_SHAPE_NODE, // Name geometry group based on shape node
73  ABC_GROUP_XFORM_NODE, // Name geometry group based on transform node
74  ABC_GROUP_SHAPE_BASENAME, // Group by last path component
75  ABC_GROUP_XFORM_BASENAME, // Group by last xform node path component
76  };
77 
79  {
80  BOX_CULL_IGNORE, // Ignore bounding box
81  BOX_CULL_ANY_INSIDE, // Add if boxes overlap
82  BOX_CULL_INSIDE, // Add if box is entirely inside
83  BOX_CULL_ANY_OUTSIDE, // Add if any of object is outside filter box
84  BOX_CULL_OUTSIDE, // Add if object is entirely outside bounds
85  };
86 
88  {
89  SIZE_CULL_IGNORE, // Ignore size constraint
90  SIZE_CULL_AREA, // Add if bounding box area passes size test
91  SIZE_CULL_RADIUS, // Add if bounding box radius passes size test
92  SIZE_CULL_VOLUME, // Add if bounding box volume passes size test
93  };
94 
96  {
97  SIZE_COMPARE_LESSTHAN, // Add if bounding box is smaller than the reference size
98  SIZE_COMPARE_GREATERTHAN, // Add if bounding box is larger than the reference size
99  };
100 
101  enum LoadMode
102  {
103  LOAD_ABC_PRIMITIVES, // Load Alembic primitives
104  LOAD_ABC_UNPACKED, // Load ABC then unpack
105  LOAD_HOUDINI_PRIMITIVES, // Load houdini primitives
106  LOAD_HOUDINI_POINTS, // Load point cloud for objects
107  LOAD_HOUDINI_BOXES, // Load Bounds as Houdini geometry
108  };
109 
110  /// Animating object filter
111  enum AFilter
112  {
113  ABC_AFILTER_STATIC, // Only static geometry
114  ABC_AFILTER_DEFORMING, // Only deforming geometry
115  ABC_AFILTER_TRANSFORMING, // Only transforming geometry
116  ABC_AFILTER_ANIMATING, // Only animating geometry
117  ABC_AFILTER_ALL // All geometry
118  };
119 
120  /// Geometry type filter
121  enum GFilter
122  {
123  ABC_GFILTER_POLYMESH = 0x01, // Load primitives that are polygons
124  ABC_GFILTER_CURVES = 0x02, // Load primitives that are curves
125  ABC_GFILTER_NUPATCH = 0x04, // Load primitives that are NURBS
126  ABC_GFILTER_POINTS = 0x08, // Load primitives that are points
127  ABC_GFILTER_SUBD = 0x10, // Load primitives that are subdivision surfaces
128  ABC_GFILTER_ALL = (ABC_GFILTER_POLYMESH | // Load all primitives
129  ABC_GFILTER_CURVES |
130  ABC_GFILTER_NUPATCH |
131  ABC_GFILTER_POINTS |
132  ABC_GFILTER_SUBD)
133  };
134 
135  /// How Alembic delayed load primitives are attached to GA points
137  {
138  ABCPRIM_SHARED_POINT, // All primitives share a GA point
139  ABCPRIM_UNIQUE_POINT, // Each prim has its own point
140  ABCPRIM_CENTROID_POINT, // Place point at centroid
141  ABCPRIM_SHAPE_POINT, // Promote xform to 'transform' intrinsic
142  };
143 
144  /// Whether to build polysoup primitives when it's possible
146  {
147  ABC_POLYSOUP_NONE, // Build polygons only
148  ABC_POLYSOUP_POLYMESH, // Polygon Mesh primitives only
149  ABC_POLYSOUP_SUBD, // Polygon soups & subdivision primitives
150  };
151 
152  /// How to load user properties
154  {
155  UP_LOAD_NONE, // Don't load user properties
156  UP_LOAD_DATA, // Load only user property values
157  UP_LOAD_ALL, // Load user property values and metadata
158  };
159 
161  bool record_time_range=false);
162  virtual ~GABC_GEOWalker();
163 
164  virtual bool preProcess(const GABC_IObject &node);
165 
166  virtual bool process(const GABC_IObject &node);
167  virtual bool interrupted() const;
168 
169  /// Quickly update ABC primitives with the new time
170  void updateAbcPrims();
171 
172  /// @{
173  /// Get state
174  GU_Detail &detail() const
175  { return myDetail; }
177  { return myErrorHandler; }
179  { return myRootObjectPath; }
180  const std::string &objectPattern() const
181  { return myObjectPattern; }
183  { return myExcludeObjects; }
185  { return myNameMapPtr; }
187  { return myFacesetAttribute; }
188 
189  fpreal time() const { return myTime; }
190  bool includeXform() const { return myIncludeXform; }
191  bool useVisibility() const { return myUseVisibility; }
192  bool staticTimeZero() const { return myStaticTimeZero; }
193  bool reusePrimitives() const { return myReusePrimitives; }
194  bool buildLocator() const { return myBuildLocator; }
195  LoadUserPropsMode loadUserProps() const { return myLoadUserProps; }
196  LoadMode loadMode() const { return myLoadMode; }
197  bool buildAbcPrim() const
198  { return myLoadMode == LOAD_ABC_PRIMITIVES
199  || myLoadMode == LOAD_ABC_UNPACKED; }
200  bool buildAbcShape() const { return myBuildAbcShape; }
201  bool buildAbcXform() const { return myBuildAbcXform; }
202  bool pathAttributeChanged() const { return myPathAttributeChanged; }
203  /// @}
204 
205  /// Get a sample selector for the given time
207  { return ISampleSelector(myTime); }
208 
209 
210  /// Keeps track of the number of geometry points added in traversal
211  GA_Offset pointCount() const { return myPointCount; }
212  /// Keeps track of the number of geometry vertices added in traversal
213  GA_Offset vertexCount() const { return myVertexCount; }
214  /// Keeps track of the number of geometry primitives added in traversal
215  GA_Offset primitiveCount() const { return myPrimitiveCount; }
216  /// True if *all* shapes and transforms are constant
217  bool isConstant() const { return myIsConstant; }
218  /// True if *all* shapes have constant topology
219  bool topologyConstant() const { return myTopologyConstant; }
220  /// True if the transform from the root to the current node is constant
221  bool transformConstant() const { return myTransformConstant; }
222  /// True if *all* transforms are constant
223  bool allTransformConstant() const { return myAllTransformConstant; }
224  bool rebuiltNURBS() const { return myRebuiltNURBS; }
225 
226  /// @{
227  /// Set state
228  bool setRootObject(const std::vector<std::string> &filenames,
229  const UT_String &rootPath);
230  void setExcludeObjects(const char *s);
231  void setObjectPattern(const char *s)
232  { myObjectPattern = s; }
233  void setFacesetAttribute(const char *s)
234  { myFacesetAttribute.harden(s); }
236  { myNameMapPtr = ptr; }
237  void setPathAttribute(const GA_RWAttributeRef &a);
238  void setTime(fpreal t) { myTime = t; }
239  void setFrame(fpreal f, fpreal fps) { myTime = f/fps; }
240  void setIncludeXform(bool v) { myIncludeXform = v; }
241  void setUseVisibility(bool v) { myUseVisibility = v; }
242  void setStaticTimeZero(bool v) { myStaticTimeZero = v; }
243  void setReusePrimitives(bool v,
244  GA_Offset pts = GA_Offset(0),
245  GA_Offset verts = GA_Offset(0),
246  GA_Offset prims = GA_Offset(0));
247  void setBuildLocator(bool v) { myBuildLocator = v; }
248  void setLoadMode(LoadMode mode) { myLoadMode = mode; }
249  void setBuildAbcShape(bool v) { myBuildAbcShape = v; }
250  void setBuildAbcXform(bool v) { myBuildAbcXform = v; }
251  void setPathAttributeChanged(bool v) { myPathAttributeChanged = v; }
252  void setUserProps(LoadUserPropsMode m) { myLoadUserProps = m; }
253  void setGroupMode(GroupMode m) { myGroupMode = m; }
254  void setAnimationFilter(AFilter m) { myAnimationFilter = m; }
255  void setGeometryFilter(int m) { myGeometryFilter = m; }
256  void setBounds(BoxCullMode mode, const UT_BoundingBox &box);
257  void setPointMode(AbcPrimPointMode mode,
258  GA_Offset shared_point = GA_INVALID_OFFSET);
259  void setPolySoup(AbcPolySoup soup) { myPolySoup = soup; }
260  void setViewportLOD(GEO_ViewportLOD v) { myViewportLOD = v; }
262  { mySizeCullMode = mode; mySizeCompare = cmp; mySize = size; }
263  /// @}
264 
265  /// @{
266  /// State accessors
267  AbcPolySoup polySoup() const { return myPolySoup; }
268  GEO_ViewportLOD viewportLOD() const { return myViewportLOD; }
269  /// @}
270 
271  /// @{
272  /// Primitive group to store subdivision primitives
273  GA_PrimitiveGroup *subdGroup() const { return mySubdGroup; }
274  void setSubdGroup(GA_PrimitiveGroup *g) { mySubdGroup = g; }
275  /// @}
276 
277  /// @{
278  /// State modified during traversal
279  void setNonConstant() { myIsConstant = false; }
280  void setNonConstantTopology() { myTopologyConstant = false; }
281  /// @}
282 
283  /// Keep track of added points/vertices/primitives. This should be called
284  /// after the primitives have been added to the detail.
285  void trackPtVtxPrim(const GABC_IObject &obj,
286  exint npoints, exint nvertex, exint nprim,
287  bool do_transform);
288 
289  /// Get the current transform
290  const UT_Matrix4D &getTransform() const { return myMatrix; }
291 
292  /// Get the group name associated with an GABC_IObject
293  bool getGroupName(UT_String &str, const GABC_IObject &obj) const;
294 
295  /// Translate attribute names. This will return false if the attribute is
296  /// not allowed.
297  bool translateAttributeName(GA_AttributeOwner own, UT_String &name);
298 
299  /// @{
300  /// Access information about last poly/subd/curve mesh loaded
301  GA_Size lastFaceCount() const { return myLastFaceCount; }
302  GA_Offset lastFaceStart() const { return myLastFaceStart; }
303  void trackLastFace(GA_Size nfaces);
304  void trackSubd(GA_Size nfaces);
305  /// @}
306 
307  /// Get a GA_Offset to which the Alembic delayed load primitive should be
308  /// attached. This may return an invalid offset
309  GA_Offset getPointForAbcPrim();
310  void setPointTransform(GU_PrimPacked *prim, GA_Offset offset) const;
311 
312 protected:
313  /// Verify the object matches filters before generating geometry
314  bool filterObject(const GABC_IObject &obj) const;
315  bool filterAnyChild(const GABC_IObject &obj) const;
316 
317 private:
318  bool matchObjectName(const GABC_IObject &obj) const;
319  bool matchAnimationFilter(const GABC_IObject &obj) const;
320  bool matchGeometryFilter(const GABC_IObject &obj) const;
321  bool matchBounds(const GABC_IObject &obj) const;
322  bool matchSize(const GABC_IObject &obj) const;
323  bool matchChildBounds(const GABC_IObject &obj) const;
324  bool matchChildSize(const GABC_IObject &obj) const;
325  bool abcPrimPointMode() const
326  { return myAbcPrimPointMode; }
327  GA_Offset abcSharedPoint() const
328  { return myAbcSharedPoint; }
329  void recordTimeRange(const GABC_IObject &node);
330 
331  // Enum values
332  AbcPolySoup myPolySoup;
333  AbcPrimPointMode myAbcPrimPointMode;
334  AFilter myAnimationFilter; // Animating object filter
335  int myGeometryFilter; // Geometry type filter
336  BoxCullMode myBoxCullMode;
337  SizeCullMode mySizeCullMode;
338  SizeCompare mySizeCompare;
339  GroupMode myGroupMode; // How to construct group names
340  LoadMode myLoadMode; // Build Alembic primitives
341  LoadUserPropsMode myLoadUserProps; // How to load user properties
342 
343  GA_Offset myAbcSharedPoint;
344  GA_Offset myLastFaceStart; // Start of faces in last mesh
345  GA_PrimitiveGroup *mySubdGroup;
346  GA_RWHandleS myPathAttribute;
347  GA_Size myLastFaceCount; // Number of faces in last mesh
348  GABC_IError &myErrorHandler;
349  GEO_PackedNameMapPtr myNameMapPtr; // Attribute map for ABC primitives
350  GEO_ViewportLOD myViewportLOD;
351  GU_Detail &myDetail;
352  UT_Matrix4D myRootInvertedMatrix;
353  UT_Matrix4D myMatrix;
354  UT_BoundingBox myCullBox;
355  UT_Interrupt *myBoss;
356  UT_String myFacesetAttribute;
357  std::string myRootObjectPath;
358  std::string myObjectPattern;
359  UT_StringArray myExcludeObjects;
360  std::stack<GABC_VisibilityType> myVisibilityStack;
361  UT_Set<std::string> myVisited;
362 
363  fpreal myTime; // Alembic evaluation time
364  fpreal mySize;
365 
366  GA_Offset myPointCount; // Points added
367  GA_Offset myPrimitiveCount; // Primitive's added count
368  GA_Offset myVertexCount; // Vertices added
369  int myBossId;
370  bool myBuildAbcXform; // Build primitives for transforms
371  bool myBuildAbcShape; // Build primitives for transforms
372  bool myBuildLocator; // Whether to build Maya locators
373  bool myIncludeXform; // Transform geometry
374  bool myPathAttributeChanged; // Whether path attrib name changed
375  bool myReusePrimitives; // Reuse primitives in input geometry
376  bool myUseVisibility; // Use visibility
377  bool myStaticTimeZero; // All static objects have frame=0
378  bool myRecordTimeRange;
379 
380  // Modified during traversal
381  bool myIsConstant; // Whether all objects are constant
382  bool myTopologyConstant; // Whether topology is constant
383  bool myTransformConstant; // All xforms down the tree are const
384  bool myAllTransformConstant; // All transforms in scene are const
385  bool myRebuiltNURBS; // Whether NURBS were rebuilt
386 };
387 }
388 
389 #endif
void setFacesetAttribute(const char *s)
const std::string & objectPattern() const
cvex test(vector P=0;int unbound=3;export float s=0;export vector Cf=0;)
Definition: test.vfl:11
AFilter
Animating object filter.
const GLdouble * v
Definition: glcorearb.h:836
void setFrame(fpreal f, fpreal fps)
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
png_voidp ptr
Definition: png.h:2145
const GEO_PackedNameMapPtr & nameMapPtr() const
GLboolean GLboolean g
Definition: glcorearb.h:1221
GA_PrimitiveGroup * subdGroup() const
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
void setUserProps(LoadUserPropsMode m)
bool allTransformConstant() const
True if all transforms are constant.
const UT_Matrix4D & getTransform() const
Get the current transform.
AbcPolySoup polySoup() const
Read-Write string handle.
Definition: GA_Handle.h:833
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
bool topologyConstant() const
True if all shapes have constant topology.
AbcPrimPointMode
How Alembic delayed load primitives are attached to GA points.
Matrix44< double > M44d
Definition: ImathMatrix.h:866
GLsizeiptr size
Definition: glcorearb.h:663
#define GABC_NAMESPACE
Definition: GABC_API.h:42
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
GA_Offset lastFaceStart() const
GA_Size GA_Offset
Definition: GA_Types.h:617
LoadUserPropsMode loadUserProps() const
This class provides a way to manage a reference to an attribute permitting Read-Write access...
GLfloat f
Definition: glcorearb.h:1925
ISampleSelector timeSample() const
Get a sample selector for the given time.
void setNameMapPtr(const GEO_PackedNameMapPtr &ptr)
int64 exint
Definition: SYS_Types.h:116
void setSizeCullMode(SizeCullMode mode, SizeCompare cmp, fpreal size)
GA_Offset primitiveCount() const
Keeps track of the number of geometry primitives added in traversal.
GLintptr offset
Definition: glcorearb.h:664
const std::string & rootObjectPath() const
void setObjectPattern(const char *s)
const UT_String & facesetAttribute() const
GLuint const GLchar * name
Definition: glcorearb.h:785
GFilter
Geometry type filter.
GA_Offset vertexCount() const
Keeps track of the number of geometry vertices added in traversal.
AbcPolySoup
Whether to build polysoup primitives when it's possible.
GLenum mode
Definition: glcorearb.h:98
int cmp(T a, T b)
Definition: ImathFun.h:119
LoadUserPropsMode
How to load user properties.
GA_AttributeOwner
Definition: GA_Types.h:33
double fpreal
Definition: SYS_Types.h:270
bool isConstant() const
True if all shapes and transforms are constant.
GEO_ViewportLOD
#define GABC_API
Definition: GABC_API.h:37
void setLoadMode(LoadMode mode)
GA_Offset pointCount() const
Keeps track of the number of geometry points added in traversal.
bool transformConstant() const
True if the transform from the root to the current node is constant.
Walk an Alembic tree to create Houdini geometry.
GEO_ViewportLOD viewportLOD() const
void setPolySoup(AbcPolySoup soup)
GU_Detail & detail() const
void setViewportLOD(GEO_ViewportLOD v)
void setSubdGroup(GA_PrimitiveGroup *g)
const UT_StringArray & excludeObjects() const