File: itkFastMarchingImageFilterBase.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 (280 lines) | stat: -rw-r--r-- 10,014 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*=========================================================================
 *
 *  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 itkFastMarchingImageFilterBase_h
#define itkFastMarchingImageFilterBase_h

#include "itkFastMarchingBase.h"
#include "itkImageRegionConstIteratorWithIndex.h"
#include "itkNeighborhoodIterator.h"
#include "itkArray.h"
#include <bitset>

namespace itk
{
/**
 * \class FastMarchingImageFilterBase
 * \brief Apply the Fast Marching method to solve an Eikonal equation on an image.
 *
 * The speed function can be specified as a speed image or a
 * speed constant. The speed image is set using the method
 * SetInput(). If the speed image is nullptr, a constant speed function
 * is used and is specified using method the SetSpeedConstant().
 *
 * If the speed function is constant and of value one, fast marching results
 * is an approximate distance function from the initial alive points.
 *
 * There are two ways to specify the output image information
 * (LargestPossibleRegion, Spacing, Origin):
 * \li it is copied directly from the input speed image
 * \li it is specified by the user.
 * Default values are used if the user does not specify all the information.
 *
 * The output information is computed as follows.
 *
 * If the speed image is nullptr or if the OverrideOutputInformation is set to
 * true, the output information is set from user specified parameters. These
 * parameters can be specified using methods
 * \li FastMarchingImageFilterBase::SetOutputRegion(),
 * \li FastMarchingImageFilterBase::SetOutputSpacing(),
 * \li FastMarchingImageFilterBase::SetOutputDirection(),
 * \li FastMarchingImageFilterBase::SetOutputOrigin().
 *
 * Else the output information is copied from the input speed image.
 *
 * Implementation of this class is based on Chapter 8 of
 * "Level Set Methods and Fast Marching Methods", J.A. Sethian,
 * Cambridge Press, Second edition, 1999.
 *
 * For an alternative implementation, see itk::FastMarchingImageFilter.
 *
 * \tparam TTraits traits
 *
 * \sa FastMarchingImageFilter
 * \sa ImageFastMarchingTraits
 * \sa ImageFastMarchingTraits2
 *
 * \ingroup ITKFastMarching
 */
template <typename TInput, typename TOutput>
class ITK_TEMPLATE_EXPORT FastMarchingImageFilterBase : public FastMarchingBase<TInput, TOutput>
{
public:
  ITK_DISALLOW_COPY_AND_MOVE(FastMarchingImageFilterBase);

  using Self = FastMarchingImageFilterBase;
  using Superclass = FastMarchingBase<TInput, TOutput>;
  using Pointer = SmartPointer<Self>;
  using ConstPointer = SmartPointer<const Self>;
  using typename Superclass::Traits;

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

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


  using InputImageType = typename Superclass::InputDomainType;
  using InputImagePointer = typename Superclass::InputDomainPointer;
  using typename Superclass::InputPixelType;

  using OutputImageType = typename Superclass::OutputDomainType;
  using OutputImagePointer = typename Superclass::OutputDomainPointer;
  using typename Superclass::OutputPixelType;
  using OutputSpacingType = typename OutputImageType::SpacingType;
  using OutputSizeType = typename OutputImageType::SizeType;
  using OutputRegionType = typename OutputImageType::RegionType;
  using OutputPointType = typename OutputImageType::PointType;
  using OutputDirectionType = typename OutputImageType::DirectionType;

  using NodeType = typename Traits::NodeType;
  using NodePairType = typename Traits::NodePairType;
  using NodePairContainerType = typename Traits::NodePairContainerType;
  using NodePairContainerPointer = typename Traits::NodePairContainerPointer;
  using NodePairContainerConstIterator = typename Traits::NodePairContainerConstIterator;

  using typename Superclass::LabelType;

  static constexpr unsigned int ImageDimension = Traits::ImageDimension;


  using LabelImageType = Image<unsigned char, ImageDimension>;
  using LabelImagePointer = typename LabelImageType::Pointer;

  using ConnectedComponentImageType = Image<unsigned int, ImageDimension>;
  using ConnectedComponentImagePointer = typename ConnectedComponentImageType::Pointer;

  using NeighborhoodIteratorType = NeighborhoodIterator<LabelImageType>;
  using NeighborhoodRadiusType = typename NeighborhoodIteratorType::RadiusType;

  class InternalNodeStructure;


  using InternalNodeStructureArray = FixedArray<InternalNodeStructure, ImageDimension>;

  itkGetModifiableObjectMacro(LabelImage, LabelImageType);

  /** The output largest possible, spacing and origin is computed as follows.
   * If the speed image is nullptr or if the OverrideOutputInformation is true,
   * the output information is set from user specified parameters. These
   * parameters can be specified using methods SetOutputRegion(),
   * SetOutputSpacing(), SetOutputDirection(), and SetOutputOrigin().
   * Else if the speed image is not nullptr, the output information
   * is copied from the input speed image. */
  virtual void
  SetOutputSize(const OutputSizeType & size)
  {
    m_OutputRegion = size;
  }
  virtual OutputSizeType
  GetOutputSize() const
  {
    return m_OutputRegion.GetSize();
  }
  itkSetMacro(OutputRegion, OutputRegionType);
  itkGetConstReferenceMacro(OutputRegion, OutputRegionType);
  itkSetMacro(OutputSpacing, OutputSpacingType);
  itkGetConstReferenceMacro(OutputSpacing, OutputSpacingType);
  itkSetMacro(OutputDirection, OutputDirectionType);
  itkGetConstReferenceMacro(OutputDirection, OutputDirectionType);
  itkSetMacro(OutputOrigin, OutputPointType);
  itkGetConstReferenceMacro(OutputOrigin, OutputPointType);
  itkSetMacro(OverrideOutputInformation, bool);
  itkGetConstReferenceMacro(OverrideOutputInformation, bool);
  itkBooleanMacro(OverrideOutputInformation);

protected:
  FastMarchingImageFilterBase();

  ~FastMarchingImageFilterBase() override = default;

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

  OutputRegionType m_BufferedRegion{};
  NodeType         m_StartIndex{};
  NodeType         m_LastIndex{};

  OutputRegionType    m_OutputRegion{};
  OutputPointType     m_OutputOrigin{};
  OutputSpacingType   m_OutputSpacing{};
  OutputDirectionType m_OutputDirection{};
  bool                m_OverrideOutputInformation{ false };

  /** Generate the output image meta information. */
  void
  GenerateOutputInformation() override;

  void
  EnlargeOutputRequestedRegion(DataObject * output) override;

  LabelImagePointer              m_LabelImage{};
  ConnectedComponentImagePointer m_ConnectedComponentImage{};

  IdentifierType
  GetTotalNumberOfNodes() const override;

  void
  SetOutputValue(OutputImageType * oImage, const NodeType & iNode, const OutputPixelType & iValue) override;

  /** Returns the output value for a given node */
  const OutputPixelType
  GetOutputValue(OutputImageType * oImage, const NodeType & iNode) const override;

  /** Returns the label value for a given node */
  unsigned char
  GetLabelValueForGivenNode(const NodeType & iNode) const override;

  /** Set the label value for a given node */
  void
  SetLabelValueForGivenNode(const NodeType & iNode, const LabelType & iLabel) override;

  /** Update values for the neighbors of a given node */
  void
  UpdateNeighbors(OutputImageType * oImage, const NodeType & iNode) override;

  /** Update value for a given node */
  void
  UpdateValue(OutputImageType * oImage, const NodeType & iNode) override;

  /** Make sure the given node does not violate any topological constraint*/
  bool
  CheckTopology(OutputImageType * oImage, const NodeType & iNode) override;
  void
  InitializeOutput(OutputImageType * oImage) override;

  /** Find the nodes were the front will propagate given a node */
  void
  GetInternalNodesUsed(OutputImageType * oImage, const NodeType & iNode, InternalNodeStructureArray & ioNodesUsed);

  /** Solve the quadratic equation */
  double
  Solve(OutputImageType * oImage, const NodeType & iNode, InternalNodeStructureArray & iNeighbors) const;

  //
  // Functions and variables to check for topology changes (2D/3D only).
  //

  // Functions/data for the 2-D case
  void
  InitializeIndices2D();
  bool
  IsChangeWellComposed2D(const NodeType &) const;
  bool
  IsCriticalC1Configuration2D(const std::bitset<9> &) const;
  bool
  IsCriticalC2Configuration2D(const std::bitset<9> &) const;
  bool
  IsCriticalC3Configuration2D(const std::bitset<9> &) const;
  bool
  IsCriticalC4Configuration2D(const std::bitset<9> &) const;

  Array<unsigned char> m_RotationIndices[4]{};
  Array<unsigned char> m_ReflectionIndices[2]{};

  // Functions/data for the 3-D case
  void
  InitializeIndices3D();
  bool
  IsCriticalC1Configuration3D(const std::bitset<8> &) const;
  unsigned int
  IsCriticalC2Configuration3D(const std::bitset<8> &) const;
  bool
  IsChangeWellComposed3D(const NodeType &) const;

  Array<unsigned char> m_C1Indices[12]{};
  Array<unsigned char> m_C2Indices[8]{};

  // Functions for both 2D/3D cases
  bool
  DoesVoxelChangeViolateWellComposedness(const NodeType &) const;
  bool
  DoesVoxelChangeViolateStrictTopology(const NodeType &) const;

  const InputImageType * m_InputCache{};

private:
};
} // end namespace itk

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

#endif // itkFastMarchingImageFilterBase_h