Developer documentation
Version 3.0.3-105-gd3941f44
lut.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __connectome_lut_h__
18#define __connectome_lut_h__
19
20#include <map>
21#include <string>
22
23#include "app.h"
24#include "types.h"
25
26#include "connectome/connectome.h"
27
28
29
30namespace MR {
31namespace Connectome {
32
33
34
35
36// Class for storing any useful information regarding a parcellation node that
37// may be imported from a lookup table
40
41 public:
42
43 using RGB = Eigen::Array<uint8_t, 3, 1>;
44
45 LUT_node (const std::string& n) :
46 name (n),
47 colour (0, 0, 0),
48 alpha (255) { }
49
50 LUT_node (const std::string& n, const std::string& sn) :
51 name (n),
52 short_name (sn),
53 colour (0, 0, 0),
54 alpha (255) { }
55
56 LUT_node (const std::string& n, const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a = 255) :
57 name (n),
58 colour (r, g, b),
59 alpha (a) { }
60
61 LUT_node (const std::string& n, const std::string& sn, const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a = 255) :
62 name (n),
63 short_name (sn),
64 colour (r, g, b),
65 alpha (a) { }
66
67 LUT_node (const std::string& n, const RGB& rgb, const uint8_t a = 255) :
68 name (n),
69 colour (rgb),
70 alpha (a) { }
71
72
73 void set_colour (const uint8_t r, const uint8_t g, const uint8_t b) { colour = RGB {r,g,b}; }
74 void set_colour (const RGB& rgb) { colour = rgb; }
75 void set_alpha (const uint8_t a) { alpha = a; }
76
77
78 const std::string& get_name() const { return name; }
79 const std::string& get_short_name() const { return short_name.size() ? short_name : name; }
80 const RGB& get_colour() const { return colour; }
81 uint8_t get_alpha() const { return alpha; }
82
83
84 private:
85 std::string name, short_name;
86 RGB colour;
87 uint8_t alpha;
88
89};
90
91
92
93
94class LUT : public std::multimap<node_t, LUT_node>
95{ MEMALIGN(LUT)
96 enum file_format { LUT_NONE, LUT_BASIC, LUT_FREESURFER, LUT_AAL, LUT_ITKSNAP, LUT_MRTRIX };
97 public:
98 using map_type = std::multimap<node_t, LUT_node>;
99 LUT () : exclusive (true) { }
100 LUT (const std::string&);
101 void load (const std::string&);
102 bool is_exclusive() const { return exclusive; }
103 private:
104 bool exclusive;
105
106 file_format guess_file_format (const std::string&);
107
108 void parse_line_basic (const std::string&);
109 void parse_line_freesurfer (const std::string&);
110 void parse_line_aal (const std::string&);
111 void parse_line_itksnap (const std::string&);
112 void parse_line_mrtrix (const std::string&);
113
114 void check_and_insert (const node_t, const LUT_node&);
115
116};
117
118
119
120
121// Convenience function for constructing a mapping from one lookup table to another
122// NOTE: If the TARGET LUT contains multiple entries for a particular index, and a
123// mapping TO that index is required, the conversion is ill-formed.
125
126
127
128
129}
130}
131
132
133#endif
134
void load(const std::string &)
std::multimap< node_t, LUT_node > map_type
Definition: lut.h:98
LUT(const std::string &)
bool is_exclusive() const
Definition: lut.h:102
uint32_t node_t
Definition: connectome.h:34
vector< node_t > get_lut_mapping(const LUT &, const LUT &)
Definition: base.h:24
#define MEMALIGN(...)
Definition: types.h:185