ANIMA  4.0
animaPyramidalSymmetryBridge.h
Go to the documentation of this file.
1 #pragma once
2 #include <cmath>
3 
4 #include <itkObject.h>
5 #include <itkImage.h>
6 #include <itkCommand.h>
7 #include <itkMultiResolutionPyramidImageFilter.h>
9 #include <itkAffineTransform.h>
10 
11 enum Metric
12 {
15 };
16 
17 namespace anima
18 {
19 
20 template <class PixelType = double, typename ScalarType = double>
21 class PyramidalSymmetryBridge : public itk::ProcessObject
22 {
23 public:
24  typedef typename itk::Image <PixelType,3> InputImageType;
25  typedef typename itk::Image <double,3> OutputImageType;
26  typedef typename InputImageType::Pointer InputImagePointer;
27  typedef typename OutputImageType::Pointer OutputImagePointer;
28 
34 
35  typedef typename itk::AffineTransform<ScalarType,3> BaseTransformType;
36  typedef typename BaseTransformType::Pointer BaseTransformPointer;
37 
38  typedef itk::MultiResolutionPyramidImageFilter <InputImageType,OutputImageType> PyramidType;
39  typedef typename PyramidType::Pointer PyramidPointer;
40 
43  typedef itk::ProcessObject Superclass;
44 
45  typedef itk::SmartPointer<Self> Pointer;
46  typedef itk::SmartPointer<const Self> ConstPointer;
47 
48  itkNewMacro(Self)
49 
50  itkTypeMacro(PyramidalSymmetryBridge,itk::ProcessObject)
51 
52  void ParseParameters(int argc, const char **argv);
53 
54  void Update() ITK_OVERRIDE;
55 
56  void WriteOutputs();
57 
58  void ComputeRealignTransform(itk::Vector <double,InputImageType::ImageDimension> centralPoint,
59  typename InputImageType::PointType &centerReal, ParametersType &imageParams);
60 
61  Metric GetMetric() {return m_metric;}
62  void SetMetric(Metric metric) {m_metric=metric;}
63 
64  int GetOptimizerMaxIterations() {return m_optMaxIterations;}
65  void SetOptimizerMaxIterations(int optMaxIterations) {m_optMaxIterations=optMaxIterations;}
66 
67  int GetHistogramSize() {return m_histogramSize;}
68  void SetHistogramSize(int histogramSize) {m_histogramSize=histogramSize;}
69 
70  double GetUpperBoundDistance() {return m_UpperBoundDistance;}
71  void SetUpperBoundDistance(double val) {m_UpperBoundDistance = val;}
72 
73  double GetUpperBoundAngle() {return m_UpperBoundAngle;}
74  void SetUpperBoundAngle(double val) {m_UpperBoundAngle = val;}
75 
76  int GetNumberOfPyramidLevels() {return m_numberOfPyramidLevels;}
77  void SetNumberOfPyramidLevels(int numberOfPyramidLevels) {m_numberOfPyramidLevels=numberOfPyramidLevels;}
78 
79  std::string GetResultfile() {return m_resultFile;}
80  void SetResultFile(std::string resultFile) {m_resultFile=resultFile;}
81 
82  std::string GetOutputRealignTransformFile() {return m_outputRealignTransformFile;}
83  void SetOutputRealignTransformFile(std::string outputRealignTransformFile) {m_outputRealignTransformFile=outputRealignTransformFile;}
84 
85  std::string GetOutputTransformFile() {return m_outputTransformFile;}
86  void SetOutputTransformFile(std::string outputTransformFile) {m_outputTransformFile=outputTransformFile;}
87 
88  std::string GetFixedfile() {return m_fixedfile;}
89  void SetFixedfile(std::string fixedfile) {m_fixedfile=fixedfile;}
90 
91  void SetReferenceImage(InputImagePointer referenceImage) {m_ReferenceImage = referenceImage;}
92 
93  void SetFloatingImage(InputImagePointer FloatingImage) {m_FloatingImage= FloatingImage;}
94 
95  void SetProgressCallback(itk::CStyleCommand::Pointer callback ) {m_progressCallback = callback;}
96 
97  void SaveResultFile(void);
98 
99  void SaveRealignTransformFile(void);
100 
101  void SaveTransformFile(void);
102 
103  OutputImagePointer GetOutputImage() {return m_OutputImage;}
104 
105  // Get Symmetry transform
106  TransformPointer GetOutputTransform() {return m_OutputTransform;}
107 
108  //Get Transform to realign image onto its mid-sagittal plane
109  BaseTransformPointer GetOutputRealignTransform() {return m_OutputRealignTransform;}
110 
111 protected:
113  {
114  m_ReferenceImage = NULL;
115  m_FloatingImage = NULL;
116 
117  m_ReferencePyramid = NULL;
118  m_FloatingPyramid = NULL;
119 
120  m_OutputTransform = TransformType::New();
121  m_OutputTransform->SetIdentity();
122 
123  m_OutputImage = NULL;
124 
125  //default values
126  m_metric = MeanSquares;
127  m_UpperBoundDistance = 6;
128  m_UpperBoundAngle = M_PI;
129  m_optMaxIterations = 100;
130  m_histogramSize = 120;
131  m_numberOfPyramidLevels = 3;
132  this->SetNumberOfWorkUnits(itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads());
133  m_fixedfile = "";
134  m_outputRealignTransformFile = "";
135  m_outputTransformFile = "";
136  m_resultFile = "";
137  }
138 
140 
141  void SetupPyramids();
142 
143 private:
144  ITK_DISALLOW_COPY_AND_ASSIGN(PyramidalSymmetryBridge);
145 
146  InputImagePointer m_ReferenceImage, m_FloatingImage;
147  PyramidPointer m_ReferencePyramid, m_FloatingPyramid;
148 
149  //Symmetry transform
150  TransformPointer m_OutputTransform;
151 
152  //Transform to realign image onto its mid-sagittal plane
153  BaseTransformPointer m_OutputRealignTransform;
154 
155  OutputImagePointer m_OutputImage;
156 
157  Metric m_metric;
158  int m_optMaxIterations;
159  int m_histogramSize;
160  int m_numberOfPyramidLevels;
161  double m_UpperBoundDistance, m_UpperBoundAngle;
162  std::string m_fixedfile;
163  std::string m_outputRealignTransformFile;
164  std::string m_outputTransformFile;
165  std::string m_resultFile;
166 
167  itk::CStyleCommand::Pointer m_progressCallback;
168 };
169 
170 }// end of namespace anima
171 
void SetOutputRealignTransformFile(std::string outputRealignTransformFile)
TransformType::ParametersType ParametersType
void SetFixedfile(std::string fixedfile)
itk::AffineTransform< ScalarType, 3 > BaseTransformType
void SetOutputTransformFile(std::string outputTransformFile)
void ParseParameters(int argc, const char **argv)
void SetResultFile(std::string resultFile)
void ComputeRealignTransform(itk::Vector< double, InputImageType::ImageDimension > centralPoint, typename InputImageType::PointType &centerReal, ParametersType &imageParams)
itk::MultiResolutionPyramidImageFilter< InputImageType, OutputImageType > PyramidType
anima::SymmetryPlaneTransform< ScalarType > TransformType
void SetNumberOfPyramidLevels(int numberOfPyramidLevels)
void SetOptimizerMaxIterations(int optMaxIterations)
itk::SmartPointer< const Self > ConstPointer
void SetFloatingImage(InputImagePointer FloatingImage)
itk::Image< PixelType, 3 > InputImageType
void SetProgressCallback(itk::CStyleCommand::Pointer callback)
BaseTransformType::Pointer BaseTransformPointer
void SetReferenceImage(InputImagePointer referenceImage)
Superclass::ParametersType ParametersType