SimpleITK  1.0.1
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 (Acutally 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 
84 {
85 public:
86  typedef Transform Self;
87 
90  Transform( void );
91 
96  template<unsigned int NDimension>
98  : m_PimpleTransform( NULL )
99  {
100  sitkStaticAssert( NDimension == 2 || NDimension == 3, "Only 2D and 3D transforms are supported" );
101  if ( compositeTransform == NULL )
102  {
103  sitkExceptionMacro( "Unable to construct a null transform!" );
104  }
105  this->InternalInitialization<NDimension>( sitkComposite, compositeTransform );
106  }
107 
108  explicit Transform( itk::TransformBase *transform );
109 
114  Transform( unsigned int dimensions, TransformEnum type);
115 
128  Transform( Image &displacement, TransformEnum type = sitkDisplacementField );
129 
130  virtual ~Transform( void );
131 
138  Transform &operator=( const Transform & );
139  Transform( const Transform & );
153  itk::TransformBase* GetITKBase( void );
154  const itk::TransformBase* GetITKBase( void ) const;
159  unsigned int GetDimension( void ) const;
160 
161  // todo get transform type
162 
166  void SetParameters ( const std::vector<double>& parameters );
167  std::vector<double> GetParameters( void ) const ;
173  void SetFixedParameters ( const std::vector<double>& parameters );
174  std::vector<double> GetFixedParameters( void ) const ;
177  // Make composition
178  SITK_RETURN_SELF_TYPE_HEADER AddTransform( Transform t );
179 
180  std::vector< double > TransformPoint( const std::vector< double > &point ) const;
181 
182  // write
183  void WriteTransform( const std::string &filename ) const;
184 
185  virtual bool IsLinear() const;
186 
187  virtual void SetIdentity();
188 
199  virtual bool SetInverse();
200 
208  Transform GetInverse() const;
209 
210  std::string ToString( void ) const;
211 
212 
214  virtual std::string GetName() const;
215 
223  void MakeUnique( void );
224 
225 protected:
226 
227 
228  explicit Transform( PimpleTransformBase *pimpleTransform );
229 
230  // this method is called to set the private pimpleTransfrom outside
231  // of the constructor, derived classes can override it of update the
232  // state.
233  virtual void SetPimpleTransform( PimpleTransformBase *pimpleTransform );
234 
235 private:
236 
237  template< unsigned int VDimension>
238  void InternalInitialization( TransformEnum type, itk::TransformBase *base = NULL );
239 
241  {
244  template< typename TransformType >
245  void operator() ( void ) const
246  {
247  TransformType *t = dynamic_cast<TransformType*>(transform);
248  if (t)
249  {
250  that->InternalInitialization<TransformType>(t);
251  }
252  }
253  };
254 
255 
256  template< class TransformType>
257  void InternalInitialization( TransformType *t );
258  void InternalInitialization( itk::TransformBase *base );
259 
260 
261  template< unsigned int >
262  void InternalBSplineInitialization( Image & img );
263 
264  template< typename TDisplacementType >
265  void InternalDisplacementInitialization( Image & img );
266 
267  template < class TMemberFunctionPointer >
269  {
270  typedef typename ::detail::FunctionTraits<TMemberFunctionPointer>::ClassType ObjectType;
271 
272  template< typename TImageType >
273  TMemberFunctionPointer operator() ( void ) const
274  {
275  return &ObjectType::template InternalDisplacementInitialization< TImageType >;
276  }
277  };
278 
279  // As is the architecture of all SimpleITK pimples,
280  // this pointer should never be null and should always point to a
281  // valid object
282  PimpleTransformBase *m_PimpleTransform;
283 };
284 
285 
286 // read
287 SITKCommon_EXPORT Transform ReadTransform( const std::string &filename );
288 
289 // write
290 SITKCommon_EXPORT void WriteTransform( const Transform &transform, const std::string &filename);
291 
292 }
293 }
294 
295 #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:97
void InternalInitialization(TransformEnum type, itk::TransformBase *base=NULL)
SITKCommon_EXPORT Transform ReadTransform(const std::string &filename)
SITKCommon_EXPORT void WriteTransform(const Transform &transform, const std::string &filename)
PimpleTransformBase * m_PimpleTransform
A simplified wrapper around a variety of ITK transforms.
Definition: sitkTransform.h:83
#define SITKCommon_EXPORT
Definition: sitkCommon.h:41
The main Image class for SimpleITK.
Definition: sitkImage.h:54
#define sitkStaticAssert(expr, str)
Definition: sitkMacro.h:115
#define sitkExceptionMacro(x)
Definition: sitkMacro.h:89
TransformBaseTemplate< double > TransformBase