SimpleITK  1.1.0
sitkTransform.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 sitkTransform_h
19 #define sitkTransform_h
20 
21 #include "sitkCommon.h"
22 #include "sitkExceptionObject.h"
23 #include "sitkImage.h"
24 #include <vector>
25 
26 
27 namespace itk
28 {
29 
30 // Forward declaration for pointer
31 // After ITK_VERSION 4.5 (Actually after June 20th, 2013) the ITK Transform
32 // classes are now templated. This requires forward declarations to be defined
33 // differently.
34 #if ( ( SITK_ITK_VERSION_MAJOR == 4 ) && ( SITK_ITK_VERSION_MINOR < 5 ) )
35 class TransformBase;
36 #else
37 template< typename TScalar > class TransformBaseTemplate;
39 #endif
40 
41 template< typename TScalar, unsigned int NDimension> class CompositeTransform;
42 
43 namespace simple
44 {
45 
46 class PimpleTransformBase;
47 
48 
63 };
64 
65 
85 {
86 public:
87  typedef Transform Self;
88 
91  Transform( void );
92 
97  template<unsigned int NDimension>
99  : m_PimpleTransform( SITK_NULLPTR )
100  {
101  sitkStaticAssert( NDimension == 2 || NDimension == 3, "Only 2D and 3D transforms are supported" );
102  if ( compositeTransform == SITK_NULLPTR )
103  {
104  sitkExceptionMacro( "Unable to construct a null transform!" );
105  }
106  this->InternalInitialization<NDimension>( sitkComposite, compositeTransform );
107  }
108 
109  explicit Transform( itk::TransformBase *transform );
110 
115  Transform( unsigned int dimensions, TransformEnum type);
116 
129  Transform( Image &displacement, TransformEnum type = sitkDisplacementField );
130 
131  virtual ~Transform( void );
132 
139  Transform &operator=( const Transform & );
140  Transform( const Transform & );
154  itk::TransformBase* GetITKBase( void );
155  const itk::TransformBase* GetITKBase( void ) const;
160  unsigned int GetDimension( void ) const;
161 
162  // todo get transform type
163 
167  void SetParameters ( const std::vector<double>& parameters );
168  std::vector<double> GetParameters( void ) const;
174  void SetFixedParameters ( const std::vector<double>& parameters );
175  std::vector<double> GetFixedParameters( void ) const;
178  // Make composition
179  SITK_RETURN_SELF_TYPE_HEADER AddTransform( Transform t );
180 
181  std::vector< double > TransformPoint( const std::vector< double > &point ) const;
182 
183  // write
184  void WriteTransform( const std::string &filename ) const;
185 
186  virtual bool IsLinear() const;
187 
188  virtual void SetIdentity();
189 
200  virtual bool SetInverse();
201 
209  Transform GetInverse() const;
210 
211  std::string ToString( void ) const;
212 
213 
215  virtual std::string GetName() const;
216 
224  void MakeUnique( void );
225 
226 protected:
227 
228 
229  explicit Transform( PimpleTransformBase *pimpleTransform );
230 
231  // this method is called to set the private pimpleTransfrom outside
232  // of the constructor, derived classes can override it of update the
233  // state.
234  virtual void SetPimpleTransform( PimpleTransformBase *pimpleTransform );
235 
236 private:
237 
238  template< unsigned int VDimension>
239  void InternalInitialization( TransformEnum type, itk::TransformBase *base = SITK_NULLPTR );
240 
242  {
245  template< typename TransformType >
246  void operator() ( void ) const
247  {
248  TransformType *t = dynamic_cast<TransformType*>(transform);
249  if (t)
250  {
251  that->InternalInitialization<TransformType>(t);
252  }
253  }
254  };
255 
256 
257  template< class TransformType>
258  void InternalInitialization( TransformType *t );
259  void InternalInitialization( itk::TransformBase *base );
260 
261 
262  template< unsigned int >
263  void InternalBSplineInitialization( Image & img );
264 
265  template< typename TDisplacementType >
266  void InternalDisplacementInitialization( Image & img );
267 
268  template < class TMemberFunctionPointer >
270  {
271  typedef typename ::detail::FunctionTraits<TMemberFunctionPointer>::ClassType ObjectType;
272 
273  template< typename TImageType >
274  TMemberFunctionPointer operator() ( void ) const
275  {
276  return &ObjectType::template InternalDisplacementInitialization< TImageType >;
277  }
278  };
279 
280  // As is the architecture of all SimpleITK pimples,
281  // this pointer should never be null and should always point to a
282  // valid object
283  PimpleTransformBase *m_PimpleTransform;
284 };
285 
286 
287 // read
288 SITKCommon_EXPORT Transform ReadTransform( const std::string &filename );
289 
290 // write
291 SITKCommon_EXPORT void WriteTransform( const Transform &transform, const std::string &filename);
292 
293 }
294 }
295 
296 #endif // sitkTransform_h
itk::simple::Image
The main Image class for SimpleITK.
Definition: sitkImage.h:54
itk::simple::Transform::TransformTryCastVisitor::transform
itk::TransformBase * transform
Definition: sitkTransform.h:243
itk::simple::Transform::Transform
Transform(itk::CompositeTransform< double, NDimension > *compositeTransform)
Construct a SimpleITK Transform from a pointer to an ITK composite transform.
Definition: sitkTransform.h:98
sitkStaticAssert
#define sitkStaticAssert(expr, str)
Definition: sitkMacro.h:126
itk::CompositeTransform
Definition: sitkTransform.h:41
itk::simple::WriteTransform
SITKCommon_EXPORT void WriteTransform(const Transform &transform, const std::string &filename)
itk::simple::sitkBSplineTransform
@ sitkBSplineTransform
Definition: sitkTransform.h:62
itk::simple::Transform::InternalInitialization
void InternalInitialization(TransformEnum type, itk::TransformBase *base=SITK_NULLPTR)
itk::simple::Transform
A simplified wrapper around a variety of ITK transforms.
Definition: sitkTransform.h:84
itk::simple::sitkQuaternionRigid
@ sitkQuaternionRigid
Definition: sitkTransform.h:55
sitkCommon.h
itk::simple::sitkVersorRigid
@ sitkVersorRigid
Definition: sitkTransform.h:57
sitkImage.h
itk::simple::sitkEuler
@ sitkEuler
Definition: sitkTransform.h:53
itk::simple::sitkIdentity
@ sitkIdentity
Definition: sitkTransform.h:49
sitkExceptionObject.h
itk::simple::sitkTranslation
@ sitkTranslation
Definition: sitkTransform.h:50
SITKCommon_EXPORT
#define SITKCommon_EXPORT
Definition: sitkCommon.h:41
itk::simple::sitkScaleLogarithmic
@ sitkScaleLogarithmic
Definition: sitkTransform.h:52
itk::simple::sitkDisplacementField
@ sitkDisplacementField
Definition: sitkTransform.h:61
itk::simple::Transform::DisplacementInitializationMemberFunctionAddressor
Definition: sitkTransform.h:269
itk::simple::Transform::m_PimpleTransform
PimpleTransformBase * m_PimpleTransform
Definition: sitkTransform.h:283
itk::simple::sitkAffine
@ sitkAffine
Definition: sitkTransform.h:59
itk::simple::Transform::DisplacementInitializationMemberFunctionAddressor::ObjectType
::detail::FunctionTraits< TMemberFunctionPointer >::ClassType ObjectType
Definition: sitkTransform.h:271
itk::simple::Transform::TransformTryCastVisitor::that
Transform * that
Definition: sitkTransform.h:244
TransformBase
TransformBaseTemplate< double > TransformBase
itk::simple::sitkComposite
@ sitkComposite
Definition: sitkTransform.h:60
SITK_NULLPTR
#define SITK_NULLPTR
Definition: sitkMacro.h:110
itk::simple::Transform::Self
Transform Self
Definition: sitkTransform.h:87
itk
itk::simple::Transform::TransformTryCastVisitor
Definition: sitkTransform.h:241
itk::simple::sitkScaleSkewVersor
@ sitkScaleSkewVersor
Definition: sitkTransform.h:58
itk::simple::sitkSimilarity
@ sitkSimilarity
Definition: sitkTransform.h:54
itk::simple::sitkVersor
@ sitkVersor
Definition: sitkTransform.h:56
itk::simple::ReadTransform
SITKCommon_EXPORT Transform ReadTransform(const std::string &filename)
itk::simple::sitkScale
@ sitkScale
Definition: sitkTransform.h:51
itk::simple::TransformEnum
TransformEnum
Definition: sitkTransform.h:49
itk::TransformBaseTemplate
Definition: sitkTransform.h:37
sitkExceptionMacro
#define sitkExceptionMacro(x)
Definition: sitkMacro.h:88