forked from InsightSoftwareConsortium/ITK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
itkBalloonForceFilter.h
234 lines (199 loc) · 8.78 KB
/
itkBalloonForceFilter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkBalloonForceFilter.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __itkBalloonForceFilter_h
#define __itkBalloonForceFilter_h
#include "itkMeshToMeshFilter.h"
#include "vnl/vnl_matrix_fixed.h"
#include "vnl/vnl_math.h"
#include "itkMesh.h"
#include "itkVector.h"
#include "itkTriangleCell.h"
#include "itkImage.h"
#include "itkImageRegionIterator.h"
#include <itkCovariantVector.h>
namespace itk
{
/** \class BalloonForceFilter
* \brief
*
* BalloonForceFilter is used to apply balloon force and the potential
* force onto the 2D deformable model. For 3D (multi-slices) segmentation
* please use BalloonForce3DFilter
* The balloon force is vertical to the surface of the model. The potential
* force is given out by the estimated boundary points. These two will meet
* a balance at the boundary, thus the deformable model will fit to the
* boundary.
* Users should use deformable model as input using SetInput and also provide
* the filter with a potential image which will provide the estimated bounday.
* The image should be a binary image with object and background labelled
* differently. These image can be given by GibbsPriorFilter or any other
* segmentation filters.
* When the nodes on the model stopped at the estimated boundary, using the
* GradientFit method to fit the model using the gradient information in the
* original image.
*
* \ingroup MeshFilters
* \ingroup MeshSegmentation
*/
template <class TInputMesh, class TOutputMesh>
class ITK_EXPORT BalloonForceFilter : public MeshToMeshFilter<TInputMesh, TOutputMesh>
{
public:
/** Standard class typedefs. */
typedef BalloonForceFilter Self;
typedef MeshToMeshFilter<TInputMesh, TOutputMesh> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(BalloonForceFilter,MeshToMeshFilter);
/** Some typedefs for the input and output types. */
typedef TInputMesh InputMeshType;
typedef TOutputMesh OutputMeshType;
/** Typedefs for containers and their iterators. */
typedef typename InputMeshType::PointsContainerPointer
InputPointsContainerPointer;
typedef typename InputMeshType::PointsContainer::Iterator
InputPointsContainerIterator;
typedef typename InputMeshType::PointDataContainerPointer
InputPointDataContainerPointer;
typedef typename InputMeshType::PointDataContainer::Iterator
InputPointDataContainerIterator;
typedef typename InputMeshType::CellsContainerPointer
InputCellsContainerPointer;
typedef typename InputMeshType::CellsContainer::Iterator
InputCellsContainerIterator;
typedef typename InputMeshType::CellDataContainerPointer
InputCellDataContainerPointer;
typedef typename InputMeshType::CellDataContainer::Iterator
InputCellDataContainerIterator;
typedef typename OutputMeshType::PointsContainerPointer
OutputPointsContainerPointer;
typedef typename OutputMeshType::PointsContainer::Iterator
OutputPointsContainerIterator;
/** Image types. */
typedef typename InputMeshType::PointType IPixelType;
typedef typename InputMeshType::PixelType PixelType;
typedef Image<unsigned short, 2> ImageType;
typedef CovariantVector<PixelType, 2> GradientType;
typedef Image<GradientType, 2> GradientImageType;
typedef typename InputMeshType::Pointer InputMeshPointer;
typedef typename OutputMeshType::Pointer OutputMeshPointer;
typedef typename ImageType::Pointer ImagePointer;
typedef typename ImageType::IndexType IndexType;
typedef typename GradientImageType::Pointer GradientImagePointer;
typedef typename GradientImageType::IndexType GradientIndexType;
typedef ImageRegionIterator<ImageType> ImageIterator;
typedef Vector<float, 3> FloatVector;
typedef Vector<int, 3> IntVector;
typedef Vector<double, 2> Double2Vector;
typedef Vector<int, 2> Int2Vector;
/** Cell related types. */
typedef typename InputMeshType::CellType CellType;
typedef typename InputMeshType::CellTraits CellTraits;
typedef ::itk::CellInterface<PixelType, CellTraits> CellInterface;
typedef ::itk::TriangleCell< CellInterface > TriCell;
/** Some functions. */
void ComputeForce();
void Initialize();
void SetStiffnessMatrix();
void Advance(); // update data for next iteration
void Reset(); // reset all data
void ComputeDt(); // compute point positions
void ComputeOutput();
void NodeAddition(int i, int res, IPixelType z); // (folowing 3) for adding new nodes, now disabled for further tests
void NodesRearrange();
void GapSearch();
void GradientFit(); // fit the model with gradient information
void ComputeNormals();
void ACDSearch(); // remove weird structures on the model surface
/** Set the output image. */
itkSetMacro(ImageOutput, ImagePointer);
itkGetMacro(ImageOutput, ImagePointer);
itkSetMacro(Gradient, GradientImagePointer);
/** Set/Get information for the algorithm. */
itkSetMacro(Stiffness, Double2Vector);
itkSetMacro(TimeStep, double);
itkSetMacro(GradientBegin, int);
itkSetMacro(Resolution, int);
itkSetMacro(Center, IndexType);
itkGetMacro(Normals, InputMeshPointer);
itkSetMacro(DistanceForGradient, float);
itkSetMacro(DistanceToStop, float);
itkSetMacro(Potential, ImagePointer);
itkGetMacro(Locations, InputMeshPointer);
itkGetMacro(Displacements, InputMeshPointer);
itkGetMacro(Derives, InputMeshPointer);
itkGetMacro(Forces, InputMeshPointer);
protected:
BalloonForceFilter();
~BalloonForceFilter();
void PrintSelf(std::ostream& os, Indent indent) const;
virtual void GenerateData();
private:
BalloonForceFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
/** These meshes are defined to hold the vectors as force, etc. */
InputMeshPointer m_Forces;
InputMeshPointer m_Normals;
InputMeshPointer m_Displacements;
InputMeshPointer m_Derives;
InputMeshPointer m_Locations;
InputMeshPointer m_Input;
OutputMeshPointer m_Output;
/** Three different kinds of stiffness matrix. */
vnl_matrix_fixed<double, 4, 4> m_NStiffness;
vnl_matrix_fixed<double, 4, 4> m_SStiffness;
vnl_matrix_fixed<double, 4, 4> m_CStiffness;
vnl_matrix_fixed<double, 4, 4> **m_K;
Double2Vector m_Stiffness;
double m_TimeStep; // the time step of each iteration
int m_Resolution;
IndexType m_Center;
float m_MiniT; // variabel help to stop the model when near potential estimation
int m_Step; // the number of iteration
unsigned int m_NumberOfNodes;
unsigned int m_NumberOfCells;
unsigned int m_NumNewNodes; // for adding new nodes, now disabled for further tests
int *m_GapLocations;
float **m_NewNodes;
int m_NewNodesExisted;
unsigned int m_NewNodeLimit;
unsigned int m_ImageWidth; // input image size
unsigned int m_ImageHeight;
unsigned int m_ImageDepth;
int m_ModelXUpLimit; // the following 4 variables record the size of the model
int m_ModelXDownLimit;
int m_ModelYUpLimit;
int m_ModelYDownLimit;
int **m_ACD; // help to remove the weird structure on the model surface
int m_ModelRestart;
int m_GradientBegin;
Int2Vector m_StepThreshold; // the threshold decide when to transfer from potential fit to gradient fit
// and the threshold decide when to stop the model
float m_DistanceToBoundary;
float m_DistanceToStop;
float m_DistanceForGradient;
ImagePointer m_Potential; // for calculate of image force from potential
GradientImagePointer m_Gradient; // for calculate of image force from gradient
// for Gibbs Prior Model parameters' recalculation
ImagePointer m_ImageOutput;
unsigned short m_ObjectLabel;
typedef ImageType::SizeType ImageSizeType;
};
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkBalloonForceFilter.txx"
#endif
#endif