Orfeo Toolbox  3.16
itkRegionOfInterestImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkRegionOfInterestImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-12-18 17:49:58 $
7  Version: $Revision: 1.17 $
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  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkRegionOfInterestImageFilter_txx
18 #define __itkRegionOfInterestImageFilter_txx
19 
21 #include "itkImageRegionIterator.h"
23 #include "itkObjectFactory.h"
24 #include "itkProgressReporter.h"
25 #include "itkImage.h"
26 
27 namespace itk
28 {
29 
33 template <class TInputImage, class TOutputImage>
36 {
37 }
38 
39 
43 template <class TInputImage, class TOutputImage>
44 void
46 ::PrintSelf(std::ostream& os, Indent indent) const
47 {
48  Superclass::PrintSelf(os,indent);
49 
50  os << indent << "RegionOfInterest: " << m_RegionOfInterest << std::endl;
51 }
52 
53 template <class TInputImage, class TOutputImage>
54 void
57 {
58  // call the superclass' implementation of this method
59  Superclass::GenerateInputRequestedRegion();
60 
61  // get pointer to the input
62  typename Superclass::InputImagePointer inputPtr =
63  const_cast< TInputImage * >( this->GetInput() );
64 
65  if( inputPtr )
66  {
67  // request the region of interest
68  inputPtr->SetRequestedRegion( m_RegionOfInterest );
69  }
70 }
71 
72 template <class TInputImage, class TOutputImage>
73 void
76 {
77  // call the superclass' implementation of this method
78  Superclass::EnlargeOutputRequestedRegion(output);
79 
80  // generate everything in the region of interest
82 }
83 
93 template <class TInputImage, class TOutputImage>
94 void
97 {
98  // do not call the superclass' implementation of this method since
99  // this filter allows the input the output to be of different dimensions
100 
101  // get pointers to the input and output
102  typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
103  typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
104 
105  if ( !outputPtr || !inputPtr)
106  {
107  return;
108  }
109 
110  // Set the output image size to the same value as the region of interest.
111  RegionType region;
112  IndexType start;
113  start.Fill(0);
114 
115  region.SetSize( m_RegionOfInterest.GetSize() );
116  region.SetIndex( start );
117 
118  // Copy Information without modification.
119  outputPtr->CopyInformation( inputPtr );
120 
121  // Adjust output region
122  outputPtr->SetLargestPossibleRegion(region);
123 
124  // Correct origin of the extracted region.
125  IndexType roiStart( m_RegionOfInterest.GetIndex() );
126  typename Superclass::OutputImageType::PointType outputOrigin;
127  inputPtr->TransformIndexToPhysicalPoint( roiStart, outputOrigin);
128  outputPtr->SetOrigin( outputOrigin );
129 
130 }
131 
144 template <class TInputImage, class TOutputImage>
145 void
147 ::ThreadedGenerateData(const RegionType& outputRegionForThread,
148  int threadId)
149 {
150  itkDebugMacro(<<"Actually executing");
151 
152  // Get the input and output pointers
153  typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
154  typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
155 
156  // support progress methods/callbacks
157  ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
158 
159  // Define the portion of the input to walk for this thread
160  InputImageRegionType inputRegionForThread;
161  inputRegionForThread.SetSize( outputRegionForThread.GetSize() );
162 
163  IndexType start;
164  IndexType roiStart( m_RegionOfInterest.GetIndex() );
165  IndexType threadStart( outputRegionForThread.GetIndex() );
166  for(unsigned int i=0; i<ImageDimension; i++)
167  {
168  start[i] = roiStart[i] + threadStart[i];
169  }
170 
171  inputRegionForThread.SetIndex( start );
172 
173  // Define the iterators.
174  typedef ImageRegionIterator<TOutputImage> OutputIterator;
175  typedef ImageRegionConstIterator<TInputImage> InputIterator;
176 
177  OutputIterator outIt(outputPtr, outputRegionForThread);
178  InputIterator inIt(inputPtr, inputRegionForThread);
179 
180  // walk the output region, and sample the input image
181  while( !outIt.IsAtEnd() )
182  {
183  // copy the input pixel to the output
184  outIt.Set( inIt.Get());
185  ++outIt;
186  ++inIt;
187  progress.CompletedPixel();
188  }
189 }
190 
191 } // end namespace itk
192 
193 #endif

Generated at Sun Feb 3 2013 00:03:18 for Orfeo Toolbox with doxygen 1.8.1.1