Home
|
Main Page
|
Topics
|
Namespace List
|
Class Hierarchy
|
Alphabetical List
|
Data Structures
|
File List
|
Namespace Members
|
Data Fields
|
Globals
|
Related Pages
Loading...
Searching...
No Matches
Core
Main
elxPixelTypeToString.h
Go to the documentation of this file.
1
/*=========================================================================
2
*
3
* Copyright UMC Utrecht and contributors
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0.txt
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*
17
*=========================================================================*/
18
#ifndef elxPixelType_h
19
#define elxPixelType_h
20
21
#include <climits>
// For CHAR_BIT.
22
#include <cstdint>
// For int8_t, uint64_t, etc.
23
#include <string>
24
#include <type_traits>
// For is_floating_point_v and is_unsigned_v.
25
26
namespace
elastix
27
{
28
// Converts the pixel type specified by its template argument to a string, which can be used as parameter value of the
29
// elastix/transformix parameter ResultImagePixelType. Uses a "fixed width" format, returning a string of the form
30
// "intN", "uintN", or "floatN", with N being the number of bits of the specified type.
31
template
<
typename
TPixel>
32
std::string
33
PixelTypeToFixedWidthString
()
34
{
35
// Check that `TPixel` can be represented losslessly as fixed-width type:
36
static_assert
(std::get<TPixel>(std::tuple<std::int8_t,
37
std::uint8_t,
38
std::int16_t,
39
std::uint16_t,
40
std::int32_t,
41
std::uint32_t,
42
std::int64_t,
43
std::uint64_t,
44
float
,
45
double
>()) == 0);
46
47
return
(std::is_floating_point_v<TPixel> ?
"float"
48
: std::is_unsigned_v<TPixel> ?
"uint"
49
:
"int"
) +
50
std::to_string(
sizeof
(TPixel) * CHAR_BIT);
51
}
52
53
54
// Converts the pixel type specified by its template argument to a string, which can be used as parameter value of the
55
// elastix/transformix parameter ResultImagePixelType.
56
template
<
typename
TPixel>
57
std::string
58
PixelTypeToString
()
59
{
60
if
constexpr
(std::is_same_v<TPixel, char> && !std::is_same_v<char, std::int8_t> &&
61
!std::is_same_v<char, std::uint8_t>)
62
{
63
// `char` appears different from both `int8_t` and `uint8_t`, so it must have its own string representation.
64
return
"char"
;
65
}
66
else
67
{
68
return
PixelTypeToFixedWidthString<TPixel>
();
69
}
70
}
71
72
}
// namespace elastix
73
74
#endif
elastix
Definition
elxDefaultConstruct.h:25
elastix::PixelTypeToFixedWidthString
std::string PixelTypeToFixedWidthString()
Definition
elxPixelTypeToString.h:33
elastix::PixelTypeToString
std::string PixelTypeToString()
Definition
elxPixelTypeToString.h:58
Generated on 1774142652 for elastix by
1.15.0