HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XUSD_AutoCollection.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef __XUSD_AutoCollection_h__
19 #define __XUSD_AutoCollection_h__
20 
21 #include "HUSD_API.h"
22 #include "HUSD_TimeCode.h"
23 #include "HUSD_Utils.h"
24 #include "XUSD_PathSet.h"
25 #include <UT/UT_StringHolder.h>
26 #include <pxr/usd/sdf/path.h>
27 #include <pxr/usd/usd/stage.h>
28 
29 extern "C" {
30  SYS_VISIBILITY_EXPORT extern void newAutoCollection(void *unused);
31 };
32 class HUSD_AutoAnyLock;
33 
35 
37 
39 {
40 public:
42  { }
44  { }
45 
46  virtual bool canCreateAutoCollection(const char *token) const = 0;
47  virtual XUSD_AutoCollection *create(
48  const UT_StringHolder &collectionname,
49  const UT_StringArray &orderedargs,
50  const UT_StringMap<UT_StringHolder> &namedargs,
51  HUSD_AutoAnyLock &lock,
53  int nodeid,
54  const HUSD_TimeCode &timecode) const = 0;
55 };
56 
57 template <class AutoCollection>
59 {
60 public:
62  : myCollectionName(cname)
63  { }
65  { }
66 
68  const char *cname) const override
69  {
70  return (myCollectionName == cname);
71  }
73  const UT_StringHolder &collectionname,
74  const UT_StringArray &orderedargs,
75  const UT_StringMap<UT_StringHolder> &namedargs,
76  HUSD_AutoAnyLock &lock,
78  int nodeid,
79  const HUSD_TimeCode &timecode) const override
80  {
81  if (collectionname == myCollectionName)
82  return new AutoCollection(collectionname, orderedargs, namedargs,
83  lock, demands, nodeid, timecode);
84 
85  return nullptr;
86  }
87 
88 private:
89  UT_StringHolder myCollectionName;
90 };
91 
93 {
94 public:
96  const UT_StringHolder &collectionname,
97  const UT_StringArray &orderedargs,
98  const UT_StringMap<UT_StringHolder> &namedargs,
99  HUSD_AutoAnyLock &lock,
101  int nodeid,
102  const HUSD_TimeCode &timecode);
103  virtual ~XUSD_AutoCollection();
104 
105  // Determines whether or not this class works in random access mode.
106  virtual bool randomAccess() const = 0;
107 
108  // A non-random access auto collection does its own traversal of the stage
109  // all at once when the auto collection is created, generating a full set
110  // of all matching paths at once.
111  virtual void matchPrimitives(XUSD_PathSet &matches) const
112  { UT_ASSERT(false); }
113 
114  // A random access auto collection gets no benefit from being executed
115  // as a depth first traversal of the whole stage. It will be called for
116  // each primitive as part of the overall pattern matching process.
118  bool *prune_branch) const
119  { UT_ASSERT(false); return false; }
120 
121  virtual bool getMayBeTimeVarying() const
122  { return myMayBeTimeVaryingSubPattern; }
123 
125  { return myTokenParsingError; }
126 
127  // Static functions for common argument parsing tasks.
128  static bool parseBool(const UT_StringRef &str);
129  static bool parseInt(const UT_StringRef &str,
130  exint &i);
131  static bool parseFloat(const UT_StringRef &str,
132  fpreal64 &flt);
133  static bool parseVector2(const UT_StringRef &str,
134  UT_Vector2D &vec);
135  static bool parseVector3(const UT_StringRef &str,
136  UT_Vector3D &vec);
137  static bool parseVector4(const UT_StringRef &str,
138  UT_Vector4D &vec);
139  static bool parseTimeRange(const UT_StringRef &str,
140  fpreal64 &tstart,
141  fpreal64 &tend,
142  fpreal64 &tstep);
143 
144  // Parse a source pattern string.
145  // Note that `timevaryingflag` will only ever be *set* (to `true`),
146  // (if the pattern is timevarying of course), but never *unset* (to `false`)
147  static bool parsePattern(const UT_StringRef &str,
148  HUSD_AutoAnyLock &lock,
150  int nodeid,
151  const HUSD_TimeCode &timecode,
152  XUSD_PathSet &paths,
153  bool *timevaryingflag);
154  // Parse a source pattern string, but only return the first result.
155  static bool parsePatternSingleResult(const UT_StringRef &str,
156  HUSD_AutoAnyLock &lock,
158  int nodeid,
159  const HUSD_TimeCode &timecode,
160  SdfPath &path,
161  bool *timevaryingflag);
162 
163  static bool canCreateAutoCollection(const char *token);
164  static XUSD_AutoCollection *create(const char *token,
165  HUSD_AutoAnyLock &lock,
167  int nodeid,
168  const HUSD_TimeCode &timecode);
169  static void registerPlugins();
170  static void registerPlugin(XUSD_AutoCollectionFactory *factory);
171 
172 protected:
178  int myNodeId;
182 
183 private:
184  static UT_Array<XUSD_AutoCollectionFactory *> theFactories;
185 };
186 
188 {
189 public:
191  const UT_StringHolder &collectionname,
192  const UT_StringArray &orderedargs,
193  const UT_StringMap<UT_StringHolder> &namedargs,
194  HUSD_AutoAnyLock &lock,
196  int nodeid,
197  const HUSD_TimeCode &timecode);
198  ~XUSD_SimpleAutoCollection() override;
199 
200  bool randomAccess() const override
201  { return false; }
202  void matchPrimitives(XUSD_PathSet &matches) const override;
203  virtual bool matchPrimitive(const UsdPrim &prim,
204  bool *prune_branch) const = 0;
205 };
206 
208 {
209 public:
211  const UT_StringHolder &collectionname,
212  const UT_StringArray &orderedargs,
213  const UT_StringMap<UT_StringHolder> &namedargs,
214  HUSD_AutoAnyLock &lock,
216  int nodeid,
217  const HUSD_TimeCode &timecode);
219 
220  bool randomAccess() const override
221  { return true; }
223  bool *prune_branch) const override;
224  virtual bool matchPrimitive(const UsdPrim &prim,
225  bool *prune_branch) const = 0;
226 };
227 
229 
230 #endif
231 
bool randomAccess() const override
#define SYS_VISIBILITY_EXPORT
const UT_StringHolder & getTokenParsingError() const
HUSD_TimeCode myHusdTimeCode
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
int64 exint
Definition: SYS_Types.h:125
#define HUSD_API
Definition: HUSD_API.h:32
virtual XUSD_AutoCollection * create(const UT_StringHolder &collectionname, const UT_StringArray &orderedargs, const UT_StringMap< UT_StringHolder > &namedargs, HUSD_AutoAnyLock &lock, HUSD_PrimTraversalDemands demands, int nodeid, const HUSD_TimeCode &timecode) const =0
virtual bool getMayBeTimeVarying() const
HUSD_PrimTraversalDemands
Definition: HUSD_Utils.h:38
double fpreal64
Definition: SYS_Types.h:201
UT_StringArray myOrderedArgs
UT_StringHolder myTokenParsingError
Definition: prim.h:135
XUSD_AutoCollection * create(const UT_StringHolder &collectionname, const UT_StringArray &orderedargs, const UT_StringMap< UT_StringHolder > &namedargs, HUSD_AutoAnyLock &lock, HUSD_PrimTraversalDemands demands, int nodeid, const HUSD_TimeCode &timecode) const override
Definition: path.h:291
UT_StringMap< UT_StringHolder > myNamedArgs
HUSD_AutoAnyLock & myLock
HUSD_PrimTraversalDemands myDemands
bool canCreateAutoCollection(const char *cname) const override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
virtual void matchPrimitives(XUSD_PathSet &matches) const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual bool matchRandomAccessPrimitive(const SdfPath &path, bool *prune_branch) const
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
SYS_VISIBILITY_EXPORT void newAutoCollection(void *unused)
virtual bool canCreateAutoCollection(const char *token) const =0
XUSD_SimpleAutoCollectionFactory(const char *cname)