Thermal Camera SDK 11.3.0
SDK for Optris Thermal Cameras
Loading...
Searching...
No Matches
TemperatureConverter.h
Go to the documentation of this file.
1// Copyright (c) 2008-2026 Optris GmbH & Co. KG
2
11
12#pragma once
13
14#include "otcsdk/Api.h"
16
17
18namespace optris
19{
20
23{
24public:
27
34
35
42
48 TemperaturePrecision getPrecision() const noexcept;
49
57 float toTemperature(unsigned short value) const noexcept;
58
69 float toTemperature(float value) const noexcept;
70
78 unsigned short toValue(float temperature) const noexcept;
79
87 bool isTemperatureValid(float temperature) noexcept;
88
96 bool isValueValid(unsigned short value) noexcept;
97
103 float getInvalidTemperature() const noexcept;
104
110 unsigned short getInvalidValue() const noexcept;
111
112
113private:
114 TemperaturePrecision _precision;
115
116 float _factor;
117 float _offset;
118
119 unsigned short _invalidValue;
120};
121
122
123// Inline implementations
125{
126 return _precision;
127}
128
129inline float TemperatureConverter::toTemperature(unsigned short value) const noexcept
130{
131 return (value == _invalidValue) ? INVALID_TEMPERATURE : static_cast<float>(value) / _factor + _offset;
132}
133
134inline float TemperatureConverter::toTemperature(float value) const noexcept
135{
136 // Compare against the float-widened invalid sentinel rather than
137 // truncating to unsigned short, otherwise valid sub-integer values
138 // in [0, 1) would be wrongly flagged as invalid.
139 return (value == static_cast<float>(_invalidValue)) ? INVALID_TEMPERATURE : value / _factor + _offset;
140}
141
142inline unsigned short TemperatureConverter::toValue(float temperature) const noexcept
143{
144 return (temperature <= INVALID_TEMPERATURE) ? _invalidValue : static_cast<unsigned short>((temperature - _offset) * _factor);
145}
146
147inline bool TemperatureConverter::isTemperatureValid(float temperature) noexcept
148{
149 return temperature > INVALID_TEMPERATURE;
150}
151
152inline bool TemperatureConverter::isValueValid(unsigned short value) noexcept
153{
154 return value != _invalidValue;
155}
156
158{
159 return INVALID_TEMPERATURE;
160}
161
162inline unsigned short TemperatureConverter::getInvalidValue() const noexcept
163{
164 return _invalidValue;
165}
166
167} // namespace optris
Contains defines controlling the Windows DLL export and import of symbols.
#define OTC_SDK_API
Only needed when working with Windows DLLs.
Definition Api.h:65
Contains an enum representing the different temperature precisions and constants denoting invalid tem...
bool isValueValid(unsigned short value) noexcept
Checks if an internal value is valid.
Definition TemperatureConverter.h:152
OTC_SDK_API TemperatureConverter() noexcept
Constructor.
TemperaturePrecision getPrecision() const noexcept
Returns the temperature precision.
Definition TemperatureConverter.h:124
unsigned short toValue(float temperature) const noexcept
Converts a temperature in °C to an internal value.
Definition TemperatureConverter.h:142
OTC_SDK_API void setPrecision(TemperaturePrecision precision) noexcept
Set the temperature precision.
unsigned short getInvalidValue() const noexcept
Returns the value signifying an invalid internal value.
Definition TemperatureConverter.h:162
float getInvalidTemperature() const noexcept
Returns the value signifying an invalid temperature.
Definition TemperatureConverter.h:157
bool isTemperatureValid(float temperature) noexcept
Checks if the given temperature in °C is valid.
Definition TemperatureConverter.h:147
float toTemperature(unsigned short value) const noexcept
Converts an internal value to a temperature in °C.
Definition TemperatureConverter.h:129
Main SDK namespace.
Definition AlarmChannel.h:21
static constexpr float INVALID_TEMPERATURE
All temperatures in °C equal or lower are invalid.
Definition TemperaturePrecision.h:24
TemperaturePrecision
Represents the available temperature precisions.
Definition TemperaturePrecision.h:32