SimpleITK  2.1.0.dev79
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 
59 };
60 
61 
81 {
82 public:
83  using Self = Transform;
84 
87  Transform( );
88 
93  template<unsigned int NDimension>
95  : m_PimpleTransform( nullptr )
96  {
97  static_assert( NDimension == 2 || NDimension == 3, "Only 2D and 3D transforms are supported" );
98  if ( compositeTransform == nullptr )
99  {
100  sitkExceptionMacro( "Unable to construct a null transform!" );
101  }
102  this->InternalInitialization<NDimension>( sitkComposite, compositeTransform );
103  }
104 
105  explicit Transform( itk::TransformBase *transform );
106 
111  Transform( unsigned int dimensions, TransformEnum type);
112 
125  explicit Transform( Image &displacement, TransformEnum type = sitkDisplacementField );
126 
127  virtual ~Transform( );
128 
135  Transform &operator=( const Transform & );
136  Transform( const Transform & );
150  itk::TransformBase* GetITKBase( );
151  const itk::TransformBase* GetITKBase( ) const;
156  unsigned int GetDimension( ) const;
157 
158  // todo get transform type
159 
163  void SetParameters ( const std::vector<double>& parameters );
164  std::vector<double> GetParameters( ) const;
168  unsigned int GetNumberOfParameters( ) const;
169 
173  void SetFixedParameters ( const std::vector<double>& parameters );
174  std::vector<double> GetFixedParameters( ) const;
178  unsigned int GetNumberOfFixedParameters( ) const;
179 
184  std::vector< double > TransformPoint( const std::vector< double > &point ) const;
185 
197  std::vector< double > TransformVector( const std::vector< double > &vector, const std::vector< double > &point) const;
198 
199  // write
200  void WriteTransform( const std::string &filename ) const;
201 
202  virtual bool IsLinear() const;
203 
204  virtual void SetIdentity();
205 
216  virtual bool SetInverse();
217 
225  Transform GetInverse() const;
226 
227  std::string ToString( ) const;
228 
229 
231  virtual std::string GetName() const;
232 
240  void MakeUnique( );
241 
249  TransformEnum GetTransformEnum() const;
250 
251 protected:
252 
253 
254  explicit Transform( PimpleTransformBase *pimpleTransform );
255 
256  // this method is called to set the private pimpleTransform outside
257  // of the constructor, derived classes can override it of update the
258  // state.
259  virtual void SetPimpleTransform( PimpleTransformBase *pimpleTransform );
260 
261 private:
262 
263  template< unsigned int VDimension>
264  void InternalInitialization( TransformEnum type, itk::TransformBase *base = nullptr );
265 
267  {
270  template< typename TransformType >
271  void operator() ( ) const
272  {
273  TransformType *t = dynamic_cast<TransformType*>(transform);
274  if (t)
275  {
276  that->InternalInitialization<TransformType>(t);
277  }
278  }
279  };
280 
281 
282  template< class TransformType>
283  void InternalInitialization( TransformType *t );
284  void InternalInitialization( itk::TransformBase *base );
285 
286 
287  template< unsigned int >
288  void InternalBSplineInitialization( Image & img );
289 
290  template< typename TDisplacementType >
291  void InternalDisplacementInitialization( Image & img );
292 
293  template < class TMemberFunctionPointer >
295  {
296  using ObjectType = typename ::detail::FunctionTraits<TMemberFunctionPointer>::ClassType;
297 
298  template< typename TImageType >
299  TMemberFunctionPointer operator() ( ) const
300  {
301  return &ObjectType::template InternalDisplacementInitialization< TImageType >;
302  }
303  };
304 
305  // As is the architecture of all SimpleITK pimples,
306  // this pointer should never be null and should always point to a
307  // valid object
308  PimpleTransformBase *m_PimpleTransform;
309 };
310 
311 
312 // read
313 SITKCommon_EXPORT Transform ReadTransform( const std::string &filename );
314 
315 // write
316 SITKCommon_EXPORT void WriteTransform( const Transform &transform, const std::string &filename);
317 
318 }
319 }
320 
321 #endif // sitkTransform_h
itk::simple::Image
The Image class for SimpleITK.
Definition: sitkImage.h:75
itk::simple::Transform::TransformTryCastVisitor::transform
itk::TransformBase * transform
Definition: sitkTransform.h:268
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:94
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:58
itk::simple::Transform
A simplified wrapper around a variety of ITK transforms.
Definition: sitkTransform.h:80
itk::simple::sitkQuaternionRigid
@ sitkQuaternionRigid
Definition: sitkTransform.h:50
itk::simple::Transform::DisplacementInitializationMemberFunctionAddressor::ObjectType
typename ::detail::FunctionTraits< TMemberFunctionPointer >::ClassType ObjectType
Definition: sitkTransform.h:296
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:57
itk::simple::Transform::DisplacementInitializationMemberFunctionAddressor
Definition: sitkTransform.h:294
itk::simple::Transform::m_PimpleTransform
PimpleTransformBase * m_PimpleTransform
Definition: sitkTransform.h:308
itk::simple::sitkAffine
@ sitkAffine
Definition: sitkTransform.h:55
itk::simple::Transform::TransformTryCastVisitor::that
Transform * that
Definition: sitkTransform.h:269
itk::simple::sitkComposite
@ sitkComposite
Definition: sitkTransform.h:56
itk::simple::sitkScaleVersor
@ sitkScaleVersor
Definition: sitkTransform.h:54
itk
itk::simple::Transform::TransformTryCastVisitor
Definition: sitkTransform.h:266
itk::simple::sitkScaleSkewVersor
@ sitkScaleSkewVersor
Definition: sitkTransform.h:53
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::TransformEnum
TransformEnum
Definition: sitkTransform.h:43
itk::TransformBaseTemplate
Definition: sitkTransform.h:30
sitkExceptionMacro
#define sitkExceptionMacro(x)
Definition: sitkMacro.h:71