Slicer  5.1
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 
28 // STD includes
29 #include <map>
30 #include <set>
31 #include <utility>
32 #include <vector>
33 
34 // Segmentation includes
35 #include "vtkSegmentationCoreConfigure.h"
36 
38 
39 class vtkAbstractTransform;
40 class vtkSegment;
41 class vtkMatrix4x4;
42 class vtkImageData;
44 
47 class vtkSegmentationCore_EXPORT vtkSegmentationConverter : public vtkObject
48 {
49 public:
50  typedef std::vector< vtkSmartPointer<vtkSegmentationConverterRule> > ConverterRulesListType;
51 
52  typedef std::vector<vtkSegmentationConverterRule*> ConversionPathType; // Contains a list of converter rule names
53  typedef std::pair<ConversionPathType, unsigned int> ConversionPathAndCostType;
54  typedef std::vector<ConversionPathAndCostType> ConversionPathAndCostListType;
55 
58  static const char* GetSegmentationBinaryLabelmapRepresentationName() { return "Binary labelmap"; };
59  static const char* GetSegmentationFractionalLabelmapRepresentationName() { return "Fractional labelmap"; };
60  static const char* GetSegmentationPlanarContourRepresentationName() { return "Planar contour"; };
61  static const char* GetSegmentationClosedSurfaceRepresentationName() { return "Closed surface"; };
62  static const char* GetBinaryLabelmapRepresentationName() { return GetSegmentationBinaryLabelmapRepresentationName(); };
63  static const char* GetFractionalLabelmapRepresentationName() { return GetSegmentationFractionalLabelmapRepresentationName(); };
64  static const char* GetPlanarContourRepresentationName() { return GetSegmentationPlanarContourRepresentationName(); };
65  static const char* GetClosedSurfaceRepresentationName() { return GetSegmentationClosedSurfaceRepresentationName(); };
66 
67  // Common conversion parameters
68  // ----------------------------
71  static const std::string GetReferenceImageGeometryParameterName() { return "Reference image geometry"; };
72 
74  static const char* GetScalarRangeFieldName() {return "ScalarRange";};
75  static const char* GetThresholdValueFieldName() {return "ThresholdValue";};
76  static const char* GetInterpolationTypeFieldName() {return "InterpolationType";};
77 
78 public:
79  static vtkSegmentationConverter* New();
80  vtkTypeMacro(vtkSegmentationConverter, vtkObject);
81  void PrintSelf(ostream& os, vtkIndent indent) override;
82 
84  virtual void DeepCopy(vtkSegmentationConverter* aConverter);
85 
87  void GetAvailableRepresentationNames(std::set<std::string>& representationNames);
88 
90  void GetPossibleConversions(const std::string& sourceRepresentationName, const std::string& targetRepresentationName, ConversionPathAndCostListType &pathsCosts);
91 
93  void GetConversionParametersForPath(vtkSegmentationConverterRule::ConversionParameterListType& conversionParameters, const ConversionPathType& path);
94 
96  void GetAllConversionParameters(vtkSegmentationConverterRule::ConversionParameterListType& conversionParameters);
97 
99  void SetConversionParameters(vtkSegmentationConverterRule::ConversionParameterListType parameters);
100 
102  void SetConversionParameter(const std::string& name, const std::string& value, const std::string& description="");
103 
106  std::string GetConversionParameter(const std::string& name);
107 
110  std::string GetConversionParameterDescription(const std::string& description);
111 
114  std::string SerializeAllConversionParameters();
115 
118  void DeserializeConversionParameters(std::string conversionParametersString);
119 
123  void ApplyTransformOnReferenceImageGeometry(vtkAbstractTransform* transform);
124 
125 // Utility functions
126 public:
128  static ConversionPathType GetCheapestPath(const ConversionPathAndCostListType &pathsCosts);
129 
131  static std::string SerializeImageGeometry(vtkOrientedImageData* orientedImageData);
132 
134  static std::string SerializeImageGeometry(vtkMatrix4x4* geometryMatrix, vtkImageData* imageData);
135 
137  static std::string SerializeImageGeometry(vtkMatrix4x4* geometryMatrix, int extent[6]);
138 
146  static bool DeserializeImageGeometry(std::string geometryString, vtkOrientedImageData* orientedImageData, bool allocateScalars=true, int scalarType=VTK_VOID, int numberOfScalarsComponents=-1);
147 
153  static bool DeserializeImageGeometry(std::string geometryString, vtkMatrix4x4* geometryMatrix, int extent[6]);
154 
155 protected:
157  void RebuildRulesGraph();
158 
168  void FindPath(const std::string& sourceRepresentationName, const std::string& targetRepresentationName, ConversionPathAndCostListType &pathsCosts, std::set<std::string>& skipRepresentations);
169 
170 protected:
172  ~vtkSegmentationConverter() override;
173 
174 protected:
179 
181  typedef std::vector<vtkSegmentationConverterRule*> RulesListType;
183  typedef std::map<std::string, RulesListType> RepresentationToRepresentationToRuleMapType;
184 
187 
188 private:
190  void operator=(const vtkSegmentationConverter&) = delete;
191 };
192 
193 #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::vector< ConversionPathAndCostType > ConversionPathAndCostListType
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.
std::vector< vtkSegmentationConverterRule * > ConversionPathType
static const char * GetSegmentationFractionalLabelmapRepresentationName()
static const char * GetFractionalLabelmapRepresentationName()
std::map< std::string, std::pair< std::string, std::string > > ConversionParameterListType
static const char * GetSegmentationPlanarContourRepresentationName()
static const char * GetPlanarContourRepresentationName()
static const char * GetScalarRangeFieldName()
Field names for 2D display parameters.
ConverterRulesListType ConverterRules
std::pair< ConversionPathType, unsigned int > ConversionPathAndCostType
Class that can convert between different representations of a segment.