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 "sitkPathType.h"
25 #include <vector>
26 
27 
28 namespace itk
29 {
30 
31 template <typename TScalar>
34 
35 #if !defined(SWIG)
36 template <typename TScalar, unsigned int NDimension>
37 class CompositeTransform;
38 #endif
39 
40 namespace simple
41 {
42 
43 class PimpleTransformBase;
44 
45 
47 {
65 };
66 
67 
87 {
88 public:
89  using Self = Transform;
90 
93  Transform();
94 
99  template <unsigned int NDimension>
101  : Transform()
102  {
103  static_assert(NDimension == 2 || NDimension == 3, "Only 2D and 3D transforms are supported");
104  if (compositeTransform == nullptr)
105  {
106  sitkExceptionMacro("Unable to construct a null transform!");
107  }
108  this->InternalInitialization<NDimension>(sitkComposite, compositeTransform);
109  }
110 
111  explicit Transform(itk::TransformBase * transform);
112 
117  Transform(unsigned int dimensions, TransformEnum type);
118 
131  explicit Transform(Image & displacement, TransformEnum type = sitkDisplacementField);
132 
133  virtual ~Transform();
134 
141  Transform &
142  operator=(const Transform &);
143  Transform(const Transform &);
158  GetITKBase();
159  const itk::TransformBase *
160  GetITKBase() const;
165  unsigned int
166  GetDimension() const;
167 
168  // todo get transform type
169 
173  void
174  SetParameters(const std::vector<double> & parameters);
175  std::vector<double>
176  GetParameters() const;
180  unsigned int
181  GetNumberOfParameters() const;
182 
186  void
187  SetFixedParameters(const std::vector<double> & parameters);
188  std::vector<double>
189  GetFixedParameters() const;
193  unsigned int
194  GetNumberOfFixedParameters() const;
195 
200  std::vector<double>
201  TransformPoint(const std::vector<double> & point) const;
202 
214  std::vector<double>
215  TransformVector(const std::vector<double> & vector, const std::vector<double> & point) const;
216 
217  // write
218  void
219  WriteTransform(const std::string & filename) const;
220 
221  virtual bool
222  IsLinear() const;
223 
224  virtual void
225  SetIdentity();
226 
237  virtual bool
238  SetInverse();
239 
247  Transform
248  GetInverse() const;
249 
250  std::string
251  ToString() const;
252 
253 
255  virtual std::string
256  GetName() const;
257 
265  void
266  MakeUnique();
267 
276  GetTransformEnum() const;
277 
278 protected:
279  explicit Transform(PimpleTransformBase * pimpleTransform);
280 
281  // this method is called to set the private pimpleTransform outside
282  // the constructor, derived classes can override it of update the
283  // state.
284  virtual void
285  SetPimpleTransform(std::unique_ptr<PimpleTransformBase> && pimpleTransform);
286 
287 private:
288  template <unsigned int VDimension>
289  void
290  InternalInitialization(TransformEnum type, itk::TransformBase * base = nullptr);
291 
293  {
296  template <typename TransformType>
297  void
298  operator()() const
299  {
300  TransformType * t = dynamic_cast<TransformType *>(transform);
301  if (t)
302  {
303  that->InternalInitialization<TransformType>(t);
304  }
305  }
306  };
307 
308 
309  template <class TransformType>
310  void
311  InternalInitialization(TransformType * t);
312  void
313  InternalInitialization(itk::TransformBase * base);
314 
315 
316  template <unsigned int>
317  void
318  InternalBSplineInitialization(Image & img);
319 
320  template <typename TDisplacementType>
321  void
322  InternalDisplacementInitialization(Image & img);
323 
324  template <class TMemberFunctionPointer>
326  {
327  using ObjectType = typename ::detail::FunctionTraits<TMemberFunctionPointer>::ClassType;
328 
329  template <typename TImageType>
330  TMemberFunctionPointer
331  operator()() const
332  {
333  return &ObjectType::template InternalDisplacementInitialization<TImageType>;
334  }
335  };
336 
337  // As is the architecture of all SimpleITK pimples,
338  // this pointer should never be null and should always point to a
339  // valid object
340  std::unique_ptr<PimpleTransformBase> m_PimpleTransform;
341 };
342 
343 
344 // read
346 ReadTransform(const PathType & filename);
347 
348 // write
350 WriteTransform(const Transform & transform, const PathType & filename);
351 
352 } // namespace simple
353 } // namespace itk
354 
355 #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:294
itk::simple::ReadTransform
SITKCommon_EXPORT Transform ReadTransform(const PathType &filename)
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:100
itk::CompositeTransform
Definition: sitkTransform.h:37
itk::simple::sitkBSplineTransform
@ sitkBSplineTransform
Definition: sitkTransform.h:64
itk::simple::Transform
A simplified wrapper around a variety of ITK transforms.
Definition: sitkTransform.h:86
itk::simple::Transform::TransformTryCastVisitor::operator()
void operator()() const
Definition: sitkTransform.h:298
itk::simple::sitkQuaternionRigid
@ sitkQuaternionRigid
Definition: sitkTransform.h:55
itk::simple::Transform::DisplacementInitializationMemberFunctionAddressor::ObjectType
typename ::detail::FunctionTraits< TMemberFunctionPointer >::ClassType ObjectType
Definition: sitkTransform.h:327
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
sitkPathType.h
itk::simple::Transform::InternalInitialization
void InternalInitialization(TransformEnum type, itk::TransformBase *base=nullptr)
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:63
itk::simple::Transform::DisplacementInitializationMemberFunctionAddressor
Definition: sitkTransform.h:325
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:61
itk::simple::Transform::TransformTryCastVisitor::that
Transform * that
Definition: sitkTransform.h:295
itk::simple::sitkComposite
@ sitkComposite
Definition: sitkTransform.h:62
itk::simple::WriteTransform
SITKCommon_EXPORT void WriteTransform(const Transform &transform, const PathType &filename)
itk::simple::sitkScaleVersor
@ sitkScaleVersor
Definition: sitkTransform.h:60
itk
itk::simple::Transform::TransformTryCastVisitor
Definition: sitkTransform.h:292
itk::simple::sitkScaleSkewVersor
@ sitkScaleSkewVersor
Definition: sitkTransform.h:58
itk::simple::sitkComposeScaleSkewVersor
@ sitkComposeScaleSkewVersor
Definition: sitkTransform.h:59
itk::simple::sitkSimilarity
@ sitkSimilarity
Definition: sitkTransform.h:54
itk::simple::sitkVersor
@ sitkVersor
Definition: sitkTransform.h:56
itk::simple::PathType
std::string PathType
Definition: sitkPathType.h:25
itk::simple::sitkUnknownTransform
@ sitkUnknownTransform
Definition: sitkTransform.h:48
itk::simple::sitkScale
@ sitkScale
Definition: sitkTransform.h:51
itk::simple::Transform::m_PimpleTransform
std::unique_ptr< PimpleTransformBase > m_PimpleTransform
Definition: sitkTransform.h:340
itk::simple::Transform::DisplacementInitializationMemberFunctionAddressor::operator()
TMemberFunctionPointer operator()() const
Definition: sitkTransform.h:331
itk::simple::TransformEnum
TransformEnum
Definition: sitkTransform.h:46
itk::TransformBaseTemplate
Definition: sitkTransform.h:32
sitkExceptionMacro
#define sitkExceptionMacro(x)
Definition: sitkMacro.h:70