File: itkPCAShapeSignedDistanceFunction.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 (212 lines) | stat: -rw-r--r-- 7,472 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
/*=========================================================================
 *
 *  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 itkPCAShapeSignedDistanceFunction_h
#define itkPCAShapeSignedDistanceFunction_h

#include "itkShapeSignedDistanceFunction.h"
#include "itkImage.h"
#include "itkInterpolateImageFunction.h"
#include "itkExtrapolateImageFunction.h"
#include "itkTransform.h"

namespace itk
{
/**
 * \class PCAShapeSignedDistanceFunction
 * \brief Compute the signed distance from a N-dimensional PCA Shape.
 *
 * This class computes the signed distance from a N-dimensional shape defined
 * by:
 * (1) a mean signed distance image \f$ M(x) \f$,
 * (2) the first \f$ q \f$ principal components images
 * \f$ P_i(x) \f$ and
 * (3) a transform \f$ T(x) \f$ to define the pose
 * (i.e. position or orientation of the shape).
 *
 * A particular instance of the shape is defined by a set of parameters \f$ p \f$.
 * The first \f$ q \f$ parameters defines the weights applied to each principal components
 * and the remaining parameters is used to define the transform. The user
 * should refer to the documentation of the particular Transform class being used.
 * The first set of parameters are called the ShapeParameters and the remaining
 * parameters the PoseParameters.
 *
 * The method Evaluate( point x ) returns the approximate signed to the
 * shape at point x such that:
 *
 * \f[ s = M(T(x)) + \sum_i^{q} p[i] * \sigma[i] * P_i(T(x)) \f]
 *
 * Where \f$\sigma[i]\f$ are the square root of the eigenvalues. These are defined using
 * method SetPrincipalComponentStandardDeviations().
 *
 * This class is templated over the coordinate representation type
 * (e.g. float or double) and the space dimension.
 *
 * \sa ShapeSignedDistanceFunction
 * \sa Transform
 * \ingroup ImageFunctions
 *
 *
 * \ingroup ITKSignedDistanceFunction
 */
template <typename TCoordRep, unsigned int VSpaceDimension, typename TImage = Image<double, VSpaceDimension>>
class ITK_TEMPLATE_EXPORT PCAShapeSignedDistanceFunction
  : public ShapeSignedDistanceFunction<TCoordRep, VSpaceDimension>
{
public:
  ITK_DISALLOW_COPY_AND_MOVE(PCAShapeSignedDistanceFunction);

  /** Standard class type aliases. */
  using Self = PCAShapeSignedDistanceFunction;
  using Superclass = ShapeSignedDistanceFunction<TCoordRep, VSpaceDimension>;

  using Pointer = SmartPointer<Self>;
  using ConstPointer = SmartPointer<const Self>;

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

  /** New macro for creation of through the object factory. */
  itkNewMacro(Self);

  /** Dimension underlying input image. */
  static constexpr unsigned int SpaceDimension = Superclass::SpaceDimension;

  /** CoordRep type alias support */
  using typename Superclass::CoordRepType;

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

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

  /** Point type alias support */
  using typename Superclass::PointType;

  /** Parameters type alias support */
  using typename Superclass::ParametersType;

  /** Image type alias support */
  using ImageType = TImage;
  using ImagePointer = typename ImageType::Pointer;
  using ImagePointerVector = std::vector<ImagePointer>;

  /** Transform type alias support */
  using TransformType = Transform<CoordRepType, Self::SpaceDimension, Self::SpaceDimension>;

  /** Interpolator type alias support */
  using InterpolatorType = InterpolateImageFunction<ImageType, CoordRepType>;
  using InterpolatorPointer = typename InterpolatorType::Pointer;
  using InterpolatorPointerVector = std::vector<InterpolatorPointer>;

  /** extrapolator type alias support */
  using ExtrapolatorType = ExtrapolateImageFunction<ImageType, CoordRepType>;
  using ExtrapolatorPointer = typename ExtrapolatorType::Pointer;
  using ExtrapolatorPointerVector = std::vector<ExtrapolatorPointer>;

  /** function type alias support */
  using FunctionType = ImageFunction<ImageType, double, CoordRepType>;
  using FunctionPointer = typename FunctionType::Pointer;
  using FunctionPointerVector = std::vector<FunctionPointer>;

  /** Set/Get the number of principal components
   * SetNumberOfPrincipalComponents must be called before SetParameters */
  void
  SetNumberOfPrincipalComponents(unsigned int n);

  itkGetConstMacro(NumberOfPrincipalComponents, unsigned int);

  /** Set/Get the mean image. */
  itkSetObjectMacro(MeanImage, ImageType);
  itkGetModifiableObjectMacro(MeanImage, ImageType);

  /** Set/Get the principal component images. */
  void
  SetPrincipalComponentImages(ImagePointerVector v)
  {
    m_PrincipalComponentImages = v;
  }
  //  ImagePointerVector & GetPrincipalComponentImages()
  //    { return m_PrincipalComponentImages; }

  /** Set/Get the principal component standard deviations. These values corresponds
   * to the square root of the eigenvalues of the principal components. */
  itkSetMacro(PrincipalComponentStandardDeviations, ParametersType);
  itkGetConstMacro(PrincipalComponentStandardDeviations, ParametersType);

  /** Set/Get transform. */
  itkSetObjectMacro(Transform, TransformType);
  itkGetModifiableObjectMacro(Transform, TransformType);

  /** A PCAShape is defined by a set of shape and pose parameters. */
  void
  SetParameters(const ParametersType &) override;

  unsigned int
  GetNumberOfShapeParameters() const override
  {
    return m_NumberOfPrincipalComponents;
  }
  unsigned int
  GetNumberOfPoseParameters() const override
  {
    return m_Transform ? m_Transform->GetNumberOfParameters() : 0;
  }

  /** Evaluate the signed distance from a shape at a given position. */
  OutputType
  Evaluate(const PointType & point) const override;

  /** Initialize must be called before the first call of
   Evaluate() to allow the class to validate any inputs. */
  void
  Initialize() override;

protected:
  PCAShapeSignedDistanceFunction();
  ~PCAShapeSignedDistanceFunction() override = default;

  void
  PrintSelf(std::ostream & os, Indent indent) const override;

private:
  /** intrinsic data members */
  unsigned int m_NumberOfPrincipalComponents{};
  unsigned int m_NumberOfTransformParameters{};

  ImagePointer       m_MeanImage{};
  ImagePointerVector m_PrincipalComponentImages{};
  ParametersType     m_PrincipalComponentStandardDeviations{};

  /** transform and interpolator/extrapolator for image interpolation */
  typename TransformType::Pointer m_Transform{};

  InterpolatorPointerVector m_Interpolators{};
  ExtrapolatorPointerVector m_Extrapolators{};

  /** shape and pose parameters */
  ParametersType m_WeightOfPrincipalComponents{};
  ParametersType m_TransformParameters{};
};
} // end namespace itk

#ifndef ITK_MANUAL_INSTANTIATION
#  include "itkPCAShapeSignedDistanceFunction.hxx"
#endif

#endif