Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkMRMLColorNode.h
Go to the documentation of this file.
1/*=auto=========================================================================
2
3 Portions (c) Copyright 2006 Brigham and Women's Hospital (BWH) All Rights Reserved.
4
5 See COPYRIGHT.txt
6 or http://www.slicer.org/copyright/copyright.txt for details.
7
8 Program: 3D Slicer
9 Module: $RCSfile: vtkMRMLColorNode.h,v $
10 Date: $Date: 2006/03/19 17:12:28 $
11 Version: $Revision: 1.0 $
12
13=========================================================================auto=*/
14
15#ifndef __vtkMRMLColorNode_h
16#define __vtkMRMLColorNode_h
17
18// MRML includes
19#include "vtkMRMLStorableNode.h"
20#include "vtkCodedEntry.h"
21
22// VTK includes
23class vtkCodedEntry;
24class vtkLookupTable;
25class vtkScalarsToColors;
26
27// Std includes
28#include <string>
29#include <vector>
30
42class VTK_MRML_EXPORT vtkMRMLColorNode : public vtkMRMLStorableNode
43{
44public:
46 void PrintSelf(ostream& os, vtkIndent indent) override;
47
49
50 //--------------------------------------------------------------------------
52 //--------------------------------------------------------------------------
53
55 void ReadXMLAttributes(const char** atts) override;
56
58 void WriteXML(ostream& of, int indent) override;
59
63
65 const char* GetNodeTagName() override { return "Color"; };
66
69 void Reset(vtkMRMLNode* defaultNode) override;
70
72 void UpdateScene(vtkMRMLScene* scene) override;
73
75 virtual void SetType(int type);
77 vtkGetMacro(Type, int);
78
83
84 void ProcessMRMLEvents(vtkObject* caller, unsigned long event, void* callData) override;
85
88 virtual int GetFirstType() { return this->User; }
89 virtual int GetLastType() { return this->File; }
90
92 virtual const char* GetTypeAsString();
93
95 enum
96 {
98 };
99
101 bool GetColorDefined(int ind);
102
104 void SetColorDefined(int ind, bool defined);
105
108
112 const char* GetColorName(int ind);
113
117 int GetColorIndexByName(const char* name);
118
128 std::string GetColorNameAsFileName(int colorIndex, const char* subst = "_");
129
135 std::string GetColorNameWithoutSpaces(int ind, const char* subst);
136
140 int SetColorName(int ind, const char* name);
141
146 int SetColorNameWithSpaces(int ind, const char* name, const char* subst);
147
148 // @{
155 std::string GetTerminologyAsString(int ind);
156 // @}
157
160 bool SetTerminologyFromString(int ind, std::string terminologyString);
161
164 bool SetTerminology(int ind,
165 std::string categoryCodingScheme,
166 std::string categoryCodeValue,
167 std::string categoryCodeMeaning,
168 std::string typeCodingScheme,
169 std::string typeCodeValue,
170 std::string typeCodeMeaning,
171 std::string typeModifierCodingScheme = "",
172 std::string typeModifierCodeValue = "",
173 std::string typeModifierCodeMeaning = "",
174 std::string regionCodingScheme = "",
175 std::string regionCodeValue = "",
176 std::string regionCodeMeaning = "",
177 std::string regionModifierCodingScheme = "",
178 std::string regionModifierCodeValue = "",
179 std::string regionModifierCodeMeaning = "");
180
182 static std::string GetTerminologyAsString(std::string terminologyContextName,
183 vtkCodedEntry* category,
184 vtkCodedEntry* type,
185 vtkCodedEntry* typeModifier,
186 std::string regionContextName = "",
187 vtkCodedEntry* region = nullptr,
188 vtkCodedEntry* regionModifier = nullptr);
189
191 const char* GetContainsTerminologyAttributeName() { return "ContainsTerminology"; };
194
196 virtual int GetNumberOfColors() = 0;
197
200 virtual bool GetColor(int ind, double color[4]) = 0;
201
203 virtual vtkLookupTable* GetLookupTable();
204
209 virtual vtkScalarsToColors* GetScalarsToColors();
210
215 const char* GetNoName()
216 {
217 vtkWarningMacro("GetNoName() method is deprecated use GetColorDefined() and SetColorDefined() methods instead");
218 return "(none)";
219 }
220
223 void SetNoName(const char*) { vtkErrorMacro("SetNoName() method is deprecated use GetColorDefined() and SetColorDefined() methods instead"); }
224
225 // @{
231 void NamesInitialisedOn() { vtkErrorMacro("NamesInitialisedOn() method is deprecated and has no effect and no longer necessary."); }
232 void NamesInitialisedOff() { vtkErrorMacro("NamesInitialisedOff() method is deprecated and has no effect and no longer necessary."); }
233 void SetNamesInitialised(int) { vtkErrorMacro("SetNamesInitialised() method is deprecated and has no effect. Use SetColorName() and SetColorDefined() methods instead."); }
235 {
236 vtkErrorMacro("GetNamesInitialised() method is deprecated. Use SetColorName() and SetColorDefined() methods to set and unset color names.");
237 return 1;
238 }
239 // @}
240
247
249 bool GetModifiedSinceRead() override;
250
257 enum
258 {
259 User = 13,
260 File = 14,
261 };
262
266 virtual vtkLookupTable* CreateLookupTableCopy();
267
268protected:
273
275 void SetContainsTerminology(bool containsTerminology);
276
278 {
279 // The label value and corresponding color has been explicitly set.
280 // If the label value is not included in the color table file then "Defined" will set to false.
281 bool Defined{ false };
282 std::string Name;
283 vtkSmartPointer<vtkCodedEntry> Category;
284 vtkSmartPointer<vtkCodedEntry> Type;
285 vtkSmartPointer<vtkCodedEntry> TypeModifier;
286 vtkSmartPointer<vtkCodedEntry> Region;
287 vtkSmartPointer<vtkCodedEntry> RegionModifier;
288 void DeepCopy(PropertyType& source)
289 {
290 this->Defined = source.Defined;
291 this->Name = source.Name;
292 this->Category = source.Category;
293 this->Type = source.Type;
294 this->TypeModifier = source.TypeModifier;
295 this->Region = source.Region;
296 this->RegionModifier = source.RegionModifier;
297 }
298 void Clear()
299 {
300 this->Defined = false;
301 this->Name.clear();
302 this->Category = nullptr;
303 this->Type = nullptr;
304 this->TypeModifier = nullptr;
305 this->Region = nullptr;
306 this->RegionModifier = nullptr;
307 }
308 bool operator==(const PropertyType& other) const
309 {
310 return this->Defined == other.Defined && //
311 this->Name == other.Name && //
312 vtkCodedEntry::AreEqual(this->Category, other.Category) && //
313 vtkCodedEntry::AreEqual(this->Type, other.Type) && //
314 vtkCodedEntry::AreEqual(this->TypeModifier, other.TypeModifier) && //
315 vtkCodedEntry::AreEqual(this->Region, other.Region) && //
316 vtkCodedEntry::AreEqual(this->RegionModifier, other.RegionModifier);
317 }
318 bool operator!=(const PropertyType& other) const { return !(*this == other); }
319 };
320
321 bool GetProperty(int ind, PropertyType& prop);
322
324 virtual bool SetNameFromColor(int index);
325
328 int Type;
329
331 std::vector<PropertyType> Properties;
332};
333
334#endif
Simple class for storing standard coded entries (coding scheme, value, meaning triplets)
static bool AreEqual(vtkCodedEntry *entry1, vtkCodedEntry *entry2)
Returns true if the two coded entries have the same content.
virtual vtkLookupTable * GetLookupTable()
Most color nodes will implement a look up table, so provide a top level get method.
static std::string GetTerminologyAsString(std::string terminologyContextName, vtkCodedEntry *category, vtkCodedEntry *type, vtkCodedEntry *typeModifier, std::string regionContextName="", vtkCodedEntry *region=nullptr, vtkCodedEntry *regionModifier=nullptr)
Convert coded entries to a string.
vtkCodedEntry * GetTerminologyRegion(int ind)
void ProcessMRMLEvents(vtkObject *caller, unsigned long event, void *callData) override
Propagate events generated in mrml.
void ReadXMLAttributes(const char **atts) override
MRMLNode methods.
vtkMRMLCopyContentMacro(vtkMRMLColorNode)
vtkCodedEntry * GetTerminologyRegionModifier(int ind)
virtual void SetType(int type)
Set Type to type, then build colors and set names.
void WriteXML(ostream &of, int indent) override
Write this node's information to a MRML file in XML format.
void SetContainsTerminology(bool containsTerminology)
Sets whether the color table has terminology information.
const char * GetContainsTerminologyAttributeName()
Get attribute name that indicates if the color table has terminology entries.
void SetNamesInitialised(int)
void operator=(const vtkMRMLColorNode &)
virtual vtkLookupTable * CreateLookupTableCopy()
void SetAllColorsDefined()
Convenience method to set all colors as defined.
vtkCodedEntry * GetTerminologyCategory(int ind)
Get terminology information for a color entry.
vtkMRMLColorNode(const vtkMRMLColorNode &)
bool SetTerminologyFromString(int ind, std::string terminologyString)
const char * GetColorName(int ind)
std::string GetColorNameWithoutSpaces(int ind, const char *subst)
void PrintSelf(ostream &os, vtkIndent indent) override
vtkCodedEntry * GetTerminologyTypeModifier(int ind)
void Reset(vtkMRMLNode *defaultNode) override
void SetColorDefined(int ind, bool defined)
Set the color defined flag for the given entry.
void SetNoName(const char *)
std::vector< PropertyType > Properties
Vector of names and other properties for the color table elements.
virtual const char * GetTypeAsString()
Return a text string describing the color look up table type.
int GetColorIndexByName(const char *name)
void UpdateScene(vtkMRMLScene *scene) override
int SetColorName(int ind, const char *name)
virtual int GetNumberOfColors()=0
Get the number of colors in the table.
virtual bool SetNameFromColor(int index)
Set values in the names vector from the colors in the node.
vtkCodedEntry * GetTerminologyType(int ind)
bool GetColorDefined(int ind)
Returns true if the entry is defined.
std::string GetTerminologyAsString(int ind)
std::string GetColorNameAsFileName(int colorIndex, const char *subst="_")
bool GetModifiedSinceRead() override
bool GetContainsTerminology()
Returns true if the color table has terminology information.
virtual int GetFirstType()
bool SetTerminology(int ind, std::string categoryCodingScheme, std::string categoryCodeValue, std::string categoryCodeMeaning, std::string typeCodingScheme, std::string typeCodeValue, std::string typeCodeMeaning, std::string typeModifierCodingScheme="", std::string typeModifierCodeValue="", std::string typeModifierCodeMeaning="", std::string regionCodingScheme="", std::string regionCodeValue="", std::string regionCodeMeaning="", std::string regionModifierCodingScheme="", std::string regionModifierCodeValue="", std::string regionModifierCodeMeaning="")
virtual vtkScalarsToColors * GetScalarsToColors()
~vtkMRMLColorNode() override
vtkMRMLNode * CreateNodeInstance() override=0
MRMLNode methods.
const char * GetNodeTagName() override
Get node XML tag name (like Volume, Model)
virtual bool GetColor(int ind, double color[4])=0
bool GetProperty(int ind, PropertyType &prop)
int SetColorNameWithSpaces(int ind, const char *name, const char *subst)
void SetNamesFromColors()
const char * GetNoName()
virtual int GetLastType()
friend class vtkMRMLScene
bool operator!=(const PropertyType &other) const
void DeepCopy(PropertyType &source)
vtkSmartPointer< vtkCodedEntry > Region
vtkSmartPointer< vtkCodedEntry > Category
bool operator==(const PropertyType &other) const
vtkSmartPointer< vtkCodedEntry > RegionModifier
vtkSmartPointer< vtkCodedEntry > TypeModifier
vtkSmartPointer< vtkCodedEntry > Type