SimpleITK  
sitkTransform.h
Go to the documentation of this file.
1 /*=========================================================================
2 *
3 * Copyright NumFOCUS
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 template< typename TScalar > class TransformBaseTemplate;
32 
33 #if !defined(SWIG)
34 template< typename TScalar, unsigned int NDimension> class CompositeTransform;
35 #endif
36 
37 namespace simple
38 {
39 
40 class PimpleTransformBase;
41 
42 
60 };
61 
62 
82 {
83 public:
84  using Self = Transform;
85 
88  Transform( );
89 
94  template<unsigned int NDimension>
96  : Transform()
97  {
98  static_assert( NDimension == 2 || NDimension == 3, "Only 2D and 3D transforms are supported" );
99  if ( compositeTransform == nullptr )
100  {
101  sitkExceptionMacro( "Unable to construct a null transform!" );
102  }
103  this->InternalInitialization<NDimension>( sitkComposite, compositeTransform );
104  }
105 
106  explicit Transform( itk::TransformBase *transform );
107 
112  Transform( unsigned int dimensions, TransformEnum type);
113 
126  explicit Transform( Image &displacement, TransformEnum type = sitkDisplacementField );
127 
128  virtual ~Transform( );
129 
136  Transform &operator=( const Transform & );
137  Transform( const Transform & );
151  itk::TransformBase* GetITKBase( );
152  const itk::TransformBase* GetITKBase( ) const;
157  unsigned int GetDimension( ) const;
158 
159  // todo get transform type
160 
164  void SetParameters ( const std::vector<double>& parameters );
165  std::vector<double> GetParameters( ) const;
169  unsigned int GetNumberOfParameters( ) const;
170 
174  void SetFixedParameters ( const std::vector<double>& parameters );
175  std::vector<double> GetFixedParameters( ) const;
179  unsigned int GetNumberOfFixedParameters( ) const;
180 
185  std::vector< double > TransformPoint( const std::vector< double > &point ) const;
186 
198  std::vector< double > TransformVector( const std::vector< double > &vector, const std::vector< double > &point) const;
199 
200  // write
201  void WriteTransform( const std::string &filename ) const;
202 
203  virtual bool IsLinear() const;
204 
205  virtual void SetIdentity();
206 
217  virtual bool SetInverse();
218 
226  Transform GetInverse() const;
227 
228  std::string ToString( ) const;
229 
230 
232  virtual std::string GetName() const;
233 
241  void MakeUnique( );
242 
250  TransformEnum GetTransformEnum() const;
251 
252 protected:
253 
254 
255  explicit Transform( PimpleTransformBase *pimpleTransform );
256 
257  // this method is called to set the private pimpleTransform outside
258  // the constructor, derived classes can override it of update the
259  // state.
260  virtual void SetPimpleTransform(std::unique_ptr<PimpleTransformBase> && pimpleTransform );
261 
262 private:
263 
264  template< unsigned int VDimension>
265  void InternalInitialization( TransformEnum type, itk::TransformBase *base = nullptr );
266 
268  {
271  template< typename TransformType >
272  void operator() ( ) const
273  {
274  TransformType *t = dynamic_cast<TransformType*>(transform);
275  if (t)
276  {
277  that->InternalInitialization<TransformType>(t);
278  }
279  }
280  };
281 
282 
283  template< class TransformType>
284  void InternalInitialization( TransformType *t );
285  void InternalInitialization( itk::TransformBase *base );
286 
287 
288  template< unsigned int >
289  void InternalBSplineInitialization( Image & img );
290 
291  template< typename TDisplacementType >
292  void InternalDisplacementInitialization( Image & img );
293 
294  template < class TMemberFunctionPointer >
296  {
297  using ObjectType = typename ::detail::FunctionTraits<TMemberFunctionPointer>::ClassType;
298 
299  template< typename TImageType >
300  TMemberFunctionPointer operator() ( ) const
301  {
302  return &ObjectType::template InternalDisplacementInitialization< TImageType >;
303  }
304  };
305 
306  // As is the architecture of all SimpleITK pimples,
307  // this pointer should never be null and should always point to a
308  // valid object
309  std::unique_ptr<PimpleTransformBase> m_PimpleTransform;
310 };
311 
312 
313 // read
314 SITKCommon_EXPORT Transform ReadTransform( const std::string &filename );
315 
316 // write
317 SITKCommon_EXPORT void WriteTransform( const Transform &transform, const std::string &filename);
318 
319 }
320 }
321 
322 #endif // sitkTransform_h
itk::simple::Image
The Image class for SimpleITK.
Definition: sitkImage.h:76
itk::simple::Transform::TransformTryCastVisitor::transform
itk::TransformBase * transform
Definition: sitkTransform.h:269
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:95
itk::CompositeTransform
Definition: sitkTransform.h:34
itk::simple::WriteTransform
SITKCommon_EXPORT void WriteTransform(const Transform &transform, const std::string &filename)
itk::simple::sitkBSplineTransform
@ sitkBSplineTransform
Definition: sitkTransform.h:59
itk::simple::Transform
A simplified wrapper around a variety of ITK transforms.
Definition: sitkTransform.h:81
itk::simple::sitkQuaternionRigid
@ sitkQuaternionRigid
Definition: sitkTransform.h:50
itk::simple::Transform::DisplacementInitializationMemberFunctionAddressor::ObjectType
typename ::detail::FunctionTraits< TMemberFunctionPointer >::ClassType ObjectType
Definition: sitkTransform.h:297
sitkCommon.h
itk::simple::sitkVersorRigid
@ sitkVersorRigid
Definition: sitkTransform.h:52
sitkImage.h
itk::simple::sitkEuler
@ sitkEuler
Definition: sitkTransform.h:48
itk::simple::sitkIdentity
@ sitkIdentity
Definition: sitkTransform.h:44
itk::simple::Transform::InternalInitialization
void InternalInitialization(TransformEnum type, itk::TransformBase *base=nullptr)
sitkExceptionObject.h
itk::simple::sitkTranslation
@ sitkTranslation
Definition: sitkTransform.h:45
SITKCommon_EXPORT
#define SITKCommon_EXPORT
Definition: sitkCommon.h:41
itk::simple::sitkScaleLogarithmic
@ sitkScaleLogarithmic
Definition: sitkTransform.h:47
itk::simple::sitkDisplacementField
@ sitkDisplacementField
Definition: sitkTransform.h:58
itk::simple::Transform::DisplacementInitializationMemberFunctionAddressor
Definition: sitkTransform.h:295
itk::point
*par Constraints *The filter requires an image with at least two dimensions and a vector *length of at least The theory supports extension to scalar but *the implementation of the itk vector classes do not **The template parameter TRealType must be floating point(float or double) or *a user-defined "real" numerical type with arithmetic operations defined *sufficient to compute derivatives. **\par Performance *This filter will automatically multithread if run with *SetUsePrincipleComponents
itk::simple::sitkAffine
@ sitkAffine
Definition: sitkTransform.h:56
itk::simple::Transform::TransformTryCastVisitor::that
Transform * that
Definition: sitkTransform.h:270
itk::simple::sitkComposite
@ sitkComposite
Definition: sitkTransform.h:57
itk::simple::sitkScaleVersor
@ sitkScaleVersor
Definition: sitkTransform.h:55
itk
itk::simple::Transform::TransformTryCastVisitor
Definition: sitkTransform.h:267
itk::simple::sitkScaleSkewVersor
@ sitkScaleSkewVersor
Definition: sitkTransform.h:53
itk::simple::sitkComposeScaleSkewVersor
@ sitkComposeScaleSkewVersor
Definition: sitkTransform.h:54
itk::simple::sitkSimilarity
@ sitkSimilarity
Definition: sitkTransform.h:49
itk::simple::sitkVersor
@ sitkVersor
Definition: sitkTransform.h:51
itk::simple::ReadTransform
SITKCommon_EXPORT Transform ReadTransform(const std::string &filename)
itk::simple::sitkUnknownTransform
@ sitkUnknownTransform
Definition: sitkTransform.h:43
itk::simple::sitkScale
@ sitkScale
Definition: sitkTransform.h:46
itk::simple::Transform::m_PimpleTransform
std::unique_ptr< PimpleTransformBase > m_PimpleTransform
Definition: sitkTransform.h:309
itk::simple::TransformEnum
TransformEnum
Definition: sitkTransform.h:43
itk::TransformBaseTemplate
Definition: sitkTransform.h:30
sitkExceptionMacro
#define sitkExceptionMacro(x)
Definition: sitkMacro.h:69