ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkFEMRobustSolver.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 
19 #ifndef itkFEMRobustSolver_h
20 #define itkFEMRobustSolver_h
21 
22 #include "itkFEMSolver.h"
23 #include "itkFEMElementBase.h"
24 #include "itkFEMMaterialBase.h"
25 #include "itkFEMLoadBase.h"
29 
30 #include <cmath>
31 
32 namespace itk
33 {
34 namespace fem
35 {
82 
83 template <unsigned int VDimension = 3>
84 class ITK_TEMPLATE_EXPORT RobustSolver : public Solver<VDimension>
85 {
86 public:
88  typedef RobustSolver Self;
92 
94  itkNewMacro(Self);
95 
97  itkTypeMacro(RobustSolver, Solver);
98 
100  typedef typename Superclass::VectorType VectorType;
101  typedef typename Superclass::Float Float;
102  typedef typename Superclass::InterpolationGridType InterpolationGridType;
103  typedef typename Superclass::InterpolationGridPointerType InterpolationGridPointerType;
104  typedef typename Superclass::InterpolationGridSizeType InterpolationGridSizeType;
105  typedef typename Superclass::InterpolationGridRegionType InterpolationGridRegionType;
106  typedef typename Superclass::InterpolationGridPointType InterpolationGridPointType;
107  typedef typename Superclass::InterpolationGridSpacingType InterpolationGridSpacingType;
108  typedef typename Superclass::InterpolationGridIndexType InterpolationGridIndexType;
110 
111  itkStaticConstMacro(FEMDimension, unsigned int, VDimension);
112 
113  typedef typename Superclass::FEMObjectType FEMObjectType;
114 
116  typedef typename Element::MatrixType MatrixType;
117  typedef typename FEMObjectType::LoadContainerType LoadContainerType;
118  typedef typename FEMObjectType::NodeContainerType NodeContainerType;
119  typedef typename FEMObjectType::LoadContainerIterator LoadContainerIterator;
120 
124  itkSetMacro(ApproximationSteps, unsigned int);
125  itkGetMacro(ApproximationSteps, unsigned int);
127 
131  itkSetMacro(OutlierRejectionSteps, unsigned int);
132  itkGetMacro(OutlierRejectionSteps, unsigned int);
134 
140  itkSetMacro(ToleranceToLargestDisplacement, double);
141  itkGetMacro(ToleranceToLargestDisplacement, double);
143 
150  itkSetMacro(TradeOffImageMeshEnergy, double);
151  itkGetMacro(TradeOffImageMeshEnergy, double);
153 
158  itkSetMacro(FractionErrorRejected, double);
159  itkGetMacro(FractionErrorRejected, double);
161 
167  itkSetMacro(UseInterpolationGrid, bool);
168  itkGetMacro(UseInterpolationGrid, bool);
170 
171 protected:
172 
177  RobustSolver();
178  ~RobustSolver() ITK_OVERRIDE;
180 
183  virtual void GenerateData() ITK_OVERRIDE;
184 
186  virtual void RunSolver(void) ITK_OVERRIDE;
187 
189  void Initialization();
190 
197  void InitializeInterpolationGrid();
198 
203  void InitializeLandmarks();
204 
209  void AssembleMeshStiffnessMatrix();
210 
215  virtual void AssembleElementMatrixWithID(const Element::Pointer & e, unsigned int matrixIndex);
216 
221  void AssembleLandmarkStiffnessMatrix();
222 
224  void AssembleGlobalMatrixFromLandmarksAndMeshMatrices();
225 
227  void AssembleF();
228 
233  void IncrementalSolverWithOutlierRejection();
234 
239  void IncrementalSolverWithoutOutlierRejection();
240 
242  void SolveSystem();
243 
249  void ComputeLandmarkSimulatedDisplacementAndWeightedError();
250 
255  void ComputeLandmarkTensor();
256 
258  float GetLandmarkTensorPonderation() const;
259 
265  void NthElementWRTDisplacementError(unsigned int numberOfRejectedBlocksPerStep);
266 
273  void UnselectLandmarks(unsigned int numberOfRejectedBlocksPerStep);
274 
279  void RemoveUnselectedLandmarkContributionInPointStiffnessMatrix();
280 
285  void DeleteFromLandmarkBeginning(unsigned int numberOfRejectedLandmarksPerStep);
286 
288  void DeleteLandmarksOutOfMesh();
289 
297  void RescaleLandmarkStiffnessMatrix(double oldPointTensorPonderation);
298 
303  void CalculateExternalForces();
304 
309  void AddExternalForcesToSetMeshZeroEnergy();
310 
311 private:
312 
313  ITK_DISALLOW_COPY_AND_ASSIGN(RobustSolver);
314 
319  unsigned int m_OutlierRejectionSteps;
320 
324  unsigned int m_ApproximationSteps;
325 
326 
328  typedef unsigned int FEMIndexType;
329 
330  FEMIndexType m_ForceIndex;
331  FEMIndexType m_LandmarkForceIndex;
332  FEMIndexType m_ExternalForceIndex;
333  FEMIndexType m_SolutionIndex;
334  FEMIndexType m_MeshStiffnessMatrixIndex;
335  FEMIndexType m_LandmarkStiffnessMatrixIndex;
336  FEMIndexType m_StiffnessMatrixIndex;
337 
338  double m_TradeOffImageMeshEnergy;
339 
340  double m_ToleranceToLargestDisplacement;
341  double m_ConjugateGradientPrecision;
342  double m_FractionErrorRejected;
343 
350  bool m_UseInterpolationGrid;
351 
353 };
354 
362  public std::binary_function<const Load::Pointer &, const Load::Pointer &, bool>
363 {
364 public:
365  bool operator()(const Load::Pointer & L1 , const Load::Pointer & L2)
366  {
367  LoadNoisyLandmark * l1 = dynamic_cast<LoadNoisyLandmark*>(L1.GetPointer());
368  LoadNoisyLandmark * l2 = dynamic_cast<LoadNoisyLandmark*>(L2.GetPointer());
370 
371  return l1->GetErrorNorm() > l2->GetErrorNorm();
372  }
373 };
374 
375 } // end namespace fem
376 } // end namespace itk
377 
378 #ifndef ITK_MANUAL_INSTANTIATION
379 #include "itkFEMRobustSolver.hxx"
380 #endif
381 
382 #endif
Light weight base class for most itk classes.
Superclass::FEMObjectType FEMObjectType
Superclass::InterpolationGridSpacingType InterpolationGridSpacingType
Superclass::InterpolationGridIndexType InterpolationGridIndexType
ObjectType * GetPointer() const
FEMObjectType::LoadContainerIterator LoadContainerIterator
FEMObjectType::LoadContainerType LoadContainerType
vnl_matrix< Float > MatrixType
SmartPointer< Self > Pointer
Superclass::VectorType VectorType
Superclass::InterpolationGridPointerType InterpolationGridPointerType
FEM solver used to generate a solution for a FE formulation.
Definition: itkFEMSolver.h:73
Abstract base element class.
bool operator()(const Load::Pointer &L1, const Load::Pointer &L2)
Element::MatrixType MatrixType
General abstract load base class.
InterpolationGridType::DirectionType InterpolationGridDirectionType
LinearSystemWrapper class that uses Itpack numeric library functions to define and solve a sparse lin...
Superclass::InterpolationGridSizeType InterpolationGridSizeType
static ITK_CONSTEXPR_VAR double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:56
Superclass::InterpolationGridType InterpolationGridType
FEMObjectType::NodeContainerType NodeContainerType
Superclass::InterpolationGridRegionType InterpolationGridRegionType
Superclass::InterpolationGridPointType InterpolationGridPointType
SmartPointer< const Self > ConstPointer
Solver< VDimension > Superclass