HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
metrics.h
Go to the documentation of this file.
1 //
2 // Copyright 2021 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_USD_PHYSICS_METRICS_H
8 #define PXR_USD_USD_PHYSICS_METRICS_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/usdPhysics/api.h"
12 #include "pxr/usd/usd/common.h"
13 
15 
16 /// \file usdPhysics/metrics.h
17 ///
18 /// Helper APIs for physics related metrics operations.
19 
20 /// Return *stage*'s authored *kilogramsPerUnit*, or 1.0 if unauthored.
23 
24 /// Return whether *stage* has an authored *kilogramsPerUnit*.
27 
28 /// Author *stage*'s *kilogramsPerUnit*.
29 ///
30 /// \return true if kilogramsPerUnit was successfully set. The stage's
31 /// UsdEditTarget must be either its root layer or session layer.
34  double kilogramsPerUnit);
35 
36 /// Return *true* if the two given metrics are within the provided
37 /// relative *epsilon* of each other, when you need to know an absolute
38 /// metric rather than a scaling factor.
39 ///
40 /// Use like so:
41 /// \code
42 /// double stageUnits = UsdPhysicsGetStageKilogramsPerUnit(stage);
43 ///
44 /// if (UsdPhysicsMassUnitsAre(stageUnits, UsdPhysicsMassUnits::kilograms))
45 /// // do something for kilograms
46 /// else if (UsdPhysicsMassUnitsAre(stageUnits, UsdPhysicsMassUnits::grams))
47 /// // do something for grams
48 /// \endcode
49 ///
50 /// \return *false* if either input is zero or negative, otherwise relative
51 /// floating-point comparison between the two inputs.
53 bool UsdPhysicsMassUnitsAre(double authoredUnits, double standardUnits,
54  double epsilon = 1e-5);
55 
56 /// \class UsdPhysicsMassUnits
57 /// Container class for static double-precision symbols representing common
58 /// mass units of measure expressed in kilograms.
60 public:
61  static constexpr double grams = 0.001;
62  static constexpr double kilograms = 1.0;
63  static constexpr double slugs = 14.5939;
64 };
65 
67 
68 #endif // PXR_USD_USD_PHYSICS_METRICS_H
static constexpr double grams
Definition: metrics.h:61
USDPHYSICS_API bool UsdPhysicsMassUnitsAre(double authoredUnits, double standardUnits, double epsilon=1e-5)
USDPHYSICS_API bool UsdPhysicsSetStageKilogramsPerUnit(const UsdStageWeakPtr &stage, double kilogramsPerUnit)
UsdStagePtr UsdStageWeakPtr
Definition: common.h:38
USDPHYSICS_API double UsdPhysicsGetStageKilogramsPerUnit(const UsdStageWeakPtr &stage)
Return stage's authored kilogramsPerUnit, or 1.0 if unauthored.
USDPHYSICS_API bool UsdPhysicsStageHasAuthoredKilogramsPerUnit(const UsdStageWeakPtr &stage)
Return whether stage has an authored kilogramsPerUnit.
#define USDPHYSICS_API
Definition: api.h:23
static constexpr double kilograms
Definition: metrics.h:62
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static constexpr double slugs
Definition: metrics.h:63