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_Util.h"
34 #include <GA/GA_Handle.h>
35 #include <GU/GU_Detail.h>
36 #include <stack>
37 
38 class GA_RWAttributeRef;
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  ~GABC_GEOWalker() override;
163 
164  bool preProcess(const GABC_IObject &node) override;
165 
166  bool process(const GABC_IObject &node) override;
167  bool interrupted() const override;
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; }
178  const std::string &rootObjectPath() const
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 buildAbcCamera() const { return myBuildAbcCamera; }
203  bool pathAttributeChanged() const { return myPathAttributeChanged; }
204  /// @}
205 
206  /// Get a sample selector for the given time
208  { return ISampleSelector(myTime); }
209 
210 
211  /// Keeps track of the number of geometry points added in traversal
212  GA_Offset pointCount() const { return myPointCount; }
213  /// Keeps track of the number of geometry vertices added in traversal
214  GA_Offset vertexCount() const { return myVertexCount; }
215  /// Keeps track of the number of geometry primitives added in traversal
216  GA_Offset primitiveCount() const { return myPrimitiveCount; }
217  /// True if *all* shapes and transforms are constant
218  bool isConstant() const { return myIsConstant; }
219  /// True if *all* shapes have constant topology
220  bool topologyConstant() const { return myTopologyConstant; }
221  /// True if the transform from the root to the current node is constant
222  bool transformConstant() const { return myTransformConstant; }
223  /// True if *all* transforms are constant
224  bool allTransformConstant() const { return myAllTransformConstant; }
225  bool rebuiltNURBS() const { return myRebuiltNURBS; }
226 
227  /// @{
228  /// Set state
229  bool setRootObject(const std::vector<std::string> &filenames,
230  const UT_String &rootPath);
231  void setExcludeObjects(const char *s);
232  void setObjectPattern(const char *s)
233  { myObjectPattern = s; }
235  { myFacesetAttribute = s; }
237  { myNameMapPtr = ptr; }
238  void setPathAttribute(const GA_RWAttributeRef &a);
239  void setTime(fpreal t) { myTime = t; }
240  void setFrame(fpreal f, fpreal fps) { myTime = f/fps; }
241  void setIncludeXform(bool v) { myIncludeXform = v; }
242  void setUseVisibility(bool v) { myUseVisibility = v; }
243  void setStaticTimeZero(bool v) { myStaticTimeZero = v; }
244  void setReusePrimitives(bool v,
245  GA_Offset pts = GA_Offset(0),
246  GA_Offset verts = GA_Offset(0),
247  GA_Offset prims = GA_Offset(0));
248  void setBuildLocator(bool v) { myBuildLocator = v; }
249  void setLoadMode(LoadMode mode) { myLoadMode = mode; }
250  void setBuildAbcShape(bool v) { myBuildAbcShape = v; }
251  void setBuildAbcXform(bool v) { myBuildAbcXform = v; }
252  void setBuildAbcCamera(bool v) { myBuildAbcCamera = v; }
253  void setPathAttributeChanged(bool v) { myPathAttributeChanged = v; }
254  void setUserProps(LoadUserPropsMode m) { myLoadUserProps = m; }
255  void setGroupMode(GroupMode m) { myGroupMode = m; }
256  void setAnimationFilter(AFilter m) { myAnimationFilter = m; }
257  void setGeometryFilter(int m) { myGeometryFilter = m; }
258  void setBounds(BoxCullMode mode, const UT_BoundingBox &box);
259  void setPointMode(AbcPrimPointMode mode,
260  GA_Offset shared_point = GA_INVALID_OFFSET);
261  void setPolySoup(AbcPolySoup soup) { myPolySoup = soup; }
262  void setViewportLOD(GEO_ViewportLOD v) { myViewportLOD = v; }
264  { mySizeCullMode = mode; mySizeCompare = cmp; mySize = size; }
265  /// @}
266 
267  /// @{
268  /// State accessors
269  AbcPolySoup polySoup() const { return myPolySoup; }
270  GEO_ViewportLOD viewportLOD() const { return myViewportLOD; }
271  /// @}
272 
273  /// @{
274  /// Primitive group to store subdivision primitives
275  GA_PrimitiveGroup *subdGroup() const { return mySubdGroup; }
276  void setSubdGroup(GA_PrimitiveGroup *g) { mySubdGroup = g; }
277  /// @}
278 
279  /// @{
280  /// State modified during traversal
281  void setNonConstant() { myIsConstant = false; }
282  void setNonConstantTopology() { myTopologyConstant = false; }
283  /// @}
284 
285  /// Keep track of added points/vertices/primitives. This should be called
286  /// after the primitives have been added to the detail.
287  void trackPtVtxPrim(const GABC_IObject &obj,
288  exint npoints, exint nvertex, exint nprim,
289  bool do_transform);
290 
291  /// Get the current transform
292  const UT_Matrix4D &getTransform() const { return myMatrix; }
293 
294  /// Get the group name associated with an GABC_IObject
295  bool getGroupName(UT_String &str, const GABC_IObject &obj) const;
296 
297  /// Translate attribute names. This will return false if the attribute is
298  /// not allowed.
299  bool translateAttributeName(GA_AttributeOwner own, UT_String &name);
300 
301  /// @{
302  /// Access information about last poly/subd/curve mesh loaded
303  GA_Size lastFaceCount() const { return myLastFaceCount; }
304  GA_Offset lastFaceStart() const { return myLastFaceStart; }
305  void trackLastFace(GA_Size nfaces);
306  void trackSubd(GA_Size nfaces);
307  /// @}
308 
309  /// Get a GA_Offset to which the Alembic delayed load primitive should be
310  /// attached. This may return an invalid offset
311  GA_Offset getPointForAbcPrim();
312  void setPointTransform(GU_PrimPacked *prim, GA_Offset offset) const;
313 
314 protected:
315  /// Verify the object matches filters before generating geometry
316  bool filterObject(const GABC_IObject &obj) const;
317  bool filterAnyChild(const GABC_IObject &obj) const;
318 
319 private:
320  bool matchObjectName(const GABC_IObject &obj) const;
321  bool matchAnimationFilter(const GABC_IObject &obj) const;
322  bool matchGeometryFilter(const GABC_IObject &obj) const;
323  bool matchBounds(const GABC_IObject &obj) const;
324  bool matchSize(const GABC_IObject &obj) const;
325  bool matchChildBounds(const GABC_IObject &obj) const;
326  bool matchChildSize(const GABC_IObject &obj) const;
327  bool abcPrimPointMode() const
328  { return myAbcPrimPointMode; }
329  GA_Offset abcSharedPoint() const
330  { return myAbcSharedPoint; }
331  void recordTimeRange(const GABC_IObject &node);
332 
333  // Enum values
334  AbcPolySoup myPolySoup;
335  AbcPrimPointMode myAbcPrimPointMode;
336  AFilter myAnimationFilter; // Animating object filter
337  int myGeometryFilter; // Geometry type filter
338  BoxCullMode myBoxCullMode;
339  SizeCullMode mySizeCullMode;
340  SizeCompare mySizeCompare;
341  GroupMode myGroupMode; // How to construct group names
342  LoadMode myLoadMode; // Build Alembic primitives
343  LoadUserPropsMode myLoadUserProps; // How to load user properties
344 
345  GA_Offset myAbcSharedPoint;
346  GA_Offset myLastFaceStart; // Start of faces in last mesh
347  GA_PrimitiveGroup *mySubdGroup;
348  GA_RWHandleS myPathAttribute;
349  GA_Size myLastFaceCount; // Number of faces in last mesh
350  GABC_IError &myErrorHandler;
351  GEO_PackedNameMapPtr myNameMapPtr; // Attribute map for ABC primitives
352  GEO_ViewportLOD myViewportLOD;
353  GU_Detail &myDetail;
354  UT_Matrix4D myRootInvertedMatrix;
355  UT_Matrix4D myMatrix;
356  UT_BoundingBox myCullBox;
357  UT_Interrupt *myBoss;
358  UT_StringHolder myFacesetAttribute;
359  std::string myRootObjectPath;
360  std::string myObjectPattern;
361  UT_StringArray myExcludeObjects;
362  std::stack<GABC_VisibilityType> myVisibilityStack;
363  UT_Set<std::string> myVisited;
364 
365  fpreal myTime; // Alembic evaluation time
366  fpreal mySize;
367 
368  GA_Offset myPointCount; // Points added
369  GA_Offset myPrimitiveCount; // Primitive's added count
370  GA_Offset myVertexCount; // Vertices added
371  int myBossId;
372  bool myBuildAbcXform; // Build primitives for transforms
373  bool myBuildAbcShape; // Build primitives for shapes
374  bool myBuildAbcCamera; // Build primitives for cameras
375  bool myBuildLocator; // Whether to build Maya locators
376  bool myIncludeXform; // Transform geometry
377  bool myPathAttributeChanged; // Whether path attrib name changed
378  bool myReusePrimitives; // Reuse primitives in input geometry
379  bool myUseVisibility; // Use visibility
380  bool myStaticTimeZero; // All static objects have frame=0
381  bool myRecordTimeRange;
382 
383  // Modified during traversal
384  bool myIsConstant; // Whether all objects are constant
385  bool myTopologyConstant; // Whether topology is constant
386  bool myTransformConstant; // All xforms down the tree are const
387  bool myAllTransformConstant; // All transforms in scene are const
388  bool myRebuiltNURBS; // Whether NURBS were rebuilt
389 };
390 }
391 
392 #endif
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:837
void setFrame(fpreal f, fpreal fps)
const GEO_PackedNameMapPtr & nameMapPtr() const
GLboolean GLboolean g
Definition: glcorearb.h:1222
GA_PrimitiveGroup * subdGroup() const
int64 exint
Definition: SYS_Types.h:125
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLdouble s
Definition: glad.h:3009
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
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:243
bool topologyConstant() const
True if all shapes have constant topology.
AbcPrimPointMode
How Alembic delayed load primitives are attached to GA points.
Matrix44< double > M44d
4x4 matrix of double
Definition: ImathMatrix.h:1404
#define GABC_NAMESPACE
Definition: GABC_API.h:42
#define GA_INVALID_OFFSET
Definition: GA_Types.h:694
GA_Offset lastFaceStart() const
IMATH_HOSTDEVICE constexpr int cmp(T a, T b) IMATH_NOEXCEPT
Definition: ImathFun.h:84
GA_Size GA_Offset
Definition: GA_Types.h:653
LoadUserPropsMode loadUserProps() const
This class provides a way to manage a reference to an attribute permitting Read-Write access...
GLfloat f
Definition: glcorearb.h:1926
ISampleSelector timeSample() const
Get a sample selector for the given time.
GLintptr offset
Definition: glcorearb.h:665
void setNameMapPtr(const GEO_PackedNameMapPtr &ptr)
const UT_StringHolder & facesetAttribute() const
void setSizeCullMode(SizeCullMode mode, SizeCompare cmp, fpreal size)
GA_Offset primitiveCount() const
Keeps track of the number of geometry primitives added in traversal.
const std::string & rootObjectPath() const
void setObjectPattern(const char *s)
GLuint const GLchar * name
Definition: glcorearb.h:786
GFilter
Geometry type filter.
GA_Offset vertexCount() const
Keeps track of the number of geometry vertices added in traversal.
GLdouble t
Definition: glad.h:2397
AbcPolySoup
Whether to build polysoup primitives when it's possible.
GLenum mode
Definition: glcorearb.h:99
LoadUserPropsMode
How to load user properties.
GLsizeiptr size
Definition: glcorearb.h:664
GA_AttributeOwner
Definition: GA_Types.h:35
bool isConstant() const
True if all shapes and transforms are constant.
GEO_ViewportLOD
fpreal64 fpreal
Definition: SYS_Types.h:283
#define GABC_API
Definition: GABC_API.h:37
auto ptr(T p) -> const void *
Definition: format.h:4331
void setLoadMode(LoadMode mode)
bool process(T &func, UT_WorkBuffer &fullpath, exint fullpath_len, const UT_StringArray &paths, const UT_Array< FS_Stat > &stats)
Utility function to process the contents of the traverse() function.
Definition: FS_Traverse.h:24
void setFacesetAttribute(const UT_StringHolder &s)
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