ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkBSplineBaseTransform.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 __itkBSplineBaseTransform_h
19 #define __itkBSplineBaseTransform_h
20 
21 #include <iostream>
22 #include "itkTransform.h"
23 #include "itkImage.h"
25 
26 namespace itk
27 {
33 template <class TScalarType = double, unsigned int NDimensions = 3,
34  unsigned int VSplineOrder = 3>
35 class ITK_EXPORT BSplineBaseTransform :
36  public Transform<TScalarType, NDimensions, NDimensions>
37 {
38 public:
44 
46  itkTypeMacro( BSplineBaseTransform, Transform );
47 
49  itkStaticConstMacro( SpaceDimension, unsigned int, NDimensions );
50 
52  itkStaticConstMacro( SplineOrder, unsigned int, VSplineOrder );
53 
55  itkCloneMacro(Self);
56 
58  typedef typename Superclass::ScalarType ScalarType;
59 
61  typedef typename Superclass::ParametersType ParametersType;
62 
64  typedef typename Superclass::JacobianType JacobianType;
65 
67  typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
68 
73 
78 
80  typedef vnl_vector_fixed<TScalarType, SpaceDimension> InputVnlVectorType;
81  typedef vnl_vector_fixed<TScalarType, SpaceDimension> OutputVnlVectorType;
82 
87 
107  void SetParameters( const ParametersType & parameters );
108 
131  virtual void SetFixedParameters( const ParametersType & parameters ) = 0;
133 
150  void SetParametersByValue( const ParametersType & parameters );
151 
160  void SetIdentity();
161 
163  virtual const ParametersType & GetParameters() const;
164 
166  virtual const ParametersType & GetFixedParameters() const;
167 
169  typedef typename ParametersType::ValueType ParametersValueType;
173 
185  virtual void SetCoefficientImages( const CoefficientImageArray & images ) = 0;
186 
188  const CoefficientImageArray GetCoefficientImages() const
189  {
190  return this->m_CoefficientImages;
191  }
192 
193  typedef typename Superclass::DerivativeType DerivativeType;
194 
205  virtual void UpdateTransformParameters( const DerivativeType & update, TScalarType factor = 1.0 );
206 
209 
211  typedef typename RegionType::SizeType SizeType;
215 
217  OutputPointType TransformPoint( const InputPointType & point ) const;
218 
221  itkGetStaticConstMacro( SpaceDimension ),
222  itkGetStaticConstMacro( SplineOrder )> WeightsFunctionType;
223 
226 
229 
238  virtual void TransformPoint( const InputPointType & inputPoint, OutputPointType & outputPoint,
239  WeightsType & weights, ParameterIndexArrayType & indices, bool & inside ) const = 0;
240 
242  unsigned long GetNumberOfWeights() const
243  {
244  return m_WeightsFunction->GetNumberOfWeights();
245  }
246 
249  using Superclass::TransformVector;
250  virtual OutputVectorType TransformVector( const InputVectorType & ) const
251  {
252  itkExceptionMacro( << "Method not applicable for deformable transform." );
253  return OutputVectorType();
254  }
256 
259  virtual OutputVnlVectorType TransformVector( const InputVnlVectorType & ) const
260  {
261  itkExceptionMacro( << "Method not applicable for deformable transform. " );
262  return OutputVnlVectorType();
263  }
265 
268  using Superclass::TransformCovariantVector;
269  virtual OutputCovariantVectorType TransformCovariantVector(
270  const InputCovariantVectorType & ) const
271  {
272  itkExceptionMacro( << "Method not applicable for deformable transfrom. " );
273  return OutputCovariantVectorType();
274  }
276 
278  void ComputeJacobianFromBSplineWeightsWithRespectToPosition(
279  const InputPointType &, WeightsType &, ParameterIndexArrayType & ) const;
280 
281  virtual void ComputeJacobianWithRespectToParameters( const InputPointType &, JacobianType & ) const = 0;
282 
283  virtual void ComputeJacobianWithRespectToPosition( const InputPointType &, JacobianType & ) const
284  {
285  itkExceptionMacro( << "ComputeJacobianWithRespectToPosition not yet implemented "
286  "for " << this->GetNameOfClass() );
287  }
288 
290  virtual NumberOfParametersType GetNumberOfParameters() const = 0;
291 
293  virtual NumberOfParametersType GetNumberOfParametersPerDimension() const = 0;
294 
300  virtual bool IsLinear() const
301  {
302  return false;
303  }
304 
305  unsigned int GetNumberOfAffectedWeights() const;
306 
308  typedef typename ImageType::PixelType PixelType;
309 
311 
312 
313 protected:
315  void PrintSelf( std::ostream & os, Indent indent ) const;
316 
318  virtual ~BSplineBaseTransform();
319 
321  itkSetObjectMacro( WeightsFunction, WeightsFunctionType );
322 
324  itkGetObjectMacro( WeightsFunction, WeightsFunctionType );
325 
327  void WrapAsImages();
328 
329 protected:
331  void SetFixedParametersFromTransformDomainInformation() const;
332 
334  virtual void SetFixedParametersGridSizeFromTransformDomainInformation() const = 0;
335 
337  virtual void SetFixedParametersGridOriginFromTransformDomainInformation() const = 0;
338 
340  virtual void SetFixedParametersGridSpacingFromTransformDomainInformation() const = 0;
341 
343  virtual void SetFixedParametersGridDirectionFromTransformDomainInformation() const = 0;
344 
346  virtual void SetCoefficientImageInformationFromFixedParameters() =0;
347 
349  virtual bool InsideValidRegion( ContinuousIndexType & ) const = 0;
350 
351  // NOTE: There is a natural duality between the
352  // two representations of of the coefficients
353  // whereby the m_InternalParametersBuffer is
354  // needed to fit into the optimization framework
355  // and the m_CoefficientImages is needed for
356  // the Jacobian computations. This implementation
357  // is an attempt to remove as much redundancy as possible
358  // and share as much information between the two
359  // instances as possible.
360  //
366 
369 
372 
373 
376 
377 private:
378  BSplineBaseTransform( const Self & ); // purposely not implemented
379  void operator=( const Self & ); // purposely not implemented
380 
381  CoefficientImageArray ArrayOfImagePointerGeneratorHelper() const;
382 }; // class BSplineBaseTransform
383 } // namespace itk
384 
385 // Define instantiation macro for this template.
386 #define ITK_TEMPLATE_BSplineBaseTransform(_, EXPORT, TypeX, TypeY) \
387  namespace itk \
388  { \
389  _( 3 ( class EXPORT BSplineBaseTransform<ITK_TEMPLATE_3 TypeX> ) ) \
390  namespace Templates \
391  { \
392  typedef BSplineBaseTransform<ITK_TEMPLATE_3 TypeX> \
393  BSplineBaseTransform##TypeY; \
394  } \
395  }
396 
397 #if ITK_TEMPLATE_EXPLICIT
398 // template < class TScalarType, unsigned int NDimensions, unsigned int
399 // VSplineOrder >
400 // const unsigned int itk::BSplineBaseTransform<TScalarType,
401 // NDimensions, VSplineOrder >::SpaceDimension;
402 // template < class TScalarType, unsigned int NDimensions, unsigned int
403 // VSplineOrder >
404 // const unsigned int itk::BSplineBaseTransform<TScalarType,
405 // NDimensions, VSplineOrder >::SplineOrder;
406 #include "Templates/itkBSplineBaseTransform+-.h"
407 #endif
408 
409 #if ITK_TEMPLATE_TXX
410 #include "itkBSplineBaseTransform.hxx"
411 #endif
412 
413 #endif /* __itkBSplineBaseTransform_h */
414