HDK
 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 //
24 /**
25  \file
26  \brief Methods for USD scene traversal.
27 */
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 
52 
53 /** Base class for custom stage traversal.
54 
55  To register traversals, define a static GusdUSD_TraverseType singleton
56  that takes an instance of the traverse object. */
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 
67  /** Find prims beneath the given root.*/
68  virtual bool FindPrims(const UsdPrim& root,
70  GusdPurposeSet purposes,
71  UT_Array<UsdPrim>& prims,
72  bool skipRoot=true,
73  const Opts* opts=nullptr) const = 0;
74 
75  /** Find prims beneath the given root prims.
76  Note that the input array of prims may contain invalid prims.
77  The returned @a prims array holds the new prims, and the index
78  of their root prim from the @a roots array. The array is sorted
79  by the index and the prim path.*/
80  virtual bool FindPrims(const UT_Array<UsdPrim>& roots,
81  const GusdDefaultArray<UsdTimeCode>& times,
82  const GusdDefaultArray<GusdPurposeSet>& purposes,
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 
94  /** Base class that can be derived to provide
95  configuration options to the traversal.*/
96  struct Opts
97  {
98  Opts() { Reset(); }
99  virtual ~Opts() {}
100 
101  /** Reset options back to defaults.*/
102  virtual void Reset() {}
103 
104  virtual bool Configure(OP_Parameters& parms, fpreal t) = 0;
105  };
106 
107 };
108 
109 
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 
134 /** Helper to provide control over traversal through children.*/
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 
148 /** Table for registering custom stage traversals. */
150 {
151 public:
155 
156  GUSD_API
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 
186 
187 #endif /*_GUSD_USD_TRAVERSE_H_*/
virtual Opts * CreateOpts() const
Definition: USD_Traverse.h:65
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
void SetDefault(const char *name)
Definition: USD_Traverse.h:171
GT_API const UT_StringHolder time
Map::iterator iterator
Definition: USD_Traverse.h:154
Map::const_iterator const_iterator
Definition: USD_Traverse.h:153
void SetVisitChildren(bool tf)
Definition: USD_Traverse.h:140
virtual bool Configure(OP_Parameters &parms, fpreal t)=0
GUSD_API void Register(const GusdUSD_TraverseType *type)
GUSD_API const GusdUSD_TraverseType * Find(const char *name) const
std::string help(const App *app, const Error &e)
Printout the full help string on error (if this fn is set, the old default for CLI11) ...
Definition: CLI11.h:8978
bool GetVisitChildren() const
Definition: USD_Traverse.h:139
UT_StringMap< const GusdUSD_TraverseType * > Map
Definition: USD_Traverse.h:152
virtual bool FindPrims(const UsdPrim &root, UsdTimeCode time, GusdPurposeSet purposes, UT_Array< UsdPrim > &prims, bool skipRoot=true, const Opts *opts=nullptr) const =0
const char * GetDefault() const
Definition: USD_Traverse.h:168
const char * GetHelp() const
Definition: USD_Traverse.h:121
const_iterator begin() const
Definition: USD_Traverse.h:175
const PRM_Name & GetName() const
Definition: USD_Traverse.h:119
void harden()
Take shallow copy and make it deep.
Definition: UT_String.h:215
std::pair< UsdPrim, exint > PrimIndexPair
Definition: USD_Traverse.h:60
const PRM_Template * GetTemplates() const
Definition: USD_Traverse.h:120
Definition: prim.h:135
virtual ~GusdUSD_Traverse()
Definition: USD_Traverse.h:63
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual void Reset()
Definition: USD_Traverse.h:102
GLdouble t
Definition: glad.h:2397
const_iterator end() const
Definition: USD_Traverse.h:178
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
fpreal64 fpreal
Definition: SYS_Types.h:277
static GUSD_API GusdUSD_TraverseTable & GetInstance()
const GusdUSD_Traverse & operator*() const
Definition: USD_Traverse.h:123
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
#define GUSD_API
Definition: api.h:40
const GusdUSD_Traverse * operator->() const
Definition: USD_Traverse.h:124
GusdPurposeSet
Definition: purpose.h:39
type
Definition: core.h:1059
GUSD_API const GusdUSD_Traverse * FindTraversal(const char *name) const