/usr/include/ITK-4.5/itkTransform.h is in libinsighttoolkit4-dev 4.5.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | /*=========================================================================
*
* Copyright Insight Software Consortium
*
* 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
*
* http://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 __itkTransform_h
#define __itkTransform_h
#include "itkTransformBase.h"
#include "itkVector.h"
#include "itkSymmetricSecondRankTensor.h"
#include "itkDiffusionTensor3D.h"
#include "itkVariableLengthVector.h"
#include "vnl/vnl_vector_fixed.h"
#include "itkMatrix.h"
namespace itk
{
/** \class Transform
* \brief Transform points and vectors from an input space to an output space.
*
* This abstract class defines the generic interface for a geometric
* transformation from one space to another. The class provides methods
* for mapping points, vectors and covariant vectors from the input space
* to the output space.
*
* Given that transformations are not necessarily invertible, this basic
* class does not provide the methods for back transformation. Back transform
* methods are implemented in derived classes where appropriate.
*
* \par Registration Framework Support
* Typically a Transform class has several methods for setting its
* parameters. For use in the registration framework, the parameters must
* also be represented by an array of doubles to allow communication
* with generic optimizers. The Array of transformation parameters is set using
* the SetParameters() method.
*
* Another requirement of the registration framework is the computation
* of the transform Jacobian. In general, an ImageToImageMetric requires
* the knowledge of the Jacobian in order to compute the metric derivatives.
* The Jacobian is a matrix whose element are the partial derivatives
* of the output point with respect to the array of parameters that defines
* the transform.
*
* Subclasses must provide implementations for:<br>
* virtual OutputPointType TransformPoint(const InputPointType &) const<br>
* virtual OutputVectorType TransformVector(const InputVectorType &) const<br>
* virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const<br>
* virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const<br>
* virtual void SetParameters(const ParametersType &)<br>
* virtual void SetFixedParameters(const ParametersType &)<br>
* virtual void ComputeJacobianWithRespectToParameters(
* const InputPointType &,
* JacobianType &) const<br>
* virtual void ComputeJacobianWithRespectToPosition(
* const InputPointType & x,
* JacobianType &jacobian ) const;<br>
*
* Since TranformVector and TransformCovariantVector have multiple
* overloaded methods from the base class, subclasses must specify:<br>
* using Superclass::TransformVector;<br>
* using Superclass::TransformCovariantVector;<br>
*
*
* \ingroup ITKTransform
*/
template <typename TScalar,
unsigned int NInputDimensions = 3,
unsigned int NOutputDimensions = 3>
class Transform : public TransformBaseTemplate< TScalar >
{
public:
/** Standard class typedefs. */
typedef Transform Self;
typedef TransformBaseTemplate< TScalar > Superclass;
typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer;
/** Run-time type information (and related methods). */
itkTypeMacro(Transform, TransformBaseTemplate);
/** Dimension of the domain space. */
itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions);
itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions);
/** define the Clone method */
itkCloneMacro(Self);
/** Get the size of the input space */
unsigned int GetInputSpaceDimension(void) const
{
return NInputDimensions;
}
/** Get the size of the output space */
unsigned int GetOutputSpaceDimension(void) const
{
return NOutputDimensions;
}
/** Type of the scalar representing coordinate and vector elements. */
typedef TScalar ScalarType;
/** Type of the input parameters. */
typedef typename Superclass::ParametersType ParametersType;
typedef typename Superclass::ParametersValueType ParametersValueType;
typedef Array<ParametersValueType> DerivativeType;
/** Type of the Jacobian matrix. */
typedef Array2D<ParametersValueType> JacobianType;
/** Standard vector type for this class. */
typedef Vector<TScalar, NInputDimensions> InputVectorType;
typedef Vector<TScalar, NOutputDimensions> OutputVectorType;
/** Standard variable length vector type for this class
* this provides an interface for the VectorImage class */
typedef VariableLengthVector<TScalar> InputVectorPixelType;
typedef VariableLengthVector<TScalar> OutputVectorPixelType;
/* Standard symmetric second rank tenosr type for this class */
typedef SymmetricSecondRankTensor<TScalar,NInputDimensions>
InputSymmetricSecondRankTensorType;
typedef SymmetricSecondRankTensor<TScalar,NOutputDimensions>
OutputSymmetricSecondRankTensorType;
/* Standard tensor type for this class */
typedef DiffusionTensor3D<TScalar> InputDiffusionTensor3DType;
typedef DiffusionTensor3D<TScalar> OutputDiffusionTensor3DType;
/** Standard covariant vector type for this class */
typedef CovariantVector<TScalar, NInputDimensions>
InputCovariantVectorType;
typedef CovariantVector<TScalar, NOutputDimensions>
OutputCovariantVectorType;
/** Standard vnl_vector type for this class. */
typedef vnl_vector_fixed<TScalar, NInputDimensions> InputVnlVectorType;
typedef vnl_vector_fixed<TScalar, NOutputDimensions> OutputVnlVectorType;
/** Standard coordinate point type for this class */
typedef Point<TScalar, NInputDimensions> InputPointType;
typedef Point<TScalar, NOutputDimensions> OutputPointType;
/** Base inverse transform type. This type should not be changed to the
* concrete inverse transform type or inheritance would be lost. */
typedef Transform<
TScalar, NOutputDimensions, NInputDimensions> InverseTransformBaseType;
typedef typename InverseTransformBaseType::Pointer
InverseTransformBasePointer;
typedef Matrix<TScalar,
itkGetStaticConstMacro(OutputSpaceDimension),
itkGetStaticConstMacro(InputSpaceDimension)> MatrixType;
typedef Matrix<double,
itkGetStaticConstMacro(OutputSpaceDimension),
itkGetStaticConstMacro(OutputSpaceDimension)>
OutputDirectionMatrix;
typedef Matrix<double,
itkGetStaticConstMacro(InputSpaceDimension),
itkGetStaticConstMacro(InputSpaceDimension)>
InputDirectionMatrix;
typedef Matrix<double,
itkGetStaticConstMacro(OutputSpaceDimension),
itkGetStaticConstMacro(InputSpaceDimension)>
DirectionChangeMatrix;
typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
/** Method to transform a point.
* \warning This method must be thread-safe. See, e.g., its use
* in ResampleImageFilter.
*/
virtual OutputPointType TransformPoint(const InputPointType &) const = 0;
/** Method to transform a vector. */
virtual OutputVectorType TransformVector(const InputVectorType &) const
{
itkExceptionMacro( "TransformVector(const InputVectorType &)"
"is unimplemented for " << this->GetNameOfClass() );
return OutputVectorType();
}
/** Method to transform a vector at a given location.
* For global transforms, \c point is ignored and \c TransformVector( vector )
* is called. Local transforms (e.g. deformation
* field transform) must override and provide required behavior. */
virtual OutputVectorType TransformVector(
const InputVectorType & vector,
const InputPointType & point ) const;
/** Method to transform a vnl_vector. */
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
{
itkExceptionMacro( "TransformVector( const InputVnlVectorType & ) is "
"unimplemented for " << this->GetNameOfClass() );
return OutputVnlVectorType();
}
/** Method to transform a vnl_vector, at a point.
* For global transforms, \c point is ignored and \c TransformVector( vector )
* is called. Local transforms (e.g. deformation
* field transform) must override and provide required behavior. */
virtual OutputVnlVectorType TransformVector(
const InputVnlVectorType & vector,
const InputPointType & point ) const;
/** Method to transform a vector stored in a VectorImage. */
virtual OutputVectorPixelType TransformVector(
const InputVectorPixelType & itkNotUsed(vector) ) const
{
itkExceptionMacro( "TransformVector( const InputVectorPixelType & ) is "
"unimplemented for " << this->GetNameOfClass() );
return OutputVectorPixelType();
}
/** Method to transform a vector stored in a VectorImage, at a point.
* For global transforms, \c point is ignored and \c TransformVector( vector )
* is called. Local transforms (e.g. deformation
* field transform) must override and provide required behavior. */
virtual OutputVectorPixelType TransformVector(
const InputVectorPixelType & vector,
const InputPointType & point ) const;
/** Method to transform a CovariantVector. */
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
{
itkExceptionMacro( "TransformCovariantVector( const InputCovariantVectorType & ) is "
"unimplemented for " << this->GetNameOfClass() );
return OutputCovariantVectorType();
}
/** Method to transform a CovariantVector, using a point. Global transforms
* can ignore the \c point parameter. Local transforms (e.g. deformation
* field transform) must override and provide required behavior.
* By default, \c point is ignored and
* \c TransformCovariantVector(vector) is called */
virtual OutputCovariantVectorType TransformCovariantVector(
const InputCovariantVectorType & vector,
const InputPointType & point ) const;
/** Method to transform a CovariantVector stored in a VectorImage. */
virtual OutputVectorPixelType TransformCovariantVector(
const InputVectorPixelType & itkNotUsed(vector) ) const
{
itkExceptionMacro( "TransformCovariantVector(const InputVectorPixelType &)"
"is unimplemented for " << this->GetNameOfClass() );
return OutputVectorPixelType();
}
/** Method to transform a CovariantVector, using a point. Global transforms
* can ignore the \c point parameter. Local transforms (e.g. deformation
* field transform) must override and provide required behavior.
* By default, \c point is ignored and \c TransformCovariantVector(vector) is
* called */
virtual OutputVectorPixelType TransformCovariantVector(
const InputVectorPixelType & vector,
const InputPointType & point ) const;
/** Method to transform a diffusion tensor */
virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(
const InputDiffusionTensor3DType & itkNotUsed(tensor) )
const
{
itkExceptionMacro(
"TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is "
"unimplemented for " << this->GetNameOfClass() );
return OutputDiffusionTensor3DType();
}
/** Method to transform a diffusion tensor at a point. Global transforms
* can ignore the \c point parameter. Local transforms (e.g. deformation
* field transform) must override and provide required behavior.
* By default, \c point is ignored and \c TransformDiffusionTensor(tensor) is
* called */
virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(
const InputDiffusionTensor3DType & tensor,
const InputPointType & point ) const;
/** Method to transform a diffusion tensor stored in a VectorImage */
virtual OutputVectorPixelType TransformDiffusionTensor3D(
const InputVectorPixelType & itkNotUsed(tensor) ) const
{
itkExceptionMacro(
"TransformDiffusionTensor( const InputVectorPixelType & ) is "
"unimplemented for " << this->GetNameOfClass() );
return OutputVectorPixelType();
}
virtual OutputVectorPixelType TransformDiffusionTensor3D(
const InputVectorPixelType & tensor,
const InputPointType & point ) const;
/** Method to transform a diffusion tensor at a point. Global transforms
* can ignore the \c point parameter. Local transforms (e.g. deformation
* field transform) must override and provide required behavior.
* By default, \c point is ignored and \c TransformSymmetricSecondRankTensor(tensor) is
* called */
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
const InputSymmetricSecondRankTensorType & tensor,
const InputPointType & point ) const;
/** Method to transform a ssr tensor stored in a VectorImage */
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
const InputSymmetricSecondRankTensorType & itkNotUsed(tensor) ) const
{
itkExceptionMacro(
"TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is "
"unimplemented for " << this->GetNameOfClass() );
return OutputSymmetricSecondRankTensorType();
}
/** Method to transform a ssr tensor stored in a VectorImage */
virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(
const InputVectorPixelType & itkNotUsed(tensor) ) const
{
itkExceptionMacro(
"TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is "
"unimplemented for " << this->GetNameOfClass() );
return OutputVectorPixelType();
}
/** Method to transform a diffusion tensor stored in a VectorImage, at
* a point. Global transforms
* can ignore the \c point parameter. Local transforms (e.g. deformation
* field transform) must override and provide required behavior.
* By default, \c point is ignored and \c TransformDiffusionTensor(tensor) is
* called */
virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(
const InputVectorPixelType & tensor,
const InputPointType & point ) const;
/** Set the transformation parameters and update internal transformation.
* SetParameters gives the transform the option to set it's
* parameters by keeping a reference to the parameters, or by
* copying. To force the transform to copy it's parameters call
* SetParametersByValue.
* \sa SetParametersByValue
*/
virtual void SetParameters(const ParametersType &) = 0;
/** Set the transformation 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)
{
this->SetParameters(p);
}
/** Get the Transformation Parameters. */
virtual const ParametersType & GetParameters(void) const
{
return m_Parameters;
}
/** Set the fixed parameters and update internal transformation. */
virtual void SetFixedParameters(const ParametersType &) = 0;
/** Get the Fixed Parameters. */
virtual const ParametersType & GetFixedParameters(void) const
{
return m_FixedParameters;
}
/** Update the transform's parameters by the values in \c update.
* \param update must be of the same length as returned by
* GetNumberOfParameters(). Throw an exception otherwise.
* \param factor is a scalar multiplier for each value in \c update.
* SetParameters is called at the end of this method, to allow the transform
* to perform any required operations on the updated parameters - typically
* a conversion to member variables for use in TransformPoint. */
virtual void UpdateTransformParameters( const DerivativeType & update, TScalar factor = 1.0 );
/** Return the number of local parameters that completely defines the
* Transform at an individual voxel.
* For transforms with local support, this will enable downstream
* computation of the jacobian wrt only the local support region.
* For instance, in the case of a deformation field, this will be equal to
* the number of image dimensions. If it is an affine transform, this will
* be the same as the GetNumberOfParameters().
*/
virtual NumberOfParametersType GetNumberOfLocalParameters(void) const
{
return this->GetNumberOfParameters();
}
/** Return the number of parameters that completely define the Transfom */
virtual NumberOfParametersType GetNumberOfParameters(void) const
{
return this->m_Parameters.Size();
}
/** Returns a boolean indicating whether it is possible or not to compute the
* inverse of this current Transform. If it is possible, then the inverse of
* the transform is returned in the inverseTransform variable passed by the
* user. The inverse is recomputed if this current transform has been
* modified.
* This method is intended to be overriden as needed by derived classes.
*
*/
bool GetInverse( Self *itkNotUsed(inverseTransform) ) const
{
return false;
}
/** Return an inverse of this transform. If the inverse has not been
* implemented, return NULL. The type of the inverse transform
* does not necessarily need to match the type of the forward
* transform. This allows one to return a numeric inverse transform
* instead.
*/
virtual InverseTransformBasePointer GetInverseTransform() const
{
return NULL;
}
/** Generate a platform independent name */
virtual std::string GetTransformTypeAsString() const;
typedef typename Superclass::TransformCategoryType TransformCategoryType;
/** Indicates the category transform.
* e.g. an affine transform, or a local one, e.g. a deformation field.
*/
virtual TransformCategoryType GetTransformCategory() const
{
return Superclass::UnknownTransformCategory;
}
virtual bool IsLinear() const
{
return ( this->GetTransformCategory() == Superclass::Linear );
}
#ifdef ITKV3_COMPATIBILITY
/**
* This function is only here for ITKv3 backwards compatibility.
*
* This is not a thread-safe version for GetJacobian(), because the internal
* class member variable m_Jacobian could be changed for different values
* in different threads.
*
* All derived classes should move the computations of computing a jacobian
* from GetJacobian to ComputeJacobianWithRespectToParameters and then
* use this forwarding function for backwards compatibility.
*/
virtual const JacobianType & GetJacobian(const InputPointType & x) const
{
this->ComputeJacobianWithRespectToParameters(x, m_SharedLocalJacobian);
return m_SharedLocalJacobian;
}
#endif
/**
* Compute the Jacobian of the transformation
*
* This method computes the Jacobian matrix of the transformation
* at a given input point. The rank of the Jacobian will also indicate
* if the transform is invertible at this point.
*
* The Jacobian is be expressed as a matrix of partial derivatives of the
* output point components with respect to the parameters that defined
* the transform:
*
* \f[
*
J=\left[ \begin{array}{cccc}
\frac{\partial x_{1}}{\partial p_{1}} &
\frac{\partial x_{1}}{\partial p_{2}} &
\cdots & \frac{\partial x_{1}}{\partial p_{m}}\\
\frac{\partial x_{2}}{\partial p_{1}} &
\frac{\partial x_{2}}{\partial p_{2}} &
\cdots & \frac{\partial x_{2}}{\partial p_{m}}\\
\vdots & \vdots & \ddots & \vdots \\
\frac{\partial x_{n}}{\partial p_{1}} &
\frac{\partial x_{n}}{\partial p_{2}} &
\cdots & \frac{\partial x_{n}}{\partial p_{m}}
\end{array}\right]
*
* \f]
*
* This is also used for efficient computation of a point-local jacobian
* for dense transforms.
* \c jacobian is assumed to be thread-local variable, otherwise memory corruption
* will most likely occur during multi-threading.
* To avoid repeatitive memory allocation, pass in 'jacobian' with its size
* already set. */
virtual void ComputeJacobianWithRespectToParameters(const InputPointType & itkNotUsed(p), JacobianType & itkNotUsed(jacobian) ) const
{
itkExceptionMacro(
"ComputeJacobianWithRespectToParamters( InputPointType, JacobianType"
" is unimplemented for " << this->GetNameOfClass() );
return;
}
/** This provides the ability to get a local jacobian value
* in a dense/local transform, e.g. DisplacementFieldTransform. For such
* transforms it would be unclear what parameters would refer to.
* Generally, global transforms should return an indentity jacobian
* since there is no change with respect to position. */
virtual void ComputeJacobianWithRespectToPosition(const InputPointType & itkNotUsed(x), JacobianType & itkNotUsed(jacobian) ) const
{
itkExceptionMacro(
"ComputeJacobianWithRespectToPosition( InputPointType, JacobianType"
" is unimplemented for " << this->GetNameOfClass() );
return;
}
/** This provides the ability to get a local jacobian value
* in a dense/local transform, e.g. DisplacementFieldTransform. For such
* transforms it would be unclear what parameters would refer to.
* Generally, global transforms should return an indentity jacobian
* since there is no change with respect to position. */
virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian ) const;
protected:
/**
* Clone the current transform.
* This does a complete copy of the transform
* state to the new transform
*/
virtual typename LightObject::Pointer InternalClone() const;
Transform();
Transform(NumberOfParametersType NumberOfParameters);
virtual ~Transform()
{
}
mutable ParametersType m_Parameters;
mutable ParametersType m_FixedParameters;
OutputDiffusionTensor3DType PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(
const InputDiffusionTensor3DType, const JacobianType ) const;
#ifdef ITKV3_COMPATIBILITY
// This is only needed to provide the old interface that returns a reference to the Jacobian.
// It is NOT thread-safe and should be avoided whenever possible.
mutable JacobianType m_SharedLocalJacobian;
#endif
mutable DirectionChangeMatrix m_DirectionChange;
private:
Transform(const Self &); // purposely not implemented
void operator=(const Self &); // purposely not implemented
template <typename TType>
std::string GetTransformTypeAsString(TType *) const
{
std::string rval("other");
return rval;
}
std::string GetTransformTypeAsString(float *) const
{
std::string rval("float");
return rval;
}
std::string GetTransformTypeAsString(double *) const
{
std::string rval("double");
return rval;
}
};
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkTransform.hxx"
#endif
#endif
|