KWStyle - itkScalableAffineTransform.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkScalableAffineTransform.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:47 $
7   Version:   $Revision: 1.4 $
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 DEF #ifndef _itkScalableAffineTransform_txx
18 DEF #define _itkScalableAffineTransform_txx
19
20 #include "itkNumericTraits.h"
21 #include "itkScalableAffineTransform.h"
22 #include "itkAffineTransform.h"
23 #include "vnl/algo/vnl_matrix_inverse.h"
24
25
26 namespace itk
27 {
28
29 /** Constructor with default arguments */
30 template<class TScalarType, unsigned int NDimensions>
31 ScalableAffineTransform<TScalarType, NDimensions>
32 ::ScalableAffineTransform()
33 IND **: 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
42 /** Constructor with default arguments */
43 template<class TScalarType, unsigned int NDimensions>
44 ScalableAffineTransform<TScalarType, NDimensions>
45 ::ScalableAffineTransform( unsigned int outputSpaceDimension,
46                            unsigned int parametersDimension )
47 IND **: 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
56 /** Constructor with default arguments */
57 template<class TScalarType, unsigned int NDimensions>
58 ScalableAffineTransform<TScalarType, NDimensions>
59 ::ScalableAffineTransform( const MatrixType & matrix,
60                            const OutputVectorType & offset )
61 IND **: 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
70 /** Destructor */
71 template<class TScalarType, unsigned int NDimensions>
72 ScalableAffineTransform<TScalarType, NDimensions>
73 ::~ScalableAffineTransform()
74 {
75   return;
76 }
77
78 /** Print self */
79 template<class TScalarType, unsigned int NDimensions>
80 void
81 ScalableAffineTransform<TScalarType, NDimensions>
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
106 ScalableAffineTransform<TScalarType, NDimensions>
107 ::SetIdentity( 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
118 /** Set the scale of the transformation */
119 template<class TScalarType, unsigned int NDimensions>
120 void
121 ScalableAffineTransform<TScalarType, NDimensions>
122 ::SetScale(const InputVectorType & scale )
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
135 ScalableAffineTransform<TScalarType, NDimensions>
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
148 /** Set the scale of the transformation */
149 template<class TScalarType, unsigned int NDimensions>
150 void
151 ScalableAffineTransform<TScalarType, NDimensions>
152 ::ComputeMatrix()
153 {
154   unsigned int i; 
155   for (i=0; i<NDimensions; i++)
156     {
157     if(m_Scale[i] != m_MatrixScale[i])
158       {
159       break;
160       }
161     }
162   if ( i < NDimensions ) 
163     { 
164     MatrixType mat;
165     for (i=0; i<NDimensions; i++)
166       {
167       if(m_MatrixScale[i] != 0 && m_Scale[i] != 0)
168         {
169         mat.GetVnlMatrix().put(i, i, m_Scale[i]/m_MatrixScale[i]
170                                      * this->GetMatrix()[i][i]);
171         m_MatrixScale[i] = m_Scale[i];
172         }
173       else
174         {
175         m_Scale[i] = 1;
176         m_MatrixScale[i] = 1;
177         mat.GetVnlMatrix().put(i, i, this->GetMatrix()[i][i]);
178         }
179       }
180     Superclass::SetVarMatrix(mat);
181     }
182 }
183
184
185 // namespace
186
187 #endif
188

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:42PM
© Kitware Inc.