6#ifndef MATERIALX_UNIT_H_
7#define MATERIALX_UNIT_H_
16MATERIALX_NAMESPACE_BEGIN
50 virtual float convert(
float input,
const string& inputUnit,
const string& outputUnit)
const = 0;
120 float convert(
float input,
const string& inputUnit,
const string& outputUnit)
const override;
158 std::unordered_map<string, float> _unitScale;
159 std::unordered_map<string, int> _unitEnumeration;
212MATERIALX_NAMESPACE_END
shared_ptr< UnitTypeDef > UnitTypeDefPtr
A shared pointer to a UnitTypeDef.
Definition: Definition.h:67
The top-level Document class.
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
Import and export declarations for the Core library.
shared_ptr< const LinearUnitConverter > ConstLinearUnitConverterPtr
A shared pointer to a const LinearUnitConverter.
Definition: Unit.h:30
shared_ptr< UnitConverter > UnitConverterPtr
A shared pointer to a UnitConverter.
Definition: Unit.h:23
shared_ptr< const UnitConverterRegistry > ConstUnitConverterRegistryPtr
A shared pointer to a const UnitConverterRegistry.
Definition: Unit.h:35
shared_ptr< const UnitConverter > ConstUnitConverterPtr
A shared pointer to a const UnitConverter.
Definition: Unit.h:25
shared_ptr< UnitConverterRegistry > UnitConverterRegistryPtr
A shared pointer to a UnitConverterRegistry.
Definition: Unit.h:33
std::unordered_map< string, UnitConverterPtr > UnitConverterPtrMap
Map of unit converters.
Definition: Unit.h:164
shared_ptr< LinearUnitConverter > LinearUnitConverterPtr
A shared pointer to a LinearUnitConverter.
Definition: Unit.h:28
A converter class for linear units that require only a scalar multiplication.
Definition: Unit.h:85
Vector3 convert(const Vector3 &input, const string &inputUnit, const string &outputUnit) const override
Convert a given value in a given unit to a desired unit.
Vector2 convert(const Vector2 &input, const string &inputUnit, const string &outputUnit) const override
Convert a given value in a given unit to a desired unit.
virtual string getUnitFromInteger(int index) const override
Given an integer index return the unit name in the map used by the converter.
int getUnitAsInteger(const string &unitName) const override
Given a unit name return a value that it can map to as an integer.
void write(DocumentPtr doc) const override
Create unit definitions in a document based on the converter.
static LinearUnitConverterPtr create(UnitTypeDefPtr UnitDef)
Creator.
float conversionRatio(const string &inputUnit, const string &outputUnit) const
Ratio between the given unit to a desired unit.
float convert(float input, const string &inputUnit, const string &outputUnit) const override
Convert a given value in a given unit to a desired unit.
Vector4 convert(const Vector4 &input, const string &inputUnit, const string &outputUnit) const override
Convert a given value in a given unit to a desired unit.
const string & getUnitType() const
Return the unit type string.
Definition: Unit.h:93
const std::unordered_map< string, float > & getUnitScale() const
Return the mappings from unit names to the scale value defined by a linear converter.
Definition: Unit.h:106
An abstract base class for unit converters.
Definition: Unit.h:41
virtual string getUnitFromInteger(int) const
Given an integer index return the unit name in the map used by the converter Returns Empty string if ...
Definition: Unit.h:58
virtual Vector3 convert(const Vector3 &input, const string &inputUnit, const string &outputUnit) const =0
Convert a given value in a given unit to a desired unit.
virtual float convert(float input, const string &inputUnit, const string &outputUnit) const =0
Convert a given value in a given unit to a desired unit.
virtual int getUnitAsInteger(const string &) const
Given a unit name return a value that it can map to as an integer Returns -1 value if not found.
Definition: Unit.h:54
virtual Vector4 convert(const Vector4 &input, const string &inputUnit, const string &outputUnit) const =0
Convert a given value in a given unit to a desired unit.
virtual Vector2 convert(const Vector2 &input, const string &inputUnit, const string &outputUnit) const =0
Convert a given value in a given unit to a desired unit.
virtual void write(DocumentPtr doc) const =0
Create unit definitions in a document based on the converter.
A registry for unit converters.
Definition: Unit.h:169
bool convertToUnit(DocumentPtr doc, const string &unitType, const string &targetUnit)
Convert input values which have a source unit to a given target unit.
int getUnitAsInteger(const string &unitName) const
Given a unit name return a value that it can map to as an integer Returns -1 value if not found.
UnitConverterPtr getUnitConverter(UnitTypeDefPtr def)
Get a unit converter for a given UnitDef Returns any empty pointer if a converter does not exist for ...
void write(DocumentPtr doc) const
Create unit definitions in a document based on registered converters.
static UnitConverterRegistryPtr create()
Creator.
bool removeUnitConverter(UnitTypeDefPtr def)
Remove a unit converter for a given UnitDef.
void clearUnitConverters()
Clear all unit converters from the registry.
bool addUnitConverter(UnitTypeDefPtr def, UnitConverterPtr converter)
Add a unit converter for a given UnitDef.
A unit definition element within a Document.
Definition: Definition.h:457
A vector of two floating-point values.
Definition: Types.h:286
A vector of three floating-point values.
Definition: Types.h:306
A vector of four floating-point values.
Definition: Types.h:328