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{
153template <typename TInputImage,
154 typename TFeatureImage,
155 typename TOutputImage,
156 typename TFiniteDifferenceFunction = FiniteDifferenceFunction<TOutputImage>,
157 typename TIdCell = unsigned int>
158class ITK_TEMPLATE_EXPORT MultiphaseFiniteDifferenceImageFilter : public InPlaceImageFilter<TFeatureImage, TOutputImage>
159{
160public:
161 ITK_DISALLOW_COPY_AND_MOVE(MultiphaseFiniteDifferenceImageFilter);
162
168
170 itkOverrideGetNameOfClassMacro(MultiphaseFiniteDifferenceImageFilter);
171
173 static constexpr unsigned int ImageDimension = TOutputImage::ImageDimension;
174
176 using InputImageType = TInputImage;
177 using InputImagePointer = typename InputImageType::Pointer;
178 using InputPointType = typename InputImageType::PointType;
179 using InputCoordinateType = typename InputPointType::CoordinateType;
180#ifndef ITK_FUTURE_LEGACY_REMOVE
181 using InputCoordRepType ITK_FUTURE_DEPRECATED(
182 "ITK 6 discourages using `InputCoordRepType`. Please use `InputCoordinateType` instead!") = InputCoordinateType;
183#endif
184 using InputIndexType = typename InputImageType::IndexType;
185 using InputIndexValueType = typename InputIndexType::IndexValueType;
186 using InputSizeType = typename InputImageType::SizeType;
187 using InputSizeValueType = typename InputSizeType::SizeValueType;
188 using InputRegionType = typename InputImageType::RegionType;
189 using InputPixelType = typename InputImageType::PixelType;
190 using InputSpacingType = typename InputImageType::SpacingType;
191 using InputOffsetValueType = typename InputImageType::OffsetValueType;
192
193 using FeatureImageType = TFeatureImage;
194 using FeatureImagePointer = typename FeatureImageType::Pointer;
195 using FeatureRegionType = typename FeatureImageType::RegionType;
196 using FeatureSizeType = typename FeatureImageType::SizeType;
197 using FeatureSpacingType = typename FeatureImageType::SpacingType;
198 using FeaturePointType = typename FeatureImageType::PointType;
199 using FeaturePixelType = typename FeatureImageType::PixelType;
201 using OutputImageType = TOutputImage;
202 using OutputImagePointer = typename OutputImageType::Pointer;
203 using OutputPixelType = typename OutputImageType::PixelType;
204 using OutputRegionType = typename OutputImageType::RegionType;
205 using OutputSizeType = typename OutputImageType::SizeType;
206 using OutputSizeValueType = typename OutputImageType::SizeValueType;
207 using OutputIndexType = typename OutputImageType::IndexType;
208 using OutputIndexValueType = typename OutputImageType::IndexValueType;
210 using IdCellType = TIdCell;
211 using VectorIdCellType = std::vector<IdCellType>;
216 using FiniteDifferenceFunctionType = TFiniteDifferenceFunction;
217 using FiniteDifferenceFunctionPointer = typename FiniteDifferenceFunctionType::Pointer;
218 using TimeStepType = typename FiniteDifferenceFunctionType::TimeStepType;
219 using TimeStepVectorType = typename std::vector<TimeStepType>;
220 using RadiusType = typename FiniteDifferenceFunctionType::RadiusType;
227 using KdTreePointer = typename KdTreeType::Pointer;
228
234 GetDifferenceFunction(const IdCellType & functionIndex) const
235 {
236 if (functionIndex < m_FunctionCount)
237 {
238 return (this->m_DifferenceFunctions[functionIndex]);
239 }
240 else
241 {
242 return nullptr;
243 }
244 }
245
246
251 virtual void
253 {
254 if (functionIndex < m_FunctionCount)
255 {
256 this->m_DifferenceFunctions[functionIndex] = function;
257 }
258 }
259
260
262 itkSetMacro(NumberOfIterations, unsigned int);
263 itkGetConstReferenceMacro(NumberOfIterations, unsigned int);
265
268 itkSetMacro(UseImageSpacing, bool);
269 itkBooleanMacro(UseImageSpacing);
270 itkGetConstReferenceMacro(UseImageSpacing, bool);
272
275 itkSetMacro(MaximumRMSError, double);
276 itkGetConstReferenceMacro(MaximumRMSError, double);
278
281 itkSetMacro(RMSChange, double);
282 itkGetConstReferenceMacro(RMSChange, double);
284
286 itkSetMacro(InitializedState, bool);
287 itkGetConstReferenceMacro(InitializedState, bool);
288 itkBooleanMacro(InitializedState);
290
293 itkSetMacro(ManualReinitialization, bool);
294 itkGetConstReferenceMacro(ManualReinitialization, bool);
295 itkBooleanMacro(ManualReinitialization);
297
299 itkSetMacro(ElapsedIterations, unsigned int);
300
302 itkGetConstReferenceMacro(ElapsedIterations, unsigned int);
303
304 void
305 SetLevelSet(const IdCellType & i, const InputImageType * levelSet)
306 {
307 m_LevelSet[i] = InputImageType::New();
308 m_LevelSet[i]->SetRequestedRegion(levelSet->GetRequestedRegion());
309 m_LevelSet[i]->SetBufferedRegion(levelSet->GetBufferedRegion());
310 m_LevelSet[i]->SetLargestPossibleRegion(levelSet->GetLargestPossibleRegion());
311 m_LevelSet[i]->Allocate();
312 m_LevelSet[i]->CopyInformation(levelSet);
313
314 ImageRegionConstIterator<InputImageType> in(levelSet, levelSet->GetBufferedRegion());
315 ImageRegionIterator<InputImageType> cp(m_LevelSet[i], levelSet->GetBufferedRegion());
316
317 in.GoToBegin();
318 cp.GoToBegin();
319
320 while (!in.IsAtEnd())
321 {
322 cp.Set(in.Get());
323 ++in;
324 ++cp;
325 }
326 }
327
328 InputImagePointer
330 {
331 if (i >= m_FunctionCount)
332 {
333 itkExceptionMacro("Request for level set #" << i << " but there are only " << m_FunctionCount);
334 }
335 else
336 {
337 return m_LevelSet[i];
338 }
339 }
340
341 void
343 {
344 this->m_Lookup = lookup;
345 }
346
347 void
349 {
350 this->m_KdTree = kdtree;
351 }
352
353 void
355 {
356 m_FunctionCount = n;
357
358 m_DifferenceFunctions.resize(m_FunctionCount, nullptr);
359
360 constexpr auto radius = MakeFilled<RadiusType>(1);
361
362 for (unsigned int i = 0; i < this->m_FunctionCount; ++i)
363 {
364 this->m_DifferenceFunctions[i] = FiniteDifferenceFunctionType::New();
365 this->m_DifferenceFunctions[i]->Initialize(radius);
366 }
367
368 // Initialize the images
369 m_LevelSet.resize(m_FunctionCount, nullptr);
370
371 // Initialize the lookup table
372 this->m_Lookup.resize(m_FunctionCount);
373
374 IdCellType k = 1;
375
376 {
377 auto it = this->m_Lookup.begin();
378 auto _end = this->m_Lookup.end();
379 while (it != _end)
380 {
381 *it = k;
382 ++it;
383 ++k;
384 }
385 }
386 }
387
388protected:
390 {
391 this->m_KdTree = nullptr;
392 this->m_ElapsedIterations = 0;
395 this->m_UseImageSpacing = true;
396 this->m_ManualReinitialization = false;
397 this->m_InitializedState = false;
399 this->m_FunctionCount = 0;
400 this->InPlaceOff();
401 }
402
404
406 std::vector<InputImagePointer> m_LevelSet{};
409
410 unsigned int m_ElapsedIterations{};
412 double m_RMSChange{};
413 unsigned int m_NumberOfIterations{};
414
416 std::vector<FiniteDifferenceFunctionPointer> m_DifferenceFunctions{};
417
421
422 void
423 PrintSelf(std::ostream & os, Indent indent) const override;
424
426 virtual void
428
432 virtual void
434
440 virtual TimeStepType
442
446 virtual void
448
452 void
453 GenerateData() override;
454
466 void
468
471 virtual bool
473
483 virtual bool
484 ThreadedHalt(void * itkNotUsed(threadInfo))
485 {
486 return this->Halt();
487 }
488
494 virtual void
496 {}
497
504 virtual void
506 {
507 for (IdCellType i = 0; i < this->m_FunctionCount; ++i)
508 {
509 this->m_DifferenceFunctions[i]->InitializeIteration();
510 }
511 }
512
513
527 inline TimeStepType
528 ResolveTimeStep(const TimeStepVectorType & timeStepList, const std::vector<uint8_t> & valid);
529
532 virtual void
535
536private:
540
543};
544} // end namespace itk
545
546#ifndef ITK_MANUAL_INSTANTIATION
547# include "itkMultiphaseFiniteDifferenceImageFilter.hxx"
548#endif
549
550#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)