go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
elxTransformBase.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright UMC Utrecht and contributors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef elxTransformBase_h
19#define elxTransformBase_h
20
22#include "elxMacro.h"
23
24#include "elxBaseComponentSE.h"
25#include "elxDefaultConstruct.h"
26#include "elxElastixBase.h"
30#include "elxProgressCommand.h"
31
32// ITK header files:
33#include <itkImage.h>
34#include <itkOptimizerParameters.h>
35#include <itkTransformMeshFilter.h>
36
37
38namespace elastix
39{
40// using namespace itk; //Not here, because a TransformBase class was added to ITK...
41
133template <class TElastix>
134class ITK_TEMPLATE_EXPORT TransformBase : public BaseComponentSE<TElastix>
135{
136public:
138
142
145
147 using typename Superclass::RegistrationType;
148
149 using CommandLineArgumentMapType = Configuration ::CommandLineArgumentMapType;
150 using CommandLineEntryType = Configuration ::CommandLineEntryType;
151
154 using FixedImageType = typename TElastix::FixedImageType;
155 using MovingImageType = typename TElastix::MovingImageType;
156
160
163
165 itkStaticConstMacro(FixedImageDimension, unsigned int, FixedImageType::ImageDimension);
166
168 itkStaticConstMacro(MovingImageDimension, unsigned int, MovingImageType::ImageDimension);
169
174
177 using ParametersType = itk::OptimizerParameters<ValueType>;
178
180 using InputPointType = typename ITKBaseType::InputPointType;
181 using OutputPointType = typename ITKBaseType::OutputPointType;
182
184 using VectorPixelType = itk::Vector<float, FixedImageDimension>;
185 using DeformationFieldImageType = itk::Image<VectorPixelType, FixedImageDimension>;
186
188 using ITKRegistrationType = typename RegistrationType::ITKBaseType;
189 using OptimizerType = typename ITKRegistrationType::OptimizerType;
190 using ScalesType = typename OptimizerType::ScalesType;
191
193 using SpatialJacobianDeterminantImageType = itk::Image<float, FixedImageDimension>;
195 itk::Image<itk::Matrix<float, MovingImageDimension, FixedImageDimension>, FixedImageDimension>;
196
197
199 using ParameterMapType = typename TElastix::ParameterMapType;
200
204 {
205 return &(this->GetSelf());
206 }
207
208
210 const ITKBaseType *
212 {
213 return &(this->GetSelf());
214 }
215
219 int
221
223 void
225
227 void
228 SetTransformParametersFileName(const char * filename);
229
231 virtual void
233
235 void
237 ParameterMapType & parameterMap,
238 const bool includeDerivedTransformParameters = true) const;
239
241 void
242 WriteToFile(xl::xoutsimple & transformationParameterInfo, const ParametersType & param) const;
243
245 void
247
249 void
250 ReadInitialTransformFromFile(const char * transformParameterFileName);
251
253 void
255
257 typename SpatialJacobianDeterminantImageType::Pointer
259
261 typename SpatialJacobianMatrixImageType::Pointer
263
265 void
267
269 void
271
275 void
277
280 template <typename TMesh>
281 typename TMesh::Pointer
282 TransformMesh(const TMesh & mesh) const
283 {
285 transformMeshFilter.SetTransform(&const_cast<CombinationTransformType &>(this->GetSelf()));
286 transformMeshFilter.SetInput(&mesh);
287 transformMeshFilter.Update();
288 return transformMeshFilter.GetOutput();
289 }
290
291protected:
293 TransformBase() = default;
295 ~TransformBase() override = default;
296
298 bool
300 {
301 return this->BaseComponentSE<TElastix>::m_Configuration->HasParameter("ITKTransformParameters");
302 }
303
310 void
312
320 void
321 AutomaticScalesEstimationStackTransform(const unsigned int numSubTransforms, ScalesType & scales) const;
322
323private:
325
327 template <template <typename, typename> class TSource, typename TOutputImage>
328 auto
330 {
331 const auto & resampleImageFilter = *(this->m_Elastix->GetElxResamplerBase()->GetAsITKBaseType());
332
334 const auto jacGenerator = TSource<TOutputImage, CoordRepType>::New();
335
336 jacGenerator->SetTransform(this->GetAsITKBaseType());
337 jacGenerator->SetOutputSize(resampleImageFilter.GetSize());
338 jacGenerator->SetOutputSpacing(resampleImageFilter.GetOutputSpacing());
339 jacGenerator->SetOutputOrigin(resampleImageFilter.GetOutputOrigin());
340 jacGenerator->SetOutputIndex(resampleImageFilter.GetOutputStartIndex());
341 jacGenerator->SetOutputDirection(resampleImageFilter.GetOutputDirection());
342 // NOTE: We can not use the following, since the fixed image does not exist in transformix
343 // jacGenerator->SetOutputParametersFromImage(
344 // this->GetRegistration()->GetAsITKBaseType()->GetFixedImage() );
345
346 return jacGenerator;
347 }
348
349
351 template <typename TImage>
352 auto
354 {
358 const auto infoChanger = itk::ChangeInformationImageFilter<TImage>::New();
359 typename FixedImageType::DirectionType originalDirection;
360 const bool retdc = this->m_Elastix->GetOriginalFixedImageDirection(originalDirection);
361 infoChanger->SetOutputDirection(originalDirection);
362 infoChanger->SetChangeDirection(retdc & !this->m_Elastix->GetUseDirectionCosines());
363 infoChanger->SetInput(image);
364
365 return infoChanger;
366 }
367
368
371 void
373
377 int
378 BeforeAllBase() override;
379
383 void
385
389 void
391
395
397 itkGetStringMacro(TransformParametersFileName);
398
400 void
401 TransformPointsSomePoints(const std::string & filename) const;
402
404 void
405 TransformPointsSomePointsVTK(const std::string & filename) const;
406
415 typename DeformationFieldImageType::Pointer
417
418 void WriteDeformationFieldImage(typename DeformationFieldImageType::Pointer) const;
419
421 void
423
424 std::string
426 {
427 if (!this->GetInitialTransform())
428 {
429 return "NoInitialTransform";
430 }
431
432 const Self * t0 = dynamic_cast<const Self *>(this->GetInitialTransform());
434 }
435
436 virtual ParameterMapType
438
440 virtual void
442 {}
443
448
450 bool m_ReadWriteTransformParameters{ true };
451};
452
453} // end namespace elastix
454
455#ifndef ITK_MANUAL_INSTANTIATION
456# include "elxTransformBase.hxx"
457#endif
458
459#endif // end #ifndef elxTransformBase_h
The BaseComponentSE class is a base class for elastix components that provides some basic functionali...
typename ElastixType::RegistrationBaseType RegistrationType
itk::SmartPointer< Self > Pointer
A specialized Command object for updating the progress of a filter.
This class is the elastix base class for all Transforms.
TMesh::Pointer TransformMesh(const TMesh &mesh) const
const ITKBaseType * GetAsITKBaseType() const
void CreateTransformParametersMap(const ParametersType &param, ParameterMapType &parameterMap, const bool includeDerivedTransformParameters=true) const
typename TElastix::FixedImageType FixedImageType
typename RegistrationType::ITKBaseType ITKRegistrationType
void SetInitialTransform(InitialTransformType *_arg)
ParametersType m_TransformParameters
ITKBaseType * GetAsITKBaseType()
void ReadInitialTransformFromConfiguration(const Configuration::Pointer)
void TransformPointsSomePointsVTK(const std::string &filename) const
DeformationFieldImageType::Pointer GenerateDeformationFieldImage() const
virtual const char * GetTransformParametersFileName() const
itk::Image< float, FixedImageDimension > SpatialJacobianDeterminantImageType
typename OptimizerType::ScalesType ScalesType
SpatialJacobianDeterminantImageType::Pointer ComputeSpatialJacobianDeterminantImage() const
virtual ParameterMapType CreateDerivedTransformParametersMap() const =0
itk::Image< VectorPixelType, FixedImageDimension > DeformationFieldImageType
void TransformPoints() const
typename ITKBaseType::OutputPointType OutputPointType
void AutomaticScalesEstimation(ScalesType &scales) const
void SetReadWriteTransformParameters(const bool _arg)
void ReadInitialTransformFromFile(const char *transformParameterFileName)
itk::Image< itk::Matrix< float, MovingImageDimension, FixedImageDimension >, FixedImageDimension > SpatialJacobianMatrixImageType
typename ITKRegistrationType::OptimizerType OptimizerType
typename TElastix::ParameterMapType ParameterMapType
void TransformPointsAllPoints() const
ParametersType m_FinalParameters
ITK_DISALLOW_COPY_AND_MOVE(TransformBase)
void SetTransformParametersFileName(const char *filename)
typename TElastix::MovingImageType MovingImageType
void ComputeAndWriteSpatialJacobianMatrixImage() const
void WriteToFile(xl::xoutsimple &transformationParameterInfo, const ParametersType &param) const
SpatialJacobianMatrixImageType::Pointer ComputeSpatialJacobianMatrixImage() const
auto CreateChangeInformationImageFilter(TImage *image) const
std::string m_TransformParametersFileName
typename ITKBaseType::InputPointType InputPointType
elxDeclarePureVirtualGetSelfMacro(ITKBaseType)
itkStaticConstMacro(FixedImageDimension, unsigned int, FixedImageType::ImageDimension)
typename CombinationTransformType::InitialTransformType InitialTransformType
Configuration ::CommandLineArgumentMapType CommandLineArgumentMapType
void ComputeAndWriteSpatialJacobianDeterminantImage() const
virtual void ReadFromFile()
Configuration ::CommandLineEntryType CommandLineEntryType
auto CreateJacobianSource() const
void TransformPointsSomePoints(const std::string &filename) const
virtual void WriteDerivedTransformDataToFile() const
void AfterRegistrationBase() override
void WriteDeformationFieldImage(typename DeformationFieldImageType::Pointer) const
itkStaticConstMacro(MovingImageDimension, unsigned int, MovingImageType::ImageDimension)
ComponentDatabase::ComponentDescriptionType ComponentDescriptionType
bool HasITKTransformParameters() const
std::string GetInitialTransformParametersFileName() const
const InitialTransformType * GetInitialTransform() const
itk::Vector< float, FixedImageDimension > VectorPixelType
void AutomaticScalesEstimationStackTransform(const unsigned int numSubTransforms, ScalesType &scales) const
ComponentDatabase::PtrToCreator PtrToCreator
~TransformBase() override=default
itk::OptimizerParameters< ValueType > ParametersType
int BeforeAllBase() override
void BeforeRegistrationBase() override
This class combines two transforms: an 'initial transform' with a 'current transform'.
xout class with only basic functionality.
Definition: xoutsimple.h:36


Generated on 2023-01-13 for elastix by doxygen 1.9.6 elastix logo