ANIMA  4.0
animaBaseOrientedModelImageToImageMetric.hxx
Go to the documentation of this file.
1 #pragma once
3 
4 #include <animaBaseTensorTools.h>
5 
6 namespace anima
7 {
8 
12 template <class TFixedImage, class TMovingImage>
15 {
16  m_FixedImage = 0; // has to be provided by the user.
17  m_MovingImage = 0; // has to be provided by the user.
18  m_Transform = 0; // has to be provided by the user.
19  m_Interpolator = 0; // has to be provided by the user.
20  m_NumberOfPixelsCounted = 0; // initialize to zero
21 
22  m_ModelRotation = FINITE_STRAIN;
23  m_OrientationMatrix.set_size(FixedImageDimension,FixedImageDimension);
24 }
25 
29 template <class TFixedImage, class TMovingImage>
32 {
33 
34 }
35 
36 
40 template <class TFixedImage, class TMovingImage>
41 void
43 ::SetTransformParameters( const ParametersType & parameters ) const
44 {
45  if( !m_Transform )
46  {
47  itkExceptionMacro(<<"Transform has not been assigned");
48  }
49  m_Transform->SetParameters( parameters );
50 
51  if (m_ModelRotation != NONE)
52  {
53  typedef itk::MatrixOffsetTransformBase <CoordinateRepresentationType, FixedImageDimension, FixedImageDimension> BaseTransformType;
54  BaseTransformType *currentTrsf = dynamic_cast<BaseTransformType *> (this->m_Transform.GetPointer());
55  vnl_matrix <double> jacMatrix = currentTrsf->GetMatrix().GetVnlMatrix().as_matrix();
56 
57  if (m_ModelRotation == FINITE_STRAIN)
58  {
59  vnl_matrix <double> tmpMat(FixedImageDimension, FixedImageDimension);
60  anima::ExtractRotationFromJacobianMatrix(jacMatrix,m_OrientationMatrix,tmpMat);
61  }
62  else
63  m_OrientationMatrix = jacMatrix;
64  }
65 }
66 
67 
71 template <class TFixedImage, class TMovingImage>
72 void
75 {
76 
77  if( !m_Transform )
78  {
79  itkExceptionMacro(<<"Transform is not present");
80  }
81 
82  if( !m_Interpolator )
83  {
84  itkExceptionMacro(<<"Interpolator is not present");
85  }
86 
87  if( !m_MovingImage )
88  {
89  itkExceptionMacro(<<"MovingImage is not present");
90  }
91 
92  if( !m_FixedImage )
93  {
94  itkExceptionMacro(<<"FixedImage is not present");
95  }
96 
97  if( m_FixedImageRegion.GetNumberOfPixels() == 0 )
98  {
99  itkExceptionMacro(<<"FixedImageRegion is empty");
100  }
101 
102  // If the image is provided by a source, update the source.
103  if( m_MovingImage->GetSource() )
104  {
105  m_MovingImage->GetSource()->Update();
106  }
107 
108  // If the image is provided by a source, update the source.
109  if( m_FixedImage->GetSource() )
110  {
111  m_FixedImage->GetSource()->Update();
112  }
113 
114  // Make sure the FixedImageRegion is within the FixedImage buffered region
115  if ( !m_FixedImageRegion.Crop( m_FixedImage->GetBufferedRegion() ) )
116  {
117  itkExceptionMacro(
118  <<"FixedImageRegion does not overlap the fixed image buffered region" );
119  }
120 
121  m_Interpolator->SetInputImage( m_MovingImage );
122 
123  // If there are any observers on the metric, call them to give the
124  // user code a chance to set parameters on the metric
125  this->InvokeEvent( itk::InitializeEvent() );
126 }
127 
128 
132 template <class TFixedImage, class TMovingImage>
133 void
135 ::PrintSelf(std::ostream& os, itk::Indent indent) const
136 {
137  Superclass::PrintSelf( os, indent );
138  os << indent << "Moving Image: " << m_MovingImage.GetPointer() << std::endl;
139  os << indent << "Fixed Image: " << m_FixedImage.GetPointer() << std::endl;
140  os << indent << "Transform: " << m_Transform.GetPointer() << std::endl;
141  os << indent << "Interpolator: " << m_Interpolator.GetPointer() << std::endl;
142  os << indent << "FixedImageRegion: " << m_FixedImageRegion << std::endl;
143  os << indent << "Moving Image Mask: " << m_MovingImageMask.GetPointer()
144  << std::endl;
145  os << indent << "Fixed Image Mask: " << m_FixedImageMask.GetPointer()
146  << std::endl;
147  os << indent << "Number of Pixels Counted: " << m_NumberOfPixelsCounted
148  << std::endl;
149 
150 }
151 
152 } // end of namespace anima
void ExtractRotationFromJacobianMatrix(vnl_matrix< RealType > &jacobianMatrix, vnl_matrix< RealType > &rotationMatrix, vnl_matrix< RealType > &tmpMat)
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
void SetTransformParameters(const ParametersType &parameters) const