Carna Version 3.3.3
Loading...
Searching...
No Matches
HUV.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Leonid Kostrykin
3 *
4 */
5
6#ifndef HUV_H_6014714286
7#define HUV_H_6014714286
8
9#include <Carna/Carna.h>
11
16namespace Carna
17{
18
19namespace base
20{
21
22
23
24// ----------------------------------------------------------------------------------
25// HUV
26// ----------------------------------------------------------------------------------
27
34struct HUV
35{
36
40 signed short value;
41
45 operator signed short() const;
46
50 HUV() = default;
51
56 explicit HUV( signed int value, bool absolute=false );
57
62 explicit HUV( float intensity, bool absolute=false );
63
67 template< typename T >
68 static HUV abs( T value );
69
73 template< typename T >
74 static HUV rel( T value );
75
79 float absIntensity() const;
80
84 float relIntensity() const;
85
86}; // HUV
87
88
89inline HUV::operator signed short() const
90{
91 return value;
92}
93
94
95inline HUV::HUV( signed int value, bool absolute )
96 : value( value )
97{
98 if( absolute )
99 {
100 if( this->value < -1024 ) this->value = -1024;
101 if( this->value > 3071 ) this->value = 3071;
102 }
103}
104
105
106inline HUV::HUV( float intensity, bool absolute )
107{
108 const static float huvMax = 3071;
109 if( absolute )
110 {
111 if( intensity < 0 ) intensity = 0;
112 if( intensity > 1 ) intensity = 1;
113 }
114 float huvFloat = intensity * 4095.f + 0.5;
115 if( absolute ) huvFloat -= 1024;
116 if( huvFloat > huvMax ) huvFloat = huvMax;
117 value = static_cast< signed short >( huvFloat );
118}
119
120
121inline float HUV::absIntensity() const
122{
123 return ( value + 1024 ) / 4095.f;
124}
125
126
127inline float HUV::relIntensity() const
128{
129 return value / 4095.f;
130}
131
132
133template< typename T >
134HUV HUV::abs( T value )
135{
136 return HUV( value, true );
137}
138
139
140template< typename T >
141HUV HUV::rel( T value )
142{
143 return HUV( value, false );
144}
145
146
147
148} // namespace Carna :: base
149
150} // namespace Carna
151
152#endif // HUV_H_6014714286
Defines Carna::base::CarnaException, Carna::base::AssertionFailure.
Represents an association.
Definition Association.h:45
Represents values in .
Definition HUV.h:35
signed short value
Holds the HU value.
Definition HUV.h:40
float relIntensity() const
Returns the corresponding relative intensity.
Definition HUV.h:127
static HUV rel(T value)
Wraps a relative HU value.
Definition HUV.h:141
HUV()=default
Constructor.
float absIntensity() const
Returns the corresponding absolute intensity.
Definition HUV.h:121
static HUV abs(T value)
Wraps an absolute HU value.
Definition HUV.h:134