8 template <
class TScalarType>
14 m_LogScale = parameters[0];
15 m_LogFirstSkew = parameters[1];
16 m_LogSecondSkew = parameters[2];
17 m_UniqueTranslation = parameters[3];
19 this->ComputeMatrix();
24 template <
class TScalarType>
29 this->m_Parameters[0] = m_LogScale;
30 this->m_Parameters[1] = m_LogFirstSkew;
31 this->m_Parameters[2] = m_LogSecondSkew;
32 this->m_Parameters[3] = m_UniqueTranslation;
34 return this->m_Parameters;
37 template <
class TScalarType>
42 Superclass::SetIdentity();
44 m_UniqueTranslation = 0;
48 m_LogTransform.fill(itk::NumericTraits<TScalarType>::Zero);
49 m_ExpTransform.set_identity();
50 m_LogVector.Fill(itk::NumericTraits<TScalarType>::Zero);
53 template <
class TScalarType>
59 m_GeometryInv = m_Geometry.GetInverse();
62 this->ComputeMatrix();
65 template <
class TScalarType>
73 this->ComputeMatrix();
76 template <
class TScalarType>
81 m_LogFirstSkew = skew;
84 this->ComputeMatrix();
87 template <
class TScalarType>
92 m_LogSecondSkew = skew;
95 this->ComputeMatrix();
98 template <
class TScalarType>
103 m_UniqueTranslation = translation;
106 this->ComputeMatrix();
109 template <
class TScalarType>
114 m_UniqueDirection = direction;
115 this->ComputeMatrix();
119 template <
class TScalarType>
125 this->GetInternalLogarithm();
126 this->GetInternalExponential();
132 this->InternalApplyGeometry(linearMatrix,off);
134 this->SetMatrix(linearMatrix);
135 this->SetOffset(off);
137 m_LogVector.Fill(itk::NumericTraits<TScalarType>::Zero);
138 for (
unsigned int i = 0;i < 3;++i)
139 for (
unsigned int j = 0;j <= 3;++j)
140 m_LogVector[i * 4 + j] = m_LogTransform(i,j);
143 template <
class TScalarType>
149 for (
unsigned int i = 0;i < 3;++i)
150 offset[i] = m_Geometry(i,m_UniqueDirection) * m_UniqueTranslation;
152 for (
unsigned int j = 0;j < 3;++j)
155 for (
unsigned int k = 0;k < 3;++k)
156 aRinv += m_LogTransform(m_UniqueDirection,k) * m_GeometryInv(k,j);
158 for (
unsigned int i = 0;i < 3;++i)
159 linearMatrix(i,j) = aRinv * m_Geometry(i,m_UniqueDirection);
162 for (
unsigned int i = 0;i < 3;++i)
164 for (
unsigned int j = 0;j < 3;++j)
165 offset[i] -= linearMatrix(i,j) * m_Geometry(j,3);
167 m_LogTransform(i,3) = offset[i];
168 for (
unsigned int j = 0;j < 3;++j)
169 m_LogTransform(i,j) = linearMatrix(i,j);
173 for (
unsigned int i = 0;i < 3;++i)
174 offset[i] = m_Geometry(i,m_UniqueDirection) * m_ExpTransform(m_UniqueDirection,3) + m_Geometry(i,3);
176 for (
unsigned int j = 0;j < 3;++j)
179 for (
unsigned int k = 0;k < 3;++k)
180 aRinv += m_ExpTransform(m_UniqueDirection,k) * m_GeometryInv(k,j);
182 for (
unsigned int i = 0;i < 3;++i)
184 linearMatrix(i,j) = aRinv * m_Geometry(i,m_UniqueDirection);
185 for (
unsigned int k = 0;k < 3;++k)
187 if (k == m_UniqueDirection)
189 linearMatrix(i,j) += m_Geometry(i,k) * m_GeometryInv(k,j);
194 for (
unsigned int i = 0;i < 3;++i)
196 for (
unsigned int j = 0;j < 3;++j)
197 offset[i] -= linearMatrix(i,j) * m_Geometry(j,3);
199 m_ExpTransform(i,3) = offset[i];
200 for (
unsigned int j = 0;j < 3;++j)
201 m_ExpTransform(i,j) = linearMatrix(i,j);
205 template <
class TScalarType>
210 m_LogTransform.fill(0.0);
212 unsigned int skewLocation = 0;
213 if (m_UniqueDirection == skewLocation)
216 m_LogTransform(m_UniqueDirection,skewLocation) = m_LogFirstSkew;
218 if (m_UniqueDirection == skewLocation)
221 m_LogTransform(m_UniqueDirection,skewLocation) = m_LogSecondSkew;
223 m_LogTransform(m_UniqueDirection,m_UniqueDirection) = m_LogScale;
224 m_LogTransform(m_UniqueDirection,3) = m_UniqueTranslation;
227 template <
class TScalarType>
232 m_ExpTransform.set_identity();
234 unsigned int skewLocation = 0;
235 if (m_UniqueDirection == skewLocation)
238 double expFactor = 1.0;
239 if (m_LogScale != 0.0)
241 expFactor = std::exp(m_LogScale);
242 m_ExpTransform(m_UniqueDirection,skewLocation) = m_LogFirstSkew * (expFactor - 1.0) / m_LogScale;
245 m_ExpTransform(m_UniqueDirection,skewLocation) = m_LogFirstSkew;
248 if (m_UniqueDirection == skewLocation)
251 if (m_LogScale != 0.0)
252 m_ExpTransform(m_UniqueDirection,skewLocation) = m_LogSecondSkew * (expFactor - 1.0) / m_LogScale;
254 m_ExpTransform(m_UniqueDirection,skewLocation) = m_LogSecondSkew;
256 m_ExpTransform(m_UniqueDirection,m_UniqueDirection) = expFactor;
258 if (m_LogScale != 0.0)
259 m_ExpTransform(m_UniqueDirection,3) = m_UniqueTranslation * (expFactor - 1.0) / m_LogScale;
261 m_ExpTransform(m_UniqueDirection,3) = m_UniqueTranslation;
265 template<
class TScalarType>
270 Superclass::PrintSelf(os,indent);
272 os << indent <<
"Direction scale transform parameters: Log scale=" << m_LogScale
273 <<
" Log first skew=" << m_LogFirstSkew
274 <<
" Log second skew=" << m_LogSecondSkew
275 <<
" Log translation=" << m_UniqueTranslation
276 <<
" Transform direction=" << m_UniqueDirection
277 <<
" Geometry=" << m_Geometry
284 template <
class TScalarType>
290 this->SetLogScale(parameters[0],
false);
291 this->SetLogFirstSkew(0,
false);
292 this->SetLogSecondSkew(0,
false);
293 this->SetUniqueTranslation(parameters[1],
false);
295 this->ComputeMatrix();
299 template <
class TScalarType>
304 this->m_Parameters[0] = this->GetLogScale();
305 this->m_Parameters[1] = this->GetUniqueTranslation();
307 return this->m_Parameters;
310 template <
class TScalarType>
315 unsigned int uniqueDirection = this->GetUniqueDirection();
317 for (
unsigned int i = 0;i < 3;++i)
318 offset[i] = this->m_Geometry(i,uniqueDirection) * this->GetUniqueTranslation();
320 for (
unsigned int j = 0;j < 3;++j)
322 double aRinv = this->m_LogTransform(uniqueDirection,uniqueDirection) * this->m_GeometryInv(uniqueDirection,j);
324 for (
unsigned int i = 0;i < 3;++i)
325 linearMatrix(i,j) = aRinv * this->m_Geometry(i,uniqueDirection);
328 for (
unsigned int i = 0;i < 3;++i)
330 for (
unsigned int j = 0;j < 3;++j)
331 offset[i] -= linearMatrix(i,j) * this->m_Geometry(j,3);
333 this->m_LogTransform(i,3) = offset[i];
334 for (
unsigned int j = 0;j < 3;++j)
335 this->m_LogTransform(i,j) = linearMatrix(i,j);
339 for (
unsigned int i = 0;i < 3;++i)
340 offset[i] = this->m_Geometry(i,uniqueDirection) * this->m_ExpTransform(uniqueDirection,3) + this->m_Geometry(i,3);
342 for (
unsigned int j = 0;j < 3;++j)
344 double aRinv = this->m_ExpTransform(uniqueDirection,uniqueDirection) * this->m_GeometryInv(uniqueDirection,j);
346 for (
unsigned int i = 0;i < 3;++i)
348 linearMatrix(i,j) = aRinv * this->m_Geometry(i,uniqueDirection);
349 for (
unsigned int k = 0;k < 3;++k)
351 if (k == uniqueDirection)
353 linearMatrix(i,j) += this->m_Geometry(i,k) * this->m_GeometryInv(k,j);
358 for (
unsigned int i = 0;i < 3;++i)
360 for (
unsigned int j = 0;j < 3;++j)
361 offset[i] -= linearMatrix(i,j) * this->m_Geometry(j,3);
363 this->m_ExpTransform(i,3) = offset[i];
364 for (
unsigned int j = 0;j < 3;++j)
365 this->m_ExpTransform(i,j) = linearMatrix(i,j);
369 template <
class TScalarType>
374 this->m_LogTransform.fill(0.0);
376 unsigned int uniqueDirection = this->GetUniqueDirection();
377 this->m_LogTransform(uniqueDirection,uniqueDirection) = this->GetLogScale();
378 this->m_LogTransform(uniqueDirection,3) = this->GetUniqueTranslation();
381 template <
class TScalarType>
386 this->m_ExpTransform.set_identity();
388 double expFactor = 1.0;
389 double logScale = this->GetLogScale();
391 expFactor = std::exp(logScale);
393 unsigned int uniqueDirection = this->GetUniqueDirection();
394 this->m_ExpTransform(uniqueDirection,uniqueDirection) = expFactor;
397 this->m_ExpTransform(uniqueDirection,3) = this->GetUniqueTranslation() * (expFactor - 1.0) / logScale;
399 this->m_ExpTransform(uniqueDirection,3) = this->GetUniqueTranslation();
405 template <
class TScalarType>
411 this->SetLogScale(0,
false);
412 this->SetLogFirstSkew(0,
false);
413 this->SetLogSecondSkew(0,
false);
414 this->SetUniqueTranslation(parameters[0],
false);
416 this->ComputeMatrix();
420 template <
class TScalarType>
425 this->m_Parameters[0] = this->GetUniqueTranslation();
426 return this->m_Parameters;
429 template <
class TScalarType>
434 unsigned int uniqueDirection = this->GetUniqueDirection();
436 for (
unsigned int i = 0;i < 3;++i)
437 offset[i] = this->m_Geometry(i,uniqueDirection) * this->GetUniqueTranslation();
439 for (
unsigned int i = 0;i < 3;++i)
440 this->m_LogTransform(i,3) = offset[i];
443 for (
unsigned int i = 0;i < 3;++i)
444 offset[i] = this->m_Geometry(i,uniqueDirection) * this->m_ExpTransform(uniqueDirection,3);
446 linearMatrix.SetIdentity();
448 for (
unsigned int i = 0;i < 3;++i)
450 this->m_ExpTransform(i,3) = offset[i];
451 for (
unsigned int j = 0;j < 3;++j)
452 this->m_ExpTransform(i,j) = linearMatrix(i,j);
456 template <
class TScalarType>
461 this->m_LogTransform.fill(0.0);
462 this->m_LogTransform(this->GetUniqueDirection(),3) = this->GetUniqueTranslation();
465 template <
class TScalarType>
470 this->m_ExpTransform.set_identity();
471 this->m_ExpTransform(this->GetUniqueDirection(),3) = this->GetUniqueTranslation();