File: itkGaussianInterpolateImageFunction.h

package info (click to toggle)
insighttoolkit5 5.4.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 704,384 kB
  • sloc: cpp: 783,592; ansic: 628,724; xml: 44,704; fortran: 34,250; python: 22,874; sh: 4,078; pascal: 2,636; lisp: 2,158; makefile: 464; yacc: 328; asm: 205; perl: 203; lex: 146; tcl: 132; javascript: 98; csh: 81
file content (215 lines) | stat: -rw-r--r-- 6,102 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*=========================================================================
 *
 *  Copyright NumFOCUS
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         https://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

#ifndef itkGaussianInterpolateImageFunction_h
#define itkGaussianInterpolateImageFunction_h

#include "itkInterpolateImageFunction.h"

#include "itkConceptChecking.h"
#include "itkFixedArray.h"
#include "vnl/vnl_erf.h"

namespace itk
{

/**
 * \class GaussianInterpolateImageFunction
 * \brief Evaluates the Gaussian interpolation of an image.
 *
 * This class defines an N-dimensional Gaussian interpolation function using
 * the vnl error function.  The two parameters associated with this function
 * are:
 *   1. Sigma - a scalar array of size ImageDimension determining the width
 *      of the interpolation function.
 *   2. Alpha - a scalar specifying the cutoff distance over which the function
 *      is calculated.
 *
 * This work was originally described in the Insight Journal article:
 * P. Yushkevich, N. Tustison, J. Gee, Gaussian interpolation.
 * \sa{https://www.insight-journal.org/browse/publication/705}
 *
 * \author Paul Yushkevich
 * \author Nick Tustison
 *
 * \ingroup ITKImageFunction
 */

template <typename TInputImage, typename TCoordRep = double>
class ITK_TEMPLATE_EXPORT GaussianInterpolateImageFunction : public InterpolateImageFunction<TInputImage, TCoordRep>
{
public:
  ITK_DISALLOW_COPY_AND_MOVE(GaussianInterpolateImageFunction);

  /** Standard class type aliases. */
  using Self = GaussianInterpolateImageFunction;
  using Superclass = InterpolateImageFunction<TInputImage, TCoordRep>;
  using Pointer = SmartPointer<Self>;
  using ConstPointer = SmartPointer<const Self>;

  /** \see LightObject::GetNameOfClass() */
  itkOverrideGetNameOfClassMacro(GaussianInterpolateImageFunction);

  /** Method for creation through the object factory. */
  itkNewMacro(Self);

  /** ImageDimension constant. */
  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;


  /** OutputType type alias support */
  using typename Superclass::OutputType;

  /** InputImageType type alias support */
  using typename Superclass::InputImageType;

  /** RealType type alias support */
  using typename Superclass::RealType;

  /** Index type alias support */
  using typename Superclass::IndexType;

  /** Size type alias support */
  using typename Superclass::SizeType;

  /** ContinuousIndex type alias support */
  using typename Superclass::ContinuousIndexType;

  /** Array type alias support */
  using ArrayType = FixedArray<RealType, ImageDimension>;

  /** Set input image. */
  void
  SetInputImage(const TInputImage * image) override
  {
    Superclass::SetInputImage(image);
    this->ComputeBoundingBox();
  }

  /** Set/Get sigma. */
  virtual void
  SetSigma(const ArrayType s)
  {
    if (this->m_Sigma != s)
    {
      this->m_Sigma = s;
      this->ComputeBoundingBox();
      this->Modified();
    }
  }
  virtual void
  SetSigma(RealType * s)
  {
    ArrayType sigma;
    for (unsigned int d = 0; d < ImageDimension; ++d)
    {
      sigma[d] = s[d];
    }
    this->SetSigma(sigma);
  }
  itkGetConstMacro(Sigma, ArrayType);

  /** Set/Get alpha. */
  virtual void
  SetAlpha(const RealType a)
  {
    if (Math::NotExactlyEquals(this->m_Alpha, a))
    {
      this->m_Alpha = a;
      this->ComputeBoundingBox();
      this->Modified();
    }
  }
  itkGetConstMacro(Alpha, RealType);

  /** Set/Get sigma and alpha. */
  virtual void
  SetParameters(RealType * sigma, RealType alpha)
  {
    this->SetSigma(sigma);
    this->SetAlpha(alpha);
  }

  /** Evaluate at the given index. */
  OutputType
  EvaluateAtContinuousIndex(const ContinuousIndexType & cindex) const override
  {
    return this->EvaluateAtContinuousIndex(cindex, nullptr);
  }

  SizeType
  GetRadius() const override;

protected:
  GaussianInterpolateImageFunction();
  ~GaussianInterpolateImageFunction() override = default;
  void
  PrintSelf(std::ostream & os, Indent indent) const override;

  virtual void
  ComputeBoundingBox();

  using RegionType = ImageRegion<ImageDimension>;

  /** Compute the region which we need to loop over. */
  RegionType
  ComputeInterpolationRegion(const ContinuousIndexType &) const;

  virtual void
  ComputeErrorFunctionArray(const RegionType &     region,
                            unsigned int           dimension,
                            RealType               cindex,
                            vnl_vector<RealType> & erfArray,
                            vnl_vector<RealType> & gerfArray,
                            bool                   evaluateGradient = false) const;

  /** Set/Get the bounding box starting point. */
  itkSetMacro(BoundingBoxStart, ArrayType);
  itkGetConstMacro(BoundingBoxStart, ArrayType);

  /** Set/Get the bounding box end point. */
  itkSetMacro(BoundingBoxEnd, ArrayType);
  itkGetConstMacro(BoundingBoxEnd, ArrayType);

  /** Set/Get the cut-off distance. */
  itkSetMacro(CutOffDistance, ArrayType);
  itkGetConstMacro(CutOffDistance, ArrayType);


private:
  /** Evaluate function value. */
  virtual OutputType
  EvaluateAtContinuousIndex(const ContinuousIndexType &, OutputType *) const;

  ArrayType m_Sigma{};
  RealType  m_Alpha{};

  ArrayType m_BoundingBoxStart{};
  ArrayType m_BoundingBoxEnd{};
  ArrayType m_ScalingFactor{};
  ArrayType m_CutOffDistance{};
};

} // end namespace itk

#ifndef ITK_MANUAL_INSTANTIATION
#  include "itkGaussianInterpolateImageFunction.hxx"
#  include "itkMath.h"
#endif

#endif