ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkImageRegistrationMethodImageSource.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 __itkImageRegistrationMethodImageSource_h
19 #define __itkImageRegistrationMethodImageSource_h
20 #include "itkImage.h"
23 #include "itkOptimizerParameters.h"
24 
34 namespace itk
35 {
36 
37 namespace testhelper
38 {
39 
40 template< typename TFixedPixelType,
41  typename TMovingPixelType,
42  unsigned int NDimension >
44 {
45 public:
46 
48  typedef Object Superclass;
52 
54  itkNewMacro(Self);
55 
57  itkTypeMacro(Image, Object);
58 
59 
62 
63 const MovingImageType * GetMovingImage(void) const
64  {
65  return m_MovingImage.GetPointer();
66  }
67 
68 const FixedImageType * GetFixedImage(void) const
69  {
70  return m_FixedImage.GetPointer();
71  }
72 
74 {
75  return m_Parameters;
76 }
77 
78 
79 void GenerateImages( const typename MovingImageType::SizeType & size )
80 {
81  typename MovingImageType::IndexType index;
82  index.Fill(0);
83  typename MovingImageType::RegionType region;
84  region.SetSize( size );
85  region.SetIndex( index );
86 
87  m_MovingImage->SetLargestPossibleRegion( region );
88  m_MovingImage->SetBufferedRegion( region );
89  m_MovingImage->SetRequestedRegion( region );
90  m_MovingImage->Allocate();
91 
92  m_FixedImage->SetLargestPossibleRegion( region );
93  m_FixedImage->SetBufferedRegion( region );
94  m_FixedImage->SetRequestedRegion( region );
95  m_FixedImage->Allocate();
96 
97  /* Fill images with a 2D gaussian*/
98  typedef itk::ImageRegionIteratorWithIndex<MovingImageType> MovingImageIteratorType;
99 
100  typedef itk::ImageRegionIteratorWithIndex<FixedImageType> FixedImageIteratorType;
101 
102 
103  itk::Point<double,2> center;
104  center[0] = (double)region.GetSize()[0]/2.0;
105  center[1] = (double)region.GetSize()[1]/2.0;
106 
107  const double s = (double)region.GetSize()[0]/2.0;
108 
111 
112  /* Set the displacement */
113  itk::Vector<double,2> displacement;
114  displacement[0] = m_Parameters[0];
115  displacement[1] = m_Parameters[1];
116 
117 
118  MovingImageIteratorType ri(m_MovingImage,region);
119  FixedImageIteratorType ti(m_FixedImage,region);
120  while(!ri.IsAtEnd())
121  {
122  p[0] = ri.GetIndex()[0];
123  p[1] = ri.GetIndex()[1];
124  d = p-center;
125  d += displacement;
126  const double x = d[0];
127  const double y = d[1];
128  const double value = 200.0 * std::exp( - ( x*x + y*y )/(s*s) );
129  ri.Set( static_cast<typename MovingImageType::PixelType>(value) );
130  ++ri;
131  }
132 
133 
134  while(!ti.IsAtEnd())
135  {
136  p[0] = ti.GetIndex()[0];
137  p[1] = ti.GetIndex()[1];
138  d = p-center;
139  const double x = d[0];
140  const double y = d[1];
141  const double value = 200.0 * std::exp( - ( x*x + y*y )/(s*s) );
142  ti.Set( static_cast<typename FixedImageType::PixelType>(value) );
143  ++ti;
144  }
145 
146 
147 }
148 
149 protected:
150 
152 {
156  m_Parameters[0] = 7.0;
157  m_Parameters[1] = 3.0;
158 }
159 
160 private:
161 
164 
166 
167 };
168 
169 } // end namespace testhelper
170 
171 } // end namespace itk
172 #endif
Superclass::RegionType RegionType
Definition: itkImage.h:140
Light weight base class for most itk classes.
Represent the size (bounds) of a n-dimensional image.
Definition: itkSize.h:52
ObjectType * GetPointer() const
static Pointer New()
void GenerateImages(const typename MovingImageType::SizeType &size)
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
Superclass::IndexType IndexType
Definition: itkImage.h:122
Base class for most ITK classes.
Definition: itkObject.h:57
Templated n-dimensional image class.
Definition: itkImage.h:75