ITK  4.4.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  itkGetModifiableObjectMacro(WeightsFunction, WeightsFunctionType );
327 
329  void WrapAsImages();
330 
331 protected:
333  void SetFixedParametersFromTransformDomainInformation() const;
334 
336  virtual void SetFixedParametersGridSizeFromTransformDomainInformation() const = 0;
337 
339  virtual void SetFixedParametersGridOriginFromTransformDomainInformation() const = 0;
340 
342  virtual void SetFixedParametersGridSpacingFromTransformDomainInformation() const = 0;
343 
345  virtual void SetFixedParametersGridDirectionFromTransformDomainInformation() const = 0;
346 
348  virtual void SetCoefficientImageInformationFromFixedParameters() =0;
349 
351  virtual bool InsideValidRegion( ContinuousIndexType & ) const = 0;
352 
353  // NOTE: There is a natural duality between the
354  // two representations of of the coefficients
355  // whereby the m_InternalParametersBuffer is
356  // needed to fit into the optimization framework
357  // and the m_CoefficientImages is needed for
358  // the Jacobian computations. This implementation
359  // is an attempt to remove as much redundancy as possible
360  // and share as much information between the two
361  // instances as possible.
362  //
368 
371 
374 
375 private:
376  BSplineBaseTransform( const Self & ); // purposely not implemented
377  void operator=( const Self & ); // purposely not implemented
378 
379  CoefficientImageArray ArrayOfImagePointerGeneratorHelper() const;
380 }; // class BSplineBaseTransform
381 } // namespace itk
382 
383 #ifndef ITK_MANUAL_INSTANTIATION
384 #include "itkBSplineBaseTransform.hxx"
385 #endif
386 
387 #endif /* __itkBSplineBaseTransform_h */
388