CiftiLib
A C++ library for CIFTI-2 and CIFTI-1 files
LabelTable.h
1#ifndef __LABELTABLE_H__
2#define __LABELTABLE_H__
3
4/*LICENSE_START*/
5/*
6 * Copyright (c) 2014, Washington University School of Medicine
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "Common/AString.h"
32
33#include <map>
34#include <set>
35#include <vector>
36#include <stdint.h>
37
38#include "Common/XmlAdapter.h"
39
40namespace cifti {
41
42class Label;
43
45
46public:
47 LabelTable();
48
49 LabelTable(const LabelTable& glt);
50
51 LabelTable& operator=(const LabelTable& glt);
52
53 bool matches(const LabelTable& rhs, const bool checkColors = false) const;
54
55 bool operator==(const LabelTable& rhs) const { return matches(rhs, true); }
56
57 bool operator!=(const LabelTable& rhs) const { return !((*this) == rhs); }
58
59 virtual ~LabelTable();
60
61private:
62 void copyHelper(const LabelTable& glt);
63
64public:
65 void clear();
66
67 std::map<int32_t,int32_t> append(const LabelTable& glt);
68
69 int32_t addLabel(
70 const AString& labelName,
71 const float red,
72 const float green,
73 const float blue,
74 const float alpha);
75
76 int32_t addLabel(
77 const AString& labelName,
78 const float red,
79 const float green,
80 const float blue);
81
82 int32_t addLabel(
83 const AString& labelName,
84 const int32_t red,
85 const int32_t green,
86 const int32_t blue,
87 const int32_t alpha);
88
89 int32_t addLabel(
90 const AString& labelName,
91 const int32_t red,
92 const int32_t green,
93 const int32_t blue);
94
95 int32_t addLabel(const Label* glt);
96
97 void deleteLabel(const int32_t key);
98
99 void deleteLabel(const Label* label);
100
101 void deleteUnusedLabels(const std::set<int32_t>& usedLabelKeys);
102
103 void insertLabel(const Label* label);
104
105 int32_t getLabelKeyFromName(const AString& name) const;
106
107 const Label* getLabel(const AString& labelName) const;
108
109 Label* getLabel(const AString& labelName);
110
111 const Label* getLabel(const int32_t key) const;
112
113 Label* getLabel(const int32_t key);
114
115 int32_t getUnassignedLabelKey() const;
116
117 int32_t getNumberOfLabels() const;
118
119 AString getLabelName(const int32_t key) const;
120
121 void setLabelName(
122 const int32_t key,
123 const AString& name);
124
125 void setLabel(const int32_t key,
126 const AString& name,
127 const float red,
128 const float green,
129 const float blue,
130 const float alpha);
131
132 bool isLabelSelected(const int32_t key) const;
133
134 void setLabelSelected(
135 const int32_t key,
136 const bool sel);
137
138 void setSelectionStatusForAllLabels(const bool newStatus);
139
140 float getLabelAlpha(const int32_t key) const;
141
142 void getLabelColor(const int32_t key, float rgbaOut[4]) const;
143
144 void setLabelColor(
145 const int32_t key,
146 const float color[4]);
147
148 void createLabelsForKeys(const std::set<int32_t>& newKeys);
149
150 void writeXML(XmlWriter& xmlWriter) const;
151
152 void readXml(XmlReader& xml);
153
154 std::set<int32_t> getKeys() const;
155
156 void getKeys(std::vector<int32_t>& keysOut) const;
157
158 void getKeysAndNames(std::map<int32_t, AString>& keysAndNamesOut) const;
159
160 int32_t generateUnusedKey() const;
161
162private:
163 typedef std::map<int32_t, Label*> LABELS_MAP;
164 typedef std::map<int32_t, Label*>::iterator LABELS_MAP_ITERATOR;
165 typedef std::map<int32_t, Label*>::const_iterator LABELS_MAP_CONST_ITERATOR;
166
167 LABELS_MAP labelsMap;
168
169};
170
171} // namespace
172
173#endif // __LABELTABLE_H__
Definition: LabelTable.h:44
void insertLabel(const Label *label)
Definition: LabelTable.cxx:408
std::set< int32_t > getKeys() const
Definition: LabelTable.cxx:877
float getLabelAlpha(const int32_t key) const
Definition: LabelTable.cxx:692
void getKeysAndNames(std::map< int32_t, AString > &keysAndNamesOut) const
Definition: LabelTable.cxx:905
void setSelectionStatusForAllLabels(const bool newStatus)
Definition: LabelTable.cxx:674
const Label * getLabel(const AString &labelName) const
Definition: LabelTable.cxx:459
bool isLabelSelected(const int32_t key) const
Definition: LabelTable.cxx:642
std::map< int32_t, int32_t > append(const LabelTable &glt)
Definition: LabelTable.cxx:120
void clear()
Definition: LabelTable.cxx:94
void setLabelName(const int32_t key, const AString &name)
Definition: LabelTable.cxx:590
int32_t generateUnusedKey() const
Definition: LabelTable.cxx:294
AString getLabelName(const int32_t key) const
Definition: LabelTable.cxx:573
int32_t getUnassignedLabelKey() const
Definition: LabelTable.cxx:536
void getLabelColor(const int32_t key, float rgbaOut[4]) const
Definition: LabelTable.cxx:708
void setLabel(const int32_t key, const AString &name, const float red, const float green, const float blue, const float alpha)
Definition: LabelTable.cxx:613
int32_t addLabel(const AString &labelName, const float red, const float green, const float blue, const float alpha)
Definition: LabelTable.cxx:148
void setLabelSelected(const int32_t key, const bool sel)
Definition: LabelTable.cxx:658
void deleteUnusedLabels(const std::set< int32_t > &usedLabelKeys)
Definition: LabelTable.cxx:381
void setLabelColor(const int32_t key, const float color[4])
Definition: LabelTable.cxx:723
int32_t getLabelKeyFromName(const AString &name) const
Definition: LabelTable.cxx:437
int32_t getNumberOfLabels() const
Definition: LabelTable.cxx:560
void deleteLabel(const int32_t key)
Definition: LabelTable.cxx:334
Definition: Label.h:39
namespace for all CiftiLib functionality
Definition: CiftiBrainModelsMap.h:42