ITK  4.3.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 "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 {
58 template< class TInputMesh, class TOutputMesh >
59 class ITK_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  DeformableMesh3DFilter(const Self &) {}
163  void operator=(const Self &) {}
164  void PrintSelf(std::ostream & os, Indent indent) const;
165 
166  virtual void GenerateData();
167 
168 private:
170  InputMeshPointer m_Forces;
171  InputMeshPointer m_Normals;
172  InputMeshPointer m_Displacements;
173  InputMeshPointer m_Derives;
174  InputMeshPointer m_Locations;
175 
176  void Initialize();
177 
178  void SetDefaultStiffnessMatrix();
179 
180  void SetMeshStiffness();
181 
182  void Advance(); // update data for next iteration
183 
184  void ComputeDt(); // compute point positions
185 
186  void ComputeOutput();
187 
188  void GradientFit(); // fit the model with gradient information
189 
190  void ComputeNormals();
191 
192  void PotentialFit();
193 
195  StiffnessMatrixType m_StiffnessMatrix[10];
196  StiffnessMatrixRawPointer *m_K;
197 
199  double2DVector m_Stiffness;
200 
202  double3DVector m_Scale;
203 
205  int m_NumberOfNodes;
206  int m_NumberOfCells;
207 
209  int m_ImageHeight;
210  int m_ImageDepth;
211 
215  unsigned short m_ModelXUpLimit;
216  unsigned short m_ModelXDownLimit;
217  unsigned short m_ModelYUpLimit;
218  unsigned short m_ModelYDownLimit;
219  unsigned short m_ModelZUpLimit;
220  unsigned short m_ModelZDownLimit;
221  unsigned short m_PotentialOn;
222  unsigned char m_ObjectLabel;
223  PixelType m_GradientMagnitude;
224  PixelType m_PotentialMagnitude;
225 
227  GradientImagePointer m_Gradient;
228  PotentialImageType::Pointer m_Potential;
229 };
230 } // end namespace itk
231 
232 #ifndef ITK_MANUAL_INSTANTIATION
233 #include "itkDeformableMesh3DFilter.hxx"
234 #endif
235 
236 #endif //#if !defined( ITK_LEGACY_REMOVE )
237 #endif
238