Orfeo Toolbox  3.16
itkScalableAffineTransform.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkScalableAffineTransform.txx,v $
5  Language: C++
6  Date: $Date: 2010-03-30 15:20:02 $
7  Version: $Revision: 1.8 $
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 #ifndef __itkScalableAffineTransform_txx
18 #define __itkScalableAffineTransform_txx
19 
20 #include "itkNumericTraits.h"
22 #include "itkAffineTransform.h"
23 #include "vnl/algo/vnl_matrix_inverse.h"
24 
25 
26 namespace itk
27 {
28 
30 template<class TScalarType, unsigned int NDimensions>
33  : Superclass(Self::OutputSpaceDimension, Self::ParametersDimension)
34 {
35  for (unsigned int i=0; i<NDimensions; i++)
36  {
37  m_Scale[i] = 1;
38  m_MatrixScale[i] = 1;
39  }
40 }
41 
43 template<class TScalarType, unsigned int NDimensions>
45 ::ScalableAffineTransform( unsigned int outputSpaceDimension,
46  unsigned int parametersDimension )
47  : Superclass(outputSpaceDimension, parametersDimension)
48 {
49  for (unsigned int i=0; i<NDimensions; i++)
50  {
51  m_Scale[i] = 1;
52  m_MatrixScale[i] = 1;
53  }
54 }
55 
57 template<class TScalarType, unsigned int NDimensions>
60  const OutputVectorType & offset )
61  : Superclass(matrix, offset)
62 {
63  for (unsigned int i=0; i<NDimensions; i++)
64  {
65  m_Scale[i] = 1;
66  m_MatrixScale[i] = 1;
67  }
68 }
69 
71 template<class TScalarType, unsigned int NDimensions>
74 {
75  return;
76 }
77 
79 template<class TScalarType, unsigned int NDimensions>
80 void
82 ::PrintSelf(std::ostream &os, Indent indent) const
83 {
84  Superclass::PrintSelf(os,indent);
85 
86  unsigned int i;
87 
88  os << indent << "Scale : ";
89  for (i = 0; i < NDimensions; i++)
90  {
91  os << m_Scale[i] << " ";
92  }
93  os << std::endl;
94  os << indent << "MatrixScale : ";
95  for (i = 0; i < NDimensions; i++)
96  {
97  os << m_MatrixScale[i] << " ";
98  }
99  os << std::endl;
100 }
101 
102 
103 // Set the parameters in order to fit an Identity transform
104 template<class TScalarType, unsigned int NDimensions>
105 void
108 {
109  for (unsigned int i=0; i<NDimensions; i++)
110  {
111  m_Scale[i] = 1;
112  m_MatrixScale[i] = 1;
113  }
114  this->Superclass::SetIdentity();
115 }
116 
117 
119 template<class TScalarType, unsigned int NDimensions>
120 void
123 {
124  unsigned int i;
125  for (i=0; i<NDimensions; i++)
126  {
127  m_Scale[i] = scale[i];
128  }
129  this->ComputeMatrix();
130  this->Modified();
131 }
132 
133 template<class TScalarType, unsigned int NDimensions>
134 void
136 ::SetScale(const double scale[NDimensions] )
137 {
138  unsigned int i;
139  for (i=0; i<NDimensions; i++)
140  {
141  m_Scale[i] = scale[i];
142  }
143  this->ComputeMatrix();
144  this->Modified();
145 }
146 
147 // Get an inverse of this transform
148 template<class TScalarType, unsigned int NDimensions>
149 bool
151 ::GetInverse(Self* inverse) const
152 {
153  return this->Superclass::GetInverse(inverse);
154 }
155 
156 // Return an inverse of this transform
157 template<class TScalarType, unsigned int NDimensions>
159 ::InverseTransformBasePointer
162 {
163  Pointer inv = New();
164  return this->GetInverse(inv) ? inv.GetPointer() : NULL;
165 }
166 
168 template<class TScalarType, unsigned int NDimensions>
169 void
172 {
173  unsigned int i;
174  for (i=0; i<NDimensions; i++)
175  {
176  if(m_Scale[i] != m_MatrixScale[i])
177  {
178  break;
179  }
180  }
181  if ( i < NDimensions )
182  {
183  MatrixType mat;
184  typename MatrixType::InternalMatrixType & imat = mat.GetVnlMatrix();
185  for (i=0; i<NDimensions; i++)
186  {
187  if(m_MatrixScale[i] != 0 && m_Scale[i] != 0)
188  {
189  imat.put(i, i, m_Scale[i]/m_MatrixScale[i] * this->GetMatrix()[i][i]);
190  m_MatrixScale[i] = m_Scale[i];
191  }
192  else
193  {
194  m_Scale[i] = 1;
195  m_MatrixScale[i] = 1;
196  imat.put(i, i, this->GetMatrix()[i][i]);
197  }
198  }
199  Superclass::SetVarMatrix(mat);
200  }
201 }
202 
203 
204 } // namespace
205 
206 #endif

Generated at Sun Feb 3 2013 00:04:03 for Orfeo Toolbox with doxygen 1.8.1.1