ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkFEMFiniteDifferenceFunctionLoad.h
Go to the documentation of this file.
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 __itkFEMFiniteDifferenceFunctionLoad_h
19 #define __itkFEMFiniteDifferenceFunctionLoad_h
20 
21 #include "itkFEMLoadElementBase.h"
22 
23 #include "itkFEMObject.h"
24 #include "itkImage.h"
26 
31 #include "itkDerivativeOperator.h"
34 #include "vnl/vnl_math.h"
35 
40 
41 namespace itk
42 {
43 namespace fem
44 {
45 
66 template <class TMoving, class TFixed>
67 class ITK_EXPORT FiniteDifferenceFunctionLoad : public LoadElement
68 {
69 public:
70 
76 
78  itkSimpleNewMacro(Self);
79 
82 
83 
86  virtual::itk::LightObject::Pointer CreateAnother(void) const;
87 
88  // Necessary typedefs for dealing with images BEGIN
89  typedef typename LoadElement::Float Float;
90 
91  typedef TMoving MovingImageType;
92  typedef typename MovingImageType::ConstPointer MovingConstPointer;
94  typedef TFixed FixedImageType;
96  typedef typename FixedImageType::ConstPointer FixedConstPointer;
97 
99  itkStaticConstMacro(ImageDimension, unsigned int,
100  MovingImageType::ImageDimension);
101 
104 
119 
120  // Typedefs for Image Data
121  typedef typename MovingImageType::PixelType MovingPixelType;
122  typedef typename FixedImageType::PixelType FixedPixelType;
123  typedef Float PixelType;
133 
136 
137 
143 
145 
148 
151 
154 
157 
158  typedef unsigned long ElementIdentifier;
160 
161 
162  /* This method sets the pointer to a FiniteDifferenceFunction object that
163  * will be used by the filter to calculate updates at image pixels.
164  * \returns A FiniteDifferenceObject pointer. */
165  void SetDifferenceFunction( FiniteDifferenceFunctionTypePointer drfp)
166  {
167  drfp->SetFixedImage(m_FixedImage);
168  drfp->SetMovingImage(m_MovingImage);
169  drfp->SetRadius(m_MetricRadius);
170  drfp->SetDisplacementField(m_DisplacementField);
171  drfp->InitializeIteration();
172  this->m_DifferenceFunction = drfp;
173  }
174 
175  void SetMetric( FiniteDifferenceFunctionTypePointer drfp )
176  {
177  this->SetDifferenceFunction( static_cast<FiniteDifferenceFunctionType *>(
178  drfp.GetPointer() ) );
179 
180  m_FixedSize = m_DisplacementField->GetLargestPossibleRegion().GetSize();
181  }
182 
184  void SetMovingImage(MovingImageType* R)
185  {
186  m_MovingImage = R;
187  m_MovingSize = m_MovingImage->GetLargestPossibleRegion().GetSize();
188  if( this->m_DifferenceFunction )
189  {
190  this->m_DifferenceFunction->SetMovingImage(m_MovingImage);
191  }
192  }
194 
196  void SetFixedImage(FixedImageType* T)
197  {
198  m_FixedImage = T;
199  m_FixedSize = T->GetLargestPossibleRegion().GetSize();
200  if( this->m_DifferenceFunction )
201  {
202  this->m_DifferenceFunction->SetFixedImage(m_MovingImage);
203  }
204  }
206 
207  MovingPointer GetMovingImage()
208  {
209  return m_MovingImage;
210  }
211 
212  FixedPointer GetFixedImage()
213  {
214  return m_FixedImage;
215  }
216 
218  void SetMetricRadius(MovingRadiusType T)
219  {
220  m_MetricRadius = T;
221  }
222 
224  MovingRadiusType GetMetricRadius()
225  {
226  return m_MetricRadius;
227  }
228 
233  void SetNumberOfIntegrationPoints(unsigned int i)
234  {
235  m_NumberOfIntegrationPoints = i;
236  }
237 
238  unsigned int GetNumberOfIntegrationPoints()
239  {
240  return m_NumberOfIntegrationPoints;
241  }
242 
246  void SetDescentDirectionMinimize( )
247  {
248  m_Sign = 1.0;
249  }
250 
251  void SetDescentDirectionMaximize()
252  {
253  m_Sign = -1.0;
254  }
255 
257  void SetGamma(Float s)
258  {
259  m_Gamma = s;
260  }
261 
262  void SetSolution(Solution::ConstPointer ptr)
263  {
264  m_Solution = ptr;
265  }
266 
268  {
269  return m_Solution;
270  }
271 
272  // FIXME - WE ASSUME THE 2ND VECTOR (INDEX 1) HAS THE INFORMATION WE WANT
273  Float GetSolution(unsigned int i, unsigned int which = 0)
274  {
275  return m_Solution->GetSolutionValue(i, which);
276  }
277 
278  Float EvaluateMetricGivenSolution( ElementContainerType *el, Float step = 1.0);
279 
280 
284  FEMVectorType Fe(FEMVectorType);
285 
287  void SetDisplacementField( DisplacementFieldTypePointer df)
288  {
289  m_DisplacementField = df;
290  }
291 
293  DisplacementFieldTypePointer GetDisplacementField()
294  {
295  return m_DisplacementField;
296  }
297 
298  void InitializeIteration();
299 
300  void InitializeMetric();
301 
302  void PrintCurrentEnergy();
303 
304  double GetCurrentEnergy();
305 
306  void SetCurrentEnergy( double e = 0.0);
307 
308  virtual void ApplyLoad(Element::ConstPointer element, Element::VectorType & Fe);
309 
310 protected:
311 
312 private:
313  FiniteDifferenceFunctionLoad(); // cannot be private until we always use smart pointers
314 
319  typename MovingImageType::SizeType m_MovingSize;
320  typename FixedImageType::SizeType m_FixedSize;
322  unsigned int m_SolutionIndex;
323  unsigned int m_SolutionIndex2;
326  float m_GradSigma;
327  float m_Sign;
330 
332 
333 };
334 
335 }
336 } // end namespace fem/itk
337 
338 #ifndef ITK_MANUAL_INSTANTIATION
339 #include "itkFEMFiniteDifferenceFunctionLoad.hxx"
340 #endif
341 
342 #endif
343