ITK  4.13.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 "itkMath.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 ITK_TEMPLATE_EXPORT 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() ITK_OVERRIDE;
195 
196 private:
197  ITK_DISALLOW_COPY_AND_ASSIGN(BalloonForceFilter);
198 
200  InputMeshPointer m_Forces;
201  InputMeshPointer m_Normals;
202  InputMeshPointer m_Displacements;
203  InputMeshPointer m_Derives;
204  InputMeshPointer m_Locations;
205  InputMeshPointer m_Input;
206  OutputMeshPointer m_Output;
207 
209  vnl_matrix_fixed< double, 4, 4 > m_NStiffness;
210  vnl_matrix_fixed< double, 4, 4 > m_SStiffness;
211  vnl_matrix_fixed< double, 4, 4 > m_CStiffness;
212  vnl_matrix_fixed< double, 4, 4 > **m_K;
213 
214  Double2Vector m_Stiffness;
215  double m_TimeStep; // the time step of each iteration
216  int m_Resolution;
217  IndexType m_Center;
218  float m_MiniT; // variabel help to stop the model when near
219  // potential estimation
220  int m_Step; // the number of iteration
221 
222  unsigned int m_NumberOfNodes;
223  unsigned int m_NumberOfCells;
224  unsigned int m_NumNewNodes; // for adding new nodes, now disabled for
225  // further tests
226  int * m_GapLocations;
227  float ** m_NewNodes;
228  int m_NewNodesExisted;
229  unsigned int m_NewNodeLimit;
230  unsigned int m_ImageWidth; // input image size
231  unsigned int m_ImageHeight;
232  unsigned int m_ImageDepth;
233 
234  int m_ModelXUpLimit; // the following 4 variables record the size of the
235  // model
236  int m_ModelXDownLimit;
237  int m_ModelYUpLimit;
238  int m_ModelYDownLimit;
239  int **m_ACD; // help to remove the weird structure on the model surface
240  int m_ModelRestart;
241  int m_GradientBegin;
242 
243  Int2Vector m_StepThreshold; // the threshold decide when to transfer from
244  // potential fit to gradient fit
245 
246  // and the threshold decide when to stop the model
247  float m_DistanceToBoundary;
248  float m_DistanceToStop;
249  float m_DistanceForGradient;
250 
251  ImagePointer m_Potential; // for calculate of image force from
252  // potential
253  GradientImagePointer m_Gradient; // for calculate of image force from
254  // gradient
255 
256  // for Gibbs Prior Model parameters' recalculation
257  ImagePointer m_ImageOutput;
258  unsigned short m_ObjectLabel;
259 
260  typedef ImageType::SizeType ImageSizeType;
261 };
262 } // end namespace itk
263 
264 #ifndef ITK_MANUAL_INSTANTIATION
265 #include "itkBalloonForceFilter.hxx"
266 #endif
267 
268 #endif //#if !defined( ITK_LEGACY_REMOVE )
269 #endif
class ITK_TEMPLATE_EXPORT CellInterface