ITK  4.13.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 "itkMath.h"
35 
40 
41 namespace itk
42 {
43 namespace fem
44 {
45 
66 template <typename TMoving, typename TFixed>
67 class ITK_TEMPLATE_EXPORT FiniteDifferenceFunctionLoad : public LoadElement
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 
135 
136 
138  typedef PDEDeformableRegistrationFunction<FixedImageType, MovingImageType,
142 
144 
145  typedef MeanSquareRegistrationFunction<FixedImageType, MovingImageType,
147 
148  typedef DemonsRegistrationFunction<FixedImageType, MovingImageType,
150 
151  typedef NCCRegistrationFunction<FixedImageType, MovingImageType,
153 
154  typedef MIRegistrationFunction<FixedImageType, MovingImageType,
156 
157  typedef unsigned long ElementIdentifier;
158  typedef VectorContainer<ElementIdentifier, Element::Pointer> ElementContainerType;
159 
160 
161  /* This method sets the pointer to a FiniteDifferenceFunction object that
162  * will be used by the filter to calculate updates at image pixels.
163  * \returns A FiniteDifferenceObject pointer. */
164  void SetDifferenceFunction( FiniteDifferenceFunctionTypePointer drfp)
165  {
166  drfp->SetFixedImage(m_FixedImage);
167  drfp->SetMovingImage(m_MovingImage);
168  drfp->SetRadius(m_MetricRadius);
169  drfp->SetDisplacementField(m_DisplacementField);
170  drfp->InitializeIteration();
171  this->m_DifferenceFunction = drfp;
172  }
173 
175  {
176  this->SetDifferenceFunction( static_cast<FiniteDifferenceFunctionType *>(
177  drfp.GetPointer() ) );
178 
179  m_FixedSize = m_DisplacementField->GetLargestPossibleRegion().GetSize();
180  }
181 
184  {
185  m_MovingImage = R;
186  m_MovingSize = m_MovingImage->GetLargestPossibleRegion().GetSize();
187  if( this->m_DifferenceFunction )
188  {
189  this->m_DifferenceFunction->SetMovingImage(m_MovingImage);
190  }
191  }
193 
196  {
197  m_FixedImage = T;
198  m_FixedSize = T->GetLargestPossibleRegion().GetSize();
199  if( this->m_DifferenceFunction )
200  {
201  this->m_DifferenceFunction->SetFixedImage(m_MovingImage);
202  }
203  }
205 
207  {
208  return m_MovingImage;
209  }
210 
212  {
213  return m_FixedImage;
214  }
215 
218  {
219  m_MetricRadius = T;
220  }
221 
224  {
225  return m_MetricRadius;
226  }
227 
232  void SetNumberOfIntegrationPoints(unsigned int i)
233  {
234  m_NumberOfIntegrationPoints = i;
235  }
236 
238  {
239  return m_NumberOfIntegrationPoints;
240  }
241 
246  {
247  m_Sign = 1.0;
248  }
249 
251  {
252  m_Sign = -1.0;
253  }
254 
256  void SetGamma(Float s)
257  {
258  m_Gamma = s;
259  }
260 
261  virtual void SetSolution(Solution::ConstPointer ptr) ITK_OVERRIDE
262  {
263  m_Solution = ptr;
264  }
265 
266  virtual Solution::ConstPointer GetSolution() ITK_OVERRIDE
267  {
268  return m_Solution;
269  }
270 
271  // FIXME - WE ASSUME THE 2ND VECTOR (INDEX 1) HAS THE INFORMATION WE WANT
272  Float GetSolution(unsigned int i, unsigned int which = 0)
273  {
274  return m_Solution->GetSolutionValue(i, which);
275  }
276 
277  Float EvaluateMetricGivenSolution( ElementContainerType *el, Float step = 1.0);
278 
279 
283  FEMVectorType Fe(FEMVectorType);
284 
287  {
288  m_DisplacementField = df;
289  }
290 
293  {
294  return m_DisplacementField;
295  }
296 
297  void InitializeIteration();
298 
299  void InitializeMetric();
300 
301  void PrintCurrentEnergy();
302 
303  double GetCurrentEnergy();
304 
305  void SetCurrentEnergy( double e = 0.0 );
306 
307  virtual void ApplyLoad(Element::ConstPointer element, Element::VectorType & Fe) ITK_OVERRIDE;
308 
309 protected:
310 
311  virtual void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
312 
313 private:
314  FiniteDifferenceFunctionLoad(); // cannot be private until we always use smart pointers
315 
318 
321 
325  unsigned int m_SolutionIndex;
326  unsigned int m_SolutionIndex2;
329  float m_GradSigma;
330  float m_Sign;
333 
335 
336 };
337 
338 }
339 } // end namespace fem/itk
340 
341 #ifndef ITK_MANUAL_INSTANTIATION
342 #include "itkFEMFiniteDifferenceFunctionLoad.hxx"
343 #endif
344 
345 #endif
FixedNeighborhoodIteratorType::RadiusType FixedRadiusType
virtual Solution::ConstPointer GetSolution() override
Light weight base class for most itk classes.
void SetDisplacementField(DisplacementFieldTypePointer df)
FiniteDifferenceFunctionType::TimeStepType TimeStepType
MovingNeighborhoodIteratorType::RadiusType MovingRadiusType
ObjectType * GetPointer() const
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 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
Control indentation during Print() invocation.
Definition: itkIndent.h:49
static ITK_CONSTEXPR_VAR double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:56
Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.
Templated n-dimensional image class.
Definition: itkImage.h:75