Slicer  4.11
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 
131 
133 {
134 #ifdef SUPPORT_4D_SPATIAL_NRRD
135  // Although internally binary labelmap representations can be of unsigned char, unsigned short
136  // or short types, the output file is always unsigned char
137  //TODO: This is a limitation for now
138  typedef itk::Image<unsigned char, 4> BinaryLabelmap4DImageType;
139  typedef itk::ImageRegionIteratorWithIndex<BinaryLabelmap4DImageType> BinaryLabelmap4DIteratorType;
140 #endif
141 
142 public:
143  static vtkMRMLSegmentationStorageNode *New();
145  void PrintSelf(ostream& os, vtkIndent indent) override;
146 
147  vtkMRMLNode* CreateNodeInstance() override;
148 
150  void ReadXMLAttributes( const char** atts) override;
151 
153  void WriteXML(ostream& of, int indent) override;
154 
156  void Copy(vtkMRMLNode *node) override;
157 
159  const char* GetNodeTagName() override {return "SegmentationStorage";}
160 
164  const char* GetDefaultWriteFileExtension() override;
165 
167  bool CanReadInReferenceNode(vtkMRMLNode *refNode) override;
168 
170  void ResetSupportedWriteFileTypes();
171 
179  vtkSetMacro(CropToMinimumExtent, bool);
180  vtkGetMacro(CropToMinimumExtent, bool);
181  vtkBooleanMacro(CropToMinimumExtent, bool);
182 
183 protected:
185  void InitializeSupportedReadFileTypes() override;
186 
188  void InitializeSupportedWriteFileTypes() override;
189 
191  vtkMRMLSegmentationNode* GetAssociatedDataNode();
192 
194  int WriteDataInternal(vtkMRMLNode *refNode) override;
195 
197  virtual int WriteBinaryLabelmapRepresentation(vtkMRMLSegmentationNode* segmentationNode, std::string path);
198 
200  virtual int WritePolyDataRepresentation(vtkMRMLSegmentationNode* segmentationNode, std::string path);
201 
203  int ReadDataInternal(vtkMRMLNode *refNode) override;
204 
206  virtual int ReadBinaryLabelmapRepresentation(vtkMRMLSegmentationNode* segmentationNode, std::string path);
207 
208 #ifdef SUPPORT_4D_SPATIAL_NRRD
209  virtual int ReadBinaryLabelmapRepresentation4DSpatial(vtkMRMLSegmentationNode* segmentationNode, std::string path);
211 #endif
212 
214  virtual int ReadPolyDataRepresentation(vtkMRMLSegmentationNode* segmentationNode, std::string path);
215 
218  void AddPolyDataFileNames(std::string path, vtkSegmentation* segmentation);
219 
221  std::string SerializeContainedRepresentationNames(vtkSegmentation* segmentation);
222 
224  void CreateRepresentationsBySerializedNames(vtkSegmentation* segmentation, std::string representationNames);
225 
227  static bool GetSegmentMetaDataFromDicitionary(std::string& headerValue, itk::MetaDataDictionary dictionary, int segmentIndex, std::string keyName);
228 
230  static bool GetSegmentationMetaDataFromDicitionary(std::string& headerValue, itk::MetaDataDictionary dictionary, std::string keyName);
231 
232  static std::string GetSegmentMetaDataKey(int segmentIndex, const std::string& keyName);
233 
234  static std::string GetSegmentationMetaDataKey(const std::string& keyName);
235 
236  static std::string GetSegmentTagsAsString(vtkSegment* segment);
237  static void SetSegmentTagsFromString(vtkSegment* segment, std::string tagsValue);
238 
239  static std::string GetImageExtentAsString(vtkOrientedImageData* image);
240  static std::string GetImageExtentAsString(int extent[6]);
241  static void GetImageExtentFromString(int extent[6], std::string extentValue);
242 
243  static std::string GetSegmentColorAsString(vtkMRMLSegmentationNode* segmentationNode, const std::string& segmentId);
244  static void GetSegmentColorFromString(double color[3], std::string colorString);
245 
246 protected:
247  bool CropToMinimumExtent{false};
248 
249 protected:
251  ~vtkMRMLSegmentationStorageNode() override;
252 
253 private:
255  void operator=(const vtkMRMLSegmentationStorageNode&) = delete;
256 };
257 
258 #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 ...