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