ITK  4.8.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 <typename TMoving, typename TFixed>
68 {
69 public:
70 
76 
78  itkSimpleNewMacro(Self);
79 
82 
83 
86  virtual::itk::LightObject::Pointer CreateAnother(void) const ITK_OVERRIDE;
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;
93  typedef MovingImageType * MovingPointer;
94  typedef TFixed FixedImageType;
95  typedef FixedImageType * FixedPointer;
96  typedef typename FixedImageType::ConstPointer FixedConstPointer;
97 
99  itkStaticConstMacro(ImageDimension, unsigned int,
100  MovingImageType::ImageDimension);
101 
104 
105  typedef NeighborhoodIterator<MovingImageType>
107  typedef typename MovingNeighborhoodIteratorType::IndexType
113  typedef NeighborhoodIterator<FixedImageType>
115  typedef typename FixedNeighborhoodIteratorType::IndexType
117  typedef typename FixedNeighborhoodIteratorType::RadiusType
119 
120  // Typedefs for Image Data
121  typedef typename MovingImageType::PixelType MovingPixelType;
122  typedef typename FixedImageType::PixelType FixedPixelType;
123  typedef Float PixelType;
124  typedef Float ComputationType;
125  typedef Image<PixelType, itkGetStaticConstMacro(ImageDimension)>
127  typedef itk::Vector<float, itkGetStaticConstMacro(ImageDimension)>
129  typedef vnl_vector<Float> FEMVectorType;
130  typedef Image<VectorType, itkGetStaticConstMacro(ImageDimension)>
133 
136 
137 
139  typedef PDEDeformableRegistrationFunction<FixedImageType, MovingImageType,
143 
145 
146  typedef MeanSquareRegistrationFunction<FixedImageType, MovingImageType,
148 
149  typedef DemonsRegistrationFunction<FixedImageType, MovingImageType,
151 
152  typedef NCCRegistrationFunction<FixedImageType, MovingImageType,
154 
155  typedef MIRegistrationFunction<FixedImageType, MovingImageType,
157 
158  typedef unsigned long ElementIdentifier;
159  typedef VectorContainer<ElementIdentifier, Element::Pointer> ElementContainerType;
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 
176  {
177  this->SetDifferenceFunction( static_cast<FiniteDifferenceFunctionType *>(
178  drfp.GetPointer() ) );
179 
180  m_FixedSize = m_DisplacementField->GetLargestPossibleRegion().GetSize();
181  }
182 
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 
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 
208  {
209  return m_MovingImage;
210  }
211 
213  {
214  return m_FixedImage;
215  }
216 
219  {
220  m_MetricRadius = T;
221  }
222 
225  {
226  return m_MetricRadius;
227  }
228 
233  void SetNumberOfIntegrationPoints(unsigned int i)
234  {
236  }
237 
239  {
241  }
242 
247  {
248  m_Sign = 1.0;
249  }
250 
252  {
253  m_Sign = -1.0;
254  }
255 
257  void SetGamma(Float s)
258  {
259  m_Gamma = s;
260  }
261 
262  virtual void SetSolution(Solution::ConstPointer ptr) ITK_OVERRIDE
263  {
264  m_Solution = ptr;
265  }
266 
267  virtual Solution::ConstPointer GetSolution() ITK_OVERRIDE
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 
279 
280 
285 
288  {
289  m_DisplacementField = df;
290  }
291 
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) ITK_OVERRIDE;
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
FixedNeighborhoodIteratorType::RadiusType FixedRadiusType
virtual Solution::ConstPointer GetSolution() override
Light weight base class for most itk classes.
void SetDisplacementField(DisplacementFieldTypePointer df)
Float EvaluateMetricGivenSolution(ElementContainerType *el, Float step=1.0)
FiniteDifferenceFunctionType::TimeStepType TimeStepType
VectorContainer< ElementIdentifier, Element::Pointer > ElementContainerType
MovingNeighborhoodIteratorType::RadiusType MovingRadiusType
ObjectType * GetPointer() const
static const double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:45
Provides functions to access the values of the solution vector.
General image pair load that uses the itkFiniteDifferenceFunctions.
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
MovingNeighborhoodIteratorType::IndexType MovingNeighborhoodIndexType
FixedNeighborhoodIteratorType::IndexType FixedNeighborhoodIndexType
Float GetSolution(unsigned int i, unsigned int which=0)
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
vnl_vector< Float > VectorType
Virtual element load base class.
virtual void ApplyLoad(Element::ConstPointer element, Element::VectorType &Fe) override
FEMVectorType Fe(FEMVectorType)
void SetDifferenceFunction(FiniteDifferenceFunctionTypePointer drfp)
virtual void SetSolution(Solution::ConstPointer ptr) override
Abstract base element class.
MovingNeighborhoodIteratorType::RadiusType RadiusType
Define a front-end to the STL &quot;vector&quot; container that conforms to the IndexedContainerInterface.
void SetMetric(FiniteDifferenceFunctionTypePointer drfp)
FiniteDifferenceFunctionTypePointer m_DifferenceFunction
virtual ::itk::LightObject::Pointer CreateAnother(void) const override
virtual Float GetSolutionValue(unsigned int i, unsigned int solutionIndex=0) const =0
Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.
Templated n-dimensional image class.
Definition: itkImage.h:75