Slicer  5.1
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
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 
37 class vtkMatrix4x4;
38 class vtkPolyData;
40 class vtkSegmentation;
42 class vtkSegment;
43 class vtkInformationStringKey;
44 class vtkInformationIntegerVectorKey;
45 
62 
63 class VTK_MRML_EXPORT vtkMRMLSegmentationStorageNode : public vtkMRMLStorageNode
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 
73 public:
74  static vtkMRMLSegmentationStorageNode *New();
76  void PrintSelf(ostream& os, vtkIndent indent) override;
77 
78  vtkMRMLNode* CreateNodeInstance() override;
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 
101  void ResetSupportedWriteFileTypes();
102 
110  vtkSetMacro(CropToMinimumExtent, bool);
111  vtkGetMacro(CropToMinimumExtent, bool);
112  vtkBooleanMacro(CropToMinimumExtent, bool);
113 
114 protected:
116  void InitializeSupportedReadFileTypes() override;
117 
119  void InitializeSupportedWriteFileTypes() override;
120 
122  vtkMRMLSegmentationNode* GetAssociatedDataNode();
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
140  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 
152  std::string SerializeContainedRepresentationNames(vtkSegmentation* segmentation);
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 
170  static std::string GetImageExtentAsString(vtkOrientedImageData* image);
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 protected:
178  bool CropToMinimumExtent{false};
179 
180 protected:
182  ~vtkMRMLSegmentationStorageNode() override;
183 
184 private:
186  void operator=(const vtkMRMLSegmentationStorageNode&) = delete;
187 };
188 
189 #endif
vtkMRMLNode * CreateNodeInstance() override=0
Create instance of the default node. Like New only virtual.
This class encapsulates a segment that is part of a segmentation.
Definition: vtkSegment.h:45
virtual int ReadDataInternal(vtkMRMLNode *refNode)
virtual void InitializeSupportedReadFileTypes()
MRML node for segmentation storage on disk.
virtual const char * GetDefaultWriteFileExtension()
Return default file extension for writing.
void operator=(const vtkMRMLStorageNode &)
Image data containing orientation information.
void ReadXMLAttributes(const char **atts) override
Read node attributes from XML file
void Copy(vtkMRMLNode *node) override
Copy the node&#39;s attributes to this object
void PrintSelf(ostream &os, vtkIndent indent) override
const char * GetNodeTagName() override
Get node XML tag name (like Storage, Model)
This class encapsulates a segmentation that can contain multiple segments and multiple representation...
void WriteXML(ostream &of, int indent) override
Write this node&#39;s information to a MRML file in XML format.
A superclass for other storage nodes.
virtual void InitializeSupportedWriteFileTypes()
virtual int WriteDataInternal(vtkMRMLNode *refNode)
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167
virtual bool CanReadInReferenceNode(vtkMRMLNode *refNode)=0
MRML node containing segmentationsSegmentation node stores a set of segments (also known as contours ...