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
28namespace itk
29{
30
31template <typename TScalar>
34
35#if !defined(SWIG)
36template <typename TScalar, unsigned int NDimension>
38#endif
39
40namespace simple
41{
42
43class PimpleTransformBase;
44
45
66
67
87{
88public:
89 using Self = Transform;
90
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 &
145
146
159 const itk::TransformBase *
160 GetITKBase() const;
162
165 unsigned int
167
168 // todo get transform type
169
173 void
174 SetParameters(const std::vector<double> & parameters);
175 std::vector<double>
178
180 unsigned int
182
186 void
187 SetFixedParameters(const std::vector<double> & parameters);
188 std::vector<double>
191
193 unsigned int
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
226
237 virtual bool
239
248 GetInverse() const;
249
250 std::string
251 ToString() const;
252
253
255 virtual std::string
256 GetName() const;
257
265 void
267
277
278protected:
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
287private:
288 template <unsigned int VDimension>
289 void
291
293 {
296 template <typename TransformType>
297 void
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
314
315
316 template <unsigned int>
317 void
319
320 template <typename TDisplacementType>
321 void
323
324 template <class TMemberFunctionPointer>
326 {
327 using ObjectType = typename ::detail::FunctionTraits<TMemberFunctionPointer>::ClassType;
328
329 template <typename TImageType>
330 TMemberFunctionPointer
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
346ReadTransform(const PathType & filename);
347
348// write
350WriteTransform(const Transform & transform, const PathType & filename);
351
352} // namespace simple
353} // namespace itk
354
355#endif // sitkTransform_h
The Image class for SimpleITK.
Definition sitkImage.h:77
A simplified wrapper around a variety of ITK transforms.
Transform GetInverse() const
Return a new inverse transform of the same type as this.
std::unique_ptr< PimpleTransformBase > m_PimpleTransform
std::vector< double > TransformPoint(const std::vector< double > &point) const
void SetFixedParameters(const std::vector< double > &parameters)
Transform(itk::TransformBase *transform)
Transform(Image &displacement, TransformEnum type=sitkDisplacementField)
Use an image to construct a transform.
unsigned int GetDimension() const
Transform(PimpleTransformBase *pimpleTransform)
Transform & operator=(const Transform &)
Copy constructor and assignment operator.
std::string ToString() const
void MakeUnique()
Performs actually coping if needed to make object unique.
virtual void SetPimpleTransform(std::unique_ptr< PimpleTransformBase > &&pimpleTransform)
void SetParameters(const std::vector< double > &parameters)
Transform(const Transform &)
Copy constructor and assignment operator.
Transform(unsigned int dimensions, TransformEnum type)
Construct a specific transformation.
virtual bool SetInverse()
Try to change the current transform to it's inverse.
virtual bool IsLinear() const
virtual std::string GetName() const
const itk::TransformBase * GetITKBase() const
std::vector< double > TransformVector(const std::vector< double > &vector, const std::vector< double > &point) const
unsigned int GetNumberOfParameters() const
std::vector< double > GetFixedParameters() const
void WriteTransform(const std::string &filename) const
itk::TransformBase * GetITKBase()
unsigned int GetNumberOfFixedParameters() const
void InternalBSplineInitialization(Image &img)
void InternalInitialization(TransformEnum type, itk::TransformBase *base=nullptr)
void InternalInitialization(itk::TransformBase *base)
Transform(itk::CompositeTransform< double, NDimension > *compositeTransform)
Construct a SimpleITK Transform from a pointer to an ITK composite transform.
TransformEnum GetTransformEnum() const
Get the TransformEnum of the underlying Transform.
Transform()
By default a 3-d identity transform is constructed.
void InternalDisplacementInitialization(Image &img)
virtual void SetIdentity()
void InternalInitialization(TransformType *t)
std::vector< double > GetParameters() const
std::string PathType
@ sitkComposeScaleSkewVersor
SITKCommon_EXPORT void WriteTransform(const Transform &transform, const PathType &filename)
SITKCommon_EXPORT Transform ReadTransform(const PathType &filename)
*par Constraints *The filter 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
TransformBaseTemplate< double > TransformBase
#define SITKCommon_EXPORT
Definition sitkCommon.h:41
#define sitkExceptionMacro(x)
Definition sitkMacro.h:70
typename ::detail::FunctionTraits< TMemberFunctionPointer >::ClassType ObjectType