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
vtkMRMLSegmentationStorageNode.h
Go to the documentation of this file.
1/*==============================================================================
2
3 Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
4 Queen's University, Kingston, ON, Canada. All Rights Reserved.
5
6 See COPYRIGHT.txt
7 or http://www.slicer.org/copyright/copyright.txt for details.
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14
15 This file was originally developed by Adam Rankin and Csaba Pinter, PerkLab, Queen's
16 University and was supported through the Applied Cancer Research Unit program of Cancer
17 Care Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
18
19==============================================================================*/
20
21#ifndef __vtkMRMLSegmentationStorageNode_h
22#define __vtkMRMLSegmentationStorageNode_h
23
24// Temporarily keep support for reading nrrd files that are saved as 4D spatial image.
25// The current way of writing volume is 3 spatial dimension and a list.
26#define SUPPORT_4D_SPATIAL_NRRD
27
28// MRML includes
29#include "vtkMRMLStorageNode.h"
30
31#ifdef SUPPORT_4D_SPATIAL_NRRD
32 // ITK includes
33 #include <itkImageRegionIteratorWithIndex.h>
34#endif
35
37class vtkMatrix4x4;
38class vtkPolyData;
40class vtkSegmentation;
42class vtkSegment;
43class vtkInformationStringKey;
44class vtkInformationIntegerVectorKey;
45
62
64{
65#ifdef SUPPORT_4D_SPATIAL_NRRD
66 // Although internally binary labelmap representations can be of unsigned char, unsigned short
67 // or short types, the output file is always unsigned char
68 //TODO: This is a limitation for now
69 typedef itk::Image<unsigned char, 4> BinaryLabelmap4DImageType;
70 typedef itk::ImageRegionIteratorWithIndex<BinaryLabelmap4DImageType> BinaryLabelmap4DIteratorType;
71#endif
72
73public:
76 void PrintSelf(ostream& os, vtkIndent indent) override;
77
79
81 void ReadXMLAttributes( const char** atts) override;
82
84 void WriteXML(ostream& of, int indent) override;
85
87 void Copy(vtkMRMLNode *node) override;
88
90 const char* GetNodeTagName() override {return "SegmentationStorage";}
91
95 const char* GetDefaultWriteFileExtension() override;
96
98 bool CanReadInReferenceNode(vtkMRMLNode *refNode) override;
99
102
110 vtkSetMacro(CropToMinimumExtent, bool);
111 vtkGetMacro(CropToMinimumExtent, bool);
112 vtkBooleanMacro(CropToMinimumExtent, bool);
113
114protected:
117
120
123
125 int WriteDataInternal(vtkMRMLNode *refNode) override;
126
128 virtual int WriteBinaryLabelmapRepresentation(vtkMRMLSegmentationNode* segmentationNode, std::string path);
129
131 virtual int WritePolyDataRepresentation(vtkMRMLSegmentationNode* segmentationNode, std::string path);
132
134 int ReadDataInternal(vtkMRMLNode *refNode) override;
135
137 virtual int ReadBinaryLabelmapRepresentation(vtkMRMLSegmentationNode* segmentationNode, std::string path);
138
139#ifdef SUPPORT_4D_SPATIAL_NRRD
141 virtual int ReadBinaryLabelmapRepresentation4DSpatial(vtkMRMLSegmentationNode* segmentationNode, std::string path);
142#endif
143
145 virtual int ReadPolyDataRepresentation(vtkMRMLSegmentationNode* segmentationNode, std::string path);
146
149 void AddPolyDataFileNames(std::string path, vtkSegmentation* segmentation);
150
153
155 void CreateRepresentationsBySerializedNames(vtkSegmentation* segmentation, std::string representationNames);
156
158 static bool GetSegmentMetaDataFromDicitionary(std::string& headerValue, itk::MetaDataDictionary dictionary, int segmentIndex, std::string keyName);
159
161 static bool GetSegmentationMetaDataFromDicitionary(std::string& headerValue, itk::MetaDataDictionary dictionary, std::string keyName);
162
163 static std::string GetSegmentMetaDataKey(int segmentIndex, const std::string& keyName);
164
165 static std::string GetSegmentationMetaDataKey(const std::string& keyName);
166
167 static std::string GetSegmentTagsAsString(vtkSegment* segment);
168 static void SetSegmentTagsFromString(vtkSegment* segment, std::string tagsValue);
169
171 static std::string GetImageExtentAsString(int extent[6]);
172 static void GetImageExtentFromString(int extent[6], std::string extentValue);
173
174 static std::string GetSegmentColorAsString(vtkMRMLSegmentationNode* segmentationNode, const std::string& segmentId);
175 static void GetSegmentColorFromString(double color[3], std::string colorString);
176
177 static void AddToExtent(int extent[6], int extentToAdd[6]);
178
179protected:
181
182protected:
185
186private:
188 void operator=(const vtkMRMLSegmentationStorageNode&) = delete;
189};
190
191#endif
MRML node containing segmentations.
void PrintSelf(ostream &os, vtkIndent indent) override
void WriteXML(ostream &of, int indent) override
Write this node's information to a MRML file in XML format.
void CreateRepresentationsBySerializedNames(vtkSegmentation *segmentation, std::string representationNames)
Create representations based on serialized representation names string.
std::string SerializeContainedRepresentationNames(vtkSegmentation *segmentation)
Serialize contained representation names in a string.
const char * GetNodeTagName() override
Get node XML tag name (like Storage, Model)
virtual int ReadPolyDataRepresentation(vtkMRMLSegmentationNode *segmentationNode, std::string path)
Read a poly data representation to file.
int WriteDataInternal(vtkMRMLNode *refNode) override
Write data from a referenced node.
void AddPolyDataFileNames(std::string path, vtkSegmentation *segmentation)
~vtkMRMLSegmentationStorageNode() override
const char * GetDefaultWriteFileExtension() override
virtual int ReadBinaryLabelmapRepresentation(vtkMRMLSegmentationNode *segmentationNode, std::string path)
Read binary labelmap representation from nrrd file (3D spatial + list)
virtual int WriteBinaryLabelmapRepresentation(vtkMRMLSegmentationNode *segmentationNode, std::string path)
Write binary labelmap representation to file.
static bool GetSegmentMetaDataFromDicitionary(std::string &headerValue, itk::MetaDataDictionary dictionary, int segmentIndex, std::string keyName)
Get the metadata string for the segment and key from the dictionary.
void ReadXMLAttributes(const char **atts) override
Read node attributes from XML file.
void InitializeSupportedWriteFileTypes() override
Initialize all the supported write file types.
static std::string GetImageExtentAsString(int extent[6])
virtual int ReadBinaryLabelmapRepresentation4DSpatial(vtkMRMLSegmentationNode *segmentationNode, std::string path)
Read binary labelmap representation from 4D spatial nrrd file - obsolete.
void ResetSupportedWriteFileTypes()
Reset supported write file types. Called when source representation is changed.
void Copy(vtkMRMLNode *node) override
Copy the node's attributes to this object.
static void GetSegmentColorFromString(double color[3], std::string colorString)
virtual int WritePolyDataRepresentation(vtkMRMLSegmentationNode *segmentationNode, std::string path)
Write a poly data representation to file.
static std::string GetImageExtentAsString(vtkOrientedImageData *image)
vtkMRMLNode * CreateNodeInstance() override
Create instance of the default node. Like New only virtual.
static void GetImageExtentFromString(int extent[6], std::string extentValue)
static void SetSegmentTagsFromString(vtkSegment *segment, std::string tagsValue)
static void AddToExtent(int extent[6], int extentToAdd[6])
void InitializeSupportedReadFileTypes() override
Initialize all the supported read file types.
static std::string GetSegmentationMetaDataKey(const std::string &keyName)
vtkMRMLSegmentationNode * GetAssociatedDataNode()
Get data node that is associated with this storage node.
static std::string GetSegmentTagsAsString(vtkSegment *segment)
static std::string GetSegmentMetaDataKey(int segmentIndex, const std::string &keyName)
bool CanReadInReferenceNode(vtkMRMLNode *refNode) override
Return true if the reference node can be read in.
static bool GetSegmentationMetaDataFromDicitionary(std::string &headerValue, itk::MetaDataDictionary dictionary, std::string keyName)
Get the metadata string for the segmentation key from the dictionary.
static vtkMRMLSegmentationStorageNode * New()
int ReadDataInternal(vtkMRMLNode *refNode) override
Read data and set it in the referenced node.
static std::string GetSegmentColorAsString(vtkMRMLSegmentationNode *segmentationNode, const std::string &segmentId)
void operator=(const vtkMRMLStorageNode &)
Image data containing orientation information.
This class encapsulates a segment that is part of a segmentation.
Definition vtkSegment.h:45
This class encapsulates a segmentation that can contain multiple segments and multiple representation...