SimpleITK  1.2.4
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;
38 typedef TransformBaseTemplate<double> TransformBase;
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;
172  unsigned int GetNumberOfParameters( void ) const;
173 
177  void SetFixedParameters ( const std::vector<double>& parameters );
178  std::vector<double> GetFixedParameters( void ) const;
182  unsigned int GetNumberOfFixedParameters( void ) const;
183 
184  // Make composition
185  SITK_RETURN_SELF_TYPE_HEADER AddTransform( Transform t );
186 
187 
197  SITK_RETURN_SELF_TYPE_HEADER FlattenTransform();
198 
203  std::vector< double > TransformPoint( const std::vector< double > &point ) const;
204 
216  std::vector< double > TransformVector( const std::vector< double > &vector, const std::vector< double > &point) const;
217 
218  // write
219  void WriteTransform( const std::string &filename ) const;
220 
221  virtual bool IsLinear() const;
222 
223  virtual void SetIdentity();
224 
235  virtual bool SetInverse();
236 
244  Transform GetInverse() const;
245 
246  std::string ToString( void ) const;
247 
248 
250  virtual std::string GetName() const;
251 
259  void MakeUnique( void );
260 
261 protected:
262 
263 
264  explicit Transform( PimpleTransformBase *pimpleTransform );
265 
266  // this method is called to set the private pimpleTransfrom outside
267  // of the constructor, derived classes can override it of update the
268  // state.
269  virtual void SetPimpleTransform( PimpleTransformBase *pimpleTransform );
270 
271 private:
272 
273  template< unsigned int VDimension>
274  void InternalInitialization( TransformEnum type, itk::TransformBase *base = SITK_NULLPTR );
275 
277  {
280  template< typename TransformType >
281  void operator() ( void ) const
282  {
283  TransformType *t = dynamic_cast<TransformType*>(transform);
284  if (t)
285  {
286  that->InternalInitialization<TransformType>(t);
287  }
288  }
289  };
290 
291 
292  template< class TransformType>
293  void InternalInitialization( TransformType *t );
294  void InternalInitialization( itk::TransformBase *base );
295 
296 
297  template< unsigned int >
298  void InternalBSplineInitialization( Image & img );
299 
300  template< typename TDisplacementType >
301  void InternalDisplacementInitialization( Image & img );
302 
303  template < class TMemberFunctionPointer >
305  {
306  typedef typename ::detail::FunctionTraits<TMemberFunctionPointer>::ClassType ObjectType;
307 
308  template< typename TImageType >
309  TMemberFunctionPointer operator() ( void ) const
310  {
311  return &ObjectType::template InternalDisplacementInitialization< TImageType >;
312  }
313  };
314 
315  // As is the architecture of all SimpleITK pimples,
316  // this pointer should never be null and should always point to a
317  // valid object
318  PimpleTransformBase *m_PimpleTransform;
319 };
320 
321 
322 // read
323 SITKCommon_EXPORT Transform ReadTransform( const std::string &filename );
324 
325 // write
326 SITKCommon_EXPORT void WriteTransform( const Transform &transform, const std::string &filename);
327 
328 }
329 }
330 
331 #endif // sitkTransform_h
::detail::FunctionTraits< TMemberFunctionPointer >::ClassType ObjectType
Transform(itk::CompositeTransform< double, NDimension > *compositeTransform)
Construct a SimpleITK Transform from a pointer to an ITK composite transform.
Definition: sitkTransform.h:98
SITKCommon_EXPORT Transform ReadTransform(const std::string &filename)
#define SITK_NULLPTR
Definition: sitkMacro.h:110
SITKCommon_EXPORT void WriteTransform(const Transform &transform, const std::string &filename)
PimpleTransformBase * m_PimpleTransform
void InternalInitialization(TransformEnum type, itk::TransformBase *base=SITK_NULLPTR)
A simplified wrapper around a variety of ITK transforms.
Definition: sitkTransform.h:84
#define SITKCommon_EXPORT
Definition: sitkCommon.h:41
The Image class for SimpleITK.
Definition: sitkImage.h:78
#define sitkStaticAssert(expr, str)
Definition: sitkMacro.h:126
#define sitkExceptionMacro(x)
Definition: sitkMacro.h:88
TransformBaseTemplate< double > TransformBase