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"
26 #include <UT/UT_StringHolder.h>
27 #include <pxr/usd/sdf/path.h>
28 #include <pxr/usd/usd/stage.h>
29 
30 extern "C" {
31  SYS_VISIBILITY_EXPORT extern void newAutoCollection(void *unused);
32 };
33 class HUSD_AutoAnyLock;
34 
36 
38 
40 {
41 public:
43  { }
45  { }
46 
47  virtual bool canCreateAutoCollection(const char *token) const = 0;
48  virtual XUSD_AutoCollection *create(
49  const UT_StringHolder &collectionname,
50  const UT_StringArray &orderedargs,
51  const UT_StringMap<UT_StringHolder> &namedargs,
52  HUSD_AutoAnyLock &lock,
54  int nodeid,
55  const HUSD_TimeCode &timecode) const = 0;
56 };
57 
58 template <class AutoCollection>
60 {
61 public:
63  : myCollectionName(cname)
64  { }
66  { }
67 
69  const char *cname) const override
70  {
71  return (myCollectionName == cname);
72  }
74  const UT_StringHolder &collectionname,
75  const UT_StringArray &orderedargs,
76  const UT_StringMap<UT_StringHolder> &namedargs,
77  HUSD_AutoAnyLock &lock,
79  int nodeid,
80  const HUSD_TimeCode &timecode) const override
81  {
82  if (collectionname == myCollectionName)
83  return new AutoCollection(collectionname, orderedargs, namedargs,
84  lock, demands, nodeid, timecode);
85 
86  return nullptr;
87  }
88 
89 private:
90  UT_StringHolder myCollectionName;
91 };
92 
94 {
95 public:
97  const UT_StringHolder &collectionname,
98  const UT_StringArray &orderedargs,
99  const UT_StringMap<UT_StringHolder> &namedargs,
100  HUSD_AutoAnyLock &lock,
102  int nodeid,
103  const HUSD_TimeCode &timecode);
104  virtual ~XUSD_AutoCollection();
105 
106  // Determines whether or not this class works in random access mode.
107  virtual bool randomAccess() const = 0;
108 
109  // A non-random access auto collection does its own traversal of the stage
110  // all at once when the auto collection is created, generating a full set
111  // of all matching paths at once.
112  virtual void matchPrimitives(XUSD_PathSet &matches) const
113  { UT_ASSERT(false); }
114 
115  // A random access auto collection gets no benefit from being executed
116  // as a depth first traversal of the whole stage. It will be called for
117  // each primitive as part of the overall pattern matching process.
119  bool *prune_branch) const
120  { UT_ASSERT(false); return false; }
121 
122  virtual bool getMayBeTimeVarying() const
123  { return false; }
124 
126  { return myTokenParsingError; }
127 
128  // Static functions for common argument parsing tasks.
129  static bool parseBool(const UT_StringRef &str);
130  static bool parseInt(const UT_StringRef &str,
131  exint &i);
132  static bool parseFloat(const UT_StringRef &str,
133  fpreal64 &flt);
134  static bool parseVector2(const UT_StringRef &str,
135  UT_Vector2D &vec);
136  static bool parseVector3(const UT_StringRef &str,
137  UT_Vector3D &vec);
138  static bool parseVector4(const UT_StringRef &str,
139  UT_Vector4D &vec);
140  static bool parseTimeRange(const UT_StringRef &str,
141  fpreal64 &tstart,
142  fpreal64 &tend,
143  fpreal64 &tstep);
144 
145  // Parse a source pattern string.
146  static bool parsePattern(const UT_StringRef &str,
147  HUSD_AutoAnyLock &lock,
149  int nodeid,
150  const HUSD_TimeCode &timecode,
152 
153  static bool canCreateAutoCollection(const char *token);
154  static XUSD_AutoCollection *create(const char *token,
155  HUSD_AutoAnyLock &lock,
157  int nodeid,
158  const HUSD_TimeCode &timecode);
159  static void registerPlugins();
160  static void registerPlugin(XUSD_AutoCollectionFactory *factory);
161 
162 protected:
167  int myNodeId;
171 
172 private:
173  static UT_Array<XUSD_AutoCollectionFactory *> theFactories;
174 };
175 
177 {
178 public:
180  const UT_StringHolder &collectionname,
181  const UT_StringArray &orderedargs,
182  const UT_StringMap<UT_StringHolder> &namedargs,
183  HUSD_AutoAnyLock &lock,
185  int nodeid,
186  const HUSD_TimeCode &timecode);
187  ~XUSD_SimpleAutoCollection() override;
188 
189  bool randomAccess() const override
190  { return false; }
191  void matchPrimitives(XUSD_PathSet &matches) const override;
192  virtual bool matchPrimitive(const UsdPrim &prim,
193  bool *prune_branch) const = 0;
194 };
195 
197 {
198 public:
200  const UT_StringHolder &collectionname,
201  const UT_StringArray &orderedargs,
202  const UT_StringMap<UT_StringHolder> &namedargs,
203  HUSD_AutoAnyLock &lock,
205  int nodeid,
206  const HUSD_TimeCode &timecode);
208 
209  bool randomAccess() const override
210  { return true; }
212  bool *prune_branch) const override;
213  virtual bool matchPrimitive(const UsdPrim &prim,
214  bool *prune_branch) const = 0;
215 };
216 
218 
219 #endif
220 
bool randomAccess() const override
#define SYS_VISIBILITY_EXPORT
const UT_StringHolder & getTokenParsingError() const
HUSD_TimeCode myHusdTimeCode
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
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:35
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:288
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:1375
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:171
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