go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
elxElastixBase.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
28#ifndef elxElastixBase_h
29#define elxElastixBase_h
30
31#include "elxBaseComponent.h"
33#include "elxConfiguration.h"
34#include "elxMacro.h"
35#include "xoutmain.h"
36
37// ITK header files:
38#include <itkChangeInformationImageFilter.h>
39#include <itkDataObject.h>
40#include <itkImageFileReader.h>
41#include <itkObject.h>
42#include <itkTimeProbe.h>
43#include <itkVectorContainer.h>
44
45#include <fstream>
46#include <iomanip>
47
54#define elxGetObjectMacro(_name, _type) \
55 _type * Get##_name() const { return this->m_##_name.GetPointer(); }
56// end elxGetObjectMacro
57
58#define elxSetObjectMacro(_name, _type) \
59 void Set##_name(_type * _arg) \
60 { \
61 if (this->m_##_name != _arg) \
62 { \
63 this->m_##_name = _arg; \
64 this->itk::Object::Modified(); \
65 } \
66 }
67// end elxSetObjectMacro
68
70#define elxGetNumberOfMacro(_name) \
71 unsigned int GetNumberOf##_name##s() const \
72 { \
73 if (this->m_##_name##Container != nullptr) \
74 { \
75 return this->m_##_name##Container->Size(); \
76 } \
77 return 0; \
78 }
79// end elxGetNumberOfMacro
80
81namespace elastix
82{
144 : public itk::Object
145 , public BaseComponent
146{
147public:
149
153
156 using ObjectPointer = itk::Object::Pointer;
157 using DataObjectPointer = itk::DataObject::Pointer; // for the images
158 using ObjectContainerType = itk::VectorContainer<unsigned int, ObjectPointer>;
159 using ObjectContainerPointer = ObjectContainerType::Pointer;
160 using DataObjectContainerType = itk::VectorContainer<unsigned int, DataObjectPointer>;
161 using DataObjectContainerPointer = DataObjectContainerType::Pointer;
162 using FileNameContainerType = itk::VectorContainer<unsigned int, std::string>;
163 using FileNameContainerPointer = FileNameContainerType::Pointer;
164
166 using ResultImageType = itk::DataObject;
167
169 using ResultDeformationFieldType = itk::DataObject;
170
174 using FlatDirectionCosinesType = std::vector<double>;
175
177 using CoordRepType = double; // itk::CostFunction::ParametersValueType
178
181
185
187 void
189
192 {
193 return this->m_DBIndex;
194 }
195
200 elxGetObjectMacro(RegistrationContainer, ObjectContainerType);
201 elxGetObjectMacro(FixedImagePyramidContainer, ObjectContainerType);
202 elxGetObjectMacro(MovingImagePyramidContainer, ObjectContainerType);
203 elxGetObjectMacro(InterpolatorContainer, ObjectContainerType);
204 elxGetObjectMacro(ImageSamplerContainer, ObjectContainerType);
208 elxGetObjectMacro(ResampleInterpolatorContainer, ObjectContainerType);
210
215 elxSetObjectMacro(RegistrationContainer, ObjectContainerType);
216 elxSetObjectMacro(FixedImagePyramidContainer, ObjectContainerType);
217 elxSetObjectMacro(MovingImagePyramidContainer, ObjectContainerType);
218 elxSetObjectMacro(InterpolatorContainer, ObjectContainerType);
219 elxSetObjectMacro(ImageSamplerContainer, ObjectContainerType);
223 elxSetObjectMacro(ResampleInterpolatorContainer, ObjectContainerType);
225
231
237
241
243 elxGetObjectMacro(ResultDeformationFieldContainer, DataObjectContainerType);
244 elxSetObjectMacro(ResultDeformationFieldContainer, DataObjectContainerType);
245
249 elxGetObjectMacro(FixedImageFileNameContainer, FileNameContainerType);
250 elxGetObjectMacro(MovingImageFileNameContainer, FileNameContainerType);
251 elxSetObjectMacro(FixedImageFileNameContainer, FileNameContainerType);
252 elxSetObjectMacro(MovingImageFileNameContainer, FileNameContainerType);
253
257 elxGetObjectMacro(FixedMaskFileNameContainer, FileNameContainerType);
258 elxGetObjectMacro(MovingMaskFileNameContainer, FileNameContainerType);
259 elxSetObjectMacro(FixedMaskFileNameContainer, FileNameContainerType);
260 elxSetObjectMacro(MovingMaskFileNameContainer, FileNameContainerType);
261
263 elxGetNumberOfMacro(Registration);
264 elxGetNumberOfMacro(FixedImagePyramid);
265 elxGetNumberOfMacro(MovingImagePyramid);
266 elxGetNumberOfMacro(Interpolator);
267 elxGetNumberOfMacro(ImageSampler);
271 elxGetNumberOfMacro(ResampleInterpolator);
275 elxGetNumberOfMacro(FixedImageFileName);
276 elxGetNumberOfMacro(MovingImageFileName);
279 elxGetNumberOfMacro(FixedMaskFileName);
280 elxGetNumberOfMacro(MovingMaskFileName);
282 elxGetNumberOfMacro(ResultDeformationField);
283
288 elxSetObjectMacro(InitialTransform, itk::Object);
289 elxGetObjectMacro(InitialTransform, itk::Object);
290
297 elxSetObjectMacro(FinalTransform, itk::Object);
298 elxGetObjectMacro(FinalTransform, itk::Object);
299
301 virtual int
302 Run() = 0;
303
305 virtual int
306 ApplyTransform(bool doReadTransform) = 0;
307
311 int
312 BeforeAllBase() override;
313
317 int
319
323 void
325
327 GetResultImage(const unsigned int idx = 0) const;
328
329 void
331
333 GetResultDeformationField(unsigned int idx = 0) const;
334
335 void
337
338
343 int
345 {
346 return this->m_DefaultOutputPrecision;
347 }
348
349
353 bool
355
358 void
360
363
365 virtual void
367
371
373 void
374 SetConfigurations(const std::vector<ConfigurationPointer> & configurations);
375
378 GetConfiguration(const size_t index) const;
379
382 {
383 return m_IterationInfo;
384 }
385
387 GetIterationInfoAt(const char * const name)
388 {
389 return m_IterationInfo[name];
390 }
391
392 void
393 AddTargetCellToIterationInfo(const char * const name)
394 {
396 }
397
398protected:
400 ~ElastixBase() override = default;
401
404
406
408 itk::TimeProbe m_Timer0{};
409 itk::TimeProbe m_IterationTimer{};
410 itk::TimeProbe m_ResolutionTimer{};
411
414
416 std::vector<ConfigurationPointer> m_Configurations;
417
419 unsigned int m_IterationCounter{};
420
423
424 std::ofstream m_IterationInfoFile;
425
438 template <class TImage>
439 class ITK_TEMPLATE_EXPORT MultipleImageLoader
440 {
441 public:
442 using DirectionType = typename TImage::DirectionType;
443
445 GenerateImageContainer(const FileNameContainerType * const fileNameContainer,
446 const std::string & imageDescription,
447 bool useDirectionCosines,
448 DirectionType * originalDirectionCosines = nullptr)
449 {
450 const auto imageContainer = DataObjectContainerType::New();
451
453 for (const auto & fileName : *fileNameContainer)
454 {
455 const auto infoChanger = itk::ChangeInformationImageFilter<TImage>::New();
456 infoChanger->SetChangeDirection(!useDirectionCosines);
457
459 try
460 {
461 const auto image = itk::ReadImage<TImage>(fileName);
462 infoChanger->SetInput(image);
463 infoChanger->Update();
464
466 if (originalDirectionCosines != nullptr)
467 {
468 *originalDirectionCosines = image->GetDirection();
469 }
470 }
471 catch (itk::ExceptionObject & excp)
472 {
474 std::string err_str = excp.GetDescription();
475 err_str += "\nError occurred while reading the image described as " + imageDescription + ", with file name " +
476 fileName + "\n";
477 excp.SetDescription(err_str);
479 throw;
480 }
481
483 imageContainer->push_back(infoChanger->GetOutput());
484
485
486 } // end for
487
488 return imageContainer;
489
490 } // end static method GenerateImageContainer
491
492
495 };
496
500
501private:
503
506
512 ObjectContainerPointer m_InterpolatorContainer{ ObjectContainerType::New() };
513 ObjectContainerPointer m_ImageSamplerContainer{ ObjectContainerType::New() };
514 ObjectContainerPointer m_MetricContainer{ ObjectContainerType::New() };
515 ObjectContainerPointer m_OptimizerContainer{ ObjectContainerType::New() };
516 ObjectContainerPointer m_RegistrationContainer{ ObjectContainerType::New() };
517 ObjectContainerPointer m_ResamplerContainer{ ObjectContainerType::New() };
519 ObjectContainerPointer m_TransformContainer{ ObjectContainerType::New() };
520
522 DataObjectContainerPointer m_FixedImageContainer{ DataObjectContainerType::New() };
523 DataObjectContainerPointer m_MovingImageContainer{ DataObjectContainerType::New() };
524 DataObjectContainerPointer m_FixedMaskContainer{ DataObjectContainerType::New() };
525 DataObjectContainerPointer m_MovingMaskContainer{ DataObjectContainerType::New() };
526
528 DataObjectContainerPointer m_ResultImageContainer{ DataObjectContainerType::New() };
529
532
538
542
547};
548
549} // end namespace elastix
550
551#undef elxGetObjectMacro
552#undef elxSetObjectMacro
553#undef elxGetNumberOfMacro
554
555#endif // end #ifndef elxElastixBase_h
The BaseComponent class is a class that all elastix components should inherit from.
itk::SmartPointer< Self > Pointer
A class that deals with user given parameters and command line arguments.
itk::SmartPointer< Self > Pointer
typename TImage::DirectionType DirectionType
static DataObjectContainerPointer GenerateImageContainer(const FileNameContainerType *const fileNameContainer, const std::string &imageDescription, bool useDirectionCosines, DirectionType *originalDirectionCosines=nullptr)
This class creates an interface for elastix.
elxSetObjectMacro(FixedImageContainer, DataObjectContainerType)
itk::TimeProbe m_ResolutionTimer
itk::TimeProbe m_IterationTimer
elxSetObjectMacro(MetricContainer, ObjectContainerType)
itk::VectorContainer< unsigned int, DataObjectPointer > DataObjectContainerType
ITK_DISALLOW_COPY_AND_MOVE(ElastixBase)
DBIndexType GetDBIndex()
DataObjectContainerPointer m_FixedImageContainer
void AddTargetCellToIterationInfo(const char *const name)
std::vector< ConfigurationPointer > m_Configurations
elxGetObjectMacro(MovingImageFileNameContainer, FileNameContainerType)
elxGetObjectMacro(InitialTransform, itk::Object)
DataObjectContainerPointer m_MovingImageContainer
elxGetObjectMacro(FinalTransform, itk::Object)
ObjectContainerPointer m_RegistrationContainer
elxGetNumberOfMacro(MovingMaskFileName)
FileNameContainerPointer m_MovingMaskFileNameContainer
itk::DataObject::Pointer DataObjectPointer
static DataObjectContainerPointer GenerateDataObjectContainer(DataObjectPointer dataObject)
elxSetObjectMacro(ResultImageContainer, DataObjectContainerType)
elxSetObjectMacro(OptimizerContainer, ObjectContainerType)
xl::xoutrow & GetIterationInfo()
elxSetObjectMacro(RegistrationContainer, ObjectContainerType)
itk::VectorContainer< unsigned int, std::string > FileNameContainerType
elxGetObjectMacro(FixedImagePyramidContainer, ObjectContainerType)
elxGetObjectMacro(FixedMaskFileNameContainer, FileNameContainerType)
itk::DataObject ResultImageType
ObjectContainerPointer m_OptimizerContainer
ObjectContainerPointer m_ResampleInterpolatorContainer
elxGetNumberOfMacro(Transform)
FileNameContainerPointer m_FixedImageFileNameContainer
elxGetNumberOfMacro(FixedImage)
elxSetObjectMacro(ResamplerContainer, ObjectContainerType)
std::vector< double > FlatDirectionCosinesType
elxGetObjectMacro(MovingImageContainer, DataObjectContainerType)
void BeforeRegistrationBase() override
elxGetObjectMacro(TransformContainer, ObjectContainerType)
unsigned int m_IterationCounter
ConfigurationPointer m_Configuration
elxGetNumberOfMacro(MovingMask)
itk::VectorContainer< unsigned int, ObjectPointer > ObjectContainerType
elxGetNumberOfMacro(MovingImage)
DataObjectContainerPointer m_FixedMaskContainer
elxSetObjectMacro(MovingImageContainer, DataObjectContainerType)
elxSetObjectMacro(Configuration, Configuration)
elxGetNumberOfMacro(FixedImagePyramid)
virtual int Run()=0
elxSetObjectMacro(MovingImagePyramidContainer, ObjectContainerType)
elxGetNumberOfMacro(FixedMaskFileName)
elxGetObjectMacro(OptimizerContainer, ObjectContainerType)
elxGetNumberOfMacro(FixedMask)
itk::Object::Pointer ObjectPointer
DataObjectContainerType::Pointer DataObjectContainerPointer
elxGetObjectMacro(ImageSamplerContainer, ObjectContainerType)
void SetOriginalFixedImageDirectionFlat(const FlatDirectionCosinesType &arg)
void SetConfigurations(const std::vector< ConfigurationPointer > &configurations)
ObjectContainerPointer m_ResamplerContainer
void SetResultDeformationField(DataObjectPointer result_deformationfield)
elxGetObjectMacro(MovingMaskContainer, DataObjectContainerType)
elxGetObjectMacro(FixedImageContainer, DataObjectContainerType)
ObjectContainerPointer m_InterpolatorContainer
bool GetUseDirectionCosines() const
elxGetObjectMacro(ResampleInterpolatorContainer, ObjectContainerType)
elxSetObjectMacro(InitialTransform, itk::Object)
FlatDirectionCosinesType m_OriginalFixedImageDirection
elxGetObjectMacro(FixedImageFileNameContainer, FileNameContainerType)
elxSetObjectMacro(FixedImagePyramidContainer, ObjectContainerType)
DataObjectContainerPointer m_ResultImageContainer
elxSetObjectMacro(MovingMaskContainer, DataObjectContainerType)
elxGetNumberOfMacro(ResultImage)
elxGetNumberOfMacro(ResultDeformationField)
ConfigurationPointer GetConfiguration(const vcl_size_t index) const
DataObjectContainerPointer m_MovingMaskContainer
elxGetNumberOfMacro(ResampleInterpolator)
elxGetObjectMacro(RegistrationContainer, ObjectContainerType)
elxSetObjectMacro(ResampleInterpolatorContainer, ObjectContainerType)
elxGetNumberOfMacro(Interpolator)
elxSetObjectMacro(FinalTransform, itk::Object)
const FlatDirectionCosinesType & GetOriginalFixedImageDirectionFlat() const
xl::xoutrow m_IterationInfo
elxGetNumberOfMacro(MovingImageFileName)
elxSetObjectMacro(ImageSamplerContainer, ObjectContainerType)
void SetDBIndex(DBIndexType _arg)
std::string m_CurrentTransformParameterFileName
ResultDeformationFieldType * GetResultDeformationField(unsigned int idx=0) const
elxSetObjectMacro(MovingMaskFileNameContainer, FileNameContainerType)
ResultImageType * GetResultImage(const unsigned int idx=0) const
elxSetObjectMacro(MovingImageFileNameContainer, FileNameContainerType)
elxGetObjectMacro(InterpolatorContainer, ObjectContainerType)
ObjectContainerPointer m_FixedImagePyramidContainer
elxGetObjectMacro(MetricContainer, ObjectContainerType)
int GetDefaultOutputPrecision() const
elxGetObjectMacro(Configuration, Configuration)
int BeforeAllBase() override
virtual int ApplyTransform(bool doReadTransform)=0
elxGetNumberOfMacro(Resampler)
elxSetObjectMacro(InterpolatorContainer, ObjectContainerType)
ObjectPointer m_InitialTransform
xl::xoutbase & GetIterationInfoAt(const char *const name)
ObjectContainerPointer m_MovingImagePyramidContainer
elxGetObjectMacro(ResamplerContainer, ObjectContainerType)
elxSetObjectMacro(ResultDeformationFieldContainer, DataObjectContainerType)
elxSetObjectMacro(FixedMaskFileNameContainer, FileNameContainerType)
elxSetObjectMacro(FixedMaskContainer, DataObjectContainerType)
std::ofstream m_IterationInfoFile
elxGetNumberOfMacro(Optimizer)
itk::DataObject ResultDeformationFieldType
ObjectContainerPointer m_TransformContainer
ObjectContainerPointer m_MetricContainer
virtual void CreateTransformParametersMap()=0
ObjectContainerPointer m_ImageSamplerContainer
ParameterMapType m_TransformParametersMap
elxGetNumberOfMacro(Registration)
elxSetObjectMacro(TransformContainer, ObjectContainerType)
elxSetObjectMacro(FixedImageFileNameContainer, FileNameContainerType)
elxGetNumberOfMacro(MovingImagePyramid)
itk::ParameterMapInterface::ParameterMapType ParameterMapType
elxGetNumberOfMacro(ImageSampler)
void SetResultImage(DataObjectPointer result_image)
elxGetObjectMacro(ResultImageContainer, DataObjectContainerType)
elxGetObjectMacro(ResultDeformationFieldContainer, DataObjectContainerType)
~ElastixBase() override=default
elxGetObjectMacro(MovingMaskFileNameContainer, FileNameContainerType)
ObjectPointer m_FinalTransform
ParameterMapType GetTransformParametersMap() const
elxGetObjectMacro(MovingImagePyramidContainer, ObjectContainerType)
elxGetNumberOfMacro(FixedImageFileName)
Configuration::Pointer ConfigurationPointer
FileNameContainerType::Pointer FileNameContainerPointer
ObjectContainerType::Pointer ObjectContainerPointer
elxGetObjectMacro(FixedMaskContainer, DataObjectContainerType)
FileNameContainerPointer m_FixedMaskFileNameContainer
itk::TimeProbe m_Timer0
FileNameContainerPointer m_MovingImageFileNameContainer
DataObjectContainerPointer m_ResultDeformationFieldContainer
ComponentDatabase::Pointer ComponentDatabasePointer
ParameterFileParser::ParameterMapType ParameterMapType
Base class for xout.
Definition: xoutbase.h:40
The xoutrow class can easily generate tables.
Definition: xoutrow.h:43
int AddNewTargetCell(const char *name)


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