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 "HUSD_TimeCode.h"
23 #include "XUSD_PathSet.h"
24 #include "XUSD_Utils.h"
25 #include <UT/UT_PathPattern.h>
26 #include <UT/UT_StringMap.h>
28 #include <SYS/SYS_Deprecated.h>
29 #include <pxr/usd/usd/stage.h>
30 #include <pxr/usd/usd/primRange.h>
31 #include <pxr/usd/sdf/path.h>
32 #include <pxr/base/tf/token.h>
33 
36 
38 
39 // Generic base class for gathering per-prim information during a multithreaded
40 // traversal of a stage using an XUSD_PathPatthern to restrict the traversal.
42 {
43 public:
44  XUSD_FindPrimsTaskData() = default;
45  virtual ~XUSD_FindPrimsTaskData();
46 
47  // Called when a matching prim is found.
48  virtual void addToThreadData(const UsdPrim &prim,
49  bool *prune) = 0;
50  // Called when a match is made to point instancer instances.
51  virtual void addInstanceIdsToThreadData(const UsdPrim &prim,
52  const UT_Array<int64> &&instance_ids)
53  { }
54 
55  /// Generally speaking, HUSD_FindPrims will never return the
56  /// HoudiniLayerInfo prim. But there are some circumstances where we
57  /// may wish to allow it.
58  void setAllowHoudiniLayerInfo(bool allow)
59  { myAllowHoudiniLayerInfo = allow; }
60  bool allowHoudiniLayerInfo() const
61  { return myAllowHoudiniLayerInfo; }
62  /// Instance ID collection for point instancers. When enabled,
63  /// the traversal task stores IDs returned by matchPrimitive.
64  void setCollectInstanceIds(bool collect)
65  { myCollectInstanceIds = collect; }
66  bool collectsInstanceIds() const
67  { return myCollectInstanceIds; }
68 
69 private:
70  bool myAllowHoudiniLayerInfo = false;
71  bool myCollectInstanceIds = false;
72 };
73 
74 // Subclass of XUSD_FindPrimsTaskData that specifically collects the SdfPaths
75 // of all USD prims found in the traversal into an XUSD_PathSet.
77 {
78 public:
80  : myTimeCode(timecode)
81  { }
82  ~XUSD_FindPrimPathsTaskData() override;
83 
86  = delete;
87 
88  // If we are collecting instance ids and the prim is a point instancer,
89  // all ids will be added from this instancer.
90  void addToThreadData(const UsdPrim &prim,
91  bool *prune) override;
92  // Record the point instancer instance ids matching a collection.
93  void addInstanceIdsToThreadData(const UsdPrim &prim,
94  const UT_Array<int64> &&instance_ids) override;
95  void gatherDataFromThreads(XUSD_PathSet &paths,
96  UT_StringMap<UT_Array<int64>> *instance_ids);
97 
98 private:
99  class FindPrimPathsTaskThreadData
100  {
101  public:
102  SdfPathVector myPaths;
103  UT_StringMap<UT_Array<int64>> myInstanceIds;
104  };
105  using FindPrimPathsTaskThreadDataTLS =
107 
108  FindPrimPathsTaskThreadDataTLS myThreadData;
109  HUSD_TimeCode myTimeCode;
110 };
111 
112 // Subclass of XUSD_FindPrimsTaskData that specifically collects the UsdPrims
113 // of all USD prims found in the traversal into a UT_Array<UsdPrim>.
115 {
116 public:
117  XUSD_FindUsdPrimsTaskData() = default;
118  ~XUSD_FindUsdPrimsTaskData() override;
119 
122  = delete;
123 
124  void addToThreadData(const UsdPrim &prim, bool *prune) override;
125 
126  void gatherPrimsFromThreads(UT_Array<UsdPrim> &prims);
127  void gatherPrimsFromThreads(std::vector<UsdPrim> &prims);
128 
129 private:
130  class FindUsdPrimsTaskThreadData
131  {
132  public:
133  UT_Array<UsdPrim> myPrims;
134  };
137 
138  FindUsdPrimsTaskThreadDataTLS myThreadData;
139 };
140 
141 // Perform a multithreaded traversal of a stage guided by a UT_PathPattern.
142 // Data is collected into an XUSD_FindPrimsTaskData object by calling its
143 // addToThreadData method with all matching prims.
144 HUSD_API void
146  const UsdPrim& prim,
148  const Usd_PrimFlagsPredicate &predicate);
149 HUSD_API void
151  const UsdPrim& prim,
153  const Usd_PrimFlagsPredicate &predicate,
154  const UT_PathPattern *pattern);
155 HUSD_API void
157  const UsdPrim& prim,
159  const Usd_PrimFlagsPredicate &predicate,
160  const XUSD_SimpleAutoCollection *autocollection);
161 
164 
165 #endif
166 
*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:632
#define SYS_DEPRECATED_PUSH_DISABLE()
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
#define SYS_DEPRECATED_POP_DISABLE()
virtual void addInstanceIdsToThreadData(const UsdPrim &prim, const UT_Array< int64 > &&instance_ids)
#define HUSD_API
Definition: HUSD_API.h:31
HUSD_API void XUSDfindPrims(const UsdPrim &prim, XUSD_FindPrimsTaskData &data, const Usd_PrimFlagsPredicate &predicate)
XUSD_FindPrimPathsTaskData(const HUSD_TimeCode &timecode)
virtual void addToThreadData(const UsdPrim &prim, bool *prune)=0
void setCollectInstanceIds(bool collect)
bool allowHoudiniLayerInfo() const
std::vector< class SdfPath > SdfPathVector
Definition: prim.h:116
bool collectsInstanceIds() const
GLushort pattern
Definition: glad.h:2583
void setAllowHoudiniLayerInfo(bool allow)
LeafData & operator=(const LeafData &)=delete
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
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:1821