go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
elxLibUtilities.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 elxLibUtilities_h
19#define elxLibUtilities_h
20
22
23#include <itkCastImageFilter.h>
24#include <itkDataObject.h>
25#include <itkSmartPointer.h>
26
27#include <map>
28#include <string>
29#include <type_traits> // For is_same_v.
30#include <vector>
31
32
34{
35using ParameterValuesType = std::vector<std::string>;
36using ParameterMapType = std::map<std::string, ParameterValuesType>;
37
38
40void
42 const std::string & parameterName,
43 const std::string & parameterValue);
44
45
47std::string
48RetrievePixelTypeParameterValue(const ParameterMapType & parameterMap, const std::string & parameterName);
49
50template <typename TInputImage>
51itk::SmartPointer<itk::DataObject>
52CastToInternalPixelType(itk::SmartPointer<TInputImage> inputImage, const std::string & internalPixelTypeString)
53{
54 if (inputImage == nullptr)
55 {
56 itkGenericExceptionMacro("The specified input image should not be null!");
57 }
58
59 itk::SmartPointer<itk::DataObject> outputImage;
60
61 elx::ForEachSupportedImageTypeUntilTrue([inputImage, &outputImage, &internalPixelTypeString](const auto elxTypedef) {
62 using ElxTypedef = decltype(elxTypedef);
63
64 if constexpr (TInputImage::ImageDimension == ElxTypedef::MovingDimension)
65 {
66 using InternalImageType = typename ElxTypedef::MovingImageType;
67
68 if (internalPixelTypeString == ElxTypedef::MovingPixelTypeString)
69 {
70 if constexpr (std::is_same_v<TInputImage, InternalImageType>)
71 {
72 outputImage = inputImage;
73 }
74 else
75 {
76 const auto castFilter = itk::CastImageFilter<TInputImage, InternalImageType>::New();
77 castFilter->SetInput(inputImage);
78 castFilter->Update();
79 outputImage = castFilter->GetOutput();
80 }
81 return true;
82 }
83 }
84 return false;
85 });
86
87 if (outputImage == nullptr)
88 {
89 itkGenericExceptionMacro("Failed to cast to the specified internal pixel type \""
90 << internalPixelTypeString
91 << "\". It may need to be added to the CMake variable ELASTIX_IMAGE_"
92 << TInputImage::ImageDimension << "D_PIXELTYPES.");
93 }
94 return outputImage;
95}
96
97} // namespace elastix::LibUtilities
98
99#endif
std::string RetrievePixelTypeParameterValue(const ParameterMapType &parameterMap, const std::string &parameterName)
std::vector< std::string > ParameterValuesType
itk::SmartPointer< itk::DataObject > CastToInternalPixelType(itk::SmartPointer< TInputImage > inputImage, const std::string &internalPixelTypeString)
std::map< std::string, ParameterValuesType > ParameterMapType
void SetParameterValueAndWarnOnOverride(ParameterMapType &parameterMap, const std::string &parameterName, const std::string &parameterValue)
bool ForEachSupportedImageTypeUntilTrue(const TFunction &func, const std::index_sequence< VIndexSequence... > &)


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