KWStyle - itkInPlaceImageFilter.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkInPlaceImageFilter.txx.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 DEF #ifndef _itkInPlaceImageFilter_txx
21 DEF #define _itkInPlaceImageFilter_txx
22 #include "itkInPlaceImageFilter.h"
23
24
25 namespace itk
26 {
27
28 /**
29  *
30  */
31 template <class TInputImage, class TOutputImage>
32 InPlaceImageFilter<TInputImage, TOutputImage>
33 ::InPlaceImageFilter()
34 IND **: m_InPlace(true)
35 {
36 }
37
38 /**
39  *
40  */
41 template <class TInputImage, class TOutputImage>
42 InPlaceImageFilter<TInputImage, TOutputImage>
43 ::~InPlaceImageFilter()
44 {
45 }
46   
47
48
49 template<class TInputImage, class TOutputImage>
50 void 
51 InPlaceImageFilter<TInputImage, TOutputImage>
52 ::PrintSelf(std::ostream& os, Indent indent) const
53 {
54   Superclass::PrintSelf(os, indent);
55   os << indent << "InPlace: " << (m_InPlace ? "On" : "Off") << std::endl;
56   if ( this->CanRunInPlace())
57     {
58 LEN     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 LEN     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, class TOutputImage>
67 void 
68 InPlaceImageFilter<TInputImage, TOutputImage>
69 ::AllocateOutputs()
70 {
71   // if told to run in place and the types support it, 
72   if (m_InPlace && (typeid(TInputImage) == typeid(TOutputImage)))
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
78 LEN,IND ******= dynamic_cast<TOutputImage *>(const_cast<TInputImage *>(this->GetInput()));
79     if (inputAsOutput)
80       {
81       this->GraftOutput( inputAsOutput );
82       }
83     else
84       {
85       // if we cannot cast the input to an output type, then allocate
86       // an output usual.
87       OutputImagePointer outputPtr;
88
89       outputPtr = this->GetOutput(0);
90       outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
91       outputPtr->Allocate();
92       }
93     
94     // If there are more than one outputs, allocate the remaining outputs
95     for (unsigned int i=1; i < this->GetNumberOfOutputs(); i++)
96       {
97       OutputImagePointer outputPtr;
98       
99       outputPtr = this->GetOutput(i);
100       outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
101       outputPtr->Allocate();
102       }
103     }
104   else
105     {
106     Superclass::AllocateOutputs();
107     }
108 }
109
110 template<class TInputImage, class TOutputImage>
111 void 
112 InPlaceImageFilter<TInputImage, TOutputImage>
113 ::ReleaseInputs()
114 {
115   // if told to run in place and the types support it, 
116   if (m_InPlace && (typeid(TInputImage) == typeid(TOutputImage)))
117     {
118     // Release any input where the ReleaseData flag has been set
119     ProcessObject::ReleaseInputs();
120     
121     // Release input 0 by default since we overwrote it
122     TInputImage * ptr = const_cast<TInputImage*>( this->GetInput() );
123     if( ptr )
124       {
125       ptr->ReleaseData();
126       }
127     }
128   else
129     {
130     Superclass::ReleaseInputs();
131     }
132 }
133
134
135 // end namespace itk
136
137 #endif
138

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