ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkMultiphaseFiniteDifferenceImageFilter.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#ifndef itkMultiphaseFiniteDifferenceImageFilter_h
19#define itkMultiphaseFiniteDifferenceImageFilter_h
20
23#include "vnl/vnl_vector.h"
25
26#include "itkListSample.h"
27#include "itkKdTreeGenerator.h"
28
29namespace itk
30{
141template <typename TInputImage,
142 typename TFeatureImage,
143 typename TOutputImage,
144 typename TFiniteDifferenceFunction = FiniteDifferenceFunction<TOutputImage>,
145 typename TIdCell = unsigned int>
146class ITK_TEMPLATE_EXPORT MultiphaseFiniteDifferenceImageFilter : public InPlaceImageFilter<TFeatureImage, TOutputImage>
147{
148public:
149 ITK_DISALLOW_COPY_AND_MOVE(MultiphaseFiniteDifferenceImageFilter);
150
156
158 itkOverrideGetNameOfClassMacro(MultiphaseFiniteDifferenceImageFilter);
159
161 static constexpr unsigned int ImageDimension = TOutputImage::ImageDimension;
162
164 using InputImageType = TInputImage;
165 using InputImagePointer = typename InputImageType::Pointer;
166 using InputPointType = typename InputImageType::PointType;
167 using InputCoordinateType = typename InputPointType::CoordinateType;
168#ifndef ITK_FUTURE_LEGACY_REMOVE
169 using InputCoordRepType ITK_FUTURE_DEPRECATED(
170 "ITK 6 discourages using `InputCoordRepType`. Please use `InputCoordinateType` instead!") = InputCoordinateType;
171#endif
172 using InputIndexType = typename InputImageType::IndexType;
173 using InputIndexValueType = typename InputIndexType::IndexValueType;
174 using InputSizeType = typename InputImageType::SizeType;
175 using InputSizeValueType = typename InputSizeType::SizeValueType;
176 using InputRegionType = typename InputImageType::RegionType;
177 using InputPixelType = typename InputImageType::PixelType;
178 using InputSpacingType = typename InputImageType::SpacingType;
179 using InputOffsetValueType = typename InputImageType::OffsetValueType;
180
181 using FeatureImageType = TFeatureImage;
182 using FeatureImagePointer = typename FeatureImageType::Pointer;
183 using FeatureRegionType = typename FeatureImageType::RegionType;
184 using FeatureSizeType = typename FeatureImageType::SizeType;
185 using FeatureSpacingType = typename FeatureImageType::SpacingType;
186 using FeaturePointType = typename FeatureImageType::PointType;
187 using FeaturePixelType = typename FeatureImageType::PixelType;
189 using OutputImageType = TOutputImage;
190 using OutputImagePointer = typename OutputImageType::Pointer;
191 using OutputPixelType = typename OutputImageType::PixelType;
192 using OutputRegionType = typename OutputImageType::RegionType;
193 using OutputSizeType = typename OutputImageType::SizeType;
194 using OutputSizeValueType = typename OutputImageType::SizeValueType;
195 using OutputIndexType = typename OutputImageType::IndexType;
196 using OutputIndexValueType = typename OutputImageType::IndexValueType;
198 using IdCellType = TIdCell;
199 using VectorIdCellType = std::vector<IdCellType>;
204 using FiniteDifferenceFunctionType = TFiniteDifferenceFunction;
205 using FiniteDifferenceFunctionPointer = typename FiniteDifferenceFunctionType::Pointer;
206 using TimeStepType = typename FiniteDifferenceFunctionType::TimeStepType;
207 using TimeStepVectorType = typename std::vector<TimeStepType>;
208 using RadiusType = typename FiniteDifferenceFunctionType::RadiusType;
215 using KdTreePointer = typename KdTreeType::Pointer;
216
222 GetDifferenceFunction(const IdCellType & functionIndex) const
223 {
224 if (functionIndex < m_FunctionCount)
225 {
226 return (this->m_DifferenceFunctions[functionIndex]);
227 }
228 else
229 {
230 return nullptr;
231 }
232 }
233
238 virtual void
240 {
241 if (functionIndex < m_FunctionCount)
242 {
243 this->m_DifferenceFunctions[functionIndex] = function;
244 }
245 }
246
248 itkSetMacro(NumberOfIterations, unsigned int);
249 itkGetConstReferenceMacro(NumberOfIterations, unsigned int);
250
253 itkSetMacro(UseImageSpacing, bool);
254 itkBooleanMacro(UseImageSpacing);
255 itkGetConstReferenceMacro(UseImageSpacing, bool);
256
259 itkSetMacro(MaximumRMSError, double);
260 itkGetConstReferenceMacro(MaximumRMSError, double);
261
264 itkSetMacro(RMSChange, double);
265 itkGetConstReferenceMacro(RMSChange, double);
266
268 itkSetMacro(InitializedState, bool);
269 itkGetConstReferenceMacro(InitializedState, bool);
270 itkBooleanMacro(InitializedState);
271
274 itkSetMacro(ManualReinitialization, bool);
275 itkGetConstReferenceMacro(ManualReinitialization, bool);
276 itkBooleanMacro(ManualReinitialization);
277
279 itkSetMacro(ElapsedIterations, unsigned int);
280
282 itkGetConstReferenceMacro(ElapsedIterations, unsigned int);
283
284 void
285 SetLevelSet(const IdCellType & i, const InputImageType * levelSet)
286 {
287 m_LevelSet[i] = InputImageType::New();
288 m_LevelSet[i]->SetRequestedRegion(levelSet->GetRequestedRegion());
289 m_LevelSet[i]->SetBufferedRegion(levelSet->GetBufferedRegion());
290 m_LevelSet[i]->SetLargestPossibleRegion(levelSet->GetLargestPossibleRegion());
291 m_LevelSet[i]->Allocate();
292 m_LevelSet[i]->CopyInformation(levelSet);
293
294 ImageRegionConstIterator<InputImageType> in(levelSet, levelSet->GetBufferedRegion());
295 ImageRegionIterator<InputImageType> cp(m_LevelSet[i], levelSet->GetBufferedRegion());
296
297 in.GoToBegin();
298 cp.GoToBegin();
299
300 while (!in.IsAtEnd())
301 {
302 cp.Set(in.Get());
303 ++in;
304 ++cp;
305 }
306 }
307
308 InputImagePointer
310 {
311 if (i >= m_FunctionCount)
312 {
313 itkExceptionMacro("Request for level set #" << i << " but there are only " << m_FunctionCount);
314 }
315 else
316 {
317 return m_LevelSet[i];
318 }
319 }
320
321 void
323 {
324 this->m_Lookup = lookup;
325 }
326
327 void
329 {
330 this->m_KdTree = kdtree;
331 }
332
333 void
335 {
336 m_FunctionCount = n;
337
338 m_DifferenceFunctions.resize(m_FunctionCount, nullptr);
339
340 constexpr auto radius = MakeFilled<RadiusType>(1);
341
342 for (unsigned int i = 0; i < this->m_FunctionCount; ++i)
343 {
344 this->m_DifferenceFunctions[i] = FiniteDifferenceFunctionType::New();
345 this->m_DifferenceFunctions[i]->Initialize(radius);
346 }
347
348 // Initialize the images
349 m_LevelSet.resize(m_FunctionCount, nullptr);
350
351 // Initialize the lookup table
352 this->m_Lookup.resize(m_FunctionCount);
353
354 IdCellType k = 1;
355
356 {
357 auto it = this->m_Lookup.begin();
358 auto _end = this->m_Lookup.end();
359 while (it != _end)
360 {
361 *it = k;
362 ++it;
363 ++k;
364 }
365 }
366 }
367
368protected:
370 {
371 this->m_KdTree = nullptr;
372 this->m_ElapsedIterations = 0;
375 this->m_UseImageSpacing = true;
376 this->m_ManualReinitialization = false;
377 this->m_InitializedState = false;
379 this->m_FunctionCount = 0;
380 this->InPlaceOff();
381 }
382
384
386 std::vector<InputImagePointer> m_LevelSet{};
389
390 unsigned int m_ElapsedIterations{};
392 double m_RMSChange{};
393 unsigned int m_NumberOfIterations{};
394
396 std::vector<FiniteDifferenceFunctionPointer> m_DifferenceFunctions{};
397
401
402 void
403 PrintSelf(std::ostream & os, Indent indent) const override;
404
406 virtual void
408
412 virtual void
414
420 virtual TimeStepType
422
426 virtual void
428
432 void
433 GenerateData() override;
434
446 void
448
451 virtual bool
453
463 virtual bool
464 ThreadedHalt(void * itkNotUsed(threadInfo))
465 {
466 return this->Halt();
467 }
468
474 virtual void
476 {}
477
484 virtual void
486 {
487 for (IdCellType i = 0; i < this->m_FunctionCount; ++i)
488 {
489 this->m_DifferenceFunctions[i]->InitializeIteration();
490 }
491 }
492
506 inline TimeStepType
507 ResolveTimeStep(const TimeStepVectorType & timeStepList, const std::vector<uint8_t> & valid);
508
511 virtual void
514
515private:
519
522};
523} // end namespace itk
524
525#ifndef ITK_MANUAL_INSTANTIATION
526# include "itkMultiphaseFiniteDifferenceImageFilter.hxx"
527#endif
528
529#endif
A multi-dimensional iterator templated over image type that walks a region of pixels.
A multi-dimensional iterator templated over image type that walks a region of pixels.
void Set(const PixelType &value) const
Control indentation during Print() invocation.
Definition itkIndent.h:50
virtual void ApplyUpdate(TimeStepType dt)=0
virtual void SetDifferenceFunction(const IdCellType &functionIndex, FiniteDifferenceFunctionPointer function)
void SetLevelSet(const IdCellType &i, const InputImageType *levelSet)
~MultiphaseFiniteDifferenceImageFilter() override=default
virtual const FiniteDifferenceFunctionPointer GetDifferenceFunction(const IdCellType &functionIndex) const
TimeStepType ResolveTimeStep(const TimeStepVectorType &timeStepList, const std::vector< uint8_t > &valid)
void PrintSelf(std::ostream &os, Indent indent) const override
virtual TimeStepType CalculateChange()=0
static constexpr T max(const T &)
Implements transparent reference counting.
This class generates a KdTree object without centroid information.
This class is the native implementation of the a Sample with an STL container.
A templated class holding a n-Dimensional vector.
Definition itkVector.h:63
static constexpr double eps
Definition itkMath.h:97
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
constexpr TContainer MakeFilled(typename TContainer::const_reference value)