KWStyle - itkImageToImageFilter.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkImageToImageFilter.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:40 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12   Portions of this code are covered under the VTK copyright.
13   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14
15      This software is distributed WITHOUT ANY WARRANTY; without even 
16      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
17 IND *****PURPOSE.  See the above copyright notices for more information.
18
19 =========================================================================*/
20 #ifndef __itkImageToImageFilter_h
21 #define __itkImageToImageFilter_h
22
23 #include "itkImage.h"
24 #include "itkImageSource.h"
25 #include "itkConceptChecking.h"
26 #include "itkImageToImageFilterDetail.h"
27
28 namespace itk
29 {
30   
31 /** \class ImageToImageFilter
32 LEN  * \brief Base class for filters that take an image as input and produce an image as output.
33  *
34  * ImageToImageFilter is the base class for all process objects that output
35  * image data and require image data as input. Specifically, this class
36  * defines the SetInput() method for defining the input to a filter.
37  *
38  * This class provides the infrastructure for supporting multithreaded
39  * processing of images.  If a filter provides an implementation of
40  * GenerateData(), the image processing will run in a single thread and the
41  * implementation is responsible for allocating its output data.  If a filter
42  * provides an implementation of ThreadedGenerateData() instead, the image
43  * will be divided into a number of pieces, a number of threads will be
44  * spawned, and ThreadedGenerateData() will be called in each thread.  Here,
45  * the output memory will be allocated by this superclass prior to calling
46  * ThreadedGenerateData().
47  *
48  * ImageToImageFilter provides an implementation of
49  * GenerateInputRequestedRegion().  The base assumption to this point in the
50  * heirarchy is that a process object would ask for the largest possible
51  * region on input in order to produce any output.  Imaging filters,
52  * however, can usually answer this question more precisely.  The default
53  * implementation of GenerateInputRequestedRegion() in this class is to
54  * request an input that matches the size of the requested output.  If a
55  * filter requires more input (say a filter that uses neighborhood
56  * information) or less input (for instance a magnify filter), then these
57  * filters will have to provide another implmentation of this method. By
58  * convention, such implementations should call the Superclass' method
59  * first.
60  *
61  * \ingroup ImageFilters
62  */
63 template <class TInputImage, class TOutputImage>
64 class ITK_EXPORT ImageToImageFilter : public ImageSource<TOutputImage>
65 {
66 public:
67   /** Standard class typedefs. */
68   typedef ImageToImageFilter  Self;
69 TDA   typedef ImageSource<TOutputImage>  Superclass;
70   typedef SmartPointer<Self>  Pointer;
71 TDA   typedef SmartPointer<const Self>  ConstPointer;
72   
73   
74   /** Run-time type information (and related methods). */
75   itkTypeMacro(ImageToImageFilter,ImageSource);
76
77   /** Superclass typedefs. */
78   typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
79
80   /** Some convenient typedefs. */
81   typedef TInputImage InputImageType;
82 TDA   typedef typename InputImageType::Pointer        InputImagePointer;
83 TDA   typedef typename InputImageType::ConstPointer   InputImageConstPointer;
84 TDA   typedef typename InputImageType::RegionType     InputImageRegionType; 
85 TDA   typedef typename InputImageType::PixelType      InputImagePixelType; 
86   
87   /** ImageDimension constants */
88   itkStaticConstMacro(InputImageDimension, unsigned int,
89                       TInputImage::ImageDimension);
90   itkStaticConstMacro(OutputImageDimension, unsigned int,
91                       TOutputImage::ImageDimension);
92
93   /** Set/Get the image input of this process object.  */
94   virtual void SetInput( const InputImageType *image);
95   virtual void SetInput( unsigned int, const TInputImage * image);
96   const InputImageType * GetInput(void);
97   const InputImageType * GetInput(unsigned int idx);
98
99
100 IND *protected:
101   ImageToImageFilter();
102   ~ImageToImageFilter();
103
104   virtual void PrintSelf(std::ostream& os, Indent indent) const;
105
106   /** What is the input requested region that is required to produce
107    * the output requested region? The base assumption for image
108    * processing filters is that the input requested region can be set
109    * to match the output requested region.  If a filter requires more
110    * input (for instance a filter that uses neighborhoods needs more
111    * input than output to avoid introducing artificial boundary
112    * conditions) or less input (for instance a magnify filter) will
113    * have to override this method.  In doing so, it should call its
114    * superclass' implementation as its first step. Note that imaging
115    * filters operate differently than the classes to this point in the
116    * class hierachy.  Up till now, the base assumption has been that
117    * the largest possible region will be requested of the input.
118    *
119    * This implementation of GenerateInputRequestedRegion() only
120    * processes the inputs that are a subclass of the
121    * ImageBase<InputImageDimension>.  If an input is another type of
122    * DataObject (including an Image of a different dimension), they
123    * are skipped by this method. The subclasses of ImageToImageFilter
124    * are responsible for providing an implementation of
125    * GenerateInputRequestedRegion() when there are multiple inputs of
126    * different types.
127    *
128    * \sa ProcessObject::GenerateInputRequestedRegion(),
129    *     ImageSource::GenerateInputRequestedRegion() */
130   virtual void GenerateInputRequestedRegion();
131
132
133   /** Typedef for the region copier function object that converts an
134    * input region to an output region. */
135 LEN   typedef ImageToImageFilterDetail::ImageRegionCopier<itkGetStaticConstMacro(OutputImageDimension),
136 LEN                     itkGetStaticConstMacro(InputImageDimension)> InputToOutputRegionCopierType;
137
138   /** Typedef for the region copier function object that converts an
139    * output region to an input region. */
140 LEN   typedef ImageToImageFilterDetail::ImageRegionCopier<itkGetStaticConstMacro(InputImageDimension),
141 LEN                     itkGetStaticConstMacro(OutputImageDimension)> OutputToInputRegionCopierType;
142
143   /** This function calls the actual region copier to do the mapping
144    * from output image space to input image space.  It uses a Function
145    * object used for dispatching to various routines to copy an output
146    * region (start index and size) to an input region.  For most
147    * filters, this is a trivial copy because most filters require the
148    * input dimension to match the output dimension.  However, some
149    * filters like itk::ExtractImageFilter can support output images of
150    * a lower dimension that the input.
151    *
152    * This function object can be used by GenerateOutputInformation()
153    * to copy the input LargestPossibleRegion to the output
154    * LargestPossibleRegion and can also be used in GenerateData or
155    * ThreadedGenerateData() where a filter may need to map an
156    * output region to an input region.
157    *
158    * The default copier uses a "dispatch pattern" to call one of three
159    * overloaded functions depending on whether the input and output
160    * images are the same dimension, the input is a higher dimension
161    * that the output, or the input is of a lower dimension than the
162    * output. The use of an overloaded function is required for proper
163    * compilation of the various cases.
164    * 
165    * For the latter two cases, trivial implementations are used.  If
166    * the input image is a higher dimension than the output, the output
167    * region information is copied into the first portion of the input
168    * region and the rest of the input region is set to zero.  If the
169    * input region is a lower dimension than the output, the first
170    * portion of the output region is copied to the input region.
171    *
172    * If a filter needs a different default behavior, it can override
173    * this method. The ExtractImageFilter overrides this function
174    * object so that if the input image is a higher dimension than the
175    * output image, the filter can control "where" in the input image
176    * the output subimage is extracted (as opposed to mapping to first
177    * few dimensions of the input). */
178 LEN   virtual void CallCopyOutputRegionToInputRegion(InputImageRegionType &destRegion,
179                               const OutputImageRegionType &srcRegion);
180
181   /** This function calls the actual region copier to do the mapping
182    * from input image space to output image space.  It uses a Function
183    * object used for dispatching to various routines to copy an input
184    * region (start index and size) to an output region.  For most
185    * filters, this is a trivial copy because most filters require the
186    * input dimension to match the output dimension.  However, some
187    * filters like itk::UnaryFunctorImageFilter can support output
188    * images of a higher dimension that the input.
189    *
190    * This function object is used by the default implementation of
191    * GenerateOutputInformation(). It can also be used in routines
192    * like ThreadedGenerateData() where a filter may need to map an
193    * input region to an output region.
194    *
195    * The default copier uses a "dispatch pattern" to call one of three
196    * overloaded functions depending on whether the input and output
197    * images are the same dimension, the input is a higher dimension
198    * that the output, or the input is of a lower dimension than the
199    * output. The use of an overloaded function is required for proper
200    * compilation of the various cases.
201    * 
202    * For the latter two cases, trivial implementations are used.  If
203    * the input image is a higher dimension than the output, the first
204    * portion of the input region is copied to the output region.  If
205    * the input region is a lower dimension than the output, the input
206    * region information is copied into the first portion of the output
207    * region and the rest of the output region is set to zero.
208    *
209    * If a filter needs a different default behavior, it can override
210    * this method. */
211 LEN   virtual void CallCopyInputRegionToOutputRegion(OutputImageRegionType &destRegion,
212                               const InputImageRegionType &srcRegion);
213   
214
215 private:
216   ImageToImageFilter(const Self&); //purposely not implemented
217   void operator=(const Self&); //purposely not implemented
218 };
219
220
221 #ifdef ITK_EXPLICIT_INSTANTIATION
222 LEN,IND ***export template class ImageToImageFilter<Image<float         ,2>, Image<float         ,2> >;
223 LEN,IND ***export template class ImageToImageFilter<Image<double        ,2>, Image<double        ,2> >;
224 LEN,IND ***export template class ImageToImageFilter<Image<unsigned char ,2>, Image<unsigned char ,2> >;
225 LEN,IND ***export template class ImageToImageFilter<Image<unsigned short,2>, Image<unsigned short,2> >;
226 LEN,IND ***export template class ImageToImageFilter<Image<signed char   ,2>, Image<signed char   ,2> >;
227 LEN,IND ***export template class ImageToImageFilter<Image<signed short  ,2>, Image<signed short  ,2> >;
228 LEN,IND ***export template class ImageToImageFilter<Image<signed int    ,2>, Image<signed int    ,2> >;
229
230 LEN,IND ***export template class ImageToImageFilter<Image<double        ,2>, Image<float         ,2> >;
231 LEN,IND ***export template class ImageToImageFilter<Image<unsigned char ,2>, Image<float         ,2> >;
232 LEN,IND ***export template class ImageToImageFilter<Image<unsigned short,2>, Image<float         ,2> >;
233 LEN,IND ***export template class ImageToImageFilter<Image<signed char   ,2>, Image<float         ,2> >;
234 LEN,IND ***export template class ImageToImageFilter<Image<signed short  ,2>, Image<float         ,2> >;
235
236 LEN,IND ***export template class ImageToImageFilter<Image<float         ,2>, Image<double        ,2> >;
237 LEN,IND ***export template class ImageToImageFilter<Image<float         ,2>, Image<unsigned char ,2> >;
238 LEN,IND ***export template class ImageToImageFilter<Image<float         ,2>, Image<unsigned short,2> >;
239 LEN,IND ***export template class ImageToImageFilter<Image<float         ,2>, Image<signed char   ,2> >;
240 LEN,IND ***export template class ImageToImageFilter<Image<float         ,2>, Image<signed short  ,2> >;
241
242 LEN,IND ***export template class ImageToImageFilter<Image<float         ,3>, Image<float         ,3> >;
243 LEN,IND ***export template class ImageToImageFilter<Image<double        ,3>, Image<double        ,3> >;
244 LEN,IND ***export template class ImageToImageFilter<Image<unsigned char ,3>, Image<unsigned char ,3> >;
245 LEN,IND ***export template class ImageToImageFilter<Image<unsigned short,3>, Image<unsigned short,3> >;
246 LEN,IND ***export template class ImageToImageFilter<Image<signed char   ,3>, Image<signed char   ,3> >;
247 LEN,IND ***export template class ImageToImageFilter<Image<signed short  ,3>, Image<signed short  ,3> >;
248 LEN,IND ***export template class ImageToImageFilter<Image<signed int    ,3>, Image<signed int    ,3> >;
249
250 LEN,IND ***export template class ImageToImageFilter<Image<double        ,3>, Image<float         ,3> >;
251 LEN,IND ***export template class ImageToImageFilter<Image<unsigned char ,3>, Image<float         ,3> >;
252 LEN,IND ***export template class ImageToImageFilter<Image<unsigned short,3>, Image<float         ,3> >;
253 LEN,IND ***export template class ImageToImageFilter<Image<signed char   ,3>, Image<float         ,3> >;
254 LEN,IND ***export template class ImageToImageFilter<Image<signed short  ,3>, Image<float         ,3> >;
255
256 LEN,IND ***export template class ImageToImageFilter<Image<float         ,3>, Image<double        ,3> >;
257 LEN,IND ***export template class ImageToImageFilter<Image<float         ,3>, Image<unsigned char ,3> >;
258 LEN,IND ***export template class ImageToImageFilter<Image<float         ,3>, Image<unsigned short,3> >;
259 LEN,IND ***export template class ImageToImageFilter<Image<float         ,3>, Image<signed char   ,3> >;
260 LEN,IND ***export template class ImageToImageFilter<Image<float         ,3>, Image<signed short  ,3> >;
261 #endif
262 // end namespace itk
263
264 #ifndef ITK_MANUAL_INSTANTIATION
265 #include "itkImageToImageFilter.txx"
266 #endif
267
268 #endif
269

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:17PM
© Kitware Inc.