1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkTransformBase_h
#define itkTransformBase_h
#include "ITKTransformExport.h"
#include "itkObject.h"
#include "itkPoint.h"
#include "itkCovariantVector.h"
#include "vnl/vnl_vector_fixed.h"
#include "itkArray2D.h"
#include "itkOptimizerParameters.h"
#include "itkObjectFactory.h"
#include "itkIntTypes.h"
namespace itk
{
/** \class TransformBaseTemplateEnums
* \brief Contains all enum classes used by TransformBaseTemplate class.
* \ingroup ITKTransform
*/
class TransformBaseTemplateEnums
{
public:
/** \class TransformCategory
* \ingroup ITKTransform
* */
enum class TransformCategory : uint8_t
{
UnknownTransformCategory = 0,
Linear = 1,
BSpline = 2,
Spline = 3,
DisplacementField = 4,
VelocityField = 5
};
};
// Define how to print enumeration
extern ITKTransform_EXPORT std::ostream &
operator<<(std::ostream & out, const TransformBaseTemplateEnums::TransformCategory value);
/** \class TransformBaseTemplate
*
* This class is an abstract class to represent a spatial transform.
*
* This class is templated over the scalar type used to store the transform's
* parameters.
*
* \ingroup ITKTransform
*/
template <typename TParametersValueType>
class TransformBaseTemplate : public Object
{
public:
ITK_DISALLOW_COPY_AND_MOVE(TransformBaseTemplate);
/** Standard class type aliases. */
using Self = TransformBaseTemplate;
using Superclass = Object;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
/** Type of the input parameters. */
using ParametersValueType = TParametersValueType;
using ParametersType = OptimizerParameters<ParametersValueType>;
using FixedParametersValueType = double;
using FixedParametersType = OptimizerParameters<FixedParametersValueType>;
/** \see LightObject::GetNameOfClass() */
itkOverrideGetNameOfClassMacro(TransformBaseTemplate);
/** The number of parameters can potentially be very large,
* therefore we use here a large capacity integer. */
using NumberOfParametersType = IdentifierType;
/* For storing the name of InputSpace */
itkSetMacro(InputSpaceName, std::string);
itkGetConstReferenceMacro(InputSpaceName, std::string);
/** For storing the name of InputSpace/OutputSpace.
InputSpaceName, OutputSpaceName provide identifiers for the world spaces
that the transform applied to and the direction of the spatial transformation.
The direction of the transform goes from the input space to output space.
Typical values include the names of an atlas or a dataset. */
itkSetMacro(OutputSpaceName, std::string);
itkGetConstReferenceMacro(OutputSpaceName, std::string);
/** Return the number of parameters that completely define the Transform */
virtual NumberOfParametersType
GetNumberOfParameters() const = 0;
/** Get the Transformation Parameters. */
virtual const ParametersType &
GetParameters() const = 0;
/** Get the size of the input space */
virtual unsigned int
GetInputSpaceDimension() const = 0;
/** Get the size of the output space */
virtual unsigned int
GetOutputSpaceDimension() const = 0;
/** Set the transformation parameters and update internal transformation. */
virtual void
SetParameters(const ParametersType &) = 0;
/** Set the transformation by copying parameters and update internal transformation.
* This method forces the transform to copy the parameters. The
* default implementation is to call SetParameters. This call must
* be overridden if the transform normally implements SetParameters
* by keeping a reference to the parameters.
* \sa SetParameters
*/
virtual void
SetParametersByValue(const ParametersType & p) = 0;
/** Set the fixed parameters. */
virtual void
SetFixedParameters(const FixedParametersType &) = 0;
/** This function allow copying a range of values into the Parameters
* The range of values must conform to std::copy(begin, end, m_Parameters)
* requirements.
*/
virtual void
CopyInParameters(const ParametersValueType * const begin, const ParametersValueType * const end) = 0;
/** This function allow copying a range of values into the FixedParameters
* The range of values must conform to std::copy(begin, end, m_FixedParameters)
* requirements.
*/
virtual void
CopyInFixedParameters(const FixedParametersValueType * const begin, const FixedParametersValueType * const end) = 0;
/** Get the fixed parameters. */
virtual const FixedParametersType &
GetFixedParameters() const = 0;
/** Generate a platform independent name */
virtual std::string
GetTransformTypeAsString() const = 0;
using TransformCategoryEnum = TransformBaseTemplateEnums::TransformCategory;
#if !defined(ITK_LEGACY_REMOVE)
// We need to expose the enum values at the class level
// for backwards compatibility
static constexpr TransformCategoryEnum UnknownTransformCategory = TransformCategoryEnum::UnknownTransformCategory;
static constexpr TransformCategoryEnum Linear = TransformCategoryEnum::Linear;
static constexpr TransformCategoryEnum BSpline = TransformCategoryEnum::BSpline;
static constexpr TransformCategoryEnum Spline = TransformCategoryEnum::Spline;
static constexpr TransformCategoryEnum DisplacementField = TransformCategoryEnum::DisplacementField;
static constexpr TransformCategoryEnum VelocityField = TransformCategoryEnum::VelocityField;
// Preserve old type name for backwards compatibility
using TransformCategoryType = TransformCategoryEnum;
#endif
/** Get transform category */
virtual TransformCategoryEnum
GetTransformCategory() const = 0;
protected:
#if defined(__GNUC__)
// A bug in some versions of the GCC and Clang compilers
// result in an ICE or linker error when "= default" is requested.
// This was observed in at least gcc 4.8 and 5.4.0, and
// AppleClang 7.0.2 and 8.0.0. Probably others too.
// "= default" doesn't gain us much, so just don't use it here.
TransformBaseTemplate(){};
~TransformBaseTemplate() override{};
#else
TransformBaseTemplate() = default;
~TransformBaseTemplate() override = default;
#endif
private:
std::string m_InputSpaceName{};
std::string m_OutputSpaceName{};
};
/** This helps to meet backward compatibility */
using TransformBase = TransformBaseTemplate<double>;
} // end namespace itk
#endif
/** Explicit instantiations */
#ifndef ITK_TEMPLATE_EXPLICIT_TransformBase
// Explicit instantiation is required to ensure correct dynamic_cast
// behavior across shared libraries.
//
// IMPORTANT: Since within the same compilation unit,
// ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
// need to be considered. This code *MUST* be *OUTSIDE* the header
// guards.
//
#if defined(ITKTransform_EXPORTS)
// We are building this library
# define ITKTransform_EXPORT_EXPLICIT ITK_TEMPLATE_EXPORT
#else
// We are using this library
# define ITKTransform_EXPORT_EXPLICIT ITKTransform_EXPORT
#endif
namespace itk
{
ITK_GCC_PRAGMA_DIAG_PUSH()
ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
extern template class ITKTransform_EXPORT_EXPLICIT TransformBaseTemplate<double>;
extern template class ITKTransform_EXPORT_EXPLICIT TransformBaseTemplate<float>;
ITK_GCC_PRAGMA_DIAG_POP()
} // end namespace itk
#undef ITKTransform_EXPORT_EXPLICIT
#endif
|