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 false; }
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  static bool parsePattern(const UT_StringRef &str,
146  HUSD_AutoAnyLock &lock,
148  int nodeid,
149  const HUSD_TimeCode &timecode,
151  // Parse a source pattern string, but only return the first result.
152  static bool parsePatternSingleResult(const UT_StringRef &str,
153  HUSD_AutoAnyLock &lock,
155  int nodeid,
156  const HUSD_TimeCode &timecode,
157  SdfPath &path);
158 
159  static bool canCreateAutoCollection(const char *token);
160  static XUSD_AutoCollection *create(const char *token,
161  HUSD_AutoAnyLock &lock,
163  int nodeid,
164  const HUSD_TimeCode &timecode);
165  static void registerPlugins();
166  static void registerPlugin(XUSD_AutoCollectionFactory *factory);
167 
168 protected:
173  int myNodeId;
177 
178 private:
179  static UT_Array<XUSD_AutoCollectionFactory *> theFactories;
180 };
181 
183 {
184 public:
186  const UT_StringHolder &collectionname,
187  const UT_StringArray &orderedargs,
188  const UT_StringMap<UT_StringHolder> &namedargs,
189  HUSD_AutoAnyLock &lock,
191  int nodeid,
192  const HUSD_TimeCode &timecode);
193  ~XUSD_SimpleAutoCollection() override;
194 
195  bool randomAccess() const override
196  { return false; }
197  void matchPrimitives(XUSD_PathSet &matches) const override;
198  virtual bool matchPrimitive(const UsdPrim &prim,
199  bool *prune_branch) const = 0;
200 };
201 
203 {
204 public:
206  const UT_StringHolder &collectionname,
207  const UT_StringArray &orderedargs,
208  const UT_StringMap<UT_StringHolder> &namedargs,
209  HUSD_AutoAnyLock &lock,
211  int nodeid,
212  const HUSD_TimeCode &timecode);
214 
215  bool randomAccess() const override
216  { return true; }
218  bool *prune_branch) const override;
219  virtual bool matchPrimitive(const UsdPrim &prim,
220  bool *prune_branch) const = 0;
221 };
222 
224 
225 #endif
226 
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:37
double fpreal64
Definition: SYS_Types.h:201
UT_StringArray myOrderedArgs
UT_StringHolder myTokenParsingError
Definition: prim.h:132
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:290
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:1394
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:153
SYS_VISIBILITY_EXPORT void newAutoCollection(void *unused)
virtual bool canCreateAutoCollection(const char *token) const =0
XUSD_SimpleAutoCollectionFactory(const char *cname)
GLenum const void * paths
Definition: glew.h:13872