Slicer  5.2
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkSegmentationConverter.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 Csaba Pinter, PerkLab, Queen's University
16  and was supported through the Applied Cancer Research Unit program of Cancer Care
17  Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
18 
19 ==============================================================================*/
20 
21 #ifndef __vtkSegmentationConverter_h
22 #define __vtkSegmentationConverter_h
23 
24 // VTK includes
25 #include <vtkObject.h>
26 #include <vtkSmartPointer.h>
27 #include <vtkStringArray.h>
28 
29 // STD includes
30 #include <map>
31 #include <set>
32 #include <utility>
33 #include <vector>
34 
35 // Segmentation includes
36 #include "vtkSegmentationCoreConfigure.h"
37 
40 
41 class vtkAbstractTransform;
42 class vtkSegment;
43 class vtkMatrix4x4;
44 class vtkImageData;
46 
49 class vtkSegmentationCore_EXPORT vtkSegmentationConverter : public vtkObject
50 {
51 public:
52 
55  static const char* GetSegmentationBinaryLabelmapRepresentationName() { return "Binary labelmap"; };
56  static const char* GetSegmentationFractionalLabelmapRepresentationName() { return "Fractional labelmap"; };
57  static const char* GetSegmentationPlanarContourRepresentationName() { return "Planar contour"; };
58  static const char* GetSegmentationClosedSurfaceRepresentationName() { return "Closed surface"; };
59  static const char* GetBinaryLabelmapRepresentationName() { return GetSegmentationBinaryLabelmapRepresentationName(); };
60  static const char* GetFractionalLabelmapRepresentationName() { return GetSegmentationFractionalLabelmapRepresentationName(); };
61  static const char* GetPlanarContourRepresentationName() { return GetSegmentationPlanarContourRepresentationName(); };
62  static const char* GetClosedSurfaceRepresentationName() { return GetSegmentationClosedSurfaceRepresentationName(); };
63 
64  // Common conversion parameters
65  // ----------------------------
68  static const std::string GetReferenceImageGeometryParameterName() { return "Reference image geometry"; };
69 
71  static const char* GetScalarRangeFieldName() {return "ScalarRange";};
72  static const char* GetThresholdValueFieldName() {return "ThresholdValue";};
73  static const char* GetInterpolationTypeFieldName() {return "InterpolationType";};
74 
75 public:
76  static vtkSegmentationConverter* New();
77  vtkTypeMacro(vtkSegmentationConverter, vtkObject);
78  void PrintSelf(ostream& os, vtkIndent indent) override;
79 
81  virtual void DeepCopy(vtkSegmentationConverter* aConverter);
82 
84  void GetAvailableRepresentationNames(std::set<std::string>& representationNames);
85 
87  void GetPossibleConversions(const std::string& sourceRepresentationName,
88  const std::string& targetRepresentationName, vtkSegmentationConversionPaths* paths);
89 
91  void GetConversionParametersForPath(vtkSegmentationConversionParameters* conversionParameters, vtkSegmentationConversionPath* path);
92 
94  void GetAllConversionParameters(vtkSegmentationConversionParameters* conversionParameters);
95 
97  void SetConversionParameters(vtkSegmentationConversionParameters* parameters);
98 
100  void SetConversionParameter(const std::string& name, const std::string& value, const std::string& description="");
101 
104  std::string GetConversionParameter(const std::string& name);
105 
108  std::string GetConversionParameterDescription(const std::string& description);
109 
112  std::string SerializeAllConversionParameters();
113 
116  void DeserializeConversionParameters(std::string conversionParametersString);
117 
121  void ApplyTransformOnReferenceImageGeometry(vtkAbstractTransform* transform);
122 
123 // Utility functions
124 public:
126  static vtkSegmentationConversionPath* GetCheapestPath(vtkSegmentationConversionPaths* paths);
127 
129  static std::string SerializeImageGeometry(vtkOrientedImageData* orientedImageData);
130 
132  static std::string SerializeImageGeometry(vtkMatrix4x4* geometryMatrix, vtkImageData* imageData);
133 
135  static std::string SerializeImageGeometry(vtkMatrix4x4* geometryMatrix, int extent[6]);
136 
144  static bool DeserializeImageGeometry(std::string geometryString, vtkOrientedImageData* orientedImageData, bool allocateScalars=true, int scalarType=VTK_VOID, int numberOfScalarsComponents=-1);
145 
151  static bool DeserializeImageGeometry(std::string geometryString, vtkMatrix4x4* geometryMatrix, int extent[6]);
152 
153 protected:
155  void RebuildRulesGraph();
156 
166  void FindPath(const std::string& sourceRepresentationName, const std::string& targetRepresentationName,
167  vtkSegmentationConversionPaths* paths, vtkStringArray* skipRepresentations);
168 
169 protected:
171  ~vtkSegmentationConverter() override;
172 
173 protected:
174  typedef std::vector< vtkSmartPointer<vtkSegmentationConverterRule> > ConverterRulesListType;
175 
180 
182  typedef std::vector<vtkSegmentationConverterRule*> RulesListType;
184  typedef std::map<std::string, RulesListType> RepresentationToRepresentationToRuleMapType;
185 
188 
189 private:
191  void operator=(const vtkSegmentationConverter&) = delete;
192 };
193 
194 #endif // __vtkSegmentationConverter_h
This class encapsulates a segment that is part of a segmentation.
Definition: vtkSegment.h:45
static const char * GetThresholdValueFieldName()
static const char * GetInterpolationTypeFieldName()
static const std::string GetReferenceImageGeometryParameterName()
static const char * GetSegmentationBinaryLabelmapRepresentationName()
std::map< std::string, RulesListType > RepresentationToRepresentationToRuleMapType
For each "from" representation (first) stores an array of rules (second)
static const char * GetClosedSurfaceRepresentationName()
std::vector< vtkSmartPointer< vtkSegmentationConverterRule > > ConverterRulesListType
Image data containing orientation information.
std::vector< vtkSegmentationConverterRule * > RulesListType
For each "to" representation (first) stores a rule (second)
static const char * GetBinaryLabelmapRepresentationName()
static const char * GetSegmentationClosedSurfaceRepresentationName()
RepresentationToRepresentationToRuleMapType RulesGraph
Source representation to target representation rule graph.
static const char * GetSegmentationFractionalLabelmapRepresentationName()
static const char * GetFractionalLabelmapRepresentationName()
Store a list of conversion parameters.
Store multiple segmentation conversion paths.
static const char * GetSegmentationPlanarContourRepresentationName()
Store a segmentation conversion path.
static const char * GetPlanarContourRepresentationName()
static const char * GetScalarRangeFieldName()
Field names for 2D display parameters.
ConverterRulesListType ConverterRules
Class that can convert between different representations of a segment.