Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
109 const char* GetColorName(int ind);
110
114 int GetColorIndexByName(const char* name);
115
125 std::string GetColorNameAsFileName(int colorIndex, const char *subst = "_");
126
132 std::string GetColorNameWithoutSpaces(int ind, const char *subst);
133
137 int SetColorName(int ind, const char* name);
138
143 int SetColorNameWithSpaces(int ind, const char *name, const char *subst);
144
145 // @{
152 std::string GetTerminologyAsString(int ind);
153 // @}
154
157 bool SetTerminologyFromString(int ind, std::string terminologyString);
158
161 bool SetTerminology(int ind,
162 std::string categoryCodingScheme, std::string categoryCodeValue, std::string categoryCodeMeaning,
163 std::string typeCodingScheme, std::string typeCodeValue, std::string typeCodeMeaning,
164 std::string typeModifierCodingScheme="", std::string typeModifierCodeValue="", std::string typeModifierCodeMeaning="",
165 std::string regionCodingScheme="", std::string regionCodeValue="", std::string regionCodeMeaning="",
166 std::string regionModifierCodingScheme="", std::string regionModifierCodeValue="", std::string regionModifierCodeMeaning="");
167
169 static std::string GetTerminologyAsString(std::string terminologyContextName,
170 vtkCodedEntry* category, vtkCodedEntry* type, vtkCodedEntry* typeModifier,
171 std::string regionContextName="", vtkCodedEntry* region=nullptr, vtkCodedEntry* regionModifier=nullptr);
172
174 const char* GetContainsTerminologyAttributeName() { return "ContainsTerminology"; };
177
179 virtual int GetNumberOfColors() = 0;
180
183 virtual bool GetColor(int ind, double color[4]) = 0;
184
186 virtual vtkLookupTable* GetLookupTable();
187
192 virtual vtkScalarsToColors* GetScalarsToColors();
193
198 const char* GetNoName()
199 {
200 vtkWarningMacro("GetNoName() method is deprecated use GetColorDefined() and SetColorDefined() methods instead");
201 return "(none)";
202 }
203
206 void SetNoName(const char*)
207 {
208 vtkErrorMacro("SetNoName() method is deprecated use GetColorDefined() and SetColorDefined() methods instead");
209 }
210
211 // @{
218 {
219 vtkErrorMacro("NamesInitialisedOn() method is deprecated and has no effect and no longer necessary.");
220 }
222 {
223 vtkErrorMacro("NamesInitialisedOff() method is deprecated and has no effect and no longer necessary.");
224 }
226 {
227 vtkErrorMacro("SetNamesInitialised() method is deprecated and has no effect. Use SetColorName() and SetColorDefined() methods instead.");
228 }
230 {
231 vtkErrorMacro("GetNamesInitialised() method is deprecated. Use SetColorName() and SetColorDefined() methods to set and unset color names.");
232 return 1;
233 }
234 // @}
235
242
244 bool GetModifiedSinceRead() override;
245
252 enum
253 {
254 User = 13,
255 File = 14,
256 };
257
261 virtual vtkLookupTable* CreateLookupTableCopy();
262
263protected:
268
270 void SetContainsTerminology(bool containsTerminology);
271
273 {
274 // The label value and corresponding color has been explicitly set.
275 // If the label value is not included in the color table file then "Defined" will set to false.
276 bool Defined{ false };
277 std::string Name;
278 vtkSmartPointer<vtkCodedEntry> Category;
279 vtkSmartPointer<vtkCodedEntry> Type;
280 vtkSmartPointer<vtkCodedEntry> TypeModifier;
281 vtkSmartPointer<vtkCodedEntry> Region;
282 vtkSmartPointer<vtkCodedEntry> RegionModifier;
283 void DeepCopy(PropertyType& source)
284 {
285 this->Defined = source.Defined;
286 this->Name = source.Name;
287 this->Category = source.Category;
288 this->Type = source.Type;
289 this->TypeModifier = source.TypeModifier;
290 this->Region = source.Region;
291 this->RegionModifier = source.RegionModifier;
292 }
293 void Clear()
294 {
295 this->Defined = false;
296 this->Name.clear();
297 this->Category = nullptr;
298 this->Type = nullptr;
299 this->TypeModifier = nullptr;
300 this->Region = nullptr;
301 this->RegionModifier = nullptr;
302 }
303 bool operator==(const PropertyType& other) const
304 {
305 return this->Defined == other.Defined &&
306 this->Name == other.Name &&
307 vtkCodedEntry::AreEqual(this->Category, other.Category) &&
308 vtkCodedEntry::AreEqual(this->Type, other.Type) &&
309 vtkCodedEntry::AreEqual(this->TypeModifier, other.TypeModifier) &&
310 vtkCodedEntry::AreEqual(this->Region, other.Region) &&
311 vtkCodedEntry::AreEqual(this->RegionModifier, other.RegionModifier);
312 }
313 bool operator!=(const PropertyType& other) const
314 {
315 return !(*this == other);
316 }
317 };
318
319 bool GetProperty(int ind, PropertyType& prop);
320
322 virtual bool SetNameFromColor(int index);
323
326 int Type;
327
329 std::vector<PropertyType> Properties;
330};
331
332#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()
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