ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkFEMSolver.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 __itkFEMSolver_h
20 #define __itkFEMSolver_h
21 
22 #include "itkProcessObject.h"
23 #include "itkFEMObject.h"
24 
27 
28 #include "itkImage.h"
29 
30 namespace itk
31 {
32 namespace fem
33 {
68 template <unsigned int VDimension = 3>
69 class ITK_EXPORT Solver : public ProcessObject
70 {
71 public:
72 
74  typedef Solver Self;
78 
80  itkNewMacro(Self);
81 
83  itkTypeMacro(Solver, ProcessObject);
84 
85  itkStaticConstMacro(FEMDimension, unsigned int, VDimension);
86  itkStaticConstMacro(MaxDimensions, unsigned int, 3);
87 
93 
101 
113 
114  /*
115  * Get/Set the Interpolation Grid Origin
116  */
117  itkSetMacro(Origin, InterpolationGridPointType);
118  itkGetMacro(Origin, InterpolationGridPointType);
119 
120  /*
121  * Get/Set the Interpolation Grid Spacing
122  */
123  itkSetMacro(Spacing, InterpolationGridSpacingType);
124  itkGetMacro(Spacing, InterpolationGridSpacingType);
125 
126  /*
127  * Get/Set the Interpolation Grid Region
128  */
129  itkSetMacro(Region, InterpolationGridRegionType);
130  itkGetMacro(Region, InterpolationGridRegionType);
131 
132  /*
133  * Get/Set the Interpolation Grid Direction
134  */
135  itkSetMacro(Direction, InterpolationGridDirectionType);
136  itkGetMacro(Direction, InterpolationGridDirectionType);
137 
139  virtual Float GetTimeStep(void) const;
140 
146  virtual void SetTimeStep(Float dt);
147 
149  Float GetSolution(unsigned int i, unsigned int which = 0);
150 
153  using Superclass::SetInput;
154  virtual void SetInput( FEMObjectType *fem);
155 
156  virtual void SetInput( unsigned int, FEMObjectType * fem);
157 
158  FEMObjectType * GetInput(void);
159 
160  FEMObjectType * GetInput(unsigned int idx);
161 
170  const Element * GetElementAtPoint(const VectorType & pt) const;
171 
173  Float GetDeformationEnergy(unsigned int SolutionIndex = 0);
174 
189  void SetLinearSystemWrapper(LinearSystemWrapper::Pointer ls);
190 
196  LinearSystemWrapper::Pointer GetLinearSystemWrapper()
197  {
198  return m_ls;
199  }
200 
215  void InitializeInterpolationGrid(const InterpolationGridSizeType & size, const InterpolationGridPointType & bb1,
216  const InterpolationGridPointType & bb2);
217 
219  void InitializeInterpolationGrid(const InterpolationGridSizeType & size)
220  {
223 
224  bb1.Fill(0.0);
225 
227  for( unsigned int i = 0; i < FEMDimension; i++ )
228  {
229  bb2[i] = size[i] - 1.0;
230  }
231  InitializeInterpolationGrid(size, bb1, bb2);
232  }
233 
237  void InitializeInterpolationGrid(const InterpolationGridRegionType & region,
238  const InterpolationGridPointType & origin,
239  const InterpolationGridSpacingType & spacing,
240  const InterpolationGridDirectionType & direction);
241 
252  const InterpolationGridType * GetInterpolationGrid(void) const
253  {
254  return m_InterpolationGrid.GetPointer();
255  }
256 
257 
261  using Superclass::MakeOutput;
263 
277  FEMObjectType * GetOutput(void);
278 
279  FEMObjectType * GetOutput(unsigned int idx);
280 
281 protected:
282  Solver();
283  virtual ~Solver();
284  void PrintSelf(std::ostream& os, Indent indent) const;
285 
288  void GenerateData();
289 
290 
299  // void GenerateGFN(void);
300 
304  void AssembleK();
305 
312  virtual void InitializeMatrixForAssembly(unsigned int N);
313 
319  virtual void FinalizeMatrixAfterAssembly(void)
320  {
321  // Apply the boundary conditions to the K matrix
322  this->ApplyBC();
323  }
324 
331  virtual void AssembleElementMatrix(Element::Pointer e);
332 
340  virtual void AssembleLandmarkContribution(Element::ConstPointer e, float);
341 
355  void ApplyBC(int dim = 0, unsigned int matrix = 0);
356 
364  void AssembleF(int dim = 0);
365 
369  void DecomposeK(void);
370 
374  virtual void RunSolver(void);
375 
380  void UpdateDisplacements(void);
381 
385  void FillInterpolationGrid(void);
386 
391  virtual void InitializeLinearSystemWrapper(void);
392 
396  unsigned int m_NGFN;
397 
402  unsigned int m_NMFC;
403 
406 
411 
418 
420 
421 private:
422  Solver(const Self &); // purposely not implemented
423  void operator=(const Self &); // purposely not implemented
424 
425  /*
426  * Properties of the Interpolation Grid
427  */
432 
433 };
434 } // end namespace fem
435 } // end namespace itk
436 
437 #ifndef ITK_MANUAL_INSTANTIATION
438 #include "itkFEMSolver.hxx"
439 #endif
440 
441 #endif // #ifndef __itkFEMSolver_h
442