Seg3D  2.4
Seg3D is a free volume segmentation and processing tool developed by the NIH Center for Integrative Biomedical Computing at the University of Utah Scientific Computing and Imaging (SCI) Institute.
itkRadialDistortionTransform.h
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2016 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 // File : itkRadialDistortionTransform.h
30 // Author : Pavel A. Koshevoy
31 // Created : 2005/06/03 10:16
32 // Copyright : (C) 2004-2008 University of Utah
33 // Description : A radial distortion transform.
34 
35 #ifndef __itkRadialDistortionTransform_h
36 #define __itkRadialDistortionTransform_h
37 
38 // system includes:
39 #include <iostream>
40 
41 // ITK includes:
42 #include <itkTransform.h>
43 #include <itkExceptionObject.h>
44 #include <itkMacro.h>
45 
46 // local includes:
47 #include <Core/ITKCommon/Transform/itkInverseTransform.h>
48 
49 
50 //----------------------------------------------------------------
51 // itk::RadialDistortionTransform
52 //
53 // Let
54 // A = (a + ta * Rmax - ac)
55 // B = (b + tb * Rmax - bc)
56 // where ta, tb specify percentage of translation along the
57 // a and b axis respectively, and
58 // ac = 0.5 * (a_min + a_max)
59 // bc = 0.5 * (b_min + b_max)
60 // define the center of distortion (specified by a_min, a_max,
61 // b_min, b_max -- the bounding box of some image).
62 //
63 // The transform is defined as
64 // x(a, b) = ac + A * S
65 // y(a, b) = bc + B * S
66 //
67 // where
68 // S = sum(n in [0, N - 1], k[n] * pow(R2 / Rmax2, n));
69 // R2 = A^2 + B^2
70 // Rmax2 = Rmax * Rmax
71 //
72 namespace itk
73 {
74 
75 template <class TScalar = double, unsigned int N = 2>
77 public Transform<TScalar, 2, 2>
78 {
79 public:
80  // standard typedefs:
82  typedef Transform<TScalar, 2, 2> Superclass;
83  typedef SmartPointer<Self> Pointer;
84  typedef SmartPointer<const Self> ConstPointer;
85 
86 
89  typedef typename Superclass::InverseTransformBaseType InverseTransformBaseType;
90  typedef typename InverseTransformBaseType::Pointer InverseTransformBasePointer;
91 
92  // static constant for the number of polynomial coefficients:
93  itkStaticConstMacro(Nk, unsigned int, N);
94 
95  // RTTI:
96  itkTypeMacro(RadialDistortionTransform, Transform);
97 
98  // macro for instantiation through the object factory:
99  itkNewMacro(Self);
100 
102  typedef typename Superclass::ScalarType ScalarType;
103 
105  typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
106 
107  // shortcuts:
108  typedef typename Superclass::ParametersType ParametersType;
109  typedef typename Superclass::JacobianType JacobianType;
110 
111  typedef typename Superclass::InputPointType InputPointType;
112  typedef typename Superclass::OutputPointType OutputPointType;
113 
114  // virtual:
115  virtual
116  OutputPointType TransformPoint(const InputPointType & p) const;
117 
118  // virtual: Inverse transformations:
119  // If y = Transform(x), then x = BackTransform(y);
120  // if no mapping from y to x exists, then an exception is thrown.
121  InputPointType BackTransformPoint(const OutputPointType & y) const;
122 
123  // virtual:
124  virtual
125  void SetFixedParameters(const ParametersType & params)
126  { this->m_FixedParameters = params; }
127 
128  // virtual:
129  virtual
130  const ParametersType & GetFixedParameters() const
131  { return this->m_FixedParameters; }
132 
133  // virtual:
134  virtual
135  void SetParameters(const ParametersType & params)
136  { this->m_Parameters = params; }
137 
138  // virtual:
139  virtual
140  const ParametersType & GetParameters() const
141  { return this->m_Parameters; }
142 
143  // virtual: mumber of parameters that define this transform:
144  virtual
145  NumberOfParametersType GetNumberOfParameters() const
146  { return N + 2; }
147 
148  // virtual:
149 // virtual
150 // const JacobianType & GetJacobian(const InputPointType & point) const;
151  virtual void ComputeJacobianWithRespectToParameters( const InputPointType &, JacobianType & ) const;
152 
153  // virtual: return an inverse of this transform.
154  virtual InverseTransformBasePointer GetInverseTransform() const
155  {
156  typedef InverseTransform<Self> InvTransformType;
157  typename InvTransformType::Pointer inv = InvTransformType::New();
158  inv->SetForwardTransform(this);
159  return inv.GetPointer();
160  }
161 
162  // setup the fixed transform parameters:
163  void setup(// image bounding box expressed in the physical space:
164  const double a_min,
165  const double a_max,
166  const double b_min,
167  const double b_max,
168 
169  // normalization parameter (image radius in physical space):
170  const double Rmax = 0.0)
171  {
172  double & ac_ = this->m_FixedParameters[0];
173  double & bc_ = this->m_FixedParameters[1];
174  double & rmax_ = this->m_FixedParameters[2];
175 
176  // center of distortion:
177  ac_ = 0.5 * (a_min + a_max);
178  bc_ = 0.5 * (b_min + b_max);
179 
180  // setup the normalization parameter:
181  if (Rmax != 0.0)
182  {
183  rmax_ = Rmax;
184  }
185  else
186  {
187  const double w = a_max - a_min;
188  const double h = b_max - b_min;
189  rmax_ = sqrt(w * w + h * h) / 2.0;
190  }
191  }
192 
193  // setup the translation parameters:
194  void setup_translation(// translation is expressed in the physical space:
195  const double ta_Rmax = 0.0,
196  const double tb_Rmax = 0.0)
197  {
198  const double & Rmax = this->m_FixedParameters[2];
199 // assert(Rmax != 0.0);
200  if (Rmax == 0.0)
201  {
202  itkExceptionMacro(<< "Rmax parameter is null");
203  }
204 
205  // store ta,tb as translation relative to Rmax:
206  double & ta = this->m_Parameters[N];
207  double & tb = this->m_Parameters[N + 1];
208  ta = ta_Rmax / Rmax;
209  tb = tb_Rmax / Rmax;
210  }
211 
212  // helper required by BackTransform:
213  // evaluate F = T(x), J = dT/dx (another Jacobian):
214  void eval(const std::vector<ScalarType> & x,
215  std::vector<ScalarType> & F,
216  std::vector<std::vector<ScalarType> > & J) const;
217 
218  // accessors to the fixed normalization parameter:
219  inline const double & GetRmax() const
220  { return this->m_FixedParameters[2]; }
221 
222  // generate a mask of shared parameters:
223  static void setup_shared_params_mask(bool shared, std::vector<bool> & mask)
224  {
225  mask.assign(N + 2, false);
226  for (unsigned int i = 0; i < N; i++)
227  {
228  mask[i] = shared;
229  }
230  }
231 
232 protected:
233  RadialDistortionTransform();
234 
235  // virtual:
236  virtual
237  void PrintSelf(std::ostream & s, Indent indent) const;
238 
239 private:
240  // disable default copy constructor and assignment operator:
241  RadialDistortionTransform(const Self & other);
242  const Self & operator = (const Self & t);
243 
244 }; // class RadialDistortionTransform
245 
246 } // namespace itk
247 
248 
249 #ifndef ITK_MANUAL_INSTANTIATION
250 #include <Core/ITKCommon/Transform/itkRadialDistortionTransform.txx>
251 #endif
252 
253 #endif // __itkRadialDistortionTransform_h
Definition: itkRadialDistortionTransform.h:76
Superclass::NumberOfParametersType NumberOfParametersType
Definition: itkRadialDistortionTransform.h:105
Definition: itkNormalizeImageFilterWithMask.h:48
Superclass::ScalarType ScalarType
Definition: itkRadialDistortionTransform.h:102
Superclass::InverseTransformBaseType InverseTransformBaseType
Definition: itkRadialDistortionTransform.h:89