ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkFEMImageMetricLoad.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 __itkFEMImageMetricLoad_h
19 #define __itkFEMImageMetricLoad_h
20 
21 #include "itkFEMLoadElementBase.h"
22 
23 #include "itkImage.h"
25 
30 #include "itkDerivativeOperator.h"
33 #include "vnl/vnl_math.h"
34 
39 
40 namespace itk
41 {
42 namespace fem
43 {
68 template <class TMoving, class TFixed>
70 {
71 public:
72 
78 
80  itkSimpleNewMacro(Self);
81 
83  itkTypeMacro(ImageMetricLoad, LoadElement);
84 
87  virtual::itk::LightObject::Pointer CreateAnother(void) const;
88 
89  // Necessary typedefs for dealing with images BEGIN
90  typedef typename LoadElement::Float Float;
91 
92  typedef TMoving MovingType;
93  typedef typename MovingType::ConstPointer MovingConstPointer;
95  typedef TFixed FixedType;
97  typedef typename FixedType::ConstPointer FixedConstPointer;
98 
100  itkStaticConstMacro(ImageDimension, unsigned int,
101  MovingType::ImageDimension);
102 
105 
118 
119 // IMAGE DATA
120  typedef typename MovingType::PixelType RefPixelType;
121  typedef typename FixedType::PixelType TarPixelType;
122  typedef Float PixelType;
128 
129 // Necessary typedefs for dealing with images END
130 
131 // ------------------------------------------------------------
132 // Set up the metrics
133 // ------------------------------------------------------------
134  typedef double
136  typedef Transform<CoordinateRepresentationType, itkGetStaticConstMacro(ImageDimension),
137  itkGetStaticConstMacro(ImageDimension)> TransformBaseType;
139  itkGetStaticConstMacro(ImageDimension)> DefaultTransformType;
140 
144 
146 
148 
150 
154 
155  typedef unsigned long ElementIdentifier;
157 // ------------------------------------------------------------
158 // Set up an Interpolator
159 // ------------------------------------------------------------
161 
163  typedef float RealType;
164  typedef CovariantVector<RealType,
165  itkGetStaticConstMacro(ImageDimension)> GradientPixelType;
166  typedef Image<GradientPixelType,
167  itkGetStaticConstMacro(ImageDimension)> GradientImageType;
172  // typedef typename GradientImageFilterType::Pointer
173  // GradientImageFilterPointer;
175 
176 // FUNCTIONS
177 
180  {
181  m_Metric = MP;
182  }
183 
186  {
187  m_RefImage = R;
188  m_RefSize = m_RefImage->GetLargestPossibleRegion().GetSize();
189  }
191 
193  {
194  m_Metric->SetMovingImage(R);
195  m_RefSize = R->GetLargestPossibleRegion().GetSize();
196  }
197 
200  {
201  m_TarImage = T;
202  m_TarSize = T->GetLargestPossibleRegion().GetSize();
203  }
205 
207  {
208  m_Metric->SetFixedImage(T);
209  m_TarSize = T->GetLargestPossibleRegion().GetSize();
210  }
211 
213  {
214  return m_RefImage;
215  }
217  {
218  return m_TarImage;
219  }
220 
223  {
224  m_MetricRadius = T;
225  }
226 
229  {
230  return m_MetricRadius;
231  }
232 
237  void SetNumberOfIntegrationPoints(unsigned int i)
238  {
240  }
242  {
244  }
246 
250  void SetSign(Float s)
251  {
252  m_Sign = s;
253  }
254 
256  void SetTemp(Float s)
257  {
258  m_Temp = s;
259  }
260 
262  void SetGamma(Float s)
263  {
264  m_Gamma = s;
265  }
266 
271  {
272  m_Solution = ptr;
273  }
274 
279  {
280  return m_Solution;
281  }
282 
286  Float GetMetric(VectorType InVec);
287 
288  VectorType GetPolynomialFitToMetric(VectorType PositionInElement, VectorType SolutionAtPosition);
289 
290  VectorType MetricFiniteDiff(VectorType PositionInElement, VectorType SolutionAtPosition);
291 
292  // FIXME - WE ASSUME THE 2ND VECTOR (INDEX 1) HAS THE INFORMATION WE WANT
293  Float GetSolution(unsigned int i, unsigned int which = 0)
294  {
295  return m_Solution->GetSolutionValue(i, which);
296  }
297 
298 // define the copy constructor
299 // ImageMetricLoad(const ImageMetricLoad& LMS);
300 
301  void InitializeMetric(void);
302 
303  ImageMetricLoad(); // cannot be private until we always use smart pointers
305 
307 
312 
314  {
315  return new ImageMetricLoad;
316  }
317 
319  // void InitializeGradientImage();
321  {
323  }
325  {
326  return m_MetricGradientImage;
327  }
329 
331  {
332  std::cout << " energy " << m_Energy << std::endl;
333  }
335  {
336  return m_Energy;
337  }
338  void SetCurrentEnergy(double e)
339  {
340  m_Energy = e;
341  }
342 
343  // FIXME - Documentation
344  virtual void ApplyLoad(Element::ConstPointer element, Element::VectorType & Fe);
345 
346 protected:
347  virtual void PrintSelf(std::ostream& os, Indent indent) const;
348 
349 private:
355  typename MovingType::SizeType m_RefSize;
356  typename FixedType::SizeType m_TarSize;
358  unsigned int m_SolutionIndex;
359  unsigned int m_SolutionIndex2;
363 
368 
369  mutable double m_Energy;
370 
371 private:
372 
373 };
374 }
375 } // end namespace fem/itk
376 
377 #ifndef ITK_MANUAL_INSTANTIATION
378 #include "itkFEMImageMetricLoad.hxx"
379 #endif
380 
381 #endif
382