HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
visitor.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 #ifndef __GUSD_VISITOR_H__
25 #define __GUSD_VISITOR_H__
26 
27 #include <gusd/api.h>
28 #include <pxr/pxr.h>
29 #include "pxr/usd/usd/prim.h"
30 
31 #include <UT/UT_Interrupt.h>
32 
34 
35 class GU_Detail;
36 
37 
38 /**
39  \deprecated This is being replaced with the more performant GusdUSD_Traverse.
40  See GusdUSD_CustomTraverse for GusdUSD_Traverse implementation that roughly
41  approximates the same configurations supported by this class.
42 
43  Class for performing controlled recursion through usd prims.
44  This includes the ability to exclude/include by visibility state,
45  purpose, prim type, etc.
46  This is the base algorithm that the import style used in
47  pxh_usdRefsSOP is based on.
48 */
50 {
51 public:
52  typedef enum
53  {
57  } TriState;
58 
59  GusdVisitor();
60 
61  bool VisitPrims(
62  const UsdPrim& prim,
63  std::vector<UsdPrim>* results ) const;
64 
66  void SetActiveState(TriState state) { m_activeState = state; }
67 
68  TriState GetRefState() const { return m_refState; }
69  void SetRefState(TriState state) { m_refState = state; }
70 
71  inline bool GetVisitPurpose(const TfToken& purpose) const;
72  void SetVisitPurpose(const TfToken& purpose, bool state)
73  { m_purpose[purpose] = state; }
74 
75  bool GetRecurseUnmatched() const { return m_recurseUnmatched; }
76  void SetRecurseUnmatched(bool state) { m_recurseUnmatched = state; }
77 
78  bool GetRecurseChildren() const { return m_recurseChildren; }
79  void SetRecurseChildren(bool state) { m_recurseChildren = state; }
80 
81  int GetMinDepth() const { return m_minDepth; }
82  void SetMinDepth(int depth) { m_minDepth = depth; }
83 
84  int GetMaxDepth() const { return m_maxDepth; }
85  void SetMaxDepth(int depth)
86  { m_maxDepth = depth < 0 ? INT_MAX : depth; }
87 
88  inline bool VisitPrimType(const TfToken& typeName) const;
89  void SetVisitPrimType(const TfToken& typeName, bool state)
90  { m_visitPrimType[typeName] = state; }
91 
92  bool GetVisitAnyClass() const { return m_visitAnyClass; }
93  void SetVisitAnyClass(bool state) { m_visitAnyClass = state; }
94 
95  bool GetVisitModels() const { return m_visitModels; }
96  void SetVisitModels(bool state) { m_visitModels = state; }
97 
98  bool GetVisitModelGroups() const { return m_visitModelGroups; }
99  void SetVisitModelGroups(bool state) { m_visitModelGroups = state; }
100 
101 
103  void SetModelKindPattern(const std::string &pat );
104 
105  /** Toggle visiting of geometry-containing prims.
106  Just a convenience method that calls SetVisitPrimType() for each
107  geometry-holding prim type.*/
108  void SetVisitGeometryPrims(bool state);
109 
110 protected:
111 
112  bool recursePrims(
113  const UsdPrim& prim,
114  bool active,
115  TfToken purpose,
116  int depth,
117  std::vector<UsdPrim>* results ) const;
118 
119 protected:
122  std::map<TfToken,bool> m_purpose;
123 
128 
129  std::map<TfToken,bool> m_visitPrimType;
134 };
135 
136 
137 bool
139 {
140  std::map<TfToken,bool>::const_iterator it = m_purpose.find(purpose);
141  return it == m_purpose.end() ? false : it->second;
142 }
143 
144 
145 bool
146 GusdVisitor::VisitPrimType(const TfToken& typeName) const
147 {
148  std::map<TfToken,bool>::const_iterator it = m_visitPrimType.find(typeName);
149  return it == m_visitPrimType.end() ? false : it->second;
150 }
151 
153 
154 #endif /* __GUSD_VISITOR_H__ */
int m_minDepth
Definition: visitor.h:126
int GetMinDepth() const
Definition: visitor.h:81
std::map< TfToken, bool > m_visitPrimType
Definition: visitor.h:129
void SetVisitPrimType(const TfToken &typeName, bool state)
Definition: visitor.h:89
TriState GetActiveState() const
Definition: visitor.h:65
bool m_visitModelGroups
Definition: visitor.h:132
bool m_visitModels
Definition: visitor.h:131
const std::string & GetModelKindPattern() const
Definition: visitor.h:102
std::map< TfToken, bool > m_purpose
Definition: visitor.h:122
void SetRefState(TriState state)
Definition: visitor.h:69
bool GetRecurseUnmatched() const
Definition: visitor.h:75
void SetMinDepth(int depth)
Definition: visitor.h:82
bool GetVisitModels() const
Definition: visitor.h:95
bool GetVisitModelGroups() const
Definition: visitor.h:98
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:475
void SetRecurseChildren(bool state)
Definition: visitor.h:79
Definition: token.h:87
void SetVisitPurpose(const TfToken &purpose, bool state)
Definition: visitor.h:72
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
bool GetVisitPurpose(const TfToken &purpose) const
Definition: visitor.h:138
bool m_visitAnyClass
Definition: visitor.h:130
std::string m_modelKindPattern
Definition: visitor.h:133
bool GetRecurseChildren() const
Definition: visitor.h:78
void SetVisitModelGroups(bool state)
Definition: visitor.h:99
Definition: prim.h:132
void SetModelKindPattern(const std::string &pat)
TriState m_refState
Definition: visitor.h:121
void SetRecurseUnmatched(bool state)
Definition: visitor.h:76
TriState m_activeState
Definition: visitor.h:120
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
bool GetVisitAnyClass() const
Definition: visitor.h:92
void SetVisitGeometryPrims(bool state)
bool m_recurseChildren
Definition: visitor.h:125
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool recursePrims(const UsdPrim &prim, bool active, TfToken purpose, int depth, std::vector< UsdPrim > *results) const
int m_maxDepth
Definition: visitor.h:127
bool m_recurseUnmatched
Definition: visitor.h:124
void SetMaxDepth(int depth)
Definition: visitor.h:85
bool VisitPrims(const UsdPrim &prim, std::vector< UsdPrim > *results) const
int GetMaxDepth() const
Definition: visitor.h:84
TriState GetRefState() const
Definition: visitor.h:68
bool VisitPrimType(const TfToken &typeName) const
Definition: visitor.h:146
void SetVisitAnyClass(bool state)
Definition: visitor.h:93
void SetActiveState(TriState state)
Definition: visitor.h:66
void SetVisitModels(bool state)
Definition: visitor.h:96