Orfeo Toolbox  3.16
itkFEMRegistrationFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkFEMRegistrationFilter.h,v $
5  Language: C++
6  Date: $Date: 2010-03-02 03:40:35 $
7  Version: $Revision: 1.29 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 
18 #ifndef __itkFEMRegistrationFilter_h
19 #define __itkFEMRegistrationFilter_h
20 
23 #include "itkFEMGenerateMesh.h"
26 #include "itkFEMImageMetricLoad.h"
28 
29 #include "itkImage.h"
30 #include "itkVector.h"
34 #include "itkWarpImageFilter.h"
35 #include "itkImageToImageMetric.h"
38 
40 #include "itkFEMLoadLandmark.h"
41 
42 #include "vnl/vnl_vector.h"
43 #include "vnl/vnl_math.h"
44 #include "vnl/vnl_vector_fixed.h"
45 
46 
47 #include <iostream>
48 #include <string>
49 
50 namespace itk {
51 namespace fem {
52 
105 template<class TMovingImage,class TFixedImage>
106 class ITK_EXPORT FEMRegistrationFilter : public ImageToImageFilter<TMovingImage, TFixedImage>
107 {
108 public:
113 
115  itkNewMacro(Self);
116 
119 
120  typedef TMovingImage MovingImageType;
121  typedef TFixedImage FixedImageType;
122  typedef typename FixedImageType::PixelType PixelType;
123  typedef typename FixedImageType::SizeType ImageSizeType;
124 
126  itkStaticConstMacro(ImageDimension, unsigned int,
127  FixedImageType::ImageDimension);
128 
132  enum Sign { positive = 1, negative = -1 };
133  typedef double Float;
135 
136 
137  typedef std::vector<typename LoadLandmark::Pointer> LandmarkArrayType;
150 
152  typedef double CoordRepType;
158 
160  itkSetObjectMacro( Interpolator, InterpolatorType );
161 
163  itkGetObjectMacro( Interpolator, InterpolatorType );
164 
165 
168 
171 
173 //#define USEIMAGEMETRIC
174 #ifdef USEIMAGEMETRIC
177 #else
182 #endif
184  /* Main functions */
185 
187  bool ReadConfigFile(const char*);
188 
189 
191  void RunRegistration(void);
192 
196  void WriteWarpedImage(const char* fn);
197 
198 
200  void IterativeSolve(SolverType& S);
201 
203  void MultiResSolve();
204 
206  void WarpImage(const MovingImageType * R);
207 
209  int WriteDisplacementField(unsigned int index);
210 
212  int WriteDisplacementFieldMultiComponent();
213 
216  void SetMovingFile(const char* r)
217  {
218  m_MovingFileName=r;
219  }
220 
221  std::string GetMovingFile()
222  {
223  return m_MovingFileName;
224  }
225 
227  void SetFixedFile(const char* t) {m_FixedFileName=t;}
228 
229  std::string GetFixedFile() {return m_FixedFileName;}
230 
231 
235  void SetMovingImage(MovingImageType* R);
236 
238  void SetFixedImage(FixedImageType* T);
239 
240  MovingImageType* GetMovingImage(){return m_MovingImage;}
241  MovingImageType* GetOriginalMovingImage(){return m_OriginalMovingImage;}
242 
243  FixedImageType* GetFixedImage(){return m_FixedImage;}
244 
245 
248  FixedImageType* GetWarpedImage(){return m_WarpedImage;}
249 
251  void ComputeJacobian(float sign=1.0, FieldType* field=NULL , float smooth=0.0);
252 
254  FloatImageType* GetJacobianImage(){return m_FloatImage;}
255 
256 
259  FieldType* GetDeformationField(){return m_Field;}
261  void SetDeformationField(FieldType* F)
262  {
263  m_FieldSize=F->GetLargestPossibleRegion().GetSize();
264  m_Field=F;
265  }
266 
269  void SetLandmarkFile(const char* l)
270  {
271  m_LandmarkFileName=l;
272  }
273 
275  void UseLandmarks(bool b)
276  {
277  m_UseLandmarks=b;
278  }
279 
287  void EnforceDiffeomorphism(float thresh , SolverType& S , bool onlywriteimages);
288 
289 
294  void SetResultsFile(const char* r)
295  {
296  m_ResultsFileName=r;
297  }
298 
299  void SetResultsFileName (const char* f)
300  {
301  m_ResultsFileName=f;
302  }
303 
304  std::string GetResultsFileName ()
305  {
306  return m_ResultsFileName;
307  }
308 
310  void SetDisplacementsFile(const char* r)
311  {
312  m_DisplacementsFileName=r;
313  }
314 
321  void SetMeshPixelsPerElementAtEachResolution(unsigned int i,unsigned int which=0)
322  {
323  m_MeshPixelsPerElementAtEachResolution[which]=i;
324  }
325 
329  void SetNumberOfIntegrationPoints(unsigned int i,unsigned int which=0)
330  {
331  m_NumberOfIntegrationPoints[which]=i;
332  }
333 
339  void SetWidthOfMetricRegion(unsigned int i,unsigned int which=0)
340  {
341  m_MetricWidth[which]=i;
342  }
343  unsigned int GetWidthOfMetricRegion(unsigned int which=0)
344  {
345  return m_MetricWidth[which];
346  }
347 
352  void SetMaximumIterations(unsigned int i,unsigned int which)
353  {
354  m_Maxiters[which]=i;
355  }
356 
359  void SetTimeStep(Float i)
360  {
361  m_Dt=i;
362  }
363 
365  void SetAlpha(Float a)
366  {
367  m_Alpha=a;
368  }
369 
372  void SetEnergyReductionFactor(Float i)
373  {
374  m_EnergyReductionFactor=i;
375  }
376 
378  void SetElasticity(Float i,unsigned int which=0)
379  {
380  m_E[which]=i;
381  }
382 
384  Float GetElasticity(unsigned int which=0)
385  {
386  return m_E[which];
387  }
388 
390  void SetRho(Float r,unsigned int which=0)
391  {
392  m_Rho[which]=r;
393  }
394 
396  void SetGamma(Float r,unsigned int which=0)
397  {
398  m_Gamma[which]=r;
399  }
400 
402  void SetDescentDirectionMinimize()
403  {
404  m_DescentDirection=positive;
405  }
406 
408  void SetDescentDirectionMaximize()
409  {
410  m_DescentDirection=negative;
411  }
412 
415  void DoLineSearch(unsigned int b)
416  {
417  m_DoLineSearchOnImageEnergy=b;
418  }
419 
421  void DoMultiRes(bool b)
422  {
423  m_DoMultiRes=b;
424  }
425 
427  void EmployRegridding(unsigned int b)
428  {
429  m_EmployRegridding=b;
430  }
431 
433  void SetLineSearchMaximumIterations(unsigned int f)
434  {
435  m_LineSearchMaximumIterations=f;
436  }
437 
439  void SetWriteDisplacements(bool b)
440  {
441  m_WriteDisplacementField=b;
442  }
443 
445  bool GetWriteDisplacements()
446  {
447  return m_WriteDisplacementField;
448  }
449 
452  void SetConfigFileName (const char* f){m_ConfigFileName=f;}
453 
454  std::string GetConfigFileName () {return m_ConfigFileName; }
455 
456  ImageSizeType GetImageSize(){ return m_FullImageSize; }
457 
459  MetricBaseTypePointer GetMetric() { return m_Metric; }
460  void SetMetric(MetricBaseTypePointer MP) { m_Metric=MP; }
461 
464  void ChooseMetric( float whichmetric);
465 
467  void SetElement(Element::Pointer e) {m_Element=e;}
468 
470  void SetMaterial(MaterialType::Pointer m) {m_Material=m;}
471 
472  void PrintVectorField(unsigned int modnum=1000);
473 
474  void SetNumLevels(unsigned int i) { m_NumLevels=i; }
475  void SetMaxLevel(unsigned int i) { m_MaxLevel=i; }
476 
477  void SetTemp(Float i) { m_Temp=i; }
478 
482 
483 // HELPER FUNCTIONS
484 protected:
485 
486 
493  class FEMOF : public FEMObjectFactory<FEMLightObject>{
494  protected:
495  FEMOF();
496  ~FEMOF();
497  };
498 
499 
501  void CreateMesh(double ElementsPerSide, Solver& S, ImageSizeType sz);
502 
504  void ApplyLoads(SolverType& S,ImageSizeType Isz,double* spacing=NULL);
505 
507  void ApplyImageLoads(SolverType& S, MovingImageType* i1, FixedImageType* i2);
508 
509 
512  void CreateLinearSystemSolver();
513 
514 
516  Float EvaluateEnergy();
517 
522  void InterpolateVectorField(SolverType& S);
523 
526  FloatImageType* GetMetricImage(FieldType* F);
527 
528 
531  FieldPointer ExpandVectorField(ExpandFactorsType* expandFactors, FieldType* f);
532 
533 
535  void SampleVectorFieldAtNodes(SolverType& S);
536 
537  Float EvaluateResidual(SolverType& mySolver,Float t);
538 
539  /* Finds a triplet that brackets the energy minimum. From Numerical Recipes.*/
540  void FindBracketingTriplet(SolverType& mySolver,Float* a, Float* b, Float* c);
541 
545  Float GoldenSection(SolverType& mySolver,Float tol=0.01,unsigned int MaxIters=25);
546 
548 // itkSetMacro( Load, ImageMetricLoadType* );
549  itkGetConstMacro( Load, ImageMetricLoadType* );
550 
551 
552  void PrintSelf(std::ostream& os, Indent indent) const;
553 
554 private:
555 
556  void InitializeField();
557 
558  FEMRegistrationFilter(const Self&); //purposely not implemented
559  void operator=(const Self&); //purposely not implemented
560 
561  std::string m_ConfigFileName;
562  std::string m_ResultsFileName;
563  std::string m_MovingFileName; // This variable is currently not being used.
564  std::string m_FixedFileName; // This variable is currently not being used.
565  std::string m_LandmarkFileName;
567  std::string m_MeshFileName;
568 
571 
572  vnl_vector<unsigned int> m_NumberOfIntegrationPoints;// resolution of integration
573  vnl_vector<unsigned int> m_MetricWidth;
574  vnl_vector<unsigned int> m_Maxiters; // max iterations
575  unsigned int m_TotalIterations;
576  unsigned int m_NumLevels; // Number of Resolution Levels
577  unsigned int m_MaxLevel; // Maximum Level (NumLevels is original resolution).
578  unsigned int m_MeshLevels;// Number of Mesh Resolutions ( should be >= 1)
579  unsigned int m_MeshStep; // Ratio Between Mesh Resolutions ( currently set to 2, should be >= 1)
580  unsigned int m_FileCount; // keeps track of number of files written
581  unsigned int m_CurrentLevel;
582 
583  typename FixedImageType::SizeType m_CurrentLevelImageSize;
584 
585  unsigned int m_WhichMetric;
586 
589  vnl_vector<unsigned int> m_MeshPixelsPerElementAtEachResolution;
590 
591  Float m_Dt; // time step
592  vnl_vector<Float> m_E; // elasticity
593  vnl_vector<Float> m_Rho; // mass matrix weight
594  vnl_vector<Float> m_Gamma; // image similarity weight
595  Float m_Energy; // current value of energy
596  Float m_MinE; // minimum recorded energy
597  Float m_MinJacobian; // minimum recorded energy
598  Float m_Alpha; // difference parameter
602 
608  unsigned int m_EmployRegridding;
610 
619  // only use TotalField if re-gridding is employed.
621  ImageMetricLoadType* m_Load; // Defines the load to use
622 
623  // define the warper
625 
626  // declare a new image to hold the warped reference
627  typename FixedImageType::Pointer m_WarpedImage;
629  typename FixedImageType::RegionType m_Wregion;
630  typename FixedImageType::IndexType m_Windex;
631 
632  // declare images for target and reference
633  typename MovingImageType::Pointer m_MovingImage;
634  typename MovingImageType::Pointer m_OriginalMovingImage;
635  typename FixedImageType::Pointer m_FixedImage;
636 
637  // element and metric pointers
641 
644 
645 
646 
647 };
648 
649 }} // end namespace itk::fem
650 
651 #ifndef ITK_MANUAL_INSTANTIATION
653 #endif
654 
655 #endif

Generated at Sat May 18 2013 23:37:59 for Orfeo Toolbox with doxygen 1.8.3.1