CortidQCT  1.2.2.52
LabelToColorMap.h
Go to the documentation of this file.
1 
13 #pragma once
14 
15 #include <functional>
16 
17 namespace CortidQCT {
18 
29 template <class Scalar, class Label>
30 using LabelToColorMap = std::function<std::array<Scalar, 3>(Label)>;
31 
33 namespace LabelToColorMaps {
34 
46 template <class Scalar, class Label>
47 inline std::array<Scalar, 3> defaultMap(Label label) {
48  auto const convertedLabel = static_cast<std::uint64_t>(label);
49 
50  // Ensure the upper 5 bytes are all zero
51  if ((convertedLabel & 0xffffffffff000000) != 0) {
52  throw std::invalid_argument("Given label cannot losslessly be converted to "
53  "24-bit unsigned integer");
54  }
55 
56  auto const redScaled = convertedLabel & 0xff;
57  auto const greenScaled = (convertedLabel & 0xff00) >> 8;
58  auto const blueScaled = (convertedLabel & 0xff0000) >> 16;
59 
60  auto const red = static_cast<Scalar>(redScaled) / Scalar{255};
61  auto const green = static_cast<Scalar>(greenScaled) / Scalar{255};
62  auto const blue = static_cast<Scalar>(blueScaled) / Scalar{255};
63 
64  return std::array<Scalar, 3>{{red, green, blue}};
65 }
66 
67 } // namespace LabelToColorMaps
68 
69 } // namespace CortidQCT
Name namespace for CortidQCT library.
Definition: CortidQCT.h:23
std::function< std::array< Scalar, 3 >(Label)> LabelToColorMap
Label to color map.
Definition: LabelToColorMap.h:30
std::array< Scalar, 3 > defaultMap(Label label)
Default label to color map.
Definition: LabelToColorMap.h:47