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 "itkObject.h"
35#include "itkDataObject.h"
36#include "elxMacro.h"
37#include "xoutmain.h"
38#include "itkVectorContainer.h"
39#include "itkImageFileReader.h"
40#include "itkChangeInformationImageFilter.h"
41
42#include <fstream>
43#include <iomanip>
44
51#define elxGetObjectMacro( _name, _type ) \
52 virtual _type * Get##_name( void ) const \
53 { \
54 return this->m_##_name.GetPointer(); \
55 }
56//end elxGetObjectMacro
57
58#define elxSetObjectMacro( _name, _type ) \
59 virtual void Set##_name( _type * _arg ) \
60 { \
61 if( this->m_##_name != _arg ) \
62 { \
63 this->m_##_name = _arg; \
64 this->GetAsITKBaseType()->Modified(); \
65 } \
66 }
67//end elxSetObjectMacro
68
70#define elxGetNumberOfMacro( _name ) \
71 virtual unsigned int GetNumberOf##_name##s( void ) const \
72 { \
73 if( this->Get##_name##Container() != nullptr ) \
74 { \
75 return this->Get##_name##Container()->Size(); \
76 } \
77 return 0; \
78 }
79// end elxGetNumberOfMacro
80
81namespace elastix
82{
144{
145public:
146
150
154 typedef itk::Object ObjectType; //for the components
155 typedef ObjectType::Pointer ObjectPointer;
156 typedef itk::DataObject DataObjectType; //for the images
157 typedef DataObjectType::Pointer DataObjectPointer;
158 typedef itk::VectorContainer<
160 typedef ObjectContainerType::Pointer ObjectContainerPointer;
161 typedef itk::VectorContainer<
163 typedef DataObjectContainerType::Pointer DataObjectContainerPointer;
164 typedef itk::VectorContainer<
165 unsigned int, std::string > FileNameContainerType;
166 typedef FileNameContainerType::Pointer FileNameContainerPointer;
167
172 typedef std::vector< double > FlatDirectionCosinesType;
173
176
180 typedef itk::Object ITKBaseType;
181
184 {
185 return dynamic_cast< ITKBaseType * >( this );
186 }
187
188
192
194 virtual void SetDBIndex( DBIndexType _arg );
195
196 virtual DBIndexType GetDBIndex( void )
197 {
198 return this->m_DBIndex;
199 }
200
201
208
213 elxGetObjectMacro( RegistrationContainer, ObjectContainerType );
214 elxGetObjectMacro( FixedImagePyramidContainer, ObjectContainerType );
215 elxGetObjectMacro( MovingImagePyramidContainer, ObjectContainerType );
216 elxGetObjectMacro( InterpolatorContainer, ObjectContainerType );
217 elxGetObjectMacro( ImageSamplerContainer, ObjectContainerType );
221 elxGetObjectMacro( ResampleInterpolatorContainer, ObjectContainerType );
223
228 elxSetObjectMacro( RegistrationContainer, ObjectContainerType );
229 elxSetObjectMacro( FixedImagePyramidContainer, ObjectContainerType );
230 elxSetObjectMacro( MovingImagePyramidContainer, ObjectContainerType );
231 elxSetObjectMacro( InterpolatorContainer, ObjectContainerType );
232 elxSetObjectMacro( ImageSamplerContainer, ObjectContainerType );
236 elxSetObjectMacro( ResampleInterpolatorContainer, ObjectContainerType );
238
244
250
254
256 elxGetObjectMacro( ResultDeformationFieldContainer, DataObjectContainerType );
257 elxSetObjectMacro( ResultDeformationFieldContainer, DataObjectContainerType );
258
262 elxGetObjectMacro( FixedImageFileNameContainer, FileNameContainerType );
263 elxGetObjectMacro( MovingImageFileNameContainer, FileNameContainerType );
264 elxSetObjectMacro( FixedImageFileNameContainer, FileNameContainerType );
265 elxSetObjectMacro( MovingImageFileNameContainer, FileNameContainerType );
266
270 elxGetObjectMacro( FixedMaskFileNameContainer, FileNameContainerType );
271 elxGetObjectMacro( MovingMaskFileNameContainer, FileNameContainerType );
272 elxSetObjectMacro( FixedMaskFileNameContainer, FileNameContainerType );
273 elxSetObjectMacro( MovingMaskFileNameContainer, FileNameContainerType );
274
276 elxGetNumberOfMacro( Registration );
277 elxGetNumberOfMacro( FixedImagePyramid );
278 elxGetNumberOfMacro( MovingImagePyramid );
279 elxGetNumberOfMacro( Interpolator );
280 elxGetNumberOfMacro( ImageSampler );
284 elxGetNumberOfMacro( ResampleInterpolator );
286 elxGetNumberOfMacro( FixedImage );
287 elxGetNumberOfMacro( MovingImage );
288 elxGetNumberOfMacro( FixedImageFileName );
289 elxGetNumberOfMacro( MovingImageFileName );
291 elxGetNumberOfMacro( MovingMask );
292 elxGetNumberOfMacro( FixedMaskFileName );
293 elxGetNumberOfMacro( MovingMaskFileName );
294 elxGetNumberOfMacro( ResultImage );
295 elxGetNumberOfMacro( ResultDeformationField );
296
301 elxSetObjectMacro( InitialTransform, ObjectType );
302 elxGetObjectMacro( InitialTransform, ObjectType );
303
310 elxSetObjectMacro( FinalTransform, ObjectType );
311 elxGetObjectMacro( FinalTransform, ObjectType );
312
314 virtual int Run( void ) = 0;
315
317 virtual int ApplyTransform( void ) = 0;
318
322 int BeforeAllBase( void ) override;
323
327 virtual int BeforeAllTransformixBase( void );
328
332 void BeforeRegistrationBase( void ) override;
333
334 void AfterRegistrationBase( void ) override;
335
340 virtual int GetDefaultOutputPrecision( void ) const
341 {
342 return this->m_DefaultOutputPrecision;
343 }
344
345
349 virtual bool GetUseDirectionCosines( void ) const;
350
354 const FlatDirectionCosinesType & arg );
355
357
359 virtual void CreateTransformParametersMap( void ) = 0;
360
363
365 virtual void SetConfigurations( std::vector< ConfigurationPointer > & configurations ) = 0;
366
367protected:
368
370 ~ElastixBase() override = default;
371
375
377
390 template< class TImage >
392 {
393public:
394
395 typedef TImage ImageType;
396 typedef typename ImageType::Pointer ImagePointer;
397 typedef itk::ImageFileReader< ImageType > ImageReaderType;
398 typedef typename ImageReaderType::Pointer ImageReaderPointer;
399 typedef typename ImageType::DirectionType DirectionType;
400 typedef itk::ChangeInformationImageFilter< ImageType > ChangeInfoFilterType;
401 typedef typename ChangeInfoFilterType::Pointer ChangeInfoFilterPointer;
402
404 FileNameContainerType * fileNameContainer, const std::string & imageDescription,
405 bool useDirectionCosines, DirectionType * originalDirectionCosines = nullptr )
406 {
407 DataObjectContainerPointer imageContainer = DataObjectContainerType::New();
408
410 for( unsigned int i = 0; i < fileNameContainer->Size(); ++i )
411 {
413 ImageReaderPointer imageReader = ImageReaderType::New();
414 imageReader->SetFileName( fileNameContainer->ElementAt( i ).c_str() );
415 ChangeInfoFilterPointer infoChanger = ChangeInfoFilterType::New();
416 DirectionType direction;
417 direction.SetIdentity();
418 infoChanger->SetOutputDirection( direction );
419 infoChanger->SetChangeDirection( !useDirectionCosines );
420 infoChanger->SetInput( imageReader->GetOutput() );
421
423 try
424 {
425 infoChanger->Update();
426 }
427 catch( itk::ExceptionObject & excp )
428 {
430 std::string err_str = excp.GetDescription();
431 err_str += "\nError occurred while reading the image described as "
432 + imageDescription + ", with file name " + imageReader->GetFileName() + "\n";
433 excp.SetDescription( err_str );
435 throw excp;
436 }
437
439 ImagePointer image = infoChanger->GetOutput();
440 imageContainer->CreateElementAt( i ) = image.GetPointer();
441
443 if( originalDirectionCosines )
444 {
445 *originalDirectionCosines = imageReader->GetOutput()->GetDirection();
446 }
447
448 } // end for i
449
450 return imageContainer;
451
452 } // end static method GenerateImageContainer
453
454
457 {
459 DataObjectContainerPointer imageContainer = DataObjectContainerType::New();
460
462 imageContainer->CreateElementAt( 0 ) = image;
463
465 return imageContainer;
466
467 } // GenerateImageContainer()
468
469
472
473 };
474
476 {
477public:
478
481 DataObjectPointer image )
482 {
483 unsigned int j = 0; //container with only one image for now
484
486 DataObjectContainerPointer imageContainer = DataObjectContainerType::New();
487
489 imageContainer->CreateElementAt( j ) = image;
490
492 return imageContainer;
493 } // end GenerateImageContainer()
494
495
499 };
500
501private:
502
503 ElastixBase( const Self & ); // purposely not implemented
504 void operator=( const Self & ); // purposely not implemented
505
507
509
523
529
532
535
541
545
548
557 const std::string & optionkey,
558 int & errorcode,
559 bool printerrors,
560 bool printinfo ) const;
561
562};
563
564} // end namespace elastix
565
566#undef elxGetObjectMacro
567#undef elxSetObjectMacro
568#undef elxGetNumberOfMacro
569
570#endif // end #ifndef __elxElastixBase_h
The BaseComponent class is a class that all elastix components should inherit from.
The ComponentDatabase class is a class that stores the New() functions of all components.
itk::SmartPointer< Self > Pointer
A class that deals with user given parameters and command line arguments.
itk::SmartPointer< Self > Pointer
static DataObjectContainerPointer GenerateImageContainer(DataObjectPointer image)
ChangeInfoFilterType::Pointer ChangeInfoFilterPointer
itk::ChangeInformationImageFilter< ImageType > ChangeInfoFilterType
itk::ImageFileReader< ImageType > ImageReaderType
static DataObjectContainerPointer GenerateImageContainer(DataObjectPointer image)
ImageReaderType::Pointer ImageReaderPointer
static DataObjectContainerPointer GenerateImageContainer(FileNameContainerType *fileNameContainer, const std::string &imageDescription, bool useDirectionCosines, DirectionType *originalDirectionCosines=nullptr)
This class creates an interface for elastix.
elxSetObjectMacro(FixedImageContainer, DataObjectContainerType)
elxSetObjectMacro(MetricContainer, ObjectContainerType)
virtual DBIndexType GetDBIndex(void)
itk::VectorContainer< unsigned int, ObjectPointer > ObjectContainerType
itk::DataObject DataObjectType
DataObjectContainerPointer m_FixedImageContainer
ConfigurationType::Pointer ConfigurationPointer
elxGetObjectMacro(MovingImageFileNameContainer, FileNameContainerType)
elxGetObjectMacro(ComponentDatabase, ComponentDatabaseType)
virtual void SetConfigurations(std::vector< ConfigurationPointer > &configurations)=0
DataObjectContainerPointer m_MovingImageContainer
ObjectContainerPointer m_RegistrationContainer
Configuration ConfigurationType
BaseComponent Superclass
elxGetNumberOfMacro(MovingMaskFileName)
ObjectType::Pointer ObjectPointer
FileNameContainerPointer m_MovingMaskFileNameContainer
itk::VectorContainer< unsigned int, DataObjectPointer > DataObjectContainerType
elxSetObjectMacro(ResultImageContainer, DataObjectContainerType)
elxSetObjectMacro(OptimizerContainer, ObjectContainerType)
elxSetObjectMacro(RegistrationContainer, ObjectContainerType)
elxSetObjectMacro(ComponentDatabase, ComponentDatabaseType)
elxGetObjectMacro(InitialTransform, ObjectType)
elxGetObjectMacro(FixedImagePyramidContainer, ObjectContainerType)
elxGetObjectMacro(FixedMaskFileNameContainer, FileNameContainerType)
DataObjectContainerType::Pointer DataObjectContainerPointer
ObjectContainerPointer m_OptimizerContainer
ObjectContainerPointer m_ResampleInterpolatorContainer
elxGetNumberOfMacro(Transform)
FileNameContainerPointer m_FixedImageFileNameContainer
elxSetObjectMacro(InitialTransform, ObjectType)
elxGetNumberOfMacro(FixedImage)
ComponentDatabasePointer m_ComponentDatabase
elxSetObjectMacro(ResamplerContainer, ObjectContainerType)
elxGetObjectMacro(MovingImageContainer, DataObjectContainerType)
elxGetObjectMacro(TransformContainer, ObjectContainerType)
virtual int Run(void)=0
ConfigurationPointer m_Configuration
elxGetNumberOfMacro(MovingMask)
elxGetNumberOfMacro(MovingImage)
DataObjectContainerPointer m_FixedMaskContainer
elxSetObjectMacro(MovingImageContainer, DataObjectContainerType)
elxGetNumberOfMacro(FixedImagePyramid)
elxSetObjectMacro(MovingImagePyramidContainer, ObjectContainerType)
elxGetNumberOfMacro(FixedMaskFileName)
elxGetObjectMacro(OptimizerContainer, ObjectContainerType)
void AfterRegistrationBase(void) override
elxGetNumberOfMacro(FixedMask)
elxGetObjectMacro(ImageSamplerContainer, ObjectContainerType)
void BeforeRegistrationBase(void) override
ObjectContainerPointer m_ResamplerContainer
elxGetObjectMacro(MovingMaskContainer, DataObjectContainerType)
elxGetObjectMacro(FixedImageContainer, DataObjectContainerType)
ObjectContainerPointer m_InterpolatorContainer
FileNameContainerType::Pointer FileNameContainerPointer
int BeforeAllBase(void) override
DataObjectType::Pointer DataObjectPointer
elxGetObjectMacro(ResampleInterpolatorContainer, ObjectContainerType)
std::vector< double > FlatDirectionCosinesType
FlatDirectionCosinesType m_OriginalFixedImageDirection
elxGetObjectMacro(FixedImageFileNameContainer, FileNameContainerType)
ObjectContainerType::Pointer ObjectContainerPointer
elxSetObjectMacro(FixedImagePyramidContainer, ObjectContainerType)
virtual ITKBaseType * GetAsITKBaseType(void)
DataObjectContainerPointer m_ResultImageContainer
elxGetObjectMacro(Configuration, ConfigurationType)
elxSetObjectMacro(MovingMaskContainer, DataObjectContainerType)
elxGetNumberOfMacro(ResultImage)
elxGetNumberOfMacro(ResultDeformationField)
DataObjectContainerPointer m_MovingMaskContainer
elxGetNumberOfMacro(ResampleInterpolator)
elxGetObjectMacro(RegistrationContainer, ObjectContainerType)
elxSetObjectMacro(Configuration, ConfigurationType)
ComponentDatabase ComponentDatabaseType
elxSetObjectMacro(ResampleInterpolatorContainer, ObjectContainerType)
elxGetNumberOfMacro(Interpolator)
ComponentDatabaseType::IndexType DBIndexType
elxGetNumberOfMacro(MovingImageFileName)
elxSetObjectMacro(ImageSamplerContainer, ObjectContainerType)
ElastixBase(const Self &)
xl::xoutrow_type m_IterationInfo
elxSetObjectMacro(MovingMaskFileNameContainer, FileNameContainerType)
elxSetObjectMacro(MovingImageFileNameContainer, FileNameContainerType)
elxGetObjectMacro(InterpolatorContainer, ObjectContainerType)
ObjectContainerPointer m_FixedImagePyramidContainer
virtual int BeforeAllTransformixBase(void)
elxGetObjectMacro(MetricContainer, ObjectContainerType)
FileNameContainerPointer GenerateFileNameContainer(const std::string &optionkey, int &errorcode, bool printerrors, bool printinfo) const
elxGetNumberOfMacro(Resampler)
elxSetObjectMacro(InterpolatorContainer, ObjectContainerType)
ObjectPointer m_InitialTransform
ObjectContainerPointer m_MovingImagePyramidContainer
elxGetObjectMacro(ResamplerContainer, ObjectContainerType)
elxGetObjectMacro(FinalTransform, ObjectType)
elxSetObjectMacro(ResultDeformationFieldContainer, DataObjectContainerType)
virtual ParameterMapType GetTransformParametersMap(void) const =0
virtual int ApplyTransform(void)=0
itk::VectorContainer< unsigned int, std::string > FileNameContainerType
void operator=(const Self &)
elxSetObjectMacro(FixedMaskFileNameContainer, FileNameContainerType)
elxSetObjectMacro(FixedMaskContainer, DataObjectContainerType)
elxGetNumberOfMacro(Optimizer)
ObjectContainerPointer m_TransformContainer
virtual void SetOriginalFixedImageDirectionFlat(const FlatDirectionCosinesType &arg)
ObjectContainerPointer m_MetricContainer
virtual void CreateTransformParametersMap(void)=0
ObjectContainerPointer m_ImageSamplerContainer
elxGetNumberOfMacro(Registration)
elxSetObjectMacro(TransformContainer, ObjectContainerType)
virtual bool GetUseDirectionCosines(void) const
virtual void SetDBIndex(DBIndexType _arg)
elxSetObjectMacro(FixedImageFileNameContainer, FileNameContainerType)
elxGetNumberOfMacro(MovingImagePyramid)
elxGetNumberOfMacro(ImageSampler)
ComponentDatabaseType::Pointer ComponentDatabasePointer
elxGetObjectMacro(ResultImageContainer, DataObjectContainerType)
elxGetObjectMacro(ResultDeformationFieldContainer, DataObjectContainerType)
~ElastixBase() override=default
elxGetObjectMacro(MovingMaskFileNameContainer, FileNameContainerType)
ObjectPointer m_FinalTransform
elxSetObjectMacro(FinalTransform, ObjectType)
elxGetObjectMacro(MovingImagePyramidContainer, ObjectContainerType)
elxGetNumberOfMacro(FixedImageFileName)
itk::ParameterMapInterface::ParameterMapType ParameterMapType
virtual int GetDefaultOutputPrecision(void) const
virtual const FlatDirectionCosinesType & GetOriginalFixedImageDirectionFlat(void) const
elxGetObjectMacro(FixedMaskContainer, DataObjectContainerType)
FileNameContainerPointer m_FixedMaskFileNameContainer
FileNameContainerPointer m_MovingImageFileNameContainer
DataObjectContainerPointer m_ResultDeformationFieldContainer
ParameterFileParser::ParameterMapType ParameterMapType
The xoutrow class can easily generate tables.
Definition: xoutrow.h:43


Generated on 1667476801 for elastix by doxygen 1.9.4 elastix logo