MCPcopy Create free account
hub / github.com/ANTsX/ANTs / GetHomogeneousMatrix

Function GetHomogeneousMatrix

Examples/ConvertTransformFile.cxx:162–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160 */
161template <typename TTransform, typename TMatrix>
162bool
163GetHomogeneousMatrix(const typename TTransform::Pointer & transform, TMatrix & hMatrix, bool outputRAS)
164{
165 const unsigned int ImageDimension = TTransform::InputSpaceDimension;
166
167 using ScalarType = typename TTransform::ScalarType;
168
169 hMatrix.Fill(itk::NumericTraits<ScalarType>::ZeroValue());
170
171 bool done = false;
172
173 // Get the NxN matrix
174 typename TTransform::MatrixType matrix;
175 if (!GetMatrix<TTransform>(transform, matrix, outputRAS))
176 {
177 return false;
178 }
179 for (unsigned int i = 0; i < ImageDimension; i++)
180 {
181 for (unsigned int j = 0; j < ImageDimension; j++)
182 {
183 hMatrix(i, j) = matrix(i, j);
184 }
185 }
186
187 // Set the lower-right corner to 1
188 unsigned int corner = ImageDimension;
189 hMatrix(corner, corner) = itk::NumericTraits<typename TTransform::ScalarType>::OneValue();
190
191 //
192 // Get the offset
193 //
194
195 // Identity
196 {
197 using CastTransformType = itk::IdentityTransform<ScalarType, ImageDimension>;
198 typename CastTransformType::Pointer castTransform = dynamic_cast<CastTransformType *>(transform.GetPointer());
199
200 if (castTransform.IsNotNull())
201 {
202 // Nothing more to do here.
203 return true;
204 }
205 }
206
207 typename TTransform::OutputVectorType offset;
208 offset.Fill(itk::NumericTraits<typename TTransform::ScalarType>::ZeroValue());
209
210 // Matrix-offset derived
211 {
212 using CastTransformType = itk::MatrixOffsetTransformBase<ScalarType, ImageDimension, ImageDimension>;
213 typename CastTransformType::Pointer castTransform = dynamic_cast<CastTransformType *>(transform.GetPointer());
214
215 if (castTransform.IsNotNull())
216 {
217 offset = castTransform->GetOffset();
218 done = true;
219 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected