All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
usdInArgs.h
1 //
2 // Copyright 2016 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 PXRUSDKATANA_USDIN_ARGS_H
25 #define PXRUSDKATANA_USDIN_ARGS_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usdGeom/bboxCache.h"
29 #include "pxr/usd/usdSkel/cache.h"
30 #include "pxr/base/tf/refPtr.h"
31 
32 #include <tbb/enumerable_thread_specific.h>
33 
40 
41 #include <FnAttribute/FnAttribute.h>
42 
43 PXR_NAMESPACE_OPEN_SCOPE
44 
47 
79 
80 
82 {
83 
84 public:
85 
86  typedef std::map<std::string, std::vector<std::string> > StringListMap;
87 
88  static PxrUsdKatanaUsdInArgsRefPtr New(
89  UsdStageRefPtr stage,
90  const std::string& rootLocation,
91  const std::string& isolatePath,
92  const std::string& sessionLocation,
93  FnAttribute::GroupAttribute sessionAttr,
94  const std::string& ignoreLayerRegex,
95  double currentTime,
96  double shutterOpen,
97  double shutterClose,
98  const std::vector<double>& motionSampleTimes,
99  const StringListMap& extraAttributesOrNamespaces,
100  const std::vector<TfToken>& materialBindingPurposes,
101  bool prePopulate,
102  bool verbose,
103  const char * errorMessage = 0) {
104  return TfCreateRefPtr(new PxrUsdKatanaUsdInArgs(
105  stage,
106  rootLocation,
107  isolatePath,
108  sessionLocation,
109  sessionAttr,
110  ignoreLayerRegex,
111  currentTime,
112  shutterOpen,
113  shutterClose,
114  motionSampleTimes,
115  extraAttributesOrNamespaces,
116  materialBindingPurposes,
117  prePopulate,
118  verbose,
119  errorMessage));
120  }
121 
122  // bounds computation is kind of important, so we centralize it here.
123  std::vector<GfBBox3d> ComputeBounds(
124  const UsdPrim& prim,
125  const std::vector<double>& motionSampleTimes,
126  bool applyLocalTransform = false);
127 
128  UsdPrim GetRootPrim() const;
129 
130  UsdStageRefPtr GetStage() const {
131  return _stage;
132  }
133 
134  std::string GetFileName() const {
135  return _stage->GetRootLayer()->GetIdentifier();
136  }
137 
138  const std::string& GetRootLocationPath() const {
139  return _rootLocation;
140  }
141 
142  const std::string& GetIsolatePath() const {
143  return _isolatePath;
144  }
145 
146  const std::string& GetSessionLocationPath() const {
147  return _sessionLocation;
148  }
149 
150  FnAttribute::GroupAttribute GetSessionAttr() {
151  return _sessionAttr;
152  }
153 
154  const std::string& GetIgnoreLayerRegex() const {
155  return _ignoreLayerRegex;
156  }
157 
158  double GetCurrentTime() const {
159  return _currentTime;
160  }
161 
162  double GetShutterOpen() const {
163  return _shutterOpen;
164  }
165 
166  double GetShutterClose() const {
167  return _shutterClose;
168  }
169 
170  const std::vector<double>& GetMotionSampleTimes() const {
171  return _motionSampleTimes;
172  }
173 
174  const StringListMap& GetExtraAttributesOrNamespaces() const {
175  return _extraAttributesOrNamespaces;
176  }
177 
178  const std::vector<TfToken>& GetMaterialBindingPurposes() const {
179  return _materialBindingPurposes;
180  }
181 
182  bool GetPrePopulate() const {
183  return _prePopulate;
184  }
185 
186  bool IsVerbose() const {
187  return _verbose;
188  }
189 
190  std::map<double, UsdGeomBBoxCache>& GetBBoxCache() {
191  return _bboxCaches.local();
192  }
193 
194  UsdSkelCache& GetUsdSkelCache() {
195  return _usdSkelCache;
196  }
197 
198  const std::string & GetErrorMessage() {
199  return _errorMessage;
200  }
201 private:
202 
204  UsdStageRefPtr stage,
205  const std::string& rootLocation,
206  const std::string& isolatePath,
207  const std::string& sessionLocation,
208  FnAttribute::GroupAttribute sessionAttr,
209  const std::string& ignoreLayerRegex,
210  double currentTime,
211  double shutterOpen,
212  double shutterClose,
213  const std::vector<double>& motionSampleTimes,
214  const StringListMap& extraAttributesOrNamespaces,
215  const std::vector<TfToken>& materialBindingPurposes,
216  bool prePopulate,
217  bool verbose,
218  const char * errorMessage = 0);
219 
221 
222  UsdStageRefPtr _stage;
223 
224  std::string _rootLocation;
225  std::string _isolatePath;
226 
227  std::string _sessionLocation;
228  FnAttribute::GroupAttribute _sessionAttr;
229  std::string _ignoreLayerRegex;
230 
231  double _currentTime;
232  double _shutterOpen;
233  double _shutterClose;
234  std::vector<double> _motionSampleTimes;
235 
236  // maps the root-level attribute name to the specified attributes or namespaces
237  StringListMap _extraAttributesOrNamespaces;
238 
239  std::vector<TfToken> _materialBindingPurposes;
240 
241  bool _prePopulate;
242  bool _verbose;
243 
244  typedef tbb::enumerable_thread_specific< std::map<double, UsdGeomBBoxCache> > _ThreadLocalBBoxCaches;
245  _ThreadLocalBBoxCaches _bboxCaches;
246 
247  // Cache for accelerating UsdSkel skinning data calculation.
248  UsdSkelCache _usdSkelCache;
249 
250  std::string _errorMessage;
251 
252 };
253 
254 
255 // utility to make it easier to exit earlier from InitUsdInArgs
256 struct ArgsBuilder
257 {
258  UsdStageRefPtr stage;
259  std::string rootLocation;
260  std::string isolatePath;
261  std::string sessionLocation;
262  FnAttribute::GroupAttribute sessionAttr;
263  std::string ignoreLayerRegex;
264  double currentTime;
265  double shutterOpen;
266  double shutterClose;
267  std::vector<double> motionSampleTimes;
268  PxrUsdKatanaUsdInArgs::StringListMap extraAttributesOrNamespaces;
269  std::vector<TfToken> materialBindingPurposes;
270  bool prePopulate;
271  bool verbose;
272  const char * errorMessage;
273 
274 
275  ArgsBuilder()
276  : currentTime(0.0)
277  , shutterOpen(0.0)
278  , shutterClose(0.0)
279  , prePopulate(false)
280  , verbose(true)
281  , errorMessage(0)
282  {
283  }
284 
286  {
287  return PxrUsdKatanaUsdInArgs::New(
288  stage,
289  rootLocation,
290  isolatePath,
291  sessionLocation,
292  sessionAttr.isValid() ? sessionAttr :
293  FnAttribute::GroupAttribute(true),
294  ignoreLayerRegex,
295  currentTime,
296  shutterOpen,
297  shutterClose,
298  motionSampleTimes,
299  extraAttributesOrNamespaces,
300  materialBindingPurposes,
301  prePopulate,
302  verbose,
303  errorMessage);
304  }
305 
306  void update(PxrUsdKatanaUsdInArgsRefPtr other)
307  {
308  stage = other->GetStage();
309  rootLocation = other->GetRootLocationPath();
310  isolatePath = other->GetIsolatePath();
311  sessionLocation = other->GetSessionLocationPath();
312  sessionAttr = other->GetSessionAttr();
313  ignoreLayerRegex = other->GetIgnoreLayerRegex();
314  currentTime = other->GetCurrentTime();
315  shutterOpen = other->GetShutterOpen();
316  shutterClose = other->GetShutterClose();
317  motionSampleTimes = other->GetMotionSampleTimes();
318  extraAttributesOrNamespaces = other->GetExtraAttributesOrNamespaces();
319  materialBindingPurposes = other->GetMaterialBindingPurposes();
320  prePopulate = other->GetPrePopulate();
321  verbose = other->IsVerbose();
322  errorMessage = other->GetErrorMessage().c_str();
323  }
324 
325  PxrUsdKatanaUsdInArgsRefPtr buildWithError(std::string errorStr)
326  {
327  errorMessage = errorStr.c_str();
328  return build();
329  }
330 
331 };
332 
333 
334 PXR_NAMESPACE_CLOSE_SCOPE
335 
336 #endif // PXRUSDKATANA_USDIN_ARGS_H
Thread-safe cache for accessing query objects for evaluating skeletal data.
Definition: cache.h:58
USD_API SdfLayerHandle GetRootLayer() const
Return this stage&#39;s root layer.
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:72
The sessionAttr is a structured GroupAttribute argument for delivering edits to the session layer of ...
Definition: usdInArgs.h:81
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131