HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_FindPrims.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 __HUSD_FindPrims_h__
19 #define __HUSD_FindPrims_h__
20 
21 #include "HUSD_API.h"
22 #include "HUSD_DataHandle.h"
23 #include "HUSD_Utils.h"
24 #include <OP/OP_ItemId.h>
25 #include <UT/UT_StringMap.h>
26 #include <UT/UT_StringArray.h>
27 #include <UT/UT_UniquePtr.h>
28 #include <UT/UT_VectorTypes.h>
29 #include <SYS/SYS_Types.h>
30 #include <pxr/pxr.h>
31 
33 class XUSD_PathPattern;
35 
36 class HUSD_PathSet;
37 class HUSD_TimeCode;
38 template <typename T> class UT_Array;
39 
41 {
42 public:
46  bool find_point_instancer_ids = false);
47  // Simple constructors when you just want to operate
48  // on one or an array of primitives and you know the
49  // paths.
51  const UT_StringRef &primpath,
55  const UT_StringArray &primpaths,
59  const HUSD_PathSet &primpaths,
62  ~HUSD_FindPrims();
63 
64  const HUSD_PathSet &getExpandedPathSet() const;
65  const HUSD_PathSet &getCollectionAwarePathSet() const;
66  const HUSD_PathSet &getExcludedPathSet(bool skipdescendants) const;
67  const HUSD_PathSet &getMissingExplicitPathSet() const;
68  const HUSD_PathSet &getExpandedOrMissingExplicitPathSet() const;
69 
70  void setTraversalDemands(HUSD_PrimTraversalDemands demands);
71  HUSD_PrimTraversalDemands traversalDemands() const;
72  void setAssumeWildcardsAroundPlainTokens(bool assume);
73  bool assumeWildcardsAroundPlainTokens() const;
74  void setTrackMissingExplicitPrimitives(bool track_missing);
75  bool trackMissingExplicitPrimitives() const;
76  void setWarnMissingExplicitPrimitives(bool warn_missing);
77  bool warnMissingExplicitPrimitives() const;
78  void setCaseSensitive(bool casesensitive);
79  bool caseSensitive() const;
80  void setFindPointInstancerIds(bool find_instancer_ids);
81  bool findPointInstancerIds() const;
82 
83  // Add a specific set of primitive paths or collection paths to our data.
84  bool addPaths(const HUSD_PathSet &paths);
85  // Evaluate the supplied pattern and add the resulting primitives and
86  // collections to our data.
87  bool addPattern(const UT_StringRef &pattern,
88  int nodeid,
89  const HUSD_TimeCode &timecode);
90  // Evaluate the supplied USD path expression and add the resulting
91  // primitives to our data.
92  bool addPathExpression(const UT_StringRef &path_expr);
93 
94  // Add ancestors or descendents of prims that actually matched.
95  bool addDescendants();
96  bool addAncestors();
97 
98  // Return the map of point instancer paths to the instance ids within
99  // each instancer that matched the pattern. Instance ids will always
100  // be sorted. The ids array for a given instancer may be empty.
102  &getPointInstancerIds() const;
103  bool getExcludedPointInstancerIds(
104  UT_StringMap<UT_Array<int64>> &excludedids,
105  const HUSD_TimeCode &timecode) const;
106 
107  bool getIsEmpty() const;
108  bool getFindPointInstancerIds() const;
109  bool getIsTimeVarying() const;
110  bool allowInstanceProxies() const;
111 
112  /// Generally speaking, HUSD_FindPrims will never return the
113  /// HoudiniLayerInfo prim. But there are some circumstances where we
114  /// may wish to allow it.
115  void setAllowHoudiniLayerInfo(bool allow);
116  bool allowHoudiniLayerInfo() const;
117 
118  /// Returns a collection path, if only a single collection was added.
119  /// Returns an empty string, if primitive target consists of more than
120  /// a single collection.
121  UT_StringHolder getSingleCollectionPath() const;
122 
123  /// Returns the path to the most nested primitive that is the shared
124  /// root primitive of every primitive in our expanded set. If the shared
125  /// root prim is the absolute root, we return an empty string.
126  UT_StringHolder getSharedRootPrim() const;
127 
128  /// Return a string describing the last error generated by a failed
129  /// call to this object's methods.
131  { return myLastError; }
132 
133  // Creates a prim pattern that executes the supplied path expression.
134  // It is safe to use the same string for th input and output parameters.
135  static bool primPatternFromPathExpression(
136  const UT_StringRef &path_expr,
137  UT_StringHolder &pattern);
138  // Creates a path expression if the prim pattern contains only an
139  // invocatino of a path expression auto collection.
140  // It is safe to use the same string for th input and output parameters.
141  static bool pathExpressionFromPrimPattern(
142  const UT_StringRef &pattern,
143  UT_StringHolder &path_expr);
144 
145 private:
146  bool addPattern(const PXR_NS::XUSD_PathPattern &pattern,
147  int nodeid);
148 
149  class husd_FindPrimsPrivate;
150 
152  HUSD_AutoAnyLock &myAnyLock;
153  HUSD_PrimTraversalDemands myDemands;
154  UT_StringHolder myLastError;
155  bool myFindPointInstancerIds;
156  bool myAssumeWildcardsAroundPlainTokens;
157  bool myTrackMissingExplicitPrimitives;
158  bool myWarnMissingExplicitPrimitives;
159  bool myCaseSensitive;
160 };
161 
162 #endif
163 
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
#define HUSD_API
Definition: HUSD_API.h:31
HUSD_PrimTraversalDemands
Definition: HUSD_Utils.h:39
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
GLushort pattern
Definition: glad.h:2583
FMT_INLINE void assume(bool condition)
Definition: format.h:535
const UT_StringHolder & getLastError() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74