VMTK
Loading...
Searching...
No Matches
vtkvmtkLevelSetSigmoidFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkLevelSetSigmoidFilter.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:47:48 $
7Version: $Revision: 1.4 $
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 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
23
24#include "vtkDataArray.h"
25#include "vtkPointData.h"
26#include "vtkDataArray.h"
27#include "vtkInformation.h"
28#include "vtkInformationVector.h"
29#include "vtkObjectFactory.h"
30#include <cmath>
31
32
34
36{
37 this->LevelSetsImage = NULL;
38 this->Sigma = 1.0;
39 this->ScaleValue = 0.02;
41}
42
44{
45 if (this->LevelSetsImage)
46 {
47 this->LevelSetsImage->Delete();
48 this->LevelSetsImage = NULL;
49 }
50}
51
52void vtkvmtkLevelSetSigmoidFilter::SimpleExecute(vtkImageData* input, vtkImageData* output)
53{
54 if (!this->LevelSetsImage)
55 {
56 vtkErrorMacro(<<"Error: no LevelSetsImage has been set!");
57 return;
58 }
59
60 vtkDataArray* inputScalars = input->GetPointData()->GetScalars();
61 vtkDataArray* levelSetsScalars = this->LevelSetsImage->GetPointData()->GetScalars();
62 vtkDataArray* outputScalars = output->GetPointData()->GetScalars();
63
64 double spacing[3];
65 input->GetSpacing(spacing);
66
67 double minSpacing = spacing[0];
68 if (spacing[1] < minSpacing)
69 {
70 minSpacing = spacing[1];
71 }
72 if (spacing[2] < minSpacing)
73 {
74 minSpacing = spacing[2];
75 }
76
77 double windowValue = 4.0;
78 double windowValueReal = windowValue * minSpacing;
79 double sigmaReal = this->Sigma * minSpacing;
80
81 double scaleValue = this->ScaleValue;
82
83 int numberOfPoints = input->GetNumberOfPoints();
84
85 int i;
87 {
88 scaleValue = 0.0;
89 for (i=0; i<numberOfPoints; i++)
90 {
91 scaleValue += inputScalars->GetComponent(i,0);
92 }
93 scaleValue /= numberOfPoints;
94 }
95
96 for (i=0; i<numberOfPoints; i++)
97 {
98 double featureValue = inputScalars->GetComponent(i,0);
99 double levelSetsValue = levelSetsScalars->GetComponent(i,0);
100 if (levelSetsValue < windowValueReal)
101 {
102 double sigmoidValue = scaleValue * 1.0 / (1.0 + std::exp((levelSetsValue-sigmaReal)/(0.5*sigmaReal)));
103 featureValue += sigmoidValue;
104 }
105 outputScalars->SetComponent(i,0,featureValue);
106 }
107}
108
109void vtkvmtkLevelSetSigmoidFilter::PrintSelf(std::ostream& os, vtkIndent indent)
110{
111 this->Superclass::PrintSelf(os,indent);
112}
Apply a sigmoid function to every voxel of an image.
void PrintSelf(std::ostream &os, vtkIndent indent) override
virtual void SimpleExecute(vtkImageData *input, vtkImageData *output) override
vtkStandardNewMacro(vtkvmtkLevelSetSigmoidFilter)