Shapeworks Studio  2.1
Shape analysis software suite
itkPSMGradientDescentOptimizer.h
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkPSMGradientDescentOptimizer_h
19 #define __itkPSMGradientDescentOptimizer_h
20 
21 #include <vector>
22 #include "itkObject.h"
23 #include "itkObjectFactory.h"
24 #include "itkWeakPointer.h"
25 #include "vnl/vnl_vector_fixed.h"
26 #include "itkPSMParticleSystem.h"
27 #include "itkPSMCostFunction.h"
28 #include "itkPSMImageDomainWithGradients.h"
29 
30 namespace itk
31 {
32 
44 template <class TGradientNumericType, unsigned int VDimension>
45 class PSMGradientDescentOptimizer : public Object
46 {
47 public:
50  typedef Object Superclass;
51  typedef SmartPointer<Self> Pointer;
52  typedef SmartPointer<const Self> ConstPointer;
53  typedef WeakPointer<const Self> ConstWeakPointer;
54 
56  itkNewMacro(Self);
57 
60 
63 
65  itkStaticConstMacro(Dimension, unsigned int, VDimension);
66 
69 
72 
75 
78 
81  {
82  if (m_OptimizationMode == 0) { this->StartJacobiOptimization(); }
83  else { this->StartGaussSeidelOptimization(); }
84  }
85  void StartJacobiOptimization();
86  void StartGaussSeidelOptimization();
87 
89  void SetModeToGaussSeidel() { this->m_OptimizationMode = 1; }
90  void SetModeToJacobi() { this->m_OptimizationMode = 0; }
91 
94  inline void StopOptimization()
95  { this->m_StopOptimization = true; }
96 
98  itkGetMacro(NumberOfIterations, unsigned int);
99  itkSetMacro(NumberOfIterations, unsigned int);
100 
103  itkGetMacro(TimeStep, double);
104  itkSetMacro(TimeStep, double);
105 
107  itkGetMacro(MaximumNumberOfIterations, unsigned int);
108  itkSetMacro(MaximumNumberOfIterations, unsigned int);
109 
111  itkGetMacro(Tolerance, double);
112  itkSetMacro(Tolerance, double);
113 
115  itkGetObjectMacro(ParticleSystem, ParticleSystemType);
116  itkSetObjectMacro(ParticleSystem, ParticleSystemType);
117 
119  itkGetObjectMacro(CostFunction, CostFunctionType);
120  itkSetObjectMacro(CostFunction, CostFunctionType);
121 
122 protected:
126  void PrintSelf(std::ostream& os, Indent indent) const
127  {
128  Superclass::PrintSelf(os, indent);
129  }
130  virtual ~PSMGradientDescentOptimizer() {};
131 
132 private:
133  typename ParticleSystemType::Pointer m_ParticleSystem;
134  typename CostFunctionType::Pointer m_CostFunction;
135  bool m_StopOptimization;
136  unsigned int m_NumberOfIterations;
137  unsigned int m_MaximumNumberOfIterations;
138  double m_Tolerance;
139  double m_TimeStep;
140  int m_OptimizationMode;
141 
142  std::vector< std::vector<double> > m_TimeSteps;
143 };
144 
145 } // end namespace
146 
147 #ifndef ITK_MANUAL_INSTANTIATION
148 #include "itkPSMGradientDescentOptimizer.hxx"
149 #endif
150 
151 #endif
152 
PSMImageDomainWithGradients< TGradientNumericType, VDimension > DomainType
itkTypeMacro(PSMGradientDescentOptimizer, Object)
itkGetMacro(NumberOfIterations, unsigned int)
itkGetObjectMacro(ParticleSystem, ParticleSystemType)
PSMParticleSystem< VDimension > ParticleSystemType
A facade class that manages interactions with a particle system.
vnl_vector_fixed< double, VDimension > VectorType
PSMCostFunction< VDimension > CostFunctionType
Definition: Shape.h:14
itkStaticConstMacro(Dimension, unsigned int, VDimension)