forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnitSystem.h
99 lines (74 loc) · 2.69 KB
/
UnitSystem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
// All rights reserved. See LICENSE.txt for license.
//
#ifndef MATERIALX_UNITSYSTEM_H
#define MATERIALX_UNITSYSTEM_H
/// @file
/// Unit system classes
#include <MaterialXGenShader/Library.h>
#include <MaterialXGenShader/ShaderNode.h>
#include <MaterialXGenShader/ShaderNodeImpl.h>
#include <MaterialXGenShader/TypeDesc.h>
#include <MaterialXCore/Unit.h>
#include <MaterialXCore/Document.h>
namespace MaterialX
{
class ShaderGenerator;
/// A shared pointer to a UnitSystem
using UnitSystemPtr = shared_ptr<class UnitSystem>;
/// @struct @UnitTransform
/// Structure that represents unit transform information
struct UnitTransform
{
UnitTransform(const string& ss, const string& ts, const TypeDesc* t, const string& unittype);
string sourceUnit;
string targetUnit;
const TypeDesc* type;
string unitType;
/// Comparison operator
bool operator==(const UnitTransform& rhs) const
{
return sourceUnit == rhs.sourceUnit &&
targetUnit == rhs.targetUnit &&
type == rhs.type &&
unitType == rhs.unitType;
}
};
/// @class UnitSystem
/// Base unit system support
class UnitSystem
{
public:
virtual ~UnitSystem() { }
/// Create a new UnitSystem
static UnitSystemPtr create(const string& language);
/// Return the UnitSystem name
virtual const string& getName() const
{
return UnitSystem::UNITSYTEM_NAME;
}
/// Assign unit converter registry replacing any previous assignment
virtual void setUnitConverterRegistry(UnitConverterRegistryPtr registry);
/// Returns the currently assigned unit converter registry
virtual UnitConverterRegistryPtr getUnitConverterRegistry() const;
/// assign document with unit implementations replacing any previously loaded content.
virtual void loadLibrary(DocumentPtr document);
/// Returns whether this unit system supports a provided transform
bool supportsTransform(const UnitTransform& transform) const;
/// Create a node to use to perform the given unit space transformation.
ShaderNodePtr createNode(ShaderGraph* parent, const UnitTransform& transform, const string& name,
GenContext& context) const;
/// Returns an implementation name for a given transform
virtual string getImplementationName(const UnitTransform& transform, const string& unitname) const;
static const string UNITSYTEM_NAME;
protected:
// Protected constructor
UnitSystem(const string& language);
protected:
UnitConverterRegistryPtr _unitRegistry;
DocumentPtr _document;
string _language;
};
} // namespace MaterialX
#endif