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 "elxIterationInfo.h"
35#include "elxMacro.h"
36#include "elxlog.h"
37
38// ITK header files:
39#include <itkChangeInformationImageFilter.h>
40#include <itkDataObject.h>
41#include <itkImageFileReader.h>
42#include <itkObject.h>
43#include <itkTimeProbe.h>
44#include <itkVectorContainer.h>
45
46#include <fstream>
47#include <iomanip>
48
55#define elxGetObjectMacro(_name, _type) \
56 _type * Get##_name() const { return m_##_name.GetPointer(); }
57// end elxGetObjectMacro
58
59#define elxSetObjectMacro(_name, _type) \
60 void Set##_name(_type * _arg) \
61 { \
62 if (m_##_name != _arg) \
63 { \
64 m_##_name = _arg; \
65 this->itk::Object::Modified(); \
66 } \
67 }
68// end elxSetObjectMacro
69
71#define elxGetNumberOfMacro(_name) \
72 unsigned int GetNumberOf##_name##s() const \
73 { \
74 if (m_##_name##Container != nullptr) \
75 { \
76 return m_##_name##Container->Size(); \
77 } \
78 return 0; \
79 }
80// end elxGetNumberOfMacro
81
82namespace elastix
83{
141 : public itk::Object
142 , public BaseComponent
143{
144public:
146
150
152 using ObjectPointer = itk::Object::Pointer;
153 using DataObjectPointer = itk::DataObject::Pointer; // for the images
154 using ObjectContainerType = itk::VectorContainer<unsigned int, ObjectPointer>;
155 using ObjectContainerPointer = ObjectContainerType::Pointer;
156 using DataObjectContainerType = itk::VectorContainer<unsigned int, DataObjectPointer>;
157 using DataObjectContainerPointer = DataObjectContainerType::Pointer;
158 using FileNameContainerType = itk::VectorContainer<unsigned int, std::string>;
159 using FileNameContainerPointer = FileNameContainerType::Pointer;
160
162 using ResultImageType = itk::DataObject;
163
165 using ResultDeformationFieldType = itk::DataObject;
166
170 using FlatDirectionCosinesType = std::vector<double>;
171
173 using CoordRepType = double; // itk::CostFunction::ParametersValueType
174
177
181
183 void
185
188 {
189 return m_DBIndex;
190 }
191
196 elxGetObjectMacro(RegistrationContainer, ObjectContainerType);
197 elxGetObjectMacro(FixedImagePyramidContainer, ObjectContainerType);
198 elxGetObjectMacro(MovingImagePyramidContainer, ObjectContainerType);
199 elxGetObjectMacro(InterpolatorContainer, ObjectContainerType);
200 elxGetObjectMacro(ImageSamplerContainer, ObjectContainerType);
204 elxGetObjectMacro(ResampleInterpolatorContainer, ObjectContainerType);
206
211 elxSetObjectMacro(RegistrationContainer, ObjectContainerType);
212 elxSetObjectMacro(FixedImagePyramidContainer, ObjectContainerType);
213 elxSetObjectMacro(MovingImagePyramidContainer, ObjectContainerType);
214 elxSetObjectMacro(InterpolatorContainer, ObjectContainerType);
215 elxSetObjectMacro(ImageSamplerContainer, ObjectContainerType);
219 elxSetObjectMacro(ResampleInterpolatorContainer, ObjectContainerType);
221
227
233
237
239 elxGetObjectMacro(ResultDeformationFieldContainer, DataObjectContainerType);
240 elxSetObjectMacro(ResultDeformationFieldContainer, DataObjectContainerType);
241
245 elxGetObjectMacro(FixedImageFileNameContainer, FileNameContainerType);
246 elxGetObjectMacro(MovingImageFileNameContainer, FileNameContainerType);
247 elxSetObjectMacro(FixedImageFileNameContainer, FileNameContainerType);
248 elxSetObjectMacro(MovingImageFileNameContainer, FileNameContainerType);
249
253 elxGetObjectMacro(FixedMaskFileNameContainer, FileNameContainerType);
254 elxGetObjectMacro(MovingMaskFileNameContainer, FileNameContainerType);
255 elxSetObjectMacro(FixedMaskFileNameContainer, FileNameContainerType);
256 elxSetObjectMacro(MovingMaskFileNameContainer, FileNameContainerType);
257
259 elxGetNumberOfMacro(Registration);
260 elxGetNumberOfMacro(FixedImagePyramid);
261 elxGetNumberOfMacro(MovingImagePyramid);
262 elxGetNumberOfMacro(Interpolator);
263 elxGetNumberOfMacro(ImageSampler);
267 elxGetNumberOfMacro(ResampleInterpolator);
271 elxGetNumberOfMacro(FixedImageFileName);
272 elxGetNumberOfMacro(MovingImageFileName);
275 elxGetNumberOfMacro(FixedMaskFileName);
276 elxGetNumberOfMacro(MovingMaskFileName);
278 elxGetNumberOfMacro(ResultDeformationField);
279
284 elxSetObjectMacro(InitialTransform, itk::Object);
285 elxGetObjectMacro(InitialTransform, itk::Object);
286
293 elxSetObjectMacro(FinalTransform, itk::Object);
294 elxGetObjectMacro(FinalTransform, itk::Object);
295
297 virtual int
298 Run() = 0;
299
301 virtual int
302 ApplyTransform(bool doReadTransform) = 0;
303
307 int
308 BeforeAllBase() override;
309
313 int
315
317 GetResultImage(const unsigned int idx = 0) const;
318
319 void
321
323 GetResultDeformationField(unsigned int idx = 0) const;
324
325 void
327
328
332 bool
334
337 void
339
342
344 virtual void
346
350
352 void
353 SetTransformConfigurations(const std::vector<Configuration::ConstPointer> & configurations);
354
357 GetTransformConfiguration(const size_t index) const;
358
363
365 size_t
367
370 {
371 return m_IterationInfo;
372 }
373
374 std::ostream &
375 GetIterationInfoAt(const char * const name)
376 {
377 return m_IterationInfo[name];
378 }
379
380 void
381 AddTargetCellToIterationInfo(const char * const name)
382 {
384 }
385
386protected:
388 ~ElastixBase() override = default;
389
391
393
395 itk::TimeProbe m_Timer0{};
396 itk::TimeProbe m_IterationTimer{};
397 itk::TimeProbe m_ResolutionTimer{};
398
401
403 unsigned int m_IterationCounter{};
404
407
408 std::ofstream m_IterationInfoFile;
409
422 template <class TImage>
423 class ITK_TEMPLATE_EXPORT MultipleImageLoader
424 {
425 public:
426 using DirectionType = typename TImage::DirectionType;
427
429 GenerateImageContainer(const FileNameContainerType * const fileNameContainer,
430 const std::string & imageDescription,
431 bool useDirectionCosines,
432 DirectionType * originalDirectionCosines = nullptr)
433 {
434 const auto imageContainer = DataObjectContainerType::New();
435
437 for (const auto & fileName : *fileNameContainer)
438 {
439 const auto infoChanger = itk::ChangeInformationImageFilter<TImage>::New();
440 infoChanger->SetChangeDirection(!useDirectionCosines);
441
443 try
444 {
445 const auto image = itk::ReadImage<TImage>(fileName);
446 infoChanger->SetInput(image);
447 infoChanger->Update();
448
450 if (originalDirectionCosines != nullptr)
451 {
452 *originalDirectionCosines = image->GetDirection();
453 }
454 }
455 catch (itk::ExceptionObject & excp)
456 {
458 std::string err_str = excp.GetDescription();
459 err_str += "\nError occurred while reading the image described as " + imageDescription + ", with file name " +
460 fileName + "\n";
461 excp.SetDescription(err_str);
463 throw;
464 }
465
467 imageContainer->push_back(infoChanger->GetOutput());
468
469
470 } // end for
471
472 return imageContainer;
473
474 } // end static method GenerateImageContainer
475
476
479 };
480
484
485private:
487
489 std::vector<Configuration::ConstPointer> m_TransformConfigurations;
490
492
498 ObjectContainerPointer m_InterpolatorContainer{ ObjectContainerType::New() };
499 ObjectContainerPointer m_ImageSamplerContainer{ ObjectContainerType::New() };
500 ObjectContainerPointer m_MetricContainer{ ObjectContainerType::New() };
501 ObjectContainerPointer m_OptimizerContainer{ ObjectContainerType::New() };
502 ObjectContainerPointer m_RegistrationContainer{ ObjectContainerType::New() };
503 ObjectContainerPointer m_ResamplerContainer{ ObjectContainerType::New() };
505 ObjectContainerPointer m_TransformContainer{ ObjectContainerType::New() };
506
508 DataObjectContainerPointer m_FixedImageContainer{ DataObjectContainerType::New() };
509 DataObjectContainerPointer m_MovingImageContainer{ DataObjectContainerType::New() };
510 DataObjectContainerPointer m_FixedMaskContainer{ DataObjectContainerType::New() };
511 DataObjectContainerPointer m_MovingMaskContainer{ DataObjectContainerType::New() };
512
514 DataObjectContainerPointer m_ResultImageContainer{ DataObjectContainerType::New() };
515
518
524
528
533};
534
535} // end namespace elastix
536
537#undef elxGetObjectMacro
538#undef elxSetObjectMacro
539#undef elxGetNumberOfMacro
540
541#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
itk::SmartPointer< const Self > ConstPointer
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)
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)
Configuration::Pointer m_Configuration
elxSetObjectMacro(ResultImageContainer, DataObjectContainerType)
elxSetObjectMacro(OptimizerContainer, ObjectContainerType)
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)
elxGetObjectMacro(TransformContainer, ObjectContainerType)
unsigned int m_IterationCounter
vcl_size_t GetNumberOfTransformConfigurations() const
elxGetNumberOfMacro(MovingMask)
itk::VectorContainer< unsigned int, ObjectPointer > ObjectContainerType
elxGetNumberOfMacro(MovingImage)
DataObjectContainerPointer m_FixedMaskContainer
elxSetObjectMacro(MovingImageContainer, DataObjectContainerType)
elxSetObjectMacro(Configuration, Configuration)
elxGetNumberOfMacro(FixedImagePyramid)
Configuration::ConstPointer GetTransformConfiguration(const vcl_size_t index) const
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)
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)
DataObjectContainerPointer m_MovingMaskContainer
elxGetNumberOfMacro(ResampleInterpolator)
elxGetObjectMacro(RegistrationContainer, ObjectContainerType)
elxSetObjectMacro(ResampleInterpolatorContainer, ObjectContainerType)
elxGetNumberOfMacro(Interpolator)
elxSetObjectMacro(FinalTransform, itk::Object)
const FlatDirectionCosinesType & GetOriginalFixedImageDirectionFlat() const
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)
elxGetObjectMacro(Configuration, Configuration)
int BeforeAllBase() override
virtual int ApplyTransform(bool doReadTransform)=0
elxGetNumberOfMacro(Resampler)
elxSetObjectMacro(InterpolatorContainer, ObjectContainerType)
ObjectPointer m_InitialTransform
std::vector< Configuration::ConstPointer > m_TransformConfigurations
Configuration::ConstPointer GetPreviousTransformConfiguration(const Configuration &configuration) const
ObjectContainerPointer m_MovingImagePyramidContainer
elxGetObjectMacro(ResamplerContainer, ObjectContainerType)
elxSetObjectMacro(ResultDeformationFieldContainer, DataObjectContainerType)
elxSetObjectMacro(FixedMaskFileNameContainer, FileNameContainerType)
elxSetObjectMacro(FixedMaskContainer, DataObjectContainerType)
std::ofstream m_IterationInfoFile
elxGetNumberOfMacro(Optimizer)
itk::DataObject ResultDeformationFieldType
virtual void CreateTransformParameterMap()=0
ObjectContainerPointer m_TransformContainer
ObjectContainerPointer m_MetricContainer
IterationInfo m_IterationInfo
ObjectContainerPointer m_ImageSamplerContainer
ParameterMapType GetTransformParameterMap() const
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
elxGetObjectMacro(MovingImagePyramidContainer, ObjectContainerType)
elxGetNumberOfMacro(FixedImageFileName)
FileNameContainerType::Pointer FileNameContainerPointer
void SetTransformConfigurations(const std::vector< Configuration::ConstPointer > &configurations)
ObjectContainerType::Pointer ObjectContainerPointer
elxGetObjectMacro(FixedMaskContainer, DataObjectContainerType)
FileNameContainerPointer m_FixedMaskFileNameContainer
itk::TimeProbe m_Timer0
ParameterMapType m_TransformParameterMap
FileNameContainerPointer m_MovingImageFileNameContainer
std::ostream & GetIterationInfoAt(const char *const name)
IterationInfo & GetIterationInfo()
DataObjectContainerPointer m_ResultDeformationFieldContainer
ComponentDatabase::Pointer ComponentDatabasePointer
void AddNewTargetCell(const char *const cellName)
ParameterFileParser::ParameterMapType ParameterMapType


Generated on 2024-07-17 for elastix by doxygen 1.11.0 (9b424b03c9833626cd435af22a444888fbbb192d) elastix logo