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 <itkDeref.h>
27#include "elxElastixBase.h"
31#include "elxProgressCommand.h"
32
33// ITK header files:
34#include <itkImage.h>
35#include <itkOptimizerParameters.h>
36#include <itkTransformMeshFilter.h>
37
38
39namespace elastix
40{
41// using namespace itk; //Not here, because a TransformBase class was added to ITK...
42
136template <class TElastix>
137class ITK_TEMPLATE_EXPORT TransformBase : public BaseComponentSE<TElastix>
138{
139public:
141
145
148
150 using typename Superclass::RegistrationType;
151
152 using CommandLineArgumentMapType = Configuration ::CommandLineArgumentMapType;
153 using CommandLineEntryType = Configuration ::CommandLineEntryType;
154
157 using FixedImageType = typename TElastix::FixedImageType;
158 using MovingImageType = typename TElastix::MovingImageType;
159
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 = itk::Optimizer::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 SetTransformParameterFileName(const std::string & filename);
229
231 virtual void
233
235 void
237 ParameterMapType & parameterMap,
238 const bool includeDerivedTransformParameters = true) const;
239
241 void
242 WriteToFile(std::ostream & transformationParameterInfo, const ParametersType & param) const;
243
245 void
247
249 void
250 ReadInitialTransformFromFile(const std::string & 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 const Configuration & configuration = itk::Deref(Superclass::GetConfiguration());
302 return configuration.HasParameter("ITKTransformParameters");
303 }
304
311 void
313
321 void
322 AutomaticScalesEstimationStackTransform(const unsigned int numSubTransforms, ScalesType & scales) const;
323
324private:
326
328 template <template <typename, typename> class TSource, typename TOutputImage>
329 auto
331 {
332 const auto & resampleImageFilter = *(this->m_Elastix->GetElxResamplerBase()->GetAsITKBaseType());
333
335 const auto jacGenerator = TSource<TOutputImage, CoordRepType>::New();
336
337 jacGenerator->SetTransform(this->GetAsITKBaseType());
338 jacGenerator->SetOutputSize(resampleImageFilter.GetSize());
339 jacGenerator->SetOutputSpacing(resampleImageFilter.GetOutputSpacing());
340 jacGenerator->SetOutputOrigin(resampleImageFilter.GetOutputOrigin());
341 jacGenerator->SetOutputIndex(resampleImageFilter.GetOutputStartIndex());
342 jacGenerator->SetOutputDirection(resampleImageFilter.GetOutputDirection());
343 // NOTE: We can not use the following, since the fixed image does not exist in transformix
344 // jacGenerator->SetOutputParametersFromImage(
345 // this->GetRegistration()->GetAsITKBaseType()->GetFixedImage() );
346
347 return jacGenerator;
348 }
349
350
352 template <typename TImage>
353 auto
355 {
359 const auto infoChanger = itk::ChangeInformationImageFilter<TImage>::New();
360 typename FixedImageType::DirectionType originalDirection;
361 const bool retdc = this->m_Elastix->GetOriginalFixedImageDirection(originalDirection);
362 infoChanger->SetOutputDirection(originalDirection);
363 infoChanger->SetChangeDirection(retdc && !this->m_Elastix->GetUseDirectionCosines());
364 infoChanger->SetInput(image);
365
366 return infoChanger;
367 }
368
369
372 void
374
378 int
379 BeforeAllBase() override;
380
384 void
386
390 void
392
396
398 itkGetStringMacro(TransformParameterFileName);
399
401 void
402 TransformPointsSomePoints(const std::string & filename) const;
403
405 void
406 TransformPointsSomePointsVTK(const std::string & filename) const;
407
416 typename DeformationFieldImageType::Pointer
418
419 void WriteDeformationFieldImage(typename DeformationFieldImageType::Pointer) const;
420
422 void
424
425 std::string
427 {
428 const InitialTransformType * const initialTransform = this->GetInitialTransform();
429
430 if (!initialTransform)
431 {
432 return "NoInitialTransform";
433 }
434
435 const auto t0 = dynamic_cast<const Self *>(initialTransform);
437 }
438
439 virtual ParameterMapType
441
443 virtual void
446
451
453 bool m_ReadWriteTransformParameters{ true };
454};
455
456} // end namespace elastix
457
458#ifndef ITK_MANUAL_INSTANTIATION
459# include "elxTransformBase.hxx"
460#endif
461
462#endif // end #ifndef elxTransformBase_h
The BaseComponentSE class is a base class for elastix components that provides some basic functionali...
typename ElastixType::RegistrationBaseType RegistrationType
A class that deals with user given parameters and command line arguments.
itk::SmartPointer< const Self > ConstPointer
bool HasParameter(const std::string &parameterName) const
This class is the elastix base class for all Transforms.
TMesh::Pointer TransformMesh(const TMesh &mesh) const
std::string m_TransformParameterFileName
const ITKBaseType * GetAsITKBaseType() const
itk::Image< itk::Matrix< float, MovingImageDimension, FixedImageDimension >, FixedImageDimension > SpatialJacobianMatrixImageType
typename TElastix::FixedImageType FixedImageType
typename RegistrationType::ITKBaseType ITKRegistrationType
void SetInitialTransform(InitialTransformType *_arg)
ParametersType m_TransformParameters
ITKBaseType * GetAsITKBaseType()
void TransformPointsSomePointsVTK(const std::string &filename) const
DeformationFieldImageType::Pointer GenerateDeformationFieldImage() const
itk::Image< float, FixedImageDimension > SpatialJacobianDeterminantImageType
std::string GetInitialTransformParameterFileName() const
SpatialJacobianDeterminantImageType::Pointer ComputeSpatialJacobianDeterminantImage() const
void ReadInitialTransformFromConfiguration(const Configuration::ConstPointer)
itk::Image< VectorPixelType, FixedImageDimension > DeformationFieldImageType
void TransformPoints() const
typename ITKBaseType::OutputPointType OutputPointType
void AutomaticScalesEstimation(ScalesType &scales) const
virtual ParameterMapType CreateDerivedTransformParameterMap() const =0
virtual const char * GetTransformParameterFileName() const
void SetReadWriteTransformParameters(const bool _arg)
typename ITKRegistrationType::OptimizerType OptimizerType
typename TElastix::ParameterMapType ParameterMapType
void WriteToFile(std::ostream &transformationParameterInfo, const ParametersType &param) const
void TransformPointsAllPoints() const
ParametersType m_FinalParameters
ITK_DISALLOW_COPY_AND_MOVE(TransformBase)
typename TElastix::MovingImageType MovingImageType
void ComputeAndWriteSpatialJacobianMatrixImage() const
SpatialJacobianMatrixImageType::Pointer ComputeSpatialJacobianMatrixImage() const
auto CreateChangeInformationImageFilter(TImage *image) const
typename ITKBaseType::InputPointType InputPointType
elxDeclarePureVirtualGetSelfMacro(ITKBaseType)
itkStaticConstMacro(FixedImageDimension, unsigned int, FixedImageType::ImageDimension)
typename CombinationTransformType::InitialTransformType InitialTransformType
Configuration ::CommandLineArgumentMapType CommandLineArgumentMapType
void ComputeAndWriteSpatialJacobianDeterminantImage() const
itk::Optimizer::ScalesType ScalesType
virtual void ReadFromFile()
Configuration ::CommandLineEntryType CommandLineEntryType
auto CreateJacobianSource() const
void TransformPointsSomePoints(const std::string &filename) const
virtual void WriteDerivedTransformDataToFile() const
void ReadInitialTransformFromFile(const std::string &transformParameterFileName)
void CreateTransformParameterMap(const ParametersType &param, ParameterMapType &parameterMap, const bool includeDerivedTransformParameters=true) const
void AfterRegistrationBase() override
void WriteDeformationFieldImage(typename DeformationFieldImageType::Pointer) const
itkStaticConstMacro(MovingImageDimension, unsigned int, MovingImageType::ImageDimension)
ComponentDatabase::ComponentDescriptionType ComponentDescriptionType
bool HasITKTransformParameters() const
const InitialTransformType * GetInitialTransform() const
itk::Vector< float, FixedImageDimension > VectorPixelType
void AutomaticScalesEstimationStackTransform(const unsigned int numSubTransforms, ScalesType &scales) const
void SetTransformParameterFileName(const std::string &filename)
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'.


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