Orfeo Toolbox  3.16
itkLabelMapToBinaryImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkLabelMapToBinaryImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2009-08-07 11:28:02 $
7  Version: $Revision: 1.3 $
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 __itkLabelMapToBinaryImageFilter_txx
18 #define __itkLabelMapToBinaryImageFilter_txx
19 
21 #include "itkNumericTraits.h"
22 #include "itkProgressReporter.h"
24 #include "itkImageRegionIterator.h"
25 
26 namespace itk {
27 
28 template <class TInputImage, class TOutputImage>
31 {
32  this->m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin();
33  this->m_ForegroundValue = NumericTraits<OutputImagePixelType>::max();
34 }
35 
36 template <class TInputImage, class TOutputImage>
37 void
40 {
41  // call the superclass' implementation of this method
42  Superclass::GenerateInputRequestedRegion();
43 
44  // We need all the input.
45  InputImagePointer input = const_cast<InputImageType *>(this->GetInput());
46 
47  if( input )
48  {
49  input->SetRequestedRegion( input->GetLargestPossibleRegion() );
50  }
51 }
52 
53 
54 template <class TInputImage, class TOutputImage>
55 void
58 {
59  this->GetOutput()->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() );
60 }
61 
62 
63 template<class TInputImage, class TOutputImage>
64 void
67 {
68  unsigned long numberOfThreads = this->GetNumberOfThreads();
70  {
71  numberOfThreads = vnl_math_min(
72  this->GetNumberOfThreads(), itk::MultiThreader::GetGlobalMaximumNumberOfThreads() );
73  }
74 
75  // number of threads can be constrained by the region size, so call the
76  // SplitRequestedRegion to get the real number of threads which will be used
77  typename TOutputImage::RegionType splitRegion; // dummy region - just to call the following method
78 
79  numberOfThreads = this->SplitRequestedRegion(0, numberOfThreads, splitRegion);
80 
81  m_Barrier = Barrier::New();
82 
83  m_Barrier->Initialize( numberOfThreads );
84 
85  this->Superclass::BeforeThreadedGenerateData();
86 }
87 
88 
89 template<class TInputImage, class TOutputImage>
90 void
92 ::ThreadedGenerateData( const OutputImageRegionType& outputRegionForThread, int threadId )
93 {
94  OutputImageType * output = this->GetOutput();
95 
96  // fill the output with background value - they will be overridden with the
97  // foreground value later, if there is some objects
98  if( this->GetNumberOfInputs() == 2 )
99  {
100  // fill the background with the background values from the background image
101  ImageRegionConstIterator< OutputImageType > bgIt( this->GetBackgroundImage(), outputRegionForThread );
102  ImageRegionIterator< OutputImageType > oIt( output, outputRegionForThread );
103 
104  bgIt.GoToBegin();
105  oIt.GoToBegin();
106 
107  while( !oIt.IsAtEnd() )
108  {
109  const OutputImagePixelType & bg = bgIt.Get();
110  if( bg != this->m_ForegroundValue )
111  {
112  oIt.Set( bg );
113  }
114  else
115  {
116  oIt.Set( this->m_BackgroundValue );
117  }
118  ++oIt;
119  ++bgIt;
120  }
121  }
122  else
123  {
124  // fill the background with the background value
125  ImageRegionIterator< OutputImageType > oIt( output, outputRegionForThread );
126  oIt.GoToBegin();
127 
128  while( !oIt.IsAtEnd() )
129  {
130  oIt.Set( this->m_BackgroundValue );
131  ++oIt;
132  }
133  }
134 
135  // wait for the other threads to complete that part
136  this->m_Barrier->Wait();
137 
138  // and delegate to the superclass implementation to use the thread support for the label objects
139  this->Superclass::ThreadedGenerateData( outputRegionForThread, threadId );
140 
141 }
142 
143 
144 template<class TInputImage, class TOutputImage>
145 void
148 {
149  OutputImageType * output = this->GetOutput();
150 
151  typedef typename LabelObjectType::LineContainerType LineContainerType;
152 
153  typename LineContainerType::const_iterator lit;
154  LineContainerType & lineContainer = labelObject->GetLineContainer();
155 
156  for( lit = lineContainer.begin(); lit != lineContainer.end(); lit++ )
157  {
158  IndexType idx = lit->GetIndex();
159 
160  unsigned long length = lit->GetLength();
161 
162  for( unsigned int i=0; i<length; i++)
163  {
164  output->SetPixel( idx, this->m_ForegroundValue );
165  idx[0]++;
166  }
167  }
168 }
169 
170 
171 template< class TInputImage, class TOutputImage >
172 void
174 ::PrintSelf(std::ostream& os, Indent indent) const
175 {
176  this->Superclass::PrintSelf(os,indent);
177 
178  os << indent << "ForegroundValue: "
179  << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(this->m_ForegroundValue) << std::endl;
180  os << indent << "BackgroundValue: "
181  << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(this->m_BackgroundValue) << std::endl;
182  os << indent << "Barrier object: " << this->m_Barrier.GetPointer() << std::endl;
183 }
184 
185 
186 } // end namespace itk
187 
188 #endif

Generated at Sat Feb 2 2013 23:49:15 for Orfeo Toolbox with doxygen 1.8.1.1