LibCarna Version 3.4.0
Loading...
Searching...
No Matches
HUV.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 - 2016 Leonid Kostrykin
3 *
4 * Chair of Medical Engineering (mediTEC)
5 * RWTH Aachen University
6 * Pauwelsstr. 20
7 * 52074 Aachen
8 * Germany
9 *
10 *
11 * Copyright (C) 2021 - 2025 Leonid Kostrykin
12 *
13 */
14
15#ifndef HUV_H_6014714286
16#define HUV_H_6014714286
17
18#include <cmath>
19#include <LibCarna/LibCarna.hpp>
21
27namespace LibCarna
28{
29
30namespace base
31{
32
33
34
35// ----------------------------------------------------------------------------------
36// HUV
37// ----------------------------------------------------------------------------------
38
44struct HUV
45{
46
50 signed short value;
51
55 operator signed short() const;
56
60 HUV() = default;
61
65 explicit HUV( signed int value );
66
70 explicit HUV( float intensity );
71
75 float intensity() const;
76
77}; // HUV
78
79
80inline HUV::operator signed short() const
81{
82 return value;
83}
84
85
86inline HUV::HUV( signed int value )
87 : value( value )
88{
89 if( this->value < -1024 ) this->value = -1024;
90 if( this->value > 3071 ) this->value = 3071;
91}
92
93
94inline HUV::HUV( float intensity )
95{
96 const static float huvMax = 3071;
97 if( intensity < 0 ) intensity = 0;
98 if( intensity > 1 ) intensity = 1;
99 const float huvFloat = intensity * 4095.f - 1024;
100 value = static_cast< signed short >( std::lround( huvFloat ) );
101}
102
103
104inline float HUV::intensity() const
105{
106 return ( value + 1024 ) / 4095.f;
107}
108
109
110
111// ----------------------------------------------------------------------------------
112// HUVOffset
113// ----------------------------------------------------------------------------------
114
121{
122
126 signed short value;
127
131 operator signed short() const;
132
136 HUVOffset() = default;
137
141 explicit HUVOffset( signed int value );
142
146 explicit HUVOffset( float intensity );
147
151 float intensity() const;
152
153}; // HUVOffset
154
155
156inline float HUVOffset::intensity() const
157{
158 return value / 4095.f;
159}
160
161
162inline HUVOffset::HUVOffset( signed int value )
163 : value( value )
164{
165 if( this->value < -4095 ) this->value = -4095;
166 if( this->value > +4095 ) this->value = +4095;
167}
168
169
170inline HUVOffset::HUVOffset( float intensity )
171{
172 if( intensity < -1 ) intensity = -1;
173 if( intensity > +1 ) intensity = +1;
174 const float huvFloat = intensity * 4095.f;
175 value = static_cast< signed short >( std::lround( huvFloat ) );
176}
177
178
179
180} // namespace LibCarna :: base
181
182} // namespace LibCarna
183
184#endif // HUV_H_6014714286
Defines LibCarna::base::LibCarnaException and LibCarna::base::AssertionFailure.
Contains forward-declarations.
Represents an association.
Represents offsets to Hounsfield Units Values.
Definition HUV.hpp:121
float intensity() const
Returns the corresponding intensity offset.
Definition HUV.hpp:156
HUVOffset()=default
Constructor.
signed short value
Holds the HU value.
Definition HUV.hpp:126
Represents Hounsfield Units Values in , usually used in CT imaging.
Definition HUV.hpp:45
HUV()=default
Constructor.
float intensity() const
Returns the corresponding intensity.
Definition HUV.hpp:104
signed short value
Holds the HU value.
Definition HUV.hpp:50