Orfeo Toolbox  3.16
itkInPlaceLabelMapFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkInPlaceLabelMapFilter.txx,v $
5  Language: C++
6  Date: $Date: 2009-07-10 13:53:12 $
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  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  PURPOSE. See the above copyright notices for more information.
18 
19 =========================================================================*/
20 #ifndef __itkInPlaceLabelMapFilter_txx
21 #define __itkInPlaceLabelMapFilter_txx
22 
24 
25 
26 namespace itk
27 {
28 
32 template <class TInputImage>
34 ::InPlaceLabelMapFilter() : m_InPlace(true)
35 {
36 }
37 
41 template <class TInputImage>
44 {
45 }
46 
47 
48 
49 template<class TInputImage>
50 void
52 ::PrintSelf(std::ostream& os, Indent indent) const
53 {
54  Superclass::PrintSelf(os, indent);
55  os << indent << "InPlace: " << (this->m_InPlace ? "On" : "Off") << std::endl;
56  if ( this->CanRunInPlace())
57  {
58  os << indent << "The input and output to this filter are the same type. The filter can be run in place." << std::endl;
59  }
60  else
61  {
62  os << indent << "The input and output to this filter are different types. The filter cannot be run in place." << std::endl;
63  }
64 }
65 
66 template<class TInputImage>
67 void
70 {
71  // if told to run in place and the types support it,
72  if( this->m_InPlace && this->CanRunInPlace() )
73  {
74  // Graft this first input to the output. Later, we'll need to
75  // remove the input's hold on the bulk data.
76  //
77  OutputImagePointer inputAsOutput = dynamic_cast<TOutputImage *>(const_cast<TInputImage *>(this->GetInput()));
78 
79  if( inputAsOutput )
80  {
81  // save the largest possible region to restore it after the graft output.
82  // the largest possible region is not that important with LabelMap and
83  // can be managed by the filter, even when running inplace
84  RegionType region = this->GetOutput()->GetLargestPossibleRegion();
85  this->GraftOutput( inputAsOutput );
86  this->GetOutput()->SetRegions( region );
87  }
88 
89  // If there are more than one outputs, allocate the remaining outputs
90  for (unsigned int i=1; i < this->GetNumberOfOutputs(); i++)
91  {
92  OutputImagePointer outputPtr;
93 
94  outputPtr = this->GetOutput(i);
95  outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
96  outputPtr->Allocate();
97  }
98  }
99  else
100  {
101  Superclass::AllocateOutputs();
102  // copy the content of the input image to the output image
103  const TInputImage * input = this->GetInput();
104  TOutputImage * output = this->GetOutput();
105  assert( input != NULL );
106  assert( output != NULL );
107 
108  output->SetBackgroundValue( input->GetBackgroundValue() );
109 
110 
111  const LabelObjectContainerType & labelObjectContainer = input->GetLabelObjectContainer();
112 
113  LabelObjectContainerConstIterator it = labelObjectContainer.begin();
114 
115  while( it != labelObjectContainer.end() )
116  {
117  const LabelObjectType * labeObject = it->second;
118 
119  assert( labeObject != NULL );
120  assert( labeObject->GetLabel() == it->first );
121 
122  typename LabelObjectType::Pointer newLabelObject = LabelObjectType::New();
123  newLabelObject->CopyAllFrom( labeObject );
124 
125  output->AddLabelObject( newLabelObject );
126  it++;
127  }
128 
129  }
130 }
131 
132 template<class TInputImage>
133 void
136 {
137  // if told to run in place and the types support it,
138  if( this->m_InPlace && (typeid(TInputImage) == typeid(TOutputImage)) )
139  {
140 
141  // Release any input where the ReleaseData flag has been set
143 
144  // Release input 0 by default since we overwrote it
145  TInputImage * ptr = const_cast<TInputImage*>( this->GetInput() );
146  if( ptr )
147  {
148  ptr->ReleaseData();
149  }
150  }
151  else
152  {
153  Superclass::ReleaseInputs();
154  }
155 }
156 
157 } // end namespace itk
158 
159 #endif

Generated at Sat Feb 2 2013 23:46:04 for Orfeo Toolbox with doxygen 1.8.1.1