Slicer  4.8
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 
63  // Common conversion parameters
64  // ----------------------------
67  static const std::string GetReferenceImageGeometryParameterName() { return "Reference image geometry"; };
68 
70  static const char* GetScalarRangeFieldName() {return "ScalarRange";};
71  static const char* GetThresholdValueFieldName() {return "ThresholdValue";};
72  static const char* GetInterpolationTypeFieldName() {return "InterpolationType";};
73 
74 public:
75  static vtkSegmentationConverter* New();
76  vtkTypeMacro(vtkSegmentationConverter, vtkObject);
77  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
78 
80  virtual void DeepCopy(vtkSegmentationConverter* aConverter);
81 
83  void GetAvailableRepresentationNames(std::set<std::string>& representationNames);
84 
86  void GetPossibleConversions(const std::string& sourceRepresentationName, const std::string& targetRepresentationName, ConversionPathAndCostListType &pathsCosts);
87 
89  void GetConversionParametersForPath(vtkSegmentationConverterRule::ConversionParameterListType& conversionParameters, const ConversionPathType& path);
90 
92  void GetAllConversionParameters(vtkSegmentationConverterRule::ConversionParameterListType& conversionParameters);
93 
95  void SetConversionParameters(vtkSegmentationConverterRule::ConversionParameterListType parameters);
96 
98  void SetConversionParameter(const std::string& name, const std::string& value, const std::string& description="");
99 
102  std::string GetConversionParameter(const std::string& name);
103 
106  std::string GetConversionParameterDescription(const std::string& description);
107 
110  std::string SerializeAllConversionParameters();
111 
114  void DeserializeConversionParameters(std::string conversionParametersString);
115 
119  void ApplyTransformOnReferenceImageGeometry(vtkAbstractTransform* transform);
120 
121 // Utility functions
122 public:
124  static ConversionPathType GetCheapestPath(const ConversionPathAndCostListType &pathsCosts);
125 
127  static std::string SerializeImageGeometry(vtkOrientedImageData* orientedImageData);
128 
130  static std::string SerializeImageGeometry(vtkMatrix4x4* geometryMatrix, vtkImageData* imageData);
131 
133  static std::string SerializeImageGeometry(vtkMatrix4x4* geometryMatrix, int extent[6]);
134 
142  static bool DeserializeImageGeometry(std::string geometryString, vtkOrientedImageData* orientedImageData, bool allocateScalars=true, int scalarType=VTK_VOID, int numberOfScalarsComponents=-1);
143 
149  static bool DeserializeImageGeometry(std::string geometryString, vtkMatrix4x4* geometryMatrix, int extent[6]);
150 
151 protected:
153  void RebuildRulesGraph();
154 
164  void FindPath(const std::string& sourceRepresentationName, const std::string& targetRepresentationName, ConversionPathAndCostListType &pathsCosts, std::set<std::string>& skipRepresentations);
165 
166 protected:
169  void operator=(const vtkSegmentationConverter&);
170 
171 protected:
175  ConverterRulesListType ConverterRules;
176 
178  typedef std::vector<vtkSegmentationConverterRule*> RulesListType;
180  typedef std::map<std::string, RulesListType> RepresentationToRepresentationToRuleMapType;
181 
183  RepresentationToRepresentationToRuleMapType RulesGraph;
184 };
185 
186 #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)
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 * GetSegmentationClosedSurfaceRepresentationName()
RepresentationToRepresentationToRuleMapType RulesGraph
Source representation to target representation rule graph.
std::vector< vtkSegmentationConverterRule * > ConversionPathType
static const char * GetSegmentationFractionalLabelmapRepresentationName()
std::map< std::string, std::pair< std::string, std::string > > ConversionParameterListType
static const char * GetSegmentationPlanarContourRepresentationName()
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.