ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkDeformableMesh3DFilter_h 00019 #define __itkDeformableMesh3DFilter_h 00020 00021 #include "itkMeshToMeshFilter.h" 00022 #include "vnl/vnl_matrix_fixed.h" 00023 #include "vnl/vnl_math.h" 00024 #include "itkMesh.h" 00025 #include "itkTriangleCell.h" 00026 #include "itkImage.h" 00027 #include "itkImageRegionIterator.h" 00028 #include "itkCovariantVector.h" 00029 00030 namespace itk 00031 { 00056 template< class TInputMesh, class TOutputMesh > 00057 class ITK_EXPORT DeformableMesh3DFilter:public MeshToMeshFilter< TInputMesh, TOutputMesh > 00058 { 00059 public: 00061 typedef DeformableMesh3DFilter Self; 00062 00064 typedef MeshToMeshFilter< TInputMesh, TOutputMesh > Superclass; 00065 00067 typedef SmartPointer< Self > Pointer; 00068 typedef SmartPointer< const Self > ConstPointer; 00069 00071 itkNewMacro(Self); 00072 00074 itkTypeMacro(DeformableMesh3DFilter, MeshToMeshFilter); 00075 00077 typedef TInputMesh InputMeshType; 00078 typedef typename InputMeshType::PointsContainerPointer InputPointsContainerPointer; 00079 typedef typename InputMeshType::PointsContainerConstPointer InputPointsContainerConstPointer; 00080 typedef typename InputMeshType::PointsContainer::Iterator InputPointsContainerIterator; 00081 typedef typename InputMeshType::PointsContainer::ConstIterator InputPointsContainerConstIterator; 00082 typedef typename InputMeshType::PointDataContainerPointer InputPointDataContainerPointer; 00083 typedef typename InputMeshType::PointDataContainer::Iterator InputPointDataContainerIterator; 00084 typedef typename InputMeshType::CellsContainerPointer InputCellsContainerPointer; 00085 typedef typename InputMeshType::CellsContainer::Iterator InputCellsContainerIterator; 00086 typedef typename InputMeshType::CellsContainerConstPointer InputCellsContainerConstPointer; 00087 typedef typename InputMeshType::CellsContainer::ConstIterator InputCellsContainerConstIterator; 00088 typedef typename InputMeshType::CellDataContainerPointer InputCellDataContainerPointer; 00089 typedef typename InputMeshType::CellDataContainer::Iterator InputCellDataContainerIterator; 00090 typedef typename InputMeshType::CellDataContainerConstPointer InputCellDataContainerConstPointer; 00091 typedef typename InputMeshType::CellDataContainer::ConstIterator InputCellDataContainerConstIterator; 00092 00093 typedef TOutputMesh OutputMeshType; 00094 typedef typename OutputMeshType::PointsContainerPointer OutputPointsContainerPointer; 00095 typedef typename OutputMeshType::CellsContainer OutputCellsContainer; 00096 typedef typename OutputMeshType::CellsContainerPointer OutputCellsContainerPointer; 00097 typedef typename OutputMeshType::PointsContainer::Iterator OutputPointsContainerIterator; 00098 00100 typedef typename InputMeshType::CellType CellType; 00101 typedef typename InputMeshType::CellTraits CellTraits; 00102 typedef typename InputMeshType::PointType InputPointType; 00103 typedef typename InputMeshType::PixelType PixelType; 00104 00106 typedef Image< unsigned char, 3 > PotentialImageType; 00107 typedef ImageRegionIterator< PotentialImageType > PotentialIterator; 00108 typedef CovariantVector< PixelType, 3 > GradientType; 00109 typedef Image< GradientType, 3 > GradientImageType; 00110 typedef ImageRegionIterator< GradientImageType > GradientIterator; 00111 typedef typename GradientImageType::SizeType ImageSizeType; 00112 typedef typename GradientImageType::IndexType ImageIndexType; 00113 00114 typedef itk::CellInterface< PixelType, CellTraits > TCellInterface; 00115 typedef itk::TriangleCell< TCellInterface > TriCell; 00116 00117 typedef CovariantVector< int, 3 > int3DVector; 00118 typedef CovariantVector< double, 2 > double2DVector; 00119 typedef CovariantVector< double, 3 > double3DVector; 00120 00121 /* Mesh pointer definition. */ 00122 typedef typename InputMeshType::Pointer InputMeshPointer; 00123 typedef typename InputMeshType::ConstPointer InputMeshConstPointer; 00124 typedef typename OutputMeshType::Pointer OutputMeshPointer; 00125 typedef typename GradientImageType::Pointer GradientImagePointer; 00126 00127 /* Stiffness Matrix Type definition */ 00128 typedef vnl_matrix_fixed< double, 4, 4 > StiffnessMatrixType; 00129 typedef StiffnessMatrixType * StiffnessMatrixRawPointer; 00130 00132 void SetStiffnessMatrix(StiffnessMatrixType *stiff, int i); 00133 00135 itkSetMacro(Gradient, GradientImagePointer); 00136 itkGetConstMacro(Gradient, GradientImagePointer); 00138 00139 itkSetMacro(StepThreshold, int); 00140 itkGetConstMacro(StepThreshold, int); 00141 00142 itkSetMacro(Stiffness, double2DVector); 00143 itkGetConstMacro(Stiffness, double2DVector); 00144 00145 itkSetMacro(TimeStep, double); 00146 itkGetConstMacro(TimeStep, double); 00147 00148 itkSetMacro(Scale, double3DVector); 00149 00150 itkSetMacro(PotentialMagnitude, PixelType); 00151 itkSetMacro(GradientMagnitude, PixelType); 00152 itkSetMacro(PotentialOn, unsigned short); 00153 itkSetMacro(ObjectLabel, unsigned char); 00154 00155 itkGetConstMacro(Normals, InputMeshPointer); 00156 protected: 00157 DeformableMesh3DFilter(); 00158 ~DeformableMesh3DFilter(); 00159 DeformableMesh3DFilter(const Self &) {} 00160 void operator=(const Self &) {} 00161 void PrintSelf(std::ostream & os, Indent indent) const; 00162 00163 virtual void GenerateData(); 00164 00165 private: 00167 InputMeshPointer m_Forces; 00168 InputMeshPointer m_Normals; 00169 InputMeshPointer m_Displacements; 00170 InputMeshPointer m_Derives; 00171 InputMeshPointer m_Locations; 00172 00173 void Initialize(); 00174 00175 void SetDefaultStiffnessMatrix(); 00176 00177 void SetMeshStiffness(); 00178 00179 void Advance(); // update data for next iteration 00180 00181 void ComputeDt(); // compute point positions 00182 00183 void ComputeOutput(); 00184 00185 void GradientFit(); // fit the model with gradient information 00186 00187 void ComputeNormals(); 00188 00189 void PotentialFit(); 00190 00192 StiffnessMatrixType m_StiffnessMatrix[10]; 00193 StiffnessMatrixRawPointer *m_K; 00194 00196 double2DVector m_Stiffness; 00197 00199 double3DVector m_Scale; 00200 00202 int m_NumberOfNodes; 00203 int m_NumberOfCells; 00204 00206 int m_ImageHeight; 00207 int m_ImageDepth; 00208 00212 unsigned short m_ModelXUpLimit; 00213 unsigned short m_ModelXDownLimit; 00214 unsigned short m_ModelYUpLimit; 00215 unsigned short m_ModelYDownLimit; 00216 unsigned short m_ModelZUpLimit; 00217 unsigned short m_ModelZDownLimit; 00218 unsigned short m_PotentialOn; 00219 unsigned char m_ObjectLabel; 00220 PixelType m_GradientMagnitude; 00221 PixelType m_PotentialMagnitude; 00222 00224 GradientImagePointer m_Gradient; 00225 PotentialImageType::Pointer m_Potential; 00226 }; 00227 } // end namespace itk 00228 00229 #ifndef ITK_MANUAL_INSTANTIATION 00230 #include "itkDeformableMesh3DFilter.hxx" 00231 #endif 00232 00233 #endif 00234