ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkBalloonForceFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 itkBalloonForceFilter_h
19 #define itkBalloonForceFilter_h
20 #if !defined( ITK_LEGACY_REMOVE )
21 
22 #include "itkMeshToMeshFilter.h"
23 #include "vnl/vnl_matrix_fixed.h"
24 #include "vnl/vnl_math.h"
25 #include "itkMesh.h"
26 #include "itkTriangleCell.h"
27 #include "itkImage.h"
28 #include "itkImageRegionIterator.h"
29 #include <itkCovariantVector.h>
30 
31 namespace itk
32 {
57 template< typename TInputMesh, typename TOutputMesh >
58 class BalloonForceFilter:public MeshToMeshFilter< TInputMesh, TOutputMesh >
59 {
60 public:
62  typedef BalloonForceFilter Self;
63  typedef MeshToMeshFilter< TInputMesh, TOutputMesh > Superclass;
64  typedef SmartPointer< Self > Pointer;
65  typedef SmartPointer< const Self > ConstPointer;
66 
68  itkNewMacro(Self);
69 
71  itkTypeMacro(BalloonForceFilter, MeshToMeshFilter);
72 
74  typedef TInputMesh InputMeshType;
75  typedef TOutputMesh OutputMeshType;
76 
78  typedef typename InputMeshType::PointsContainerPointer
79  InputPointsContainerPointer;
80  typedef typename InputMeshType::PointsContainer::Iterator
81  InputPointsContainerIterator;
82  typedef typename InputMeshType::PointsContainerConstPointer
83  InputPointsContainerConstPointer;
84  typedef typename InputMeshType::PointsContainer::ConstIterator
85  InputPointsContainerConstIterator;
86  typedef typename InputMeshType::PointDataContainerPointer
87  InputPointDataContainerPointer;
88  typedef typename InputMeshType::PointDataContainer::Iterator
89  InputPointDataContainerIterator;
90  typedef typename InputMeshType::CellsContainerPointer
91  InputCellsContainerPointer;
92  typedef typename InputMeshType::CellsContainer::Iterator
93  InputCellsContainerIterator;
94  typedef typename InputMeshType::CellDataContainerPointer
95  InputCellDataContainerPointer;
96  typedef typename InputMeshType::CellDataContainer::Iterator
97  InputCellDataContainerIterator;
98  typedef typename InputMeshType::CellsContainerConstPointer
99  InputCellsContainerConstPointer;
100  typedef typename InputMeshType::CellsContainer::ConstIterator
101  InputCellsContainerConstIterator;
102  typedef typename InputMeshType::CellDataContainerConstPointer
103  InputCellDataContainerConstPointer;
104  typedef typename InputMeshType::CellDataContainer::ConstIterator
105  InputCellDataContainerConstIterator;
106 
107  typedef typename OutputMeshType::PointsContainerPointer
108  OutputPointsContainerPointer;
109  typedef typename OutputMeshType::PointsContainer::Iterator
110  OutputPointsContainerIterator;
111 
113  typedef typename InputMeshType::PointType IPixelType;
114  typedef typename InputMeshType::PixelType PixelType;
115 
116  typedef Image< unsigned short, 2 > ImageType;
117  typedef CovariantVector< PixelType, 2 > GradientType;
118  typedef Image< GradientType, 2 > GradientImageType;
119  typedef typename InputMeshType::Pointer InputMeshPointer;
120  typedef typename InputMeshType::ConstPointer InputMeshConstPointer;
121  typedef typename OutputMeshType::Pointer OutputMeshPointer;
122  typedef typename ImageType::Pointer ImagePointer;
123  typedef typename ImageType::IndexType IndexType;
124  typedef typename GradientImageType::Pointer GradientImagePointer;
125  typedef typename GradientImageType::IndexType GradientIndexType;
126  typedef ImageRegionIterator< ImageType > ImageIterator;
127  typedef Vector< float, 3 > FloatVector;
128  typedef Vector< int, 3 > IntVector;
129  typedef Vector< double, 2 > Double2Vector;
130  typedef Vector< int, 2 > Int2Vector;
131 
133  typedef typename InputMeshType::CellType CellType;
134  typedef typename InputMeshType::CellTraits CellTraits;
135  typedef::itk::CellInterface< PixelType, CellTraits > CellInterface;
136  typedef::itk::TriangleCell< CellInterface > TriCell;
137 
139  void ComputeForce();
140 
141  void Initialize();
142 
143  void SetStiffnessMatrix();
144 
145  void Advance(); // update data for next iteration
146 
147  void Reset(); // reset all data
148 
149  void ComputeDt(); // compute point positions
150 
151  void ComputeOutput();
152 
153  void NodeAddition(int i, int res, IPixelType z); // (following 3) for adding
154  // new nodes, now disabled
155  // for further tests
156 
157  void NodesRearrange();
158 
159  void GapSearch();
160 
161  void GradientFit(); // fit the model with gradient information
162 
163  void ComputeNormals();
164 
165  void ACDSearch(); // remove weird structures on the model surface
166 
168  itkSetMacro(ImageOutput, ImagePointer);
169  itkGetConstMacro(ImageOutput, ImagePointer);
170  itkSetMacro(Gradient, GradientImagePointer);
172 
174  itkSetMacro(Stiffness, Double2Vector);
175  itkSetMacro(TimeStep, double);
176  itkSetMacro(GradientBegin, int);
177  itkSetMacro(Resolution, int);
178  itkSetMacro(Center, IndexType);
179  itkGetConstMacro(Normals, InputMeshPointer);
180  itkSetMacro(DistanceForGradient, float);
181  itkSetMacro(DistanceToStop, float);
182  itkSetMacro(Potential, ImagePointer);
183  itkGetConstMacro(Locations, InputMeshPointer);
184  itkGetConstMacro(Displacements, InputMeshPointer);
185  itkGetConstMacro(Derives, InputMeshPointer);
186  itkGetConstMacro(Forces, InputMeshPointer);
188 
189 protected:
190  BalloonForceFilter();
191  ~BalloonForceFilter();
192  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
193 
194  virtual void GenerateData();
195 
196 private:
197  BalloonForceFilter(const Self &); //purposely not implemented
198  void operator=(const Self &); //purposely not implemented
199 
201  InputMeshPointer m_Forces;
202  InputMeshPointer m_Normals;
203  InputMeshPointer m_Displacements;
204  InputMeshPointer m_Derives;
205  InputMeshPointer m_Locations;
206  InputMeshPointer m_Input;
207  OutputMeshPointer m_Output;
208 
210  vnl_matrix_fixed< double, 4, 4 > m_NStiffness;
211  vnl_matrix_fixed< double, 4, 4 > m_SStiffness;
212  vnl_matrix_fixed< double, 4, 4 > m_CStiffness;
213  vnl_matrix_fixed< double, 4, 4 > **m_K;
214 
215  Double2Vector m_Stiffness;
216  double m_TimeStep; // the time step of each iteration
217  int m_Resolution;
218  IndexType m_Center;
219  float m_MiniT; // variabel help to stop the model when near
220  // potential estimation
221  int m_Step; // the number of iteration
222 
223  unsigned int m_NumberOfNodes;
224  unsigned int m_NumberOfCells;
225  unsigned int m_NumNewNodes; // for adding new nodes, now disabled for
226  // further tests
227  int * m_GapLocations;
228  float ** m_NewNodes;
229  int m_NewNodesExisted;
230  unsigned int m_NewNodeLimit;
231  unsigned int m_ImageWidth; // input image size
232  unsigned int m_ImageHeight;
233  unsigned int m_ImageDepth;
234 
235  int m_ModelXUpLimit; // the following 4 variables record the size of the
236  // model
237  int m_ModelXDownLimit;
238  int m_ModelYUpLimit;
239  int m_ModelYDownLimit;
240  int **m_ACD; // help to remove the weird structure on the model surface
241  int m_ModelRestart;
242  int m_GradientBegin;
243 
244  Int2Vector m_StepThreshold; // the threshold decide when to transfer from
245  // potential fit to gradient fit
246 
247  // and the threshold decide when to stop the model
248  float m_DistanceToBoundary;
249  float m_DistanceToStop;
250  float m_DistanceForGradient;
251 
252  ImagePointer m_Potential; // for calculate of image force from
253  // potential
254  GradientImagePointer m_Gradient; // for calculate of image force from
255  // gradient
256 
257  // for Gibbs Prior Model parameters' recalculation
258  ImagePointer m_ImageOutput;
259  unsigned short m_ObjectLabel;
260 
261  typedef ImageType::SizeType ImageSizeType;
262 };
263 } // end namespace itk
264 
265 #ifndef ITK_MANUAL_INSTANTIATION
266 #include "itkBalloonForceFilter.hxx"
267 #endif
268 
269 #endif //#if !defined( ITK_LEGACY_REMOVE )
270 #endif