ITK  4.3.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::TransformCategoryType TransformCategoryType;
68 
70  typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
71 
76 
81 
83  typedef vnl_vector_fixed<TScalarType, SpaceDimension> InputVnlVectorType;
84  typedef vnl_vector_fixed<TScalarType, SpaceDimension> OutputVnlVectorType;
85 
90 
110  void SetParameters( const ParametersType & parameters );
111 
134  virtual void SetFixedParameters( const ParametersType & parameters ) = 0;
136 
153  void SetParametersByValue( const ParametersType & parameters );
154 
163  void SetIdentity();
164 
166  virtual const ParametersType & GetParameters() const;
167 
169  virtual const ParametersType & GetFixedParameters() const;
170 
172  typedef typename ParametersType::ValueType ParametersValueType;
176 
188  virtual void SetCoefficientImages( const CoefficientImageArray & images ) = 0;
189 
191  const CoefficientImageArray GetCoefficientImages() const
192  {
193  return this->m_CoefficientImages;
194  }
195 
196  typedef typename Superclass::DerivativeType DerivativeType;
197 
208  virtual void UpdateTransformParameters( const DerivativeType & update, TScalarType factor = 1.0 );
209 
212 
214  typedef typename RegionType::SizeType SizeType;
218 
220  OutputPointType TransformPoint( const InputPointType & point ) const;
221 
224  itkGetStaticConstMacro( SpaceDimension ),
225  itkGetStaticConstMacro( SplineOrder )> WeightsFunctionType;
226 
229 
232 
241  virtual void TransformPoint( const InputPointType & inputPoint, OutputPointType & outputPoint,
242  WeightsType & weights, ParameterIndexArrayType & indices, bool & inside ) const = 0;
243 
245  unsigned long GetNumberOfWeights() const
246  {
247  return m_WeightsFunction->GetNumberOfWeights();
248  }
249 
252  using Superclass::TransformVector;
253  virtual OutputVectorType TransformVector( const InputVectorType & ) const
254  {
255  itkExceptionMacro( << "Method not applicable for deformable transform." );
256  return OutputVectorType();
257  }
259 
262  virtual OutputVnlVectorType TransformVector( const InputVnlVectorType & ) const
263  {
264  itkExceptionMacro( << "Method not applicable for deformable transform. " );
265  return OutputVnlVectorType();
266  }
268 
271  using Superclass::TransformCovariantVector;
272  virtual OutputCovariantVectorType TransformCovariantVector(
273  const InputCovariantVectorType & ) const
274  {
275  itkExceptionMacro( << "Method not applicable for deformable transfrom. " );
276  return OutputCovariantVectorType();
277  }
279 
281  void ComputeJacobianFromBSplineWeightsWithRespectToPosition(
282  const InputPointType &, WeightsType &, ParameterIndexArrayType & ) const;
283 
284  virtual void ComputeJacobianWithRespectToParameters( const InputPointType &, JacobianType & ) const = 0;
285 
286  virtual void ComputeJacobianWithRespectToPosition( const InputPointType &, JacobianType & ) const
287  {
288  itkExceptionMacro( << "ComputeJacobianWithRespectToPosition not yet implemented "
289  "for " << this->GetNameOfClass() );
290  }
291 
293  virtual NumberOfParametersType GetNumberOfParameters() const = 0;
294 
296  virtual NumberOfParametersType GetNumberOfParametersPerDimension() const = 0;
297 
298  virtual TransformCategoryType GetTransformCategory() const
299  {
300  return Self::BSpline;
301  }
302 
303  unsigned int GetNumberOfAffectedWeights() const;
304 
306  typedef typename ImageType::PixelType PixelType;
307 
309 
311  virtual NumberOfParametersType GetNumberOfLocalParameters() const
312  {
313  return this->GetNumberOfParameters();
314  }
315 
316 protected:
318  void PrintSelf( std::ostream & os, Indent indent ) const;
319 
321  virtual ~BSplineBaseTransform();
322 
324  itkSetObjectMacro( WeightsFunction, WeightsFunctionType );
325 
327  itkGetObjectMacro( WeightsFunction, WeightsFunctionType );
328 
330  void WrapAsImages();
331 
332 protected:
334  void SetFixedParametersFromTransformDomainInformation() const;
335 
337  virtual void SetFixedParametersGridSizeFromTransformDomainInformation() const = 0;
338 
340  virtual void SetFixedParametersGridOriginFromTransformDomainInformation() const = 0;
341 
343  virtual void SetFixedParametersGridSpacingFromTransformDomainInformation() const = 0;
344 
346  virtual void SetFixedParametersGridDirectionFromTransformDomainInformation() const = 0;
347 
349  virtual void SetCoefficientImageInformationFromFixedParameters() =0;
350 
352  virtual bool InsideValidRegion( ContinuousIndexType & ) const = 0;
353 
354  // NOTE: There is a natural duality between the
355  // two representations of of the coefficients
356  // whereby the m_InternalParametersBuffer is
357  // needed to fit into the optimization framework
358  // and the m_CoefficientImages is needed for
359  // the Jacobian computations. This implementation
360  // is an attempt to remove as much redundancy as possible
361  // and share as much information between the two
362  // instances as possible.
363  //
369 
372 
375 
376 private:
377  BSplineBaseTransform( const Self & ); // purposely not implemented
378  void operator=( const Self & ); // purposely not implemented
379 
380  CoefficientImageArray ArrayOfImagePointerGeneratorHelper() const;
381 }; // class BSplineBaseTransform
382 } // namespace itk
383 
384 #ifndef ITK_MANUAL_INSTANTIATION
385 #include "itkBSplineBaseTransform.hxx"
386 #endif
387 
388 #endif /* __itkBSplineBaseTransform_h */
389