HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UnitSystem.h
Go to the documentation of this file.
1 //
2 // TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
3 // All rights reserved. See LICENSE.txt for license.
4 //
5 
6 #ifndef MATERIALX_UNITSYSTEM_H
7 #define MATERIALX_UNITSYSTEM_H
8 
9 /// @file
10 /// Unit system classes
11 
13 
17 #include <MaterialXCore/Unit.h>
18 
19 #include <MaterialXCore/Document.h>
20 
22 
23 class ShaderGenerator;
24 
25 /// A shared pointer to a UnitSystem
26 using UnitSystemPtr = shared_ptr<class UnitSystem>;
27 
28 /// @struct @UnitTransform
29 /// Structure that represents unit transform information
31 {
32  UnitTransform(const string& ss, const string& ts, const TypeDesc* t, const string& unittype);
33 
34  string sourceUnit;
35  string targetUnit;
36  const TypeDesc* type;
37  string unitType;
38 
39  /// Comparison operator
40  bool operator==(const UnitTransform& rhs) const
41  {
42  return sourceUnit == rhs.sourceUnit &&
43  targetUnit == rhs.targetUnit &&
44  type == rhs.type &&
45  unitType == rhs.unitType;
46  }
47 };
48 
49 /// @class UnitSystem
50 /// Base unit system support
52 {
53  public:
54  virtual ~UnitSystem() { }
55 
56  /// Create a new UnitSystem
57  static UnitSystemPtr create(const string& target);
58 
59  /// Return the UnitSystem name
60  virtual const string& getName() const
61  {
63  }
64 
65  /// Assign unit converter registry replacing any previous assignment
66  virtual void setUnitConverterRegistry(UnitConverterRegistryPtr registry);
67 
68  /// Returns the currently assigned unit converter registry
69  virtual UnitConverterRegistryPtr getUnitConverterRegistry() const;
70 
71  /// assign document with unit implementations replacing any previously loaded content.
72  virtual void loadLibrary(DocumentPtr document);
73 
74  /// Returns whether this unit system supports a provided transform
75  bool supportsTransform(const UnitTransform& transform) const;
76 
77  /// Create a node to use to perform the given unit space transformation.
78  ShaderNodePtr createNode(ShaderGraph* parent, const UnitTransform& transform, const string& name,
79  GenContext& context) const;
80 
81  /// Returns an implementation for a given transform
82  virtual ImplementationPtr getImplementation(const UnitTransform& transform, const string& unitname) const;
83 
84  static const string UNITSYTEM_NAME;
85 
86  protected:
87  // Protected constructor
88  UnitSystem(const string& language);
89 
90  protected:
93  string _target;
94 };
95 
97 
98 #endif
virtual const string & getName() const
Return the UnitSystem name.
Definition: UnitSystem.h:60
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:23
shared_ptr< class UnitSystem > UnitSystemPtr
A shared pointer to a UnitSystem.
Definition: UnitSystem.h:26
static const string UNITSYTEM_NAME
Definition: UnitSystem.h:84
MX_FORMAT_API void loadLibrary(const FilePath &file, DocumentPtr doc, const FileSearchPath &searchPath=FileSearchPath(), const XmlReadOptions *readOptions=nullptr)
Load a given MaterialX library into a document.
#define MX_GENSHADER_API
Definition: Export.h:18
GLuint const GLchar * name
Definition: glcorearb.h:786
GLdouble GLdouble t
Definition: glew.h:1403
GLenum target
Definition: glcorearb.h:1667
string _target
Definition: UnitSystem.h:93
GLuint GLenum GLenum transform
Definition: glew.h:15055
string targetUnit
Definition: UnitSystem.h:35
shared_ptr< class ShaderNode > ShaderNodePtr
Shared pointer to a ShaderNode.
Definition: ShaderNode.h:35
const TypeDesc * type
Definition: UnitSystem.h:36
shared_ptr< Implementation > ImplementationPtr
A shared pointer to an Implementation.
Definition: Definition.h:37
string sourceUnit
Definition: UnitSystem.h:34
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
virtual ~UnitSystem()
Definition: UnitSystem.h:54
shared_ptr< UnitConverterRegistry > UnitConverterRegistryPtr
A shared pointer to a UnitConverterRegistry.
Definition: Unit.h:33
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:24
UnitConverterRegistryPtr _unitRegistry
Definition: UnitSystem.h:91
DocumentPtr _document
Definition: UnitSystem.h:92
type
Definition: core.h:1059
bool operator==(const UnitTransform &rhs) const
Comparison operator.
Definition: UnitSystem.h:40
string unitType
Definition: UnitSystem.h:37