VMTK
Loading...
Searching...
No Matches
vtkvmtkFastMarchingDirectionalFreezeImageFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkFastMarchingDirectionalFreezeImageFilter.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:48:25 $
7Version: $Revision: 1.1 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 Portions of this code are covered under the ITK copyright.
17 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm
18 for details.
19
20 This software is distributed WITHOUT ANY WARRANTY; without even
21 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
22 PURPOSE. See the above copyright notices for more information.
23
24=========================================================================*/
25
27#include "vtkObjectFactory.h"
28
30
32
34
36{
37 this->GenerateGradientImage = 0;
38 this->TargetReachedMode = ONE_TARGET;
39 this->TargetValue = 0.0;
40 this->TargetOffset = 0.0;
41 this->Seeds = NULL;
42 this->Targets = NULL;
43}
44
46{
47 if (this->Seeds)
48 {
49 this->Seeds->Delete();
50 this->Seeds = NULL;
51 }
52 if (this->Targets)
53 {
54 this->Targets->Delete();
55 this->Targets = NULL;
56 }
57}
58
59void vtkvmtkFastMarchingDirectionalFreezeImageFilter::SimpleExecute(vtkImageData* input, vtkImageData* output)
60{
61 typedef itk::Image<float,3> ImageType;
62
63 ImageType::Pointer inImage = ImageType::New();
64
66
68
69 FastMarchingFilterType::Pointer fastMarchingFilter = FastMarchingFilterType::New();
70 fastMarchingFilter->SetInput(inImage);
71 fastMarchingFilter->SetGenerateGradientImage(this->GenerateGradientImage);
72 fastMarchingFilter->SetTargetOffset(this->TargetOffset);
73 if (this->TargetReachedMode == ONE_TARGET)
74 {
75 fastMarchingFilter->SetTargetReachedMode(FastMarchingFilterType::OneTarget);
76 }
77 else
78 {
79 fastMarchingFilter->SetTargetReachedMode(FastMarchingFilterType::AllTargets);
80 }
81
82 FastMarchingFilterType::NodeContainerPointer seeds = FastMarchingFilterType::NodeContainer::New();
83 int i;
84 for (i=0; i<this->Seeds->GetNumberOfIds(); i++)
85 {
86 // TODO: here we get the point. We should get the cell center instead.
87 ImageType::PointType seedPoint(input->GetPoint(this->Seeds->GetId(i)));
88#if (ITK_VERSION_MAJOR >= 5)
89 FastMarchingFilterType::NodeType::IndexType seedIndex = inImage->TransformPhysicalPointToIndex(seedPoint);
90#else
91 FastMarchingFilterType::NodeType::IndexType seedIndex;
92 inImage->TransformPhysicalPointToIndex(seedPoint,seedIndex);
93#endif
94 FastMarchingFilterType::PixelType seedValue = itk::NumericTraits<FastMarchingFilterType::PixelType>::Zero;
95 FastMarchingFilterType::NodeType seed;
96 seed.SetValue(seedValue);
97 seed.SetIndex(seedIndex);
98 seeds->InsertElement(i,seed);
99 }
100 fastMarchingFilter->SetTrialPoints(seeds);
101
102 FastMarchingFilterType::NodeContainerPointer targets = FastMarchingFilterType::NodeContainer::New();
103 for (i=0; i<this->Targets->GetNumberOfIds(); i++)
104 {
105 // TODO: here we get the point. We should get the cell center instead.
106 ImageType::PointType seedPoint(input->GetPoint(this->Targets->GetId(i)));
107#if (ITK_VERSION_MAJOR >= 5)
108 FastMarchingFilterType::NodeType::IndexType seedIndex = inImage->TransformPhysicalPointToIndex(seedPoint);
109#else
110 FastMarchingFilterType::NodeType::IndexType seedIndex;
111 inImage->TransformPhysicalPointToIndex(seedPoint,seedIndex);
112#endif
113 FastMarchingFilterType::PixelType seedValue = itk::NumericTraits<FastMarchingFilterType::PixelType>::Zero;
114 FastMarchingFilterType::NodeType seed;
115 seed.SetValue(seedValue);
116 seed.SetIndex(seedIndex);
117 targets->InsertElement(i,seed);
118 }
119 fastMarchingFilter->SetTargetPoints(targets);
120 fastMarchingFilter->Update();
121
122 this->TargetValue = fastMarchingFilter->GetTargetValue();
123
124 vtkvmtkITKFilterUtilities::ITKToVTKImage<ImageType>(fastMarchingFilter->GetOutput(),output);
125}
Propagates a front, freezing points based on the relative direction of the front and the gradient vec...
virtual void SimpleExecute(vtkImageData *input, vtkImageData *output) override
static void ITKToVTKImage(typename TImage::Pointer input, vtkImageData *output)
static void VTKToITKImage(vtkImageData *input, typename TImage::Pointer output)
vtkStandardNewMacro(vtkvmtkFastMarchingDirectionalFreezeImageFilter)