ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkDeformableMesh3DFilter.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 itkDeformableMesh3DFilter_h
19 #define itkDeformableMesh3DFilter_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 {
58 template< typename TInputMesh, typename TOutputMesh >
59 class ITK_TEMPLATE_EXPORT DeformableMesh3DFilter:public MeshToMeshFilter< TInputMesh, TOutputMesh >
60 {
61 public:
63  typedef DeformableMesh3DFilter Self;
64 
66  typedef MeshToMeshFilter< TInputMesh, TOutputMesh > Superclass;
67 
69  typedef SmartPointer< Self > Pointer;
70  typedef SmartPointer< const Self > ConstPointer;
71 
73  itkNewMacro(Self);
74 
76  itkTypeMacro(DeformableMesh3DFilter, MeshToMeshFilter);
77 
79  typedef TInputMesh InputMeshType;
80  typedef typename InputMeshType::PointsContainerPointer InputPointsContainerPointer;
81  typedef typename InputMeshType::PointsContainerConstPointer InputPointsContainerConstPointer;
82  typedef typename InputMeshType::PointsContainer::Iterator InputPointsContainerIterator;
83  typedef typename InputMeshType::PointsContainer::ConstIterator InputPointsContainerConstIterator;
84  typedef typename InputMeshType::PointDataContainerPointer InputPointDataContainerPointer;
85  typedef typename InputMeshType::PointDataContainer::Iterator InputPointDataContainerIterator;
86  typedef typename InputMeshType::CellsContainerPointer InputCellsContainerPointer;
87  typedef typename InputMeshType::CellsContainer::Iterator InputCellsContainerIterator;
88  typedef typename InputMeshType::CellsContainerConstPointer InputCellsContainerConstPointer;
89  typedef typename InputMeshType::CellsContainer::ConstIterator InputCellsContainerConstIterator;
90  typedef typename InputMeshType::CellDataContainerPointer InputCellDataContainerPointer;
91  typedef typename InputMeshType::CellDataContainer::Iterator InputCellDataContainerIterator;
92  typedef typename InputMeshType::CellDataContainerConstPointer InputCellDataContainerConstPointer;
93  typedef typename InputMeshType::CellDataContainer::ConstIterator InputCellDataContainerConstIterator;
94 
95  typedef TOutputMesh OutputMeshType;
96  typedef typename OutputMeshType::PointsContainerPointer OutputPointsContainerPointer;
97  typedef typename OutputMeshType::CellsContainer OutputCellsContainer;
98  typedef typename OutputMeshType::CellsContainerPointer OutputCellsContainerPointer;
99  typedef typename OutputMeshType::PointsContainer::Iterator OutputPointsContainerIterator;
100 
102  typedef typename InputMeshType::CellType CellType;
103  typedef typename InputMeshType::CellTraits CellTraits;
104  typedef typename InputMeshType::PointType InputPointType;
105  typedef typename InputMeshType::PixelType PixelType;
106 
108  typedef Image< unsigned char, 3 > PotentialImageType;
109  typedef ImageRegionIterator< PotentialImageType > PotentialIterator;
110  typedef CovariantVector< PixelType, 3 > GradientType;
111  typedef Image< GradientType, 3 > GradientImageType;
112  typedef ImageRegionIterator< GradientImageType > GradientIterator;
113  typedef typename GradientImageType::SizeType ImageSizeType;
114  typedef typename GradientImageType::IndexType ImageIndexType;
115 
116  typedef itk::CellInterface< PixelType, CellTraits > TCellInterface;
117  typedef itk::TriangleCell< TCellInterface > TriCell;
118 
119  typedef CovariantVector< int, 3 > int3DVector;
120  typedef CovariantVector< double, 2 > double2DVector;
121  typedef CovariantVector< double, 3 > double3DVector;
122 
123  /* Mesh pointer definition. */
124  typedef typename InputMeshType::Pointer InputMeshPointer;
125  typedef typename InputMeshType::ConstPointer InputMeshConstPointer;
126  typedef typename OutputMeshType::Pointer OutputMeshPointer;
127  typedef typename GradientImageType::Pointer GradientImagePointer;
128 
129  /* Stiffness Matrix Type definition */
130  typedef vnl_matrix_fixed< double, 4, 4 > StiffnessMatrixType;
131  typedef StiffnessMatrixType * StiffnessMatrixRawPointer;
132 
134  void SetStiffnessMatrix(StiffnessMatrixType *stiff, int i);
135 
137  itkSetMacro(Gradient, GradientImagePointer);
138  itkGetConstMacro(Gradient, GradientImagePointer);
140 
141  itkSetMacro(StepThreshold, int);
142  itkGetConstMacro(StepThreshold, int);
143 
144  itkSetMacro(Stiffness, double2DVector);
145  itkGetConstMacro(Stiffness, double2DVector);
146 
147  itkSetMacro(TimeStep, double);
148  itkGetConstMacro(TimeStep, double);
149 
150  itkSetMacro(Scale, double3DVector);
151 
152  itkSetMacro(PotentialMagnitude, PixelType);
153  itkSetMacro(GradientMagnitude, PixelType);
154  itkSetMacro(PotentialOn, unsigned short);
155  itkSetMacro(ObjectLabel, unsigned char);
156 
157  itkGetConstMacro(Normals, InputMeshPointer);
158 
159 protected:
160  DeformableMesh3DFilter();
161  ~DeformableMesh3DFilter();
162  ITK_DISALLOW_COPY_AND_ASSIGN(DeformableMesh3DFilter);
163  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
164 
165  virtual void GenerateData() ITK_OVERRIDE;
166 
167 private:
169  InputMeshPointer m_Forces;
170  InputMeshPointer m_Normals;
171  InputMeshPointer m_Displacements;
172  InputMeshPointer m_Derives;
173  InputMeshPointer m_Locations;
174 
175  void Initialize();
176 
177  void SetDefaultStiffnessMatrix();
178 
179  void SetMeshStiffness();
180 
181  void Advance(); // update data for next iteration
182 
183  void ComputeDt(); // compute point positions
184 
185  void ComputeOutput();
186 
187  void GradientFit(); // fit the model with gradient information
188 
189  void ComputeNormals();
190 
191  void PotentialFit();
192 
194  StiffnessMatrixType m_StiffnessMatrix[10];
195  StiffnessMatrixRawPointer *m_K;
196 
198  double2DVector m_Stiffness;
199 
201  double3DVector m_Scale;
202 
204  int m_NumberOfNodes;
205  int m_NumberOfCells;
206 
208  int m_ImageHeight;
209  int m_ImageDepth;
210 
214  unsigned short m_ModelXUpLimit;
215  unsigned short m_ModelXDownLimit;
216  unsigned short m_ModelYUpLimit;
217  unsigned short m_ModelYDownLimit;
218  unsigned short m_ModelZUpLimit;
219  unsigned short m_ModelZDownLimit;
220  unsigned short m_PotentialOn;
221  unsigned char m_ObjectLabel;
222  PixelType m_GradientMagnitude;
223  PixelType m_PotentialMagnitude;
224 
226  GradientImagePointer m_Gradient;
227  PotentialImageType::Pointer m_Potential;
228 };
229 } // end namespace itk
230 
231 #ifndef ITK_MANUAL_INSTANTIATION
232 #include "itkDeformableMesh3DFilter.hxx"
233 #endif
234 
235 #endif //#if !defined( ITK_LEGACY_REMOVE )
236 #endif
An abstract interface for cells.