HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XUSD_FindPrimsTask.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_FindPrimsTask_h__
19 #define __XUSD_FindPrimsTask_h__
20 
21 #include "HUSD_API.h"
22 #include "XUSD_PathSet.h"
23 #include "XUSD_Utils.h"
24 #include <UT/UT_PathPattern.h>
26 #include <SYS/SYS_Deprecated.h>
27 #include <pxr/usd/usd/stage.h>
28 #include <pxr/usd/usd/primRange.h>
29 #include <pxr/usd/sdf/path.h>
30 #include <pxr/base/tf/token.h>
31 
34 
36 
37 // Generic base class for gathering per-prim information during a multithreaded
38 // traversal of a stage using an XUSD_PathPatthern to restrict the traversal.
40 {
41 public:
42  virtual ~XUSD_FindPrimsTaskData();
43  virtual void addToThreadData(const UsdPrim &prim, bool *prune) = 0;
44 
45  /// Generally speaking, HUSD_FindPrims will never return the
46  /// HoudiniLayerInfo prim. But there are some circumstances where we
47  /// may wish to allow it.
48  void setAllowHoudiniLayerInfo(bool allow)
49  { myAllowHoudiniLayerInfo = allow; }
50  bool allowHoudiniLayerInfo() const
51  { return myAllowHoudiniLayerInfo; }
52 
53 private:
54  bool myAllowHoudiniLayerInfo = false;
55 };
56 
57 // Subclass of XUSD_FindPrimsTaskData that specifically collects the SdfPaths
58 // of all USD prims found in the traversal into an XUSD_PathSet.
60 {
61 public:
62  XUSD_FindPrimPathsTaskData() = default;
63  ~XUSD_FindPrimPathsTaskData() override;
64 
67  = delete;
68 
69  void addToThreadData(const UsdPrim &prim, bool *prune) override;
70 
71  void gatherPathsFromThreads(XUSD_PathSet &paths);
72 
73 private:
74  class FindPrimPathsTaskThreadData
75  {
76  public:
77  SdfPathVector myPaths;
78  };
81 
82  FindPrimPathsTaskThreadDataTLS myThreadData;
83 };
84 
85 // Subclass of XUSD_FindPrimsTaskData that specifically collects the UsdPrims
86 // of all USD prims found in the traversal into a UT_Array<UsdPrim>.
88 {
89 public:
90  XUSD_FindUsdPrimsTaskData() = default;
91  ~XUSD_FindUsdPrimsTaskData() override;
92 
95  = delete;
96 
97  void addToThreadData(const UsdPrim &prim, bool *prune) override;
98 
99  void gatherPrimsFromThreads(UT_Array<UsdPrim> &prims);
100  void gatherPrimsFromThreads(std::vector<UsdPrim> &prims);
101 
102 private:
103  class FindUsdPrimsTaskThreadData
104  {
105  public:
106  UT_Array<UsdPrim> myPrims;
107  };
110 
111  FindUsdPrimsTaskThreadDataTLS myThreadData;
112 };
113 
114 // Perform a multithreaded traversal of a stage guided by a UT_PathPattern.
115 // Data is collected into an XUSD_FindPrimsTaskData object by calling its
116 // addToThreadData method with all matching prims.
117 HUSD_API void
119  const UsdPrim& prim,
121  const Usd_PrimFlagsPredicate &predicate,
122  const UT_PathPattern *pattern,
123  const XUSD_SimpleAutoCollection *autocollection);
124 
127 
128 #endif
129 
HUSD_API void XUSDfindPrims(const UsdPrim &prim, XUSD_FindPrimsTaskData &data, const Usd_PrimFlagsPredicate &predicate, const UT_PathPattern *pattern, const XUSD_SimpleAutoCollection *autocollection)
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:623
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
#define HUSD_API
Definition: HUSD_API.h:32
virtual void addToThreadData(const UsdPrim &prim, bool *prune)=0
bool allowHoudiniLayerInfo() const
Definition: prim.h:133
GLushort pattern
Definition: glad.h:2583
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:211
void setAllowHoudiniLayerInfo(bool allow)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
LeafData & operator=(const LeafData &)=delete
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
void prune(TreeT &tree, typename TreeT::ValueType tolerance=zeroVal< typename TreeT::ValueType >(), bool threaded=true, size_t grainSize=1)
Reduce the memory footprint of a tree by replacing with tiles any nodes whose values are all the same...
Definition: Prune.h:335
Definition: format.h:895