All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
USD_Traverse.h
Go to the documentation of this file.
1 //
2 // Copyright 2017 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
28 #ifndef _GUSD_USD_TRAVERSE_H_
29 #define _GUSD_USD_TRAVERSE_H_
30 
31 
32 #include <PRM/PRM_Name.h>
33 #include <UT/UT_Array.h>
34 #include <UT/UT_Error.h>
35 #include <UT/UT_NonCopyable.h>
36 #include <UT/UT_String.h>
37 #include <UT/UT_StringMap.h>
38 
39 #include "gusd/api.h"
40 #include "gusd/defaultArray.h"
41 #include "gusd/purpose.h"
42 #include "gusd/USD_Utils.h"
43 
44 #include "pxr/pxr.h"
45 #include "pxr/usd/usd/prim.h"
46 
47 
48 class OP_Parameters;
49 class PRM_Template;
50 
51 PXR_NAMESPACE_OPEN_SCOPE
52 
58 {
59 public:
60  struct Opts;
61  typedef std::pair<UsdPrim,exint> PrimIndexPair;
62 
63  virtual ~GusdUSD_Traverse() {}
64 
65  virtual Opts* CreateOpts() const { return nullptr; }
66 
68  virtual bool FindPrims(const UsdPrim& root,
69  UsdTimeCode time,
70  GusdPurposeSet purposes,
71  UT_Array<UsdPrim>& prims,
72  bool skipRoot=true,
73  const Opts* opts=nullptr) const = 0;
74 
80  virtual bool FindPrims(const UT_Array<UsdPrim>& roots,
81  const GusdDefaultArray<UsdTimeCode>& times,
82  const GusdDefaultArray<GusdPurposeSet>& purposes,
83  UT_Array<PrimIndexPair>& prims,
84  bool skipRoot=true,
85  const Opts* opts=nullptr) const = 0;
86 
87  bool FindPrims(const UT_Array<UsdPrim>& roots,
88  const GusdDefaultArray<UsdTimeCode>& times,
89  const GusdDefaultArray<GusdPurposeSet>& purposes,
90  UT_Array<UsdPrim>& prims,
91  bool skipRoot=true,
92  const Opts* opts=nullptr) const;
93 
96  struct Opts
97  {
98  Opts() { Reset(); }
99  virtual ~Opts() {}
100 
102  virtual void Reset() {}
103 
104  virtual bool Configure(OP_Parameters& parms, fpreal t) = 0;
105  };
106 
107 };
108 
109 
110 class GusdUSD_TraverseType
111 {
112 public:
113  GusdUSD_TraverseType(const GusdUSD_Traverse* traversal,
114  const char* name,
115  const char* label,
116  const PRM_Template* templates=nullptr,
117  const char* help=nullptr);
118 
119  const PRM_Name& GetName() const { return _name; }
120  const PRM_Template* GetTemplates() const { return _templates; }
121  const char* GetHelp() const { return _help; }
122 
123  const GusdUSD_Traverse& operator*() const { return *_traversal; }
124  const GusdUSD_Traverse* operator->() const { return _traversal; }
125 
126 private:
127  const GusdUSD_Traverse* const _traversal;
128  const PRM_Name _name;
129  const PRM_Template* const _templates;
130  const UT_String _help;
131 };
132 
133 
136 {
137  GusdUSD_TraverseControl() : _visitChildren(true) {}
138 
139  bool GetVisitChildren() const { return _visitChildren; }
140  void SetVisitChildren(bool tf) { _visitChildren = tf; }
141  void PruneChildren() { SetVisitChildren(false); }
142 
143 private:
144  bool _visitChildren;
145 };
146 
147 
149 class GusdUSD_TraverseTable : UT_NonCopyable
150 {
151 public:
152  typedef UT_StringMap<const GusdUSD_TraverseType*> Map;
153  typedef Map::const_iterator const_iterator;
154  typedef Map::iterator iterator;
155 
156  GUSD_API
157  static GusdUSD_TraverseTable& GetInstance();
158 
159  GUSD_API
160  void Register(const GusdUSD_TraverseType* type);
161 
162  GUSD_API
163  const GusdUSD_TraverseType* Find(const char* name) const;
164 
165  GUSD_API
166  const GusdUSD_Traverse* FindTraversal(const char* name) const;
167 
168  const char* GetDefault() const
169  { return _default; }
170 
171  void SetDefault(const char* name)
172  { _default.harden(name); }
173 
174  iterator begin() { return _map.begin(); }
175  const_iterator begin() const { return _map.begin(); }
176 
177  iterator end() { return _map.end(); }
178  const_iterator end() const { return _map.end(); }
179 
180 private:
181  Map _map;
182  UT_String _default;
183 };
184 
185 PXR_NAMESPACE_CLOSE_SCOPE
186 
187 #endif /*_GUSD_USD_TRAVERSE_H_*/
Table for registering custom stage traversals.
Definition: USD_Traverse.h:149
virtual bool FindPrims(const UsdPrim &root, UsdTimeCode time, GusdPurposeSet purposes, UT_Array< UsdPrim > &prims, bool skipRoot=true, const Opts *opts=nullptr) const =0
Find prims beneath the given root.
Base class for custom stage traversal.
Definition: USD_Traverse.h:57
Helper to provide control over traversal through children.
Definition: USD_Traverse.h:135
Base class that can be derived to provide configuration options to the traversal. ...
Definition: USD_Traverse.h:96
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
virtual void Reset()
Reset options back to defaults.
Definition: USD_Traverse.h:102