ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkLevelSetEvolution.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 itkLevelSetEvolution_h
19 #define itkLevelSetEvolution_h
20 
22 #include "itkLevelSetDenseImage.h"
23 
26 
29 
32 
35 
36 namespace itk
37 {
47 template< typename TEquationContainer, typename TLevelSet >
48 class ITK_TEMPLATE_EXPORT LevelSetEvolution
49 {};
50 
51 template< typename TEquationContainer, typename TImage >
52 class ITK_TEMPLATE_EXPORT LevelSetEvolution< TEquationContainer,
53  LevelSetDenseImage< TImage > > :
54  public LevelSetEvolutionBase< TEquationContainer, LevelSetDenseImage< TImage > >
55 {
56 public:
57  ITK_DISALLOW_COPY_AND_ASSIGN(LevelSetEvolution);
58 
60 
65 
67  itkNewMacro( Self );
68 
71 
72  using EquationContainerType = typename Superclass::EquationContainerType;
73  using EquationContainerPointer = typename Superclass::EquationContainerPointer;
74  using TermContainerType = typename Superclass::TermContainerType;
75  using TermContainerPointer = typename Superclass::TermContainerPointer;
76 
77  using TermType = typename Superclass::TermType;
78  using TermPointer = typename Superclass::TermPointer;
79 
80  using InputImageType = typename Superclass::InputImageType;
81  using InputImagePixelType = typename Superclass::InputImagePixelType;
82  using InputImageConstPointer = typename Superclass::InputImageConstPointer;
83  using InputImageRegionType = typename Superclass::InputImageRegionType;
84  using InputPixelRealType = typename Superclass::InputPixelRealType;
85 
86  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
87 
88  using LevelSetContainerType = typename Superclass::LevelSetContainerType;
89 
90  using LevelSetIdentifierType = typename Superclass::LevelSetIdentifierType;
91 
93 
94  using LevelSetOutputType = typename Superclass::LevelSetOutputType;
95  using LevelSetOutputRealType = typename Superclass::LevelSetOutputRealType;
96  using LevelSetDataType = typename Superclass::LevelSetDataType;
97 
98  using IdListType = typename Superclass::IdListType;
99  using IdListIterator = typename Superclass::IdListIterator;
100  using IdListConstIterator = typename Superclass::IdListConstIterator;
101  using IdListImageType = typename Superclass::IdListImageType;
102  using CacheImageType = typename Superclass::CacheImageType;
103  using DomainMapImageFilterType = typename Superclass::DomainMapImageFilterType;
104 
105  using StoppingCriterionType = typename Superclass::StoppingCriterionType;
106  using StoppingCriterionPointer = typename Superclass::StoppingCriterionPointer;
107 
110 
113 
115 
117 
119 
121  void SetNumberOfWorkUnits( const ThreadIdType threads );
122 
124  ThreadIdType GetNumberOfWorkUnits() const;
125 
126  ~LevelSetEvolution() override = default;
127 
128 protected:
130 
133  void AllocateUpdateBuffer() override;
134 
136  void ComputeIteration() override;
137 
139  void ComputeTimeStepForNextIteration() override;
140 
142  void UpdateLevelSets() override;
143 
145  void UpdateEquations() override;
146 
148  void ReinitializeToSignedDistance();
149 
150  typename LevelSetContainerType::Pointer m_UpdateBuffer;
151 
153  using SplitLevelSetComputeIterationThreaderType = LevelSetEvolutionComputeIterationThreader< LevelSetType, ThreadedImageRegionPartitioner< TImage::ImageDimension >, Self >;
154  typename SplitLevelSetComputeIterationThreaderType::Pointer m_SplitLevelSetComputeIterationThreader;
155 
156  using DomainMapConstIteratorType = typename DomainMapImageFilterType::DomainMapType::const_iterator;
158  friend class LevelSetEvolutionComputeIterationThreader< LevelSetType, ThreadedDomainMapPartitionerType, Self >;
159  using SplitDomainMapComputeIterationThreaderType = LevelSetEvolutionComputeIterationThreader< LevelSetType, ThreadedDomainMapPartitionerType, Self >;
160  typename SplitDomainMapComputeIterationThreaderType::Pointer m_SplitDomainMapComputeIterationThreader;
161 
162  friend class LevelSetEvolutionUpdateLevelSetsThreader< LevelSetType, ThreadedImageRegionPartitioner< TImage::ImageDimension >, Self >;
163  using SplitLevelSetUpdateLevelSetsThreaderType = LevelSetEvolutionUpdateLevelSetsThreader< LevelSetType, ThreadedImageRegionPartitioner< TImage::ImageDimension >, Self >;
164  typename SplitLevelSetUpdateLevelSetsThreaderType::Pointer m_SplitLevelSetUpdateLevelSetsThreader;
165 
167  const IdListType * m_IdListToProcessWhenThreading;
168 };
169 
170 
171 template< typename TEquationContainer, typename TOutput, unsigned int VDimension >
172 class ITK_TEMPLATE_EXPORT LevelSetEvolution< TEquationContainer, WhitakerSparseLevelSetImage< TOutput, VDimension > > :
173  public LevelSetEvolutionBase< TEquationContainer, WhitakerSparseLevelSetImage< TOutput, VDimension > >
174 {
175 public:
176  ITK_DISALLOW_COPY_AND_ASSIGN(LevelSetEvolution);
177 
179 
184 
186  itkNewMacro( Self );
187 
189  itkTypeMacro( LevelSetEvolution, LevelSetEvolutionBase );
190 
191  using EquationContainerType = typename Superclass::EquationContainerType;
192  using EquationContainerPointer = typename Superclass::EquationContainerPointer;
193  using TermContainerType = typename Superclass::TermContainerType;
194  using TermContainerPointer = typename Superclass::TermContainerPointer;
195 
196  using TermType = typename Superclass::TermType;
197  using TermPointer = typename Superclass::TermPointer;
198 
199  using InputImageType = typename Superclass::InputImageType;
200  using InputImagePixelType = typename Superclass::InputImagePixelType;
201  using InputImageConstPointer = typename Superclass::InputImageConstPointer;
202  using InputImageRegionType = typename Superclass::InputImageRegionType;
203  using InputPixelRealType = typename Superclass::InputPixelRealType;
204 
205  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
206 
207  using LevelSetContainerType = typename Superclass::LevelSetContainerType;
208  using LevelSetIdentifierType = typename Superclass::LevelSetIdentifierType;
209 
210  using LevelSetInputType = typename Superclass::LevelSetInputType;
211  using LevelSetOutputType = typename Superclass::LevelSetOutputType;
212  using LevelSetOutputRealType = typename Superclass::LevelSetOutputRealType;
213  using LevelSetDataType = typename Superclass::LevelSetDataType;
214 
216 
219 
220 
221  using IdListType = typename Superclass::IdListType;
222  using IdListIterator = typename Superclass::IdListIterator;
223  using IdListImageType = typename Superclass::IdListImageType;
224  using CacheImageType = typename Superclass::CacheImageType;
225  using DomainMapImageFilterType = typename Superclass::DomainMapImageFilterType;
226 
227  using StoppingCriterionType = typename Superclass::StoppingCriterionType;
228  using StoppingCriterionPointer = typename Superclass::StoppingCriterionPointer;
229 
231 
234 
236  void SetNumberOfWorkUnits( const ThreadIdType threads );
237 
239  ThreadIdType GetNumberOfWorkUnits() const;
240 
241 protected:
243  ~LevelSetEvolution() override;
244 
245  using NodePairType = std::pair< LevelSetInputType, LevelSetOutputType >;
246 
247  // For sparse case, the update buffer needs to be the size of the active layer
248  std::map< IdentifierType, LevelSetLayerType* > m_UpdateBuffer;
249 
252  void AllocateUpdateBuffer() override;
253 
255  void ComputeIteration() override;
256 
258  void ComputeTimeStepForNextIteration() override;
259 
261  void UpdateLevelSets() override;
262 
264  void UpdateEquations() override;
265 
269  typename SplitLevelSetComputeIterationThreaderType::Pointer m_SplitLevelSetComputeIterationThreader;
270 };
271 
272 
273 // Shi
274 template< typename TEquationContainer, unsigned int VDimension >
275 class ITK_TEMPLATE_EXPORT LevelSetEvolution<
276  TEquationContainer,
277  ShiSparseLevelSetImage< VDimension > > :
278 public LevelSetEvolutionBase< TEquationContainer, ShiSparseLevelSetImage< VDimension > >
279 {
280 public:
281  ITK_DISALLOW_COPY_AND_ASSIGN(LevelSetEvolution);
282 
284 
289 
291  itkNewMacro( Self );
292 
294  itkTypeMacro( LevelSetEvolution, LevelSetEvolutionBase );
295 
296  using EquationContainerType = typename Superclass::EquationContainerType;
297  using EquationContainerPointer = typename Superclass::EquationContainerPointer;
298  using TermContainerType = typename Superclass::TermContainerType;
299  using TermContainerPointer = typename Superclass::TermContainerPointer;
300 
301  using TermType = typename Superclass::TermType;
302  using TermPointer = typename Superclass::TermPointer;
303 
304  using InputImageType = typename Superclass::InputImageType;
305  using InputImagePixelType = typename Superclass::InputImagePixelType;
306  using InputImageConstPointer = typename Superclass::InputImageConstPointer;
307  using InputImageRegionType = typename Superclass::InputImageRegionType;
308  using InputPixelRealType = typename Superclass::InputPixelRealType;
309 
310  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
311 
312  using LevelSetContainerType = typename Superclass::LevelSetContainerType;
313  using LevelSetIdentifierType = typename Superclass::LevelSetIdentifierType;
314 
315  using LevelSetInputType = typename Superclass::LevelSetInputType;
316  using LevelSetOutputType = typename Superclass::LevelSetOutputType;
317  using LevelSetOutputRealType = typename Superclass::LevelSetOutputRealType;
318  using LevelSetDataType = typename Superclass::LevelSetDataType;
319 
321 
324 
325 
326  using IdListType = typename Superclass::IdListType;
327  using IdListIterator = typename Superclass::IdListIterator;
328  using IdListImageType = typename Superclass::IdListImageType;
329  using CacheImageType = typename Superclass::CacheImageType;
330  using DomainMapImageFilterType = typename Superclass::DomainMapImageFilterType;
331 
332  using StoppingCriterionType = typename Superclass::StoppingCriterionType;
333  using StoppingCriterionPointer = typename Superclass::StoppingCriterionPointer;
334 
336 
339 
340  LevelSetEvolution() = default;
341  ~LevelSetEvolution() override = default;
342 
343 protected:
344 
346  void UpdateLevelSets() override;
347 
349  void UpdateEquations() override;
350 };
351 
352 // Malcolm
353 template< typename TEquationContainer, unsigned int VDimension >
354 class ITK_TEMPLATE_EXPORT LevelSetEvolution< TEquationContainer,
355  MalcolmSparseLevelSetImage< VDimension > > :
356 public LevelSetEvolutionBase< TEquationContainer, MalcolmSparseLevelSetImage< VDimension > >
357 {
358 public:
359  ITK_DISALLOW_COPY_AND_ASSIGN(LevelSetEvolution);
360 
362 
367 
369  itkNewMacro( Self );
370 
372  itkTypeMacro( LevelSetEvolution, LevelSetEvolutionBase );
373 
374  using EquationContainerType = typename Superclass::EquationContainerType;
375  using EquationContainerPointer = typename Superclass::EquationContainerPointer;
376  using TermContainerType = typename Superclass::TermContainerType;
377  using TermContainerPointer = typename Superclass::TermContainerPointer;
378 
379  using TermType = typename Superclass::TermType;
380  using TermPointer = typename Superclass::TermPointer;
381 
382  using InputImageType = typename Superclass::InputImageType;
383  using InputImagePixelType = typename Superclass::InputImagePixelType;
384  using InputImageConstPointer = typename Superclass::InputImageConstPointer;
385  using InputImageRegionType = typename Superclass::InputImageRegionType;
386  using InputPixelRealType = typename Superclass::InputPixelRealType;
387 
388  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
389 
390  using LevelSetContainerType = typename Superclass::LevelSetContainerType;
391  using LevelSetIdentifierType = typename Superclass::LevelSetIdentifierType;
392 
393  using LevelSetInputType = typename Superclass::LevelSetInputType;
394  using LevelSetOutputType = typename Superclass::LevelSetOutputType;
395  using LevelSetOutputRealType = typename Superclass::LevelSetOutputRealType;
396  using LevelSetDataType = typename Superclass::LevelSetDataType;
397 
400 
403 
404 
405  using IdListType = typename Superclass::IdListType;
406  using IdListIterator = typename Superclass::IdListIterator;
407  using IdListImageType = typename Superclass::IdListImageType;
408  using CacheImageType = typename Superclass::CacheImageType;
409  using DomainMapImageFilterType = typename Superclass::DomainMapImageFilterType;
410 
411  using StoppingCriterionType = typename Superclass::StoppingCriterionType;
412  using StoppingCriterionPointer = typename Superclass::StoppingCriterionPointer;
413 
415 
418 
419  LevelSetEvolution() = default;
420  ~LevelSetEvolution() override = default;
421 
422 protected:
423  void UpdateLevelSets() override;
424  void UpdateEquations() override;
425 };
426 }
427 
428 #ifndef ITK_MANUAL_INSTANTIATION
429 #include "itkLevelSetEvolution.hxx"
430 #endif
431 
432 #endif // itkLevelSetEvolution_h
Light weight base class for most itk classes.
typename Superclass::LayerIterator LayerIterator
Derived class for the shi representation of level-set function.
Class for partitioning of an ImageRegion.
typename Superclass::LayerType LayerType
A multi-dimensional iterator templated over image type that walks an image region and is specialized ...
Class for iterating and evolving the level-set function.
This filter calculates the Euclidean distance transform of a binary image in linear time for arbitrar...
Binarize an input image by thresholding.
typename Superclass::LabelMapType LabelMapType
typename Superclass::LabelMapPointer LabelMapPointer
Derived class for the Malcolm representation of level-set function.
Derived class for the sparse-field representation of level-set function.
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
typename DomainMapImageFilterType::DomainMapType::const_iterator DomainMapConstIteratorType
Base class for the &quot;dense&quot; representation of a level-set function on one image.
typename Superclass::LabelMapPointer LabelMapPointer
Partitions an iterator range for threading.
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
typename Superclass::LayerType LayerType
Base class for updating the level-set function.
typename Superclass::LabelMapPointer LabelMapPointer
Base class for updating the Shi representation of level-set function.
typename Superclass::LabelMapType LabelMapType
typename Superclass::LayerType LayerType
Base class for updating the Malcolm representation of level-set function.
typename Superclass::LabelMapType LabelMapType
Class for iterating and evolving the dense level-set function.