ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkFastGrowCut.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
19#ifndef itkFastGrowCut_h
20#define itkFastGrowCut_h
21
22#include <limits>
23#include <memory>
24
25#include "FibHeap.h"
26
28#include "itkMath.h"
29
30namespace itk
31{
32
57template <typename TInputImage, typename TLabelImage, typename TMaskImage = TLabelImage>
58class ITK_TEMPLATE_EXPORT FastGrowCut : public ImageToImageFilter<TInputImage, TLabelImage>
59{
60public:
61 ITK_DISALLOW_COPY_AND_MOVE(FastGrowCut);
62
68
70 itkNewMacro(Self);
71
73 itkOverrideGetNameOfClassMacro(FastGrowCut);
74
75 using InputImageType = TInputImage;
76 using IntensityPixelType = typename InputImageType::PixelType;
77
78 using LabelImageType = TLabelImage;
79 using LabelPixelType = typename LabelImageType::PixelType;
80
81 using MaskImageType = TMaskImage;
82 using MaskPixelType = typename MaskImageType::PixelType;
83
84 using RegionType = typename InputImageType::RegionType;
85 using IndexType = typename InputImageType::IndexType;
86 using SizeType = typename InputImageType::SizeType;
87 using SpacingType = typename InputImageType::SpacingType;
88
89 // using SeedsContainerType = std::vector<IndexType>;
90
91 // using InputRealType = typename NumericTraits<IntensityPixelType>::RealType;
92
93
97 void
99
105 virtual void
106 SetDistancePenalty(double penalty)
107 {
109 {
110 return;
111 }
112 m_DistancePenalty = penalty;
113 // The cached distance volume is derived from the penalty; discard it so
114 // the next Update() recomputes it instead of taking the incremental path.
115 this->Reset();
116 this->Modified();
117 }
118 itkGetMacro(DistancePenalty, double);
119
120 void
121 PrintSelf(std::ostream & os, Indent indent) const override;
122
123 void
124 SetSeedImage(const LabelImageType * seedImage)
125 {
126 // Process object is not const-correct so the const casting is required.
127 this->SetNthInput(1, const_cast<LabelImageType *>(seedImage));
128 }
129 const LabelImageType *
131 {
132 return static_cast<const LabelImageType *>(this->ProcessObject::GetInput(1));
133 }
134
141 void
142 SetMaskImage(const MaskImageType * maskImage)
143 {
144 this->SetNthInput(2, const_cast<MaskImageType *>(maskImage));
145 }
146 const MaskImageType *
148 {
149 return static_cast<const MaskImageType *>(this->ProcessObject::GetInput(2));
150 }
151
152 void
153 GenerateData() override;
154
155
156 static_assert(TInputImage::ImageDimension == 3, "FastGrowCut only works with 3D images");
157 static_assert(TLabelImage::ImageDimension == 3, "FastGrowCut only works with 3D images");
158 static_assert(TMaskImage::ImageDimension == 3, "FastGrowCut only works with 3D images");
160 itkConceptMacro(OutputHasNumericTraitsCheck, (Concept::HasNumericTraits<LabelPixelType>));
161 itkConceptMacro(MaskHasNumericTraitsCheck, (Concept::HasNumericTraits<MaskPixelType>));
162
163protected:
164 FastGrowCut() = default;
165 ~FastGrowCut() override
166 {
167 delete m_Heap;
168 delete[] m_HeapNodes;
169 }
170
171 static constexpr NodeKeyValueType DIST_INF = std::numeric_limits<float>::max();
172 static constexpr NodeKeyValueType DIST_EPSILON = 1e-3f;
173 static constexpr unsigned char NNGBH = 26;
174 using DistancePixelType = float;
176
177 // Override since the filter needs all the data for the algorithm
178 void
180
181 // Override since the filter produces the entire dataset
182 void
184
185 bool
187
188 void
190
191private:
193
197
198 std::vector<NodeIndexType> m_NeighborIndexOffsets;
199 std::vector<double> m_NeighborDistancePenalties;
200 std::vector<unsigned char> m_NumberOfNeighbors; // same everywhere except at the image boundary
201
202 FibHeap * m_Heap{ nullptr };
203 FibHeapNode * m_HeapNodes{ nullptr }; // a node is stored for each voxel
204 bool m_bSegInitialized{ false };
205 double m_DistancePenalty{ 0.0 };
206};
207} // namespace itk
208
209#ifndef ITK_MANUAL_INSTANTIATION
210# include "itkFastGrowCut.hxx"
211#endif
212
213#endif // itkFastGrowCut
unsigned int NodeIndexType
Definition FibHeap.h:55
float NodeKeyValueType
Definition FibHeap.h:49
Base class for all data objects in ITK.
std::vector< NodeIndexType > m_NeighborIndexOffsets
const LabelImageType * GetSeedImage()
std::vector< double > m_NeighborDistancePenalties
typename InputImageType::RegionType RegionType
DistanceImageType::Pointer m_DistanceVolume
TLabelImage LabelImageType
~FastGrowCut() override
SmartPointer< Self > Pointer
bool InitializationAHP()
void PrintSelf(std::ostream &os, Indent indent) const override
void EnlargeOutputRequestedRegion(DataObject *output) override
NodeIndexType m_DimY
typename MaskImageType::PixelType MaskPixelType
typename InputImageType::SizeType SizeType
void GenerateData() override
typename InputImageType::SpacingType SpacingType
NodeIndexType m_DimX
NodeIndexType m_DimZ
static constexpr unsigned char NNGBH
void SetMaskImage(const MaskImageType *maskImage)
static constexpr NodeKeyValueType DIST_EPSILON
void GenerateInputRequestedRegion() override
std::vector< unsigned char > m_NumberOfNeighbors
const MaskImageType * GetMaskImage()
typename InputImageType::IndexType IndexType
typename InputImageType::PixelType IntensityPixelType
typename LabelImageType::PixelType LabelPixelType
itk::Image< DistancePixelType, 3 > DistanceImageType
void DijkstraBasedClassificationAHP()
FastGrowCut()=default
SmartPointer< const Self > ConstPointer
FibHeapNode * m_HeapNodes
TInputImage InputImageType
TMaskImage MaskImageType
virtual void SetDistancePenalty(double penalty)
static constexpr NodeKeyValueType DIST_INF
ImageToImageFilter< TInputImage, TLabelImage > Superclass
void SetSeedImage(const LabelImageType *seedImage)
Templated n-dimensional image class.
Definition itkImage.h:89
SmartPointer< Self > Pointer
Definition itkImage.h:96
Control indentation during Print() invocation.
Definition itkIndent.h:53
virtual void Modified() const
virtual void SetNthInput(DataObjectPointerArraySizeType idx, DataObject *input)
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
Implements transparent reference counting.
#define itkConceptMacro(name, conceptType)
Compile-time check that a template argument satisfies an itk::Concept.
constexpr bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potentially different types.
Definition itkMath.h:743
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....